SYNTOLOGY HomeExplorerAtlasCodeMethodologyAboutDevelopersFeedPricing
Paper · 2411.07107 · ICLR · 2025

Training Neural Networks as Recognizers of Formal Languages

Brian Dusell, Ryan Cotterell, Anej Svete, Alexandra Butoi, Ghazal Khalighinejad, Josef Valvoda

arXiv · PDF · Open in the Atlas

Code that ran

8 of 9 samples (functions and classes) lifted from this paper's linked repositories executed on a synthesized input in Syntology's jail (0 of them constructed an object rather than computing a result; 1 honoured the contract we drafted, 1 violated it and 0 have no contract verdict; 6 failures of our instrument; 1 no recorded run), measured 2026-11-23; repository links from the Papers with Code archive attributed under CC BY-SA, no affiliation; bodies inline only under a permissive licence as GitHub detects it. Not a reproduction of the paper's results.

"Ran" means the function executed on a synthesized input and returned a value. It is not a reproduction of the paper's results. This record, dated, as JSON: /api/ran/2411.07107.json · badge: /api/ran/2411.07107.svg

Each repository's role is a label: a classifier's output recorded on the link, or, where no role is recorded, what the Papers with Code archive marked. The line under it names its basis. Neither says who wrote the code.

RepositoryRoleRan
rycolab/neural-network-recognizers canonical (classifier label)
classifier basis: census
8 ran · 1 no recorded run
FunctionStatusWhere it lives
build_softmax_vocab Ran
ran; our contract draft was wrong, not the code
rycolab/neural-network-recognizers/src/recognizers/neural_networks/vocabulary.py
code served (permissive licence) · get_code("37ba7b44c2f80edd")
How it ran

Ran in Syntology's sandbox on this synthesized input (drafted by a language model, Claude Haiku 4.5, prompt python_fixture_v1, through the batch API) and returned str. The image it ran in was not recorded. If your copy returns the same type on these inputs, it matched what we observed; nothing here checks that. It does NOT mean the output is correct: nothing has compared it to the paper.

import torch
import torch.nn as nn

torch.manual_seed(0)

class MockBuilder:
    def content(self, tokens):
        # Returns a representation of the content tokens
        return f"content({len(tokens)})"
    
    def catchall(self, name):
        # Returns a representation of a catchall token
        return f"+catchall({name})"
    
    def reserved(self, names):
        # Returns a representation of reserved tokens
        return f"+reserved({names})"

ARGS = {
    "tokens": ["hello", "world", "python"],
    "allow_unk": True,
    "use_eos": False,
    "builder": MockBuilder()
}
Setup block drafted by
a language model, Claude Haiku 4.5, prompt python_fixture_v1, through the batch API
Imports
torch — import names as written, not package names to install; a name the repository itself provides is not a package
Returned
type str — a str output has no array shape of its own; none is stated — the instrument coerces any output to an array; for a str output the recorded ndim 0 and dtype family float describe that coercion, not the output, and are not stated
Environment
image not recorded; re-verify against syntology-harvest-sandbox:v5-deps; not recorded for this sample: the harness installs a cuda-to-cpu shim (cuda_shim.py) before every sample and no run records whether a sample needed it; seed: none by the harness; any seed is in the setup block
divide Ran
ran; the contract check could not run (RAISES, DEP_MISSING or TIMEOUT)
rycolab/neural-network-recognizers/src/recognizers/analysis/plot_cross_entropy_vs_num_edits.py
code served (permissive licence) · get_code("ab34813074cc49bf")
How it ran

Ran in Syntology's sandbox on this synthesized input (drafted by a language model, Claude Haiku 4.5, prompt python_fixture_v1, through the batch API) and returned Tensor, ndim 2, dtype family float, shape (2, 4) as a later run recorded it. The image it ran in was not recorded. If your copy returns the same type, ndim and shape on these inputs, it matched what we observed; nothing here checks that. It does NOT mean the output is correct: nothing has compared it to the paper.

import torch
import numpy as np

torch.manual_seed(0)

# The divide function takes x which is unpacked into numer and denom
# It performs numer / denom, so both should support division
# Using small tensors as a simple case

