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.

11.3 词干提取

词干提取(Stemming)是自然语言处理(NLP)中的一种技术,用于将单词还原为其词根或词干形式。词干提取的目的是消除不同词形变化带来的多样性,从而将具有相同词根的单词归一化,便于文本分析和处理。

例如,如果我们对单词 Stems、Stemming、Stemmed 和 Stemitization 进行词干提取,结果将是一个单词:Stem。

使用 NLTK 库进行词干提取的代码如下所示:

from nltk.stem.snowball import SnowballStemmer 
text = "It's a Stemming testing"
parsed_text = word_tokenize(text)
stemmer = SnowballStemmer('english')

[(word, stemmer.stem(word)) for i, word in enumerate(parsed_text)
if word.lower() != stemmer.stem(parsed_text[i])]
[('Stemming', 'stem'), ('testing', 'test')]