Package jazzparser :: Package utils :: Package nltk :: Module hmm :: Class PicklableHmmTrainer
[hide private]
[frames] | no frames]

Class PicklableHmmTrainer

source code

                           object --+    
                                    |    
nltk.tag.hmm.HiddenMarkovModelTrainer --+
                                        |
                                       PicklableHmmTrainer

We override HiddenMarkovModelTrainer to overcome the fact that it produces HMMs that can't be pickled. We only make supervised trained HMMs picklable at the moment.

This is quite a nasty hack to overcome the fact that NLTK HMMs can't be stored and also can't be pickled if constructed using the default trainer. However, this is not very stable, since someone could, for example, set some attribute of the model to be a Python lambda and pickling would once again fail.

Instance Methods [hide private]
HiddenMarkovModelTagger
train_supervised(self, *args, **kwargs)
If you set 'estimator' in the kwargs, make sure it's a top-level named function, not a lambda, or else you won't be able to pickle your HMM.
source code

Inherited from nltk.tag.hmm.HiddenMarkovModelTrainer: __init__, train, train_unsupervised

Inherited from object: __delattr__, __format__, __getattribute__, __hash__, __new__, __reduce__, __reduce_ex__, __repr__, __setattr__, __sizeof__, __str__, __subclasshook__

Properties [hide private]

Inherited from object: __class__

Method Details [hide private]

train_supervised(self, *args, **kwargs)

source code 

If you set 'estimator' in the kwargs, make sure it's a top-level named function, not a lambda, or else you won't be able to pickle your HMM.

Parameters:
  • labelled_sequences - the training data, a set of labelled sequences of observations
  • kwargs - may include an 'estimator' parameter, a function taking a FreqDist and a number of bins and returning a ProbDistI; otherwise a MLE estimate is used
Returns: HiddenMarkovModelTagger
the trained model
Overrides: nltk.tag.hmm.HiddenMarkovModelTrainer.train_supervised