Source-linked AI summary
Attention in Natural Language Processing
Andrea Galassi, Marco Lippi, Paolo Torroni
TL;DR
The rapid, diverse development of NLP attention models has left the literature without a systematic overview. This article provides a unified model and four-dimensional taxonomy for vector-based attention architectures, alongside comparisons, prior-knowledge examples, and open challenges. Its synthesis organizes a substantial body of work while highlighting attention’s possible roles in knowledge injection, transfer learning, and unsupervised learning.
Problem
Rapidly expanding and inconsistent attention research has created ambiguity in model concepts and terminology, motivating a systematic overview.
Method
The article defines a general model of NLP attention and classifies vector-based architectures by input representation, compatibility function, distribution function, and input/output multiplicity.
Results
The taxonomy systematically charts and compares a substantial portion of the NLP attention literature, providing what the authors describe as the first systematic, comprehensive taxonomy for NLP attention models.
Takeaways & Limitations
Attention may support injecting task or prior knowledge into neural models and may contribute to combining subsymbolic models with symbolic representations or guiding unsupervised learning.
Abstract
from arXiv · showhide
Attention is an increasingly popular mechanism used in a wide range of neural architectures. The mechanism itself has been realized in a variety of formats. However, because of the fast-paced advances in this domain, a systematic overview of attention is still missing. In this article, we define a unified model for attention architectures in natural language processing, with a focus on those designed to work with vector representations of the textual data. We propose a taxonomy of attention models according to four dimensions: the representation of the input, the compatibility function, the distribution function, and the multiplicity of the input and/or output. We present the examples of how prior information can be exploited in attention models and discuss ongoing research efforts and open challenges in the area, providing the first extensive categorization of the vast body of literature in this exciting domain.
I. INTRODUCTION
Attention helps NLP models focus computational resources on task-relevant input elements, but rapid and inconsistent development has made the literature difficult to organize. This survey addresses that complexity with a unified model and taxonomy of attention architectures.
- Motivation: Attention learns weights for input elements so neural architectures can account for their differing relevance during tasks such as translation and sentiment analysis.It offers an alternative to manually tailoring solutions to specific input genres, especially for long or information-rich texts.
- Motivation: Attention was first introduced to NLP for machine translation and has since been adopted across a broad range of neural architectures and tasks.The surveyed applications span NLP and other fields, including computer vision, speech recognition, recommendation, and time-series analysis.
- Interpretation: Attention can provide visual highlights that help analyze neural-network behavior, although its reliability as an explanation remains debated.Some studies find attention inconsistent with other explainability metrics, while others support its use as an analytic tool.
- Research gap: Rapid development has produced a complex literature containing independently similar models and terms that different authors use for different concepts.The survey cites inner attention and word attention as arguably identical, while context vector has multiple meanings.
- Contribution: The article proposes a unified model and taxonomy organized by input representation, compatibility function, distribution function, and input/output multiplicity.It also compares attention models, discusses prior information, and identifies open challenges and future directions.
- Scope: The analysis is restricted to attentive architectures designed for vector representations and does not provide a comprehensive account or quantitative comparison of all NLP attention mechanisms.The authors state that broad empirical comparison would require extensive experimentation across architectures and benchmarks.
II. ATTENTION FUNCTION
Attention dynamically highlights relevant input features by weighting sequence elements. In RNNsearch, the mechanism produces context vectors that guide recurrent decoding for machine translation.
- Attention dynamically assigns higher weights to input elements judged more relevant to the task.The mechanism can operate on textual elements or higher-level representations.
- RNNsearch uses an encoder-decoder architecture with attention for machine translation.A bidirectional recurrent encoder processes the input, while the decoder generates the output sequence.
- At each decoding step, attention combines the previous decoder hidden state with encoder annotations to score input-output matches.The alignment model produces scalar energy scores for the input positions.
- A softmax normalizes the alignment scores into attention weights, and the weighted annotations form the context vector.The context vector is supplied to the subsequent recurrent decoder.
- Attention distributes source information across annotations so the decoder can selectively retrieve it instead of relying on one fixed-length vector.This is the motivation attributed to Bahdanau et al.’s attention approach.
B. Unified Attention Model
The unified attention model organizes attention around keys, queries, compatibility scores, distributions, and optional values. It provides a common framework for comparing diverse NLP attention architectures.
- B. Unified Attention Model: The proposed unified model extends prior attention formulations and includes a core shared by almost all surveyed models.Additional components occur in most, but not universally all, literature models.
- B. Unified Attention Model: The core mechanism maps key vectors K to a distribution a of weights over the input elements.Keys encode the data features on which attention is computed.
- B. Unified Attention Model: A query q can serve as a reference for emphasizing elements relevant to the task; without one, attention emphasizes elements inherently relevant to the task.Queries may be vectors or matrices and are task-independent in this framework.
- B. Unified Attention Model: A compatibility function f computes energy scores from keys and the query, while a distribution function g converts those scores into attention weights.The framework distinguishes matching inputs from normalizing or transforming their scores.
- B. Unified Attention Model: When values V are present, attention weights produce weighted value representations that are merged into a context vector.Summation is common, although gating functions are also used; higher-weighted values mainly determine the result.
- B. Unified Attention Model: The term context vector is used inconsistently across the literature, so the survey distinguishes its own terminology from alternative usages.The cited authors attach the term to different elements of their attention architectures.
C. Deterministic Versus Probabilistic Attention
The literature distinguishes attention models by whether attention weights are interpreted probabilistically or selected deterministically. The article avoids these labels because they are used inconsistently across approaches.
- Softmax normalization allows attention weights to be interpreted as a probability distribution.
- Deterministic attention models select context words deterministically, for example through a constituency parse tree.
- The article avoids classifying attention models as deterministic, probabilistic, or stochastic.
III. USES OF ATTENTION
Attention is used to estimate relevance, build compact representations, support dynamic sequence generation, select words, and model interactions among multiple input sequences. These uses span tasks including classification, translation, sequence labeling, parsing, question answering, and multimodal processing.
- Attention encodes inputs into compact representations for tasks such as document classification and multimodal processing.
- Attention creates dynamic input representations for text generation, tailoring the encoding to each decoding time step.
- Attention can produce sequence-to-sequence annotators without relying on RNNs or CNNs.
- Attention selects specific words for tasks such as dependency parsing and cloze question answering.
- Attention models mutual interactions between multiple input sequences in tasks such as question answering.
A. Input Representation
Attention can operate on contextual or isolated input representations and can be arranged into self-attentive and hierarchical architectures. These designs produce representations that capture relevance within sequences and across multiple semantic levels.
- Keys and values may encode contextual document elements through annotation functions such as RNN layers.
- Inner attention applies attention directly to isolated inputs such as one-hot vectors or pretrained embeddings.
- Inner attention uses fewer layers and hyperparameters, reducing the computational resources required for training.
- Self-Attention: Self-attention applies multiple attention steps to one input sequence, producing one context embedding per key.
- Self-Attention: Self-attention allows each output element to incorporate information from the whole input without locality boundaries.
- Hierarchical Input: Hierarchical attention applies multiple attention modules at different levels, such as characters, words, sentences, and documents.
- Hierarchical Input: A target macro-object can provide a query for a second attention operation over document word embeddings.
B. Compatibility Functions
Compatibility functions determine how attention keys and queries are matched or combined. The taxonomy covers comparison-based, combination-based, convolutional, deep, biased, activated, location-based, and self-attentive variants.
- Compatibility functions match or combine keys K and queries q to compute attention energies.
- Similarity attention assigns higher relevance to keys that are more similar to the query.
- General attention uses a learnable matrix to map queries into the vector space of keys.
- Biased general attention adds a learnable bias, while activated general attention applies a nonlinear activation function.
- Combination-based attention forms a joint key-query representation and multiplies it by an importance vector.
- Additive and concat attention use a single neural layer, whereas deep attention uses multiple layers.
- Convolution-based attention uses learned filters as relevance templates applied to key subsequences.
- Location-based attention depends on key position, while self-attention can depend only on the input keys.
C. Distribution Functions
Distribution functions convert energy scores into attention weights whose properties depend on probabilistic interpretation, sparsity, positional structure, and selection behavior.
- Distribution-function roles: Attention distribution functions map energy scores to weights, with choices shaped by probability, sparsity, and positional requirements.Weights may be probabilistic, probability-like, or Boolean, and may account for key positions.
- Probabilistic distributions: Sigmoid attention constrains each weight between 0 and 1, allowing weights to be interpreted as probabilities that elements are relevant.The corresponding values and weighted values share these boundaries.
- Probabilistic distributions: Softmax produces soft attention by normalizing scores into a probability distribution over the context-vector elements.Each weight can be interpreted as the probability that its corresponding element is most relevant.
- Sparse and selective distributions: Sparse distributions can ignore completely irrelevant keys, reducing noise and the computational footprint.This motivates alternatives to sigmoid and softmax when some input elements should receive zero weight.
- Structured and localized distributions: Attention can incorporate structure through conditional random fields, positional masks, hard selection, hybrid filtering, and adaptive temperature.These mechanisms respectively model dependencies, restrict locations, select subsets, combine hard and soft attention, or control smoothness.
D. Multiplicity
Multiplicity extends attention beyond a single input or output by modeling multiple relevance views and interactions between sequences. Coattention may use compact cross-input summaries or element-pair energy matrices.
- Multiple outputs: Multiple attention distributions can represent ambiguous or multitask data through an importance matrix and produce richer context representations.The resulting context vectors can be concatenated, while regularization can encourage distinct relevance models.
- Multiple inputs: Coattention: Coattention jointly processes key and query sequences so their element-to-element interactions inform both representations.This avoids missing interaction information that independent attention would omit.
- Coarse-grained coattention: Coarse-grained coattention uses a compact representation of one input to compute attention over the other, with roles potentially alternating between inputs.Alternating coattention is one sequential example.
- Fine-grained coattention: Fine-grained coattention assigns energy scores to every key/query pair in a coattention matrix computed by a cocompatibility function.Cocompatibility functions can adapt standard compatibility functions or use new constructions.
- Coattention aggregation: Aggregation functions extract key and query relevance from the pairwise energy matrix, using operations such as rowwise or columnwise pooling.Attention pooling gives a key high weight when it has a high coattention score with at least one query element.
- Coattention aggregation: Nested coattention applies rowwise and columnwise softmaxes, averages one result, and combines it with the other to obtain query and document distributions.Multiple coattention models can also be combined into a single embedding.
V. COMBINING ATTENTION AND KNOWLEDGE
Attention is presented as both a route toward partial neural-network interpretability and a possible interface for incorporating external knowledge. The surveyed perspective connects these goals to broader neural-symbolic integration efforts.
- Motivation: Combining subsymbolic neural models with symbolic knowledge representation is identified as a major open challenge in artificial intelligence.Statistical relational learning, neural-symbolic learning, and related deep architectures are cited as approaches to this gap.
- Interpretability and knowledge: Attention weights may help isolate features that are significant for predictions because they represent input relevance with respect to a task.This gives attention a potential interpretive role beyond performance gains.
- Scope: The article surveys techniques for injecting prior knowledge into neural networks through attention and reserves open-challenge discussion for a later section.The surveyed techniques are framed as ways to exploit external knowledge in attention models.
A. Supervised Attention
Attention is usually trained jointly with a neural architecture without its own target distribution, but available relevance information can supervise or guide attention learning. The surveyed approaches include preliminary training, auxiliary tasks, transfer, coverage, and domain-specific distance.
- Training setup: In most surveyed work, attention is trained with the rest of the architecture for a specific task and lacks its own target distribution.The attention model therefore selects useful information under the main supervised training procedure.
- Training setup: External labels or tools can provide desired weight distributions, enabling supervised training of the attention model.This differs from the common target-free attention-learning setup.
- Supervision strategies: Preliminary training uses an external classifier to learn attention weights before plugging them into another architecture.One example learns sentence relevance from rationales supporting document categorizations.
- Supervision strategies: Joint auxiliary-task training teaches attention alongside the main task and has produced good results in machine translation, visual question answering, and domain classification.The attention objective is performed without preliminary training.
- Structured and transferred supervision: Attention can encode syntactic structure or transfer learned input-to-weight mappings across domains and tasks.LISA trains one attention head for dependency parsing, while pretrained attentive models can support target-domain tasks.
- Additional prior information: Coverage constraints regulate how much attention a word receives across iterations, while dependency-graph distance can replace positional distance in distribution functions.These mechanisms inject sequence-level or syntactic prior information into attention.
VI. CHALLENGES AND FUTURE DIRECTIONS
The article identifies open directions for using attention to investigate neural representations, detect outliers, assess uncertainty, and integrate symbolic knowledge. It also emphasizes that attention’s explanatory status remains debated.
- Attention for Deep Networks Investigation: Attention-based explanations remain contested because local adversarial distributions can alter outcomes, although attention may still provide plausible information about feature importance.The cited discussion distinguishes plausible reconstruction from faithful reconstruction of decision-making.
- Attention for Deep Networks Investigation: Attention weights may help investigate whether deep networks learn high-level features and how different heads behave.The cited work relates heads to positions or syntactic elements and examines locality across depths.
- Attention for Deep Networks Investigation: Attention weights could support transfer-learning-style tests of whether an architecture has learned high-level features.The proposed approach uses attention weights as input features in another model.
- Attention for Outlier Detection and Sample Weighing: Attention may identify outliers or dynamically select training samples by assigning low weights to less relevant examples.The survey notes that no attention-based approach had been experimentally studied for this purpose at the time described.
- Attention and Uncertainty: The distribution of attention weights may indicate when a model cannot identify relevant information and provide a task-specific confidence signal.The survey speculates that high entropy or unusually large weights may be informative, while noting possible causes include uninformative data or poor discrimination.
- Attention and Uncertainty: Model uncertainty could inform merging strategies in hybrid symbolic-subsymbolic, multitask, and reinforcement-learning systems.The survey presents these as contexts where uncertainty information may be relevant.
D. Unsupervised Learning With Attention
The survey reviews emerging uses of attention in unsupervised learning and neural-symbolic NLP. It presents these directions as promising but early-stage applications spanning representation learning, domain adaptation, reasoning, and knowledge integration.
- D. Unsupervised Learning With Attention: Attention is usually trained within supervised architectures, but recent work has begun applying it to purely unsupervised models.The survey characterizes unsupervised attention as a promising long-term research direction.
- D. Unsupervised Learning With Attention: Unsupervised attention has been used to remove sentiment-irrelevant words, improve aspect coherence, and encode and decode semantic question representations.The cited examples cover aspect extraction and question retrieval with self-attention.
- D. Unsupervised Learning With Attention: Attention alignment has been proposed to align source- and target-domain attention patterns for unsupervised domain adaptation.The survey identifies this computer-vision proposal as a potentially interesting NLP scenario.
- Neural-Symbolic Models: Neural-symbolic NLP applications use attention for knowledge-graph reasoning, graph-neighbor aggregation, textual entailment, and complex reasoning.The reviewed architectures combine attention with rule-based or neural information in several reasoning settings.
- Neural-Symbolic Models: Logical constraints have been used to govern attention and enforce word alignment in machine comprehension and natural language inference.This connects attention distributions with explicit logical statements.
- General Role of Attention: Attention selects input parts or features through a distribution function to form compact representations and highlight relevant information.The survey notes that selection can involve locality across space, time, or semantics.
- Conclusion: The survey’s taxonomy systematically charts and compares attention models across a vast portion of the NLP literature.It is presented as the first systematic, comprehensive taxonomy of attention models for NLP.
- Conclusion: Attention may help inject knowledge, support transfer learning, combine subsymbolic models with symbolic representations, and guide unsupervised training.The survey frames symbolic integration and unsupervised learning as challenging research avenues rather than settled capabilities.