When the algorithm is a table

A second try before any feature

A nearest-word search that learned one starting bound for a whole stream was proposed a bound for each query instead, read off features the search can compute before it walks. The proposed feature separates nothing: 58% of misspelt vocabulary words and 53% of words the vocabulary lacks begin with a real three-letter prefix. Length and unseen letter-triples do predict distance, and still buy about 1%, because the best start is two for almost every class. What closes half the gap to an oracle is a second cheap walk: one, then two, then discover.

A trie fitted to its queries found that a stream of misspelt words knows something its vocabulary does not: how far the answers lie. A misspelling of a vocabulary word is always within two edits of the word it came from, and a nearest-word search told its answer’s distance in advance reads a fifth of the cells of one that discovers its bound as it goes — the price the bound the search finds for itself put on not knowing. The page learned one starting bound for the whole stream, the median of the last 200 answers, and found that one try at that bound, falling back to the discovering walk when nothing lay within it, never cost more than discovering. On a stream where a fifth of the queries were misspellings of words the vocabulary lacks, it read 13,028 cells a query against discovering’s 21,090.

Its closing section proposed the obvious refinement. One number for the whole stream ignores what each query says about itself. A long query with unfamiliar letters is more likely to be a word the vocabulary lacks, and a query whose first three letters are a real prefix in the trie is more likely a misspelling of a word it has. The proposal was a bound chosen per query from such features, with the first-three-letters test singled out as the one that should separate the two kinds of query.

This page measures that proposal. The test it singled out separates nothing. Two other features do predict distance, and a start chosen from them still buys almost nothing. What does buy something, more than any feature, is a second try.

The test that was proposed does not separate

The setting is the earlier page’s exactly: the 2,424 distinct words of the collection’s fixed corpus of essays in a trie of 7,709 prefixes, 2,000 queries made by putting one or two random typing errors into vocabulary words, and 600 made the same way from words of a second fixed corpus that the vocabulary does not contain. The walk is the bounded walk the columns the candidates share built. It computes one edit-distance column per trie node, prunes a subtree when a column’s smallest value passes the bound, and tightens the bound whenever it reaches a word. Every cost below is cells of that table, every attempt charged. Every answer is checked against the discovering walk’s.

The test proposed as a separator: 58% of misspelt vocabulary words and 53% of misspelt words the vocabulary lacks begin with three letters that are a prefix in the trie — the two kinds of query go down the trie almost equally farFor each kind of query, the share whose own letters can be followed down the trie for exactly 0, 1, 2 … 5 letters before the vocabulary has no such prefix, and 6 or more. Misspelt vocabulary words: 0 1%, 1 18%, 2 23%, 3 20%, 4 13%, 5 10%, 6+ 15%. Misspelt words it lacks: 0 1%, 1 21%, 2 25%, 3 22%, 4 13%, 5 9%, 6+ 10%. The first-three-letters test sends everything at 3 or more to one side.first three letters a prefix0%10%20%30%0123456+letters of the query that are a prefix in the trieshare of queriesmisspelt vocabulary wordsmisspelt words it lacks2,000 and 600 queriesshaded: the test says known
Fig. 1 How far each kind of query’s own letters can be followed down the trie before the vocabulary has no such prefix. Misspelt vocabulary words: 18% stop after one letter, 23% after two, 20% after three, and 15% go six or more. Misspelt words the vocabulary lacks: 21%, 25%, 22% and 10%. The shaded region is what the first-three-letters test calls known: 58% of the first kind and 53% of the second.

The first-three-letters test calls 58% of misspelt vocabulary words known and 53% of misspellings of words the vocabulary lacks. The two distributions of how far a query’s letters go down the trie are nearly the same shape. The test sends the two kinds of query to its two sides in almost the same proportions, so a bound keyed on it would be applied to nearly the same mixture either way.

Both halves of the prediction’s reasoning fail. A typing error falls anywhere in a word with equal chance, and for a short word the first three letters are much of it. A misspelling of code has an error in its first three letters most of the time, so a misspelt vocabulary word loses its known prefix 42% of the time. The other half fails because the words the vocabulary lacks are English words too. Instrumented, pretending and duration begin ins, pre and dur, and a vocabulary of a few thousand English words has all of those. An unfamiliar word is unfamiliar in its middle and its end, where its stem and its suffix are.

