Sub topic 2
Extractive and abstractive summaries
This chapter assumes you can read basic Python, have sent prompts to an LLM through an API, and know roughly what a token is. It also assumes you have already fixed the purpose, audience and length of your summary, as covered in the previous chapter. Here you choose between the two basic ways a summary can be produced. That choice affects how faithful the summary is, how fluent it reads, and how you check it.
The two approaches
An extractive summary is built from pieces of the source text. The system selects sentences (or phrases) and returns them unchanged, usually in their original order.
An abstractive summary is newly written. The system reads the source and produces fresh sentences that express the main points. It can reword, merge, reorder and generalise.
Here is a short source passage:
The council voted 7 to 2 on Tuesday to approve the new bus lane. Construction will start in March and last about five months. Opponents argued that the lane removes 120 parking spaces. The council promised to review the effect on local shops after one year.An extractive summary of two sentences would be:
The council voted 7 to 2 on Tuesday to approve the new bus lane. The council promised to review the effect on local shops after one year.An abstractive summary might be:
The council approved the bus lane by a wide margin despite parking concerns, with a shop-impact review due in a year.The abstractive version is shorter and reads better. It also contains the judgments "by a wide margin" and "despite parking concerns", which the source never states in those words. That gap between fluency and traceability runs through the rest of this chapter.
What each approach is good and bad at
| Property | Extractive | Abstractive |
|---|---|---|
| Wording | Copied from the source | Newly written |
| Hallucination risk | Very low. Every sentence exists in the source. | Real. The model can add, distort or invent. |
| Fluency | Often choppy | Usually smooth |
| Compression | Limited by sentence length | High. Many sentences become one. |
| Context | Can lose it ("He rejected this." Who? What?) | Can restate context so the summary stands alone |
| Redundancy | Selected sentences may repeat each other | The model can merge duplicates |
| Auditing | Easy. Point to the original sentence. | Harder. You must compare meaning. |
| Typical tool | Scoring rules, embeddings, or an LLM that picks sentences | An LLM prompted to write |
Extractive summaries fail in a few predictable ways:
- Dangling references. A sentence such as "This caused the delay" is selected without the sentence that explains "this".
- Lead bias. Simple scorers favour sentences near the start of the document, which is fine for news and poor for reports that put conclusions last.
- Redundancy. Two high-scoring sentences can say nearly the same thing.
- Missing synthesis. If the main point appears only across several sentences, no single sentence carries it.
Abstractive summaries fail differently, and the failures are harder to spot:
- Invented details, such as a date or name that is not in the source.
- Distorted numbers, for example "7 to 2" becoming "unanimous".
- Flipped or dropped negation, such as "did not find evidence" becoming "found evidence".
- Over-generalisation, where "two of the five trials" becomes "the trials".
- Prior-knowledge leakage, where the model adds facts it knows from training but that the document does not contain.
Modern LLMs are abstractive by default. If you ask for a summary, you get a rewrite. You have to ask for extraction explicitly, and you should verify that the model did it.
A simple extractive summariser in Python
You do not need an LLM to extract. The scorer below ranks sentences by how many frequent content words they contain, then returns the top sentences in their original order. It is a baseline, not a state-of-the-art method, but it shows the mechanism and costs nothing per call.
import re
from collections import Counter
STOPWORDS = {
'the', 'a', 'an', 'and', 'or', 'but', 'of', 'to', 'in', 'on', 'for',
'with', 'is', 'are', 'was', 'were', 'be', 'by', 'that', 'this', 'it',
'as', 'at', 'from', 'will', 'has', 'have', 'had', 'its', 'their',
}
def split_sentences(text):
parts = re.split(r'(?<=[.!?])\s+', text.strip())
return [p.strip() for p in parts if p.strip()]
def content_words(sentence):
words = re.findall(r"[a-z']+", sentence.lower())
return [w for w in words if w not in STOPWORDS]
def extractive_summary(text, n=2):
sentences = split_sentences(text)
freq = Counter(w for s in sentences for w in content_words(s))
scores = []
for s in sentences:
words = content_words(s)
scores.append(sum(freq[w] for w in words) / (len(words) or 1))
ranked = sorted(range(len(sentences)), key=lambda i: scores[i], reverse=True)
chosen = sorted(ranked[:n]) # restore document order
return ' '.join(sentences[i] for i in chosen)
if __name__ == '__main__':
text = (
'The council voted 7 to 2 on Tuesday to approve the new bus lane. '
'Construction will start in March and last about five months. '
'Opponents argued that the lane removes 120 parking spaces. '
'The council promised to review the effect on local shops after one year.'
)
print(extractive_summary(text, n=2))Two details matter. Dividing the score by the sentence's word count stops long sentences winning just because they are long. Sorting the chosen indices restores document order, which keeps the output readable. The regex sentence splitter will break on abbreviations such as "Dr. Smith", so for real documents use a proper sentence tokenizer.
Extraction with an LLM
An LLM can do better than word counts because it judges importance by meaning. The risk is that the model rewrites the sentences while claiming to quote them. A safer pattern is to number the sentences and have the model return only the numbers. Your code then looks up the original text, so the output cannot contain words that were not in the source.
This block reuses split_sentences from the previous one. call_llm is any function that takes a prompt string and returns the model's text.
import json
def llm_extract(text, call_llm, n=3):
sentences = split_sentences(text)
numbered = '\n'.join(f'[{i}] {s}' for i, s in enumerate(sentences))
prompt = (
f'Below are numbered sentences from a document. Choose the {n} sentences '
'that best capture the main points. Reply with only a JSON list of '
'sentence numbers, for example [0, 4, 7]. Do not add any other text.\n\n'
+ numbered
)
reply = call_llm(prompt)
try:
picked = json.loads(reply)
except json.JSONDecodeError:
raise ValueError('Model did not return a JSON list: ' + reply[:100])
if not isinstance(picked, list) or not all(isinstance(i, int) for i in picked):
raise ValueError('Expected a list of integers')
valid = sorted({i for i in picked if 0 <= i < len(sentences)})
return ' '.join(sentences[i] for i in valid)The code validates the reply because models sometimes wrap JSON in prose or return out-of-range numbers. It also removes duplicates and sorts the indices, so the result stays in document order. In production you would retry once on a parse failure instead of raising immediately.
Prompting for abstractive output
Abstractive summaries are the default, but the prompt decides how much freedom the model has. Compare these two instructions:
loose_prompt = 'Summarise this document.\n\n'
strict_prompt = (
'Write a summary of the document below in at most 3 sentences. '
'Use only information stated in the document. '
'Do not add background knowledge, opinions or numbers that are not in the text. '
'Keep every number and name exactly as written. '
'If the document does not say something, do not guess.\n\n'
)The strict version does not remove hallucination, but it narrows the model's room to improvise and gives you a clear rule to check against. The Faithfulness chapter returns to this with verification steps.
Combining the two: extract, then abstract
The approaches work well together, and the combination matters for long documents. A common pipeline is:
- Extract the key sentences from each chunk, or from the whole document.
- Give only those sentences to the model and ask it to write a coherent summary.
This shrinks the input before the expensive abstractive step. It also anchors the model to sentences that really exist. The cost is that anything the extraction step missed is gone for good, and the abstractive step can still distort what it receives.
Choosing in practice
Use these criteria rather than a default:
- Legal, medical, compliance or audit material. Prefer extractive, or abstractive with quoted evidence for each claim. A wrong paraphrase costs more than a choppy summary.
- Briefings, newsletters, executive summaries. Prefer abstractive, because readers expect smooth prose and a single reader-facing voice.
- Search results and previews. Extractive snippets are cheap, fast and predictable.
- Very large collections. An inexpensive extractive pass can cut volume before any LLM call, which helps with the cost trade-offs covered later.
- Mixed needs. Produce an abstractive summary and attach the extracted source sentences as supporting evidence, so a reader can check any claim.
You should also check which kind of output you actually got. If you asked for extraction through an LLM, confirm that each returned sentence appears verbatim in the source. A one-line check such as all(s in text for s in returned_sentences) catches most silent rewrites. For an abstractive summary no such exact check exists, which is why it needs the evaluation methods covered in later chapters.
Exercise
You summarise customer contracts for a legal team, and a reviewer must be able to find the source of every statement in the summary. Which approach do you choose, and what check can you automate if an LLM does the selecting?
Show answer
Choose extractive summarisation, because every sentence in the output exists in the source. Have the LLM return sentence numbers (as in llmextract) rather than text, so your code copies the original sentences. As a second check, confirm that each returned sentence appears verbatim in the contract text, for example with all(s in contracttext for s in returned_sentences). Any sentence that fails the check means the output was rewritten and should be rejected or retried.
Exercise
A source says: "The trial found no significant improvement in two of the three groups." An abstractive summary says: "The trial found significant improvement." Name two failure types from this chapter that the summary shows.
Show answer
Over-generalisation ("two of the three groups" became "the trial") and flipped negation ("no significant improvement" became "significant improvement"). Neither would occur in an extractive summary that copied the original sentence.