I am training a Brill's POS tagger using the py-crfsuite
as provided in NLTK. However when I try to save a trained model, I get the following error:
crf_tagger = CRFTagger()
crf_tagger.train(train_sents, 'model_trained.crf.tagger')
templates = nltk.tag.brill.nltkdemo18()
trainer = nltk.tag.brill_trainer.BrillTaggerTrainer(crf_tagger, templates)
bt = trainer.train(train_sents, max_rules=10)
file_writing = file('trained_brill_tagger.yaml', 'w')
yaml.dump(bt, file_writing)
#even pickle fails
file_w = open('trained_brills.pickle', 'wb')
pickle.dump(bt, file_w)
file_w.close()
File "stringsource", line 2, in pycrfsuite._pycrfsuite.Tagger.reduce_cython TypeError: self.c_tagger cannot be converted to a Python object for pickling
I have tried using pickle
, dill
and also yaml
however the error seems to persist. Is there any solution to this. Is this because of using CRF tagger as baseline? Thank you.
Here's an example of how you can train a
nltk.tag.brill_trainer.BrillTaggerTrainer
in NLTK v3.2.5Then to save the trainer, simply
pickle
: