BPE X-Ray Vision

Compiling token spellings into weight space for character-level tasks in frozen models

Drag the lens to see the text behind Qwen3’s token IDs. The bars under each token show its letter counts. In str | aw | berry, the highlighted bars add up to three r’s. The demo uses Qwen3’s recorded tokenization.

How many r’s are in strawberry? Qwen3’s tokenizer splits the quoted word into str | aw | berry. The model receives three IDs and looks up learned vectors. To count letters, it has to recover the spelling from those vectors. The tokenizer already has the exact text.

BPE X-Ray puts that spelling lookup inside the model. I compile the tokenizer’s vocabulary into fixed tables indexed by token ID. Looking up the three tokens gives 1 + 0 + 2 = 3 occurrences of r. That’s the weight-space intervention. The lookup runs in the forward pass while the pretrained weights stay frozen.

The X-Ray ALU computes and writes the answer when it sees an [XRAY …] tag, with no training. The Word Retina uses trained adapters to feed spelling features into hidden layers, so the model can answer a plain-language question about a quoted word.

With the input IDs fixed, lowering berry’s r count by one changes the model’s answer from 3 to 2. Try it in the demo.

25 → 100%two-shot accuracy across six held-out tasks with the ALU on Qwen3-0.6B
97.1%on four held-out letter tasks with the Word Retina, vs. 71.7% for LoRA
88%of feature edits followed with input tokens fixed (44 of 50 trials)
96.9%on letter tasks with compound pseudowords, vs. 64.4% for LoRA

Token Blindness

Byte-pair encoding groups text into tokens that can contain several letters. The model receives token IDs and looks up their embeddings. Earlier work measured how much spelling information models recover from those learned representations. I test what changes when the forward pass has an explicit lookup for the letters.

I built the benchmark from 418 training words and 162 held-out English words, with no overlap between the sets. The four perceptual tasks ask the model to count letters, measure word length, find the nth letter, or detect an adjacent double. The other three ask it to delete a letter, replace a letter, or reverse the word. I also test unfamiliar strings, alternate token splits, and tasks held out from training.

Figure 1. Evaluation splits, shown with their real Qwen3 tokenizations. Generated pseudowords reduce reliance on familiar spellings. In cross-token doubles, the only repeated letter straddles a token boundary. Multi-word count and anagram detection are never seen in training.

Frozen Qwen3-0.6B-Base scores 19.1% zero-shot over the seven tasks and 25.0% 2-shot over six, including 0% on reverse and rot13. On the same six-task, two-shot evaluation, Qwen3-1.7B reaches 34.7%.


Compiling the Tokenizer

A tokenizer is a finite map from token ID to string. I read it once, offline, and compile a frozen CharWeightBank (src/char_tables.py) of three tables indexed by token ID:

The tokenizer still converts the prompt into token IDs. Once those IDs enter the forward pass, the modules read their character features by indexing frozen tensors, for example F_retina[input_ids].Compilation takes 5.2 s for SmolLM2-1.7B and 12–29 s for the Qwen3 models.

Figure 2. The 358 dimensions of F_retina for one token. Hover a cell to see what it encodes. Each 27-way block is a one-hot with slot 0 meaning "none". The vector is computed in your browser with the same rules as char_tables.py; the token IDs are Qwen3's.

Each row describes one token. A word may span several rows. The ALU combines them after recognising a tagged call. The retina combines them as it scans a quoted span.


An Exact ALU

The ALU is a tensor circuit attached to the host’s final RMSNorm. It follows the read, compute, and write recipe from Weight-Space Micromachines. The closing ]= activates the circuit. Until then, the hook returns the hidden state untouched. In my checks, logits on ordinary prose and before the trigger were bit-identical to the base model’s.

Figure 3. The X-Ray ALU at a glance. It reads the call from the token stream with vocabulary indicators and prefix sums, computes the answer from the compiled tables, and adds a solved direction γ·W_write[t] after the final norm so that t becomes the argmax. The 28 transformer layers are never modified.

