Emergent Stack Representations in Modeling Counter Languages Using Transformers

Utkarsh Tiwari, Aviral Gupta, Michael Hahn
2/3/2025
cs.CLcs.LG
transformer-attention

No confident code implementation found for this paper.

Abstract

Transformer architectures are the backbone of most modern language models, but understanding the inner workings of these models still largely remains an open problem. One way that research in the past has tackled this problem is by isolating the learning capabilities of these architectures by training them over well-understood classes of formal languages.

Show full abstract

We extend this literature by analyzing models trained over counter languages, which can be modeled using counter variables. We train transformer models on 4 counter languages, and equivalently formulate these languages using stacks, whose depths can be understood as the counter values. We then probe their internal representations for stack depths at each input token to show that these models when trained as next token predictors learn stack-like representations. This brings us closer to understanding the algorithmic details of how transformers learn languages and helps in circuit discovery.

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. Any repos shown below are weak matches — 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{tiwari2025emergent,
  title  = {Emergent Stack Representations in Modeling Counter Languages Using Transformers},
  author = {Utkarsh Tiwari and Aviral Gupta and Michael Hahn},
  year   = {2025},
  eprint = {2502.01432},
  archivePrefix = {arXiv},
  url    = {http://arxiv.org/abs/2502.01432v1}
}

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

Discussion