What Accuracy Hides In Learned Transformer Programs
Organizations: Martian
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.
Figures & tables
| Task | Token accuracy (%) | Sequence accuracy (%) |
|---|---|---|
| Histogram | 100.00 | 100.00 |
| Sorting | 100.00 | 100.00 |
| Reversal | 99.96 | 99.79 |
| Dyck 1 | 99.89 | 98.60 |
| Dyck 2 | 99.35 | 95.75 |
| Double histogram | 98.41 | 97.45 |
| Task | Token (%) | Seq. (%) | Counterexample found? | Checked domain or first failure |
|---|---|---|---|---|
| Histogram | 100.00 | 100.00 | No | Exhaustive through |
| Sorting | 100.00 | 100.00 | No | Exhaustive through |
| Reversal | 99.96 | 99.79 | Yes | First failure at |
| Dyck 1 | 99.89 | 98.60 | Yes | Failure at trained length |
| Dyck 2 | 99.54 | 96.50 | Yes | Failure at trained length |
| Double histogram | 100.00 | 100.00 | No | Checked through |
Appendix figures & tables13 assets
Supplementary material from the paper’s appendix.
Appendix
| Task | Required answer |
|---|---|
| Histogram | At each position, the number of occurrences of its input value. |
| Double histogram | At each position, the number of distinct values with the same frequency as its input value. |
| Sorting | All input values in ascending order, preserving multiplicities. |
| Reversal | All input values in reverse order. |
| Frequency ranking | Each distinct value once, in decreasing frequency order. Equal frequencies are ordered by first occurrence. |
| Dyck 1 | At each prefix over one bracket type: balanced ( T ), valid but incomplete ( P ), or invalid ( F ). Invalidity persists through later prefixes. |
| Tasks | Ordinary input and boundaries | Total length |
|---|---|---|
| Sorting, reversal | Values 0 through 4; ; BOS and EOS | , 3 to 8 |
| Histogram, double histogram, frequency ranking | Values 0 through 5; ; BOS | , 2 to 8 |
| Dyck 1, Dyck 2 | Fifteen brackets of one or two types; BOS | |
| Addition | Digits 0 through 9, + , BOS; | |
| Addition with hints | Same operands and delimiters; one letter before each digit |
| Role | Seed | |
|---|---|---|
| Highlighted histogram program | 4/2/2 | 27983 |
| Histogram repair baseline and retrained example | 4/2/2 | 13877 |
| Initial sorting program | 3/16/4 | 27983 |
| Selected sorting model after coverage enrichment | 3/16/4 | 51229 |
| Baseline frequency program | 4/16/8 | 47389 |
| Enriched frequency program | 4/16/8 | 56543 |
| Task | Grid best | 13877 | 27983 | 47389 | 51229 | 56543 |
|---|---|---|---|---|---|---|
| Dyck 1 | 98.60 | 97.55 | 97.20 | 90.15 | 96.05 | 94.95 |
| Dyck 2 | 95.75 | 81.90 | 91.70 | 86.50 | 84.40 | 96.50 |
| Recipe | 13877 | 27983 | 47389 | 51229 | 56543 | Mean |
|---|---|---|---|---|---|---|
| Addition, | ||||||
| Carry balanced comparator | 90.23 | 92.76 | 89.48 | 94.22 | 91.36 | 91.61 |
| Position coupling | 89.46 | 91.66 | 91.75 | 91.57 | 89.91 | 90.87 |
| Entropy and longer training | 91.79 | 96.98 | 93.32 | 92.71 | 90.34 | 93.03 |
| Frequency ranking, , 250 epochs | ||||||
| Natural, request 20,000 | 80.90 | 81.78 | 82.40 | 81.84 | 81.97 | 81.78 |
| Recipe | Seed | Epochs | Sequence result | |
|---|---|---|---|---|
| Addition length sampling | 4/16/2 | 47389 | 250 | 2.73 to 58.48 |
| Hints length sampling | 4/16/8 | 56543 | 250 | 39.66 to 65.20 |
| Final addition | 4/24/8 | 47389 | 150 | 76.30 |
| Final hints | 4/24/8 | 51229 | 500 | 84.22 |
| Condition | 13877 | 27983 | 47389 | 51229 | 56543 | Mean |
|---|---|---|---|---|---|---|
| Histogram enrichment 0.45 | 0 | 0 | 0 | 0 | 0 | 0.0 |
| Sorting natural baseline | 13 | 9 | 4 | 9 | 20 | 11.0 |
| Sorting high count 0.45 | 76 | 47 | 33 | 34 | 49 | 47.8 |
| Sorting high count 0.15 | 262 | 85 | 62 | 31 | 67 | 101.4 |
| Sorting high count 0.30 | 579 | 128 | 397 | 29 | 16 | 229.8 |
| Sorting failure cases 0.30 | 13 | 15 | 51 | 22 | 67 | 33.6 |
| Task | Seed | Result | |
| Initial histogram | 4/2/2 | 27983 | Python failure at . |
| Initial sorting | 3/16/4 | 27983 | Python failure at . |
| Reversal | 4/16/4 | 13877 | Python failures at . |
| Dyck 1 | 4/16/8 | 47389 | Replayed failure at trained length . |
| Dyck 2 grid | 2/16/8 | 27983 | Replayed failure at . |
| Dyck 2 depth recipe | 6/16/8 | 56543 | Model test failure at ; solver time limit reached. |
| Task | Ordinary input | Program answer | Required answer | |
|---|---|---|---|---|
| Sorting | 8 | |||
| Reversal | 5 | |||
| Addition | 6 | |||
| Addition with hints | 8 |
| Contribution | Answer 6 | Answer 7 |
|---|---|---|
| Other contributions combined | ||
| First count, value 7 | 8.769 | |
| Sum of counts, value 49 | 102.845 | 192.605 |
| Total | 54.409 | 67.800 |
| Answer class | Baseline total | Enriched total |
|---|---|---|
| 0 | 6.73346 | |
| 1 | 10.88742 | 13.77100 |
| 2 | 3.82967 | |
| 3 | 7.30950 | 9.03644 |
| 4 | 14.35276 | 13.76628 |
| 5 |
| Task | Layers | Computation | ||
|---|---|---|---|---|
| Histogram | 1 | 0 | 1 | Equality count and count label lookup |
| Reversal | 2 | 1 | 0 | Locate end, compute mirror position, copy token |
| Sorting | 3 | 0 | Value counts, cumulative counts and lookup decoding | |
| Dyck 1 | 6 | 1 | 2 | Causal balance and bracket matching |
| Dyck 2 | 6 | 1 | 4 | Same construction with two bracket types |
| Addition | 1 | 0 | Carry propagation with fixed width output |
| Study | Runs | Hardware | Time |
|---|---|---|---|
| Baseline grid | 2,160 | GPU workers | About 260 to 415 GPU hours |
| Histogram and sorting repair | 35 | T4, five workers | About 3 to 8 GPU hours |
| Enriched frequency and double histogram | 10 | Shared GPU VM | 11.19 hours |
| Addition length sampling | 10 | A100 40 GB | About 2.5 hours |
| Addition and hints, 150 epochs | 10 | A100, ten workers | About 45 minutes |
| Bracket models with six layers | 10 | A100 40 GB | About 2.8 hours |
Transformer Interpretability
Transformer interpretability studies how attention, feed-forward layers, and hidden representations support model predictions and behavior.
See all 338 papers