Sub topic 12
Evaluating summary quality
This chapter assumes you can call an LLM from Python, know what tokens are, and have built a summariser with one of the strategies from earlier chapters. Here you will learn how to tell whether a summary is any good.
Why evaluation is hard
A document has many valid summaries. Two good summaries can share few words. A bad summary can look fluent. So no single score settles the question. In practice you combine three methods: human review, reference-based metrics, and LLM-based judging.
What to measure
Pick criteria that match the goal you set at the start of the tutorial. Four are common:
- Faithfulness: every claim is supported by the source.
- Coverage: the main points of the source appear.
- Concision: the length fits the brief, with no repetition.
- Fluency: the text reads cleanly.
Faithfulness and coverage matter most. A summary can be faithful but miss the key point. It can also cover the key point and invent a detail.
Human review
Human review is the most trusted method and the slowest. Give reviewers a short rubric, and score each criterion from 1 to 5. Use a small, fixed sample of documents, perhaps 20 to 50, and keep it unchanged between runs. Then you can compare versions of your summariser fairly.
Have two people score the same items when you can. If they often disagree, your rubric is unclear.
Reference-based metrics
If you have human-written reference summaries, you can compare the model output against them. ROUGE counts overlapping words and word sequences. BERTScore compares meaning using embeddings, so it handles paraphrase better.
These metrics are cheap and repeatable. They also have limits. A good abstractive summary that rewords the source can score low on ROUGE. A summary that copies the right words but gets a fact wrong can score high. Use them to spot large changes between versions, not to judge a single summary.
def rouge1_f(candidate, reference):
cand = candidate.lower().split()
ref = reference.lower().split()
if not cand or not ref:
return 0.0
ref_counts = {}
for w in ref:
ref_counts[w] = ref_counts.get(w, 0) + 1
overlap = 0
for w in cand:
if ref_counts.get(w, 0) > 0:
overlap += 1
ref_counts[w] -= 1
if overlap == 0:
return 0.0
precision = overlap / len(cand)
recall = overlap / len(ref)
return 2 * precision * recall / (precision + recall)
print(rouge1_f("the cat sat on the mat", "a cat sat on a mat"))This prints about 0.67. Four of six words match. For real work, use a maintained library such as rouge-score, which handles tokenising and stemming.
LLM-based judging
When you have no references, ask a second model to score the summary against the source. This scales well and catches faithfulness problems that word overlap misses.
import json
def judge(source, summary, call_llm):
prompt = (
'You are grading a summary against its source.\n'
'Score each criterion from 1 to 5: faithfulness, coverage, concision.\n'
'List any claim in the summary that the source does not support.\n'
'Reply with JSON only, using the keys faithfulness, coverage, '
'concision and unsupported_claims.\n\n'
'SOURCE:\n' + source + '\n\nSUMMARY:\n' + summary
)
return json.loads(call_llm(prompt))Judges have known biases. They tend to prefer longer text and their own style of writing. They can also miss subtle errors. Reduce the risk in three ways:
- Score one criterion at a time, or ask for evidence for each score.
- Use a different model from the one that wrote the summary.
- Check the judge against your human scores on a sample. If they disagree often, do not trust the judge yet.
For long sources, the judge faces the same long-context limits as your summariser. Judge each section against its own partial summary when the whole document does not fit.
Common errors
- Relying on one metric. ROUGE alone rewards copying.
- Changing the test set between runs, so scores are not comparable.
- Trusting a judge that was never checked against human scores.
- Measuring only fluency. Fluent summaries hide invented facts.
- Ignoring variance. Run the model several times, because one lucky output proves little.
Exercise
Your new prompt raises ROUGE-1 by 5 points, but a reviewer finds two invented figures in a sample of ten summaries. What should you conclude, and what do you do next?
Show answer
ROUGE measures word overlap, not truth, so it cannot show that the summaries are faithful. The invented figures mean faithfulness got worse or was never good. Treat the human finding as the stronger evidence. Add a faithfulness check, such as an LLM judge that lists unsupported claims, run it on the full test set, and tighten the prompt with "use only information in the text" before shipping.
Exercise
Why should you compare an LLM judge's scores with human scores before relying on it?
Show answer
Judges have biases, such as favouring longer text, and can miss subtle errors. If the judge's scores rarely match human scores on a sample, its scores on other documents are not reliable.