The earlier page found the test plausible because a misspelling “usually keeps a real prefix”. That claim is true of misspellings a person makes, which cluster late in a word and near the keyboard’s neighbours. It is not true of the uniformly placed errors every measurement of this search has used, and the distinction matters. A feature’s value depends on the process that made the queries, and the one proposed was reasoned from a different process than the one it would have been used on.

Two features that do predict a distance

A query’s length and its letter-triples are different. The vocabulary’s letter-triples are a set of a few thousand, computed once. A query’s triples that are not in the set are evidence that the query is not a small edit of anything in the vocabulary, since one typing error breaks at most three triples.

The features that do predict a distance: a misspelt word the vocabulary lacks lies 1.9 edits from its nearest word when it is six letters or fewer and 6.2 when it is ten or more; a misspelt vocabulary word lies 1.3 to 1.5 edits away whatever its lengthThe mean edit distance from each query to its nearest vocabulary word, for classes of two features computable before the search: the query's length, and how many of its letter-triples never occur in the vocabulary. Length ≤ 6: misspelt vocabulary words 1.3 (44% of them), misspelt words it lacks 1.9 (37%); Length 7–9: misspelt vocabulary words 1.4 (37% of them), misspelt words it lacks 3.0 (36%); Length 10+: misspelt vocabulary words 1.5 (19% of them), misspelt words it lacks 6.2 (27%); Unseen letter-triples 0: misspelt vocabulary words 1.1 (29% of them), misspelt words it lacks 2.0 (22%); Unseen letter-triples 1: misspelt vocabulary words 1.3 (29% of them), misspelt words it lacks 2.6 (28%); Unseen letter-triples 2: misspelt vocabulary words 1.5 (23% of them), misspelt words it lacks 3.3 (23%); Unseen letter-triples 3+: misspelt vocabulary words 1.8 (19% of them), misspelt words it lacks 5.5 (28%).0246≤ 67–910+0123+lengthunseen letter-triplesmean edits to the nearest wordmisspelt vocabulary wordsmisspelt words it lackscomputed before the walkone query, one class
Fig. 2 Mean edit distance from each query to its nearest vocabulary word, by class of two features computed before the walk. By length: misspelt vocabulary words 1.3, 1.4 and 1.5 for six letters or fewer, seven to nine, and ten or more; misspelt words the vocabulary lacks 1.9, 3.0 and 6.2. By letter-triples the vocabulary never contains: 1.1, 1.3, 1.5 and 1.8 for none, one, two and three or more; for words it lacks, 2.0, 2.6, 3.3 and 5.5.

Both features predict distance, and strongly for the queries that matter. A word the vocabulary lacks lies 1.9 edits from its nearest word when it is six letters or fewer and 6.2 when it is ten or more. The more letters it has, the more of them the vocabulary cannot match, and a long technical word often has no neighbour closer than a whole suffix away. With three or more unseen letter-triples its answer lies 5.5 edits away on average; with none, 2.0. Misspelt vocabulary words move much less, 1.1 to 1.8, because a word with two errors is at most two edits from its source whatever its length.

These are the features the proposal wanted. They are cheap: a length is free, and the triples are one pass over the query against a hash set. They are computed before the search reads a single cell. And they sort the stream into classes whose answer distances genuinely differ.

The obvious next step keeps the earlier page’s rule and applies it per class: learn the median of recent answers separately for each class, and give each query one try at its own class’s median.

What a feature buys once the stream is sorted into classes

The measurement runs that rule for each feature on streams with 0%, 10%, 20% and 30% of queries from outside the vocabulary. It then asks a stronger question. For each class, what single starting bound would have been best, chosen knowing the whole stream in advance? No rule keyed on that feature can do better with one try. The same question is asked for schedules of more than one try, which the next sections come to.

