Benchmarking Neural Networks on Formal Language Classes

Understanding the computational abilities of neural networks is key to predicting their performance on real-world tasks, and formal language theory offers a mature, rigorous framework for characterizing what kinds of problems they can solve. A large body of theoretical work has sought to pin down which formal language classes they can express, but this work relies on various simplifications (e.g., hard attention) that differ from practice. Empirical studies that use unsimplified architectures therefore provide an important supplement to this work, but they typically evaluate models on small sets of hand-picked languages, leaving the rest of a class drastically underexplored. To remedy this, we evaluate transformers, simple RNNs, and LSTMs on formal languages sampled randomly from a hierarchy of pertinent classes: $\mathscr{R}$-trivial, star-free, regular, and context-free languages. We sample from distributions with full support over each class, so expanding the coverage of a class is simply a matter of scale. Our experiments on a benchmark of 30 languages per class, which we call SoL (Sets of Languages), reveal that transformers recognize some $\mathscr{R}$-trivial and star-free languages but no non-star-free regular languages. All models learn to approximate context-free languages well but struggle to recognize them perfectly. We have publicly released our code.

Authors

Publication Details

Journal
arXiv
Published
2026-11-30
Primary Topic
semigroups and automata theory
Type
preprint
Controls
|||
ALL TIME
JAN
FEB
MAR
APR
MAY
JUN
JUL
AUG
SEP
OCT
NOV
preprint

Benchmarking Neural Networks on Formal Language Classes

Alexandra Butoi, Nicola Lorenzón, Brian DuSell, Ryan Cotterell et al.
arXiv
semigroups and automata theory
preprint

Benchmarking Neural Networks on Formal Language Classes

Alexandra Butoi, Nicola Lorenzón, Brian DuSell, Ryan Cotterell, Anej Svete, Taiga Someya, Selim Jerad
preprint en

Abstract

Understanding the computational abilities of neural networks is key to predicting their performance on real-world tasks, and formal language theory offers a mature, rigorous framework for characterizing what kinds of problems they can solve. A large body of theoretical work has sought to pin down which formal language classes they can express, but this work relies on various simplifications (e.g., hard attention) that differ from practice. Empirical studies that use unsimplified architectures therefore provide an important supplement to this work, but they typically evaluate models on small sets of hand-picked languages, leaving the rest of a class drastically underexplored. To remedy this, we evaluate transformers, simple RNNs, and LSTMs on formal languages sampled randomly from a hierarchy of pertinent classes: $\mathscr{R}$-trivial, star-free, regular, and context-free languages. We sample from distributions with full support over each class, so expanding the coverage of a class is simply a matter of scale. Our experiments on a benchmark of 30 languages per class, which we call SoL (Sets of Languages), reveal that transformers recognize some $\mathscr{R}$-trivial and star-free languages but no non-star-free regular languages. All models learn to approximate context-free languages well but struggle to recognize them perfectly. We have publicly released our code.

arXiv
semigroups and automata theory
AI Navigator

Ask Laika to Summarize, Analyze, and Connect papers live on the map.

Summarize Papers & Methodologies

Extract key findings, datasets, and comparative methods across publications.

Benchmark Rankings & Visual Analytics

Rank top research institutions, authors, funders, topics, and journals by Field-Weighted Citation Impact (FWCI) and paper volume with instant charts.

Connect Distant Disciplines

Bridge topological clusters on the map to find hidden collaborative intersections.

Laika access coming soon