liveBook · Manning

Chapter 8: Summarization and more effective metric functions

What you will learn in chapter 8 of Building LLM Applications with DSPy

This introduction explains why evaluating open-ended LM outputs, especially summaries, requires more sophisticated metric functions than evaluating simple classification-style answers.

After this chapter you will be able to

What it builds on

Section by section

Introduction

This introduction explains why evaluating open-ended LM outputs, especially summaries, requires more sophisticated metric functions than evaluating simple classification-style answers.

Key terms: metric functions, text summarization, entailment, open-ended question answering, accuracy, relevance, completeness, wording, numeric score

8.1 Summarization

This section explains why judging a document summary requires balancing several qualities, while affirming that meaningful evaluation is possible.

Key terms: document summary, important content, level of detail

8.1.1 Types of summarization

This section distinguishes extractive from abstractive summarization and explains their different readability and accuracy challenges.

Key terms: extractive summarization, abstractive summarization, relevant passages, coherent, readable, accuracy, large LMs

8.1.2 Evaluating summarization

This section explains how to choose and assess summary-evaluation methods, including when examples have no ground truth summary.

Key terms: ground truth summaries, unlabeled data, LLM-as-a-judge, metric function, lexical evaluations, embeddings, lexical comparison, extractive summaries, abstractive summaries, text embeddings

8.2 The DialogSum dataset

The section introduces DialogSum’s human-written conversation summaries and prepares separate datasets for optimizing and evaluating a summarizer.

Key terms: DialogSum, salient information, named entities, observer perspective, abstractive, dialogue, summary, train set, validation set, test set

8.3 Baseline summarizer

The section builds a minimal DSPy dialog summarizer, considers adding annotation instructions, and checks its output against one ground-truth summary.

Key terms: baseline model, signature, Predict, gpt-4.1-nano, annotators, ground truth summaries, docstring, ground truth summary, LM’s summary

8.4 Evaluation by lexical similarity

The section explains how to evaluate generated summaries by comparing their wording with provided summaries, using Jaccard similarity and n-grams.

Key terms: lexical metric function, Jaccard similarity score, provided summaries, n-grams, 2-grams, word level

8.4.1 Precision and recall

This section defines word-overlap precision and recall for summaries, explains one way to combine them, and identifies limits of unique-word comparisons.

Key terms: precision, recall, LM’s summary, ground truth summary, average, minimum, Jaccard similarity, unique words, word order, n-grams

8.4.2 The F1 score

This section explains how F1 combines precision and recall, how DSPy normalizes text before calculating it, and how to evaluate a summarizer across a test set.

Key terms: F1 score, harmonic mean, precision, recall, f1_score, normalize_text(), normalizing text, DSPy’s evaluation framework, prog_summarizer, test set

8.5 Evaluation using embeddings

This section explains how to evaluate summaries by comparing their embeddings, how to interpret similarity scores, and why those scores can be hard to diagnose.

Key terms: semantic similarity, embedder, embedding, ground truth summary, cosine similarity, metric function, embeddings, similarity metrics, tone, writing style

8.6 Evaluation using LLM-as-a-judge

Introduces the upcoming discussion of LLM-as-a-judge evaluation with and without reference text.

8.6.1 Metrics used with LLM-as-a-judge

The section explains how to choose and organize LLM-as-a-judge metrics for summaries, including semantic precision and recall, groundedness, and completeness.

Key terms: LLM-as-a-judge, judge LM, output fields, semantic precision and recall, lexical precision and recall, SemanticF1, question, response, groundedness, precision

8.6.2 Metric functions using LLM-as-a-judge

The section explains how DSPy can use an LM-powered judge inside a metric function and how that judge can be optimized without leaking evaluation data.

Key terms: LLM-as-a-judge, metric function, prediction, Predict, signature, judge LM, task LM, prompt LM, demos, training and validation data

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

This section shows how LLM-as-a-judge multiplies LM calls during prompt optimization and why that cost must be weighed against potential production gains.

Key terms: prompt LM, task LM, judge LM, validation set, early stopping, minibatches, optimization, evaluation, production

8.6.4 Using LLM-as-a-judge with DSPy

The section lays out a two-part DSPy workflow: calibrate an LLM judge against known scores, then use that judge to evaluate and optimize a summarizer.

Key terms: DSPy programs, judges, metric, groundedness, ground truth score, training data, validation data, holdout test set, well calibrated, groundedness judge

8.6.5 Creating the datasets for the judge programs

This section explains how to build labeled datasets for summary-judging programs, including good and bad examples and different treatment of training versus evaluation data.

Key terms: judge, dialog, summary, 0.0, 1.0, ground truth summaries, true_score, good summaries, bad responses, training

8.6.6 Groundedness

This section creates a DSPy judge for how well a summary is grounded in its original document, then tests and evaluates the judge.

Key terms: groundedness, judge program, original document, judge_val_data, ground truth summaries, groundedness score, groundedness metric function, true score, predicted score, higher-is-better

8.6.7 Completeness

This section introduces a DSPy judge for summary completeness and explains how to interpret and validate its initial output.

Key terms: completeness, signature, completeness_predictor, discussion, completeness scores, full validation set, well calibrated

8.6.8 Testing both groundedness and completeness

The section shows how to combine groundedness and completeness scores to evaluate summaries, and how a custom module can make that combined evaluation optimizable.

Key terms: groundedness, completeness, simple average, validation set, custom module, submodules, f1_score, LM, optimized

8.6.9 Evaluation by Q&A

This section presents question-and-answer evaluation as a way to judge whether a summary covers expected content.

Key terms: Q&A-based evaluation, predefined questions, metric function, judge programs, Q&A-based methods, content, style

8.6.10 An example of creating and using a judge

This section builds a Q&A-based summary judge, validates and optimizes it, then uses it as a metric for a baseline summarizer.

Key terms: Q&A, judge, ground truth summaries, salience, named entities, qa_judge_metric, judge_val_data, SIMBA, feedback, hold-out test set

8.7 Summary

Where this is used later

Concepts explained in this chapter

← Chapter 7: Custom modules Chapter 9: Creating an agentic RAG-based chatbot →

These guides are generated from the text of Manning books by Manning's knowledge graph and link to the sections they draw on. The full books are available on liveBook and at manning.com.