Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/291.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 我是否缺少spaCy'中的预处理功能;什么是柠檬化?_Python_Spacy_Lemmatization - Fatal编程技术网

Python 我是否缺少spaCy'中的预处理功能;什么是柠檬化?

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', '

我正在尝试使用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', '!']
预期结果:

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.is_stop
    -如果token是stopword
  • -和
  • 不是标记。是点状的
    -如果标记是标点符号,则省略它们

您可以添加一个条件以排除不需要的tokens@SergeyBushmanov作为spaCy的一部分,或者仅仅作为结果的一个条件?第二种选择你说你需要得到所有的标记引理,那么你为什么要说过滤掉一些东西呢?请澄清问题。注意
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停止词列表中。我一直在寻找的就是停下来和点。谢谢