gpt4 book ai didi

python-3.x - 我的作业文档中的 NLP 示例崩溃了

转载 作者:行者123 更新时间:2023-12-05 01:39:57 24 4
gpt4 key购买 nike

所以我是 NLP 的新手,我正在尝试我的文档中的示例代码,但它给了我错误。

比如

"ModelsWarning: [W007] 您使用的模型没有加载词向量,因此Token.similarity方法的结果将基于tagger、parser和NER,这可能无法给出有用的相似性判断。如果您使用的是一种小型模型(例如 en_core_web_sm),则可能会发生这种情况,它不附带词向量,只使用上下文敏感的张量。您可以随时添加自己的词向量,或者如果可用,请改用其中一种较大的型号”

我从文档中完全输入的第二句话给出了这个错误

“只能将 str(不是“numpy.float64”)连接到 str”

我可能只是在做一些愚蠢的事情,但我会很感激一些关于为什么会发生这种情况的见解

import spacy
nlp = spacy.load('en')

tokens = nlp('cat apple monkey banana')

for token1 in tokens:
for token2 in tokens:
print(token1.text, token2.text, token1.similarity(token2))


print("\nWorking With Sentences\n")

sentence_to_compare = 'Why is my cat on the car'

sentences = ["Where did my dog go",
'hello, where is my car',
'I\'ve lost my car in my car',
'i\'d like my boat back',
'I will name my dog Diana'
]

model_sentences = nlp(sentence_to_compare)

for sentence in sentences:
similarity = nlp(sentence).similarity(model_sentences)
print(sentence + "-" + similarity)

最佳答案

SpaCy 的小型模型 (en_core_web_sm, en) 没有给出相似性方法的最佳结果,因为它们没有附带词向量张量。这就是您在控制台中收到警告的原因。因此,我认为您应该使用 en_core_web_lg 而不是小型模型。

关于python-3.x - 我的作业文档中的 NLP 示例崩溃了,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57445532/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com