Python 我是否缺少spaCy'中的预处理功能;什么是柠檬化?
我正在尝试使用spacy为文档中的所有令牌获取引理(即token.lemma_) 代码:Python 我是否缺少spaCy'中的预处理功能;什么是柠檬化?,python,spacy,lemmatization,Python,Spacy,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', '
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', '!']
预期结果:
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', '!']
实际结果:
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']
增加了以下部分:
-如果token是stopword如果不是token.is_stop
-和和
-如果标记是标点符号,则省略它们不是标记。是点状的
be
是一个停止字,如果您使用if token.is\u stop
,它将被过滤,但您希望它出现在输出中[token.lemma uuuu如果不是token.is u stop而不是token.is u punt,则用于文档中的token]
返回['look','lemma','help','find']
。请为您的问题添加更多详细信息。@WiktorStribiżew我不知道“be”会是这个问题的停止词,因为它不在NLTK停止词列表中。我一直在寻找的就是停下来和点。谢谢