我加载了常规的spacy语言,并尝试了以下代码:
import spacy
nlp = spacy.load("en_core_web_md")
text = "xxasdfdsfsdzz is the first U.S. public company"
if 'xxasdfdsfsdzz' in nlp.vocab:
print("in")
else:
print("not")
if 'Apple' in nlp.vocab:
print("in")
else:
print("not")
# Process the text
doc = nlp(text)
if 'xxasdfdsfsdzz' in nlp.vocab:
print("in")
else:
print("not")
if 'Apple' in nlp.vocab:
print("in")
else:
print("not")
在调用分析后,似乎是空间加载的单词-- nlp(text)
,有人能解释输出吗?我怎么才能避免呢?为什么"Apple
“不存在于词汇表中?为什么"xxasdfdsfsdzz
“存在?
输出:
not
not
in
not
发布于 2022-02-27 20:26:29
spaCy词汇表主要是与存储字符串的内存高效方法接口的内部实现细节。它肯定是,而不是--一个“真实单词”的列表,或者其他你可能会发现有用的东西。
默认情况下,词汇表存储的主要内容是内部使用的字符串,例如POS和依赖项标签。在具有向量的管道中,还包括向量中的单词。您可以阅读有关实现细节这里的更多信息。
nlp
对象看到的所有单词都需要存储它们的字符串,因此将出现在词汇表中。这就是你在上面的例子中所看到的无稽之谈。
https://stackoverflow.com/questions/71280615
复制相似问题