Learning Guides
Text Summarization Using NLP: Extractive vs Abstractive Methods
Quick answer: Learn the two main approaches to text summarization in NLP, extractive and abstractive, with a practical extractive summarization example in Python.
What is Text Summarization?
Text summarization automatically condenses a longer document into a shorter version while preserving its key information, a task with obvious value for news, research papers and long reports.
Two Fundamentally Different Approaches
| Extractive | Abstractive |
|---|---|
| Selects existing sentences directly from the text | Generates new sentences that may not appear in the original |
| Simpler, more reliably factual | Can read more naturally, but risks generating inaccurate content |
| Uses statistical or graph based ranking | Uses deep learning, typically transformer models |
Extractive Summarization: How It Works
Extractive methods score each sentence by importance, using signals like word frequency or sentence position, then select the highest scoring sentences to form the summary, preserving the original wording exactly.
A Simple Extractive Example Using Word Frequency
import nltk
from nltk.corpus import stopwords
from nltk.tokenize import sent_tokenize, word_tokenize
from collections import defaultdict
nltk.download('punkt')
nltk.download('stopwords')
def summarize(text, num_sentences=3):
sentences = sent_tokenize(text)
words = word_tokenize(text.lower())
stop_words = set(stopwords.words('english'))
word_freq = defaultdict(int)
for word in words:
if word.isalnum() and word not in stop_words:
word_freq[word] += 1
sentence_scores = defaultdict(int)
for sentence in sentences:
for word in word_tokenize(sentence.lower()):
if word in word_freq:
sentence_scores[sentence] += word_freq[word]
top_sentences = sorted(sentence_scores, key=sentence_scores.get, reverse=True)[:num_sentences]
return ' '.join(top_sentences)
This scores each sentence by how many frequently occurring, non-stopword terms it contains, then selects the top-scoring sentences as the summary.
Abstractive Summarization Using Transformers
from transformers import pipeline
summarizer = pipeline("summarization", model="facebook/bart-large-cnn")
summary = summarizer(long_text, max_length=100, min_length=30, do_sample=False)
print(summary[0]['summary_text'])
This uses a pretrained transformer model to generate a genuinely new summary, potentially paraphrasing and rewording content rather than only extracting original sentences.
Which Approach to Choose
Extractive summarization is more reliably factual since it never invents content, making it safer for domains like legal or medical text where accuracy is critical. Abstractive summarization can produce more fluent, natural summaries but carries a genuine risk of introducing inaccurate or fabricated details, sometimes called hallucination.
Evaluating Summary Quality
ROUGE scores are the standard metric, comparing overlap between the generated summary and one or more human-written reference summaries.
Common Interview Questions
What is the difference between extractive and abstractive summarization?
Extractive summarization selects and combines existing sentences directly from the source text. Abstractive summarization generates new sentences that may reword or paraphrase the original content.
Why might extractive summarization be preferred in a high-stakes domain?
It never invents content, since it only selects sentences that already exist in the source, making it more reliably factual than abstractive methods, which can occasionally generate inaccurate details.
FAQ
Frequently Asked Questions
What is the difference between extractive and abstractive text summarization?
Extractive summarization selects existing sentences directly from the source text. Abstractive summarization generates new sentences, potentially rewording the original content.
Which summarization approach is safer for accuracy?
Extractive summarization, since it only selects sentences that already exist in the source and never invents new content, unlike abstractive methods which can occasionally hallucinate details.
What metric is commonly used to evaluate summary quality?
ROUGE score, which measures overlap between the generated summary and one or more human-written reference summaries.
Keep Reading
Related Articles
Learning Guides
INNER JOIN in SQL with Examples: Complete Beginner's Guide
Learn INNER JOIN in SQL with practical examples, syntax, interview questions, and real-world use cases. A complete beginner-friendly SQL JOI
Learning Guides
OUTER JOIN in SQL: Complete Guide with Examples for Beginners
Master OUTER JOIN in SQL with practical examples and real-world scenarios. Learn LEFT JOIN, RIGHT JOIN, FULL OUTER JOIN, syntax, use cases,
Learning Guides
Multi-Row Functions in SQL: Complete Guide with Examples
Learn multi-row (aggregate) functions in SQL including SUM, AVG, COUNT, MIN, MAX, GROUP BY and HAVING, with practical examples, NULL handlin