Pickling a trained NLTK Model

跟風遠走 提交于 2019-12-07 07:56:30

问题


So I am currently training a Hidden Markov Model on a set of surgical data like so:

nltkTrainer = nltk.tag.hmm.HiddenMarkovModelTrainer(range(15),range(90))
model = nltkTrainer.train_unsupervised(data, max_iterations=3)

If it's helpful, 'model' is given as 'HiddenMarkovModelTagger 15 states and 90 output symbols'

However, it takes nearly an hour to run this full training on my machine. I want to be able to serialize the nltk model output 'model' to load and save between sessions. I've read around and everybody seems to use Python's built in pickle, which works all fine and dandy for known data types. I can even pickle my trained model variable using this code:

f = open('my_classifier.pickle', 'wb')
pickle.dump(model, f)
f.close()

But when trying to load the pickled file, I get the error:

/usr/local/lib/python2.7/dist-packages/nltk/probability.pyc in __init__(self, probdist_dict)
   1971         """
   1972         defaultdict.__init__(self, DictionaryProbDist)
-> 1973         self.update(probdist_dict)
   1974 
   1975 ##//////////////////////////////////////////////////////

TypeError: 'type' object is not iterable

has anybody found a way around this? Is it an issue with NLTK?

来源:https://stackoverflow.com/questions/13020823/pickling-a-trained-nltk-model

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!