Below, scrub through generation of one call. Each step shows the prefix-sum span state, whether the ALU is active, and what it writes.

Figure 3. One ALU call, step by step. The tokens and output are Qwen3-0.6B's recorded generation; the span-state rows are a schematic of the circuit's prefix-sum logic. Note that " strawberry", with its leading space, is a single token (72600): the base model receives no sub-word pieces at all, and answers 2.

Even turning a count into decimal digits is ReLU arithmetic. Python's str(n) is never called. An indicator relu_step(x, t) = ReLU(x − t + 1) − ReLU(x − t) is exactly 1 for integers x ≥ t and 0 otherwise. Summing nine of them gives the hundreds digit; the remainder repeats the trick for tens.

Figure 4. The digit extractor. The staircase is Σ relu_step(n, 100c) for c = 1…9, and it is exact on every integer from 0 to 999. Drag n; this is the real computation, run in your browser.
The digit extractor in code
def relu_step(x, t):      # 1 iff integer x >= t
    return F.relu(x - (t - 1)) - F.relu(x - t)

d_hundreds = sum(relu_step(n, 100 * c) for c in range(1, 10))
rem        = n - 100 * d_hundreds
d_tens     = sum(relu_step(rem, 10 * c) for c in range(1, 10))
d_ones     = rem - 10 * d_tens

Results across model families

I ran the same compiler, unchanged, on three models from two families with different tokenizers. Each was evaluated 2-shot, with in-context examples teaching only the tag format and no gradient steps. I also checked each circuit directly on all 13 suites.

Figure 5. Exact-match accuracy per task, from the base model 2-shot () to the same model with the ALU (). On held-out words, Qwen3-0.6B goes from 25.0% to 100.0% on average, including 0 → 100% on reverse and rot13. Hover for values.
ModelCompileProse logitsHeld-out (6 tasks)PseudowordsMulti-wordDirect
Qwen3-0.6B-Base28.8 sbit-identical25.0 → 100.022.3 → 92.028.0 → 100.0100.0
Qwen3-1.7B-Base12.6 sbit-identical34.7 → 100.029.3 → 93.034.0 → 100.0100.0
SmolLM2-1.7B5.2 sbit-identical29.7 → 99.718.3 → 94.730.0 → 100.0100.0

The gap on pseudowords (92–95% vs. 100% direct) is a copying error, not a circuit error. Under 2-shot prompting the base model sometimes mis-copies an unfamiliar string into the tag before the ALU fires. Once triggered, the ALU made no mistakes on any suite, on any of the three models.

Figure 6. Recorded ALU calls on Qwen3-0.6B-Base. Underlined characters were written by the ALU; everything else is ordinary generation. From results/alu_eval_Qwen_Qwen3-0.6B-Base.json.

The Word Retina

The Word Retina uses the same tables to answer natural-language questions about quoted words. For How many times does the letter 'r' appear in 'strawberry'?, the scanner computes the count and trained adapters feed features into the model’s hidden layers. I test whether the frozen host can use them to produce the answer as its next token, without a special tag or a written chain of thought.

Every design below was trained on Qwen3-0.6B-Base with 4,096 word-disjoint examples over the seven tasks. All are compared against a plain LoRA (r = 18, 11.35M parameters).

Two designs that fail

Figure 7. Three ways to give the host access to F_retina. Each panel reports perceptual accuracy, the accuracy drop when the feature path is turned off, and the fraction of count edits the model follows. The Word Retina shows the strongest dependence on the compiled features.

Layer-0 injection (src/xray_retina.py) projects F_retina[ids] into the input embeddings alongside a LoRA (10.81M parameters). It scores 47.9% on held-out words and 58.1% on pseudowords, slightly below plain LoRA (49.5 / 60.7). Ablating the retina costs just 2.4 points. At layer 0, the token embedding for berry is still independent of the question. The small ablation drop suggests that the trained model relied little on this feature path.

