Note
Access to this page requires authorization. You can try signing in or changing directories.
Access to this page requires authorization. You can try changing directories.
After you successfully deploy a model, you can query the deployment to classify text based on the model you assigned to the deployment. You can query the deployment programmatically Prediction API or through the client libraries (Azure SDK).
Send a text classification request to your model (REST API)
First you need to get your resource key and endpoint:
Go to your resource overview page in the Azure portal
From the menu on the left side, select Keys and Endpoint. You use the endpoint and key for the API requests
Submit a custom text classification task
Use this POST request to start a text classification task.
{ENDPOINT}/language/analyze-text/jobs?api-version={API-VERSION}
| Placeholder | Value | Example |
|---|---|---|
{ENDPOINT} |
The endpoint for authenticating your API request. | https://<your-custom-subdomain>.cognitiveservices.azure.com |
{API-VERSION} |
The version of the API you're calling. The value referenced is for the latest version released. For more information, see Model lifecycle. | 2022-05-01 |
Headers
| Key | Value |
|---|---|
| Ocp-Apim-Subscription-Key | Your key that provides access to this API. |
Body
{
"displayName": "Classifying documents",
"analysisInput": {
"documents": [
{
"id": "1",
"language": "{LANGUAGE-CODE}",
"text": "Text1"
},
{
"id": "2",
"language": "{LANGUAGE-CODE}",
"text": "Text2"
}
]
},
"tasks": [
{
"kind": "CustomMultiLabelClassification",
"taskName": "Multi Label Classification",
"parameters": {
"projectName": "{PROJECT-NAME}",
"deploymentName": "{DEPLOYMENT-NAME}"
}
}
]
}
| Key | Placeholder | Value | Example |
|---|---|---|---|
displayName |
{JOB-NAME} |
Your job name. | MyJobName |
documents |
[{},{}] | List of documents to run tasks on. | [{},{}] |
id |
{DOC-ID} |
Document name or ID. | doc1 |
language |
{LANGUAGE-CODE} |
A string specifying the language code for the document. If this key isn't specified, the service will assume the default language of the project that was selected during project creation. See language support for a list of supported language codes. | en-us |
text |
{DOC-TEXT} |
Document task to run the tasks on. | Lorem ipsum dolor sit amet |
tasks |
List of tasks we want to perform. | [] |
|
taskName |
CustomMultiLabelClassification | The task name | CustomMultiLabelClassification |
parameters |
List of parameters to pass to the task. | ||
project-name |
{PROJECT-NAME} |
The name for your project. This value is case-sensitive. | myProject |
deployment-name |
{DEPLOYMENT-NAME} |
The name of your deployment. This value is case-sensitive. | prod |
Response
You receive a 202 response indicating success. In the response headers, extract operation-location.
operation-location is formatted like this:
{ENDPOINT}/language/analyze-text/jobs/{JOB-ID}?api-version={API-VERSION}
You can use this URL to query the task completion status and get the results when task is completed.
Get task results (Azure SDK)
Use the following GET request to query the status/results of the text classification task.
{ENDPOINT}/language/analyze-text/jobs/{JOB-ID}?api-version={API-VERSION}
| Placeholder | Value | Example |
|---|---|---|
{ENDPOINT} |
The endpoint for authenticating your API request. | https://<your-custom-subdomain>.cognitiveservices.azure.com |
{API-VERSION} |
The version of the API you're calling. The value referenced is for the latest released model version version. | 2022-05-01 |
Headers
| Key | Value |
|---|---|
| Ocp-Apim-Subscription-Key | Your key that provides access to this API. |
Response body
The response will be a JSON document with the following parameters.
{
"createdDateTime": "2021-05-19T14:32:25.578Z",
"displayName": "MyJobName",
"expirationDateTime": "2021-05-19T14:32:25.578Z",
"jobId": "xxxx-xxxxxx-xxxxx-xxxx",
"lastUpdateDateTime": "2021-05-19T14:32:25.578Z",
"status": "succeeded",
"tasks": {
"completed": 1,
"failed": 0,
"inProgress": 0,
"total": 1,
"items": [
{
"kind": "customMultiClassificationTasks",
"taskName": "Classify documents",
"lastUpdateDateTime": "2020-10-01T15:01:03Z",
"status": "succeeded",
"results": {
"documents": [
{
"id": "{DOC-ID}",
"classes": [
{
"category": "Class_1",
"confidenceScore": 0.0551877357
}
],
"warnings": []
}
],
"errors": [],
"modelVersion": "2020-04-01"
}
}
]
}
}
First you need to get your resource key and endpoint:
Go to your resource overview page in the Azure portal
From the menu on the left side, select Keys and Endpoint. The endpoint and key are used for API requests.
Download and install the client library package for your language of choice:
Language Package version .NET 5.2.0-beta.3 Java 5.2.0-beta.3 JavaScript 6.0.0-beta.1 Python 5.2.0b4 After you install the client library, use the following samples on GitHub to start calling the API.
Single label classification:
Multi label classification:
See the following reference documentation on the client, and return object: