0

Thanks for advice, I have edited the question

I meet this: AttributeError: 'Doc2Vec' object has no attribute 'dv'

The error comes from

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'

the 'D:/pyspace/headline/headline/utils/model3/doc2vec.model' is an model that has ever been trained.

gensim version is 4.1.2

Django version is 4.0.3

I don't know what should I do to solve this problem. Thanks for help

foling
  • 1
  • 2
  • You should edit your question to include the full error message you're seeing, including lines of traceback showing involved files/code/line-numbers, to help answerers see exactly what's triggering the error. Also, you should generally try to use the latest Gesnim version (4.1.2 as of April 2022) unless you're sure you need to use an older one for a specific reason. Where did this `doc2vec.model` file come from? – gojomo Apr 04 '22 at 03:50
  • always put full error message (starting at word "Traceback") in question (not in comments) as text (not screenshot, not link to external portal). There are other useful information. – furas Apr 04 '22 at 03:58
  • where did you get `doc2vec.model` ? maybe it can't be used with `Doc2Vec` – furas Apr 04 '22 at 03:59

1 Answers1

0

It may be the problem of your version, or you can try to correct your code "model.doc2vec"

Whitney
  • 1
  • 1
  • I tried to reduce the version, but the error keeps the same. I use "Doc2Vec.load( )" to load a model, so where should I correct the code? thanks for your help! – foling Apr 12 '22 at 10:47