chapter eight

8 Summarization and more effective metric functions

 

This chapter covers

  • Using DSPy for text summarization
  • Creating more sophisticated metric functions
  • Lexical and semantic similarity
  • LLM-as-a-judge evaluation

To evaluate or optimize any DSPy programs we create, we must have metric functions that can reliably evaluate their output. So far, we’ve worked primarily with classification problems, which allow for fairly straightforward metric functions. Many other tasks required when working with language models (LMs) also use simple metric functions similar to these. For example, with entailment, as we saw in chapter 2, we test whether one piece of text follows logically from another. If the LM returns only a Boolean value indicating whether there’s logical entailment, the metric function can be very simple, just indicating whether the LM’s response is correct. This is often true for question answering as well, at least when working strictly with questions that have short answers, for example, “What is the capital of France?” But for many other LM-based tasks that we’ll likely need to handle, much more complicated metric functions will be necessary.

8.1 Summarization

8.1.1 Types of summarization

8.1.2 Evaluating summarization

8.2 The DialogSum dataset

8.3 Baseline summarizer

8.4 Evaluation by lexical similarity

8.4.1 Precision and recall

8.4.2 The F1 score

8.5 Evaluation using embeddings

8.6 Evaluation using LLM-as-a-judge

8.6.1 Metrics used with LLM-as-a-judge

8.6.2 Metric functions using LLM-as-a-judge

8.6.3 The volume of LM calls when using LLM-as-a-judge

8.6.4 Using LLM-as-a-judge with DSPy

8.6.5 Creating the datasets for the judge programs

8.6.6 Groundedness

8.6.7 Completeness

8.6.8 Testing both groundedness and completeness

8.6.9 Evaluation by Q&A

8.6.10 An example of creating and using a judge

Summary