Class DenseTransformer

java.lang.Object
org.tribuo.interop.onnx.DenseTransformer
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, ExampleTransformer, ProtoSerializable<org.tribuo.interop.onnx.protos.ExampleTransformerProto>

public class DenseTransformer extends Object implements ExampleTransformer
Converts a sparse Tribuo example into a dense float vector, then wraps it in an OnnxTensor.
See Also:
  • Field Details

    • CURRENT_VERSION

      public static final int CURRENT_VERSION
      Protobuf serialization version.
      See Also:
    • THRESHOLD

      public static final int THRESHOLD
      Feature size beyond which a warning is generated (as ONNX requires dense features and large feature spaces are memory hungry).
      See Also:
    • WARNING_THRESHOLD

      public static final int WARNING_THRESHOLD
      Number of times the feature size warning should be printed.
      See Also:
  • Constructor Details

    • DenseTransformer

      public DenseTransformer()
      Construct a transformer which converts Tribuo sparse vectors into a dense tensor.
  • Method Details

    • deserializeFromProto

      public static DenseTransformer 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.
    • transform

      public ai.onnxruntime.OnnxTensor transform(ai.onnxruntime.OrtEnvironment env, SparseVector vector) throws ai.onnxruntime.OrtException
      Description copied from interface: ExampleTransformer
      Converts a SparseVector representing the features into a OnnxTensor.

      It generates it as a single example minibatch.

      Specified by:
      transform in interface ExampleTransformer
      Parameters:
      env - The OrtEnvironment to create the tensor in.
      vector - The features to convert.
      Returns:
      A dense OnnxTensor representing this vector.
      Throws:
      ai.onnxruntime.OrtException - if the transformation failed.
    • transform

      public ai.onnxruntime.OnnxTensor transform(ai.onnxruntime.OrtEnvironment env, List<SparseVector> vectors) throws ai.onnxruntime.OrtException
      Description copied from interface: ExampleTransformer
      Converts a list of SparseVectors representing a batch of features into a OnnxTensor.
      Specified by:
      transform in interface ExampleTransformer
      Parameters:
      env - The OrtEnvironment to create the tensor in.
      vectors - The batch of features to convert.
      Returns:
      A dense OnnxTensor representing this minibatch.
      Throws:
      ai.onnxruntime.OrtException - if the transformation failed.
    • toString

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

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

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

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

      public com.oracle.labs.mlrg.olcut.provenance.ConfiguredObjectProvenance getProvenance()
      Specified by:
      getProvenance in interface com.oracle.labs.mlrg.olcut.provenance.Provenancable<com.oracle.labs.mlrg.olcut.provenance.ConfiguredObjectProvenance>