Class SequenceExample<T extends Output<T>>
java.lang.Object
org.tribuo.sequence.SequenceExample<T>
- All Implemented Interfaces:
Serializable
,Iterable<Example<T>>
public class SequenceExample<T extends Output<T>>
extends Object
implements Iterable<Example<T>>, Serializable
A sequence of examples, used for sequence classification.
- See Also:
-
Field Summary
Fields -
Constructor Summary
ConstructorsConstructorDescriptionCreates 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.SequenceExample
(List<T> outputs, List<? extends List<? extends Feature>> features, float weight, boolean attemptBinaryFeatures) 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_WEIGHT- See Also:
-
-
Constructor Details
-
SequenceExample
public SequenceExample()Creates an empty sequence example. -
SequenceExample
-
SequenceExample
-
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
-
SequenceExample
-
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
-
get
-
validateExample
-
reduceByName
-
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
-
copy
-
iterator
-
featureIterator
-
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.
-