Source-linked AI summary

An Introductory Survey on Attention Mechanisms in NLP Problems

Dichao Hu

arXiv:1811.05544v1cs.CLcs.LGstat.ML

TL;DR

Attention mechanisms assign importance scores to sequence elements and have been applied across NLP tasks, but their broad use has outpaced rigorous mathematical justification. This paper surveys their formulation, variants, applications, connections with other techniques, and evaluation, concluding that attention has achieved broad success while theoretical justification remains scarce.

  • Problem

    Attention is widely used across NLP tasks, yet rigorous mathematical justification of why it works in varied scenarios remains scarce.

  • Method

    The paper provides an introductory survey organized around attention’s formulation, variants, applications, associations with other machine-learning techniques, and evaluation.

  • Results

    Attention-based methods have attained significant success across machine translation and diverse NLP applications, including complex temporal reasoning and embedding pre-training.

  • Takeaways & Limitations

    The survey offers basic knowledge of a widely used mechanism while showing that task complexity motivates specialized attention variants.

  • Takeaways & Limitations

    Extrinsic evaluation can be misleading because downstream improvements cannot be attributed specifically to the attention component.

Abstract

from arXiv · show

First derived from human intuition, later adapted to machine translation for automatic token alignment, attention mechanism, a simple method that can be used for encoding sequence data based on the importance score each element is assigned, has been widely applied to and attained significant improvement in various tasks in natural language processing, including sentiment classification, text summarization, question answering, dependency parsing, etc. In this paper, we survey through recent works and conduct an introductory summary of the attention mechanism in different NLP problems, aiming to provide our readers with basic knowledge on this widely used method, discuss its different variants for different tasks, explore its association with other techniques in machine learning, and examine methods for evaluating its performance.

1 Introduction

Attention augments recurrent encoder-decoder translation by assigning scores to source tokens and forming a context vector during decoding. The survey presents attention’s motivation, broad applications, variants, and evaluation methods.

  • Motivation: Traditional RNN encoder-decoder models compress the source sequence into the encoder’s last hidden representation before generating target tokens sequentially.The survey identifies forgetfulness and difficulty retaining information from earlier inputs as drawbacks of this architecture.
  • Basic mechanism: The context vector is combined with the current decoder hidden state and previous target token to generate the next target token.This procedure repeats for each output token until the sequence ends.
  • Motivation: Attention addresses recurrent memory limitations by computing representations from every input element and enables soft alignment that emphasizes relevant sequence parts.Elements receive higher or lower influence according to their attention scores.
  • Survey scope: The survey covers attention formulation, task-specific variants and applications, associations with other machine-learning techniques, and performance evaluation.Its evaluation coverage includes methods for examining attention performance.
  • Basic mechanism: Attention computes a score for each source-token representation during every decoding step and uses the scores to obtain a context vector.The context vector is a weighted average of input elements relative to the current decoder state.

2 Formulation

The basic attention mechanism matches a task-specific pattern vector against sequence elements, normalizes the resulting scores, and aggregates the sequence into a contextual representation. In translation, these weights can represent alignment between target and source tokens.

  • Score computation: Basic attention represents the input as a sequence of vectors and matches each element against a task-specific pattern vector.The alignment function produces a scalar score indicating match quality.
  • Score computation: Alignment functions compute scalar scores using similarity formulations such as multiplicative, additive, and other pairwise comparisons.The supplied formulation passage introduces common choices while the displayed equations provide their forms.
  • Sequence encoding: The scores are normalized into weights that encode the sequence as a context vector used as an additional contextual feature downstream.Elements with stronger matches receive larger weights and contribute more to the encoding.
  • Translation interpretation: In machine translation, attention scores can measure the alignment of a target token with each source token.Ideally, source tokens aligned with the gold target token receive high scores.

3 Variation

