首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >AttributeError:“列表”对象没有属性“相似性”

问AttributeError:“列表”对象没有属性“相似性”
EN

Stack Overflow用户
提问于 2019-05-05 14:41:26
回答 1查看 1.6K关注 0票数 0
代码语言:javascript
复制
ws = {}
nlp = spacy.load('de_core_news_sm')
data = 'Some long text'
train_corpus = nlp(data)
train_corpus = [token.text for token in train_corpus if not token.is_stop and len(token) > 4]
test_corpus = nlp('Some short sentence')   
ae = train_corpus.similarity(test_corpus)

我在AttributeError: 'list' object has no attribute 'similarity'在ae = train_corpus.similarity(test_corpus)。如果我删除了train_corpus = [token.text for token in train_corpus if not token.is_stop and len(token) > 4],它就会正常工作,但仍然可以使用秒针。

我如何删除停止的话,使它仍然有效?

编辑:ae = nlp(train_corpus).similarity(test_corpus)通向TypeError: Argument 'string' has incorrect type (expected str, got list)。

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2019-05-07 14:19:22

请注意,您正在使用德语模式的英语短语。在您的示例中,您需要将剩余的令牌粘合起来,并再次创建一个"spacy对象“。在您的情况下,您可以通过以下条件删除所有令牌--len(令牌)>4。

代码语言:javascript
复制
import spacy

nlp = spacy.load('en_core_web_sm')
# nlp = spacy.load('de_core_news_sm')
ws = {}
#data = 'Some long text'
data = 'Some long text Elephant'
train_corpus = nlp(data)
train_corpus = nlp(" ".join([token.text for token in train_corpus if not token.is_stop and len(token) > 4]))
test_corpus = nlp('Some short sentence')
ae = train_corpus.similarity(test_corpus)

print(ae)
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/55993124

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档