class FunctionBackedMaxentFeatureEncoding(MaxentFeatureEncodingI): (source)
Constructor: FunctionBackedMaxentFeatureEncoding(func, length, labels)
A feature encoding that calls a user-supplied function to map a given featureset/label pair to a sparse joint-feature vector.
Method | __init__ |
Construct a new feature encoding based on the given function. |
Method | describe |
:return: A string describing the value of the joint-feature whose index in the generated feature vectors is ``fid``. :rtype: str |
Method | encode |
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. |
Method | labels |
:return: 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``. :rtype: list |
Method | length |
:return: The size of the fixed-length joint-feature vectors that are generated by this encoding. :rtype: int |
Instance Variable | _func |
Undocumented |
Instance Variable | _labels |
Undocumented |
Instance Variable | _length |
Undocumented |
Inherited from MaxentFeatureEncodingI
:
Method | train |
Construct and return new feature encoding, based on a given training corpus ``train_toks``. |
Construct a new feature encoding based on the given function. :type func: (callable) :param func: 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. :type length: int :param length: The size of the fixed-length joint-feature vectors that are generated by this encoding. :type labels: list :param labels: 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``.
:return: A string describing the value of the joint-feature whose index in the generated feature vectors is ``fid``. :rtype: str
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.
:type featureset: dict :rtype: list(tuple(int, int))
:return: 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``. :rtype: list