Generic cross-attention at layers 14, 20 and 24 (V1, src/visual_cortex.py) attaches where the residual stream already encodes the query. The host now depends on it (−17.1 points when ablated), but accuracy stalls at 35.0%. A generic attention module has to learn subword-to-word aggregation from 4,096 examples.

Cross-token doubles offered a clue. In a V1 variant with LoRA, accuracy on that test reached 78.8% and fell by 30 points when I turned off the feature path. I had already precomputed the double-letter signal across token boundaries. That led me to compute the rest of the word-level features explicitly and train the adapters to use those features.

A compiled word-level recurrence

WordRetinaScanner (src/word_retina.py) is a causal, gated linear recurrence over F_retina[ids] and E_alpha_chars[ids]. Inside a quoted span it accumulates the word's letter histogram and length. It detects doubles across token boundaries with one product, prev_last · first, and places each letter into a 16 × 26 grid at its cumulative offset. It also forms query readouts such as matched_cnt, matched_nth and is_anagram, for 623 dimensions in all.The 623 dimensions are: word histogram (26), length one-hot 0–24 (25) and scalar (1), double flag (1), matched-count one-hot 0–20 (21) and scalar (1), nth letter (26), anagram features (2), first/last letter (52), query letters (52), and the 16 × 26 character grid (416). Two supported token splits can update these features at different points in the scan. Once both have processed the full word, the counts, ordered letters within the grid, and double-letter flag agree.

Figure 8. The retina's running state for two tokenizations of the same word: Qwen3's own, and a different valid split of the same bytes. Drag through the characters. Midway, the two states differ, because one tokenization hasn't finished a token yet. At the end they agree exactly, cross-token doubles included (). The accumulators are re-implemented in your browser; all tokens shown are valid Qwen3 tokens.

The state enters the frozen host through three SwiGLU-style bilinear residual taps (LatentIntuitionTap) at layers 16, 20 and 24:

h′ = h + α · Wout( SiLU(Wg2 h̃) ⊙ Wmix( SiLU(Wg1 h̃) ⊙ Ws S ) )

The taps total 6.47M trainable parameters, 57% of the LoRA budget. Each output projection is zero-initialised, so the model is bit-identical at step 0, and a KL term on prose during training discourages changes to the base model’s output distribution.

Figure 9. Held-out accuracy against training-set size. At n = 2,048 with 6.47M parameters, the Word Retina on a frozen host already exceeds LoRA at n = 4,096 with 11.35M. The grey line is the frozen base model.
Figure 10. Per-task accuracy after training on 4,096 examples. The Word Retina is strongest on letter-level questions. Transfer to held-out tasks is mixed (73.3% on multi-word count and 61.7% on anagrams), and rewriting strings remains difficult.
Qwen3-0.6B, n = 4,096ParamsHostPerceptual*All 7, held-outAll 7, pseudoCross-token dblOOD multi-wordΔPPL†
Frozen base0frozen32.119.110.750.025.00.00
Plain LoRA, r = 1811.35Madapted71.749.560.770.038.3+5.08
Layer-0 retina + LoRA10.81Madapted70.847.958.160.043.3+7.72
Generic V18.35Mfrozen55.035.043.646.333.3+0.94
BPE-V2 Word Retina6.47Mfrozen97.160.063.683.873.3+0.31
BPE-V2 + LoRA11.51Madapted96.763.870.082.571.7+0.27

* Count, length, nth and double on held-out words; frozen V2 per task: 98.3 / 91.7 / 100.0 / 98.3. On compound pseudowords (perceptual / all 7): LoRA 64.4 / 44.3, V1 46.9 / 31.1, V2 96.9 / 58.6, V2 + LoRA 93.8 / 62.1. OOD anagram: base 38.3, LoRA 58.3, layer-0 63.3, V1 40.0, V2 61.7, V2 + LoRA 38.3. † Held-out prose perplexity shift. The LoRA and layer-0 arms were evaluated on a different prose sample (base PPL 25.9) from the V1/V2 arms (30.2–30.4).


