Search in sources :

Example 1 with FileProvenance

use of com.oracle.labs.mlrg.olcut.provenance.primitives.FileProvenance in project tribuo by oracle.

the class OCIModel method createOCIModel.

/**
 * Creates an {@code OCIModel} by wrapping an OCI DS Model Deployment endpoint.
 * <p>
 * Uses the endpointURL as the value to hash for the trainer provenance.
 *
 * @param factory         The output factory to use.
 * @param featureMapping  The feature mapping between Tribuo names and model integer ids.
 * @param outputMapping   The output mapping between Tribuo outputs and model integer ids.
 * @param configFile      The OCI configuration file, if null use the default file.
 * @param profileName     The profile name in the OCI configuration file, if null uses the default profile.
 * @param endpointURL     The endpoint URL.
 * @param outputConverter The converter for the specified output type.
 * @param <T> The output type.
 * @return An OCIModel ready to score new inputs.
 */
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) {
    try {
        ImmutableFeatureMap featureMap = ExternalModel.createFeatureMap(featureMapping.keySet());
        ImmutableOutputInfo<T> outputInfo = ExternalModel.createOutputInfo(factory, outputMapping);
        OffsetDateTime now = OffsetDateTime.now();
        ExternalTrainerProvenance trainerProvenance = new ExternalTrainerProvenance((endpointURL).getBytes(StandardCharsets.UTF_8));
        DatasetProvenance datasetProvenance = new ExternalDatasetProvenance("unknown-external-data", factory, false, featureMapping.size(), outputMapping.size());
        String[] endpoint = endpointURL.split("/");
        String domain = "https://" + endpoint[2] + "/";
        String modelDeploymentId = endpoint[3];
        HashMap<String, Provenance> runProvenance = new HashMap<>();
        runProvenance.put("configFile", new FileProvenance("configFile", configFile));
        runProvenance.put("endpointURL", new StringProvenance("endpointURL", endpointURL));
        runProvenance.put("modelDeploymentId", new StringProvenance("modelDeploymentId", modelDeploymentId));
        ModelProvenance provenance = new ModelProvenance(OCIModel.class.getName(), now, datasetProvenance, trainerProvenance, runProvenance);
        return new OCIModel<T>("oci-ds-model", provenance, featureMap, outputInfo, featureMapping, configFile, profileName, domain, modelDeploymentId, outputConverter);
    } catch (IOException e) {
        throw new IllegalArgumentException("Unable to load configuration from path " + configFile, e);
    }
}
Also used : ExternalDatasetProvenance(org.tribuo.interop.ExternalDatasetProvenance) ModelProvenance(org.tribuo.provenance.ModelProvenance) DatasetProvenance(org.tribuo.provenance.DatasetProvenance) ExternalTrainerProvenance(org.tribuo.interop.ExternalTrainerProvenance) FileProvenance(com.oracle.labs.mlrg.olcut.provenance.primitives.FileProvenance) Provenance(com.oracle.labs.mlrg.olcut.provenance.Provenance) StringProvenance(com.oracle.labs.mlrg.olcut.provenance.primitives.StringProvenance) ExternalDatasetProvenance(org.tribuo.interop.ExternalDatasetProvenance) ExternalTrainerProvenance(org.tribuo.interop.ExternalTrainerProvenance) HashMap(java.util.HashMap) StringProvenance(com.oracle.labs.mlrg.olcut.provenance.primitives.StringProvenance) ModelProvenance(org.tribuo.provenance.ModelProvenance) DatasetProvenance(org.tribuo.provenance.DatasetProvenance) ExternalDatasetProvenance(org.tribuo.interop.ExternalDatasetProvenance) IOException(java.io.IOException) FileProvenance(com.oracle.labs.mlrg.olcut.provenance.primitives.FileProvenance) OffsetDateTime(java.time.OffsetDateTime) ImmutableFeatureMap(org.tribuo.ImmutableFeatureMap)

Aggregations

Provenance (com.oracle.labs.mlrg.olcut.provenance.Provenance)1 FileProvenance (com.oracle.labs.mlrg.olcut.provenance.primitives.FileProvenance)1 StringProvenance (com.oracle.labs.mlrg.olcut.provenance.primitives.StringProvenance)1 IOException (java.io.IOException)1 OffsetDateTime (java.time.OffsetDateTime)1 HashMap (java.util.HashMap)1 ImmutableFeatureMap (org.tribuo.ImmutableFeatureMap)1 ExternalDatasetProvenance (org.tribuo.interop.ExternalDatasetProvenance)1 ExternalTrainerProvenance (org.tribuo.interop.ExternalTrainerProvenance)1 DatasetProvenance (org.tribuo.provenance.DatasetProvenance)1 ModelProvenance (org.tribuo.provenance.ModelProvenance)1