【问题标题】:ImportError: cannot import name 'deprecated' from 'gensim.utilsImportError:无法从“gensim.utils”导入名称“已弃用”
【发布时间】:2021-08-20 14:08:51
【问题描述】:

在导入以下行时,Jupyter 编译器会导致错误。

ImportError: cannot import name 'deprecated' from 'gensim.utils
from gensim.summarization.summarizer import summarize
from gensim.summarization import keywords**

错误如下:

~\AppData\Local\Programs\Python\Python39\Lib\site-packages\gensim\summarization\summarizer.py in <module>
     54 
     55 import logging
---> 56 from gensim.utils import deprecated
     57 from gensim.summarization.pagerank_weighted import pagerank_weighted as _pagerank
     58 from gensim.summarization.textcleaner import clean_text_by_sentences as _clean_text_by_sentences

ImportError: cannot import name 'deprecated' from 'gensim.utils' (C:\Users\PavanKumar\AppData\Local\Programs\Python\Python39\Lib\site-packages\gensim\utils.py)

【问题讨论】:

  • line from gensim.utils import deprecated 可与 Python 3.8 一起使用,但 gensim 可能无法与 Python 3.9 一起使用,因此最好使用可能包含所有模块的较旧的 Python。最新版本有时可能需要等待专门为最新 Python 创建的模块。或者检查是否有更新版本的gensim 可能已经与Python 3.9 一起使用
  • gensims page 上你可以看到tested with versions 3.6, 3.7 and 3.8. 所以它没有用3.9 测试,它可能不适用于这个版本。而你使用3.9
  • line from gensim.utils import deprecated 适用于我的 Python 3.9gensims 4.0.1
  • 但他们从4.0.1 中删除了gensim.summarization,所以最好保留版本3.8.3

标签: python scipy deprecated gensim summarize


【解决方案1】:

summarization 代码已从 Gensim 4.0 中删除。见:

https://github.com/RaRe-Technologies/gensim/wiki/Migrating-from-Gensim-3.x-to-4#12-removed-gensimsummarization

12.删除gensim.summarization

尽管它的名字听起来很笼统,但该模块不能满足 生产中的大多数用例,可能会浪费人们的 时间。见this Github ticket 这背后有更多的动力。

如果需要,可以试试:

  • 安装较旧的 gensim 版本;或者……
  • 将源代码复制到您自己的本地模块中

但是,我预计您可能会对它的不灵活以及它无能为力感到失望。它只是抽取式摘要 - 从已经存在的句子中选择一些关键句子 - 只有当源文本已经以说明性风格编写良好时,将高级摘要与细节混合在一起,才会产生令人印象深刻的结果。而且它的单词分析/排序方法非常粗糙且难以定制。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2022-01-22
    • 2021-06-30
    • 2020-10-19
    • 2018-08-13
    • 2015-01-26
    • 2020-10-10
    • 2020-02-12
    • 2021-11-27
    相关资源
    最近更新 更多