Package jazzparser :: Package parsers :: Package pcfg :: Module model :: Class PcfgModel
[hide private]
[frames] | no frames]

Class PcfgModel

source code

object --+
         |
        PcfgModel
Known Subclasses:

A trainable model used by a pcfg parser.

Instance Methods [hide private]
 
__init__(self, model_name, overwrite=False, options={}, description=None, grammar=None)
Creates an empty, untrained model.
source code
 
__get_my_filename(self) source code
 
process_training_options(self)
Verifies and processes the training option values.
source code
 
_get_options(self)
Instead of processing training options when instantiating (which makes it impossible to have required options, since we're not always training when instantiating), we process the training options the first time they're needed.
source code
 
save(self)
Saves the model data to a file.
source code
 
delete(self)
Removes all the model's data.
source code
 
_generate_description(self)
Don't override this.
source code
 
__get_description(self) source code
 
generate(self, logger=None, max_depth=None)
Generate a surface form from the PCFG model.
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
 
inside_probability(*args, **kwargs)
Probability of a (non-leaf) subtree, computed from the probability of its expansions and the inner probabilities already associated with its components.
source code
 
outside_probability(*args, **kwargs)
Outside probability of a subtree.
source code

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

Class Methods [hide private]
 
__get_filename(cls, model_name) source code
 
_get_model_dir(cls) source code
 
list_models(cls)
Returns a list of the names of available models.
source code
 
load_model(cls, model_name) source code
 
_load_model(cls, name, data)
Subclasses should implement this method to load up the model data given in the argument data.
source code
Static Methods [hide private]
 
train(name, training_data, options, grammar=None, logger=None)
Trains a new model using the data in the list of sequences.
source code
Class Variables [hide private]
  MODEL_TYPE = None
hash(x)
  TRAINING_OPTIONS = []
  LEX_INPUT_TYPES = []
Properties [hide private]
  _filename
  options
Instead of processing training options when instantiating (which makes it impossible to have required options, since we're not always training when instantiating), we process the training options the first time they're needed.
  description

Inherited from object: __class__

Method Details [hide private]

__init__(self, model_name, overwrite=False, options={}, description=None, grammar=None)
(Constructor)

source code 

Creates an empty, untrained model. To load a previously stored model, use from_file().

Optionally stores some custom descriptive text. This will be included in the descriptive text that gets stored along with the model.

Overrides: object.__init__

process_training_options(self)

source code 

Verifies and processes the training option values. Access them in self.options.

_get_options(self)

source code 

Instead of processing training options when instantiating (which makes it impossible to have required options, since we're not always training when instantiating), we process the training options the first time they're needed.

If you want to do this ahead of time to verify the validity of the values, call process_training_options.

delete(self)

source code 

Removes all the model's data. It is assumed that the tagger will not be used at all after this has been called.

_generate_description(self)

source code 

Don't override this. You can add your own information into the descriptive text (per subclass, for example) by calling __init__ with the description kwarg, or by setting the model_description attribute. You might, for example, want to do this at training time.

generate(self, logger=None, max_depth=None)

source code 

Generate a surface form from the PCFG model. A pcfg model might not provide an implementation of this, in which case it will always return None.

_load_model(cls, name, data)
Class 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.

_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.

inside_probability(*args, **kwargs)

source code 

Probability of a (non-leaf) subtree, computed from the probability of its expansions and the inner probabilities already associated with its components. The result is the inside probability of the subtree.

There are several different cases. It may be a unary expansion, in which case expansion='unary' and right=None. It may be a right-head expansion: expansion='right' and both left and right daughters are given. Or it may be a left-head expansion: expansion='left' and both daughters are given.

Decorators:
  • @abstractmethod

outside_probability(*args, **kwargs)

source code 

Outside probability of a subtree. This is approximated in these models as the prior probability of the parent of the tree.

Decorators:
  • @abstractmethod

Property Details [hide private]

_filename

Get Method:
__get_my_filename(self)

options

Instead of processing training options when instantiating (which makes it impossible to have required options, since we're not always training when instantiating), we process the training options the first time they're needed.

If you want to do this ahead of time to verify the validity of the values, call process_training_options.

Get Method:
_get_options(self) - Instead of processing training options when instantiating (which makes it impossible to have required options, since we're not always training when instantiating), we process the training options the first time they're needed.

description

Get Method:
__get_description(self)