Package jazzparser :: Package utils :: Package nltk :: Package ngram :: Module dictionary :: Class DictionaryHmmModel
[hide private]
[frames] | no frames]

Class DictionaryHmmModel

source code

      object --+    
               |    
model.NgramModel --+
                   |
                  DictionaryHmmModel
Known Subclasses:

Like an NgramModel, but (a) restricted to be an HMM (order 2 and no backoff) and (b) uses dictionary distributions, rather than distributions generated from counts.

Using dictionary distributions allows the parameters to be retrained, e.g. with Baum-Welch EM, but means we can't use the kind of backoff model NgramModel implements, since this is dependent on having counts for the training data available.

The distributions given at initialization don't have to be dictionary distributions, but will be converted to such.

Instance Methods [hide private]
 
__init__(self, label_dist, emission_dist, label_dom, emission_dom, mutable=False)
x.__init__(...) initializes x; see help(type(x)) for signature
source code
 
to_picklable_dict(self)
Produces a picklable representation of model as a dict.
source code
 
compute_gamma(self, *args, **kwargs)
This is now implemented much better than it used to be by the superclass.
source code
 
compute_xi(self, sequence, forward=None, backward=None, emission_matrix=None, transition_matrix=None, use_logs=False)
Computes the xi matrix used by Baum-Welch.
source code
 
viterbi_decode(self, sequence)
More efficient Viterbi decoding than superclass.
source code

Inherited from model.NgramModel: __repr__, backward_log_probabilities, backward_probabilities, clear_cache, decode_forward, decode_gamma, emission_log_probability, emission_probability, forward_backward_log_probabilities, forward_backward_probabilities, forward_log_probabilities, forward_probabilities, gamma_probabilities, generalized_viterbi, generate, get_all_ngrams, get_backoff_models, get_emission_matrix, get_transition_matrix, labeled_sequence_log_probability, normal_backward_probabilities, normal_forward_backward_probabilities, normal_forward_probabilities, precompute, transition_log_probability, transition_log_probability_debug, transition_probability, transition_probability_debug, viterbi_selector_probabilities

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

Static Methods [hide private]
 
from_ngram_model(model, mutable=False)
Creates a DictionaryHmmModel from an NgramModel.
source code
 
from_picklable_dict(data)
Reproduces an n-gram model that was converted to a picklable form using to_picklable_dict.
source code

Inherited from model.NgramModel: train

Properties [hide private]

Inherited from model.NgramModel: model_type

Inherited from object: __class__

Method Details [hide private]

__init__(self, label_dist, emission_dist, label_dom, emission_dom, mutable=False)
(Constructor)

source code 

x.__init__(...) initializes x; see help(type(x)) for signature

Parameters:
  • label_dist (nltk prob dist) - transition distribution
  • emission_dist (nltk prob dist) - emission distribution
  • label_dom (list) - state domain
  • emission_dom (list) - emission domain
  • mutable (bool) - if true, the distributions stored will be mutable dictionary distributions, so the model can be updated
Overrides: object.__init__

from_ngram_model(model, mutable=False)
Static Method

source code 

Creates a DictionaryHmmModel from an NgramModel. Note that the ngram model must of the correct sort: order 2 with no backoff.

to_picklable_dict(self)

source code 

Produces a picklable representation of model as a dict.

Overrides: model.NgramModel.to_picklable_dict

from_picklable_dict(data)
Static Method

source code 

Reproduces an n-gram model that was converted to a picklable form using to_picklable_dict.

Overrides: model.NgramModel.from_picklable_dict

compute_gamma(self, *args, **kwargs)

source code 

This is now implemented much better than it used to be by the superclass. Use jazzparser.utils.nltk.ngram.NgramModel.gamma_probabilities. This method is now just a wrapper to that.

compute_xi(self, sequence, forward=None, backward=None, emission_matrix=None, transition_matrix=None, use_logs=False)

source code 

Computes the xi matrix used by Baum-Welch. It is the matrix of joint probabilities of occupation of pairs of consecutive states: P(i_t, j_{t+1} | O).

As with compute_gamma forward and backward matrices can optionally be passed in to avoid recomputing.

Parameters:
  • use_logs (bool) - by default, this function does not use logs in its calculations. This can lead to underflow if your forward/backward matrices have sufficiently low values. If use_logs=True, logs will be used internally (though the returned values are exponentiated again). This makes the function an order of magnitude slower.

viterbi_decode(self, sequence)

source code 

More efficient Viterbi decoding than superclass.

Overrides: model.NgramModel.viterbi_decode