Stem words 到其 根 form
Stemming reduces words 到其 stem (running → 运行, better → bet). Learn Porter stemmer 和当 到 use lemmatization instead.
- 1
Stemming removes suffixes 到查找字 stem: "running" → "运行", "happily" → "happi", "better" → "bet". Porter stemmer 是最多常见 algorithm — 快但 crude (produces non-words). Lemmatization 我们 dictionary 到查找引理: "better" → "好", "running" → "运行" — accurate 但 slower. Use stemming 为搜索 indexing, lemmatization 为 NLP 分析.
- 2 字数统计器 →
统计 words before and after stemming to verify the vocabulary reduction. Stemming typically reduces vocabulary by 20-40%, which improves search recall (different forms match the same stem).
- 3 正则表达式替换器 →
Implement simplified stemmer 具有 regex: 移除常见 suffixes (s, es, ed, ing, ly, ment). Replace (\w+)s$ 具有 $1, (\w+)ing$ 具有 $1. 此是 crude 但 demonstrates concept. 为 production, use proper stemmer 库 (Porter, Lancaster, Snowball).
常见问题
- Stemming vs lemmatization?
- Stemming 是快 和 crude — 它 chops suffixes using rules, producing non-words ("happi" 从 "happily"). Lemmatization 是 slower 但 accurate — 它我们 dictionary 和 morphology 到查找 actual 根字 ("happy" 从 "happily"). Use stemming 为搜索 (速度 matters, 召回率是 重要); use lemmatization 为 NLP 分析 (准确率 matters).
- 哪个 stemmer 应该 I use?
- Porter 是最多常见 — 好 balance 的速度和 准确率. Lancaster 是更多 aggressive (over-stems). Snowball (Porter2) 是 improved Porter. 为 non-English, use language-specific stemmers (ISnowball, OUD). 为 production NLP, use lemmatization (spaCy, NLTK) instead.