use of com.oracle.labs.mlrg.olcut.provenance.Provenance 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);
}
}
use of com.oracle.labs.mlrg.olcut.provenance.Provenance in project tribuo by oracle.
the class StripProvenance method cleanProvenance.
/**
* Creates a new model provenance with the requested provenances stripped out.
* @param old The old model provenance.
* @param provenanceHash The hash of the provenance (if requested it can be written into the new provenance for tracking).
* @param opt The program options.
* @return A new model provenance.
*/
private static ModelProvenance cleanProvenance(ModelProvenance old, String provenanceHash, StripProvenanceOptions opt) {
// Dataset provenance
DatasetProvenance datasetProvenance;
if (opt.removeProvenances.contains(ALL) || opt.removeProvenances.contains(DATASET)) {
datasetProvenance = new EmptyDatasetProvenance();
} else {
datasetProvenance = old.getDatasetProvenance();
}
// Trainer provenance
TrainerProvenance trainerProvenance;
if (opt.removeProvenances.contains(ALL) || opt.removeProvenances.contains(TRAINER)) {
trainerProvenance = new EmptyTrainerProvenance();
} else {
trainerProvenance = old.getTrainerProvenance();
}
// Instance provenance
OffsetDateTime time;
Map<String, Provenance> instanceProvenance;
if (opt.removeProvenances.contains(ALL) || opt.removeProvenances.contains(INSTANCE)) {
instanceProvenance = new HashMap<>();
time = OffsetDateTime.MIN;
} else {
instanceProvenance = new HashMap<>(old.getInstanceProvenance().getMap());
time = old.getTrainingTime();
}
if (opt.storeHash) {
logger.info("Writing provenance hash into instance map.");
instanceProvenance.put("original-provenance-hash", new HashProvenance(opt.hashType, "original-provenance-hash", provenanceHash));
}
boolean stripSystem;
if (opt.removeProvenances.contains(ALL) || opt.removeProvenances.contains(SYSTEM)) {
stripSystem = true;
} else {
stripSystem = false;
}
return new ModelProvenance(old.getClassName(), time, datasetProvenance, trainerProvenance, instanceProvenance, !stripSystem);
}
Aggregations