Package jazzparser :: Package taggers :: Package ngram :: Module tagger :: Class NgramTaggerModel
[hide private]
[frames] | no frames]

Class NgramTaggerModel

source code

        object --+    
                 |    
models.TaggerModel --+
                     |
                    NgramTaggerModel

hash(x)

Instance Methods [hide private]
 
__init__(self, model_name, model=None, chordmap=None, *args, **kwargs)
An n-gram model to be used as a tagging model.
source code
 
train(self, sequences, grammar=None, logger=None)
Trains the loaded model using the data in the list of sequences.
source code
 
_get_model_data(self)
Subclasses should implement this method to return the raw data of the model in a form that can be pickled and written out to a file.
source code
 
generate_chord_sequence(self, length=20)
Just for a laugh, use the trained n-gram to generate a chord sequence and output it in a playable form.
source code
 
forward_probabilities(self, sequence)
Interface to the NgramModel's forward_probabilities
source code
 
forward_backward_probabilities(self, sequence) source code
 
viterbi_probabilities(self, sequence) source code
 
_get_tags(self) source code
 
_get_readable_params(self) source code

Inherited from models.TaggerModel: delete, get_extra_filenames, process_training_options, save

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

Class Methods [hide private]

Inherited from models.TaggerModel: list_models, load_model

Inherited from models.TaggerModel (private): _get_model_dir

Static Methods [hide private]
 
_load_model(data)
Subclasses should implement this method to load up the model data given in the argument data.
source code
Class Variables [hide private]
  MODEL_TYPE = 'ngram'
hash(x)
  TRAINING_OPTIONS = [ModuleOption('n', filter= int, help_text= ...
Properties [hide private]
  tags
  readable_parameters

Inherited from models.TaggerModel: description, options

Inherited from models.TaggerModel (private): _filename

Inherited from object: __class__

Method Details [hide private]

__init__(self, model_name, model=None, chordmap=None, *args, **kwargs)
(Constructor)

source code 

An n-gram model to be used as a tagging model. Uses NLTK to represent, train and evaluate the n-gram model.

Overrides: object.__init__

train(self, sequences, grammar=None, logger=None)

source code 

Trains the loaded model using the data in the list of sequences.

Overrides: models.TaggerModel.train
(inherited documentation)

_load_model(data)
Static Method

source code 

Subclasses should implement this method to load up the model data given in the argument data. They should return an instance of themselves. The data will be in the form of a dictionary, as returned by the class' _get_model_data().

A default implementation that just uses simple pickling is provided. It assumes that the class can be instantiated using no arguments.

Overrides: models.TaggerModel._load_model
(inherited documentation)

_get_model_data(self)

source code 

Subclasses should implement this method to return the raw data of the model in a form that can be pickled and written out to a file.

A default implementation to complement the implementation of _load_model is provided.

*** IMPORTANT: *** Some implementations perform part of the model storage in their _get_model_data method, so you shouldn't use this just to get the data if you don't plan to store it. (Not sure why you'd want the raw data anyway and this is a private method - just warning you!)

Overrides: models.TaggerModel._get_model_data
(inherited documentation)

generate_chord_sequence(self, length=20)

source code 

Just for a laugh, use the trained n-gram to generate a chord sequence and output it in a playable form. Returns a tuple: (chords, tags)

To Do: this isn't implemented yet for n-grams. It's not a high priority, but would be fun.


Class Variable Details [hide private]

TRAINING_OPTIONS

Value:
[ModuleOption('n', filter= int, help_text= "Length of the n-grams whic\
h this model will use.", usage= "n=N, where N is an integer. Defaults \
to bigrams", default= 2), ModuleOption('backoff', filter= int, help_te\
xt= "Number of orders of backoff to use. This must be " "less than n. \
E.g. if using a trigram model (n=3) you can " "set backoff=2 to back o\
ff to bigrams and from bigrams " "to unigrams. Set to 0 to use no back\
off at all (default).", usage= "backoff=X, where X is an integer < n",\
 default= 0), ModuleOption('cutoff', filter= int, help_text= "In estim\
...

Property Details [hide private]

tags

Get Method:
_get_tags(self)

readable_parameters

Get Method:
_get_readable_params(self)