use of com.google.cloud.aiplatform.v1.ModelName in project java-automl by googleapis.
the class TablesBatchPredictBigQuery method batchPredict.
static void batchPredict(String projectId, String modelId, String inputUri, String outputUri) throws IOException, ExecutionException, InterruptedException {
// the "close" method on the client to safely clean up any remaining background resources.
try (PredictionServiceClient client = PredictionServiceClient.create()) {
// Get the full path of the model.
ModelName name = ModelName.of(projectId, "us-central1", modelId);
// Configure the source of the file from BigQuery
BigQuerySource bigQuerySource = BigQuerySource.newBuilder().setInputUri(inputUri).build();
BatchPredictInputConfig inputConfig = BatchPredictInputConfig.newBuilder().setBigquerySource(bigQuerySource).build();
// Configure where to store the output in BigQuery
BigQueryDestination bigQueryDestination = BigQueryDestination.newBuilder().setOutputUri(outputUri).build();
BatchPredictOutputConfig outputConfig = BatchPredictOutputConfig.newBuilder().setBigqueryDestination(bigQueryDestination).build();
// Build the request that will be sent to the API
BatchPredictRequest request = BatchPredictRequest.newBuilder().setName(name.toString()).setInputConfig(inputConfig).setOutputConfig(outputConfig).build();
// Start an asynchronous request
OperationFuture<BatchPredictResult, OperationMetadata> future = client.batchPredictAsync(request);
System.out.println("Waiting for operation to complete...");
BatchPredictResult response = future.get();
System.out.println("Batch Prediction results saved to BigQuery.");
}
}
use of com.google.cloud.aiplatform.v1.ModelName in project java-automl by googleapis.
the class TablesGetModel method getModel.
// Demonstrates using the AutoML client to get model details.
public static void getModel(String projectId, String computeRegion, String modelId) throws IOException, StatusRuntimeException {
// the "close" method on the client to safely clean up any remaining background resources.
try (AutoMlClient client = AutoMlClient.create()) {
// Get the full path of the model.
ModelName modelFullId = ModelName.of(projectId, computeRegion, modelId);
// Get complete detail of the model.
Model model = client.getModel(modelFullId);
// Display the model information.
System.out.format("Model name: %s%n", model.getName());
System.out.format("Model Id: %s\n", model.getName().split("/")[model.getName().split("/").length - 1]);
System.out.format("Model display name: %s%n", model.getDisplayName());
System.out.format("Dataset Id: %s%n", model.getDatasetId());
System.out.println("Tables Model Metadata: ");
System.out.format("\tTraining budget: %s%n", model.getTablesModelMetadata().getTrainBudgetMilliNodeHours());
System.out.format("\tTraining cost: %s%n", model.getTablesModelMetadata().getTrainBudgetMilliNodeHours());
DateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSSZ");
String createTime = dateFormat.format(new java.util.Date(model.getCreateTime().getSeconds() * 1000));
System.out.format("Model create time: %s%n", createTime);
System.out.format("Model deployment state: %s%n", model.getDeploymentState());
// Get features of top importance
for (TablesModelColumnInfo info : model.getTablesModelMetadata().getTablesModelColumnInfoList()) {
System.out.format("Column: %s - Importance: %.2f%n", info.getColumnDisplayName(), info.getFeatureImportance());
}
}
}
use of com.google.cloud.aiplatform.v1.ModelName in project java-automl by googleapis.
the class UndeployModel method undeployModel.
// Undeploy a model from prediction
static void undeployModel(String projectId, String modelId) throws IOException, ExecutionException, InterruptedException {
// the "close" method on the client to safely clean up any remaining background resources.
try (AutoMlClient client = AutoMlClient.create()) {
// Get the full path of the model.
ModelName modelFullId = ModelName.of(projectId, "us-central1", modelId);
UndeployModelRequest request = UndeployModelRequest.newBuilder().setName(modelFullId.toString()).build();
OperationFuture<Empty, OperationMetadata> future = client.undeployModelAsync(request);
future.get();
System.out.println("Model undeployment finished");
}
}
use of com.google.cloud.aiplatform.v1.ModelName in project java-automl by googleapis.
the class LanguageEntityExtractionPredict method predict.
static void predict(String projectId, String modelId, String content) throws IOException {
// the "close" method on the client to safely clean up any remaining background resources.
try (PredictionServiceClient client = PredictionServiceClient.create()) {
// Get the full path of the model.
ModelName name = ModelName.of(projectId, "us-central1", modelId);
// For available mime types, see:
// https://cloud.google.com/automl/docs/reference/rest/v1/projects.locations.models/predict#textsnippet
TextSnippet textSnippet = TextSnippet.newBuilder().setContent(content).setMimeType(// Types: text/plain, text/html
"text/plain").build();
ExamplePayload payload = ExamplePayload.newBuilder().setTextSnippet(textSnippet).build();
PredictRequest predictRequest = PredictRequest.newBuilder().setName(name.toString()).setPayload(payload).build();
PredictResponse response = client.predict(predictRequest);
for (AnnotationPayload annotationPayload : response.getPayloadList()) {
System.out.format("Text Extract Entity Type: %s\n", annotationPayload.getDisplayName());
System.out.format("Text score: %.2f\n", annotationPayload.getTextExtraction().getScore());
TextSegment textSegment = annotationPayload.getTextExtraction().getTextSegment();
System.out.format("Text Extract Entity Content: %s\n", textSegment.getContent());
System.out.format("Text Start Offset: %s\n", textSegment.getStartOffset());
System.out.format("Text End Offset: %s\n\n", textSegment.getEndOffset());
}
}
}
use of com.google.cloud.aiplatform.v1.ModelName in project java-automl by googleapis.
the class LanguageSentimentAnalysisPredict method predict.
static void predict(String projectId, String modelId, String content) throws IOException {
// the "close" method on the client to safely clean up any remaining background resources.
try (PredictionServiceClient client = PredictionServiceClient.create()) {
// Get the full path of the model.
ModelName name = ModelName.of(projectId, "us-central1", modelId);
// For available mime types, see:
// https://cloud.google.com/automl/docs/reference/rest/v1/projects.locations.models/predict#textsnippet
TextSnippet textSnippet = TextSnippet.newBuilder().setContent(content).setMimeType(// Types: text/plain, text/html
"text/plain").build();
ExamplePayload payload = ExamplePayload.newBuilder().setTextSnippet(textSnippet).build();
PredictRequest predictRequest = PredictRequest.newBuilder().setName(name.toString()).setPayload(payload).build();
PredictResponse response = client.predict(predictRequest);
for (AnnotationPayload annotationPayload : response.getPayloadList()) {
System.out.format("Predicted class name: %s\n", annotationPayload.getDisplayName());
System.out.format("Predicted sentiment score: %d\n", annotationPayload.getTextSentiment().getSentiment());
}
}
}
Aggregations