Stop 09 · Natural Language ProcessingProjects · 2/2

Text Summarizer

Part of the AI Engineer Roadmap

In short

Build a tool that turns a long article or lecture transcript into a short, readable summary. Along the way, you'll hit the real-world problem every NLP engineer meets: documents longer than the model can read.

A tool that takes long text (articles, documents) and produces a concise summary — practice combining a pretrained model with a usable interface.

The blob as an editor trims a long scroll of paper down to a small card with big scissors.

Think of it like this

The 60-word news card

Some news apps squeeze every story into a 60-word card you read in seconds. Someone has to read the full article and keep only what matters. Your summarizer is that editor: it reads in sections, notes the key points, then writes one short card.

Watch it happen

Your build plan

Input
Clean
Chunk
Summarise
Merge
Show

1/6Accept pasted text or an uploaded .txt file. URL scraping can come later.

The big ideas

What you need to know

Chunk by tokens, not characters

Models count tokens. Use the tokenizer to split, so no chunk silently gets truncated.

Map, then reduce

Summarise each chunk (map), then summarise the combined summaries (reduce). It scales to long documents.

Let users pick length

Expose max_length as a short, medium or long option. Different readers want different detail.

Make it checkable

Show the source next to the summary. Users should be able to verify any surprising claim.

See it in code

Walk through the code

python
1from transformers import AutoTokenizer, pipeline2 3name = "facebook/bart-large-cnn"4tok = AutoTokenizer.from_pretrained(name)5summarizer = pipeline("summarization", model=name, tokenizer=tok)6 7def summarize_long(text, chunk_tokens=900):8    ids = tok(text, add_special_tokens=False)["input_ids"]9    chunks = [tok.decode(ids[i:i + chunk_tokens]) for i in range(0, len(ids), chunk_tokens)]10    partial = [summarizer(c, max_length=80, min_length=20, do_sample=False)[0]["summary_text"] for c in chunks]11    combined = " ".join(partial)12    if len(partial) == 1:13        return combined14    return summarizer(combined, max_length=120, min_length=40, do_sample=False)[0]["summary_text"]15 16print(summarize_long(open("article.txt", encoding="utf-8").read()))

1/3Tokenise the whole text, then cut the ids into 900-token chunks and turn each back into text.

The tricky part of the project: handling text longer than the model's limit with a map-then-reduce approach.

Save yourself the pain

Common mistakes

Oops

Splitting text every 4,000 characters and hoping it fits.

Do this instead

Character counts don't map neatly to tokens. Split with the tokenizer so every chunk is safely under the limit.

Oops

Cutting chunks mid-sentence and getting odd summaries.

Do this instead

Once it works, improve chunking to break at sentence or paragraph boundaries near the token limit.

Your mission

Milestone 1: summarise a long article

~45 min

Quick check

Why does the summarizer split the document into chunks before summarising?

Go deeper

  1. 1Use a pretrained summarization model and wrap it behind a simple API.
  2. 2Handle long documents by chunking text before summarizing.
  3. 3Add a length/style control (short vs. detailed summary) as a stretch goal.

More projects 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