TypeError:Python空间停止字NLP中需要整数
为什么在Python Spacy中获取“需要整数”这样的错误TypeError:Python空间停止字NLP中需要整数,python,nlp,spacy,Python,Nlp,Spacy,为什么在Python Spacy中获取“需要整数”这样的错误 import spacy from spacy.lang.en import English nlp = English() from spacy.lang.en.stop_words import STOP_WORDS doc = nlp('Hello World') for word in doc: print(nlp.vocab[word].is_stop) 错误 --------------------------
import spacy
from spacy.lang.en import English
nlp = English()
from spacy.lang.en.stop_words import STOP_WORDS
doc = nlp('Hello World')
for word in doc:
print(nlp.vocab[word].is_stop)
错误
---------------------------------------------------------------------------
TypeError Traceback (most recent call last)
<ipython-input-58-028ad9619aba> in <module>()
5 doc = nlp('Hello World')
6 for word in doc:
----> 7 print(word in nlp.vocab)
vocab.pyx in spacy.vocab.Vocab.__contains__()
TypeError: an integer is required
---------------------------------------------------------------------------
TypeError回溯(最近一次调用上次)
在()
5 doc=nlp(“你好世界”)
6对于文档中的word:
---->7打印(nlp.vocab中的单词)
spacy.vocab.vocab.中的vocab.pyx包含
TypeError:需要一个整数
只需将令牌转换为字符串,它就可以工作了
import spacy
from spacy.lang.en import English
nlp = English()
from spacy.lang.en.stop_words import STOP_WORDS
doc = nlp('Hello World, I am Juned')
for word in doc:
print(nlp.vocab[str(word)].is_stop)
简单地将令牌转换成字符串,它就可以工作了
import spacy
from spacy.lang.en import English
nlp = English()
from spacy.lang.en.stop_words import STOP_WORDS
doc = nlp('Hello World, I am Juned')
for word in doc:
print(nlp.vocab[str(word)].is_stop)
如果你需要的话,可以用这个来代替stopwords
如果需要将其用于stopwords,请使用此选项。stopword值作为
文档中标记的标记
属性提供,因此可以简化为:
from spacy.lang.en import English
nlp = English()
doc = nlp('Hello World')
for word in doc:
print(word.is_stop)
停止字值作为文档
中标记的标记
属性提供,因此可以简化为:
from spacy.lang.en import English
nlp = English()
doc = nlp('Hello World')
for word in doc:
print(word.is_stop)
您希望输出的内容是什么,您希望输出为真/假还是其他类型,尝试基于stopwords“基于stopwords”打印真、假?但是您正在检查单词是否存在于nlp.vocab
中,您是否应该像这样替换检查print(单词在停止词中)
?因为vocab
返回单词我认为打印(STOP\u WORDS中的单词)不起作用,我们必须检查like print(nlp.vocab['via'].is\u STOP),要检查token是stopword还是not你想输出什么,你想输出为真/假还是其他什么,尝试根据stopwords“基于stopwords”打印真、假 ? 但是您正在检查单词是否存在于nlp.vocab
中,您是否应该像这样替换检查print(单词在停止词中)
?因为vocab
返回单词我认为print(STOP\u WORDS中的单词)不起作用,我们必须检查like print(nlp.vocab['via'].is\u STOP),要检查token是否是stopword