Manuscript Offprint

arXiv:2610.22891

What Accuracy Hides In Learned Transformer Programs

Jonathan Lee, Narmeen Oozeer, Philip Quirke

ABSTRACT

Transformer Programs (TP) (Friedman et al., 2023) constrain a Transformer’s architecture so that its learned computation can be extracted as readable Python code. TP expose learned computations, but token accuracy can hide incorrect complete answers. In this work, we examine how program inspection provides insights beyond accuracy scores and helps guide training. We first evaluated TP on nine algorithmic tasks. We compared token accuracy with accuracy on complete output sequences and checked for failures missed by sampled tests. Further, we assessed training data improvements informed by program inspection and failure analysis, finding gains in sequence accuracy on several tasks. We examined a counting task where a program achieved 100% accuracy on sampled test sequences but failed on another input using the symbols and lengths allowed during training. The program counted correctly, but the required answer was missing from its output labels. After adding training examples with larger counts, the retrained models passed exhaustive evaluation over the bounded domain. In the frequency ranking task, inspection showed how correct counts contributed to incorrect answers in programs trained before and after changes to the training data. Finally, we studied constraints imposed by TP training and operations. The TP training process can lead to accuracy losses late in training. Our reference constructions also show how composing the restricted TP operations can use many layers or large lookup tables.

1 INTRODUCTION

Our goal is to study programs where we can inspect the computations and whose correctness we can check over a defined input domain. Transformer Programs (TP) constrain a Transformer's architecture so that its learned computation can be extracted as readable, executable Python code (Friedman et al., 2023). This enables us to follow the calculations in the extracted code and compare its outputs with the required answers. Having the code available allows us to understand the underlying computations and verify whether the program is correct giving interpretability by construction.

In order to establish correctness for a learned program, we require expressivity, trainability and verifiability (Figure 1). First, the architecture should be expressive enough to represent a correct program for a given task. However, just because a program can be represented does not mean that it will be learned. The second requirement is trainability. During training, soft choices are gradually sharpened toward the discrete choices required for program extraction. Training must find a correct program and retain its performance as these choices become discrete. The

Constrained

Transformer

Discrete computation

Extracted Python

program

Readable and

executable

  1. Expressivity

Can the architecture represent a correct solution?

  1. Trainability

Can training find and retain it?

  1. Verifiability

Can we prove task algorithm correctness (in a bounded domain)?

Figure 1: We consider three distinct abilities: architectural expressivity, learning during training, and algorithmic verification.

ing must find a correct program and retain its performance as these choices become discrete. The third requirement is verifiability, which allows us to establish whether the program achieves correctness over the claimed domain.

Existing work evaluates TP using token accuracy (Friedman et al., 2023; Oosterlaar et al., 2024). For the tasks we study, a complete answer receives a score of one only if every scored output token is correct, and zero otherwise. We report this sequence accuracy as well as token accuracy because a partly correct output does not solve the task. Several tasks achieve high token accuracy but much lower sequence accuracy. Even perfect sequence accuracy on a sampled test set does not guarantee correctness. One of our histogram programs, which labels each input value with the number of times it appears, achieves 100% sequence accuracy on its sampled test set. However, it fails on seven copies of 4, an input using the symbols and lengths allowed during training. The program correctly counts seven occurrences, but seven is not among its available answer labels. It instead returns six at every position. A failure that the sampled test set missed is revealed by checking this input, while inspecting the computation allows us to discover why the answer is wrong.

We evaluate nine algorithmic tasks (Table 1) and examine the histogram and frequency ranking programs in detail. We trace their computations on failing inputs to explain how they produce incorrect answers. For histogram, the diagnosis motivates adding training examples with larger counts. For frequency ranking, we compare programs trained before and after changes motivated by earlier error analysis, examining which computations changed and which failures remain. We use training data enrichment to emphasize rare or missing cases. We make the following three contributions:

  1. Evaluation of TP with complete answers and a formal verifier. We evaluate token accuracy alongside accuracy on complete output sequences and use a formal verifier to search for violations of task specifications, checking counterexamples by program execution. High token accuracy can conceal incorrect complete answers. Counterexamples also reveal failures in programs that achieve perfect sequence accuracy on sampled tests.

  2. Program analysis and informed training improvements. We use computational diagnoses and observed failures to guide changes to training data. For histogram, adding examples with larger counts produces retrained models that answer every input correctly within the checked domain. Training changes that rebalance operand lengths also improve addition and addition with hints. Our frequency ranking analysis explains how correct counts contribute to incorrect answers in programs trained both before and after enrichment.

  3. Analysis of constraints on the programs and their training. We show that accuracy can fall as training moves from soft choices toward the discrete choices required for executable code. Our reference constructions also show how implementing some operations can require many layers or large lookup tables, but we do not claim that these constructions are minimal. The cost of verification limits our correctness checks to small input domains. Our frequency ranking analyses explain particular answers, but do not recover the full ranking algorithms.

