NeurIPS 2026Coming to NeurIPS?Explore papers, orals & directions

Borrowing a Language at Inference Time: Layer-Selective Attention Injection with Trap-Based Leakage Checks

A multilingual text generator fine-tuned on English summaries often keeps writing English, or the source language, when asked to summarize in Swahili or Thai. mmT5: Modular Multilingual Pre-Training Solves Source Language Hallucinations reports that a standard mT5 model produces output in the correct target language only 7% of the time in this zero-shot setting on XL-Sum. Their modular model, which has separate small language modules, reaches 99%. The catch is that the fix has to be built in at pre-training time. We ask whether the same control can be added to an existing model at inference time, with no training. Diffusion image models already do something similar. Cross-image attention injection copies the internal "keys" and "values" (the lookup vectors each layer attends over) from a reference image into the generation of a target image. The target then takes on the reference's appearance while keeping its own layout.

The proposal applies this move to language. While generating a summary, a chosen subset of the decoder's layers also attends to keys and values computed from a short, unrelated reference passage written in the target language. The expected effect is that the reference contributes its language and the source document contributes the content. The known failure mode is content leakage, where the reference's own facts creep into the output. To measure it cleanly, we borrow the trap idea from verifiable quantum secret sharing. We plant rare, checkable "trap" spans in the reference and count how often they surface in the output. This gives a detection guarantee that tightens with the number of traps.

Core Claim

Our central claim is that language identity in a pre-trained encoder–decoder is concentrated at particular decoder depths. Injecting target-language keys and values only at those depths should do three things. It should raise zero-shot target-language consistency far above plain mT5's 7%. It should stay close to mT5 on content quality. It should also leak measurably less reference content than injecting at every layer.

The layer-selective part carries the claim, and the reason is simple. Injecting the reference at every layer by concatenation is mathematically almost the same as pasting the reference in front of the output as a text prompt. If only full injection works, the idea reduces to prompting and is not worth a paper. We state this up front because it defines the key ablation.

Relation to Prior Work

Four lines of prior work play different roles here.

The image methods supply the mechanism. Cross-Image Attention for Zero-Shot Appearance Transfer pairs a target's queries with a reference's keys and values, and uses temperature sharpening to avoid blurry averaging. Style Injection in Diffusion does training-free style transfer by swapping keys and values and normalizing statistics. ZePo and Text to Sketch Generation with Multi-Styles concatenate the target's and reference's keys and values rather than replacing them, specifically to limit content leakage. The swapping-attention work (基于交换注意力机制的任意图像风格迁移) shows that network depth separates layout from appearance. We reuse concatenation, temperature, and depth targeting. We depart from all of them by moving from pixels to tokens, where the "appearance" to transfer is a language rather than a texture.

Style Aligned Image Generation via Shared Attention constrains the design. It finds that letting many images all attend to each other causes collapse and mutual leakage, and that one-way routing from a single reference works. We therefore inject in one direction only, from a single reference.

The language-modularity work motivates the question. Multi-Way, Multilingual NMT with a Shared Attention Mechanism shows attention can be shared while encoders and decoders stay language-specific. Sachan et al. show that sharing attention while keeping the feed-forward blocks per language beats both extremes. mmT5 locates language behavior in adapters placed after the feed-forward blocks. Together these suggest that language information is carried in the hidden states that keys and values are computed from, and that it sits at identifiable depths. All three build this structure in with training. We test whether it can be read off an unmodified model and moved at inference time, without the explicit language IDs that mmT5 requires.

The quantum secret sharing work contributes a verification idea, not a mechanism. Verifiable threshold quantum secret sharing with sequential communication and A verifiable framework of entanglement-free quantum secret sharing embed auxiliary check qudits, which catch a cheater with error rate $1/d$. Approximate Quantum Error-Correcting Codes and Secret Sharing Schemes turns hidden corruption into a detectable event through authentication. We take the principle of planting checkable traps inside the payload so that silent failure becomes observable.

We deliberately reject the file's suggestion of secret-sharing the attention keys and values across parties. For classical vectors, ordinary classical secret sharing already does that, and quantum protocols would add cost with no benefit.

Research Program

Injection. We start from mT5 fine-tuned on English XL-Sum. For each test document and target language $\ell$, we run a short, topically unrelated reference passage in $\ell$ through the decoder with teacher forcing and cache its per-layer keys and values. During generation, each selected layer $j \in S$ attends over the concatenation of its own and the reference's keys and values. The reference logits are scaled by a strength $\lambda$ and a temperature $\tau$:

