liveBook · Manning

Crossover

As explained in Building LLM Applications with DSPy

Crossover is an optimization operation that combines parts or information from candidate solutions to produce a new candidate.

Crossover combines two or more candidate prompts to create a new prompt for evaluation. In genetic algorithms, it is commonly paired with mutation; GEPA performs one of these operations at a time. section 6.5.1

Candidates for crossover are selected from a pool. In GEPA, that pool is the Pareto front: prompts that score highest on at least one validation example. section 6.5.2

Figure 6.4 The first four steps in generating and evaluating candidate prompts in the GEPA optimizer. The nodes indicate single prompts. Those in gray are in the Pareto front and may be used to create subsequent candidate prompts. After step 1, we have a single prompt, which is the prompt related to the DSPy program passed to the GEPA optimizer. In step 2, we mutate this prompt, creating Prompt 2, and evaluate it on the validation set. As long as this prompt is the top-performing prompt on at least one example in the validation set, it becomes part of the Pareto front. In step 3, we can either mutate or combine prompts from the Pareto front. In this case, we combine Prompts 1 and 2, creating Prompt 3. This prompt is the top-scoring prompt on at least one example, so it enters the Pareto front, but Prompt 1 is no longer part of the Pareto front. In step 4, we can again either mutate or combine elements of the Pareto front. In this case, we mutate Prompt 3, creating Prompt 4, which also becomes part of the Pareto front.
figure

The figure traces candidate prompts through mutation and crossover, showing how combining two prompts creates a new candidate that is evaluated. section 6.5.2

How Building LLM Applications with DSPy covers it

How deep it goes
Explains candidate selection and evaluation, but does not specify how prompt content is merged.
Examples
Combines Prompts 1 and 2 to create Prompt 3, then evaluates it on validation examples.
What it assumes
Assumes candidate prompts and validation scores for selecting prompts to combine.
What you can do after
Apply crossover by combining selected candidate prompts and evaluating the resulting prompt.
How it connects
Connects crossover to genetic algorithms, mutation, GEPA, and the Pareto front.

Also explained in

Compare how 7 books explain crossover →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Building LLM Applications with DSPy. The section links point to the parts of the book it draws on.