numer = torch.tensor([[1.0, 2.0, 3.0, 4.0],
                      [5.0, 6.0, 7.0, 8.0]])

denom = torch.tensor([[2.0, 2.0, 2.0, 2.0],
                      [2.0, 2.0, 2.0, 2.0]])

x = (numer, denom)

ARGS = {
    "x": x
}
Setup block drafted by
a language model, Claude Haiku 4.5, prompt python_fixture_v1, through the batch API
Imports
numpy, torch — import names as written, not package names to install; a name the repository itself provides is not a package
Returned
type Tensor, ndim 2, dtype family float, shape (2, 4) — shape (2, 4) as a later run recorded it
dtype family
int means an integer dtype; float means any other dtype the instrument saw, bool and complex included (fixture_check.py records only these two families)
Environment
image not recorded; re-verify against syntology-harvest-sandbox:v5-deps; not recorded for this sample: the harness installs a cuda-to-cpu shim (cuda_shim.py) before every sample and no run records whether a sample needed it; seed: none by the harness; any seed is in the setup block
get_file_names_from_directory Ran
ran; our contract draft was wrong, not the code
rycolab/neural-network-recognizers/src/recognizers/neural_networks/prepare_data.py
code served (permissive licence) · get_code("ab6fb5ddcfea8962")
How it ran

Ran in Syntology's sandbox on this synthesized input (drafted by a language model, Claude Haiku 4.5, prompt python_fixture_v1, through the batch API) and returned tuple, ndim 2, dtype family float; no output shape is stated. The image it ran in was not recorded. If your copy returns the same type and ndim on these inputs, it matched what we observed; nothing here checks that. It does NOT mean the output is correct: nothing has compared it to the paper.

from pathlib import Path
import tempfile

# Create a temporary directory to use as the base directory
temp_dir = tempfile.TemporaryDirectory()
directory = Path(temp_dir.name)

# Define the arguments
ARGS = {
    "directory": directory,
    "use_next_symbols": True
}
Setup block drafted by
a language model, Claude Haiku 4.5, prompt python_fixture_v1, through the batch API
Imports
none outside the standard library — import names as written, not package names to install; a name the repository itself provides is not a package
Returned
type tuple, ndim 2, dtype family float — a tuple output has no array shape of its own; none is stated
dtype family
int means an integer dtype; float means any other dtype the instrument saw, bool and complex included (fixture_check.py records only these two families)
Environment
image not recorded; re-verify against syntology-harvest-sandbox:v5-deps; not recorded for this sample: the harness installs a cuda-to-cpu shim (cuda_shim.py) before every sample and no run records whether a sample needed it; seed: none by the harness; any seed is in the setup block
get_loss_terms Ran
ran; our contract draft was wrong, not the code
rycolab/neural-network-recognizers/src/recognizers/neural_networks/training_loop.py
code served (permissive licence) · get_code("dfd7c6df71691537")
How it ran

Ran in Syntology's sandbox on this synthesized input (drafted by a language model, Claude Haiku 4.5, prompt python_fixture_v1, through the batch API) and returned dict. The image it ran in was not recorded. If your copy returns the same type on these inputs, it matched what we observed; nothing here checks that. It does NOT mean the output is correct: nothing has compared it to the paper.

import torch
import torch.nn as nn

torch.manual_seed(0)

# Define a minimal model
class DummyModel(nn.Module):
    def __init__(self):
        super().__init__()
        self.linear = nn.Linear(4, 4)
    
    def forward(self, x):
        return self.linear(x)

# Define a minimal model interface
class DummyModelInterface:
    def __init__(self):
        self.output_padding_index = 0
    
    def get_logits(self, model, model_input):
        # Returns (recognition_logits, language_modeling_logits, next_symbols_logits)
        batch_size = 2
        recognition_logits = torch.randn(batch_size, 4)
        language_modeling_logits = torch.randn(batch_size, 5, 3)  # (batch, seq_len, vocab)
        next_symbols_logits = torch.randn(batch_size, 5, 4)  # (batch, seq_len, alphabet_size)
        return recognition_logits, language_modeling_logits, next_symbols_logits

