When the algorithm is a table

The triples a typo writes

A spelling checker capped at two edits keeps every correction it could make and still gives a false suggestion to 72% of the unfamiliar words it answers, because on short words distance cannot tell a typo of a vocabulary word from a word the vocabulary lacks. The query's letters were proposed as the second test: decline a query whose letter-triples the vocabulary has never seen. They cannot separate the two either. One edit writes about one unseen triple into any word, familiar or not, while an unfamiliar word brings 0.59 of its own, and two thirds bring none. Declining at two unseen triples removes a quarter of the false suggestions and costs half the corrections — twenty-two corrections for every false suggestion removed.

A checker that stops at two edits put a cap on a spelling checker. It searches a trie of 2,424 vocabulary words for the words nearest a misspelt query, and it stops and declines to answer once the nearest word is more than two edits away. Every misspelling in the test streams is one or two edits from its source, so a cap of two keeps every correction the checker could make, at 42% of the uncapped price. What it does not do is stop false suggestions. Of the misspelt words the vocabulary lacks, the cap still answers 44%, and 72% of those answers are words the writer did not mean. It declines 95% of unfamiliar words of eleven letters or more and 1% of three or four.

The essay’s closing section named the reason and proposed a second test. Distance cannot tell hop mistyped twice from bfs mistyped once, since both land a couple of edits from something. The query’s letters might. A second try before any feature had found that the count of a query’s letter-triples that no vocabulary word contains predicts how far the query’s answer is. The proposal: decline a query when that count passes a threshold, before any walk, and combine it with the cap. It predicted the triples would add nothing on long words, where the cap already declines, and would do what distance cannot on short ones. A three-letter query has a single triple, so its test is one yes or no. The question was whether one triple is enough evidence to decline a word.

A test on the letters, before any walk

The vocabulary’s letter-triples are a fixed set: every run of three consecutive letters in any of its 2,424 words, 2,102 distinct triples of the 17,576 that three letters can make. A query’s unseen triples are those of its own triples not in the set, counted in a single pass over its letters. The checker here declines a query outright when it carries at least θ\theta unseen triples, for θ\theta from one to four, and costs nothing for it. Every other query is answered as the earlier page answered it: a walk that gives up past one edit, then one that gives up past two, and no answer beyond that. The streams, the walks and the verdicts are the earlier page’s. A misspelt vocabulary word is corrected when its source is among the suggestions. A suggestion for an unfamiliar word is a variant when it shares the word’s stem and differs only in an ending, and false otherwise.

Two kinds of query, one distribution

The triples do not tell the two kinds apart: of misspelt vocabulary words 71% carry at least one letter-triple no vocabulary word contains, and of misspelt words the vocabulary lacks 79%; among words of three or four letters, 50% and 51% — the two distributions are nearly the sameThe share of queries carrying 0, 1, 2, 3, or 4 or more letter-triples that no vocabulary word contains. All queries: misspelt vocabulary words 28.8%, 28.9%, 23.3%, 13.5%, 5.5%; misspelt words the vocabulary lacks 21.5%, 27.5%, 23.2%, 14.0%, 13.8%. Queries of three or four letters (323 and 98): 50.5%, 33.7%, 15.8%, 0.0%, 0.0% and 49.0%, 38.8%, 12.2%, 0.0%, 0.0%.every query0%25%50%01234+unseen letter-triplesthree or four letters0%25%50%01234+unseen letter-triplesmisspelt vocabulary wordsmisspelt words the vocabulary lacks2,000 and 600 queriesa triple is unseen if no vocabulary word contains it
Fig. 1 The share of queries carrying 0, 1, 2, 3, or 4 or more unseen triples. Misspelt vocabulary words: 29%, 29%, 23%, 14%, 6%. Misspelt words the vocabulary lacks: 22%, 28%, 23%, 14%, 14%. Among queries of three or four letters: 50%, 34%, 16% and 49%, 39%, 12%.

