Abstract
High-quality span representations are crucial to natural language processing tasks involving span prediction and classification. Most existing methods derive a span representation by aggregation of token representations within the span. In contrast, we aim to improve span representations by considering span-span interactions as well as more comprehensive span-token interactions. Specifically, we introduce layers of span-level attention on top of a normal token-level transformer encoder. Given that attention between all span pairs results in $O(n^4)$ complexity ($n$ being the sentence length) and not all span interactions are intuitively meaningful, we restrict the range of spans that a given span could attend to, thereby reducing overall complexity to $O(n^3)$. We conduct experiments on various span-related tasks and show superior performance of our model surpassing baseline models.
Introduction
In Natural Language Processing (NLP), many tasks revolve around spans—sequences of tokens that form a meaningful unit, such as "the President of the United States" or "went to the store." Traditionally, models create a representation of a span by simply aggregating the tokens inside it, such as taking the average or the maximum of the word vectors.
However, this approach is often too simplistic as it ignores critical structural information: the internal hierarchy of sub-spans (e.g., "New York" inside "New York City") and the external context of how a span relates to its neighbors. While span-level attention could theoretically solve this, a sentence of length $n$ has roughly $n^2$ possible spans. Comparing every span to every other span requires $O(n^4)$ operations, which is computationally prohibitive for standard use. This paper addresses this challenge by introducing efficient, restricted attention patterns.
Efficient Span-Level Attention Patterns
The proposed architecture consists of a Span-Level Transformer layer that sits on top of standard encoders like BERT. To reduce the computational complexity from $O(n^4)$ to $O(n^3)$, the researchers restrict the "field of view" for each span using four specific attention patterns:
- Inside-Token: A span only attends to the individual tokens contained within it, reinforcing the link between the phrase and its constituent words.
- Containment: A span attends to other spans that share its starting or ending point (its sub-spans and super-spans), capturing hierarchical relationships.
- Adjacency: A span attends to spans that immediately precede or follow it, helping the model understand how adjacent phrases interact.
- All-Token: A span attends to every individual token in the entire sentence, allowing it to gather global context beyond its own boundaries.
By limiting each span to attend to only $O(n)$ other elements, the total complexity is successfully brought down to $O(n^3)$.
Experimental Evaluation
The model was evaluated across a diverse set of benchmarks to test its generalizability:
- Probing Tasks: Six tasks including Named Entity Labeling (NEL), Coreference Arc Prediction (REF), Semantic Role Classification (SRC), and various Constituency Parsing tasks.
- Nested NER: The ACE2004 and ACE2005 datasets, which require identifying entities that may be nested inside one another.
Key Results
The proposed span-level attention consistently outperformed standard pooling baselines. On probing tasks, the model reached an average F1 score of 96.83%, compared to 96.46% for the best pooling baseline. On the ACE2005 Nested NER dataset, the model achieved an F1 score of 80.83 (with a frozen BERT backbone), a significant improvement over the 76.22 achieved by max pooling. These improvements held true across different backbones, including BERT and SpanBERT.
Discussion and Insights
Analysis of the results revealed that different tasks benefit from different attention patterns. Structural tasks like constituency parsing benefit most from Containment and Adjacency patterns. Conversely, tasks focused on textual meaning, like coreference resolution, perform better with the All-Token pattern.
While individual patterns provide gains, the combination of Inside-Token and Containment emerged as a robust "all-rounder" that performs well across almost all tasks. This suggests that explicitly modeling the interactions between spans provides a much richer signal than simply pooling token-level features.
Conclusion
This work demonstrates that span representations can be significantly improved by incorporating span-level attention. By carefully designing attention patterns based on linguistic intuition, the computational cost can be managed while achieving state-of-the-art results. Future work may explore using Reinforcement Learning to automatically discover optimal attention patterns for specific tasks and further reducing the $O(n^3)$ overhead for long-document processing.
Summary updated