Overview

8 Summarization and more effective metric functions

The chapter explains that summarization is a useful but difficult LM task to evaluate because quality depends on more than exact wording. A good summary must preserve the important ideas, avoid hallucinations, stay concise, and remain readable. DSPy helps by providing a framework for building both summarizers and the metric functions needed to optimize them, but the user still has to choose what “good” means for the task.

It first contrasts extractive and abstractive summarization, then shows how labeled and unlabeled data can be used for evaluation. With labeled examples, the chapter explores lexical metrics such as Jaccard similarity, n-gram overlap, precision, recall, and F1, while noting their limits with paraphrases and meaning changes. It then moves to semantic evaluation with embeddings, which compare meaning more directly but can be harder to interpret.

The chapter’s larger theme is that LLM-based judging can be the most flexible approach for summarization. It demonstrates judges for groundedness and completeness, and shows how multiple criteria can be combined into a single metric, including Q&A-style evaluation tailored to specific requirements like salience and named entities. By building, testing, and optimizing these judges separately from the summarizer, DSPy supports a practical workflow for improving summary quality and making evaluation more aligned with real application goals.

Summary

  • There are two main types of summaries: extractive summaries based on quotes, and abstractive summaries that capture the main ideas, but may use different words or phrases.
  • Like many other LM-based tasks, summaries are difficult to evaluate.
  • To develop effective LM-based applications, it’s necessary to develop some meaningful way to evaluate the LM responses.
  • When ground truth summaries are available, we can evaluate how similar the LM’s summaries are to the ground truth using lexical comparisons, embeddings, or LLM as a Judge-based methods.
  • Lexical methods look at how similar the words or n-grams are between the two summaries.
  • Lexical methods can struggle to evaluate summaries well, but they are very efficient and useful where they are sufficient.
  • Using LLM as a Judge allows us to evaluate summaries when we don't have labeled data.
  • Using LLM as a Judge with DSPy, we create DSPy programs to evaluate LM responses and execute them from within the DSPy metric functions.
  • These judge programs can themselves be evaluated and optimized.
  • To evaluate and optimize the judges, we should create a dataset that includes both good and poor responses.
  • Using LLM as a Judge methods allows us to specify exactly how to evaluate the summary.
  • Common measures include groundedness, completeness, readability, and conciseness.
  • We may also check semantic precision and recall. Although similar to lexical precision and recall, semantic precision and recall check for matching ideas, as opposed to words or n-grams.
  • We can create specific judges to evaluate each of these individual concerns or create a single judge with many output fields that checks each of the relevant concerns.
  • QA-based methods allow us to enumerate exactly what we want to evaluate.

FAQ

What makes summarization harder to evaluate than classification?Summarization is harder to evaluate because there is usually no single exact answer. A good summary must balance correctness, relevance, completeness, brevity, readability, and wording. Unlike classification, a summary can be good even if it is phrased differently from the reference.
What is the difference between extractive and abstractive summarization?Extractive summarization selects passages directly from the source text and combines them into a summary. Abstractive summarization lets the LM generate a new summary in its own words, without copying source text. Abstractive summaries are usually more readable, while extractive summaries are easier to evaluate lexically.
Can DSPy evaluate summarization without ground truth summaries?Yes. DSPy can work with unlabeled examples that contain only the input text. In that case, evaluation usually relies on LLM-as-a-judge methods, comparing the generated summary directly against the source document rather than a reference summary.
Why are lexical metrics limited for summarization?Lexical metrics only compare word overlap or n-gram overlap. They can miss summaries that are semantically correct but use different wording, and they can incorrectly reward summaries that share many words but have the wrong meaning. They work better for extractive summaries than abstractive ones.
What is Jaccard similarity in this chapter?Jaccard similarity measures overlap between two sets of words or n-grams: intersection divided by union. In summarization, it provides a simple lexical score for comparing a generated summary to a reference summary.
Why are precision and recall both useful for summary evaluation?Precision measures how much of the generated summary matches the reference, while recall measures how much of the reference is covered by the generated summary. A good summary should usually be high on both, so combining them helps capture balance between over-generating and omitting important content.
What does the F1 score tell us about a summary?F1 is the harmonic mean of precision and recall, so it rewards summaries that are balanced on both. It is lower when either precision or recall is weak, which makes it useful for summary evaluation when you want both coverage and fidelity.
Why use embeddings to compare summaries?Embeddings allow semantic comparison rather than exact word matching. Two summaries can be scored as similar even if they use different vocabulary, as long as they express similar meaning. This is especially useful for abstractive summaries.
What is LLM-as-a-Judge evaluation?LLM-as-a-Judge uses one LM to score or compare the output of another LM. For summarization, the judge can evaluate criteria such as groundedness, completeness, salience, clarity, or conciseness. It is flexible because the prompt can explicitly define what should matter.
What are groundedness and completeness in summarization metrics?Groundedness checks whether the claims in the summary are supported by the original document, similar to precision against the source. Completeness checks whether the important ideas in the source are covered by the summary, similar to recall. Together, they give a strong view of summary quality.

pro $24.99 per month

  • access to all Manning books, MEAPs, liveVideos, liveProjects, and audiobooks!
  • choose one free eBook per month to keep
  • exclusive 50% discount on all purchases
  • renews monthly, pause or cancel renewal anytime

lite $19.99 per month

  • access to all Manning books, including MEAPs!

team

5, 10 or 20 seats+ for your team - learn more


choose your plan

team

monthly
annual
$49.99
$499.99
only $41.67 per month
  • five seats for your team
  • access to all Manning books, MEAPs, liveVideos, liveProjects, and audiobooks!
  • choose another free product every time you renew
  • choose twelve free products per year
  • exclusive 50% discount on all purchases
  • renews monthly, pause or cancel renewal anytime
  • renews annually, pause or cancel renewal anytime
  • Building LLM Applications with DSPy ebook for free
choose your plan

team

monthly
annual
$49.99
$499.99
only $41.67 per month
  • five seats for your team
  • access to all Manning books, MEAPs, liveVideos, liveProjects, and audiobooks!
  • choose another free product every time you renew
  • choose twelve free products per year
  • exclusive 50% discount on all purchases
  • renews monthly, pause or cancel renewal anytime
  • renews annually, pause or cancel renewal anytime
  • Building LLM Applications with DSPy ebook for free
choose your plan

team

monthly
annual
$49.99
$499.99
only $41.67 per month
  • five seats for your team
  • access to all Manning books, MEAPs, liveVideos, liveProjects, and audiobooks!
  • choose another free product every time you renew
  • choose twelve free products per year
  • exclusive 50% discount on all purchases
  • renews monthly, pause or cancel renewal anytime
  • renews annually, pause or cancel renewal anytime
  • Building LLM Applications with DSPy ebook for free