Transformer-XL: Attentive Language Models Beyond a Fixed-Length Context

Zihang Dai, Zhilin Yang, Yiming Yang, Jaime Carbonell, Quoc V. Le +1 more
1/9/2019
cs.LGcs.CLstat.ML

Official code: kimiyoung/transformer-xl (3,717 stars, Apache-2.0, last commit 2022-09-21).

Abstract

Transformers have a potential of learning longer-term dependency, but are limited by a fixed-length context in the setting of language modeling. We propose a novel neural architecture Transformer-XL that enables learning dependency beyond a fixed length without disrupting temporal coherence. It consists of a segment-level recurrence mechanism and a novel positional encoding scheme. Our method not only enables capturing longer-term dependency, but also resolves the context fragmentation problem. As a result, Transformer-XL learns dependency that is 80% longer than RNNs and 450% longer than vanilla Transformers, achieves better performance on both short and long sequences, and is up to 1,800+ times faster than vanilla Transformers during evaluation. Notably, we improve the state-of-the-art results of bpc/perplexity to 0.99 on enwiki8, 1.08 on text8, 18.3 on WikiText-103, 21.8 on One Billion Word, and 54.5 on Penn Treebank (without finetuning). When trained only on WikiText-103, Transformer-XL manages to generate reasonably coherent, novel text articles with thousands of tokens. Our code, pretrained models, and hyperparameters are available in both Tensorflow and PyTorch.

View on arXivView PDF

Code Implementations(1)

Apache-2.0
3,717763Shell, PythonJan 8, 20194 years agoApache-2.0

Similar Papers

Cite this paper

@article{dai2019transformerxl,
  title  = {Transformer-XL: Attentive Language Models Beyond a Fixed-Length Context},
  author = {Zihang Dai and Zhilin Yang and Yiming Yang and Jaime Carbonell and Quoc V. Le and Ruslan Salakhutdinov},
  year   = {2019},
  eprint = {1901.02860},
  archivePrefix = {arXiv},
  url    = {https://arxiv.org/abs/1901.02860}
}

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/1901.02860.svg)](https://codeofpaper.com/paper/1901.02860)

Discussion