What the neighbours voted
930 short customer messages across five intents, labelled by a simulated sloppy annotator who got 41.8% of them wrong. Each message's 15 nearest neighbours in embedding space vote on its label, weighted by how similar they are. Five real rows:
| Message | Label given | Neighbours voted | Outcome |
|---|---|---|---|
| “I was charged twice for the mobile app” | billing | fixed | |
| “it says server error every time” | technical | fixed | |
| “my rder has not arrived yet asap” | shipping | fixed | |
| “can you ship your product faster thanks” | shipping | fixed | |
| “i love the new the premium plan feature” | praise | broken |
The first four had wrong labels, and the vote put them right, typos and all. The last one was labelled correctly, but its closest neighbours are complaints that the premium plan's button does nothing: the shared product name outweighed the praise. Cleaning does both, as the tables below show, and these five come out the same in every one of the 30 runs behind them.
What happens to the labels
The dataset repeats many messages word for word, so neighbours are often exactly tied and rounding decides between them. Each number here is therefore the median and range over 30 runs, each with the embeddings nudged by one part in a million: far too little to change any meaning, enough to re-roll the ties.
| Measure | Median | Range over 30 runs |
|---|---|---|
| Wrong labels put right | 85.6% | 83.0–87.1% |
| Right labels made wrong | 7.7% | 6.8–9.1% |
| Label accuracy, from 58.2% to | 89.5% | 87.6–90.2% |
Classifier accuracy after cleaning the full dataset
The original split can place the same text on both sides, and noisy test labels can influence the cleaner.
| Trained on | Median | Range over 30 runs |
|---|---|---|
| The raw noisy labels | 84.1% | 83.7–84.1% |
| Consensus-corrected labels | 91.4% | 90.1–92.3% |
| Corrected, low-confidence rows dropped | 91.2% | 85.8–93.6% |
- Cleaning works. The corrected labels beat the raw ones in all 30 runs, by about 7 points, without ever seeing the true labels.
- It has a cost. About 8% of the labels that were right become wrong. Net, label accuracy goes from 58% to about 89%.
- The confidence gate does not reliably help. Dropping low-confidence rows beats plain correction in half the runs or fewer, between 8 and 15 of the 30 depending on the machine, and swings by seven or eight points.
Classifier accuracy on unseen message strings
One Windows run kept identical strings together and cleaned only the training labels. On the same 232 test rows, accuracy was 78.0% with raw labels, 84.1% with corrected labels, and 85.3% after the confidence gate. Variants of a synthetic message template can still appear in both folds.
Why the gate is unreliable
The gate keeps a row when at least 0.6 of the vote agrees, and 9 of 15 neighbours agreeing is exactly 0.6. With only 336 distinct messages among the 930, many rows land right on the cut-off: roughly a hundred sit within 0.005 of it, 68 to 126 on the machines tested so far. Whether each one is kept comes down to rounding, and the gate's result moves with it.
Even the processor matters. ONNX Runtime picks different low-level routines on different CPUs, so the last bits of the embeddings differ, and those bits decide ties. The medians above move by up to about a point between machines; the conclusions hold on all of them.
An earlier version of this project reported the gate as the best result, about 93%, from a run that happened to land near the top of its range. Reporting a spread instead of a single run is what caught it.
Three smaller experiments
Distillation: a small student imitating a big teacher
A teacher using the full 384-dimensional embeddings labels data with soft probabilities, and a linear student with 45 parameters learns to imitate it. The student gets within about 3 points of the teacher, 91% against 94%, at 1/42 of the size.
The textbook claim that soft labels beat hard ones did not hold. Compared fairly, each pair starting from the same weights, over 30 splits, soft labels came out 0.5 points worse on average (95% CI −0.84 to −0.14) and won only 8 of the 30.
Conformal prediction: sets of labels with a coverage guarantee
Instead of one label, return a set that contains the right one at least, say, 90% of the time. Confident messages get a single label; vague ones such as “ok” get several. The textbook rule meets its target partly by sometimes returning an empty set. A practical rule that always keeps the top class can never cover less than the classifier's own top-1 accuracy, 95% here, so it over-covers at low targets. Averaged over 200 random draws:
| Target | Never-empty sets | Textbook sets | Empty sets (textbook) |
|---|---|---|---|
| 80% | 98.0% | 81.2% | 16.8% |
| 90% | 98.6% | 90.3% | 8.3% |
| 95% | 99.3% | 95.9% | 3.5% |
A language model for the rows the vote cannot settle
llm_denoise.py sends only the ambiguous rows to Claude Opus 5.5, with each
row's neighbours as context and an explicit “uncertain” option, and uses structured output
so the answer is always one of the known labels. It needs Anthropic credentials; without
them it prints its plan.
Run it yourself
pip install -r requirements.txt
python clarity_engine.py # cleaning and training; writes the figures
python clarity_engine.py --grouped-holdout # evaluate on unseen message strings
python clarity_engine.py --stability # the medians and ranges above
python distill_demo.py # teacher and student
python conformal_demo.py # conformal prediction sets
Python 3.11 to 3.14. The first run downloads the embedding model, about 90 MB, once, and runs it through ONNX Runtime, so there is no PyTorch to install.
The tests re-run every number in the README with the real model on Linux, Windows and macOS, and check this page against the README and the code, the five rows above included.
pip install -r requirements-dev.txt
pytest
Future scope
- Real noise: a real labelled sample as ground truth, instead of uniform random corruption. Real mistakes cluster in particular classes and hard examples.
- Fix the gate's ties: vote once per distinct message, or move the cut-off between the steps such votes take (0.63 sits between 9/15 and 10/15), then choose it on held-out data rather than by hand.
- A second opinion: cross-check the vote against confident learning (cleanlab), and send the rows where they disagree to review or to the language model.
- Calibration: measure expected calibration error before trusting any confidence score.
- Scale: an approximate nearest-neighbour index past about 100,000 rows.
- Python 3.15, once ONNX Runtime publishes wheels for it.