Package nltk :: Package classify :: Module maxent :: Class FunctionBackedMaxentFeatureEncoding
[hide private]
[frames] | no frames]

Class FunctionBackedMaxentFeatureEncoding

source code

            object --+    
                     |    
MaxentFeatureEncodingI --+
                         |
                        FunctionBackedMaxentFeatureEncoding

A feature encoding that calls a user-supplied function to map a given featureset/label pair to a sparse joint-feature vector.

Instance Methods [hide private]
 
__init__(self, func, length, labels)
Construct a new feature encoding based on the given function.
source code
list of (int, number)
encode(self, featureset, label)
Given a (featureset, label) pair, return the corresponding vector of joint-feature values.
source code
int
length(self)
Returns: The size of the fixed-length joint-feature vectors that are generated by this encoding.
source code
list
labels(self)
Returns: A list of the "known labels" -- i.e., all labels l such that self.encode(fs,l) can be a nonzero joint-feature vector for some value of fs.
source code
str
describe(self, fid)
Returns: A string describing the value of the joint-feature whose index in the generated feature vectors is fid.
source code

Inherited from MaxentFeatureEncodingI: train

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

Properties [hide private]

Inherited from object: __class__

Method Details [hide private]

__init__(self, func, length, labels)
(Constructor)

source code 

Construct a new feature encoding based on the given function.

Parameters:
  • func ((callable)) - A function that takes two arguments, a featureset and a label, and returns the sparse joint feature vector that encodes them:
    >>> func(featureset, label) -> feature_vector

    This sparse joint feature vector (feature_vector) is a list of (index,value) tuples.

  • length (int) - The size of the fixed-length joint-feature vectors that are generated by this encoding.
  • labels (list) - A list of the "known labels" for this encoding -- i.e., all labels l such that self.encode(fs,l) can be a nonzero joint-feature vector for some value of fs.
Overrides: object.__init__

encode(self, featureset, label)

source code 

Given a (featureset, label) pair, return the corresponding vector of joint-feature values. This vector is represented as a list of (index, value) tuples, specifying the value of each non-zero joint-feature.

Returns: list of (int, number)
Overrides: MaxentFeatureEncodingI.encode
(inherited documentation)

length(self)

source code 
Returns: int
The size of the fixed-length joint-feature vectors that are generated by this encoding.
Overrides: MaxentFeatureEncodingI.length
(inherited documentation)

labels(self)

source code 
Returns: list
A list of the "known labels" -- i.e., all labels l such that self.encode(fs,l) can be a nonzero joint-feature vector for some value of fs.
Overrides: MaxentFeatureEncodingI.labels
(inherited documentation)

describe(self, fid)

source code 
Returns: str
A string describing the value of the joint-feature whose index in the generated feature vectors is fid.
Overrides: MaxentFeatureEncodingI.describe
(inherited documentation)