English

Can Transformers Learn $n$-gram Language Models?

Computation and Language 2024-10-07 v1

Abstract

Much theoretical work has described the ability of transformers to represent formal languages. However, linking theoretical results to empirical performance is not straightforward due to the complex interplay between the architecture, the learning algorithm, and training data. To test whether theoretical lower bounds imply \emph{learnability} of formal languages, we turn to recent work relating transformers to nn-gram language models (LMs). We study transformers' ability to learn random nn-gram LMs of two kinds: ones with arbitrary next-symbol probabilities and ones where those are defined with shared parameters. We find that classic estimation techniques for nn-gram LMs such as add-λ\lambda smoothing outperform transformers on the former, while transformers perform better on the latter, outperforming methods specifically designed to learn nn-gram LMs.

Keywords

Cite

@article{arxiv.2410.03001,
  title  = {Can Transformers Learn $n$-gram Language Models?},
  author = {Anej Svete and Nadav Borenstein and Mike Zhou and Isabelle Augenstein and Ryan Cotterell},
  journal= {arXiv preprint arXiv:2410.03001},
  year   = {2024}
}
R2 v1 2026-06-28T19:07:51.253Z