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.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.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
- 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
-
SequenceExample
-
SequenceExample
Creates a deep copy of the supplied sequence example.- Parameters:
other
- The sequence example to copy.
-
-
Method Details
-
size
-
removeFeatures
Removes the features in the supplied list from each example contained in this sequence.- Parameters:
features
- The features to remove.
-
get
-
validateExample
-
reduceByName
Reduces the features in each example using the suppliedMerger
.- Parameters:
merger
- The merger to use in the reduction.
-
setWeight
Sets the weight of this sequence.- Parameters:
weight
- The new weight.
-
getWeight
-
addExample
Adds anExample
to this sequence.- Parameters:
e
- The example to add.
-
copy
-
iterator
-
featureIterator
Creates an iterator over every feature in this sequence.- Returns:
- An iterator over features.
-
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.
-