At 20% unfamiliar queries, a median learned per class does better than one learned for the whole stream — 11,626 against 13,009 — but the best a feature allows in hindsight is 10,950 against 11,083 for one try and 10,194 against 10,327 for a scheduleMean cells a query on a stream with 20% of its queries for words the vocabulary lacks, for rules keyed on each feature. No feature: median of its class, one try 13,009, best single start, in hindsight 11,083, best schedule of tries, in hindsight 10,327. Prefix test: median of its class, one try 13,254, best single start, in hindsight 11,083, best schedule of tries, in hindsight 10,327. Length: median of its class, one try 11,655, best single start, in hindsight 11,083, best schedule of tries, in hindsight 10,308. Letter-triples: median of its class, one try 11,626, best single start, in hindsight 11,047, best schedule of tries, in hindsight 10,212. Length and triples: median of its class, one try 11,879, best single start, in hindsight 10,950, best schedule of tries, in hindsight 10,194. Discovering the bound costs 21,090; a search told each distance, 8,089.told: 8.1k05k10k15k20kno feature13,00911,08310,327prefix test13,25411,08310,327length11,65511,08310,308letter-triples11,62611,04710,212length and triples11,87910,95010,194median of its class, one trybest single start, in hindsightbest schedule of tries, in hindsight20% unfamiliar, cells a querydotted: told the distance
Fig. 3 Cells a query at 20% unfamiliar queries, for rules keyed on each feature. One try at the class’s own learned median: 13,009 with no feature, 13,254 on the prefix test, 11,655 on length, 11,626 on letter-triples, 11,879 on both. The best single start per class in hindsight: 11,083, 11,083, 11,083, 11,047 and 10,950. The best schedule of tries per class in hindsight: 10,327, 10,327, 10,308, 10,212 and 10,194. Discovering the bound costs 21,090; told each distance, 8,089.

The learned rule improves with the features: letter-triples take the single try from 13,009 cells a query to 11,626, 11% less. The prefix test makes it slightly worse, 13,254. That looks like the proposal half-vindicated, until the hindsight column is read beside it.

With no feature at all, the best single start in hindsight costs 11,083 cells. With the best feature, 10,950: 1.2% less. The hindsight optimum for no feature is a start of two for every query. For length it is two in every class. For letter-triples it is one for queries with no unseen triple and two for the rest; for length and triples crossed into twelve classes, one in the class of short queries with no unseen triple and two in the other eleven. A feature that predicts distance by a factor of three moves the best start by one step in a sliver of the stream.

So the 11% the letter-triples rule gained was not bought by the feature. The featureless median rule is simply a poor rule. On this stream the median answer is one edit, and 41% of misspelt vocabulary words lie at two, so a start at the median fails and falls back on nearly half the familiar queries. Splitting the stream into classes moved some classes’ medians to two, and two was the right start all along. The median was a constant somebody chose, of the kind the threshold somebody chose found in library sorts, and a single quantile set higher does the same thing with no feature: taking the 60th to 80th percentile of the last 200 answers instead of the median, the one-class rule reads 11,104 cells a query, within 0.2% of its hindsight optimum.

Why the start is two for almost everything

The reason a feature buys so little is in what the walk costs at each bound.

A walk at a bound of two costs 4,865 cells on a misspelt vocabulary word and 6,171 on a word the vocabulary lacks, against 17,621 and 35,306 for discovering the bound — a premium of a quarter to a sixth of the claim it insures against, which is why two is the start for almost everythingFor each bound from 1 to 6, the mean cells of one bounded walk at that bound (thin, dotted), and of one try at it with the discovering walk charged whenever the answer lies further (solid), on each kind of query. Misspelt vocabulary words: walk 1: 1,083, 2: 4,865, 3: 9,528, 4: 13,755, 5: 16,178, 6: 17,193; one try 1: 10,065, 2: 4,865, 3: 9,528, 4: 13,755, 5: 16,178, 6: 17,193; discovering 17,621. Misspelt words it lacks: walk 1: 1,091, 2: 6,171, 3: 14,611, 4: 22,456, 5: 27,588, 6: 30,322; one try 1: 35,810, 2: 36,318, 3: 37,728, 4: 39,358, 5: 40,187, 6: 40,164; discovering 35,306. The vertical axis is logarithmic; dashed lines are the discovering walk.10³10⁴the bound walked atcells a query123456one try, vocabularythe walk aloneone try, unfamiliarthe walk aloneevery attempt chargeddashed: discovering
Fig. 4 Cells of one bounded walk at each bound (dotted), and of one try at it with the discovering walk charged when the answer lies further (solid). Misspelt vocabulary words: walks of 1,083, 4,865, 9,528, 13,755 cells at bounds 1 to 4, one try cheapest at two with 4,865, discovering 17,621. Misspelt words the vocabulary lacks: walks of 1,091, 6,171, 14,611 and 22,456; one try from 35,810 at bound one to 40,164 at six, never under discovering’s 35,306.

