import%20marimo%0A%0A__generated_with%20%3D%20%220.17.2%22%0Aapp%20%3D%20marimo.App(width%3D%22medium%22)%0A%0A%0A%40app.cell%0Adef%20_()%3A%0A%20%20%20%20import%20marimo%20as%20mo%0A%20%20%20%20import%20dspy%0A%20%20%20%20import%20datasets%0A%20%20%20%20import%20asyncio%0A%20%20%20%20import%20os%0A%20%20%20%20import%20random%0A%20%20%20%20return%20asyncio%2C%20datasets%2C%20dspy%2C%20mo%2C%20os%2C%20random%0A%0A%0A%40app.cell(hide_code%3DTrue)%0Adef%20_(mo)%3A%0A%20%20%20%20mo.md(%0A%20%20%20%20%20%20%20%20r%22%22%22%0A%20%20%20%20%23%23%20DSPy%20Tutorials%0A%0A%20%20%20%20There%20are%20many%20tutorials%20on%20DSPy%20on%20the%20web.%20The%20%5BDSPy%20website%5D(https%3A%2F%2Fdspy.ai)%20is%20itself%20a%20good%20source%2C%20and%20so%20is%20the%20DSPy%20Discord.%20I%20recommend%20reading%20%5BDSPy%20Programming%5D(https%3A%2F%2Fdspy.ai%2Flearn%2Fprogramming%2Foverview%2F)%20section%20of%20the%20DSPy%20website%20before%20proceeding.%0A%20%20%20%20%22%22%22%0A%20%20%20%20)%0A%20%20%20%20return%0A%0A%0A%40app.cell(hide_code%3DTrue)%0Adef%20_(mo)%3A%0A%20%20%20%20mo.md(r%22%22%22%23%23%20DSPy%20Example%3A%20Math%20Word%20Problems%22%22%22)%0A%20%20%20%20return%0A%0A%0A%40app.cell(hide_code%3DTrue)%0Adef%20_(mo)%3A%0A%20%20%20%20mo.md(r%22%22%22We%20will%20use%20DSPy%20to%20solve%20math%20word%20problems%2C%20as%20we%20have%20done%20several%20times%20before.%22%22%22)%0A%20%20%20%20return%0A%0A%0A%40app.cell%0Adef%20_(datasets)%3A%0A%20%20%20%20test_data%20%3D%20datasets.load_dataset(%22nuprl%2Fengineering-llm-systems%22%2C%20%22math_word_problems%22%2C%20split%3D%22test%22)%0A%20%20%20%20test_data%5B0%5D%0A%20%20%20%20return%20(test_data%2C)%0A%0A%0A%40app.cell%0Adef%20_()%3A%0A%20%20%20%20STUDENT_MODEL%20%3D%20%22meta-llama%2FLlama-3.1-8B-Instruct%3Acerebras%22%0A%20%20%20%20return%20(STUDENT_MODEL%2C)%0A%0A%0A%40app.cell(hide_code%3DTrue)%0Adef%20_(mo)%3A%0A%20%20%20%20mo.md(r%22%22%22DSPy%20uses%20LiteLLM%20under%20the%20hood%2C%20so%20you%20can%20use%20it%20with%20many%20different%20models.%20The%20code%20below%20creates%20an%20%60dspy.LM%60%20object%20that%20references%20a%20small%20model%20hosted%20by%20Hugging%20Face.%22%22%22)%0A%20%20%20%20return%0A%0A%0A%40app.cell%0Adef%20_(STUDENT_MODEL%2C%20dspy%2C%20os)%3A%0A%20%20%20%20student%20%3D%20dspy.LM(%0A%20%20%20%20%20%20%20%20model%3Df%22openai%2F%7BSTUDENT_MODEL%7D%22%2C%0A%20%20%20%20%20%20%20%20api_base%3D%22https%3A%2F%2Frouter.huggingface.co%2Fv1%22%2C%0A%20%20%20%20%20%20%20%20api_key%3Dos.environ%5B%22HUGGINGFACE_TOKEN%22%5D%2C%0A%20%20%20%20%20%20%20%20model_type%3D%22chat%22%2C%0A%20%20%20%20%20%20%20%20max_tokens%3D8192%2C%0A%20%20%20%20%20%20%20%20temperature%3D0.2)%0A%20%20%20%20student(%22Can%20you%20hear%20me%3F%22)%0A%20%20%20%20return%20(student%2C)%0A%0A%0A%40app.cell%0Adef%20_(mo)%3A%0A%20%20%20%20mo.md(r%22%22%22Instead%20of%20calling%20the%20model%20directly%2C%20we%20can%20define%20a%20*DSPy%20signature*%20which%20specifies%20the%20types%20of%20inputs%20and%20outputs.%22%22%22)%0A%20%20%20%20return%0A%0A%0A%40app.cell%0Adef%20_(dspy)%3A%0A%20%20%20%20simple_solver_sig%20%3D%20dspy.Signature(%22problem%3Astr%20-%3E%20solution%3Afloat%22%2C%20instructions%3D%22Solve%20the%20given%20problem.%22)%0A%20%20%20%20return%20(simple_solver_sig%2C)%0A%0A%0A%40app.cell%0Adef%20_(mo)%3A%0A%20%20%20%20mo.md(r%22%22%22The%20simplest%20way%20to%20instantiate%20a%20signature%20is%20with%20the%20*dspy.Predict*%20prompting%20technique%2C%20which%20asks%20the%20LLM%20to%20solve%20the%20problem%20directly.%22%22%22)%0A%20%20%20%20return%0A%0A%0A%40app.cell%0Adef%20_(dspy%2C%20simple_solver_sig%2C%20student%2C%20test_data)%3A%0A%20%20%20%20simple_solver_predict%20%3D%20dspy.Predict(simple_solver_sig)%0A%20%20%20%20simple_solver_predict.set_lm(student)%0A%20%20%20%20simple_solver_predict(problem%3Dtest_data%5B0%5D%5B%22question%22%5D)%0A%20%20%20%20return%20(simple_solver_predict%2C)%0A%0A%0A%40app.cell(hide_code%3DTrue)%0Adef%20_(mo)%3A%0A%20%20%20%20mo.md(r%22%22%22Let's%20evaluate%20on%20the%20entire%20test%20set.%20The%20code%20below%20uses%20asyncio%20to%20issue%20all%20queries%20concurrently.%22%22%22)%0A%20%20%20%20return%0A%0A%0A%40app.cell%0Aasync%20def%20_(asyncio%2C%20simple_solver_predict%2C%20test_data)%3A%0A%20%20%20%20async%20def%20eval_simple_solver(f)%3A%0A%20%20%20%20%20%20%20%20async%20def%20g(problem)%3A%0A%20%20%20%20%20%20%20%20%20%20%20%20try%3A%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20return%20(await%20f.aforward(problem%3Dproblem)).solution%0A%20%20%20%20%20%20%20%20%20%20%20%20except%3A%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%23%20At%20scale%2C%20we%20can%20get%20exceptions%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20return%20None%0A%0A%20%20%20%20%20%20%20%20solutions%20%3D%20await%20asyncio.gather(*%5B%20g(item%5B%22question%22%5D)%20for%20item%20in%20test_data%20%5D)%0A%20%20%20%20%20%20%20%20correct%20%3D%20sum(1%20for%20result%2C%20item%20in%20zip(solutions%2C%20test_data)%20if%20result%20%3D%3D%20item%5B%22answer%22%5D)%0A%20%20%20%20%20%20%20%20accuracy%20%3D%20correct%20%2F%20len(test_data)%0A%20%20%20%20%20%20%20%20print(f%22Accuracy%3A%20%7Baccuracy%3A.2%25%7D%22)%0A%20%20%20%20%20%20%20%20return%20solutions%0A%0A%20%20%20%20await%20eval_simple_solver(simple_solver_predict)%0A%20%20%20%20return%20(eval_simple_solver%2C)%0A%0A%0A%40app.cell(hide_code%3DTrue)%0Adef%20_(mo)%3A%0A%20%20%20%20mo.md(r%22%22%22We%20can%20do%20a%20lot%20better%20using%20chain%20of%20thought.%20Notably%2C%20we%20do%20not%20have%20to%20change%20the%20signature.%22%22%22)%0A%20%20%20%20return%0A%0A%0A%40app.cell%0Aasync%20def%20_(dspy%2C%20eval_simple_solver%2C%20simple_solver_sig%2C%20student)%3A%0A%20%20%20%20simple_solver_cot%20%3D%20dspy.ChainOfThought(simple_solver_sig)%0A%20%20%20%20simple_solver_cot.set_lm(student)%0A%20%20%20%20await%20eval_simple_solver(simple_solver_cot)%0A%20%20%20%20return%0A%0A%0A%40app.cell(hide_code%3DTrue)%0Adef%20_(mo)%3A%0A%20%20%20%20mo.md(r%22%22%22%23%23%20Reflective%20Prompt%20Optimization%22%22%22)%0A%20%20%20%20return%0A%0A%0A%40app.cell(hide_code%3DTrue)%0Adef%20_(mo)%3A%0A%20%20%20%20mo.md(%0A%20%20%20%20%20%20%20%20r%22%22%22%0A%20%20%20%20DSPy%20comes%20with%20several%20prompt%20optimizers%2C%20and%20this%20is%20an%20active%20area%20of%20research.%20We'll%20build%20a%20simple%20prompt%0A%20%20%20%20optimizer%20ourselves.%20Our%20prompt%20optimizer%20relies%20on%20*reflection*%20(%5BShinn%2C%20et%20al%202023%5D(https%3A%2F%2Fopenreview.net%2Fforum%3Fid%3DvAElhFcKW6))%2C%20which%20is%20the%20ability%20of%20cutting-edge%20language%20models%20to%20update%20their%20own%20instructions%20based%20on%20external%20correctness%20signals.%0A%0A%20%20%20%20Any%20prompt%20optimizer%20should%20use%20a%20training%20set%20that%20is%20disjoint%20from%20the%20test%20set.%20(We%20wouldn't%20want%20to%20optimizer%20to%20just%20put%20the%20training%20examples%20in%20the%20prompt.)%0A%20%20%20%20%22%22%22%0A%20%20%20%20)%0A%20%20%20%20return%0A%0A%0A%40app.cell%0Adef%20_(datasets%2C%20random)%3A%0A%20%20%20%20train_data%20%3D%20list(datasets.load_dataset(%22nuprl%2Fengineering-llm-systems%22%2C%20%22gsm8k%22%2C%20split%3D%22train%22))%0A%20%20%20%20%23%20There%20are%20a%20few%20items%20with%20commas%20in%20the%20answer%2C%20e.g.%2C%201%2C000.%0A%20%20%20%20train_data%20%3D%20%5B%20%0A%20%20%20%20%20%20%20%20%7B%20%22question%22%3A%20item%5B%22question%22%5D%2C%20%22answer%22%3A%20float(item%5B%22answer%22%5D.replace(%22%2C%22%2C%20%22%22))%20%7D%20%0A%20%20%20%20%20%20%20%20for%20item%20in%20train_data%20%0A%20%20%20%20%5D%0A%20%20%20%20random.shuffle(train_data)%0A%20%20%20%20return%20(train_data%2C)%0A%0A%0A%40app.cell(hide_code%3DTrue)%0Adef%20_(STUDENT_MODEL%2C%20mo)%3A%0A%20%20%20%20mo.md(rf%22%22%22It%20can%20help%20to%20use%20a%20better%20model%20to%20optimize%20prompts.%20In%20my%20prompts%20below%2C%20I%20use%20instructions%20such%20as%20%22use%20no%20more%20than%20*N*%20sentences.%22%20I%20find%20that%20%60%7BSTUDENT_MODEL%7D%60%20does%20not%20follow%20that%20instruction%20well%2C%20which%20is%20the%20only%20reason%20I%20use%20a%20larger%20model.%22%22%22)%0A%20%20%20%20return%0A%0A%0A%40app.cell%0Adef%20_(dspy%2C%20os)%3A%0A%20%20%20%20teacher%20%3D%20dspy.LM(%0A%20%20%20%20%20%20%20%20%23%20model%3Df%22openai%2Fmeta-llama%2FLlama-3.3-70B-Instruct%3Acerebras%22%2C%0A%20%20%20%20%20%20%20%20model%20%3D%20%22openai%2FQwen%2FQwen3-235B-A22B-Instruct-2507%3Acerebras%22%2C%0A%20%20%20%20%20%20%20%20%23%20model%3Df%22openai%2F%7BSTUDENT_MODEL%7D%22%2C%0A%20%20%20%20%20%20%20%20api_base%3D%22https%3A%2F%2Frouter.huggingface.co%2Fv1%22%2C%0A%20%20%20%20%20%20%20%20api_key%3Dos.environ%5B%22HUGGINGFACE_TOKEN%22%5D%2C%0A%20%20%20%20%20%20%20%20model_type%3D%22chat%22%2C%0A%20%20%20%20%20%20%20%20max_tokens%3D16_384%2C%0A%20%20%20%20%20%20%20%20temperature%3D0.7)%0A%20%20%20%20teacher(%22Can%20you%20hear%20me%3F%22)%0A%20%20%20%20return%20(teacher%2C)%0A%0A%0A%40app.cell(hide_code%3DTrue)%0Adef%20_(mo)%3A%0A%20%20%20%20mo.md(r%22%22%22Compare%20the%20solver%20below%20with%20the%20one%20we%20defined%20earlier.%20All%20that%20we%20have%20done%20is%20added%20a%20%22hint%22%20field%2C%20and%20the%20optimizer%20will%20try%20to%20write%20a%20better%20hint.%20As%20a%20first%20step%2C%20we'll%20start%20with%20a%20trivial%20hint.%22%22%22)%0A%20%20%20%20return%0A%0A%0A%40app.cell%0Aasync%20def%20_(asyncio%2C%20dspy%2C%20student%2C%20test_data)%3A%0A%20%20%20%20solve_problem_sig%20%3D%20dspy.Signature(%0A%20%20%20%20%20%20%20%20%22instruction%2C%20problem%20-%3E%20solution%3Aint%22%2C%0A%20%20%20%20%20%20%20%20instructions%3D%22Solve%20the%20given%20problem%20using%20the%20instructions.%22)%0A%20%20%20%20solve_problem%20%3D%20dspy.ChainOfThought(solve_problem_sig)%0A%20%20%20%20solve_problem.set_lm(student)%0A%0A%20%20%20%20async%20def%20eval_instructed_solver(instruction%2C%20problems%2C%20label)%3A%0A%20%20%20%20%20%20%20%20async%20def%20g(problem%2C%20expected)%3A%0A%20%20%20%20%20%20%20%20%20%20%20%20try%3A%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20r%20%3D%20await%20solve_problem.aforward(instruction%3Dinstruction%2C%20problem%3Dproblem)%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20return%20%7B%20%22problem%22%3A%20problem%2C%20%22expected%22%3A%20expected%2C%20**r%7D%0A%20%20%20%20%20%20%20%20%20%20%20%20except%3A%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%23%20At%20scale%2C%20we%20can%20get%20exceptions%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20return%20%7B%20%22problem%22%3A%20r%2C%20%22expected%22%3A%20expected%2C%20%22solution%22%3A%20None%2C%20%22reasoning%22%3A%20None%20%7D%0A%0A%20%20%20%20%20%20%20%20solutions%20%3D%20await%20asyncio.gather(*%5B%20g(item%5B%22question%22%5D%2C%20item%5B%22answer%22%5D)%20for%20item%20in%20test_data%20%5D)%0A%20%20%20%20%20%20%20%20correct%20%3D%20sum(1%20for%20item%20in%20solutions%20if%20item%5B%22solution%22%5D%20%3D%3D%20item%5B%22expected%22%5D)%0A%20%20%20%20%20%20%20%20accuracy%20%3D%20correct%20%2F%20len(test_data)%0A%20%20%20%20%20%20%20%20print(f%22%7Blabel%7D%3A%20%7Baccuracy%3A.2%25%7D%22)%0A%20%20%20%20%20%20%20%20return%20solutions%0A%0A%20%20%20%20_%20%3D%20await%20eval_instructed_solver(%22Return%20just%20a%20number.%22%2C%20test_data%2C%20label%3D%22test%20accuracy%20(initial)%22)%0A%20%20%20%20return%20(eval_instructed_solver%2C)%0A%0A%0A%40app.cell(hide_code%3DTrue)%0Adef%20_(mo)%3A%0A%20%20%20%20mo.md(r%22%22%22Notice%20above%20that%20the%20accuracy%20is%20not%20exactly%20what%20we%20had%20before%20--%20models%20are%20prompt%20sensitive%20--%20but%20its%20in%20the%20same%20ballpark.%22%22%22)%0A%20%20%20%20return%0A%0A%0A%40app.cell(hide_code%3DTrue)%0Adef%20_(mo)%3A%0A%20%20%20%20mo.md(r%22%22%22The%20core%20of%20our%20optimizer%20is%20the%20two%20signatures%20below%3A%20the%20first%20asks%20the%20model%20to%20identify%20its%20own%20errors%20on%20a%20particular%20solution.%20The%20second%20aggregates%20feedback%20and%20asks%20the%20model%20for%20new%20directions.%22%22%22)%0A%20%20%20%20return%0A%0A%0A%40app.cell%0Adef%20_(dspy%2C%20teacher)%3A%0A%20%20%20%20give_feedback_sig%20%3D%20dspy.Signature(%0A%20%20%20%20%20%20%20%20%22problem%2C%20prediction%2C%20expected%20-%3E%20feedback%22%2C%0A%20%20%20%20%20%20%20%20instructions%3D%22I%20tried%20to%20solve%20the%20given%20problem%2C%20but%20did%20not%20give%20the%20'expected'%20answer.%20Identify%20my%20mistakes%20and%20give%20me%20general%20guidance.%20Do%20not%20mention%20the%20specifics%20of%20the%20problem%20in%20the%20feedback.%20Be%20brief%20--%20no%20more%20than%205%20sentences.%22%0A%20%20%20%20)%0A%20%20%20%20give_feedback%20%3D%20dspy.Predict(give_feedback_sig)%0A%20%20%20%20give_feedback.set_lm(teacher)%0A%0A%20%20%20%20aggregate_feedback_sig%20%3D%20dspy.Signature(%0A%20%20%20%20%20%20%20%20%22old_instructions%3Astr%2C%20errors_made%3A%20List%5Bstr%5D%20-%3E%20new_instructions%22%2C%0A%20%20%20%20%20%20%20%20instructions%3D%22When%20I%20followed%20old_instructions%2C%20I%20made%20several%20errors.%20Read%20them%20and%20give%20me%20updated%20instructions%20to%20help%20me%20avoid%20these%20errors.%20Do%20not%20exceed%2010%20sentences.%22)%0A%20%20%20%20aggregate_feedback%20%3D%20dspy.Predict(aggregate_feedback_sig)%0A%20%20%20%20aggregate_feedback.set_lm(teacher)%0A%20%20%20%20return%20aggregate_feedback%2C%20give_feedback%0A%0A%0A%40app.cell(hide_code%3DTrue)%0Adef%20_(mo)%3A%0A%20%20%20%20mo.md(r%22%22%22The%20code%20below%20is%20a%20single%20trainiing%20step.%20We%20get%20predictions%20for%20a%20batch%20of%20solutions%20given%20the%20current%20instructions%2C%20get%20feedback%20on%20the%20wrong%20answers%2C%20aggregate%20them%20and%20produce%20an%20updated%20instruction.%22%22%22)%0A%20%20%20%20return%0A%0A%0A%40app.cell%0Adef%20_(%0A%20%20%20%20aggregate_feedback%2C%0A%20%20%20%20asyncio%2C%0A%20%20%20%20eval_instructed_solver%2C%0A%20%20%20%20give_feedback%2C%0A%20%20%20%20mo%2C%0A%20%20%20%20test_data%2C%0A)%3A%0A%20%20%20%20async%20def%20get_feedback(item)%3A%0A%20%20%20%20%20%20%20%20try%3A%0A%20%20%20%20%20%20%20%20%20%20%20%20feedback%20%3D%20await%20give_feedback.aforward(%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20problem%3Ditem%5B%22problem%22%5D%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20prediction%3Df%22%7Bitem%5B%22reasoning%22%5D%7D%5CnAnswer%3A%20%7Bitem%5B%22solution%22%5D%7D%22%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20expected%3Ditem%5B%22expected%22%5D)%0A%20%20%20%20%20%20%20%20%20%20%20%20return%20feedback.feedback%0A%20%20%20%20%20%20%20%20except%20Exception%20as%20e%3A%0A%20%20%20%20%20%20%20%20%20%20%20%20print(%22Exn%22%2C%20e)%0A%20%20%20%20%20%20%20%20%20%20%20%20return%20%22%22%0A%0A%20%20%20%20async%20def%20train_step(instruction%2C%20batch)%3A%0A%20%20%20%20%20%20%20%20predictions%20%3D%20await%20eval_instructed_solver(instruction%2C%20batch%2C%20label%3D%22train%20batch%20accuracy%22)%0A%20%20%20%20%20%20%20%20wrong_predictions%20%3D%20%5B%20pred%20for%20pred%20in%20predictions%20if%20pred%5B%22solution%22%5D%20!%3D%20pred%5B%22expected%22%5D%20%5D%0A%20%20%20%20%20%20%20%20feedback_futures%20%3D%20%5B%0A%20%20%20%20%20%20%20%20%20%20%20%20get_feedback(item)%20for%20item%20in%20wrong_predictions%0A%20%20%20%20%20%20%20%20%5D%0A%20%20%20%20%20%20%20%20feedback%20%3D%20%5B%20r%20for%20r%20in%20await%20asyncio.gather(*feedback_futures)%20%5D%0A%20%20%20%20%20%20%20%20new_instructions%20%3D%20aggregate_feedback(old_instructions%20%3D%20instruction%2C%20errors_made%3Dfeedback).new_instructions%0A%20%20%20%20%20%20%20%20_%20%3D%20await%20eval_instructed_solver(new_instructions%2C%20test_data%2C%20label%3D%22test%20accuracy%20(after%20update)%22)%0A%20%20%20%20%20%20%20%20mo.output.append(mo.md(f%22%23%23%23%20Feedback%5B0%5D%5Cn%5Cn%7Bfeedback%5B0%5D%7D%22))%0A%20%20%20%20%20%20%20%20mo.output.append(mo.md(f%22%23%23%23%20New%20Instructions%5Cn%5Cn%7Bnew_instructions%7D%22))%0A%20%20%20%20%20%20%20%20return%20new_instructions%0A%20%20%20%20return%20(train_step%2C)%0A%0A%0A%40app.cell(hide_code%3DTrue)%0Adef%20_(mo)%3A%0A%20%20%20%20mo.md(r%22%22%22We%20manually%20run%20several%20training%20steps%20below.%20We%20can%20experiment%20with%20different%20teacher%20models.%22%22%22)%0A%20%20%20%20return%0A%0A%0A%40app.cell%0Aasync%20def%20_(train_data%2C%20train_step)%3A%0A%20%20%20%20dir0%20%3D%20await%20train_step(%22Return%20just%20a%20number.%22%2C%20train_data%5B0%3A10%5D)%0A%20%20%20%20return%20(dir0%2C)%0A%0A%0A%40app.cell%0Aasync%20def%20_(dir0%2C%20train_data%2C%20train_step)%3A%0A%20%20%20%20dir1%20%3D%20await%20train_step(dir0%2C%20train_data%5B10%3A20%5D)%0A%20%20%20%20return%20(dir1%2C)%0A%0A%0A%40app.cell%0Aasync%20def%20_(dir1%2C%20train_data%2C%20train_step)%3A%0A%20%20%20%20dir2%20%3D%20await%20train_step(dir1%2C%20train_data%5B40%3A60%5D)%0A%20%20%20%20return%20(dir2%2C)%0A%0A%0A%40app.cell%0Aasync%20def%20_(dir2%2C%20train_data%2C%20train_step)%3A%0A%20%20%20%20dir3%20%3D%20await%20train_step(dir2%2C%20train_data%5B60%3A80%5D)%0A%20%20%20%20return%20(dir3%2C)%0A%0A%0A%40app.cell%0Aasync%20def%20_(dir3%2C%20train_data%2C%20train_step)%3A%0A%20%20%20%20dir4%20%3D%20await%20train_step(dir3%2C%20train_data%5B50%3A60%5D)%0A%20%20%20%20return%0A%0A%0A%40app.cell%0Adef%20_(mo)%3A%0A%20%20%20%20mo.md(r%22%22%22We%20seem%20to%20be%20overfitting.%20There%20are%20better%20algorithms%20than%20this%20trivial%20optimizer.%20See%20GEPA%20(%5BAgrawal%2C%20et%20al%202025%5D(https%3A%2F%2Farxiv.org%2Fabs%2F2507.19457))%20for%20an%20example.%22%22%22)%0A%20%20%20%20return%0A%0A%0Aif%20__name__%20%3D%3D%20%22__main__%22%3A%0A%20%20%20%20app.run()%0A
d5f033b21fd0b963c41c99494c44ef99d194950faafeeaa151d03c5d5e4964da