How to Build a Text Summarisation Tool: Models, Prompts and Evaluation
Build a text summarisation tool from scratch: pick extractive or abstractive models, write prompts, then evaluate with ROUGE. A practical developer guide.
By Galactic News Editorial · Published 2026-11-28T04:41:00+00:00 · Updated 2026-11-28T04:41:00+00:00
How to Build a Text Summarisation Tool: Models, Prompts and Evaluation
To build a text summarisation tool, pick an extractive or abstractive approach, wire up a model or prompt, then score the output with ROUGE against human references. This guide walks through both approaches in Python, from a first working summariser to a tested, deployable tool.
Extractive vs abstractive: pick your approach first
Summarisation has two families. Extractive methods pick the best sentences from the source and return them unchanged. Abstractive methods write new sentences that restate the content.
Extractive output is always grammatical because it is lifted verbatim. It stays faithful to the source and needs no neural network. Its weakness is coverage: key facts spread across the document can be missed, and the result can read like a list of fragments.
Abstractive output is fluent and compact. A transformer reads the document and generates a short version in new words. Its weakness is hallucination: the model can invent facts that were not in the source. It also needs more compute and more care in testing.
| Aspect | Extractive | Abstractive |
|---|---|---|
| Method | Score sentences, return the top ones | Generate new text with a transformer |
| Faithfulness | High; words come from the source | Lower; model can invent details |
| Fluency | Choppy; sentences were not written together | Fluent; reads like a human summary |
| Compute | Light; runs on CPU | Heavy; needs a GPU for large models |
| Best for | Legal, medical and compliance text | News, articles and general reading |
Start with extractive if accuracy matters most. Start with abstractive if readability matters most. Many production tools run both and let the user choose.
How to build a text summarisation tool in 6 steps
Step 1: Build the extractive version with TF-IDF
The simplest extractive summariser scores sentences with TF-IDF. A word counts more when it is frequent in a sentence but rare in the others. Keep the top sentences and restore their original order.
import re
from sklearn.feature_extraction.text import TfidfVectorizer
def summarize(text, k=3):
sentences = re.split(r'(?<=[.!?])\s+', text.strip())
tfidf = TfidfVectorizer().fit_transform(sentences)
scores = tfidf.sum(axis=1).A1
top = sorted(scores.argsort()[-k:])
return ' '.join(sentences[i] for i in top)TextRank is a stronger option. It treats sentences as nodes in a graph and scores them by how connected they are to everything else. The canonical implementation comes from Mihalcea and Tarau (2004). It costs little more than TF-IDF and usually picks better sentences.
Step 2: Build the abstractive version with BART
For abstractive summaries, use a pre-trained transformer. BART-large-CNN is a standard starting point. It is a transformer encoder-decoder model fine-tuned on the CNN/DailyMail corpus of news articles and summaries. It produces news-style summaries out of the box.
from transformers import pipeline
summarizer = pipeline("summarization", model="facebook/bart-large-cnn")
summary = summarizer(article, max_length=130, min_length=30, do_sample=False)
print(summary[0]['summary_text'])Control length with max_length and min_length. Set do_sample=False for deterministic output. Long documents need chunking: split the text, summarise each chunk, then summarise the combined chunk summaries.
Other models suit other domains. PEGASUS uses a gap-sentence pre-training objective that works well for summarisation without much fine-tuning. T5 handles many text tasks with a single model. Pick the model that matches your text type, not the one with the highest score on a news benchmark.
Step 3: Design prompts for LLM-based summarisation
If you use a large language model instead of a fine-tuned model, the prompt is the product. Write it with care.
State the audience and the length first. Ask for the key facts, the main argument and any numbers. Tell the model what to leave out. Add a rule against adding facts not present in the source. Ask for bullet points when the user wants a scan, and prose when they want to read.
A useful template looks like this: summarise the text below in about 120 words. Keep all names, dates and numbers exactly as written. Do not add information from outside the text. End with the single most important point.
Test the prompt on hard cases: long documents, texts with numbers and texts where the key point sits at the end. Prompts that work on short news articles often fail on long reports.
Step 4: Evaluate with ROUGE
ROUGE is the standard automatic metric for summarisation. It measures overlap between your summary and a human-written reference. ROUGE-1 counts unigram overlap. ROUGE-2 counts bigram overlap. ROUGE-L scores the longest common subsequence. Report all three.
from rouge_score import rouge_scorer
scorer = rouge_scorer.RougeScorer(['rouge1', 'rouge2', 'rougeL'], use_stemmer=True)
scores = scorer.score(reference_summary, generated_summary)
print(scores)ROUGE has limits. It rewards word overlap, not meaning. A good paraphrase can score badly. A bad summary that copies the right words can score well. Use ROUGE to compare models on the same data. Use human review to judge real quality.
Build a small test set first. Collect 20 to 50 documents with human-written summaries. Run every model and prompt change against it. Track ROUGE scores and keep the best version. Without a fixed test set, you cannot tell whether a change helped.
Step 5: Add human checks for factual accuracy
Automatic metrics cannot catch invented facts. Add a human review step for abstractive output. Check names, dates, numbers and quotes against the source. Flag any claim that does not appear in the original text.
A simple check works well: list the key facts in the summary and verify each one in the source. If a fact cannot be found, the summary fails. This takes a minute per document and catches the errors that damage trust.
Step 6: Ship the tool as a service
Wrap the summariser in a small API. Accept text and a target length. Return the summary and the model used. Add a length limit on input so one huge document cannot stall the service. Queue long jobs instead of blocking the request.
Log every request with its input length, model and output length. That log becomes your evaluation data over time. Review a sample of real outputs each week. Real user text always differs from your test set.
Common mistakes to avoid
- Trusting ROUGE alone. Pair it with human review on every release.
- Feeding whole books to the model. Chunk long text first, or the model will drop the middle.
- Ignoring the domain. A news model summarises legal text badly. Match the model to the text.
- No length control. Set max and min length. Unbounded output drifts.
- Skipping the test set. Without fixed references, every change is a guess.
Bottom line
Start with an extractive summariser for safe, faithful output. Add BART or an LLM prompt when you need fluent summaries. Evaluate with ROUGE on a fixed test set and check facts by hand. That combination ships a summarisation tool you can trust.