71% of misspelt vocabulary words carry at least one unseen triple, and 79% of misspelt words the vocabulary lacks. The two distributions are almost the same shape. The unfamiliar words have a slightly longer tail, 14% with four or more against 6%, and that is all the triples can see. Among queries of three or four letters, where the test was meant to do its work, the difference vanishes: 50% of misspelt vocabulary words have an unseen triple and 51% of unfamiliar ones. A short query’s letters say nothing about which kind it is.

The prediction assumed the triples measure unfamiliarity. They measure something else, and the next plate shows what.

The typo writes the triples

The typo writes the triples, not the unfamiliarity: a vocabulary word has no unseen triple and a word the vocabulary lacks 0.59 on average (66% have none), while one edit adds about one unseen triple to either — 0.99 and 1.39 — and two edits nearly two, 1.77 and 2.23Mean count of letter-triples no vocabulary word contains. Vocabulary words as written: 0.00; after one edit 0.99; after two 1.77. Words the vocabulary lacks as written: 0.59 (66% with none); after one edit 1.39; after two 2.23.012unseen triples a word, on averagevocabulary words, as written0.00after one edit0.99after two edits1.77unfamiliar words, as written0.59after one edit1.39after two edits2.23upper three: vocabulary words; lower three: words the vocabulary lacksedits as in the streams
Fig. 2 Mean unseen triples a word. Vocabulary words as written: 0. After one edit: 0.99. After two: 1.77. Words the vocabulary lacks as written: 0.59, with 66% having none. After one edit: 1.39. After two: 2.23.

A single edit writes about one unseen triple into any word; a word the vocabulary lacks brings 0.59 of its own. One insertion, deletion or substitution changes the triples that span the edited position — up to three of them — and on average 1.62 of a mistyped word’s triples are new. The vocabulary’s triples are 12% of the triples three letters can make, so a new triple is more likely unseen than seen, and 0.99 of the 1.62 are. The edit’s contribution is the same whether the word it lands on is familiar or not. Two edits write 1.77 unseen triples into a vocabulary word and add 1.64 to an unfamiliar one.

The unfamiliar words’ own contribution is small because they are ordinary English. The second stream is words from another technical text, about instrumenting programs — instrumented, snapshots, counters, with a few run-together identifiers such as alloctotal — and two thirds of them are made entirely of triples the vocabulary already has. A word the vocabulary lacks is rarely a strange string. It is usually a familiar arrangement of familiar pieces that happens not to be on the list. So the triples carry about one unit of evidence about typing errors for every half unit about vocabulary. A test built on them mostly counts edits, which is what the cap already counts, and more precisely.

The q-grams an error cannot destroy used the same arithmetic in the other direction. An error destroys at most qq of a string’s qq-grams, so a pattern of 21 four-grams keeps thirteen through two errors, and a filter demanding thirteen shared ones loses no true occurrence. That filter asks what an error cannot destroy. The decline asks what an error writes, and an error writes new triples as readily into a known word as into an unknown one.

What the test buys

The trade a triple test offers: the cap of two alone corrects 94% of misspelt vocabulary words and gives 32% of unfamiliar words a false suggestion; declining at four unseen triples 88% and 32%, at three 75% and 31%, at two 53% and 24%, at one 25% and 12% — on a stream one fifth unfamiliar, each false suggestion the threshold of two removes costs 22 correctionsFor each threshold on the count of unseen letter-triples, the share of 2,000 misspelt vocabulary words corrected (their source among the suggestions) against the share of 600 misspelt words the vocabulary lacks given a false suggestion. Decline at 1: 25.1% corrected, 11.7% false, 4.5% given a variant of their own word. Decline at 2: 52.5% corrected, 24.2% false, 8.2% given a variant of their own word. Decline at 3: 75.0% corrected, 30.5% false, 10.8% given a variant of their own word. Decline at 4: 88.4% corrected, 31.7% false, 12.2% given a variant of their own word. Decline at never: 93.9% corrected, 31.7% false, 12.3% given a variant of their own word.00.1000.2000.30000.2500.5000.7501misspelt vocabulary words correctedunfamiliar words given a false suggestionat 1at 2at 3at 4cap aloneeach point: one threshold, with the cap of twoup and right: the cap alone
Fig. 3 Corrections of misspelt vocabulary words against false suggestions to unfamiliar words, for each threshold with the cap of two. The cap alone: 94% corrected, 32% false. Declining at four unseen triples: 88% and 32%. At three: 75% and 31%. At two: 53% and 24%. At one: 25% and 12%.