References (42)

  • Position coupling: Improving length generalization of arithmetic Transformers using task structure (opens arXiv in a new tab)
  • Learning Transformer programs (opens arXiv in a new tab)
  • Categorical Reparameterization with Gumbel-Softmax
  • Adaptive Transformer programs
  • Learning Transformer programs even better
  • Understanding addition in Transformers (opens arXiv in a new tab)
  • The reproduction study by Oosterlaar et al. (2024) adds addition and addition with hints
  • Equal frequencies are ordered by first occurrence.</td></tr><tr><td>Dyck 1</td><td>At each prefix over one bracket type: balanced (T), valid but incomplete (P), or invalid (F)
  • The beginning, end and padding tokens are $<s>$, $</s>$ and $<pad>$, respectively
  • The first tokenized a whole answer as one token instead of separate digits
  • There are 48 configurations per task, and 5 seeds per configuration across 9 tasks
  • Adam optimizer is used with a learning rate of 0.05
  • For example, depending on whether the natural frequency request is 20,000 or 50,000, we end up with 16,200 or 40,500 examples to train with, respectively
  • We first explored greater depth and variations in the training
  • The histogram model with 42 exhaustive failures is not the highlighted program from Section 4.1
  • The comparisons shown here retained combinations of changes that were made together to the training recipe
  • Entropy regularization helped the two weakest comparator seeds but hurt the strongest one
  • It adds no zero padding, allows repetition, and does not impose a disjoint partition of the finite input space
  • Each task group has its own configuration and comparator
  • It targets a $40\%$ quota of inputs with at least three distinct values tied at the maximum count
  • The ordinary input length in this case is between 1 and 8
  • The histogram domain of 335,922 legal inputs with ordinary lengths from 1 to 7, over 6 symbols, is examined
  • It was successful on 335,700 other inputs
  • Seed 51229 (L4/H24/M8) attained a soft sequence accuracy of $90.50\%$ at epoch 71 and a final score of $56.12\%$ at 500 epochs
  • TPV (verified-ai, 2025) reconstructs the hard model from its weights and translates the operations into constraints for Z3
  • Sorting must preserve the input multiset and place it in ascending order; reversal must reproduce the exact reversed sequence
  • The initial histogram and sorting programs are grid selections and have counterexamples
  • The sorting example in the table shows that the program changes an input value rather than merely placing it at the wrong rank
  • (( ) (( ) ( ) ) ( ) )
  • Boundary tokens are omitted
  • This example reflects a failure of the task specification, but not evidence of failure inside the enriched training support, whose minimum ordinary length is three
  • For the example provided for sorting, the full set of ordinary strings of length between one and six over five symbols requires the model to consider 19,530 inputs
  • To determine the classification logic of the program for this input, we manually trace its operations and add the associated classifier coefficients
  • As shown by the source code provided, operations similar to those shown for the first position occur for the other six positions, with class seven winning and class six the runner up at each
  • The baseline is made up of 2145 lines of code, and the enriched program is made up of 2022 lines of code
  • These states distinguish generating, blocking and propagating a carry (Quirke & Barez, 2024)
  • A lookup table reads those statistics together with the requested output position and returns the corresponding ranked value
  • 48 configurations for nine tasks with five seeds each
  • The first two rows are extrapolated GPU hours under the assumptions below; remaining entries are elapsed execution windows
  • Its endpoints assume either unchanged elapsed time per run or unchanged device throughput as worker sharing increases
  • their durations sum to 105.33 hours, but their combined execution window is 11.19 hours
  • Complete project timing and allocation records are unavailable