AttributeError:无法在<module'__main __'>上获取属性'tokenizer'

问题描述

我针对文本数据训练了一个logistic regression模型,并使用pickle保存了该模型。但是对于测试,当我尝试加载模型时,执行以下行时出现标题中提到的错误

model = pickle.load(open("sentiment.model","rb"))

以下是用于保存模型代码

import pickle

print("[INFO] saving Model...")
f = open('sentiment.model',"wb")

# first I saved the best_estimator_
f.write(pickle.dumps(gs_lr_tfidf.best_estimator_))

# but again I saved the model completely without mentioning any attribute i.e: 
# f.write(pickle.dumps(gs_lr_tfidf))
# but none of them helped and I got the same error

f.close()
print("[INFO] Model saved!")

当我在完成训练过程之后(在相同的运行时)将模型加载到同一笔记本中时,不会出现此错误。但是,即使模型加载器代码相同,当我尝试在不同的运行时分别加载模型时,也会发生此错误。为什么会这样?

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)