Class Label

java.lang.Object
org.tribuo.classification.Label
All Implemented Interfaces:
Serializable, Classifiable<Label>, Output<Label>, ProtoSerializable<org.tribuo.protos.core.OutputProto>

public final class Label extends Object implements Classifiable<Label>
An immutable multi-class classification label.

The labels themselves are Strings. A Label also contains an optional score which measures the confidence in that label, though it is not required to be a probability.

Label equality and hashCode is defined solely on the String label, it does not take into account the score.

See Also:
  • Field Details

    • UNKNOWN

      public static final String UNKNOWN
      The name of the unknown label (i.e., an unlabelled output).
      See Also:
    • label

      protected final String label
      The name of the label.
    • score

      protected final double score
      The score of the label.
  • Constructor Details

    • Label

      public Label(String label, double score)
      Builds a label with the supplied string and score.
      Parameters:
      label - The label name.
      score - The label instance score.
    • Label

      public Label(String label)
      Builds a label with the sentinel score of Double.NaN.
      Parameters:
      label - The name of this label.
  • Method Details

    • deserializeFromProto

      public static Label 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.
    • serialize

      public org.tribuo.protos.core.OutputProto serialize()
      Description copied from interface: ProtoSerializable
      Serializes this object to a protobuf.
      Specified by:
      serialize in interface ProtoSerializable<org.tribuo.protos.core.OutputProto>
      Returns:
      The protobuf.
    • getScore

      public double getScore()
      Get a real valued score for this label.

      If the score is not set then it returns Double.NaN.

      Returns:
      The predicted score for this label.
    • getLabel

      public String getLabel()
      Gets the name of this label.
      Returns:
      A String.
    • equals

      public boolean equals(Object o)
      Overrides:
      equals in class Object
    • fullEquals

      public boolean fullEquals(Label o)
      Description copied from interface: Output
      Compares other to this output. Uses all score values and the strings.
      Specified by:
      fullEquals in interface Output<Label>
      Parameters:
      o - Another output instance.
      Returns:
      True if the other instance has value equality to this instance. False otherwise.
    • fullEquals

      public boolean fullEquals(Label o, double tolerance)
      Description copied from interface: Output
      Compares other to this output. Uses all score values and the strings.

      The default implementation of this method ignores the tolerance for compatibility reasons, it is overridden in all output classes in Tribuo.

      Specified by:
      fullEquals in interface Output<Label>
      Parameters:
      o - Another output instance.
      tolerance - The tolerance level for an absolute value comparison.
      Returns:
      True if the other instance has value equality to this instance. False otherwise.
    • hashCode

      public int hashCode()
      Overrides:
      hashCode in class Object
    • toString

      public String toString()
      Overrides:
      toString in class Object
    • copy

      public Label copy()
      Description copied from interface: Output
      Deep copy of the output up to its immutable state.
      Specified by:
      copy in interface Output<Label>
      Returns:
      A copy of the output.
    • getSerializableForm

      public String getSerializableForm(boolean includeConfidence)
      Returns "labelName" or "labelName,score=labelScore".
      Specified by:
      getSerializableForm in interface Output<Label>
      Parameters:
      includeConfidence - Include whatever confidence score the label contains, if known.
      Returns:
      A String form suitable for serialization.