A walk at a bound of two costs 4,865 cells on a misspelt vocabulary word and 6,171 on a word the vocabulary lacks. The discovering walk costs 17,621 and 35,306. One try at two is insurance, and the premium is a quarter to a sixth of the claim it covers. For a familiar query the try at two always succeeds. For an unfamiliar one it fails 56% of the time, and each failure wastes the walk — 6,862 cells on the queries that fail it — before a discovering walk that would have been paid anyway.

The asymmetry decides everything. If a class were known to hold only unfamiliar queries, the right policy would be to skip the try and discover at once, saving the premium on each. But a class that a feature can identify is never pure. The class with the most unfamiliar queries, ten letters or more with three or more unseen triples, holds 63 unfamiliar queries and 140 familiar ones on the 20% stream. Skipping the try there would save each of the 63 its walk at two, 6,943 cells on average, and cost each of the 140 the difference between discovering and a walk at two, which for these long familiar queries is 35,157 cells. The class would have to be more than five parts unfamiliar to one familiar before skipping paid, and no class a feature draws comes near that. The hindsight search picks two everywhere because the premium is small against the claim and every class contains some queries that claim.

This is what insurance against an estimate costs found for a query planner, seen from the other side. There the question was whether to buy cover against a wrong estimate; here it is whether an estimate can be good enough to cancel cover that is already cheap. A feature is worth something to a search only when it can identify queries for which the insurance is certainly wasted, and on a stream where most queries claim, a feature that shifts the odds by a factor of three still cannot.

A second try, which no feature beats

The single try’s weakness is on the familiar queries, not the unfamiliar ones. A familiar query whose answer is at one edit pays 4,865 cells for a walk at two when a walk at one, at 1,083, would have found it. Starting at one and widening to two recovers that. The earlier page measured exactly this on a pure stream — widening one step at a time from one — and found it the best policy measured there and the worst once unfamiliar queries arrived. That was because it kept widening, one walk per step, all the way to answers twenty edits away.

The policy between the two takes two steps and then stops widening: a walk at one, a walk at two, and then the discovering walk.

With a fifth of the queries unfamiliar, one try at the stream's median costs 13,009 cells a query; one try at two costs 11,083; a walk at one, then at two, then the discovering walk costs 10,327 — no feature of the query was needed for any of itMean cells a query on streams mixing misspelt vocabulary words with misspelt words the vocabulary lacks, against the share of the second kind. Discover the bound: 0% 17,621, 10% 19,257, 20% 21,090, 30% 21,702. One try at the median: 0% 10,033, 10% 11,707, 20% 13,009, 30% 13,516. One try at two: 0% 4,865, 10% 7,885, 20% 11,083, 30% 12,123. One, then two, then discover: 0% 3,726, 10% 6,933, 20% 10,327, 30% 11,424. A search told each answer's distance in advance (dotted): 0% 3,268, 10% 5,580, 20% 8,089, 30% 8,906.01020share of queries for words the vocabulary lacksthousands of cells a query0%10%20%30%discover the boundone try at the medianone try at twoone, then two, then discovertold the distanceevery attempt chargeddotted: told the answer's distance
Fig. 5 Cells a query against the share of queries for words the vocabulary lacks. Discovering the bound: 17,621 to 21,702. One try at the stream’s median: 10,033 to 13,516. One try at two: 4,865 to 12,123. A walk at one, then two, then discovering: 3,726, 6,933, 10,327 and 11,424. Told each answer’s distance (dotted): 3,268 to 8,906.

One, then two, then discover reads 10,327 cells a query at 20% unfamiliar, against 13,009 for the earlier page’s single try at the median and 11,083 for the best single start any feature allows. On a stream with no unfamiliar queries it reads 3,726, exactly what widening read there, because every familiar answer lies within two. At every mixture measured it is below one try at two and below every feature’s hindsight optimum for a single try. Measured against the gap between the earlier page’s rule and a search told every answer’s distance, it closes 55% of that gap. The best features, chosen per class in hindsight on top of it, close a further 2.7%.

