SAMRank: Unsupervised Keyphrase Extraction using Self-Attention Map in BERT and GPT-2

Byungha Kang, Youhyun ShinEMNLP 2023

Abstract

SAMRank is a novel unsupervised method for keyphrase extraction that utilizes raw self-attention maps from pre-trained language models (PLMs) like BERT and GPT-2, bypassing traditional word embeddings. By analyzing token-to-token attention weights, SAMRank identifies thematic importance more effectively than embedding-based similarity measures, which often suffer from anisotropy. Evaluated across multiple benchmarks, SAMRank achieves state-of-the-art performance, demonstrating that internal model mechanics provide a rich source of information for document understanding.

Introduction

Extracting keyphrases—the most representative terms in a document—is a foundational task in Natural Language Processing (NLP), supporting applications from search indexing to automatic summarization. While supervised models offer high accuracy, they require extensive labeled datasets, which are often unavailable for niche domains. Consequently, unsupervised methods have become a primary focus of research.

Recent state-of-the-art (SOTA) unsupervised approaches typically leverage contextualized embeddings from models like BERT to measure semantic similarity between a document and candidate phrases. However, these embeddings suffer from anisotropy, where vectors tend to cluster in a narrow cone of the vector space. This lack of uniform distribution makes traditional similarity measures, such as cosine similarity, less reliable. SAMRank addresses this by looking directly at the self-attention weights that the model uses to construct these embeddings, finding that the internal "routing" of information is often more informative than the final output vectors.

Methods

SAMRank operates through a multi-stage pipeline designed to rank candidate phrases based on their structural importance within the model's attention mechanism.

  1. Candidate Generation: The system identifies potential keyphrases (typically noun phrases) using standard NLP tools like Stanford CoreNLP and NLTK.
  2. Attention Map Extraction: The document is processed by a PLM (e.g., BERT or GPT-2). Instead of using the final layer's embeddings, SAMRank extracts the self-attention maps from every head across all layers.
  3. Global Attention Score ($G$): This score represents the total attention a token receives from all other tokens in the document. High global attention suggests the token is a central thematic element.
  4. Proportional Attention Score ($P$): To refine the ranking, SAMRank employs a redistribution trick. If a token is not globally "famous" but is highly attended to by a globally important token, its score is boosted proportionally.
  5. Scoring and Ranking: The final token score is calculated as $G + P$. These scores are aggregated at the phrase level, normalized for frequency to prevent common single words from dominating, and then ranked to produce the final keyphrase list.
The SAMRank architecture showing the calculation of Global and Proportional attention scores from Self-Attention Maps (SAM).

Key Insights

The "Specialist Head" Phenomenon

A critical discovery in the SAMRank research is that not all attention heads are equally useful for keyphrase extraction. The authors identified specific "specialist" heads that naturally learn to identify thematic essence during pre-training. For BERT, heads in the 3rd and 5th layers performed best, while for GPT-2, the 11th layer was the most effective.

GPT-2 vs. BERT

Interestingly, GPT-2 (a decoder-only model) frequently outperformed BERT (an encoder-only model). The authors hypothesize that GPT-2’s causal nature—where tokens only look backward—preserves the unique meaning of words more effectively. In contrast, BERT’s bidirectional attention can sometimes "dilute" a word's specific meaning by over-mixing it with its neighbors.

Key Results

SAMRank consistently outperformed existing embedding-based and graph-based unsupervised methods across several diverse benchmarks, including Inspec (short abstracts) and SemEval2010 (full-length articles).

Performance comparison of SAMRank against statistics-based, graph-based, and embedding-based models across three datasets.

As shown in the results table, SAMRank (BERT) achieved an F1@15 score of 39.73 on the Inspec dataset, significantly surpassing the previous best embedding-based model, JointGL (36.67). On longer documents like those in SemEval2010, SAMRank (GPT-2) achieved an F1@10 of 19.49, outperforming MDERank (18.27). These results establish SAMRank as a new SOTA for unsupervised keyphrase extraction.

Limitations and Future Work

While powerful, SAMRank currently requires the manual identification of the "best" attention head for a given dataset, as the optimal head can vary based on text length and domain. Additionally, handling extremely long documents (e.g., the Krapivin dataset) requires segmenting the text, which can lead to a loss of global context. Future research may focus on automatically combining outputs from multiple high-performing heads or utilizing models designed for long-range dependencies, such as BigBird or Longformer, to maintain context across entire documents.

Summary updated

BibTeX
@inproceedings{kang2023samrank,
  author = {Byungha Kang and Youhyun Shin},
  title = {{SAMRank: Unsupervised Keyphrase Extraction using Self-Attention Map in BERT and GPT-2}},
  booktitle = {Conference on Empirical Methods in Natural Language Processing},
  year = {2023},
  doi = {10.18653/v1/2023.emnlp-main.630},
}
Figure