FoolNLTK icon indicating copy to clipboard operation
FoolNLTK copied to clipboard

使用foolNLTK时出现错误“ModuleNotFoundError: No module named 'tensorflow.contrib'”

Open newmrxu opened this issue 4 years ago • 2 comments

我的环境:anaconda 3.7 tensorflow: 2.2.0

程序:

import fool

text = "林语堂是中国最好的英文作家。"
print(fool.cut(text))

newmrxu avatar May 19 '20 02:05 newmrxu

tensorflow2.0及以上版本没有这个模块了。https://github.com/tensorflow/tensorflow/issues/30794

Sanchez2020 avatar May 29 '20 09:05 Sanchez2020

tensorflow2.0及以上版本一些API发生了变化,卸载安装1.X的版本就可以使用。如果不想卸载tensorflow2.0,可以做以下修改,亲测可用,本人修改后运行fool.cut(text)和fool.analysis(text)都没问题:

1.安装tensorflow_addons: pip install tensorflow-addons 2.找到Anaconda3下的Lib/site-packages/fool 3.修改model.py文件中的代码: 第8行改为from tensorflow_addons.text import viterbi_decode 4.修改predictor.py文件中的代码: 第8行改为from tensorflow_addons.text import viterbi_decode 第32行改为with tf.io.gfile.GFile(path, "rb") as f: 第33行改为graph_def = tf.compat.v1.GraphDef() 第53行改为self.sess = tf.compat.v1.Session(graph=self.graph)

qh-deng avatar Sep 26 '20 13:09 qh-deng