Universal Transformers

Mostafa Dehghani, Stephan Gouws, Oriol Vinyals, Jakob Uszkoreit, Lukasz Kaiser

Introduction

Since their introduction, Transformers have dominated sequence modeling due to their ability to process entire sequences in parallel, a stark contrast to inherently sequential Recurrent Neural Networks (RNNs). However, this speed comes at a cost: standard Transformers lack the "recurrent inductive bias" that allows RNNs to naturally excel at tasks requiring iterative or recursive logic.

Standard Transformers rely on a fixed stack of distinct layers, making them essentially fixed-depth circuits. This architecture struggles to generalize to sequence lengths longer than those seen during training. For example, a model trained to copy strings of length 20 might fail on length 100. Furthermore, standard Transformers are not "computationally universal" (Turing-complete) because their total computation is fixed regardless of the input's complexity.

To bridge this gap, researchers introduced the Universal Transformer (UT), a novel architecture that combines the parallel efficiency of the Transformer with the recursive inductive bias of RNNs. By applying self-attention recurrently over "depth" and incorporating a dynamic halting mechanism, the UT achieves superior generalization on algorithmic tasks and sets new benchmarks in natural language understanding.

Methods: The Universal Transformer Architecture

The Universal Transformer generalizes the standard Transformer by introducing recurrence over the model's depth.

Universal Transformer Architecture

The architecture relies on several core modifications:

  1. Recurrence over Depth: Instead of passing data through a stack of $L$ different layers, the UT passes the sequence through the same recurrent layer multiple times (for $T$ steps). In each step, the model applies multi-head self-attention followed by a transition function, such as a position-wise feed-forward network or a depth-wise separable convolution.
  2. Weight Sharing: Because the exact same layer is utilized at every step, parameters are tied across the "depth" (or time steps) of the model. This makes the UT highly parameter-efficient and encourages it to learn a general transformation rule rather than a sequence of specific, layer-bound transformations.
  3. Dynamic Halting (ACT): The authors integrate Adaptive Computation Time (ACT), allowing the model to dynamically decide how many processing steps to apply to each individual symbol in a sequence. More ambiguous or complex tokens can be processed for more steps before the model moves to the next stage.
  4. Coordinate Embeddings: To help the model keep track of its state, the authors use two-dimensional embeddings representing both position (the index of the token in the string) and time (the current recurrent step).

Key Insights and Ideas

The architectural changes in the Universal Transformer yield several profound theoretical and practical benefits:

  • Turing-Completeness: Unlike the standard Transformer, the UT is theoretically Turing-complete. Given sufficient memory and steps, it can simulate any computer program, making it "computationally universal."
  • Generalization through Recurrence: By learning a single, shared transformation, the UT learns the underlying logic of a task (like string reversal) rather than just a fixed-length mapping. This allows it to perform nearly perfectly on sequences up to 10x longer than those it was trained on.
  • Weight Sharing as Regularization: Sharing weights across layers acts as a powerful regularizer. This helps the model perform better on smaller datasets where standard Transformers often overfit.
Ponder Time Visualization
  • The "Pondering" Effect: Visualizations of the dynamic halting mechanism (ACT) reveal that the model naturally spends more steps on tokens that are critical for reasoning. For instance, when answering a question based on a set of facts, the model "ponders" longer on the specific entities and actions needed to deduce the answer, while spending fewer steps on irrelevant filler words.

Key Results

The UT was evaluated across a diverse set of benchmarks, demonstrating strong performance across the board:

  • Language Understanding (bAbI): The UT reached state-of-the-art results on the bAbI question-answering dataset. It failed zero tasks in the 10K training regime and significantly outperformed the standard Transformer in the data-scarce 1K regime.
  • Language Modeling (LAMBADA): On the challenging LAMBADA dataset, which requires broad context to predict a missing word, the UT achieved a new state-of-the-art, significantly outperforming both LSTMs and standard Transformers.
  • Machine Translation: On the standard WMT14 En-De dataset, the UT improved upon the base Transformer by 0.9 BLEU, reaching 28.9 BLEU with a similar parameter count.
  • Algorithmic Mastery: While standard Transformers failed on long-sequence generalization for tasks like "Copy" and "Addition" (e.g., generalizing from length 40 to 400), the UT achieved near-perfect accuracy.

Limitations and Future Work

While the Universal Transformer is highly effective, the authors noted that the dynamic halting mechanism (ACT) marginally degraded performance on large-scale machine translation tasks. This suggests that the trade-off between adaptive computation and accuracy in high-resource, complex generation settings requires further refinement.

Future work could explore more sophisticated transition functions or alternative halting criteria to improve the efficiency of the "pondering" process. Ultimately, the UT's ability to learn recursive, universal transformations represents a significant step toward building more data-efficient and generalizable AI systems.

Summary updated

BibTeX
@inproceedings{dehghani2019universal,
  author = {Mostafa Dehghani and Stephan Gouws and Oriol Vinyals and Jakob Uszkoreit and Lukasz Kaiser},
  title = {{Universal Transformers}},
  booktitle = {International Conference on Learning Representations},
  year = {2019},
}
Figure