From Interpolation to Extrapolation: Complete Length Generalization for Arithmetic Transformers

Shaoxiong Duan, Yining Shi, Wei Xu
10/18/2023
cs.LGcs.CL

Official code: shaoxiongduan/AttentionBiasCalibration (7 stars, last commit 2024-09-19).

Abstract

In this paper, we investigate the inherent capabilities of transformer models in learning arithmetic algorithms, such as addition and parity. Through experiments and attention analysis, we identify a number of crucial factors for achieving optimal length generalization. We show that transformer models are able to generalize to long lengths with the help of targeted attention biasing. In particular, our solution solves the Parity task, a well-known and theoretically proven failure mode for Transformers. We then introduce Attention Bias Calibration (ABC), a calibration stage that enables the model to automatically learn the proper attention biases, which we show to be connected to mechanisms in relative position encoding. We demonstrate that using ABC, the transformer model can achieve unprecedented near-perfect length generalization on certain arithmetic tasks. In addition, we show that ABC bears remarkable similarities to RPE and LoRA, which may indicate the potential for applications to more complex tasks.

View on arXivView PDF

Code Implementations(1)

Repo for the paper on Attention Bias Calibration for Transformer models

70PythonAug 13, 20232 years ago

Similar Papers

Cite this paper

@article{duan2023from,
  title  = {From Interpolation to Extrapolation: Complete Length Generalization for Arithmetic Transformers},
  author = {Shaoxiong Duan and Yining Shi and Wei Xu},
  year   = {2023},
  eprint = {2310.11984},
  archivePrefix = {arXiv},
  url    = {http://arxiv.org/abs/2310.11984v3}
}

Add a badge to your README

Shows whether official code is linked for this paper.

Code of Paper badge
[![Code of Paper](https://codeofpaper.com/badge/2310.11984.svg)](https://codeofpaper.com/paper/2310.11984)

Discussion