# Create instances
model = DummyModel()
model_interface = DummyModelInterface()

# Create prepared_batch
batch_size = 2
seq_len = 5
vocab_size = 3
alphabet_size = 4
feature_dim = 4

model_input = torch.randn(batch_size, feature_dim)
expected_recognition_output = torch.randint(0, 2, (batch_size, 4)).float()
expected_language_modeling_output = torch.randint(0, vocab_size, (batch_size, seq_len))
expected_next_symbols_output = torch.randint(0, 2, (batch_size, seq_len, alphabet_size)).float()
next_symbols_padding_mask = torch.ones(batch_size, seq_len)
positive_output_lengths = torch.tensor([seq_len, seq_len], dtype=torch.float32)

prepared_batch = (
    model_input,
    (
        expected_recognition_output,
        expected_language_modeling_output,
        expected_next_symbols_output,
        next_symbols_padding_mask,
        positive_output_lengths
    )
)

ARGS = {
    'model': model,
    'model_interface': model_interface,
    'prepared_batch': prepared_batch,
    'numerator_reduction': 'none',
    'denominator_reduction': 'sum',
    'label_smoothing_factor': 0.1,
    'include_accuracy': True
}
Setup block drafted by
a language model, Claude Haiku 4.5, prompt python_fixture_v1, through the batch API
Imports
torch — import names as written, not package names to install; a name the repository itself provides is not a package
Returned
type dict — a dict output has no array shape of its own; none is stated — the instrument coerces any output to an array; for a dict output the recorded ndim 0 and dtype family float describe that coercion, not the output, and are not stated
Environment
image not recorded; re-verify against syntology-harvest-sandbox:v5-deps; not recorded for this sample: the harness installs a cuda-to-cpu shim (cuda_shim.py) before every sample and no run records whether a sample needed it; seed: none by the harness; any seed is in the setup block
get_smoothed_points Ran
ran; the contract check could not run (RAISES, DEP_MISSING or TIMEOUT)
rycolab/neural-network-recognizers/src/recognizers/analysis/plot_cross_entropy_vs_length.py
code served (permissive licence) · get_code("357c7b74e93367d1")
How it ran

Ran in Syntology's sandbox on this synthesized input (drafted by a language model, Claude Haiku 4.5, prompt python_fixture_v1, through the batch API) and returned tuple, ndim 2, dtype family float; no output shape is stated. The image it ran in was not recorded. If your copy returns the same type and ndim on these inputs, it matched what we observed; nothing here checks that. It does NOT mean the output is correct: nothing has compared it to the paper.

import numpy as np

# Construct arguments for get_smoothed_points
# The function expects:
# - xs: sequence of x-coordinates (numeric values)
# - ys: sequence of y-coordinates (numeric values)

# Create small test data with x values in range that makes sense for the function
# The function groups by x values from 0 to 500 in steps of 10
xs = [5, 15, 25, 35, 45, 55, 65, 75, 85, 95]
ys = [10.0, 12.5, 11.0, 13.5, 14.0, 12.0, 15.5, 16.0, 14.5, 17.0]

ARGS = {
    "xs": xs,
    "ys": ys
}
Setup block drafted by
a language model, Claude Haiku 4.5, prompt python_fixture_v1, through the batch API
Imports
numpy — import names as written, not package names to install; a name the repository itself provides is not a package
Returned
type tuple, ndim 2, dtype family float — a tuple output has no array shape of its own; none is stated
dtype family
int means an integer dtype; float means any other dtype the instrument saw, bool and complex included (fixture_check.py records only these two families)
Environment
image not recorded; re-verify against syntology-harvest-sandbox:v5-deps; not recorded for this sample: the harness installs a cuda-to-cpu shim (cuda_shim.py) before every sample and no run records whether a sample needed it; seed: none by the harness; any seed is in the setup block
get_test_accuracy Ran
ran, honoured the contract we drafted
rycolab/neural-network-recognizers/src/recognizers/analysis/plot_cross_entropy_vs_length.py
code served (permissive licence) · get_code("8aeac5c10121fbe0")
How it ran

