Search code examples
pythoncompiler-errorsgensim

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


enter image description here

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:

enter image description here

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


Solution

  • 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.