Text Summarization Techniques

Text summarization condenses long documents into shorter, coherent summaries. Deep learning models approach this task using either extractive methods (selecting key sentences) or abstractive methods (generating new sentences), often leveraging pointer-generator networks to copy words directly from the source.


Extractive vs. Abstractive Summarization

Summarization models fall into two distinct paradigms: selecting key phrases directly, or generating new sentences to synthesize context.

Extractive Mechanics

Extractive summarization operates as a selection task. The model evaluates sentences in a source document and extracts a subset of them to form the summary. Traditional methods use graph-ranking algorithms like TextRank, where sentences are represented as nodes in a graph and edges represent semantic similarity. The model computes centrality scores to identify the most representative sentences.

In neural networks, this is formulated as a binary classification problem: each sentence in the document is passed through an encoder (like a CNN or Transformer) to generate a vector representation, and a classification head predicts whether the sentence should be included in the summary. While extractive summarization is fast and avoids grammatical errors, the summaries can feel disjointed and lack cohesion.

Abstractive Generation

Abstractive summarization is a generation task. Rather than copying sentences directly, the model reads the entire document and generates a summary using its own vocabulary, similar to how a human would summarize a text. This requires an encoder-decoder architecture (often a sequence-to-sequence network with attention) to map the source document to a new summary sequence. The decoder must synthesize information, rephrase concepts, and maintain grammatical coherence.

Abstractive summarization can produce fluent, natural summaries that merge information from different parts of the document. However, it is computationally intensive and prone to generating factual errors or hallucinations, where the model generates plausible-sounding sentences that are not supported by the source text.

Encoder-Decoder Summarization Models

Abstractive summarization models use pointer-generator networks to combine word generation with direct copying from the source text.

Pointer-Generator Networks

Abstractive summarization models struggle with out-of-vocabulary (OOV) words and factual details, such as names, dates, and numbers. To address this, See et al. (2017) introduced the Pointer-Generator Network. This architecture combines a standard sequence-to-sequence generator with a pointer mechanism that can copy words directly from the input text. At each step \\( t \\), the model calculates a generation probability \\( p_{gen} \\in [0, 1] \\) based on the context vector, decoder state, and input embedding:

\\( p_{gen} = \\sigma(\\mathbf{w}_c^T c_t + \\mathbf{w}_s^T s_t + \\mathbf{w}_x^T x_t + b) \\)

This probability acts as a switch: with probability \\( p_{gen} \\), the model generates a word from the vocabulary, and with probability \\( 1 - p_{gen} \\), it copies a word from the source document by sampling from the attention distribution \\( \\alpha_t \\). The final probability distribution for a word \\( w \\) is a mixture of the generation and copy probabilities, allowing the model to generate fluent text while preserving names and details.

PyTorch Copy Mechanism

This PyTorch forward pass demonstrates how to calculate the combined generation and pointer probability distribution for a single step:

<pre><code class="language-python">import torch import torch.nn as nn class PointerGeneratorStep(nn.Module): def __init__(self, vocab_size, hidden_dim, embed_dim): super().__init__() # Linear layer to compute p_gen self.p_gen_layer = nn.Linear(hidden_dim + hidden_dim + embed_dim, 1) # Project hidden state to vocabulary distribution self.vocab_dist_proj = nn.Linear(hidden_dim, vocab_size) def forward(self, dec_state, context, dec_input, attn_dist, src_input_ids): """ Args: dec_state: Decoder hidden state [batch_size, hidden_dim] context: Attention context vector [batch_size, hidden_dim] dec_input: Decoder input embedding [batch_size, embed_dim] attn_dist: Attention weights over source tokens [batch_size, src_len] src_input_ids: Source token IDs [batch_size, src_len] """ batch_size = dec_state.size(0) # Compute p_gen switch probability features = torch.cat((context, dec_state, dec_input), dim=-1) p_gen = torch.sigmoid(self.p_gen_layer(features)) # [batch_size, 1] # Compute standard vocabulary distribution vocab_logits = self.vocab_dist_proj(dec_state) vocab_dist = torch.softmax(vocab_logits, dim=-1) # [batch_size, vocab_size] # Scale vocab distribution by p_gen scaled_vocab = p_gen * vocab_dist # [batch_size, vocab_size] # Scale copy distribution by (1 - p_gen) scaled_copy = (1.0 - p_gen) * attn_dist # [batch_size, src_len] # Merge distributions final_dist = scaled_vocab.clone() for i in range(batch_size): # Scatter the copy probabilities to the matching vocabulary indices final_dist[i].scatter_add_(0, src_input_ids[i], scaled_copy[i]) # Returns the final probability distribution of shape [batch_size, vocab_size] return final_dist, p_gen # Instantiate and run step step = PointerGeneratorStep(vocab_size=20, hidden_dim=8, embed_dim=8) d_state = torch.randn(2, 8) ctx = torch.randn(2, 8) d_in = torch.randn(2, 8) a_dist = torch.tensor([[0.7, 0.3], [0.1, 0.9]]) # Attention over 2 source words src_ids = torch.tensor([[3, 14], [14, 5]]) # Word IDs in source final_dist, p_gen = step(d_state, ctx, d_in, a_dist, src_ids) print("Final probability distribution shape:", final_dist.shape) # [2, 20] print("p_gen value:", p_gen)</pre>

Summarization Evaluation and Challenges

Summarization models are evaluated using the ROUGE metric suite and optimized to reduce factual inaccuracies.

ROUGE Metric Suite

ROUGE (Recall-Oriented Understudy for Gisting Evaluation) is the standard metric suite for text summarization. Unlike BLEU, which is precision-oriented, ROUGE focuses on recall, measuring how many n-grams in the human reference summary were generated by the model. The most common variants are ROUGE-N and ROUGE-L. ROUGE-1 and ROUGE-2 measure the recall of unigrams and bigrams, respectively:

\\( \\text{ROUGE-N} = \\frac{\\sum_{S \\in \\text{Reference}} \\sum_{\\text{gram}_n \\in S} \\text{Count}_{\\text{match}}(\\text{gram}_n)}{\\sum_{S \\in \\text{Reference}} \\sum_{\\text{gram}_n \\in S} \\text{Count}(\\text{gram}_n)} \\)

ROUGE-L measures the Longest Common Subsequence (LCS) between the generated and reference summaries. This captures structural similarity and word order without requiring exact n-gram matching. While ROUGE is useful, models can achieve high scores by outputting key words in ungrammatical order, making human evaluation essential.

The Hallucination Problem

Abstractive summarization models are prone to hallucinating facts. These hallucinations occur because the model's language decoder relies on likelihood-based training objectives, which can prioritize fluent-sounding sentences over factual accuracy. If the model sees similar phrasing in the training data associated with different facts, it may combine them incorrectly.

To mitigate this, models incorporate coverage mechanisms. The coverage vector accumulates attention weights from previous steps: \\( c^t = \\sum_{i=0}^{t-1} \\alpha^i \\). During training, a coverage loss is added to penalize the model for repeatedly attending to the same words, reducing repetition and forcing the model to focus on new parts of the source text.