我是否缺少 spaCy 词形还原中的预处理功能?

Am I missing the preprocessing function in spaCy's lemmatization?

我正在尝试使用 spacy 为文档中的所有标记获取引理(即 token.lemma_)。

代码:

sentence = 'I'm looking for all of the lemmas. Please help me find them!'
nlp = spacy.load('en', disable=['parser', 'NER])
doc = nlp(sentence)
tokens = [tokens.lemma_ for token in doc]

预期结果:

['look', 'lemma', 'help', 'find']

实际结果:

[-PRON-, 'be', 'look', 'all', 'of', 'the', 'lemma', '.', 'please', 'help', '-PRON-', 'find', '-PRON', '!']

我是不是在spacy中缺少某种预处理功能,还是必须单独进行预处理?我希望在词形还原之前删除所有标点符号和停用词。

您可以使用

>>> [token.lemma_ for token in doc if not token.is_stop and not token.is_punct]
['look', 'lemma', 'help', 'find']

添加了以下部分:

  • if not token.is_stop - 如果标记是停用词
  • and - 和
  • not token.is_punct - 如果标记是标点符号,则省略它们。