Skip to article frontmatterSkip to article content
Site not loading correctly?

This may be due to an incorrect BASE_URL configuration. See the MyST Documentation for reference.

Summary

Method Comparison

Stemmers and lemmatizers side by side.

MethodApproachCorrectnessSpeedMulti-lingualNeeds dictionary
PorterRule-based suffix stripping (English)pseudo-stemfastEnglish onlyno
LancasterAggressive rule-based (English)pseudo-stem, over-stems short wordsfastestEnglish onlyno
SnowballRule-based frameworkpseudo-stemfast20+ languagesno
WordNetDictionary + POS lemmatizerlinguistic lemmaslowEnglish only (multilingual variants weaker)yes
spaCyNeural POS tagger + dictionary lemmatizerlinguistic lemmamediummany languagesyes

Use a rule-based stemmer when performance dominates or when no dictionary is available for the language. Use a dictionary-based lemmatizer when accuracy on strongly-inflected languages matters (German case-inflected nouns, English strong verbs like “went -> go”) or when the downstream task needs linguistic base forms rather than arbitrary reductions. Snowball is the go-to compromise for multi-language corpora when only rule-based options are practical.

Key Takeaways

  1. Classical retrieval fails in two directions: one concept has many surface forms on the document side (recall gap), and free-text queries carry structure that the retriever ignores (query understanding gap). Advanced text processing addresses both.

  2. Tokenization is the first stage and the largest source of quality issues. A naive regex tokenizer breaks on possessives, numbers, abbreviations, and punctuation. Modern nltk and spaCy tokenizers handle these but still need retrieval-oriented cleanup.

  3. Normalization decides which surface forms collapse to the same token. Case folding is nearly always applied. Unicode normalization is applied silently. Accent folding trades recall for precision and depends on the scenario.

  4. Sentence segmentation is a small but essential step. Every RAG chunking strategy, every POS tagger, and every query-analysis pipeline depends on being able to find sentence boundaries reliably.

  5. Stop-word removal is a size-versus-recall trade-off. Modern BM25-based systems handle stop words gracefully through IDF and can afford to keep them in the index. Legacy vector-space systems remove them aggressively. Phrase queries and titles like Stephen King’s “It” break under aggressive removal.

  6. Stemming is a fast pseudo-linguistic reduction; lemmatization is a slower dictionary-based one that produces the true linguistic base form. Choose based on speed budget, language complexity, and whether downstream steps need real words.

  7. Phrases and compounds sit on opposite sides of the word-boundary problem. Bi-grams like “New York” pack multiple tokens into one concept and need explicit phrase indexing; PMI and LHR are the classical selectors for which bi-grams are worth adding. Compounds like “Bücherregal” do the reverse, hiding multiple concepts in one token, and are split into their parts by log-frequency scoring, though only endocentric compounds split safely (a “Bücherregal” is a kind of “Regal”; a “Wolkenkratzer” is not a kind of “Kratzer”, so splitting it hurts precision).

  8. Query understanding turns free text into structured features: language, POS tags, named entities, corrected spelling. Together they let the retriever route the query to the right backend and generate structured queries rather than doing bag-of-words matching.

  9. A Naive Bayes classifier applied to hand-engineered features is enough to build both a language detector and an intent classifier. Modern production stacks use neural classifiers for accuracy but keep Naive Bayes as the baseline and as the fast path for cost-sensitive deployments.

  10. Every classical technique in this chapter still runs in production 2025 search stacks. Dense retrieval subsumes some of them (synonym expansion) implicitly, but hybrid retrieval combines both branches and needs the classical stack on the lexical side.

Key Formulas

pmi(t1,t2)=log⁡2N⋅tf(t1,t2)tf(t1)⋅tf(t2)\text{pmi}(t_1, t_2) = \log_2 \frac{N \cdot \text{tf}(t_1, t_2)}{\text{tf}(t_1) \cdot \text{tf}(t_2)}

Pointwise Mutual Information: high when two tokens almost always appear together and rarely apart. Biased toward rare-word bi-grams; requires a minimum-frequency filter.

log⁡λ=log⁡L(H1)L(H2)\log \lambda = \log \frac{L(H_1)}{L(H_2)}

Log Likelihood Ratio: log-ratio of the probability under independence to the probability under dependence. Robust on sparse data; ranks by −2log⁡λ-2 \log \lambda.

score(S)=1∣S∣∑pi∈Slog⁡tf(pi)N\text{score}(S) = \frac{1}{|S|} \sum_{p_i \in S} \log \frac{\text{tf}(p_i)}{N}

Compound Split Score: average log-frequency of the parts in split SS. Choose the split with the highest score.

C^=arg⁡max⁡k(log⁡P(Ck)+∑j=1Mlog⁡P(xj∣Ck))\hat{C} = \arg\max_{k} \left( \log P(C_k) + \sum_{j=1}^{M} \log P(x_j \mid C_k) \right)

Naive Bayes Maximum A Posteriori: pick the class that maximizes the log-prior plus the sum of log-likelihoods. Used for language detection over character n-grams and for intent classification over feature vectors combining tokens, POS tags, and NER labels.

Self-Check Questions

  1. (Understand) The naive tokenizer produces ['Watson', 's'] from “Watson’s”. Under what retrieval scenario is this desirable, and under what scenario is it a problem? What information is permanently lost?

  2. (Understand) Why does BM25 tolerate stop words that appear in the index better than a raw vector-space TF-IDF model does?

  3. (Analyze) Given the A Study in Scarlet corpus where “said” occurs 207 times, “Holmes” 98 times, “Sherlock” 52 times, “Sherlock Holmes” 52 times, and “said Holmes” 12 times, compute PMI for the two bi-grams “Sherlock Holmes” and “said Holmes”. Explain why the ranking matches (or does not match) what a human would call “the more meaningful phrase”. Assume a corpus of N=43,200N = 43{,}200 tokens.

  4. (Analyze) Explain why aggressive accent folding hurts a legal-document retrieval system for German but helps a general-purpose web search engine over the same language.

  5. (Analyze) A retrieval system indexes “Wolkenkratzer” only as itself (no compound splitting). A user queries “Wolke”. A different user queries “Kratzer”. Which query, if any, retrieves documents about skyscrapers, and why? Would splitting help both users equally? Would you split this specific compound?

  6. (Evaluate) A production search team proposes replacing the entire classical query pipeline (tokenization, stemming, POS, NER, intent classification) with a single call to a large language model that outputs a structured query directly. State two reasons the team might keep the classical pipeline anyway, and one query type where the LLM call is likely to win.

  7. (Apply) A user queries “Livres de Molière”. Walk through the end-to-end pipeline from section 5, listing the output of each step and the final routing decision. Assume the search stack supports French.

Further Reading

Implementations and tools

The classical tools in this chapter sit at the end of a seventy-year research arc. The optional note below traces that history from 1950s symbolic AI through statistical corpus methods to today’s neural models, for readers who want the wider context.