首先需要获取资源密钥和终结点:
在 Azure 门户中,转到资源概述页面
在左侧菜单中,选择“密钥和终结点”。 你将为 API 请求使用终结点和密钥
提交自定义 NER 任务
使用此 POST 请求启动文本分类任务。
{ENDPOINT}/language/analyze-text/jobs?api-version={API-VERSION}
占位符 |
值 |
示例 |
{ENDPOINT} |
用于对 API 请求进行身份验证的终结点。 |
https://<your-custom-subdomain>.cognitiveservices.azure.com |
{API-VERSION} |
要调用的 API 版本。 此处引用的值适用于最新发布的版本。 请参阅模型生命周期,了解有关其他可用 API 版本的详细信息。 |
2022-05-01 |
键 |
价值 |
Ocp-Apim-Subscription-Key |
你的密钥,用于提供对此 API 的访问权限。 |
Body
{
"displayName": "Extracting entities",
"analysisInput": {
"documents": [
{
"id": "1",
"language": "{LANGUAGE-CODE}",
"text": "Text1"
},
{
"id": "2",
"language": "{LANGUAGE-CODE}",
"text": "Text2"
}
]
},
"tasks": [
{
"kind": "CustomEntityRecognition",
"taskName": "Entity Recognition",
"parameters": {
"projectName": "{PROJECT-NAME}",
"deploymentName": "{DEPLOYMENT-NAME}"
}
}
]
}
键 |
占位符 |
值 |
示例 |
displayName |
{JOB-NAME} |
作业名称。 |
MyJobName |
documents |
[{},{}] |
要对其运行任务的文档列表。 |
[{},{}] |
id |
{DOC-ID} |
文档名称或 ID。 |
doc1 |
language |
{LANGUAGE-CODE} |
指定文档语言代码的字符串。 如果未指定此密钥,该服务将假定在项目创建时选择项目的默认语言。 有关支持语言代码的列表,请参阅语言支持。 |
en-us |
text |
{DOC-TEXT} |
要对其运行任务的文档任务。 |
Lorem ipsum dolor sit amet |
tasks |
|
要执行的任务列表。 |
[] |
taskName |
CustomEntityRecognition |
任务名称 |
CustomEntityRecognition |
parameters |
|
要传递给任务的参数列表。 |
|
project-name |
{PROJECT-NAME} |
项目名称。 此值区分大小写。 |
myProject |
deployment-name |
{DEPLOYMENT-NAME} |
部署的名称。 此值区分大小写。 |
prod |
响应
你将收到 202 响应,它指示任务已成功提交。 在响应头中,提取 operation-location
。
operation-location
的格式如下:
{ENDPOINT}/language/analyze-text/jobs/{JOB-ID}?api-version={API-VERSION}
可以使用此 URL 查询任务完成状态,并在任务完成时获取结果。
获取任务结果
使用以下 GET 请求查询自定义实体识别任务的状态/结果。
{ENDPOINT}/language/analyze-text/jobs/{JOB-ID}?api-version={API-VERSION}
占位符 |
值 |
示例 |
{ENDPOINT} |
用于对 API 请求进行身份验证的终结点。 |
https://<your-custom-subdomain>.cognitiveservices.azure.com |
{API-VERSION} |
要调用的 API 版本。 此处引用的值适用于最新发布的版本。 请参阅模型生命周期,了解有关其他可用 API 版本的详细信息。 |
2022-05-01 |
键 |
价值 |
Ocp-Apim-Subscription-Key |
你的密钥,用于提供对此 API 的访问权限。 |
响应正文
响应将是具有以下参数的 JSON 文档
{
"createdDateTime": "2021-05-19T14:32:25.578Z",
"displayName": "MyJobName",
"expirationDateTime": "2021-05-19T14:32:25.578Z",
"jobId": "xxxx-xxxx-xxxxx-xxxxx",
"lastUpdateDateTime": "2021-05-19T14:32:25.578Z",
"status": "succeeded",
"tasks": {
"completed": 1,
"failed": 0,
"inProgress": 0,
"total": 1,
"items": [
{
"kind": "EntityRecognitionLROResults",
"taskName": "Recognize Entities",
"lastUpdateDateTime": "2020-10-01T15:01:03Z",
"status": "succeeded",
"results": {
"documents": [
{
"entities": [
{
"category": "Event",
"confidenceScore": 0.61,
"length": 4,
"offset": 18,
"text": "trip"
},
{
"category": "Location",
"confidenceScore": 0.82,
"length": 7,
"offset": 26,
"subcategory": "GPE",
"text": "Seattle"
},
{
"category": "DateTime",
"confidenceScore": 0.8,
"length": 9,
"offset": 34,
"subcategory": "DateRange",
"text": "last week"
}
],
"id": "1",
"warnings": []
}
],
"errors": [],
"modelVersion": "2020-04-01"
}
}
]
}
}