Class OCIModel<T extends Output<T>>

All Implemented Interfaces:
com.oracle.labs.mlrg.olcut.provenance.Provenancable<ModelProvenance>, Serializable, AutoCloseable, ProtoSerializable<org.tribuo.protos.core.ModelProto>

public final class OCIModel<T extends Output<T>> extends ExternalModel<T,DenseMatrix,DenseMatrix> implements AutoCloseable
A wrapper class around an OCI Data Science Model Deployment endpoint which sends off inputs for scoring and converts the output into a Tribuo prediction.
See Also:
  • Field Details

    • CURRENT_VERSION

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

    • deserializeFromProto

      public static OCIModel<?> deserializeFromProto(int version, String className, com.google.protobuf.Any message) throws com.google.protobuf.InvalidProtocolBufferException, IOException
      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.
      IOException
    • getTopFeatures

      public Map<String,List<com.oracle.labs.mlrg.olcut.util.Pair<String,Double>>> getTopFeatures(int i)
      Description copied from class: Model
      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 Model<T extends Output<T>>
      Parameters:
      i - 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 it's 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
    • copy

      protected Model<T> copy(String s, ModelProvenance modelProvenance)
      Description copied from class: Model
      Copies a model, replacing its provenance and name with the supplied values.

      Used to provide the provenance removal functionality.

      Specified by:
      copy in class Model<T extends Output<T>>
      Parameters:
      s - The new name.
      modelProvenance - The new provenance.
      Returns:
      A copy of the model.
    • convertFeatures

      protected DenseMatrix convertFeatures(SparseVector sparseVector)
      Description copied from class: ExternalModel
      Converts from a SparseVector using the external model's indices into the ingestion format for the external model.
      Specified by:
      convertFeatures in class ExternalModel<T extends Output<T>,DenseMatrix,DenseMatrix>
      Parameters:
      sparseVector - The features using external indices.
      Returns:
      The ingestion format for the external model.
    • convertFeaturesList

      protected DenseMatrix convertFeaturesList(List<SparseVector> list)
      Description copied from class: ExternalModel
      Converts from a list of SparseVector using the external model's indices into the ingestion format for the external model.
      Specified by:
      convertFeaturesList in class ExternalModel<T extends Output<T>,DenseMatrix,DenseMatrix>
      Parameters:
      list - The features using external indices.
      Returns:
      The ingestion format for the external model.
    • externalPrediction

      protected DenseMatrix externalPrediction(DenseMatrix features)
      Description copied from class: ExternalModel
      Runs the external model's prediction function.
      Specified by:
      externalPrediction in class ExternalModel<T extends Output<T>,DenseMatrix,DenseMatrix>
      Parameters:
      features - The input in the external model's format.
      Returns:
      The output in the external model's format.
    • convertOutput

      protected Prediction<T> convertOutput(DenseMatrix scores, int numValidFeature, Example<T> example)
      Description copied from class: ExternalModel
      Converts the output of the external model into a Prediction.
      Specified by:
      convertOutput in class ExternalModel<T extends Output<T>,DenseMatrix,DenseMatrix>
      Parameters:
      scores - The output of the external model.
      numValidFeature - The number of valid features in the input.
      example - The input example, used to construct the Prediction.
      Returns:
      A Tribuo Prediction.
    • convertOutput

      protected List<Prediction<T>> convertOutput(DenseMatrix scores, int[] numValidFeatures, List<Example<T>> list)
      Description copied from class: ExternalModel
      Converts the output of the external model into a list of Predictions.
      Specified by:
      convertOutput in class ExternalModel<T extends Output<T>,DenseMatrix,DenseMatrix>
      Parameters:
      scores - The output of the external model.
      numValidFeatures - An array with the number of valid features in each example.
      list - The input examples, used to construct the Predictions.
      Returns:
      A list of Tribuo Predictions.
    • close

      public void close()
      Specified by:
      close in interface AutoCloseable
    • serialize

      public org.tribuo.protos.core.ModelProto serialize()
      Description copied from interface: ProtoSerializable
      Serializes this object to a protobuf.
      Specified by:
      serialize in interface ProtoSerializable<T extends Output<T>>
      Overrides:
      serialize in class Model<T extends Output<T>>
      Returns:
      The protobuf.
    • makeAuthProvider

      public static com.oracle.bmc.auth.ConfigFileAuthenticationDetailsProvider makeAuthProvider(Path configFile, String profile) throws IOException
      Makes an authentication provider from the config file and profile.

      If the config file is null then it loads the default config file, if the profile is null it loads the default profile in the chosen config file.

      Parameters:
      configFile - The config file to load.
      profile - The profile to load.
      Returns:
      An authentication provider.
      Throws:
      IOException - If the config file could not be read.
    • createOCIModel

      public static <T extends Output<T>> OCIModel<T> createOCIModel(OutputFactory<T> factory, Map<String,Integer> featureMapping, Map<T,Integer> outputMapping, Path configFile, String endpointURL, OCIOutputConverter<T> outputConverter)
      Creates an OCIModel by wrapping an OCI DS Model Deployment endpoint.

      Uses the endpointURL as the value to hash for the trainer provenance.

      Loads the default profile in the configuration file.

      Type Parameters:
      T - The output type.
      Parameters:
      factory - The output factory to use.
      featureMapping - The feature mapping between Tribuo names and model integer ids.
      outputMapping - The output mapping between Tribuo outputs and model integer ids.
      configFile - The OCI configuration file, if null use the default file.
      endpointURL - The endpoint URL.
      outputConverter - The converter for the specified output type.
      Returns:
      An OCIModel ready to score new inputs.
    • createOCIModel

      public static <T extends Output<T>> OCIModel<T> createOCIModel(OutputFactory<T> factory, Map<String,Integer> featureMapping, Map<T,Integer> outputMapping, Path configFile, String profileName, String endpointURL, OCIOutputConverter<T> outputConverter)
      Creates an OCIModel by wrapping an OCI DS Model Deployment endpoint.

      Uses the endpointURL as the value to hash for the trainer provenance.

      Type Parameters:
      T - The output type.
      Parameters:
      factory - The output factory to use.
      featureMapping - The feature mapping between Tribuo names and model integer ids.
      outputMapping - The output mapping between Tribuo outputs and model integer ids.
      configFile - The OCI configuration file, if null use the default file.
      profileName - The profile name in the OCI configuration file, if null uses the default profile.
      endpointURL - The endpoint URL.
      outputConverter - The converter for the specified output type.
      Returns:
      An OCIModel ready to score new inputs.