Is the Retina Really Read?

The adapted system scores higher on these tasks. To test what the gain depends on, I turn the feature path off, then edit an individual count while keeping the prompt fixed.

Ablation

Setting the retina’s scale to zero removes its contribution at test time. Accuracy across the seven held-out tasks drops from 60.0% to 17.4%, close to the untouched base model’s 19.1%.

Figure 11. BPE-V2 on a frozen host, with the retina on and with it ablated (scale = 0). Held-out words fall from 60.0% to 17.4%, near the untouched base model's 19.1%.

Optical illusions

A stronger test leaves the input untouched. I hold the token IDs fixed and add an integer δ to a single feature: the 'r' count of F_retina for the token berry. If the host is reading its retina, it should look at the unchanged word strawberry and report a count the text contradicts.

Figure 12. The optical-illusion test on strawberry. Drag δ. Every prediction shown is a recorded greedy output from the corresponding trained model, not live inference.

On strawberry, the frozen host reports the edited count when δ = −2, −1 and 0. For positive edits, it keeps predicting 3 as the edited count rises. The systematic suite uses 25 held-out words, a random letter each, and δ ∈ {+1, +2} on the word's last token. There, the edit is followed 88% of the time (44/50) on the frozen host and 94% (47/50) with LoRA.

Figure 13. Fraction of the 50 feature edits for which the predicted answer matched the edited count. The two BPE-V2 variants follow the edits most often.

Compression and re-tokenization

Compound pseudowords glue random 4–7 character BPE chunks into 9–13 character strings of at most three tokens, the worst case for memorised spellings. Frozen V2 reaches 96.9% on perceptual tasks (count 100, double 100, length 95, nth 92.5), against 64.4% for LoRA.

Re-tokenization splits held-out words into a different valid tokenization of the same bytes. Evaluated on count, length, nth and reverse, V2 does not lose aggregate accuracy under the tested re-splits (70.0 → 73.1 on the frozen host, 73.1 → 75.0 with LoRA). I did not run the ALU on this split.An earlier version of this post showed the ALU at 100% → 100% here. That value was hard-coded in the plotting script rather than measured, so I removed it. The ALU's circuit indexes characters rather than tokens, and is 100% on every suite in the direct check.

Figure 14. Left: compound pseudowords, perceptual tasks vs. all seven. Right: canonical tokenization vs. a random valid re-split of the same strings.

Limitations

String rewriting. On the frozen host, V2 scores 23% on deletion, 7% on replacement, and 2% on reversal. The strong results on short answers do not extend to generating edited words.

Readout saturation. In the strawberry intervention, the readout stops tracking the feature above three. The experiment leaves open how well the adapter handles larger counts in other words.

Span latching. The scanner relies on quote tokens to find its target span. Unquoted prose would need learned boundary gates or a rolling word register.

Scale. The ALU is verified on three models in two families. V2 was trained only on Qwen3-0.6B, with a single seed. Larger hosts, more seeds, and RL co-training as in WSM are untested.

The tokenizer supplies the spellings. The circuit and scanner compute the relevant character features. With the retina, training teaches the adapters how to pass those features to a frozen model so it can use them in an answer.

Notes on the measurements

All numbers come from the saved runs in results/*.json; the charts on this page are rendered from them directly. A few corrections relative to the first version of this post:

Every BPE-V2 number is from a single seed (42).

Reproducing

Code and results: github.com/samarth777/bpe-xray.

Citation

For attribution in academic contexts, please cite this work as

P, Samarth. "BPE X-Ray Vision." 2026. https://samarth777.github.io/bpe-xray/

BibTeX citation

@misc{samarth2026bpexray,
  title  = {BPE X-Ray Vision: Weight-Space Character Modules for Token-Blind LLMs},
  author = {P, Samarth},
  year   = {2026},
  month  = {November},
  url    = {https://samarth777.github.io/bpe-xray/}
}