rasa.shared.nlu.training_data.features
Features Objects
Stores the features produced by any featurizer.
__init__
Initializes the Features object.
Arguments:
features
- The features.feature_type
- Type of the feature, e.g. FEATURE_TYPE_SENTENCE.attribute
- Message attribute, e.g. INTENT or TEXT.origin
- Name of the component that created the features.
is_sparse
Checks if features are sparse or not.
Returns:
True, if features are sparse, false otherwise.
is_dense
Checks if features are dense or not.
Returns:
True, if features are dense, false otherwise.
combine_with_features
Combine the incoming features with this instance's features.
Arguments:
additional_features
- additional features to add
Returns:
Combined features.
__key__
Returns a 4-tuple of defining properties.
Returns:
Tuple of type, attribute, features, and origin properties.
__eq__
Tests if the self
Feature
equals to the other
.
Arguments:
other
- The other object.
Returns:
True
when the other object is a Feature
and has the same
type, attribute, and feature tensors.
fingerprint
Calculate a stable string fingerprint for the features.
filter
Filters the given list of features.
Arguments:
features_list
- list of features to be filteredattributes
- List of attributes that we're interested in. Set this toNone
to disable this filter.type
- The type of feature we're interested in. Set this toNone
to disable this filter.origin
- If specified, this method will check that the exact order of origins matches the given list of origins. The reason for this is that if multiple origins are listed for a Feature, this means that this feature has been created by concatenating Features from the listed origins in that particular order.is_sparse
- Defines whether all features that we're interested in should be sparse. Set this toNone
to disable this filter.
Returns:
sub-list of features with the desired properties
groupby_attribute
Groups the given features according to their attribute.
Arguments:
features_list
- list of features to be groupedattributes
- If specified, the result will be a grouping with respect to the given attributes. If some specified attribute has no features attached to it, then the resulting dictionary will map it to an empty list. If this is None, the result will be a grouping according to all attributes for which features can be found.
Returns:
a mapping from the requested attributes to the list of correspoding features
combine
Combine features of the same type and level that describe the same attribute.
If sequence features are to be combined, then they must have the same sequence dimension.
Arguments:
features
- Non-empty list of Features of the same type and level that describe the same attribute.expected_origins
- The expected origins of the given features. This method will check that the origin information of each feature is as expected, i.e. the origin of the i-th feature in the given list is the i-th origin in this list of origins.
Raises:
ValueError
will be raised
- if the given list is empty
- if there are inconsistencies in the given list of
Features
- if the origins aren't as expected
reduce
Combines features of same type and level into one Feature.
Arguments:
features_list
- list of Features which must all describe the same attributeexpected_origins
- if specified, this list will be used to validate that the features from the right featurizers are combined in the right order (cf.Features.combine
)
Returns:
a list of the combined Features, i.e. at most 4 Features, where
- all the sparse features are listed before the dense features
- sequence feature is always listed before the sentence feature with the same sparseness property