Attention variants extend the basic mechanism to capture richer interactions, hierarchical structure, internal dependencies, memory updates, and task-specific selection. These designs address increasingly complex NLP tasks by adapting what is attended to and how attention is computed.

  • Motivation: Basic attention is often insufficient for tasks requiring indirect relationships, motivating more sophisticated mechanisms guided by latent contextual clues.The survey illustrates this with question answering requiring temporal reasoning between the question and the answer location.
  • 3.1 Multi-dimensional Attention: Multi-dimensional attention stacks representations across spaces to capture multiple interactions, but may require constraints so attention columns focus on different sequence parts.In aspect and opinion extraction, projected representations can highlight different tokens associated with an aspect.
  • 3.2 Hierarchical Attention: Hierarchical attention models nested textual structure, such as words within sentences and sentences within documents, before using the resulting representation for classification.Word-level and sentence-level pattern vectors are learned, and the sentence representation is fed to logistic regression.
  • 3.3 Self Attention: Self-attention matches sequence elements with internal patterns, enabling pairwise relations and contextual token representations that reflect surrounding terms.Transformer combines self-attention layers with feed-forward layers for machine translation.
  • Reusability: Memory-based attention performs iterative query updates to navigate indirectly related evidence and can locate answers after several hops in complex temporal reasoning tasks.More sophisticated variants use recurrent updates across multiple query-content time steps or combine content and location information.
  • 3.5 Task-specific Attention: Task-specific attention includes local attention, which predicts a pivot position and applies Gaussian smoothing around it instead of attending globally.This design targets long-sequence translation where global attention is expensive.

4 Application

The survey connects attention with ensemble methods, memory-based gating, and attention-driven pre-training. These applications use attention to weight representations, update recurrent memory contextually, or learn richer contextual token representations.

  • 4.1 Attention for Ensemble: Attention can act like model ensembling by treating sequence elements as models and normalized scores as weighted votes.This perspective is used to combine word embeddings into meta-embeddings.
  • 4.1 Attention for Ensemble: Meta-embeddings assign different weights to embeddings according to word characteristics such as concreteness and frequency.ImageNet embeddings receive larger weights than FastText embeddings for concrete words.
  • 4.2 Attention for Gating: Attention-based gating replaces a GRU update gate with an attention score to produce context-aware memory updates.The attention scores come from an external module, and the update uses hi = αi ◦˜hi + (1 −αi) ◦hi−1.
  • 4.2 Attention for Gating: Memory-based attention constructs query-specific token representations by interacting a query with document tokens and iteratively updating their embeddings.This approach aims to build deep query-specific token representations.
  • 4.3 Attention for Pre-training: Attention-integrated pre-training seeks higher-quality token representations that incorporate syntactic and semantic information from surrounding contexts before downstream fine-tuning.BERT is described as a bidirectional pre-training model based on the Transformer Encoder, combining feed-forward and self-attention layers.

5 Evaluation

The survey distinguishes intrinsic, extrinsic, and qualitative approaches for evaluating attention. Intrinsic measures compare attention with task-specific alignment labels, whereas extrinsic and heatmap-based methods offer broader or more convenient assessment but have important interpretive limits.

  • 5.1 Quantitative: Quantitative evaluation is divided into intrinsic and extrinsic methods according to whether attention is assessed directly or within a downstream supervised task.Intrinsic evaluation examines attention itself, while extrinsic evaluation compares overall downstream model performance.
  • 5.1 Quantitative: Intrinsic machine-translation evaluation compares attention distributions with gold word-alignment data to quantify alignment performance.These measurements are precise but restricted to particular tasks and dependent on abundant labelled data.
  • 5.1 Quantitative: Extrinsic evaluation compares overall performance across models using different attention mechanisms under a downstream task such as machine translation.Figure 4 illustrates this evaluation setting.
  • 5.2 Qualitative: Qualitative evaluation commonly visualizes normalized attention scores as heatmaps whose intensity indicates the score assigned to each element.Attention is expected to focus on task-relevant keywords, but heatmaps are considered more useful for visualization than analysis.
  • 5.1 Quantitative: Extrinsic improvements can be misleading because overall performance differences cannot determine whether attention itself caused the gains.The method is more general and widely used than intrinsic evaluation, but attribution to the attention component remains unresolved.

6 Conclusion and Prospects

The survey summarizes attention’s formulations, variants, applications, and evaluation across NLP research. It notes that mathematical justifications remain scarce, while attention-based embedding pre-training has achieved strong results and is identified as a prospective research area.

  • 6 Conclusion and Prospects: The paper surveys recent attention research through its formulation, variation, application, and evaluation.This conclusion reflects the paper’s stated introductory scope.
  • 6 Conclusion and Prospects: Attempts to provide mathematical justification for attention remain scarce relative to its wide use across NLP tasks.The conclusion identifies this imbalance as an unresolved area in the surveyed literature.
  • 6 Conclusion and Prospects: Attention-based embedding pre-training has attained great success and may be a prospective area for future research.The paper presents this direction as a prospect rather than a settled conclusion.
Loading 1811.05544v1…