TextFeatureConcat¶
APIs¶
- class pyis.python.ops.TextFeatureConcat(self: ops.TextFeatureConcat, start_id: int) None ¶
Concatenate TextFeatures from different feature spaces(groups) into a single linear feature space.
Create a TextFeatureConcat object.
- Parameters
start_id (int) – The starting feature id in the target feature space. Usually, you should set it to 0. For libsvm/liblinear, 0 is illegal id. You should set it to 1.
- fit(self: ops.TextFeatureConcat, feature_groups: List[List[ops.TextFeature]]) None ¶
Collect new features from features from a series of feaure spaces(groups).
For example, the feature group 0 provides TextFeature 0 and TextFeature 1, the feature space 1 provides TextFeature 0 and TextFeature 1. In the contatenated feature space, 4 features will be created:
(group 0, TextFeature 0) mapped to TextFeature 0 (group 0, TextFeature 1) mapped to TextFeature 1 (group 1, TextFeature 0) mapped to TextFeature 2 (group 1, TextFeature 1) mapped to TextFeature 3
- Parameters
feature_groups (List[List[TextFeature]]) – The feaures from all feature spaces.
- transform(self: ops.TextFeatureConcat, feature_groups: List[List[ops.TextFeature]]) List[ops.TextFeature] ¶
Collect features that are already seen given features from all feature spaces.
- Parameters
feature_groups (List[List[TextFeature]]) – The feaures from all feature spaces.
Example¶
# Copyright (c) Microsoft Corporation. All rights reserved.
# Licensed under the MIT license.
from pyis.python import ops
featurizer = ops.TextFeatureConcat(1)
feature_group0 = [ops.TextFeature(0, 1.0, 0, 0), ops.TextFeature(1, 1.0, 0, 0)]
feature_group1 = [ops.TextFeature(0, 1.0, 0, 0), ops.TextFeature(1, 1.0, 0, 0)]
featurizer.fit([feature_group0, feature_group1])
features = featurizer.transform([feature_group0, feature_group1])
for f in features:
print(f.to_tuple())
'''Output:
(1, 1.0, 0, 0)
(2, 1.0, 0, 0)
(3, 1.0, 0, 0)
(4, 1.0, 0, 0)
'''