Package org.tribuo.interop.tensorflow
Class MultiLabelConverter
java.lang.Object
org.tribuo.interop.tensorflow.MultiLabelConverter
- All Implemented Interfaces:
com.oracle.labs.mlrg.olcut.config.Configurable
,com.oracle.labs.mlrg.olcut.provenance.Provenancable<com.oracle.labs.mlrg.olcut.provenance.ConfiguredObjectProvenance>
,Serializable
,OutputConverter<MultiLabel>
,ProtoSerializable<org.tribuo.interop.tensorflow.protos.OutputConverterProto>
Can convert a
MultiLabel
into a Tensor
containing a binary encoding of the label vector and
can convert a TFloat16
or TFloat32
into a Prediction
or a MultiLabel
.
Predictions are thresholded at THRESHOLD
, probabilities above this are considered to be present in the
output.
- See Also:
-
Field Summary
Modifier and TypeFieldDescriptionstatic final int
Protobuf serialization version.static final double
The threshold to determine if a label has been predicted.Fields inherited from interface org.tribuo.protos.ProtoSerializable
DESERIALIZATION_METHOD_NAME, PROVENANCE_SERIALIZER
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionconvertToBatchOutput
(org.tensorflow.Tensor tensor, ImmutableOutputInfo<MultiLabel> outputIDInfo) Converts aTensor
containing multiple outputs into a list ofOutput
s.convertToBatchPrediction
(org.tensorflow.Tensor tensor, ImmutableOutputInfo<MultiLabel> outputIDInfo, int[] numValidFeatures, List<Example<MultiLabel>> examples) Converts aTensor
containing multiple outputs into a list ofPrediction
s.convertToOutput
(org.tensorflow.Tensor tensor, ImmutableOutputInfo<MultiLabel> outputIDInfo) Converts aTensor
into the specified output type.convertToPrediction
(org.tensorflow.Tensor tensor, ImmutableOutputInfo<MultiLabel> outputIDInfo, int numValidFeatures, Example<MultiLabel> example) Converts aTensor
into aPrediction
.org.tensorflow.Tensor
convertToTensor
(List<Example<MultiLabel>> examples, ImmutableOutputInfo<MultiLabel> outputIDInfo) Converts a list ofExample
into aTensor
representing all the outputs in the list.org.tensorflow.Tensor
convertToTensor
(MultiLabel example, ImmutableOutputInfo<MultiLabel> outputIDInfo) Converts anOutput
into aTensor
representing it's output.static MultiLabelConverter
deserializeFromProto
(int version, String className, com.google.protobuf.Any message) Deserialization factory.boolean
Does this OutputConverter generate probabilities.com.oracle.labs.mlrg.olcut.provenance.ConfiguredObjectProvenance
The type witness used when deserializing the TensorFlow model from a protobuf.BiFunction<org.tensorflow.op.Ops,
com.oracle.labs.mlrg.olcut.util.Pair<org.tensorflow.op.core.Placeholder<? extends org.tensorflow.types.family.TNumber>, org.tensorflow.Operand<org.tensorflow.types.family.TNumber>>, org.tensorflow.Operand<org.tensorflow.types.family.TNumber>> loss()
Returns a sigmoid cross-entropy loss.<V extends org.tensorflow.types.family.TNumber>
BiFunction<org.tensorflow.op.Ops,org.tensorflow.Operand<V>, org.tensorflow.op.Op> Applies a softmax.org.tribuo.interop.tensorflow.protos.OutputConverterProto
Serializes this object to a protobuf.toString()
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
Methods inherited from interface com.oracle.labs.mlrg.olcut.config.Configurable
postConfig
-
Field Details
-
CURRENT_VERSION
public static final int CURRENT_VERSIONProtobuf serialization version.- See Also:
-
THRESHOLD
public static final double THRESHOLDThe threshold to determine if a label has been predicted.- See Also:
-
-
Constructor Details
-
MultiLabelConverter
public MultiLabelConverter()Constructs a MultiLabelConverter.
-
-
Method Details
-
deserializeFromProto
public static MultiLabelConverter deserializeFromProto(int version, String className, com.google.protobuf.Any message) Deserialization factory.- Parameters:
version
- The serialized object version.className
- The class name.message
- The serialized data.- Returns:
- The deserialized object.
-
serialize
public org.tribuo.interop.tensorflow.protos.OutputConverterProto serialize()Description copied from interface:ProtoSerializable
Serializes this object to a protobuf.- Specified by:
serialize
in interfaceProtoSerializable<org.tribuo.interop.tensorflow.protos.OutputConverterProto>
- Returns:
- The protobuf.
-
loss
public BiFunction<org.tensorflow.op.Ops,com.oracle.labs.mlrg.olcut.util.Pair<org.tensorflow.op.core.Placeholder<? extends org.tensorflow.types.family.TNumber>, loss()org.tensorflow.Operand<org.tensorflow.types.family.TNumber>>, org.tensorflow.Operand<org.tensorflow.types.family.TNumber>> Returns a sigmoid cross-entropy loss.- Specified by:
loss
in interfaceOutputConverter<MultiLabel>
- Returns:
- The sigmoid cross-entropy loss.
-
outputTransformFunction
public <V extends org.tensorflow.types.family.TNumber> BiFunction<org.tensorflow.op.Ops,org.tensorflow.Operand<V>, outputTransformFunction()org.tensorflow.op.Op> Applies a softmax.- Specified by:
outputTransformFunction
in interfaceOutputConverter<MultiLabel>
- Type Parameters:
V
- The softmax input type (should be TFloat32).- Returns:
- A function which applies a softmax.
-
convertToPrediction
public Prediction<MultiLabel> convertToPrediction(org.tensorflow.Tensor tensor, ImmutableOutputInfo<MultiLabel> outputIDInfo, int numValidFeatures, Example<MultiLabel> example) Description copied from interface:OutputConverter
Converts aTensor
into aPrediction
.- Specified by:
convertToPrediction
in interfaceOutputConverter<MultiLabel>
- Parameters:
tensor
- The tensor to convert.outputIDInfo
- The output info to use to identify the outputs.numValidFeatures
- The number of valid features used by the prediction.example
- The example to insert into the prediction.- Returns:
- A prediction object.
-
convertToOutput
public MultiLabel convertToOutput(org.tensorflow.Tensor tensor, ImmutableOutputInfo<MultiLabel> outputIDInfo) Description copied from interface:OutputConverter
Converts aTensor
into the specified output type.- Specified by:
convertToOutput
in interfaceOutputConverter<MultiLabel>
- Parameters:
tensor
- The tensor to convert.outputIDInfo
- The output info to use to identify the outputs.- Returns:
- A output.
-
convertToBatchPrediction
public List<Prediction<MultiLabel>> convertToBatchPrediction(org.tensorflow.Tensor tensor, ImmutableOutputInfo<MultiLabel> outputIDInfo, int[] numValidFeatures, List<Example<MultiLabel>> examples) Description copied from interface:OutputConverter
Converts aTensor
containing multiple outputs into a list ofPrediction
s.- Specified by:
convertToBatchPrediction
in interfaceOutputConverter<MultiLabel>
- Parameters:
tensor
- The tensor to convert.outputIDInfo
- The output info to use to identify the outputs.numValidFeatures
- The number of valid features used by the prediction.examples
- The example to insert into the prediction.- Returns:
- A list of predictions.
-
convertToBatchOutput
public List<MultiLabel> convertToBatchOutput(org.tensorflow.Tensor tensor, ImmutableOutputInfo<MultiLabel> outputIDInfo) Description copied from interface:OutputConverter
Converts aTensor
containing multiple outputs into a list ofOutput
s.- Specified by:
convertToBatchOutput
in interfaceOutputConverter<MultiLabel>
- Parameters:
tensor
- The tensor to convert.outputIDInfo
- The output info to use to identify the outputs.- Returns:
- A list of outputs.
-
convertToTensor
public org.tensorflow.Tensor convertToTensor(MultiLabel example, ImmutableOutputInfo<MultiLabel> outputIDInfo) Description copied from interface:OutputConverter
Converts anOutput
into aTensor
representing it's output.- Specified by:
convertToTensor
in interfaceOutputConverter<MultiLabel>
- Parameters:
example
- The output to convert.outputIDInfo
- The output info to use to identify the outputs.- Returns:
- A Tensor representing this output.
-
convertToTensor
public org.tensorflow.Tensor convertToTensor(List<Example<MultiLabel>> examples, ImmutableOutputInfo<MultiLabel> outputIDInfo) Description copied from interface:OutputConverter
Converts a list ofExample
into aTensor
representing all the outputs in the list. It accepts a list of Example rather than a list of Output for efficiency reasons.- Specified by:
convertToTensor
in interfaceOutputConverter<MultiLabel>
- Parameters:
examples
- The examples to convert.outputIDInfo
- The output info to use to identify the outputs.- Returns:
- A Tensor representing all the supplied Outputs.
-
generatesProbabilities
public boolean generatesProbabilities()Description copied from interface:OutputConverter
Does this OutputConverter generate probabilities.- Specified by:
generatesProbabilities
in interfaceOutputConverter<MultiLabel>
- Returns:
- True if it produces a probability distribution in the
Prediction
.
-
toString
-
getProvenance
public com.oracle.labs.mlrg.olcut.provenance.ConfiguredObjectProvenance getProvenance()- Specified by:
getProvenance
in interfacecom.oracle.labs.mlrg.olcut.provenance.Provenancable<com.oracle.labs.mlrg.olcut.provenance.ConfiguredObjectProvenance>
-
getTypeWitness
Description copied from interface:OutputConverter
The type witness used when deserializing the TensorFlow model from a protobuf.The default implementation throws
UnsupportedOperationException
for compatibility with implementations which don't use protobuf serialization. This implementation will be removed in the next major version of Tribuo.- Specified by:
getTypeWitness
in interfaceOutputConverter<MultiLabel>
- Returns:
- The output class this object produces.
-