无法从’gensim.models.doc2vec’导入名称’LabeledSentence’。

huangapple go评论84阅读模式
英文:

Cannot import name 'LabeledSentence' from 'gensim.models.doc2vec'

问题

这是我每次尝试执行代码时都会遇到的错误。无法从'gensim.models.doc2vec'导入名称'LabeledSentence' 问题的来源(指示的目录路径)是这个文件:

它似乎没有**'from gensim.models.doc2vec import LabeledSentence',所以我不知道如何解决这个问题。我在一个类似的主题中看到,库gensim.models.doc2vec中的LabeledSentence已被弃用,所以我应该将gensim.models.doc2vec替换为gensim.models.deprecated.doc2vec**,但是...在代码中哪里?它在代码中并没有出现。这不是我第一次在导入的代码中遇到这样的问题。有人可以帮帮我吗?
术语**"LabeledSentence"**甚至在代码中都没有出现。

英文:

无法从’gensim.models.doc2vec’导入名称’LabeledSentence’。

This is the error I get every time I try to execute the code. cannot import name 'LabeledSentence' from 'gensim.models.doc2vec'
The source of the problem (the directory path indicated) is this file:

无法从’gensim.models.doc2vec’导入名称’LabeledSentence’。

It doesn't seems to have a "from gensim.models.doc2vec import LabeledSentence" so I don't know how to fix the problem. I saw in a similar topic that the library gensim.models.doc2vec LabeledSentence is deprecated so I should substite gensim.models.doc2vec with gensim.models.deprecated.doc2vec but..where? It doesn't appear in the code. This is not the first time I have problems like this with my imported code. Can anyone help me?
The term "LabeledSentence" doesn't even appear in the code

答案1

得分: 1

似乎您正在使用一些五年前的代码(也许是https://github.com/FakeNewsDetection/FakeBuster/tree/master?),这些代码依赖于一个旧版本的Gensim。

可能可以通过更新对LabeledSentence的引用来解决这个特定错误,改为导入/使用gensim.models.doc2vec.TaggedDocument

然而,更新此代码可能需要修复其他问题,而一些问题可能只会悄悄地降低结果,而不是指出需要更改的代码行。

因此,您需要阅读并理解您尝试使用的代码,并通过错误消息、日志输出和测量结果来验证它是否按照您的期望工作。(也就是说,这么旧的代码不能作为一个可信的“黑匣子”,只会按照它说的去做。)

可以尝试猜测该项目使用了哪个旧版本的Gensim,但是由于它没有正式声明所需的版本(在文档或类似requirements.txt的规范中),这将需要根据当时的活跃发布版本进行一些试验和错误。但是,即使成功,这也意味着您的Gensim和其他相关库可能会落后于当前库和在线帮助,性能、错误和使用技巧方面。

如果您不特别坚持使用那个过时的代码片段,您可以考虑在其他更近期维护的示例上构建您当前的任务/分配。

英文:

It appears you're using some 5-year-old code (perhaps https://github.com/FakeNewsDetection/FakeBuster/tree/master ?) that's dependent on a much-older version of Gensim.

You might be able to get over this one particular error by updating references to LabeledSentence to instead import/use gensim.models.doc2vec.TaggedDocument.

However, there are likely to be other problems that need fixing to update this code – and some might just silently degrade results, rather than give big errors pointing at exactly the lines-of-code to change.

So you'd need to read & understand the code you're trying to use, and via error messages, logged output, & measured results, verify that it's doing what you wanted. (That is, code this old can't be used as a trustworthy 'black box' that just does-what-it-says.)

You could try guessing exactly which older version of Gensim was used by the project, but as it hasn't formally declared the version it needs (in docs or a requirements.txt-like spec), that would require some trial-and-error based on then-active releases. But, even if it works, it'd mean your Gensim & perhaps other related libraries would be years behind current libraries & online help with regard to performance, bugs, & usage tips.

If you are not specifically wedded to the idea of using that particular bit of outdated code, you might consider building whatever your current task/assignment is on some other more-recently-maintained examples.

huangapple
  • 本文由 发表于 2023年6月26日 22:27:25
  • 转载请务必保留本文链接:https://go.coder-hub.com/76557640.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定