Stop 09 · Natural Language ProcessingTopics · 9/10

Text Summarization

Part of the AI Engineer Roadmap

In short

Long reports, legal documents and lecture transcripts pile up faster than anyone can read. Summarisation models turn pages into a few lines, and knowing their limits matters as much as using them.

Generating a shorter version of a text that preserves key information — extractive (selecting sentences) vs. abstractive (generating new text) approaches.

The blob holds a long unrolled film reel and squeezes it into a small neat bundle.

Think of it like this

The friend who saw the movie

Your friend watched a three-hour film and tells you the story in three lines. One friend just repeats the best dialogues word for word. Another retells it in her own words. That's extractive vs abstractive summarisation.

Watch it happen

Two ways to summarise

Extractive

  • Picks the most important sentences
  • Copies them word for word
  • Never invents facts, can feel choppy

Abstractive

  • Writes new sentences
  • Reads naturally, like a person
  • Can hallucinate details not in the text

Abstractive models like BART, T5 and LLMs give nicer summaries. For legal or medical text, check facts against the source or use extractive methods.

The big ideas

What you need to know

Encoder-decoder models

BART and T5 read the whole input with an encoder, then a decoder writes the summary word by word.

Input length limits

BART reads about 1,024 tokens at a time. Longer documents must be chunked and summarised in parts.

Hallucinations

Abstractive models sometimes add names, numbers or claims that aren't in the source. Always spot-check.

ROUGE measures overlap

ROUGE compares word overlap with a reference summary. Useful for comparing models, but it can't judge factual accuracy.

See it in code

Walk through the code

python
1from transformers import pipeline2 3summarizer = pipeline("summarization", model="facebook/bart-large-cnn")4 5article = """The college canteen will now stay open until 11 pm during exam weeks.6The student council asked for longer hours after many hostel students said7they had nowhere to eat while studying late. The canteen will serve a smaller8menu after 8 pm, mainly tea, sandwiches and instant noodles."""9 10summary = summarizer(article, max_length=40, min_length=10, do_sample=False)11print(summary[0]["summary_text"])

1/3Load BART fine-tuned on CNN/DailyMail news summaries. It's large, so the first download takes a while.

BART fine-tuned on news articles. max_length and min_length are measured in tokens, not words.

Save yourself the pain

Common mistakes

Oops

Feeding a 30-page PDF straight into a summarisation model.

Do this instead

The model silently truncates long input. Split it into chunks, summarise each, then summarise the summaries.

Oops

Publishing abstractive summaries without checking numbers and names.

Do this instead

Compare key facts against the source, or highlight sentences in the source that support each line.

Your mission

Summarise and fact-check

~25 min

Quick check

What's the main risk of abstractive summarisation compared to extractive?

Go deeper

  1. 1Use a pretrained summarization model (e.g. BART, T5) via Hugging Face.
  2. 2Compare extractive vs. abstractive summaries on the same document.
  3. 3Evaluate summaries with ROUGE and understand its limitations.

More topics at this stop

Stuck on this topic? Ask an Insider

Get 1:1 guidance from people who've walked this exact path — on the InsideEdge app.

Download
InsideEdge