Python:“Doc2Vec”对象没有属性“dv”

问题描述 投票:0回答:2

感谢您的建议,我已经编辑了问题

我遇到了这个:

AttributeError: 'Doc2Vec' object has no attribute 'dv'

错误来自

Traceback (most recent call last):
  File "F:\Projects\项目代码\爬虫程序\headline\main.py", line 13, in <module>
    execute(["scrapy", "crawl", "head_spider", '-a', 'key='+sys.argv[1]])
  File "C:\Python310\lib\site-packages\scrapy\cmdline.py", line 144, in execute
    cmd.crawler_process = CrawlerProcess(settings)
  File "C:\Python310\lib\site-packages\scrapy\crawler.py", line 290, in __init__
    super().__init__(settings)
  File "C:\Python310\lib\site-packages\scrapy\crawler.py", line 167, in __init__
    self.spider_loader = self._get_spider_loader(settings)
  File "C:\Python310\lib\site-packages\scrapy\crawler.py", line 161, in _get_spider_loader
    return loader_cls.from_settings(settings.frozencopy())
  File "C:\Python310\lib\site-packages\scrapy\spiderloader.py", line 67, in from_settings
    return cls(settings)
  File "C:\Python310\lib\site-packages\scrapy\spiderloader.py", line 24, in __init__
    self._load_all_spiders()
  File "C:\Python310\lib\site-packages\scrapy\spiderloader.py", line 51, in _load_all_spiders
    for module in walk_modules(name):
  File "C:\Python310\lib\site-packages\scrapy\utils\misc.py", line 88, in walk_modules
    submod = import_module(fullpath)
  File "C:\Python310\lib\importlib\__init__.py", line 126, in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
  File "<frozen importlib._bootstrap>", line 1050, in _gcd_import
  File "<frozen importlib._bootstrap>", line 1027, in _find_and_load
  File "<frozen importlib._bootstrap>", line 1006, in _find_and_load_unlocked
  File "<frozen importlib._bootstrap>", line 688, in _load_unlocked
  File "<frozen importlib._bootstrap_external>", line 883, in exec_module
  File "<frozen importlib._bootstrap>", line 241, in _call_with_frames_removed
  File "F:\Projects\项目代码\爬虫程序\headline\headline\spiders\head_spider.py", line 6, in <module>
    from headline.items import Artical
  File "F:\Projects\项目代码\爬虫程序\headline\headline\items.py", line 20, in <module>
    model = Doc2Vec.load('D:/pyspace/headline/headline/utils/model3/doc2vec.model')
  File "C:\Python310\lib\site-packages\gensim\models\doc2vec.py", line 813, in load
    raise ae
  File "C:\Python310\lib\site-packages\gensim\models\doc2vec.py", line 807, in load
    return super(Doc2Vec, cls).load(*args, rethrow=True, **kwargs)
  File "C:\Python310\lib\site-packages\gensim\models\word2vec.py", line 1937, in load
    raise ae
  File "C:\Python310\lib\site-packages\gensim\models\word2vec.py", line 1930, in load
    model = super(Word2Vec, cls).load(*args, **kwargs)
  File "C:\Python310\lib\site-packages\gensim\utils.py", line 486, in load
    obj._load_specials(fname, mmap, compress, subname)
  File "C:\Python310\lib\site-packages\gensim\models\word2vec.py", line 1946, in _load_specials
    super(Word2Vec, self)._load_specials(*args, **kwargs)
  File "C:\Python310\lib\site-packages\gensim\utils.py", line 517, in _load_specials
    getattr(self, attrib)._load_specials(cfname, mmap, compress, subname)
  File "C:\Python310\lib\site-packages\gensim\utils.py", line 1521, in new_func1
    return func(*args, **kwargs)
  File "C:\Python310\lib\site-packages\gensim\models\doc2vec.py", line 326, in docvecs
    return self.dv
AttributeError: 'Doc2Vec' object has no attribute 'dv'

“D:/pyspace/headline/headline/utils/model3/doc2vec.model”是一个已经训练过的模型。

gensim版本是4.1.2

Django版本是4.0.3

我不知道该怎么做才能解决这个问题。感谢您的帮助

python nlp gensim doc2vec
2个回答
0
投票

可能是你的版本问题,或者你可以尝试更正你的代码“model.doc2vec”


0
投票

似乎属性“dv”在 gensim 版本 4.0.0+ 中已被弃用。所以解决方案非常简单:只需将 gensim 降级到 3.8.3,一切就可以了。

pip install gensim\<4.0.0
© www.soinside.com 2019 - 2024. All rights reserved.