Table of Contents
Fetching ...

Improve Transformer Models with Better Relative Position Embeddings

Zhiheng Huang, Davis Liang, Peng Xu, Bing Xiang

TL;DR

This work addresses how transformers encode positional information, arguing that fixed absolute embeddings underutilize relative position cues. It introduces four relative position embedding variants designed to increase interaction among queries, keys, and relative positions, with the fourth method generalizing the absolute embedding. On SQuAD1.1, the proposed method yields higher accuracy than prior approaches, and the experiments demonstrate robustness to longer sequences and competitive performance on GLUE. The approach provides a practical, near drop-in replacement for improving large models with modest computational budgets.

Abstract

Transformer architectures rely on explicit position encodings in order to preserve a notion of word order. In this paper, we argue that existing work does not fully utilize position information. For example, the initial proposal of a sinusoid embedding is fixed and not learnable. In this paper, we first review absolute position embeddings and existing methods for relative position embeddings. We then propose new techniques that encourage increased interaction between query, key and relative position embeddings in the self-attention mechanism. Our most promising approach is a generalization of the absolute position embedding, improving results on SQuAD1.1 compared to previous position embeddings approaches. In addition, we address the inductive property of whether a position embedding can be robust enough to handle long sequences. We demonstrate empirically that our relative position embedding method is reasonably generalized and robust from the inductive perspective. Finally, we show that our proposed method can be adopted as a near drop-in replacement for improving the accuracy of large models with a small computational budget.

Improve Transformer Models with Better Relative Position Embeddings

TL;DR

This work addresses how transformers encode positional information, arguing that fixed absolute embeddings underutilize relative position cues. It introduces four relative position embedding variants designed to increase interaction among queries, keys, and relative positions, with the fourth method generalizing the absolute embedding. On SQuAD1.1, the proposed method yields higher accuracy than prior approaches, and the experiments demonstrate robustness to longer sequences and competitive performance on GLUE. The approach provides a practical, near drop-in replacement for improving large models with modest computational budgets.

Abstract

Transformer architectures rely on explicit position encodings in order to preserve a notion of word order. In this paper, we argue that existing work does not fully utilize position information. For example, the initial proposal of a sinusoid embedding is fixed and not learnable. In this paper, we first review absolute position embeddings and existing methods for relative position embeddings. We then propose new techniques that encourage increased interaction between query, key and relative position embeddings in the self-attention mechanism. Our most promising approach is a generalization of the absolute position embedding, improving results on SQuAD1.1 compared to previous position embeddings approaches. In addition, we address the inductive property of whether a position embedding can be robust enough to handle long sequences. We demonstrate empirically that our relative position embedding method is reasonably generalized and robust from the inductive perspective. Finally, we show that our proposed method can be adopted as a near drop-in replacement for improving the accuracy of large models with a small computational budget.

Paper Structure

This paper contains 20 sections, 15 equations, 5 figures, 5 tables.

Figures (5)

  • Figure 1: Transformer architectures with the original absolute position embedding (left) and all other variations of relative position embeddings (right).
  • Figure 2: Absolute position embedding $p_{i}$.
  • Figure 3: Relative position weights $a_{ij}$.
  • Figure 4: Relative position (from -50 to 50) embedding weights on first transformer layer and first head for method 4.
  • Figure 5: Averaged attention weights across 12 heads on the first transformer layer for method 4.