Routing Around Memorization: Contamination-Corrected Local Competence for LLM Routers

A router is a small model that decides, for each incoming prompt, which of several large language models should answer it. The cheapest way to train one is to reuse the per-question score logs that already exist for public benchmarks such as MMLU, GSM8K, MBPP and HELM. Those same benchmarks, however, have often leaked into the models' training data. When that happens, a model's recorded "competence" on a region of questions can reflect memorized answers rather than skill. The inflation is uneven: it is large for some models and some question types and absent for others. A router trained on these logs will therefore learn to send new questions to whichever model memorized the old ones. We propose to measure this failure and to correct it. Each logged success is discounted by a per-item memorization signal. The discount is calibrated against a small set of clean, post-training-cutoff questions, and the router then routes on the corrected competence.

In two sentences: benchmark-trained routers inherit contamination as misrouting, because contamination inflates competence non-uniformly across models and input regions. A router that combines the large contaminated logs with memorization detectors and a small clean anchor set should route post-cutoff prompts better than a router trained on raw logs or on clean data alone.

Core Claim

Dynamic classifier selection picks a model per input using that model's accuracy on nearby labeled examples, rather than trusting a global average. Dynamic Classifier Selection introduced this idea to stop weak models from diluting strong ones. LLM Routing with Benchmark Datasets carries it over to language models. It uses a k-nearest-neighbor correctness predictor on prompt embeddings, trained on HELM logs, and shrinks toward average accuracy when a new task looks far from the training data. RouterBench builds 405,467 logged outcomes from MMLU, GSM8K, MBPP and others. Both papers treat every logged success as evidence of skill. Neither asks whether that success was memorized.

The contamination literature says this assumption fails, and it fails in a structured way. Data Contamination: From Memorization to Exploitation shows that the accuracy gain from contamination depends on how often an item was duplicated and on when the model saw it: roughly 1% at low exposure, up to 40% at 200 repetitions. Contamination therefore varies by item and by model, which is exactly the level at which local competence is estimated. A geometric neighborhood full of memorized items is a biased neighborhood.

Our claim is that local competence can be de-biased item by item, using signals that are already known to detect memorization, and that doing so changes routing decisions in a way that shows up on genuinely fresh prompts. Section 2 of the research file shows no prior router audits or corrects for contamination. The closest work, Shnitzer et al., handles distribution shift between tasks, not inflated labels within a task. This is a different error. A shift-aware router still trusts a memorized neighborhood that looks exactly like the query.

Research Program

For each logged item $i$ and candidate model $m$, we record three things. The first is the benchmark correctness $y_{im}$. The second is a memorization score $s_{im}$ built from black-box detectors. One detector is output-distribution collapse, as in the CDD method of Generalization or Memorization, which flags contamination when several sampled answers are nearly identical. Another is a recognition test in the style of the Data Contamination Quiz, which asks the model to pick the original benchmark text from lightly reworded versions while controlling for its bias toward particular answer letters. A third is the consistency gap under option shuffling and distractor edits from CAP. These detectors play the role of method suppliers. We reuse them, but we use them as features at the level of individual items rather than as dataset-level verdicts.

The third ingredient is a small clean anchor set: questions the models cannot have seen. We draw these from LiveBench items released after each model's cutoff, and from RepliQA, a question-answering set built around fictional entities and used as an uncontaminated reference in The Emperor's New Clothes in Benchmarking?.

We cluster the embeddings of the logged items and the anchor items into shared regions. Within each region $r$ we observe two quantities for each model: the logged accuracy and the anchor accuracy. We fit a per-model correction $g_m(s)$, defined as the probability that a logged success reflects transferable skill given memorization score $s$. The fit chooses $g_m$ so that the discounted logged accuracy in each region matches the anchor accuracy in that region. This pools evidence across regions, so no single region needs many anchor items. The corrected local competence for a query $q$ is

$$\hat c_m(q) = \frac{\sum_{i \in N(q)} K(q,x_i)\, y_{im}\, g_m(s_{im}) + \lambda \sum_{j \in A(q)} K(q,a_j)\, y_{jm}}{\sum_{i \in N(q)} K(q,x_i) + \lambda \sum_{j \in A(q)} K(q,a_j)}.$$

Here $N(q)$ is the query's nearest logged items and $A(q)$ its nearest anchor items. $K$ is a Gaussian kernel on embedding distance, the same smoother Shnitzer et al. use for their out-of-distribution shrinkage. $\lambda$ sets the relative weight given to clean evidence. The router sends $q$ to $\arg\max_m \hat c_m(q)$, or, in the cost-aware version, to the cheapest model within a tolerance of that maximum.

The analysis has three parts. First, we measure how much raw-log routers misroute toward contaminated models, both in a controlled setting and in a natural one. Second, we test whether the correction fixes this misrouting. Third, we locate the anchor-set size at which clean data alone becomes sufficient. That last result is the honest answer to the question of whether this machinery is needed at all.

Baselines

The naive reference points are the single best model on average and uniform majority voting over the pool. The best single model is the bar every router must clear. On HELM, LLM Routing with Benchmark Datasets reports that Llama 2 70B scores 0.688 overall accuracy. On LiveBench, no model dominates every category: o1-preview leads overall at 64.7%, Claude 3.5 Sonnet leads Coding at 67.1%, and o1-mini leads Reasoning at 72.3%. This suggests routing has room to help on clean data. We will compute best-single-model and voting accuracy on our own anchor-held-out test sets, using the same pool.

