Constructing Reflective Immediate Optimization with GEPA: Multi-Element Prompts, Structured Suggestions, and Held-Out Validation

Constructing Reflective Immediate Optimization with GEPA: Multi-Element Prompts, Structured Suggestions, and Held-Out Validation


def make_problems(n, seed=0):
   rng = random.Random(seed)
   out = []
   for _ in vary(n):
       t = rng.selection(["discount", "travel", "wallet", "chain"])
       if t == "low cost":
           unit  = rng.selection([40, 60, 80, 120])
           qty   = rng.selection([5, 6, 8, 10])
           disc  = rng.selection([10, 20, 25, 50])
           complete = unit * qty
           gold  = complete - complete * disc // 100
           q = (f"A store sells notebooks at {unit} rupees every. You purchase {qty} "
                f"notebooks and get a {disc}% low cost on the entire invoice. "
                f"What number of rupees do you pay in complete?")
       elif t == "journey":
           s1, h1 = rng.selection([40, 50, 60]), rng.selection([2, 3])
           s2, h2 = rng.selection([30, 45, 70]), rng.selection([1, 2, 3])
           gold = s1 * h1 + s2 * h2
           q = (f"A automotive drives at {s1} km/h for {h1} hours, then at {s2} km/h "
                f"for {h2} hours. What's the complete distance travelled, in km?")
       elif t == "pockets":
           tens   = rng.selection([3, 5, 7, 9])
           fifties= rng.selection([2, 4, 6])
           spent  = rng.selection([50, 80, 110, 150])
           gold = tens * 10 + fifties * 50 - spent
           q = (f"You've {tens} ten-rupee notes and {fifties} fifty-rupee "
                f"notes. You spend {spent} rupees. What number of rupees are left?")
       else:
           x = rng.selection([6, 9, 12, 15]); y = rng.selection([4, 7, 10]); z = rng.selection([3, 8, 11])
           gold = x * 2 - y + z
           q = (f"Begin with the quantity {x}. Double it, then subtract {y}, "
                f"then add {z}. What quantity do you finish with?")
       out.append({"query": q, "reply": gold})
   return out
all_problems = make_problems(18, seed=42)
random.Random(1).shuffle(all_problems)
trainset = all_problems[:12]
valset   = all_problems[12:]
print(f"Dataset: {len(trainset)} prepare / {len(valset)} val problemsn")



Source link

Leave a Reply

Your email address will not be published. Required fields are marked *