Document summarization
Text Summarization
Condensing a long document into a short summary. Extractive and abstractive methods.
Text Summarization
Condensing a long document into a short summary. Extractive and abstractive methods.
Document summarization (Text Summarization) is a natural language processing technique that extracts or generates the key content of long text to create a short, meaningful summary. As an essential tool for efficiently digesting vast documents in the age of information explosion, it is used in various fields such as news articles, research papers, legal documents, and customer reviews.
Document summarization is broadly divided into two approaches: extractive and abstractive. Extractive summarization selects important sentences from the original text as they are, while abstractive summarization generates new sentences to re-express the meaning of the original text. Since the emergence of the Transformer in 2017, abstractive summarization has developed rapidly, and models such as GPT, BART, and T5 have achieved human-level summarization quality.
Modern document summarization systems identify important parts within a document through the attention mechanism and generate natural summaries through a decoder. In particular, in 2024-2025, the latest LLMs such as Claude and GPT-4o became able to summarize long documents of tens of thousands of tokens accurately while maintaining context.
In practice, document summarization is widely applied to news curation, legal document analysis, research paper review, automatic meeting minutes generation, customer review analysis, and more. In RAG (Retrieval-Augmented Generation) pipelines as well, it plays a key role in summarizing retrieved documents and efficiently passing them to the LLM.
# OpenAI GPT를 활용한 문서 요약 (2024-2025)
from openai import OpenAI
client = OpenAI()
def summarize_document(text: str, max_length: int = 200) -> str:
"""
긴 문서를 요약합니다.
Args:
text: 요약할 원문 텍스트
max_length: 요약문 최대 단어 수
Returns:
요약된 텍스트
"""
response = client.chat.completions.create(
model="gpt-4o",
messages=[
{
"role": "system",
"content": f"당신은 문서 요약 전문가입니다. 핵심 내용을 {max_length}단어 이내로 요약하세요."
},
{
"role": "user",
"content": f"다음 문서를 요약해주세요:\n\n{text}"
}
],
temperature=0.3 # 낮은 temperature로 일관성 확보
)
return response.choices[0].message.content
# 사용 예시
long_document = """
인공지능(AI)은 21세기 가장 혁신적인 기술 중 하나로 자리잡았습니다.
머신러닝과 딥러닝의 발전으로 AI는 이미지 인식, 자연어 처리,
자율주행 등 다양한 분야에서 인간 수준의 성능을 달성했습니다.
특히 2022년 ChatGPT의 등장은 AI 기술의 대중화를 이끌었으며,
기업들은 경쟁적으로 AI를 비즈니스에 통합하고 있습니다.
"""
summary = summarize_document(long_document)
print(f"요약: {summary}")
# Hugging Face Transformers를 활용한 로컬 요약
from transformers import pipeline
summarizer = pipeline("summarization", model="facebook/bart-large-cnn")
result = summarizer(long_document, max_length=130, min_length=30, do_sample=False)
print(f"BART 요약: {result[0]['summary_text']}")
Comparison of major document summarization models/services (as of January 2025):
| Model/Service | Maximum context | Cost (1M tokens) | Features |
|---|---|---|---|
| GPT-4o | 128K | $2.50 / $10.00 | High quality, multilingual support |
| Claude 3.5 Sonnet | 200K | $3.00 / $15.00 | Excellent at handling long documents |
| Gemini 1.5 Pro | 2M | $1.25 / $5.00 | Ultra-large document support |
| BART-large-CNN | 1K | Free (local) | Specialized in news summarization |
| Pegasus | 1K | Free (local) | Excellent at abstractive summarization |
"When we applied a document summarization pipeline to customer review analysis, we were able to condense 10,000 reviews into key insights in 5 minutes. Abstractive summarization produced more natural results than extractive summarization, so we chose GPT-4o."
"Document summarization is broadly divided into Extractive and Abstractive approaches. Extractive selects sentences from the original text as they are, and Abstractive generates new sentences. Recently, Transformer-based models have achieved ROUGE scores of 45 or higher in abstractive summarization, approaching human-level performance."
"In a RAG system, if the retrieved documents are too long, they exceed the context window. By adding a document summarization layer, you can compress and pass along only the relevant information. Summarizing each chunk with the Map-Reduce pattern and then generating the final summary is effective."
Take a mock interview on this topic → WIA SOOM AI Interview · Start for free
Abstractive summarization models may fabricate content that is not in the original text, or incorrectly generate important figures/proper nouns. In domains where accuracy is critical, such as law and medicine, human verification is essential.
Attempting to summarize a 100-page document in one pass often runs into token limits. Long documents should be chunked and then summarized step by step using the Map-Reduce approach.
Design prompts suited to the target domain for summarization, and add a post-processing layer that verifies important entities (numbers, names, dates) against the original text. Monitoring summarization quality quantitatively with ROUGE, BERTScore, and similar metrics is also recommended.