Declining at two unseen triples removes a quarter of the false suggestions, from 32% of unfamiliar words to 24%, and costs 41% of the corrections, from 94% of misspelt vocabulary words to 53%. Every threshold makes a trade of the same shape. At four the test removes no false suggestion and costs 6% of the corrections. At one it removes more than half the false suggestions and three quarters of the corrections. On a stream where a fifth of the queries are unfamiliar, a threshold of two gives up twenty-two corrections for each false suggestion it prevents. The curve never bends toward the corner where both would be good, because the test is not looking at the property that separates the two kinds.

The variants go the same way as the false suggestions. The cap alone gives 12.3% of unfamiliar words a variant of their own word — timed for time, adjacent for adjacency — a suggestion a writer might accept. At two unseen triples 8.2% get one. The triples decline plausible answers and false ones in about the same proportion, which is what a test blind to the difference between them would do.

Rarity instead of absence

A triple is unseen or it is not, and the test throws away everything in between. A triple that occurs in one vocabulary word is weaker evidence of familiarity than one that occurs in two hundred, and an unfamiliar word built from familiar pieces may still use pieces the vocabulary uses rarely. So a finer version of the test was run beside the plates: score each query by the mean surprise of its triples, −log⁡2-\log_2 of the share of vocabulary words containing each, and decline above a threshold.

It does better than counting unseen triples, and not by enough. Declining when the mean surprise is 11 bits or more keeps 82% of the corrections and leaves 23.5% of unfamiliar words with a false suggestion; at 10 bits, 66% and 19.5%. The unseen-triple test at three keeps 75% and leaves 30.5%. On a stream one fifth unfamiliar, the surprise test at 11 bits gives up about six corrections for each false suggestion it prevents, against twenty-two for unseen triples at two. On words of three and four letters it moves false suggestions from 91% to 63% at 12 bits, and corrections from 79% to 56%. That is closer to an even trade, still a loss, since a correction is what the checker exists to make.

The improvement is in the same direction as everything else on this page. Rarity carries a little of the vocabulary’s own statistics into the test, and the vocabulary’s statistics are the only part of the evidence that is about the source rather than the typing. The filter that feeds the table found a cheap test in front of an expensive one worth having exactly when it rejected what the expensive one would reject. Neither letter test does that here; both reject what the cap would have answered correctly.

Where the triples cost most

The triples cost most where the cap needed no help: declining at 2 unseen triples loses 15% of the corrections on words of three or four letters and 64% on words of eleven or more, and removes false suggestions from 91% to 79% of unfamiliar short words and from 1.0% to 0.0% of long onesBy the query's length, with a threshold of 2 unseen triples and the cap of two: the share of misspelt vocabulary words the cap alone would correct that the triples decline instead, and the share of misspelt words the vocabulary lacks given a false suggestion, with and without the triples. 3 to 4 letters (287 and 81 queries): corrections lost 15.0%; false suggestions 91.4% with the cap alone, 79.0% with the triples. 5 to 6 letters (550 and 123 queries): corrections lost 36.2%; false suggestions 54.5% with the cap alone, 34.1% with the triples. 7 to 8 letters (540 and 163 queries): corrections lost 45.9%; false suggestions 16.0% with the cap alone, 11.7% with the triples. 9 to 10 letters (363 and 103 queries): corrections lost 53.4%; false suggestions 6.8% with the cap alone, 4.9% with the triples. 11 to 22 letters (223 and 97 queries): corrections lost 63.7%; false suggestions 1.0% with the cap alone, 0.0% with the triples.corrections lostfalse suggestions: cap alone, then with triples3–4 letters15%5–6 letters36%7–8 letters46%9–10 letters53%11–22 letters64%declining at 2 unseen triplespale: the cap alone; dark: with the triples
Fig. 4 By the query’s length, declining at two unseen triples. Corrections lost: 15% at three or four letters, 36% at five or six, 46% at seven or eight, 53% at nine or ten, 64% at eleven or more. False suggestions to unfamiliar words, the cap alone against the triples: 91% to 79%, 55% to 34%, 16% to 12%, 6.8% to 4.9%, 1.0% to 0.