The strongest existing method is the S3 router of Shnitzer et al. It is a k-nearest-neighbor correctness predictor on all-mpnet-base-v2 embeddings with Nadaraya–Watson shrinkage over dataset distance. The paper reports 0.694 overall accuracy on HELM, against 0.688 for the best single model, and 0.59 average correctness-prediction accuracy on unseen tasks. It is the strongest competitor because it already corrects for one kind of unreliability in logged competence. We also run RouterBench's k-nearest-neighbor and multilayer-perceptron routers, which were reported to cut cost 2–5x at competitive quality. For these we report AIQ (average improvement in quality, the area under the cost–quality curve) with RouterBench's definition. RouterBench reports no AIQ values on post-cutoff data, and we found no reported routing result on Lacuna for LiveBench.

Fairness is enforced in three ways. Every router sees the same logs, the same embedding model and the same anchor items. S3 receives the anchor set as additional in-distribution training data, so any advantage we show cannot come from anchor access alone. All kernel bandwidths, neighbor counts and $\lambda$ are tuned with the same budget on a validation split of anchor items, and that split is disjoint from test.

The ablations isolate the key ingredient. "Anchor only" sets $g_m \equiv 1$, which reduces to kernel pooling of raw logs with clean anchors. "Detector only" uses a hand-set discount from $s_{im}$ with no anchor calibration. "Clean-only router" uses the anchor set alone. Beating the method means one of two things. On post-cutoff test prompts, the method should raise routing accuracy over S3-with-anchors by more than the seed-to-seed standard deviation. Alternatively, it should reduce regret, defined as the gap to the per-query oracle, while matching S3 on uncontaminated regions. It must also beat "anchor only," or the detectors are adding nothing.

Why not just…?

Why not just train the router on clean, post-cutoff data only? This is the real threat. If a few hundred LiveBench items per region already give reliable neighborhoods, the logs are unnecessary. Against it, LiveBench replaces only about one sixth of its questions per month, covers only script-verifiable tasks, and is English-centric. Sparse reference sets are also the documented failure mode of neighborhood selection: Expression Detection Based on a Novel Emotion Recognition Method reports wrong assignments when the validation set lacks nearby examples. We do not argue this point in the abstract. The anchor-size sweep measures the crossover directly. If the clean-only router matches ours at anchor sizes practitioners can realistically collect, we will report that the contribution is diagnostic rather than methodological.

Why not just drop benchmarks or models that a detector flags as contaminated? Dataset-level filtering discards the large, informative uncontaminated portion of each log. The Magar and Schwartz result shows that inflation depends on each item's duplication count, so contamination is concentrated rather than uniform. We include "drop flagged datasets" and "drop flagged model–dataset pairs" as extra baselines to test whether the item-level discount recovers the accuracy that coarse filtering throws away.

Why not just paraphrase or perturb the benchmarks before collecting logs? The Emperor's New Clothes in Benchmarking? tested 20 such mitigations across 10 models. Surface edits kept fidelity above 0.9 but gave almost zero contamination resistance. Aggressive edits dropped MMLU fidelity to 0.686. Rewritten logs would therefore stay inflated or stop measuring the intended skill. This constrains our design: we use perturbations only as one input to $s_{im}$ and never as a replacement label. We also run a "paraphrased-log S3" baseline to confirm the prediction empirically.

Why not just use the best single model? Routers already beat it on HELM, but that margin (0.694 against 0.688) was measured on possibly contaminated data. Our post-cutoff evaluation is the test that shows whether routing's advantage over the best single model survives.

Proposed Experiments

The controlled experiment follows the design of Magar and Schwartz. We take several open-weight models (Llama, Qwen, Yi, Mistral families, 3B–34B, matching the Emperor's New Clothes pool). For some of them we create a "contaminated twin" by continued pretraining on chosen MMLU, GSM8K and MBPP test items, duplicated 1, 10, 50 or 200 times, with the chosen items restricted to particular topic clusters. Ground-truth contamination is then known item by item. The pool mixes twins with their clean originals. Routers are trained on the logs and tested on held-out post-cutoff LiveBench items, plus on the untouched remainder of each benchmark.

The first decisive check is misrouting. Raw-log routers should send injected-topic LiveBench queries to the contaminated twin, which by construction has no extra skill. The corrected router should not. The misrouting rate should grow with duplication count, following the exploitation curve in Magar and Schwartz. The second check is harmlessness: on clusters where nothing was injected, corrected and raw routers should agree.

The natural experiment reruns the RouterBench task mix and the HELM subsets from Shnitzer et al. on the open-weight pool plus phi-3.5-moe-instruct. We train on those logs and evaluate on LiveBench months released after every pool model's cutoff and on RepliQA. We report routing accuracy, oracle regret, AIQ under the cost–quality trade-off, and the Brier score of $\hat c_m(q)$ against realized correctness. The Brier score tells us whether corrected competence is better calibrated, not just better at picking the top model.

We also check how well the memorization score agrees with verified leaks. On FinEval, CAP's audit found a 21-question training–test overlap, which provides confirmed cases. On HumanEval, Generalization or Memorization estimates a 41.5% leak ratio for ChatGPT, which gives an external estimate to compare against.

The project fails cleanly under two outcomes. One is that injected contamination does not change raw-router decisions, meaning memorized logs are harmless to routing. The other is that "anchor only" matches the full method, meaning the detectors are redundant. We would report either outcome as the result.