Modeling Recurrence for Transformer

Jie Hao, Xing Wang, Baosong Yang, Longyue Wang, Jinfeng Zhang, Zhaopeng Tu

Abstract

While the Transformer architecture revolutionized natural language processing by replacing recurrence with self-attention, it sacrificed the "recurrent bias" essential for modeling sequential structures. This paper introduces an auxiliary Recurrence Encoder, specifically a novel Attentive Recurrent Network (ARN), that operates alongside the standard Transformer to capture deep syntactic and semantic dependencies. Experimental results demonstrate significant improvements in translation quality with minimal computational overhead.

Introduction

The Transformer model, characterized by its "Attention is All You Need" philosophy, enables massive parallelism by treating sequences as sets of interacting elements. However, this approach lacks explicit recurrence, making it challenging to capture the hierarchical relationships and structural representations inherent in language. Previous attempts to address this limitation often involved complex hybrid models or simple positional encodings. This research argues that the Transformer still lacks a "recurrent bias"—the ability to incrementally refine representations based on sequential context—which limits its capacity for complex sentence structures.

Methodology

The authors propose augmenting the Transformer with an additional Recurrence Encoder that runs in parallel to the standard Self-Attention (SAN) encoder.

The parallel architecture of the Self-Attention Encoder and the proposed Recurrence Encoder.

The Recurrence Encoder

This module processes word embeddings to output a sequence of hidden states. Two versions were evaluated:

  1. Standard RNN: A bidirectional GRU/LSTM.
  2. Attentive Recurrent Network (ARN): A novel architecture combining global attention modeling with sequential refinement. Instead of recurring over individual words, the ARN recurrently revises its internal representations over feature vectors extracted via attention.
Comparison between a standard Recurrent Neural Network (a) and the proposed Attentive Recurrent Network (b).

Integration Strategies

The study explored two methods for feeding recurrent information into the decoder:

  • Gated Sum: The decoder attends to both encoders simultaneously, merging results via a learnable gate.
  • Stack: The decoder attends to the SAN encoder first, using that output as a query to attend to the Recurrence Encoder.

A key finding was the "short-cut" effect: a single-layer recurrence encoder connected directly to the top layer of the decoder outperformed deeper configurations, providing an efficient path for gradient flow and sequential information.

Experimental Setup

The model was evaluated on two large-scale machine translation benchmarks:

  • WMT14 English-German: 4.6 million sentence pairs.
  • WMT17 Chinese-English: 20.6 million sentence pairs.

Key Results and Insights

The proposed approach consistently outperformed the baseline Transformer across different model sizes (Base and Big).

  • Translation Quality: On WMT14 En-De, the "Base" model improved BLEU scores from 27.31 to 28.21 (+0.9). On WMT17 Zh-En, the "Base" model saw an increase from 24.13 to 24.70.
  • Efficiency: The 1-layer ARN "short-cut" only reduced training speed by approximately 3%, maintaining practical feasibility.
  • Linguistic Probing: Probing tasks confirmed that the model captures significantly more syntactic information, such as tree depth and constituent structure, compared to the base Transformer.
  • Complementary Representations: Self-attention excels at global modeling, while recurrence is superior at capturing local, sequential, and hierarchical structures. The ARN leverages both by using attention to summarize the sequence before applying recurrence.

Conclusion

Integrating a recurrent bias into the Transformer via a parallel Recurrence Encoder significantly enhances its ability to model language structure. The Attentive Recurrent Network (ARN) proves to be a powerful and efficient mechanism for this purpose. Future work may explore the impact on inference latency and the generalization of this architecture to other tasks like reading comprehension or natural language inference.

Summary updated

BibTeX
@inproceedings{hao2019modeling,
  author = {Jie Hao and Xing Wang and Baosong Yang and Longyue Wang and Jinfeng Zhang and Zhaopeng Tu},
  title = {{Modeling Recurrence for Transformer}},
  booktitle = {Conference of the North American Chapter of the Association for Computational Linguistics},
  year = {2019},
  doi = {10.18653/v1/n19-1122},
}
Figure