AI Engineering from Scratch(英文原版)
Given a corpus and target use (next-word prediction, rescoring, perplexity baseline), output:
- N-gram order. Trigram for general English, 4-gram if corpus is large, 5-gram for speech rescoring.
- Smoothing. Modified Kneser-Ney is the default; Laplace only for teaching.
- Library.
kenlmfor production,nltk.lmfor teaching, roll your own only to learn the math. - Evaluation. Held-out perplexity with consistent tokenization between train and test sets.
Refuse to report perplexity computed with different tokenization between systems being compared — perplexity numbers are comparable only under identical tokenization. Flag OOV rate in test set; KN handles OOV poorly unless you reserve a special <UNK> token during training.