Google colab:找不到名为pytextrank的模块(以前使用过同一个笔记本)



从最近开始,每当我运行笔记本时,我都会收到此错误:

ModuleNotFoundError: No module named 'pytextrank'

这是我笔记本的链接:https://colab.research.google.com/github/neomatrix369/awesome-ai-ml-dl/blob/master/examples/better-nlp/notebooks/jupyter/better_nlp_summarisers.ipynb#scrollTo=-dJrJ54a3w8S

尽管检查显示已安装该库,但 python 导入失败 - 我曾在不同的情况下遇到过一次,并使用以下方法修复了它:

python -m pip install pytextrank

但这没有任何影响,错误仍然存在。

这在过去不是问题,同一个笔记本运行良好 - 我认为这可能是一种回归。

有什么想法吗?任何有用的反馈将不胜感激。

这是我调用的代码:

import pytextrank
import sys
import networkx as nx
import pylab as plt

我在colab单元格中得到了这个:

[nltk_data] Downloading package stopwords to /root/nltk_data...
[nltk_data]   Unzipping corpora/stopwords.zip.
---------------------------------------------------------------------------
ModuleNotFoundError                       Traceback (most recent call last)
<ipython-input-3-7f30423e40f2> in <module>()
      3 sys.path.insert(0, './awesome-ai-ml-dl/examples/better-nlp/library')
      4 
----> 5 from org.neomatrix369.better_nlp import BetterNLP
1 frames
/content/awesome-ai-ml-dl/examples/better-nlp/library/org/neomatrix369/summariser_pytextrank.py in <module>()
----> 1 import pytextrank
      2 import sys
      3 import networkx as nx
      4 import pylab as plt
      5 
ModuleNotFoundError: No module named 'pytextrank'
---------------------------------------------------------------------------
NOTE: If your import is failing due to a missing package, you can
manually install dependencies using either !pip or !apt.
To view examples of installing some common dependencies, click the
"Open Examples" button below.

您可以运行一个单元以使用 pip 在 Colab 中显式安装pytextrank

!pip install pytextrank

之后,假设已创建或上传mih.json数据文件,以下代码将在 Colab 中运行:

import pytextrank
path_stage0 = "mih.json"
path_stage1 = "o1.json"
with open(path_stage1, 'w') as f:
    for graf in pytextrank.parse_doc(pytextrank.json_iter(path_stage0)):
        f.write("%sn" % pytextrank.pretty_print(graf._asdict()))
graph, ranks = pytextrank.text_rank(path_stage1)
for rl in pytextrank.normalize_key_phrases(path_stage1, ranks):
    print(pytextrank.pretty_print(rl))

生成此输出:

["systems", 0.11805817287949238, [2], "np", 1]
["mixed types", 0.09727027009440953, [31, 24], "np", 1]
["minimal set", 0.0656181165649375, [19, 5], "np", 1]
["considered", 0.05314007683878527, [15], "vbn", 2]
["strict inequations", 0.05291409382374228, [11, 12], "np", 1]
["natural numbers", 0.0502966356772243, [6, 7], "np", 1]
["types", 0.048635135047204764, [24], "nns", 3]
["be", 0.04857443543935028, [14], "vb", 3]
["set", 0.03280905828246875, [5], "nn", 4]
["minimal generating sets", 0.03280905828246875, [19, 23, 5], "np", 1]
["solving", 0.03256884170337274, [30], "vbg", 1]
["solutions", 0.030576007873278972, [20], "nns", 3]
["linear constraints", 0.0271278909527188, [3, 4], "np", 1]
["linear diophantine equations", 0.0271278909527188, [3, 9, 10], "np", 1]
["inequations", 0.02645704691187114, [12], "nns", 2]
["nonstrict inequations", 0.02645704691187114, [13, 12], "np", 1]
["numbers", 0.02514831783861215, [7], "nns", 1]
["used", 0.021117092168160108, [29], "vbn", 1]
["given", 0.020891260341666464, [25], "vbn", 1]
["supporting", 0.014650048747874869, [28], "vbg", 1]
["constraints", 0.0135639454763594, [4], "nns", 1]
["diophantine", 0.0135639454763594, [9], "nnp", 1]
["generating", 0.013543878573169788, [23], "nn", 1]
["algorithms", 0.013397910676526051, [21], "nns", 2]
["equations", 0.013056662983606804, [10], "nns", 1]
["constructing", 0.012594570053681782, [27], "vbg", 1]
["upper bounds", 0.012248038294705636, [16, 17], "np", 1]
["nonstrict", 0.011793629610984586, [13], "nn", 1]
["components", 0.0113294598001366, [18], "nns", 1]
["construction", 0.009991849727289892, [22], "nn", 1]
["compatibility", 0.006124019147352818, [1], "nn", 2]
["bounds", 0.006124019147352818, [17], "nns", 1]
["corresponding", 0.006124019147352818, [26], "vbg", 1]
["criteria", 0.004297554552892375, [8], "nns", 2]

最新更新