テキスト エンティティ抽出用のモデル評価を一覧表示します。
コードサンプル
Go
AutoML Natural Language で認証を行うには、アプリケーションのデフォルト認証情報を設定します。詳細については、ローカル開発環境の認証の設定をご覧ください。
import (
"context"
"fmt"
"io"
automl "cloud.google.com/go/automl/apiv1"
"cloud.google.com/go/automl/apiv1/automlpb"
"google.golang.org/api/iterator"
)
// listModelEvaluation lists existing model evaluations.
func listModelEvaluations(w io.Writer, projectID string, location string, modelID string) error {
// projectID := "my-project-id"
// location := "us-central1"
// modelID := "TRL123456789..."
ctx := context.Background()
client, err := automl.NewClient(ctx)
if err != nil {
return fmt.Errorf("NewClient: %w", err)
}
defer client.Close()
req := &automlpb.ListModelEvaluationsRequest{
Parent: fmt.Sprintf("projects/%s/locations/%s/models/%s", projectID, location, modelID),
}
it := client.ListModelEvaluations(ctx, req)
// Iterate over all results
for {
evaluation, err := it.Next()
if err == iterator.Done {
break
}
if err != nil {
return fmt.Errorf("ListModelEvaluations.Next: %w", err)
}
fmt.Fprintf(w, "Model evaluation name: %v\n", evaluation.GetName())
fmt.Fprintf(w, "Model annotation spec id: %v\n", evaluation.GetAnnotationSpecId())
fmt.Fprintf(w, "Create Time:\n")
fmt.Fprintf(w, "\tseconds: %v\n", evaluation.GetCreateTime().GetSeconds())
fmt.Fprintf(w, "\tnanos: %v\n", evaluation.GetCreateTime().GetNanos())
fmt.Fprintf(w, "Evaluation example count: %v\n", evaluation.GetEvaluatedExampleCount())
fmt.Fprintf(w, "Entity extraction model evaluation metrics: %v\n", evaluation.GetTextExtractionEvaluationMetrics())
}
return nil
}
Java
AutoML Natural Language で認証を行うには、アプリケーションのデフォルト認証情報を設定します。詳細については、ローカル開発環境の認証の設定をご覧ください。
import com.google.cloud.automl.v1.AutoMlClient;
import com.google.cloud.automl.v1.ListModelEvaluationsRequest;
import com.google.cloud.automl.v1.ModelEvaluation;
import com.google.cloud.automl.v1.ModelName;
import java.io.IOException;
class ListModelEvaluations {
public static void main(String[] args) throws IOException {
// TODO(developer): Replace these variables before running the sample.
String projectId = "YOUR_PROJECT_ID";
String modelId = "YOUR_MODEL_ID";
listModelEvaluations(projectId, modelId);
}
// List model evaluations
static void listModelEvaluations(String projectId, String modelId) throws IOException {
// Initialize client that will be used to send requests. This client only needs to be created
// once, and can be reused for multiple requests. After completing all of your requests, call
// 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);
ListModelEvaluationsRequest modelEvaluationsrequest =
ListModelEvaluationsRequest.newBuilder().setParent(modelFullId.toString()).build();
// List all the model evaluations in the model by applying filter.
System.out.println("List of model evaluations:");
for (ModelEvaluation modelEvaluation :
client.listModelEvaluations(modelEvaluationsrequest).iterateAll()) {
System.out.format("Model Evaluation Name: %s\n", modelEvaluation.getName());
System.out.format("Model Annotation Spec Id: %s", modelEvaluation.getAnnotationSpecId());
System.out.println("Create Time:");
System.out.format("\tseconds: %s\n", modelEvaluation.getCreateTime().getSeconds());
System.out.format("\tnanos: %s", modelEvaluation.getCreateTime().getNanos() / 1e9);
System.out.format(
"Evalution Example Count: %d\n", modelEvaluation.getEvaluatedExampleCount());
System.out.format(
"Entity Extraction Model Evaluation Metrics: %s\n",
modelEvaluation.getTextExtractionEvaluationMetrics());
}
}
}
}
Node.js
AutoML Natural Language で認証を行うには、アプリケーションのデフォルト認証情報を設定します。詳細については、ローカル開発環境の認証の設定をご覧ください。
/**
* TODO(developer): Uncomment these variables before running the sample.
*/
// const projectId = 'YOUR_PROJECT_ID';
// const location = 'us-central1';
// const modelId = 'YOUR_MODEL_ID';
// Imports the Google Cloud AutoML library
const {AutoMlClient} = require('@google-cloud/automl').v1;
// Instantiates a client
const client = new AutoMlClient();
async function listModelEvaluations() {
// Construct request
const request = {
parent: client.modelPath(projectId, location, modelId),
filter: '',
};
const [response] = await client.listModelEvaluations(request);
console.log('List of model evaluations:');
for (const evaluation of response) {
console.log(`Model evaluation name: ${evaluation.name}`);
console.log(`Model annotation spec id: ${evaluation.annotationSpecId}`);
console.log(`Model display name: ${evaluation.displayName}`);
console.log('Model create time');
console.log(`\tseconds ${evaluation.createTime.seconds}`);
console.log(`\tnanos ${evaluation.createTime.nanos / 1e9}`);
console.log(
`Evaluation example count: ${evaluation.evaluatedExampleCount}`
);
console.log(
`Entity extraction model evaluation metrics: ${evaluation.textExtractionEvaluationMetrics}`
);
}
}
listModelEvaluations();
Python
AutoML Natural Language で認証を行うには、アプリケーションのデフォルト認証情報を設定します。詳細については、ローカル開発環境の認証の設定をご覧ください。
from google.cloud import automl
# TODO(developer): Uncomment and set the following variables
# project_id = "YOUR_PROJECT_ID"
# model_id = "YOUR_MODEL_ID"
client = automl.AutoMlClient()
# Get the full path of the model.
model_full_id = client.model_path(project_id, "us-central1", model_id)
print("List of model evaluations:")
for evaluation in client.list_model_evaluations(parent=model_full_id, filter=""):
print(f"Model evaluation name: {evaluation.name}")
print(f"Model annotation spec id: {evaluation.annotation_spec_id}")
print(f"Create Time: {evaluation.create_time}")
print(f"Evaluation example count: {evaluation.evaluated_example_count}")
print(
"Entity extraction model evaluation metrics: {}".format(
evaluation.text_extraction_evaluation_metrics
)
)
次のステップ
他の Google Cloud プロダクトに関連するコードサンプルの検索およびフィルタ検索を行うには、Google Cloud のサンプルをご覧ください。