liveBook · Manning

Evaluator

As explained in Building LLM Applications with DSPy

A language model assigned to assess the quality of responses produced by another language model.

An evaluator uses a language model to judge another model’s predictions. In DSPy, the judge can be called from a metric function and improved as a program through prompt optimization. section 8.6.2

Plan for the evaluator’s role and cost:

  • Use the judge during optimization and evaluation, not production; repeated candidate predictions can generate many judge calls. section 8.6.3
  • Select an appropriate judge model and optimize its instructions or demonstrations. Keep judge and summarizer data separate to avoid leakage. section 8.6.2
  • Early stopping or minibatches can reduce calls, but a capable judge may be expensive. section 8.6.3
Listing 8.14 DSPy metric function using LLM-as-a-judge
def evaluate_summary(example: dspy.Example, prediction: dspy.Prediction, trace=None):
    judge = dspy.Predict("ground_truth_summary, system_summary ->
                          summary_quality: float")
    return judge(
        ground_truth_summary=example.summary,
        system_summary=prediction.summary)

evaluate_summary(summarizer_train_data[0], pred)

See a DSPy metric function that asks a judge to score a predicted summary against a ground-truth summary. section 8.6.2

How Building LLM Applications with DSPy covers it

How deep it goes
Shows a DSPy metric implementation and judge optimization, while leaving model-call cost controls to early stopping or minibatches.
Examples
Scores a predicted summary against a ground-truth summary and estimates calls for optimizing candidate prompts.
What you can do after
Apply it via a DSPy metric function that calls a judge to assess model predictions.
How it connects
Connects evaluators to metric functions, DSPy programs, prompt optimization, and task language models.

Also explained in

Compare how 9 books explain evaluator →

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.