Reproduce “Transformers Can Represent $n$-gram Language Models” on OpenResearch

Run Claude Code, Codex or any coding agent as a research agent: literature, hypotheses and experiments on your laptop, cluster or cloud GPUs.

Universal app for Apple silicon and Intel. Requires macOS 11 or later.

About this paper

Anej Svete, Ryan Cotterell

This paper provides the first formal results on the probabilistic representational capacity of Transformer Language Models by demonstrating they can exactly represent any n-gram Language Model. It establishes concrete lower bounds on their capabilities by providing constructive proofs for various architectural configurations and attention mechanisms.

Key insights

  • Transformers can implement n-gram language models through various internal mechanisms, including dedicated attention heads for each history position, iterative information accumulation across layers, or complex decoding of dense, packed representations within a single layer and head.
  • The representational capacity of Transformers for probabilistic models depends on the specific attention mechanism (e.g., hardmax vs. sparsemax) and the design of positional encodings and internal transformations.
  • The internal space complexity for exact n-gram representation grows proportionally to the alphabet size raised to the power of the n-gram context length, indicating substantial resource requirements for storing full history states.

Summary by alphaXiv.

Tip: change arxiv.org to autoarxiv.org in any arXiv abstract link to open the paper here.