Reducing Redundant Computations with Flexible Attention

Raphael Shu, Hideki NakayamaarXiv 2016

Abstract: Recently, the attention mechanism plays a key role to achieve high performance for Neural Machine Translation models. However, as it computes a score function for the encoder states in all positions at each decoding step, the attention model greatly increases the computational complexity. In this paper, we investigate the adequate vision span of attention models in the context of machine translation, by proposing a novel attention framework that is capable of reducing redundant score computation dynamically. The term "vision span" means a window of the encoder states considered by the attention model in one step. In our experiments, we found that the average window size of vision span can be reduced by over 50% with modest loss in accuracy on English-Japanese and German-English translation tasks. These results indicate that the conventional attention mechanism performs a significant amount of redundant computation.

1. Introduction

In the world of Neural Machine Translation (NMT), the attention mechanism is a double-edged sword. While it allows models to handle long-range dependencies—such as identifying a verb at the end of a German sentence—it is computationally greedy. Standard "soft attention" forces the decoder to calculate a score for every single input word for every single output word, resulting in $O(N \times M)$ complexity.

As the field moves toward character-level translation or processing extremely long documents, this "global" approach becomes a massive bottleneck. Previous attempts at "Local Attention" utilized fixed-size windows, but these often fail when languages require significant reordering (e.g., English to Japanese). This paper introduces Flexible Attention, a mechanism that dynamically adjusts the "vision span" based on the current context, reducing redundant computation by over 50% with minimal impact on translation quality.

2. Methodology: The Flexible Attention Framework

The authors propose a framework that introduces a position-based penalty directly into the attention mechanism. Unlike standard attention, which treats all input positions equally until the final softmax, Flexible Attention predicts which parts of the source sentence are relevant at each step.

The Flexible Attention mechanism uses a dynamic penalty function to restrict the vision span of encoder states based on the decoder state.

The mechanism operates through four key stages:

  1. Tracking the Center: The model tracks the "center of attention" ($p_t$) derived from the previous decoding step.
  2. Dynamic Penalty: It calculates a penalty for input states based on their distance from this center. The "strength" of this penalty ($g(t)$) is predicted by a sigmoid function based on the current decoder state. If the model is translating a local phrase, $g(t)$ is high, creating a narrow window. If it needs to "jump" to a distant part of the sentence for reordering, $g(t)$ drops, allowing a wider search.
  3. Thresholding: During inference, any input state with a penalty above a certain threshold ($\tau$) is ignored entirely, skipping the expensive score calculation.
  4. Fine-tuning: The researchers use a specialized loss function during training to encourage the model to use the smallest vision span possible without hurting accuracy.

3. Experimental Setup

The approach was evaluated on two language pairs known for complex reordering requirements:

  • English-Japanese (En-Ja): Using the ASPEC corpus (1.5M training pairs).
  • German-English (De-En): Using WMT’15 data (4.5M training pairs). The study also tested character-based NMT on the En-Ja task to observe how the model handles significantly longer input sequences where computational savings are most critical.

4. Results and Discussion

The empirical findings confirm that global attention is overkill for the majority of decoding steps. Most translation happens in local "chunks." The model successfully learns to "open" its vision span specifically when it encounters reordering points, then "closes" it back down for the next local phrase.

Quantitative comparison of Global, Local, and Flexible Attention models across English-Japanese and German-English tasks.

As shown in the table above, Flexible Attention reduced the average window size by 56% for English-Japanese and 64% for German-English compared to the global attention baseline. These gains came with only a "modest loss" in accuracy. For En-Ja, the BLEU score only dipped from 35.01 to 34.78 while cutting the window size by more than half.

Computational Efficiency

  • CPU Performance: The model achieved a measurable speedup (approx. 10% faster) because the reduction in mathematical operations outweighed the overhead of the penalty calculation.
  • GPU Performance: Interestingly, the model was slightly slower on GPUs. Current GPU kernels are highly optimized for dense matrix multiplications; the overhead of calculating the dynamic penalty currently outweighs the savings of skipping computations in highly parallel environments.

5. Conclusion

Flexible Attention demonstrates that conventional attention mechanisms perform a significant amount of redundant computation. By integrating a soft penalty inside the softmax function, the model maintains a valid probability distribution while effectively "switching off" irrelevant words. Future work will focus on writing custom GPU kernels to realize these theoretical speed benefits on modern hardware, potentially making Flexible Attention a "force multiplier" for even more complex recurrent attention models.

Summary updated

BibTeX
@misc{shu2016reducing,
  author = {Raphael Shu and Hideki Nakayama},
  title = {{Reducing Redundant Computations with Flexible Attention}},
  year = {2016},
  eprint = {1612.06043},
  archivePrefix = {arXiv},
  url = {https://arxiv.org/abs/1612.06043},
}
Figure