On words of eleven letters or more, declining at two unseen triples loses 64% of the corrections the cap would make and removes false suggestions from 1% of unfamiliar long words to none. The prediction said the triples would add nothing on long words. They add a large loss. A long word has more triples for a typo to break, and nothing about a long vocabulary word protects the triples its typo writes from being unseen. The cap had already made long words safe: it declines almost every unfamiliar long word because such words are far from anything. The triples then decline the misspelt long vocabulary words as well.

On words of three or four letters, the triples take false suggestions from 91% of unfamiliar short words to 79%, and lose 15% of the corrections. That is where the test does the most of what it was meant to do, and it is not much. A four-letter word has two triples. A typo in it breaks one or two of them, and a word the vocabulary lacks has as good a chance of containing only familiar pieces as a long one. With a single triple the decision is exactly the section’s question — is this string one the vocabulary could contain? — and at these lengths the answer is yes for most strings of either kind.

The work, which is the one thing the triples save

What the triples save in work, on a stream one fifth unfamiliar: the cap of two alone costs 4,368 cells a query; declining at four unseen triples 3,802, at two 1,814, at one 723 — the work falls with the corrections, at 53% of them kept at twoMean trie cells walked a query on a stream of 80% misspelt vocabulary words and 20% misspelt words the vocabulary lacks, a declined query costing nothing, for each threshold on unseen triples with the cap of two. Decline at 1: 723 cells, 25.1% of vocabulary words corrected. Decline at 2: 1,814 cells, 52.5% of vocabulary words corrected. Decline at 3: 2,974 cells, 75.0% of vocabulary words corrected. Decline at 4: 3,802 cells, 88.4% of vocabulary words corrected. Decline at never: 4,368 cells, 93.9% of vocabulary words corrected.decline at 1723 cells, 25% correcteddecline at 21,814 cells, 53% correcteddecline at 32,974 cells, 75% correcteddecline at 43,802 cells, 88% correctedcap alone4,368 cells, 94% correcteda stream one fifth unfamiliara declined query walks nothing
Fig. 5 Mean trie cells a query on a stream one fifth unfamiliar. The cap alone: 4,368. Declining at four unseen triples: 3,802, with 88% of vocabulary words corrected. At three: 2,974. At two: 1,814, with 53% corrected. At one: 723, with 25% corrected.

A declined query walks nothing, so every threshold saves work. The cost is the number of subproblems is why the work is counted in table cells: each cell is one subproblem of the edit-distance recurrence, and a declined query solves none. The saving runs from 4,368 cells a query with the cap alone to 1,814 at two unseen triples and 723 at one. The saving is almost entirely in the corrections given up. Cells are not the cost made the point that a count of table cells prices the work and says nothing of the answer’s value. The prices here fall with the corrections, and a checker that saved work this way would be cheaper and would stop doing its job.

At four unseen triples the trade is closest to free: 13% of the work saved and 6% of the corrections lost, with no false suggestion prevented. That is a cost cut, not a quality repair, and it is the only threshold a checker could defend. It declines the queries so damaged that their nearest word, if any, is a guess.

