Class SequenceExample<T extends Output<T>>
- All Implemented Interfaces:
Serializable
,Iterable<Example<T>>
- See Also:
-
Field Summary
Modifier and TypeFieldDescriptionstatic final float
The default sequence example weight. -
Constructor Summary
ConstructorDescriptionCreates an empty sequence example.SequenceExample
(List<Example<T>> examples) Creates a sequence example from the list of examples.SequenceExample
(List<Example<T>> examples, float weight) Creates a sequence example from the list of examples, setting the weight.Creates a sequence example from the supplied outputs and list of list of features.SequenceExample
(List<T> outputs, List<? extends List<? extends Feature>> features, boolean attemptBinaryFeatures) Creates a sequence example from the supplied weight, outputs and list of list of features.Creates a sequence example from the supplied weight, outputs and list of list of features.SequenceExample
(List<T> outputs, List<? extends List<? extends Feature>> features, float weight, boolean attemptBinaryFeatures) Creates a sequence example from the supplied weight, outputs and list of list of features.SequenceExample
(SequenceExample<T> other) Creates a deep copy of the supplied sequence example. -
Method Summary
Modifier and TypeMethodDescriptionvoid
addExample
(Example<T> e) Adds anExample
to this sequence.void
canonicalise
(FeatureMap featureMap) Reassigns feature name Strings in each Example inside this SequenceExample to point to those in theFeatureMap
.copy()
Returns a deep copy of this SequenceExample.static <T extends Output<T>>
SequenceExample<T>createWithEmptyOutputs
(List<? extends List<? extends Feature>> features, OutputFactory<T> outputFactory) Creates a SequenceExample usingOutputFactory.getUnknownOutput()
as the output for each sequence element.void
densify
(FeatureMap fMap) Converts all implicit zeros into explicit zeros based on the supplied feature map.Creates an iterator over every feature in this sequence.get
(int i) Gets the example found at the specified index.float
Gets the weight of this sequence.boolean
isDense
(FeatureMap fMap) Is this sequence example dense wrt the supplied feature map.iterator()
void
reduceByName
(Merger merger) Reduces the features in each example using the suppliedMerger
.void
removeFeatures
(List<Feature> features) Removes the features in the supplied list from each example contained in this sequence.void
setWeight
(float weight) Sets the weight of this sequence.int
size()
Return how many examples are in this sequence.boolean
Checks that eachExample
in this sequence is valid.Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
Methods inherited from interface java.lang.Iterable
forEach, spliterator
-
Field Details
-
DEFAULT_WEIGHT
public static final float DEFAULT_WEIGHTThe default sequence example weight.- See Also:
-
-
Constructor Details
-
SequenceExample
public SequenceExample()Creates an empty sequence example. -
SequenceExample
Creates a sequence example from the list of examples.The examples are not copied by this method.
- Parameters:
examples
- The examples to incorporate.
-
SequenceExample
Creates a sequence example from the list of examples, setting the weight.The examples are encapsulated by this constructor, not copied.
- Parameters:
examples
- The examples to incorporate.weight
- The weight of this sequence.
-
SequenceExample
Creates a sequence example from the supplied outputs and list of list of features.The features are copied out by this constructor. The outputs and features lists must be of the same length. Sets the weight to
DEFAULT_WEIGHT
.- Parameters:
outputs
- The outputs for each sequence element.features
- The features for each sequence element.
-
SequenceExample
public SequenceExample(List<T> outputs, List<? extends List<? extends Feature>> features, float weight) Creates a sequence example from the supplied weight, outputs and list of list of features.The features are copied out by this constructor. The outputs and features lists must be of the same length.
- Parameters:
outputs
- The outputs for each sequence element.features
- The features for each sequence element.weight
- The weight for this sequence example.
-
SequenceExample
public SequenceExample(List<T> outputs, List<? extends List<? extends Feature>> features, boolean attemptBinaryFeatures) Creates a sequence example from the supplied weight, outputs and list of list of features.The features are copied out by this constructor. The outputs and features lists must be of the same length. Sets the weight to
DEFAULT_WEIGHT
.- Parameters:
outputs
- The outputs for each sequence element.features
- The features for each sequence element.attemptBinaryFeatures
- Attempt to useBinaryFeaturesExample
as the inner examples.
-
SequenceExample
public SequenceExample(List<T> outputs, List<? extends List<? extends Feature>> features, float weight, boolean attemptBinaryFeatures) Creates a sequence example from the supplied weight, outputs and list of list of features.The features are copied out by this constructor. The outputs and features lists must be of the same length.
- Parameters:
outputs
- The outputs for each sequence element.features
- The features for each sequence element.weight
- The weight for this sequence example.attemptBinaryFeatures
- Attempt to useBinaryFeaturesExample
as the inner examples.
-
SequenceExample
Creates a deep copy of the supplied sequence example.- Parameters:
other
- The sequence example to copy.
-
-
Method Details
-
size
public int size()Return how many examples are in this sequence.- Returns:
- The number of examples.
-
removeFeatures
Removes the features in the supplied list from each example contained in this sequence.- Parameters:
features
- The features to remove.
-
get
Gets the example found at the specified index.- Parameters:
i
- The index to lookup.- Returns:
- The
Example
for index i.
-
validateExample
public boolean validateExample()Checks that eachExample
in this sequence is valid.- Returns:
- True if each
Example
is valid, false otherwise.
-
reduceByName
Reduces the features in each example using the suppliedMerger
.- Parameters:
merger
- The merger to use in the reduction.
-
setWeight
public void setWeight(float weight) Sets the weight of this sequence.- Parameters:
weight
- The new weight.
-
getWeight
public float getWeight()Gets the weight of this sequence.- Returns:
- The weight of this sequence.
-
addExample
Adds anExample
to this sequence.- Parameters:
e
- The example to add.
-
copy
Returns a deep copy of this SequenceExample.- Returns:
- A deep copy.
-
iterator
-
featureIterator
Creates an iterator over every feature in this sequence.- Returns:
- An iterator over features.
-
isDense
Is this sequence example dense wrt the supplied feature map.A sequence example is "dense" if each example inside it contains all the features in the map, and only those features.
- Parameters:
fMap
- The feature map to check against.- Returns:
- True if this sequence example contains only the features in the map, and all the features in the map.
-
densify
Converts all implicit zeros into explicit zeros based on the supplied feature map.- Parameters:
fMap
- The feature map to use for densification.
-
canonicalise
Reassigns feature name Strings in each Example inside this SequenceExample to point to those in theFeatureMap
. This significantly reduces memory allocation. It is called when a SequenceExample is added to aMutableSequenceDataset
, and should not be called outside of that context as it may interact unexpectedly withHashedFeatureMap
.- Parameters:
featureMap
- The feature map containing canonical feature names.
-
createWithEmptyOutputs
public static <T extends Output<T>> SequenceExample<T> createWithEmptyOutputs(List<? extends List<? extends Feature>> features, OutputFactory<T> outputFactory) Creates a SequenceExample usingOutputFactory.getUnknownOutput()
as the output for each sequence element.Note: this method is used to create SequenceExamples at prediction time where there is no ground truth
Output
.- Type Parameters:
T
- The type of theOutput
.- Parameters:
features
- The features for each sequence element.outputFactory
- The output factory to use.- Returns:
- A new SequenceExample.
-