Sub topic 3
Refine: Carry a Running Summary Forward
Assume you know basic Python, can call an LLM, and understand tokens. Refine summarisation processes chunks in order. The model receives the summary so far and the next chunk, then rewrites the summary.
Refine summarisation
def refine_summary(chunks, call_llm):
summary = ""
for chunk in chunks:
if summary:
prompt = (
"Update the summary using the next document section. "
"Keep only source-supported facts and stay under 150 words.\n\n"
"Summary so far:\n" + summary +
"\n\nNext section:\n" + chunk
)
else:
prompt = (
"Summarise this document section in under 150 words. "
"Use only information in the section.\n\n" + chunk
)
summary = call_llm(prompt)
return summaryThis method preserves document order and needs little working memory. However, details from early chunks can disappear as later chunks replace the running summary. Each call also includes the previous summary, so the prompt grows slightly.
Hierarchical summarisation
For very long documents, group chunks into sections. Summarise each section, combine those summaries, and summarise the combined result again. This creates a hierarchy:
- Level 1: summarise paragraphs or pages.
- Level 2: summarise related section summaries.
- Level 3: produce the final summary.
Hierarchical processing handles more text than one model call, but information may be lost at every level.
Keeping summaries faithful
A faithful summary does not invent facts, change numbers, or claim that an implication was stated directly. Reduce errors by asking the model to use only the supplied text, preserve names and figures, and mark missing information as unknown. Keep source chunks and summaries so you can trace important claims back to their locations.
Evaluating summary quality
Use several checks rather than one score:
| Check | Question |
|---|---|
| Coverage | Are the main points included? |
| Faithfulness | Does each claim match the source? |
| Clarity | Can the intended reader understand it? |
Human review is useful for high-stakes text. Reference-based metrics compare against a trusted summary. An LLM judge can find omissions, but it may share the summariser's errors, so sample-based source checking remains important.
Cost and latency trade-offs
| Strategy | Calls | Main trade-off |
|---|---|---|
| Refine | One per chunk | Sequential and slower |
| Hierarchical | Several batches | More scalable, possible information loss |
Exercise
When is refine a poor choice?
Show answer
It is a poor choice when chunks are independent, parallel processing matters, or early details must remain equally visible throughout the summary.