如何解决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 举报,一经查实,本站将立刻删除。