smile.feature
Class Bag<T>
- java.lang.Object
-
- smile.feature.Bag<T>
-
- All Implemented Interfaces:
- FeatureGenerator<T[]>
public class Bag<T> extends java.lang.Object implements FeatureGenerator<T[]>
The bag-of-words feature of text used in natural language processing and information retrieval. In this model, a text (such as a sentence or a document) is represented as an unordered collection of words, disregarding grammar and even word order. This is a generic implementations. Thus, it can be used for sequences of any (discrete) data types with limited number of values.
-
-
Constructor Summary
Constructors Constructor and Description Bag(T[] features)Constructor.Bag(T[] features, boolean binary)Constructor.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method and Description Attribute[]attributes()Returns the variable attributes of generated features.double[]feature(T[] x)Returns the bag-of-words features of a document.
-
-
-
Constructor Detail
-
Bag
public Bag(T[] features)
Constructor.- Parameters:
features- the list of feature objects.
-
Bag
public Bag(T[] features, boolean binary)
Constructor.- Parameters:
features- the list of feature objects. The feature objects should be unique in the list. Note that the Bag class doesn't learn the features, but just use them as attributes.binary- true to check if feature object appear in a collection instead of their frequencies.
-
-
Method Detail
-
attributes
public Attribute[] attributes()
Description copied from interface:FeatureGeneratorReturns the variable attributes of generated features. Note that these are NOT the original variable attributes of objects.- Specified by:
attributesin interfaceFeatureGenerator<T[]>- Returns:
- the variable attributes of generated features
-
feature
public double[] feature(T[] x)
Returns the bag-of-words features of a document. The features are real-valued in convenience of most learning algorithms although they take only integer or binary values.- Specified by:
featurein interfaceFeatureGenerator<T[]>- Parameters:
x- an object of interest.- Returns:
- a feature vector.
-
-
DataMelt 3.0 © DataMelt by jWork.ORG