Package jazzparser :: Package utils :: Package nltk :: Package ngram :: Module model :: Class PrecomputedNgramModel
[hide private]
[frames] | no frames]

Class PrecomputedNgramModel

source code

object --+    
         |    
NgramModel --+
             |
            PrecomputedNgramModel

Overrides parts of NgramModel to provide exactly the same interface, but stores the precomputed transition matrix and uses this to provide transition probabilities. This makes using the model a lot faster if you're doing things like forward-backward computations, since it needs the full transition matrix anyway. This processing is effectively pushed to training time instead of testing time.

Instance Methods [hide private]
 
__init__(self, *args, **kwargs)
x.__init__(...) initializes x; see help(type(x)) for signature
source code
 
transition_probability(self, *ngram)
Like the superclass, but read off from the precomputed matrix.
source code
 
transition_log_probability(self, *ngram)
Like the superclass, but read off from the precomputed matrix.
source code
 
get_transition_matrix(self, transpose=False)
Returns the precomputed transition matrix.
source code
 
to_picklable_dict(self)
Produces a picklable representation of model as a dict.
source code

Inherited from 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, labeled_sequence_log_probability, normal_backward_probabilities, normal_forward_backward_probabilities, normal_forward_probabilities, precompute, transition_log_probability_debug, transition_probability_debug, viterbi_decode, viterbi_selector_probabilities

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

Static Methods [hide private]
 
train(*args, **kwargs)
Just calls NgramModel's train method and converts the result to a PrecomputedNgramModel.
source code
 
from_picklable_dict(data)
Reproduces an n-gram model that was converted to a picklable form using to_picklable_dict.
source code
Properties [hide private]

Inherited from NgramModel: model_type

Inherited from object: __class__

Method Details [hide private]

__init__(self, *args, **kwargs)
(Constructor)

source code 

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

Overrides: object.__init__
(inherited documentation)

train(*args, **kwargs)
Static Method

source code 

Just calls NgramModel's train method and converts the result to a PrecomputedNgramModel.

Overrides: NgramModel.train

transition_probability(self, *ngram)

source code 

Like the superclass, but read off from the precomputed matrix.

Overrides: NgramModel.transition_probability

See Also: NgramModel.transition_log_probability

transition_log_probability(self, *ngram)

source code 

Like the superclass, but read off from the precomputed matrix.

Overrides: NgramModel.transition_log_probability

See Also: NgramModel.transition_log_probability

get_transition_matrix(self, transpose=False)

source code 

Returns the precomputed transition matrix.

Overrides: NgramModel.get_transition_matrix

See Also: NgramModel.get_transition_matrix

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: NgramModel.to_picklable_dict
(inherited documentation)

from_picklable_dict(data)
Static 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: NgramModel.from_picklable_dict
(inherited documentation)