Demonstration 1 of 1
Word, character and combined TF-IDF when only the assessment text has typos
At what typo rate, and at what term coverage, does a character TF-IDF model overtake a word model?
A word model can only use words it saw in training, so every misspelled word becomes a blank. Character n-grams keep matching the unchanged fragments, but spanning word boundaries they also add noisy features, which is why they lose on clean text. Where the two lines cross is a property of the data and the metric, not a coverage constant. Placing both representations side by side gives the lowest log loss up to moderate noise here, but under heavy typos it only ties the character model, and with any typos it is less accurate than characters alone, so the scored metric decides.
Scroll sideways for the whole equation
Coverage is the frequency-weighted share of assessment tokens found in the training vocabulary. Log loss is the mean negative log probability of the true class (lower is better), accuracy the share of correct top predictions.
Predict first. With 20% of assessment words misspelled (about 81% coverage), which model has the lower log loss?
Choose an example
Scroll sideways for the whole figure
Constructed example: seeded synthetic titles from invented words and sparse logistic regressions, measured by the chapter activity.
Calculated values
- Token coverage
- 0.814
- Word log loss
- 0.434
- Character log loss
- 0.425
- Combined log loss
- 0.389
- Word accuracy
- 0.864
- Character accuracy
- 0.890
With 20% of assessment words misspelled, 0.814 of assessment tokens are in the training vocabulary. Word log loss is 0.434 and character log loss 0.425: 0.434 - 0.425 = 0.009 (standard error 0.004). The character model is ahead on log loss by a small margin, between two and three standard errors: this is near the switch. Accuracy is 0.864 for words and 0.890 for characters; the combined model has log loss 0.389 and accuracy 0.879.
Worked steps
- Coverage of assessment tokens: 0.814.
- Log loss, word minus character: 0.434 - 0.425 = +0.009 (positive means characters are better).
- Accuracy, character minus word: 0.890 - 0.864 = +0.026.
- Combined model against the better single model: 0.389 - 0.425 = -0.037 log loss.
Use the idea
Measure frequency-weighted coverage of the assessment text first, then compare word, character and combined sparse models on identical rows with the scored metric, before spending time on embeddings.
Where the conclusion applies
Constructed text from invented words, with typos in the assessment text only; real noise has structure (keyboard neighbours, language), and training text with the same typos would favour the word model. The character analyzer spans word boundaries as in the chapter's baseline; a word-bounded analyzer would lose less on clean text. Models are regularised logistic regressions with C = 10.
Check your understanding: On clean text the word model wins clearly. Why is that not a reason to drop character features, and what does a coverage rule miss?
Chapter 49 source: section "A Small Sparse Comparator".