Ran in Syntology's sandbox on this synthesized input (drafted by a language model, Claude Haiku 4.5, prompt python_fixture_v1, through the batch API) and returned float, ndim 0, dtype family float, shape () as a later run recorded it. The image it ran in was not recorded. If your copy returns the same type, ndim and shape on these inputs, it matched what we observed; nothing here checks that. It does NOT mean the output is correct: nothing has compared it to the paper.

import json
import tempfile
import os

# Create a temporary JSON file with the expected structure
temp_dir = tempfile.mkdtemp()
temp_file = os.path.join(temp_dir, "test_data.json")

data = {
    'scores': {
        'recognition_accuracy': 0.95
    }
}

with open(temp_file, 'w') as f:
    json.dump(data, f)

ARGS = {
    'fin': temp_file
}
Setup block drafted by
a language model, Claude Haiku 4.5, prompt python_fixture_v1, through the batch API
Imports
none outside the standard library — import names as written, not package names to install; a name the repository itself provides is not a package
Returned
type float, ndim 0, dtype family float, shape () — shape () as a later run recorded it
dtype family
int means an integer dtype; float means any other dtype the instrument saw, bool and complex included (fixture_check.py records only these two families)
Environment
image not recorded; re-verify against syntology-harvest-sandbox:v5-deps; not recorded for this sample: the harness installs a cuda-to-cpu shim (cuda_shim.py) before every sample and no run records whether a sample needed it; seed: none by the harness; any seed is in the setup block
load_prepared_labels_file Ran
ran, violated the contract we drafted
rycolab/neural-network-recognizers/src/recognizers/neural_networks/data.py
code served (permissive licence) · get_code("08bd77bfa41e19db")
How it ran

Ran in Syntology's sandbox on this synthesized input (drafted by a language model, Claude Haiku 4.5, prompt python_fixture_v1, through the batch API) and returned list, ndim 1, dtype family float; no output shape is stated. The image it ran in was not recorded. If your copy returns the same type and ndim on these inputs, it matched what we observed; nothing here checks that. It does NOT mean the output is correct: nothing has compared it to the paper.

import pathlib
import torch
import tempfile
import os

torch.manual_seed(0)

# Create a temporary directory and file
temp_dir = tempfile.mkdtemp()
temp_file = pathlib.Path(temp_dir) / "labels.pt"

# Create a small list of booleans and save it
labels = [True, False, True, False]
torch.save(labels, temp_file)

ARGS = {
    "path": temp_file
}
Setup block drafted by
a language model, Claude Haiku 4.5, prompt python_fixture_v1, through the batch API
Imports
torch — import names as written, not package names to install; a name the repository itself provides is not a package
Returned
type list, ndim 1, dtype family float — a list output has no array shape of its own; none is stated
dtype family
int means an integer dtype; float means any other dtype the instrument saw, bool and complex included (fixture_check.py records only these two families)
Environment
image not recorded; re-verify against syntology-harvest-sandbox:v5-deps; not recorded for this sample: the harness installs a cuda-to-cpu shim (cuda_shim.py) before every sample and no run records whether a sample needed it; seed: none by the harness; any seed is in the setup block
load_vocabulary_data_from_file Ran
ran; our contract draft was wrong, not the code
rycolab/neural-network-recognizers/src/recognizers/neural_networks/vocabulary.py
code served (permissive licence) · get_code("c83517b2f4da4069")
How it ran

Ran in Syntology's sandbox on this synthesized input (drafted by a language model, Claude Haiku 4.5, prompt python_fixture_v1, through the batch API) and returned VocabularyData. The image it ran in was not recorded. If your copy returns the same type on these inputs, it matched what we observed; nothing here checks that. It does NOT mean the output is correct: nothing has compared it to the paper.

import dataclasses
import pathlib
import torch
import tempfile
import os

torch.manual_seed(0)

# Create a temporary directory and file for testing
temp_dir = tempfile.mkdtemp()
temp_file = pathlib.Path(temp_dir) / "vocab.pt"