$$\text{Attn}_j = \text{softmax}\!\left(\frac{Q_j[K_j, \lambda K^{\text{ref}}_j]^T}{\tau\sqrt{d}}\right)[V_j, V^{\text{ref}}_j]$$

Here $Q_j, K_j, V_j$ are the generated sequence's queries, keys, and values at layer $j$, and $K^{\text{ref}}_j, V^{\text{ref}}_j$ are the cached reference keys and values. Before concatenation we rescale the reference keys to match the norm of the generation's own keys, the token analogue of latent AdaIN (adaptive instance normalization), so that the reference cannot dominate by magnitude alone.

Finding the language layers. We choose $S$ with a small held-out development set. We measure, layer by layer and for small contiguous windows, how much single-window injection moves the rate of correct-language output. We then pick the smallest window that captures most of the gain. We also report whether the same window transfers across target languages. If it does, a single layer choice works for all languages.

Trap-based leakage checks. Each reference passage is seeded with $k$ trap spans, such as rare named entities or unusual numbers, that are absent from the source document. If each trap independently surfaces with probability $p$, then at least one of the $k$ traps is caught with probability $1-(1-p)^k$. This lets us bound leakage from above even when it is rare. It plays the same role as the $1/d$ detection rate of an auxiliary qudit. We check the independence assumption empirically by comparing single-trap and multi-trap references.

Baselines

The naive reference point is plain mT5 fine-tuned on English and decoded zero-shot. On XL-Sum, mmT5 reports 7% target-language consistency for it.

The strongest existing method is mmT5 itself, at 99% target-language consistency on XL-Sum. This is the upper bound a training-free method should approach, not one it must beat. It uses modular pre-training and language IDs, so we cite its number rather than retrain it.

The most direct training-free competitor is reference-as-prompt: the same reference passage, carrying the same traps, placed as a decoder prefix. It is run with the same references and the same decoding settings, and its prefix length and wording are given the same development-set tuning budget as our $\lambda$ and $\tau$.

The second training-free competitor is activation steering. We add a target-language mean-difference vector to the decoder hidden states at the same candidate layers, with an equal tuning budget. No reported result was found on Lacuna for steering on XL-Sum, so we will run it ourselves.

The third competitor is script-restricted constrained decoding, which masks out tokens outside the target language's script.

The ablation that isolates our key ingredient is all-layer injection, which approximates the prompt baseline, compared against layer-selective injection, with and without key-norm matching.

We count the method as beating the competitors if two conditions hold. First, it matches or exceeds the prompt and steering baselines on language consistency. Second, it shows lower trap leakage than the prompt baseline and at least equal ROUGE, averaged over five or more target languages with bootstrap confidence intervals.

Why not just…?

Why not just put a target-language example in the prompt? This is the real threat, because full-layer concatenation nearly equals it. The all-layer versus selected-layer ablation settles the question directly. If selected-layer injection is not better on leakage at equal consistency, we report that the effect is prompting and drop the injection claim.

Why not just mask the vocabulary to the target script? Masking fixes the script, not the language. It cannot separate languages that share a script, such as Indonesian and English. We therefore evaluate same-script target languages separately, where we expect masking to fail and injection to succeed.

Why not just add a steering vector? Steering is cheaper and needs no reference passage. It may, however, damage content, because it shifts every token in the same direction. Injection instead lets each token choose what to borrow from the reference. The head-to-head comparison on ROUGE at matched consistency tests this. If steering ties with injection, it is the simpler answer and we will say so.

Why not just use mmT5? It works, at 99%, but it requires pre-training a new model. Our question is about models that already exist. We report the remaining gap to mmT5 rather than claiming to close it.

Proposed Experiments

The main experiment uses XL-Sum zero-shot transfer from English into a mix of target languages. It covers distinct scripts, such as Thai and Arabic, and shared scripts, such as Indonesian and Swahili. We report four metrics: language consistency from an off-the-shelf language identifier, ROUGE against the gold summary, trap leakage rate, and the upper bound on leakage implied by the traps.

A secondary check uses MASSIVE semantic parsing. There the output format is language-neutral, so injection should leave exact match unchanged, and any drop would indicate collateral damage.

We treat three findings as decisive. The first is whether a narrow window of decoder layers accounts for most of the consistency gain, and whether that window is shared across languages. The second is whether selective injection leaks fewer traps than the prompt baseline at equal consistency. The third is whether trap leakage predicts content contamination judged by humans on a small annotated sample. If the traps fail to track real leakage, the verification component is not valid.