Package jazzparser :: Package backoff :: Package ngram :: Module hmmpath :: Class HmmPathNgram
[hide private]
[frames] | no frames]

Class HmmPathNgram

source code

                       object --+    
                                |    
utils.nltk.ngram.model.NgramModel --+
                                    |
                                   HmmPathNgram

An ngram model that takes multiple chords (weighted by probability) as input to its decoding. It is trained on labeled data.

This is similar to jazzparser.taggers.ngram_multi.model.MultiChordNgramModel, but the states represent points on a TS path, rather than categories.

Instance Methods [hide private]
 
__init__(self, order, point_transition_counts, fn_transition_counts, type_emission_counts, subst_emission_counts, estimator, backoff_model, chord_map, vector_dom, point_dom, history='')
x.__init__(...) initializes x; see help(type(x)) for signature
source code
 
add_history(self, string)
Adds a line to the end of this model's history string.
source code
 
transition_log_probability(self, *states)
Gives the probability P(label_i | label_(i-1), ..., label_(i-n)), where the previous labels are given in the sequence label_context.
source code
 
emission_log_probability(self, emission, state)
Gives the probability P(emission | label).
source code
 
to_picklable_dict(self)
Produces a picklable representation of model as a dict.
source code

Inherited from utils.nltk.ngram.model.NgramModel: __repr__, backward_log_probabilities, backward_probabilities, clear_cache, decode_forward, decode_gamma, 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_debug, transition_probability, transition_probability_debug, viterbi_decode, viterbi_selector_probabilities

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

Class Methods [hide private]
 
from_picklable_dict(cls, data)
Reproduces an n-gram model that was converted to a picklable form using to_picklable_dict.
source code
Static Methods [hide private]
 
train(data, estimator, grammar, cutoff=0, logger=None, chord_map=None, order=2, backoff_orders=0, backoff_kwargs={})
Initializes and trains an HMM in a supervised fashion using the given training data.
source code
Properties [hide private]

Inherited from utils.nltk.ngram.model.NgramModel: model_type

Inherited from object: __class__

Method Details [hide private]

__init__(self, order, point_transition_counts, fn_transition_counts, type_emission_counts, subst_emission_counts, estimator, backoff_model, chord_map, vector_dom, point_dom, history='')
(Constructor)

source code 

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

Overrides: object.__init__
(inherited documentation)

train(data, estimator, grammar, cutoff=0, logger=None, chord_map=None, order=2, backoff_orders=0, backoff_kwargs={})
Static Method

source code 

Initializes and trains an HMM in a supervised fashion using the given training data. Training data should be chord sequence data (input type bulk-db or bulk-db-annotated).

Overrides: utils.nltk.ngram.model.NgramModel.train

transition_log_probability(self, *states)

source code 

Gives the probability P(label_i | label_(i-1), ..., label_(i-n)), where the previous labels are given in the sequence label_context. The context should be in reverse order, i.e. with the most recent label at the start.

Note that this is the probability of a label given the previous n-1 labels, which is the same as the probability of the n-gram [label_i, ..., label_(i-n+1)] given the ngram [label_(i-1), ..., label_(i-n)], since all but the last element of the ngram overlaps with the condition, so has probability 1.

Caches all computed transition probabilities. This is particularly important for backoff models. Many n-grams will back off to the same (n-1)-gram and we don't want to recompute the transition probability for that each time.

Overrides: utils.nltk.ngram.model.NgramModel.transition_log_probability
(inherited documentation)

emission_log_probability(self, emission, state)

source code 

Gives the probability P(emission | label). Returned as a base 2 log.

The emission should be a pair of (root,label), together defining a chord.

There's a special case of this. If the emission is a list, it's assumed to be a distribution over emissions. The list should contain (prob,em) pairs, where em is an emission, such as is normally passed into this function, and prob is the weight to give to this possible emission. The probabilities of the possible emissions are summed up, weighted by the prob values.

Overrides: utils.nltk.ngram.model.NgramModel.emission_log_probability

to_picklable_dict(self)

source code 

Produces a picklable representation of model as a dict. You can't just pickle the object directly because some of the NLTK classes can't be pickled. You can pickle this dict and reconstruct the model using NgramModel.from_picklable_dict(dict).

Overrides: utils.nltk.ngram.model.NgramModel.to_picklable_dict
(inherited documentation)

from_picklable_dict(cls, data)
Class Method

source code 

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

Extra args/kwargs are passed to the class constructor.

Overrides: utils.nltk.ngram.model.NgramModel.from_picklable_dict
(inherited documentation)