After you have created (trained) a model, you can request predictions from the model. A prediction occurs when you submit a document to the model and ask it to analyze the document according to the objective for that model (classification, entity extraction, or sentiment analysis).
AutoML Natural Language supports both online prediction, where you submit a single document and the model returns the analysis synchronously, and batch prediction, where you submit a collection of documents that the model analyzes asynchronously.
Online prediction
To make a prediction using the AutoML Natural Language UI:
Click the lightbulb icon in the left navigation bar to display the available models.
To view the models for a different project, select the project from the drop-down list in the upper right of the title bar.
Click the row for the model you want to use to analyze the document.
Click the Test & Use tab just below the title bar.
Enter the text you want to analyze into the text box, or click Select a file on Cloud Storage and enter the Cloud Storage path for a PDF or TIFF file.
Click Predict.
Code samples
Classification
REST
Before using any of the request data, make the following replacements:
- project-id: your project ID
- location-id: the location for the resource,
us-central1
for the Global location oreu
for the European Union - model-id: your model ID
HTTP method and URL:
POST https://automl.googleapis.com/v1/projects/project-id/locations/location-id/models/model-id:predict
Request JSON body:
{ "payload" : { "textSnippet": { "content": "Google, headquartered in Mountain View, unveiled the new Android phone at the Consumer Electronic Show. Sundar Pichai said in his keynote that users love their new Android phones.", "mime_type": "text/plain" }, } }
To send your request, expand one of these options:
You should receive a JSON response similar to the following:
{ "payload": [ { "displayName": "Technology", "classification": { "score": 0.8989502 } }, { "displayName": "Automobiles", "classification": { "score": 0.10098731 } } ] }
Python
To learn how to install and use the client library for AutoML Natural Language, see AutoML Natural Language client libraries. For more information, see the AutoML Natural Language Python API reference documentation.
To authenticate to AutoML Natural Language, set up Application Default Credentials. For more information, see Set up authentication for a local development environment.
Java
To learn how to install and use the client library for AutoML Natural Language, see AutoML Natural Language client libraries. For more information, see the AutoML Natural Language Java API reference documentation.
To authenticate to AutoML Natural Language, set up Application Default Credentials. For more information, see Set up authentication for a local development environment.
Node.js
To learn how to install and use the client library for AutoML Natural Language, see AutoML Natural Language client libraries. For more information, see the AutoML Natural Language Node.js API reference documentation.
To authenticate to AutoML Natural Language, set up Application Default Credentials. For more information, see Set up authentication for a local development environment.
Go
To learn how to install and use the client library for AutoML Natural Language, see AutoML Natural Language client libraries. For more information, see the AutoML Natural Language Go API reference documentation.
To authenticate to AutoML Natural Language, set up Application Default Credentials. For more information, see Set up authentication for a local development environment.
Additional languages
C#: Please follow the C# setup instructions on the client libraries page and then visit the AutoML Natural Language reference documentation for .NET.
PHP: Please follow the PHP setup instructions on the client libraries page and then visit the AutoML Natural Language reference documentation for PHP.
Ruby: Please follow the Ruby setup instructions on the client libraries page and then visit the AutoML Natural Language reference documentation for Ruby.
Entity extraction
REST
Before using any of the request data, make the following replacements:
- project-id: your project ID
- location-id: the location for the resource,
us-central1
for the Global location oreu
for the European Union - model-id: your model ID
HTTP method and URL:
POST https://automl.googleapis.com/v1/projects/project-id/locations/location-id/models/model-id:predict
Request JSON body:
{ "payload" : { "textSnippet": { "content": "The Wilms tumor-suppressor gene, WT1, plays a key role in urogenital development, and WT1 dysfunction is implicated in both neoplastic and nonneoplastic (glomerulosclerosis) disease. The analysis of diseases linked specifically with WT1 mutations, such as Denys-Drash syndrome (DDS), can provide valuable insight concerning the role of WT1 in development and disease. We report that heterozygosity for a targeted murine Wt1 allele, Wt1 (tmT396), which truncates ZF3 at codon 396, induces mesangial sclerosis characteristic of DDS in adult heterozygous and chimeric mice. Male genital defects also were evident and there was a single case of Wilms tumor in which the transcript of the nontargeted allele showed an exon 9 skipping event, implying a causal link between Wt1 dysfunction and Wilms tumorigenesis in mice. However, the mutant WT1 (tmT396) protein accounted for only 5% of WT1 in both heterozygous embryonic stem cells and the WT. This has implications regarding the mechanism by which the mutant allele exerts its effect.", "mime_type": "text/plain" }, } }
To send your request, expand one of these options:
You should receive a JSON response similar to the following:
{ "annotations": [ { "text_extraction": { "text_segment": { "end_offset": 67, "start_offset": 62 } }, "display_name": "Modifier" }, { "text_extraction": { "text_segment": { "end_offset": 158, "start_offset": 141 } }, "display_name": "SpecificDisease" }, { "text_extraction": { "text_segment": { "end_offset": 330, "start_offset": 290 } }, "display_name": "SpecificDisease" }, { "text_extraction": { "text_segment": { "end_offset": 337, "start_offset": 332 } }, "display_name": "SpecificDisease" }, { "text_extraction": { "text_segment": { "end_offset": 627, "start_offset": 610 } }, "display_name": "Modifier" }, { "text_extraction": { "text_segment": { "end_offset": 754, "start_offset": 749 } }, "display_name": "Modifier" }, { "text_extraction": { "text_segment": { "end_offset": 875, "start_offset": 865 } }, "display_name": "Modifier" }, { "text_extraction": { "text_segment": { "end_offset": 968, "start_offset": 951 } }, "display_name": "Modifier" }, { "text_extraction": { "text_segment": { "end_offset": 1553, "start_offset": 1548 } }, "display_name": "Modifier" }, { "text_extraction": { "text_segment": { "end_offset": 1652, "start_offset": 1606 } }, "display_name": "CompositeMention" }, { "text_extraction": { "text_segment": { "end_offset": 1833, "start_offset": 1826 } }, "display_name": "DiseaseClass" }, { "text_extraction": { "text_segment": { "end_offset": 1860, "start_offset": 1843 } }, "display_name": "SpecificDisease" }, { "text_extraction": { "text_segment": { "end_offset": 1930, "start_offset": 1913 } }, "display_name": "SpecificDisease" }, { "text_extraction": { "text_segment": { "end_offset": 2129, "start_offset": 2111 } }, "display_name": "SpecificDisease" }, { "text_extraction": { "text_segment": { "end_offset": 2188, "start_offset": 2160 } }, "display_name": "SpecificDisease" }, { "text_extraction": { "text_segment": { "end_offset": 2260, "start_offset": 2243 } }, "display_name": "Modifier" }, { "text_extraction": { "text_segment": { "end_offset": 2356, "start_offset": 2339 } }, "display_name": "Modifier" } ], }
Python
To learn how to install and use the client library for AutoML Natural Language, see AutoML Natural Language client libraries. For more information, see the AutoML Natural Language Python API reference documentation.
To authenticate to AutoML Natural Language, set up Application Default Credentials. For more information, see Set up authentication for a local development environment.
Java
To learn how to install and use the client library for AutoML Natural Language, see AutoML Natural Language client libraries. For more information, see the AutoML Natural Language Java API reference documentation.
To authenticate to AutoML Natural Language, set up Application Default Credentials. For more information, see Set up authentication for a local development environment.
Node.js
To learn how to install and use the client library for AutoML Natural Language, see AutoML Natural Language client libraries. For more information, see the AutoML Natural Language Node.js API reference documentation.
To authenticate to AutoML Natural Language, set up Application Default Credentials. For more information, see Set up authentication for a local development environment.
Go
To learn how to install and use the client library for AutoML Natural Language, see AutoML Natural Language client libraries. For more information, see the AutoML Natural Language Go API reference documentation.
To authenticate to AutoML Natural Language, set up Application Default Credentials. For more information, see Set up authentication for a local development environment.
Additional languages
C#: Please follow the C# setup instructions on the client libraries page and then visit the AutoML Natural Language reference documentation for .NET.
PHP: Please follow the PHP setup instructions on the client libraries page and then visit the AutoML Natural Language reference documentation for PHP.
Ruby: Please follow the Ruby setup instructions on the client libraries page and then visit the AutoML Natural Language reference documentation for Ruby.
Sentiment analysis
REST
Before using any of the request data, make the following replacements:
- project-id: your project ID
- location-id: the location for the resource,
us-central1
for the Global location oreu
for the European Union - model-id: your model ID
HTTP method and URL:
POST https://automl.googleapis.com/v1/projects/project-id/locations/location-id/models/model-id:predict
Request JSON body:
{ "payload" : { "textSnippet": { "content": "Enjoy your vacation!", "mime_type": "text/plain" }, } }
To send your request, expand one of these options:
You should receive a successful status code (2xx) and an empty response.
Python
To learn how to install and use the client library for AutoML Natural Language, see AutoML Natural Language client libraries. For more information, see the AutoML Natural Language Python API reference documentation.
To authenticate to AutoML Natural Language, set up Application Default Credentials. For more information, see Set up authentication for a local development environment.
Java
To learn how to install and use the client library for AutoML Natural Language, see AutoML Natural Language client libraries. For more information, see the AutoML Natural Language Java API reference documentation.
To authenticate to AutoML Natural Language, set up Application Default Credentials. For more information, see Set up authentication for a local development environment.
Node.js
To learn how to install and use the client library for AutoML Natural Language, see AutoML Natural Language client libraries. For more information, see the AutoML Natural Language Node.js API reference documentation.
To authenticate to AutoML Natural Language, set up Application Default Credentials. For more information, see Set up authentication for a local development environment.
Go
To learn how to install and use the client library for AutoML Natural Language, see AutoML Natural Language client libraries. For more information, see the AutoML Natural Language Go API reference documentation.
To authenticate to AutoML Natural Language, set up Application Default Credentials. For more information, see Set up authentication for a local development environment.
Additional languages
C#: Please follow the C# setup instructions on the client libraries page and then visit the AutoML Natural Language reference documentation for .NET.
PHP: Please follow the PHP setup instructions on the client libraries page and then visit the AutoML Natural Language reference documentation for PHP.
Ruby: Please follow the Ruby setup instructions on the client libraries page and then visit the AutoML Natural Language reference documentation for Ruby.
Batch prediction
If you would like to use your model to do high-throughput asynchronous
prediction on a corpus of documents you can use the batchPredict
method. The
batch prediction methods require you to specify input and output URIs that
point to locations in Cloud Storage buckets.
The input URI points to a CSV or JSONL file, which specifies the content to analyze. Use a CSV file for classification and sentiment analysis. Use a JSONL file for entity extraction. The output specifies a location where AutoML Natural Language saves results from the batch prediction.
For classification and sentiment analysis, create a CSV file with a single column that lists the input files to classify, one file per row. The CSV file and each input file needs to be stored in your Cloud Storage bucket.
gs://folder/text1.txt
gs://folder/text2.pdf
For entity extraction, you need to prepare a JSONL file that contains all of the content to analyze, either inline or as links to files that are stored in a Cloud Storage bucket. The following example shows inline content that is included in the JSONL file. Each item must include a unique id.
{ "id": "0", "text_snippet": { "content": "First item content to be analyzed." } }
{ "id": "1", "text_snippet": { "content": "Second item content to be analyzed." } }
...
{ "id": "n", "text_snippet": { "content": "Last item content to be analyzed." } }
The following example shows a JSONL file that contains links to input files, which must be in Cloud Storage buckets.
{ "document": { "input_config": { "gcs_source": { "input_uris": [ "gs://folder/document1.pdf" ] } } } }
{ "document": { "input_config": { "gcs_source": { "input_uris": [ "gs://folder/document2.tif" ] } } } }
...
REST
Before using any of the request data, make the following replacements:
- project-id: your project ID
- location-id: the location for the resource,
us-central1
for the Global location oreu
for the European Union - model-id: your model ID
HTTP method and URL:
POST https://automl.googleapis.com/v1/projects/project-id/locations/location-id/models/model-id:batchPredict
Request JSON body:
{ "input_config": { "gcs_source": { "input_uris": [ "csv-file-URI"] } }, "output_config": { "gcs_destination": { "output_uri_prefix": "dest-dir-URI" } } }
To send your request, expand one of these options:
You should see output similar to the following. You can use the operation ID to get the status of the task. For an example, see Getting the status of an operation.
{ "name": "projects/434039606874/locations/us-central1/operations/TCN8195786061721370625", "metadata": { "@type": "type.googleapis.com/google.cloud.automl.v1beta1.OperationMetadata", "createTime": "2019-03-13T15:37:49.972372Z", "updateTime": "2019-03-13T15:37:49.972372Z" } }
Python
To learn how to install and use the client library for AutoML Natural Language, see AutoML Natural Language client libraries. For more information, see the AutoML Natural Language Python API reference documentation.
To authenticate to AutoML Natural Language, set up Application Default Credentials. For more information, see Set up authentication for a local development environment.
Java
To learn how to install and use the client library for AutoML Natural Language, see AutoML Natural Language client libraries. For more information, see the AutoML Natural Language Java API reference documentation.
To authenticate to AutoML Natural Language, set up Application Default Credentials. For more information, see Set up authentication for a local development environment.
Node.js
To learn how to install and use the client library for AutoML Natural Language, see AutoML Natural Language client libraries. For more information, see the AutoML Natural Language Node.js API reference documentation.
To authenticate to AutoML Natural Language, set up Application Default Credentials. For more information, see Set up authentication for a local development environment.
Go
To learn how to install and use the client library for AutoML Natural Language, see AutoML Natural Language client libraries. For more information, see the AutoML Natural Language Go API reference documentation.
To authenticate to AutoML Natural Language, set up Application Default Credentials. For more information, see Set up authentication for a local development environment.
Additional languages
C#: Please follow the C# setup instructions on the client libraries page and then visit the AutoML Natural Language reference documentation for .NET.
PHP: Please follow the PHP setup instructions on the client libraries page and then visit the AutoML Natural Language reference documentation for PHP.
Ruby: Please follow the Ruby setup instructions on the client libraries page and then visit the AutoML Natural Language reference documentation for Ruby.