# Create vocabulary data and save it
vocab_data = {
    'tokens': ['hello', 'world', 'foo', 'bar', 'baz'],
    'allow_unk': True
}
torch.save(vocab_data, temp_file)

ARGS = {
    'path': temp_file
}
Setup block drafted by
a language model, Claude Haiku 4.5, prompt python_fixture_v1, through the batch API
Imports
torch — import names as written, not package names to install; a name the repository itself provides is not a package
Returned
type VocabularyData — a VocabularyData output has no array shape of its own; none is stated — the instrument coerces any output to an array; for a VocabularyData output the recorded ndim 0 and dtype family float describe that coercion, not the output, and are not stated
Environment
image not recorded; re-verify against syntology-harvest-sandbox:v5-deps; not recorded for this sample: the harness installs a cuda-to-cpu shim (cuda_shim.py) before every sample and no run records whether a sample needed it; seed: none by the harness; any seed is in the setup block
generate_batches Not yet run
unverified (harvested, no recorded run)
rycolab/neural-network-recognizers/src/recognizers/neural_networks/training_loop.py
code served (permissive licence) · get_code("4785d72514a2e8c3")
How it ran

no invocation recorded.

Also present in other papers' code

Of 9 samples lifted from this paper's linked repositories, 9 carry a function identity and 0 do not. Of the 9 distinct functions with an identity, 0 are also present in other papers whose code we hold (0 with at least one paper dated earlier, 0 the same month, 0 later) and 9 are only here among the 52,977 papers whose code Syntology holds (as of 2026-09-26).

Only here means: among the 52,977 papers whose code Syntology holds (51,887 with lifted samples, 1,090 through their assemblies only), as of 2026-09-26, no other paper's lifted samples or current assembly bricks contain an identical function body after normalisation.

Presence, not direction: an identical function body in two papers' repositories does not say who wrote it, which came from which, or that either paper's method rests on it. Matching is exact after normalisation, so a renamed or edited function is not matched. Dates are when papers appeared, not when code was written. Only .py files the harvester lifted are covered; notebooks are not read. A new-style arXiv id YYMM.NNNN dates a paper to the month 20YY-MM; otherwise Paper.year dates it to the year; otherwise it is undated. Dates are when the paper appeared, not when the code was written. Read 2026-11-23.

Repositories linked to this paper

Some links come from the archived Papers with Code dataset (CC BY-SA 4.0): attribution and licence.

Abstract

Characterizing the computational power of neural network architectures in terms of formal language theory remains a crucial line of research, as it describes lower and upper bounds on the reasoning capabilities of modern AI. However, when empirically testing these bounds, existing work often leaves a discrepancy between experiments and the formal claims they are meant to support. The problem is that formal language theory pertains specifically to recognizers: machines that receive a string as input and classify whether it belongs to a language. On the other hand, it is common instead to evaluate language models on proxy tasks, e.g., language modeling or sequence-to-sequence transduction, that are similar in only an informal sense to the underlying theory. We correct this mismatch by training and evaluating neural networks directly as binary classifiers of strings, using a general method that can be applied to a wide variety of languages. As part of this, we extend an algorithm recently proposed by Snaebjarnarson et al. (2025) for efficient length-controlled sampling of strings from regular languages. We provide results on a variety of languages across the Chomsky hierarchy for three neural architectures: a simple RNN, an LSTM, and a causally-masked transformer. We find that the RNN and LSTM often outperform the transformer, and that auxiliary training objectives such as language modeling can help, although no single objective uniformly improves performance across languages and architectures. Our contributions will facilitate theoretically sound empirical testing of language recognition claims in future work. We have released our datasets as a benchmark called FLaRe 1 (Formal Language Recognition), along with our code. 2

For agents

The same record, over MCP at https://syntology.ai/mcp:

get_harvested_code_for_paper("2411.07107")
get_code_for_paper("2411.07107")
have("2411.07107")

The run record, dated, one paper per request, free:

curl https://syntology.ai/api/ran/2411.07107.json

A badge for a README (the split and the date, never a ratio):

[![Syntology run record](https://syntology.ai/api/ran/2411.07107.svg)](https://syntology.ai/paper/2411.07107)

Connect an agent — have() is free.