What was wrong with the evidence

The evidence the proposal leaned on was real. The earlier page found unseen triples predicting a query’s distance to its nearest word, and they do: a query with four or more unseen triples lies far from the vocabulary whichever stream it came from. But distance was never the problem. The cap already measures distance exactly, and the queries it answers wrongly are the ones that are close. For a close query the triples mostly count the typos that made it close, since those write the same unseen triples into a familiar word as into an unfamiliar one.

What would separate the two kinds is evidence about the source rather than the query. A misspelt vocabulary word is one or two edits from a word on the list, and an unfamiliar word is one or two edits from a word that is not. The checker cannot see the second word. It can only see that the nearest listed word is close, and that is equally true of both. The bound the search finds for itself showed a search can learn a great deal from its own walk about where the answer lies. What a walk cannot learn is whether a writer meant a word it has no record of.

So the section’s own question has a short answer. One triple is not enough evidence to decline a word, and neither are two. A three-letter query’s single triple is unseen for half the misspelt vocabulary words of that length, because the typo that made the query wrote it. The unfamiliar words are no more likely to have one. On these streams the answer to is this a string the vocabulary could contain? is the same for both kinds of short query, and for the same reason: the vocabulary could contain almost any three letters that a slip of the fingers could produce. A test that asks it can only decline at random with respect to the thing the checker cares about. That is what the plate of corrections against false suggestions shows, every threshold on it trading corrections for false suggestions at a loss.

What was not measured

One vocabulary and one other corpus. The unfamiliar words come from one technical text about instrumenting programs, and their triples overlap the vocabulary’s because both are English written about computing. A second stream from another language or from identifiers in code would bring many more unseen triples of its own, and there the test might separate the kinds. Only this pair was measured.

Triples, counted and weighted. Unseen triples are on the plates, and the mean surprise of a query’s triples is reported in the text without a plate of its own. Pairs of letters, or longer grams, were not tried. A vocabulary ten times larger would see more of the 17,576 possible triples, so a typo would write fewer unseen ones; it would also leave fewer in the unfamiliar words, and whether the gap between the two kinds widens or narrows with the vocabulary’s size was not measured.

Uniform edits. The streams apply insertions, deletions and substitutions at uniformly random positions with uniformly random letters. Real typing errors favour adjacent keys and transpositions, which write triples that look more like English, and a real typo might carry fewer unseen triples than these. That would make the test decline fewer vocabulary words, and it would also tell the two kinds apart no better, since unfamiliar words would be mistyped the same way.

Still open: a decline that asks whether the nearest word is common

Distance and letters both fail on short words for the same reason: the question they answer is about the query, and the question that matters is about the writer’s intention. There is one source of evidence about intention the checker already holds, which is how often each vocabulary word is used. A two-edit typo of the is far more likely than a two-edit typo of theorem at the same distance, and a query whose nearest words are all rare is more likely to be a word the vocabulary lacks than a typo of one of them. A trie fitted to its queries put a trie’s structure where its queries went; a checker could weigh its answers the same way.

The measurement that follows gives each vocabulary word its frequency in the corpus it was taken from, and declines a capped answer when the nearest words’ combined frequency, weighed against the chance of the edits needed to reach them, falls below a threshold. It counts corrections kept and false suggestions removed, by length. The prediction is that the frequency test does what the triples could not on short words, removing most false suggestions to unfamiliar words of three and four letters while keeping most corrections. Common short words are both the most often mistyped and the most often suggested. The question is whether a vocabulary’s own word counts are enough to tell a slip from a word the writer meant, or whether the one thing a spelling checker cannot know is the thing it most needs.

Named alongside this one

Essays reaching for the same objects. Nobody chose these; they are what the concept index makes visible.

The objects this essay names

Each one links to every other essay that touches it.

Edit distanceExpected costMeasured countPruningQ gramThresholdTrieWorkload