Class ViterbiModel

java.lang.Object
org.tribuo.sequence.SequenceModel<Label>
org.tribuo.classification.sequence.viterbi.ViterbiModel
All Implemented Interfaces:
com.oracle.labs.mlrg.olcut.provenance.Provenancable<ModelProvenance>, Serializable, ProtoSerializable<org.tribuo.protos.core.SequenceModelProto>

public class ViterbiModel extends SequenceModel<Label>
An implementation of a viterbi model.
See Also:
  • Field Details

    • CURRENT_VERSION

      public static final int CURRENT_VERSION
      Protobuf 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 the message.
    • predict

      public List<List<Prediction<Label>>> predict(SequenceDataset<Label> examples)
      Description copied from class: SequenceModel
      Uses the model to predict the labels for multiple examples contained in a data set.
      Overrides:
      predict in class SequenceModel<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

      public List<Prediction<Label>> predict(SequenceExample<Label> examples)
      Description copied from class: SequenceModel
      Uses the model to predict the output for a single example.
      Specified by:
      predict in class SequenceModel<Label>
      Parameters:
      examples - the example to predict.
      Returns:
      the result of the prediction.
    • getInnerModel

      public Model<Label> getInnerModel()
      Returns the inner model used for sequence element predictions.
      Returns:
      The inner model.
    • getTopLabels

      protected List<Label> getTopLabels(Map<String,Label> distribution)
      Gets the most likely labels.
      Parameters:
      distribution - The label distribution.
      Returns:
      The most likely labels in descending order.
    • getTopLabels

      protected static List<Label> getTopLabels(Map<String,Label> distribution, int stackSize)
      Gets the stackSize 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

      public ViterbiModel.ScoreAggregation getScoreAggregation()
      Gets the score aggregation function.
      Returns:
      The score aggregation function.
    • getTopFeatures

      public Map<String,List<com.oracle.labs.mlrg.olcut.util.Pair<String,Double>>> getTopFeatures(int n)
      Description copied from class: SequenceModel
      Gets the top n 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 class SequenceModel<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 interface ProtoSerializable<org.tribuo.protos.core.SequenceModelProto>
      Overrides:
      serialize in class SequenceModel<Label>
      Returns:
      The protobuf.