Sub topic 2
Extractive and abstractive summaries
This chapter assumes you can write basic Python, have sent prompts to an LLM through an API or chat interface, and know roughly what a token is. It covers the two basic ways a summary can be built, and how to ask an LLM for each one.
Two ways to build a summary
An extractive summary is made of sentences or phrases copied unchanged from the source. An abstractive summary is written in new words. It may merge sentences, shorten them, or restate them.
Classic systems such as TextRank were extractive. They scored sentences and kept the top few. LLMs are naturally abstractive, because they generate text token by token. You can still push them toward extractive behaviour with the prompt.
| Property | Extractive | Abstractive |
|---|---|---|
| Wording | Copied from the source | Newly written |
| Fluency | Can read as choppy, with dangling references such as "he" or "this" | Usually smooth |
| Faithfulness risk | Low. Every word is in the source | Higher. The model can add or distort facts |
| Compression | Limited by sentence length | Can be much shorter |
| Verification | Search for the quote | Compare meaning, which is harder |
What each style looks like
Take this source passage:
The city council voted 7 to 2 on Tuesday to approve the new bus lane on Elm Street. Construction will begin in March and last about four months. Shop owners had argued that the lane would remove parking spaces, but the council said the change would cut commute times by roughly ten minutes.An extractive summary picks sentences:
The city council voted 7 to 2 on Tuesday to approve the new bus lane on Elm Street. Construction will begin in March and last about four months.An abstractive summary rewrites:
Despite shop owners' parking concerns, the council approved an Elm Street bus lane. Work starts in March and should take four months.The abstractive version is shorter and covers the objection. It also needed the model to judge what mattered and to compress it, and every such judgement can go wrong.
Asking an LLM for each style
The prompt controls the style. This script builds both prompts. Pass in any call_llm function that takes a prompt string and returns text.
SOURCE = (
"The city council voted 7 to 2 on Tuesday to approve the new bus lane "
"on Elm Street. Construction will begin in March and last about four "
"months. Shop owners had argued that the lane would remove parking "
"spaces, but the council said the change would cut commute times by "
"roughly ten minutes."
)
def extractive_prompt(text, n=2):
return (
f"Select the {n} most important sentences from the text below. "
"Copy them exactly, word for word, in their original order. "
"Do not change, add or merge any words.\n\n" + text
)
def abstractive_prompt(text):
return (
"Summarise the text below in two sentences, in your own words. "
"Use only information in the text.\n\n" + text
)
def quotes_are_exact(summary, source):
lines = [s.strip() for s in summary.split("\n") if s.strip()]
return all(line in source for line in lines)
if __name__ == "__main__":
print(extractive_prompt(SOURCE))
print()
print(abstractive_prompt(SOURCE))
print(quotes_are_exact("Construction will begin in March and last about four months.", SOURCE))
print(quotes_are_exact("Work starts in March.", SOURCE))The last two lines print True and False. This is the main practical benefit of extractive output: you can check it with a plain string comparison.
Common errors
- Assuming "extract" means the model complied. LLMs often paraphrase slightly even when told to copy. Check the output with a function like
quotes_are_exact, and retry or fall back if it fails. If the model returns sentences separated by something other than newlines, split them to match. - Losing context in extracts. A copied sentence that begins "However, this was rejected" is meaningless alone. Ask for the sentences that stand on their own, or use abstractive output.
- Trusting abstractive output because it reads well. Fluent text can still contain an invented number or a reversed cause. Later chapters cover faithfulness checks.
- Using one style for every job. Match the style to the purpose you set in the previous chapter.
A hybrid approach
Many pipelines combine the two. The model first extracts key sentences, then writes an abstractive summary from only those sentences. This shortens the input and anchors the final text to material you can inspect.
Exercise
A compliance team needs a summary of a contract in which each point can be traced to the exact clause. Which style fits better, and how would you verify the output automatically?
Show answer
Extractive. Ask the model to copy the key clauses word for word, then check that each returned line appears in the source text with a substring test such as line in source. Reject or retry any line that fails the test.
Exercise
Why is an abstractive summary usually shorter than an extractive one of equal coverage, and what is the cost of that advantage?
Show answer
The model can merge and restate ideas instead of keeping whole sentences, so it compresses more. The cost is a higher risk of unfaithful content, and checking it requires comparing meaning rather than matching text.