Class ViterbiModel
- All Implemented Interfaces:
com.oracle.labs.mlrg.olcut.provenance.Provenancable<ModelProvenance>
,Serializable
,ProtoSerializable<org.tribuo.protos.core.SequenceModelProto>
An implementation of a viterbi model.
- See Also:
-
Nested Class Summary
Modifier and TypeClassDescriptionstatic enum
Types of label score aggregation. -
Field Summary
Modifier and TypeFieldDescriptionstatic final int
Protobuf serialization version.Fields inherited from class org.tribuo.sequence.SequenceModel
featureIDMap, name, outputIDMap, provenanceOutput
Fields inherited from interface org.tribuo.protos.ProtoSerializable
DESERIALIZATION_METHOD_NAME, PROVENANCE_SERIALIZER
-
Method Summary
Modifier and TypeMethodDescriptionstatic ViterbiModel
deserializeFromProto
(int version, String className, com.google.protobuf.Any message) Deserialization factory.Returns the inner model used for sequence element predictions.Gets the score aggregation function.int
Gets the stack size of this model.getTopFeatures
(int n) Gets the topn
features associated with this model.getTopLabels
(Map<String, Label> distribution) Gets the most likely labels.getTopLabels
(Map<String, Label> distribution, int stackSize) Gets thestackSize
most likely labels.List<List<Prediction<Label>>>
predict
(SequenceDataset<Label> examples) Uses the model to predict the labels for multiple examples contained in a data set.predict
(SequenceExample<Label> examples) Uses the model to predict the output for a single example.org.tribuo.protos.core.SequenceModelProto
Serializes this object to a protobuf.Methods inherited from class org.tribuo.sequence.SequenceModel
castModel, createDataCarrier, deserialize, deserializeFromFile, deserializeFromStream, getFeatureIDMap, getName, getOutputIDInfo, getProvenance, predict, serializeToFile, serializeToStream, setName, toMaxLabels, toString, validate
-
Field Details
-
CURRENT_VERSION
public static final int CURRENT_VERSIONProtobuf serialization version.- See Also:
-
-
Method Details
-
deserializeFromProto
public static ViterbiModel deserializeFromProto(int version, String className, com.google.protobuf.Any message) throws com.google.protobuf.InvalidProtocolBufferException Deserialization factory.- Parameters:
version
- The serialized object version.className
- The class name.message
- The serialized data.- Returns:
- The deserialized object.
- Throws:
com.google.protobuf.InvalidProtocolBufferException
- If the protobuf could not be parsed from themessage
.
-
predict
Description copied from class:SequenceModel
Uses the model to predict the labels for multiple examples contained in a data set.- Overrides:
predict
in classSequenceModel<Label>
- Parameters:
examples
- the data set containing the examples to predict.- Returns:
- the results of the predictions, in the same order as the data set generates the example.
-
predict
Description copied from class:SequenceModel
Uses the model to predict the output for a single example.- Specified by:
predict
in classSequenceModel<Label>
- Parameters:
examples
- the example to predict.- Returns:
- the result of the prediction.
-
getInnerModel
Returns the inner model used for sequence element predictions.- Returns:
- The inner model.
-
getTopLabels
Gets the most likely labels.- Parameters:
distribution
- The label distribution.- Returns:
- The most likely labels in descending order.
-
getTopLabels
Gets thestackSize
most likely labels.- Parameters:
distribution
- The label distribution.stackSize
- The number of labels to pick.- Returns:
- The most likely labels in descending order.
-
getStackSize
public int getStackSize()Gets the stack size of this model.- Returns:
- The stack size.
-
getScoreAggregation
Gets the score aggregation function.- Returns:
- The score aggregation function.
-
getTopFeatures
Description copied from class:SequenceModel
Gets the topn
features associated with this model.If the model does not produce per output feature lists, it returns a map with a single element with key Model.ALL_OUTPUTS.
If the model cannot describe it's top features then it returns
Collections.emptyMap()
.- Specified by:
getTopFeatures
in classSequenceModel<Label>
- Parameters:
n
- the number of features to return. If this value is less than 0, all features should be returned for each class, unless the model cannot score its features.- Returns:
- a map from string outputs to an ordered list of pairs of feature names and weights associated with that feature in the model
-
serialize
public org.tribuo.protos.core.SequenceModelProto serialize()Description copied from interface:ProtoSerializable
Serializes this object to a protobuf.- Specified by:
serialize
in interfaceProtoSerializable<org.tribuo.protos.core.SequenceModelProto>
- Overrides:
serialize
in classSequenceModel<Label>
- Returns:
- The protobuf.
-