Package org.tribuo.interop.oci
Class OCIModel<T extends Output<T>>
java.lang.Object
org.tribuo.Model<T>
org.tribuo.interop.ExternalModel<T,DenseMatrix,DenseMatrix>
org.tribuo.interop.oci.OCIModel<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:
-
Nested Class Summary
Modifier and TypeClassDescriptionstatic final class
Carrier type for easy deserialization from JSON. -
Field Summary
Modifier and TypeFieldDescriptionstatic final int
Protobuf serialization version.Fields inherited from class org.tribuo.interop.ExternalModel
DEFAULT_BATCH_SIZE, featureBackwardMapping, featureForwardMapping
Fields inherited from class org.tribuo.Model
ALL_OUTPUTS, BIAS_FEATURE, featureIDMap, generatesProbabilities, name, outputIDInfo, provenance, provenanceOutput
Fields inherited from interface org.tribuo.protos.ProtoSerializable
DESERIALIZATION_METHOD_NAME, PROVENANCE_SERIALIZER
-
Method Summary
Modifier and TypeMethodDescriptionvoid
close()
protected DenseMatrix
convertFeatures
(SparseVector sparseVector) Converts from a SparseVector using the external model's indices into the ingestion format for the external model.protected DenseMatrix
convertFeaturesList
(List<SparseVector> list) Converts from a list of SparseVector using the external model's indices into the ingestion format for the external model.protected List<Prediction<T>>
convertOutput
(DenseMatrix scores, int[] numValidFeatures, List<Example<T>> list) Converts the output of the external model into a list ofPrediction
s.protected Prediction<T>
convertOutput
(DenseMatrix scores, int numValidFeature, Example<T> example) Converts the output of the external model into aPrediction
.copy
(String s, ModelProvenance modelProvenance) Copies a model, replacing its provenance and name with the supplied values.createOCIModel
(OutputFactory<T> factory, Map<String, Integer> featureMapping, Map<T, Integer> outputMapping, Path configFile, String profileName, String endpointURL, OCIOutputConverter<T> outputConverter) Creates anOCIModel
by wrapping an OCI DS Model Deployment endpoint.createOCIModel
(OutputFactory<T> factory, Map<String, Integer> featureMapping, Map<T, Integer> outputMapping, Path configFile, String endpointURL, OCIOutputConverter<T> outputConverter) Creates anOCIModel
by wrapping an OCI DS Model Deployment endpoint.static OCIModel<?>
deserializeFromProto
(int version, String className, com.google.protobuf.Any message) Deserialization factory.protected DenseMatrix
externalPrediction
(DenseMatrix features) Runs the external model's prediction function.getTopFeatures
(int i) Gets the topn
features associated with this model.static com.oracle.bmc.auth.ConfigFileAuthenticationDetailsProvider
makeAuthProvider
(Path configFile, String profile) Makes an authentication provider from the config file and profile.org.tribuo.protos.core.ModelProto
Serializes this object to a protobuf.Methods inherited from class org.tribuo.interop.ExternalModel
createFeatureMap, createOutputInfo, getBatchSize, getExcuse, innerPredict, predict, setBatchSize, validateFeatureMapping
Methods inherited from class org.tribuo.Model
castModel, copy, createDataCarrier, deserialize, deserializeFromFile, deserializeFromStream, generatesProbabilities, getExcuses, getFeatureIDMap, getName, getOutputIDInfo, getProvenance, predict, predict, serializeToFile, serializeToStream, setName, toString, validate
-
Field Details
-
CURRENT_VERSION
public static final int CURRENT_VERSIONProtobuf 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 themessage
.IOException
-
getTopFeatures
Description copied from class:Model
Gets the topn
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 classModel<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
Description copied from class:Model
Copies a model, replacing its provenance and name with the supplied values.Used to provide the provenance removal functionality.
-
convertFeatures
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 classExternalModel<T extends Output<T>,
DenseMatrix, DenseMatrix> - Parameters:
sparseVector
- The features using external indices.- Returns:
- The ingestion format for the external model.
-
convertFeaturesList
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 classExternalModel<T extends Output<T>,
DenseMatrix, DenseMatrix> - Parameters:
list
- The features using external indices.- Returns:
- The ingestion format for the external model.
-
externalPrediction
Description copied from class:ExternalModel
Runs the external model's prediction function.- Specified by:
externalPrediction
in classExternalModel<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
Description copied from class:ExternalModel
Converts the output of the external model into aPrediction
.- Specified by:
convertOutput
in classExternalModel<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 ofPrediction
s.- Specified by:
convertOutput
in classExternalModel<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 interfaceAutoCloseable
-
serialize
public org.tribuo.protos.core.ModelProto serialize()Description copied from interface:ProtoSerializable
Serializes this object to a 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 anOCIModel
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 anOCIModel
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.
-