Its cost falls where it should. A familiar query at one edit pays 1,083 cells. One at two pays 7,563 on average: the failed walk at one, then the walk at two. An unfamiliar query whose answer lies past two pays both short walks before discovering, 7,985 cells of premium where one try at two paid 6,862, which is why on a stream of only unfamiliar queries this schedule reads 37,086 against one try’s 36,318. The walk at one is so cheap that paying it on every query costs less than the walks at two it saves on the familiar ones.

A third step does not pay. One, two, three, then discover reads 11,081 at 20%, 7% more than stopping at two. The walk at three costs 9,528 on a familiar query and 14,611 on an unfamiliar one, and on this stream only the unfamiliar queries ever reach it, where it fails 56% of the time. Doubling is worse still: one, two, four, then discover reads 11,158, and two, four, then discover 11,914. Doubling is the schedule a band as wide as the answer uses to find an edit distance between two strings, where the cost of a band grows linearly with its width and a geometric schedule wastes at most a constant factor. Here the cost of a bound grows much faster than linearly, and the answers pile up at two steps and then scatter over twenty. A schedule has to be fitted to where the answers are, and this stream’s answers are at one and two, or anywhere at all.

A schedule chosen from a price list, and the queries that pay it

A fixed schedule was found by trying eight of them. The natural way to make that automatic is to price each schedule and pick the cheapest per query. The walk’s cost at each bound, by query length, is a property of the trie and can be measured once on a calibration stream. The chance that the answer lies past each bound can be read off the last 200 answers. The discovering walk’s cost can be learned from the fallbacks the search actually pays.

That rule reads 11,146 cells a query at 20% unfamiliar, 8% more than the fixed schedule it was meant to find. It chooses one, two, three, then discover for most queries, the schedule the measurement just showed is 7% dearer. Pricing the discovering walk by how far the answers that fell back had lain, rather than by the mean of all fallbacks, changes the result by less than 0.2%.

Why a schedule chosen from a price list loses to a fixed one: the queries that reach a walk at three pay 19,254 cells for it, not the 12,633 the list says, and the ones still unfound after three pay 72,606 to discover, not 41,235On a stream with 20% unfamiliar queries: for the queries that reach each step of a schedule — a walk at a bound s reached by queries whose answer lies at s or further, a discovering walk reached by those whose answer lies past s — the mean cells the step costs them (dark) against the price the list gives queries of the same lengths (light). Walk at 1, d ≥ 1 (98% of queries): 1,093 against 1,084; Walk at 2, d ≥ 2 (51% of queries): 6,516 against 5,112; Walk at 3, d ≥ 3 (11% of queries): 19,254 against 12,633; Discover, d > 1 (51% of queries): 27,823 against 21,867; Discover, d > 2 (11% of queries): 52,737 against 32,100; Discover, d > 3 (6% of queries): 72,606 against 41,235. A rule choosing schedules from the list reads 11,146 cells a query; the fixed schedule 1, 2, discover reads 10,327.020k40k60k80kwalk at 1d ≥ 1walk at 2d ≥ 2walk at 3d ≥ 3discoverd > 1discoverd > 2discoverd > 3cells, for the queries that reach the stepthe price list, by lengthwhat those queries pay20% unfamiliarpriced on 400 calibration queries
Fig. 6 For the queries that reach each step of a schedule on a stream with 20% unfamiliar queries, the price the list gives queries of their lengths (light) and what the step actually costs them (dark). Walk at one, reached by 98% of queries: 1,084 priced, 1,093 paid. Walk at two, 51%: 5,112 and 6,516. Walk at three, 11%: 12,633 and 19,254. Discovering past one: 21,867 and 27,823; past two: 32,100 and 52,737; past three: 41,235 and 72,606.

