Transformers Can Represent n-gram Language Models

Anej Svete, Ryan Cotterell
4/23/2024
cs.CLcs.AIcs.CC

No confident code implementation found for this paper. 1 possible match can be shown below.

Abstract

Existing work has analyzed the representational capacity of the transformer architecture by means of formal models of computation. However, the focus so far has been on analyzing the architecture in terms of language \emph{acceptance}. We contend that this is an ill-suited problem in the study of \emph{language models} (LMs), which are definitionally \emph{probability distributions} over strings. In this paper, we focus on the relationship between transformer LMs and $n$-gram LMs, a simple and historically relevant class of language models. We show that transformer LMs using the hard or sparse attention mechanisms can exactly represent any $n$-gram LM, giving us a concrete lower bound on their probabilistic representational capacity. This provides a first step towards understanding the mechanisms that transformer LMs can use to represent probability distributions over strings.

View on arXivView PDF

Code Implementations

No confident code match yet

We couldn't find an author-owned or strongly-evidenced community implementation for this paper. 1 weaker match is hidden by default — verify before relying on them.

No code implementations found yet.

Know of an implementation? Let us know in the comments below!

Similar Papers

Cite this paper

@article{svete2024transformers,
  title  = {Transformers Can Represent n-gram Language Models},
  author = {Anej Svete and Ryan Cotterell},
  year   = {2024},
  eprint = {2404.14994},
  archivePrefix = {arXiv},
  url    = {http://arxiv.org/abs/2404.14994v3}
}

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

Discussion