The price list is right about the average query and wrong about the queries that reach each step. A query reaches the walk at three only when its answer lies at three or beyond, and those are the queries for which every walk is dear. They are long and unfamiliar, and they keep their bounds loose for most of the trie. The walk at three costs them 19,254 cells, 52% more than the list’s 12,633. The discovering walk after three costs them 72,606, 76% more than the list’s 41,235. At the first step the list is right, because nearly every query reaches it. The error grows with every step, because each step selects a narrower and dearer set of queries.

That is selection, and a price list keyed on length cannot see it. Length is correlated with being unfamiliar, but the queries that fail at two are a far more selected set than the long ones. A rule that multiplies the chance of reaching a step by the average price of that step has assumed the two are independent, and here they are not. A budget split before the question arrives failed in the same way from a different direction: a textbook variance for a difference of sketches omitted a covariance, and a switch that believed it chose wrong on every draw. In both cases the formula was built from quantities that are each right on average, and the error is in their product.

The fixed schedule avoids the problem by not pricing anything. A rule that tried each schedule in turn and kept the cheapest measured one would avoid it too, since it would pay the real costs of the queries that reach each step. What cannot work is a model of the steps priced separately, because the cost of a step and the chance of reaching it are set by the same thing, the query’s distance from the vocabulary.

What was measured and what was not

Uniform typing errors, one vocabulary. The queries have one or two errors placed uniformly in the word. Real errors cluster late in the word and near the keyboard’s neighbours, which would make the first-three-letters test better than it is here. On such a stream the prefix test might separate the two kinds of query, and the measurement says nothing either way.

One corpus of unfamiliar words. The words the vocabulary lacks are technical English, so they share its prefixes. Proper names, foreign words or random strings would share fewer, and a feature that separated them could pay. It would pay only in a class unfamiliar enough that skipping the insurance saves more than it costs the familiar queries in the class, and the price plate says how unfamiliar that is.

Features chosen in advance. Three features were tried, the three the earlier page proposed or that are nearly free. A learned classifier over many features might identify unfamiliar queries better, and there is a ceiling on what it could buy. A search that knew perfectly which kind each query was, and gave every familiar query one try at two and every unfamiliar one the discovering walk at once, would read 10,884 cells a query at 20% — 5% more than the fixed schedule, which identifies nothing. Given the schedule for its familiar queries instead, the perfect classifier reads 9,973, 3.4% under it. Perfect knowledge of which kind a query is buys less than a second walk at one bound.

Cells, not time. Every count is a cell of the edit-distance table, the earlier pages’ unit. A schedule of three walks restarts from the root three times. The count is not the time is the reminder that restarts and cells are priced differently by a machine, and that difference is unmeasured here.

Still open: the answer a checker can decline to give

Every policy here ends in the discovering walk, which finds the nearest vocabulary word however far away it is. The selection plate says what that costs: the queries still unfound after a walk at two pay 52,737 cells each to discover, and they are 11% of the stream. For those queries, the answer found is almost never useful. A misspelt vocabulary word is always within two edits of its source, so every query that fails the walk at two is a query whose intended word the vocabulary does not have. The nearest vocabulary word to instrumnted is not what its writer meant, however carefully it is found.

That suggests a checker that declines. After the walk at two fails it reports “no suggestion within two edits” and stops, or it pays for one more walk at three and then stops. The filter that feeds the table refused candidates before they reached a table on a cheap test. This would refuse the answer after a cheap test, which is a different kind of economy, since it changes what the search promises rather than how it keeps the promise.

The measurement that follows sets a cap on the answer’s distance, from one to six and none, and counts two things at each: the cells a query and the share of queries whose intended word is among the suggestions returned. For misspelt vocabulary words the intended word is known. For misspellings of words the vocabulary lacks the right suggestion is none, and a suggestion at any distance counts as a false one. The prediction is that a cap at two keeps every useful suggestion on this stream and costs about a third of discovering, and that the false suggestions the uncapped search makes are almost all at three edits or more. The cap would then be worth more than any schedule, because it removes the most expensive walk rather than fitting the walks before it. It could fail in one way: if a large share of unfamiliar words have a vocabulary word within two edits that is a plausible suggestion — a plural, a tense, a word with a common suffix — then a cap at two keeps those false suggestions and saves only the far walks.

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.

Cost modelEdit distanceExpected costLower boundMeasured countPredictionPruningSelection biasThresholdTrieWorkload