
Communications Mining 用户指南
这是 API 的教程式简介 - 如果您知道自己在寻找什么,请直接跳至参考资料。
All data, individual pieces of which are called messages, are grouped into sources. A source should correspond to the origin of the data, like a single mailbox, or a particular feedback channel. These can be combined for the purposes of a single inference model, so it's better to err on the side of multiple different sources than a single monolith if you're in any doubt.
A dataset is a combination of sources together with the associated label categories. For instance one dataset may be built on a website feedback source, with labels like Ease of Use or Available Information, while a different dataset could base itself on various post-purchase survey response sources and apply completely different labels about Packaging or Speed of Delivery.
因此,在添加任何注释之前,您需要创建一个来源以放入注释。
重击
curl -X PUT 'https://<my_api_endpoint>/api/v1/sources/<project>/example' \
-H "Authorization: Bearer $REINFER_TOKEN" \
-H "Content-Type: application/json" \
-d '{
"source": {
"description": "An optional long form description.",
"title": "An Example Source"
}
}'
curl -X PUT 'https://<my_api_endpoint>/api/v1/sources/<project>/example' \
-H "Authorization: Bearer $REINFER_TOKEN" \
-H "Content-Type: application/json" \
-d '{
"source": {
"description": "An optional long form description.",
"title": "An Example Source"
}
}'
节点
const request = require("request");
request.put(
{
url: "https://<my_api_endpoint>/api/v1/sources/<project>/example",
headers: {
Authorization: "Bearer " + process.env.REINFER_TOKEN,
},
json: true,
body: {
source: {
description: "An optional long form description.",
title: "An Example Source",
},
},
},
function (error, response, json) {
// digest response
console.log(JSON.stringify(json, null, 2));
}
);
const request = require("request");
request.put(
{
url: "https://<my_api_endpoint>/api/v1/sources/<project>/example",
headers: {
Authorization: "Bearer " + process.env.REINFER_TOKEN,
},
json: true,
body: {
source: {
description: "An optional long form description.",
title: "An Example Source",
},
},
},
function (error, response, json) {
// digest response
console.log(JSON.stringify(json, null, 2));
}
);
Python
import json
import os
import requests
response = requests.put(
"https://<my_api_endpoint>/api/v1/sources/<project>/example",
headers={"Authorization": "Bearer " + os.environ["REINFER_TOKEN"]},
json={
"source": {
"title": "An Example Source",
"description": "An optional long form description.",
}
},
)
print(json.dumps(response.json(), indent=2, sort_keys=True))
import json
import os
import requests
response = requests.put(
"https://<my_api_endpoint>/api/v1/sources/<project>/example",
headers={"Authorization": "Bearer " + os.environ["REINFER_TOKEN"]},
json={
"source": {
"title": "An Example Source",
"description": "An optional long form description.",
}
},
)
print(json.dumps(response.json(), indent=2, sort_keys=True))
响应
{
"source": {
"created_at": "2018-10-16T10:43:56.463000Z",
"description": "An optional long form description.",
"id": "22f0f76e82fd8867",
"language": "en",
"last_modified": "2018-10-16T10:43:56.463000Z",
"name": "example",
"owner": "<project>",
"sensitive_properties": [],
"should_translate": false,
"title": "An Example Source",
"updated_at": "2018-10-16T10:43:56.463000Z"
},
"status": "ok"
}
{
"source": {
"created_at": "2018-10-16T10:43:56.463000Z",
"description": "An optional long form description.",
"id": "22f0f76e82fd8867",
"language": "en",
"last_modified": "2018-10-16T10:43:56.463000Z",
"name": "example",
"owner": "<project>",
"sensitive_properties": [],
"should_translate": false,
"title": "An Example Source",
"updated_at": "2018-10-16T10:43:56.463000Z"
},
"status": "ok"
}
To create a source you need the following:
- A project - An existing project you are a part of.
- A name - Alphanumeric characters, hyphens and underscores are all OK (e.g. 'post-purchase').
- A title - A short human-readable title for your source to display in the user interface, for example, Post Purchase Survey Responses.
- A description - Optionally, a longer form description of the source to show on the sources overview page.
The first two form the fully qualified name of your source, which is used to refer to it programatically. The latter two are meant for human consumption in the user interface.
Proceed with creating an example source.
Check out your sources page, then come back.
让我们以编程方式检索源页面上可用的相同信息,以及所有源的所有元数据。 您应该会看到来源。
重击
curl -X GET 'https://<my_api_endpoint>/api/v1/sources' \
-H "Authorization: Bearer $REINFER_TOKEN"
curl -X GET 'https://<my_api_endpoint>/api/v1/sources' \
-H "Authorization: Bearer $REINFER_TOKEN"
节点
const request = require("request");
request.get(
{
url: "https://<my_api_endpoint>/api/v1/sources",
headers: {
Authorization: "Bearer " + process.env.REINFER_TOKEN,
},
},
function (error, response, json) {
// digest response
console.log(JSON.stringify(json, null, 2));
}
);
const request = require("request");
request.get(
{
url: "https://<my_api_endpoint>/api/v1/sources",
headers: {
Authorization: "Bearer " + process.env.REINFER_TOKEN,
},
},
function (error, response, json) {
// digest response
console.log(JSON.stringify(json, null, 2));
}
);
Python
import json
import os
import requests
response = requests.get(
"https://<my_api_endpoint>/api/v1/sources",
headers={"Authorization": "Bearer " + os.environ["REINFER_TOKEN"]},
)
print(json.dumps(response.json(), indent=2, sort_keys=True))
import json
import os
import requests
response = requests.get(
"https://<my_api_endpoint>/api/v1/sources",
headers={"Authorization": "Bearer " + os.environ["REINFER_TOKEN"]},
)
print(json.dumps(response.json(), indent=2, sort_keys=True))
响应
{
"sources": [
{
"created_at": "2018-10-16T10:43:56.463000Z",
"description": "An optional long form description.",
"id": "22f0f76e82fd8867",
"language": "en",
"last_modified": "2018-10-16T10:43:56.463000Z",
"name": "example",
"owner": "<project>",
"sensitive_properties": [],
"should_translate": false,
"title": "An Example Source",
"updated_at": "2018-10-16T10:43:56.463000Z"
}
],
"status": "ok"
}
{
"sources": [
{
"created_at": "2018-10-16T10:43:56.463000Z",
"description": "An optional long form description.",
"id": "22f0f76e82fd8867",
"language": "en",
"last_modified": "2018-10-16T10:43:56.463000Z",
"name": "example",
"owner": "<project>",
"sensitive_properties": [],
"should_translate": false,
"title": "An Example Source",
"updated_at": "2018-10-16T10:43:56.463000Z"
}
],
"status": "ok"
}
如果您只需要属于特定项目的来源,则可以将其名称添加到端点。
删除来源将无法恢复地破坏所有消息以及与其关联的任何其他信息。 使用此来源的任何数据集也将丢失已添加到此来源中消息的任何标签提供的训练数据,因此应谨慎使用此端点。 也就是说,删除我们在上一节中为您的项目创建的来源应该是安全的。
重击
curl -X DELETE 'https://<my_api_endpoint>/api/v1/sources/id:22f0f76e82fd8867' \
-H "Authorization: Bearer $REINFER_TOKEN"
curl -X DELETE 'https://<my_api_endpoint>/api/v1/sources/id:22f0f76e82fd8867' \
-H "Authorization: Bearer $REINFER_TOKEN"
节点
const request = require("request");
request.delete(
{
url: "https://<my_api_endpoint>/api/v1/sources/id:22f0f76e82fd8867",
headers: {
Authorization: "Bearer " + process.env.REINFER_TOKEN,
},
},
function (error, response, json) {
// digest response
console.log(JSON.stringify(json, null, 2));
}
);
const request = require("request");
request.delete(
{
url: "https://<my_api_endpoint>/api/v1/sources/id:22f0f76e82fd8867",
headers: {
Authorization: "Bearer " + process.env.REINFER_TOKEN,
},
},
function (error, response, json) {
// digest response
console.log(JSON.stringify(json, null, 2));
}
);
Python
import json
import os
import requests
response = requests.delete(
"https://<my_api_endpoint>/api/v1/sources/id:22f0f76e82fd8867",
headers={"Authorization": "Bearer " + os.environ["REINFER_TOKEN"]},
)
print(json.dumps(response.json(), indent=2, sort_keys=True))
import json
import os
import requests
response = requests.delete(
"https://<my_api_endpoint>/api/v1/sources/id:22f0f76e82fd8867",
headers={"Authorization": "Bearer " + os.environ["REINFER_TOKEN"]},
)
print(json.dumps(response.json(), indent=2, sort_keys=True))
响应
{
"status": "ok"
}
{
"status": "ok"
}
{"status": "ok"}
。 为确保该问题已消失,您可以再次请求所有来源。
重击
curl -X GET 'https://<my_api_endpoint>/api/v1/sources' \
-H "Authorization: Bearer $REINFER_TOKEN"
curl -X GET 'https://<my_api_endpoint>/api/v1/sources' \
-H "Authorization: Bearer $REINFER_TOKEN"
节点
const request = require("request");
request.get(
{
url: "https://<my_api_endpoint>/api/v1/sources",
headers: {
Authorization: "Bearer " + process.env.REINFER_TOKEN,
},
},
function (error, response, json) {
// digest response
console.log(JSON.stringify(json, null, 2));
}
);
const request = require("request");
request.get(
{
url: "https://<my_api_endpoint>/api/v1/sources",
headers: {
Authorization: "Bearer " + process.env.REINFER_TOKEN,
},
},
function (error, response, json) {
// digest response
console.log(JSON.stringify(json, null, 2));
}
);
Python
import json
import os
import requests
response = requests.get(
"https://<my_api_endpoint>/api/v1/sources",
headers={"Authorization": "Bearer " + os.environ["REINFER_TOKEN"]},
)
print(json.dumps(response.json(), indent=2, sort_keys=True))
import json
import os
import requests
response = requests.get(
"https://<my_api_endpoint>/api/v1/sources",
headers={"Authorization": "Bearer " + os.environ["REINFER_TOKEN"]},
)
print(json.dumps(response.json(), indent=2, sort_keys=True))
响应
{
"sources": [],
"status": "ok"
}
{
"sources": [],
"status": "ok"
}
Sources would be useless without the comments that go in them. A comment in Communications Mining™ is either an individual piece of text, or multiple text items that are combined into a conversation. Examples of the former include survey responses, support tickets, and customer reviews, while examples of the latter include email chains.
We will add a couple of comments to the example source created in the previous section:
添加电子邮件
重击
curl -X POST 'https://<my_api_endpoint>/api/v1/sources/<project>/example/sync' \
-H "Authorization: Bearer $REINFER_TOKEN" \
-H "Content-Type: application/json" \
-d '{
"comments": [
{
"id": "0123456789abcdef",
"messages": [
{
"body": {
"text": "Hi Bob,\n\nCould you send me today'"'"'s figures?\n\nThanks,\nAlice"
},
"from": "alice@company.com",
"sent_at": "2011-12-11T11:02:03.000000+00:00",
"to": [
"bob@organisation.org"
]
},
{
"body": {
"text": "Alice,\n\nHere are the figures for today.\n\nRegards,\nBob"
},
"from": "bob@organisation.org",
"sent_at": "2011-12-11T11:05:10.000000+00:00",
"to": [
"alice@company.com"
]
},
{
"body": {
"text": "Hi Bob,\n\nI think these are the wrong numbers - could you check?\n\nThanks again,\nAlice"
},
"from": "alice@company.com",
"sent_at": "2011-12-11T11:18:43.000000+00:00",
"to": [
"bob@organisation.org"
]
}
],
"timestamp": "2011-12-11T01:02:03.000000+00:00"
},
{
"id": "abcdef0123456789",
"messages": [
{
"body": {
"text": "All,\n\nJust to let you know that processing is running late today.\n\nRegards,\nBob"
},
"from": "bob@organisation.org",
"sent_at": "2011-12-12T10:04:30.000000+00:00",
"to": [
"alice@company.com",
"carol@company.com"
]
},
{
"body": {
"text": "Hi Bob,\n\nCould you estimate when you'"'"'ll be finished?\n\nThanks,\nCarol"
},
"from": "carol@company.com",
"sent_at": "2011-12-12T10:06:22.000000+00:00",
"to": [
"alice@company.com",
"bob@organisation.org"
]
},
{
"body": {
"text": "Carol,\n\nWe should be done by 12pm. Sorry about the delay.\n\nBest,\nBob"
},
"from": "bob@organisation.org",
"sent_at": "2011-12-11T10:09:40.000000+00:00",
"to": [
"alice@company.com",
"carol@company.com"
]
}
],
"timestamp": "2011-12-11T02:03:04.000000+00:00",
"user_properties": {
"number:severity": 3,
"string:Recipient Domain": "company.com",
"string:Sender Domain": "organisation.org"
}
}
]
}'
curl -X POST 'https://<my_api_endpoint>/api/v1/sources/<project>/example/sync' \
-H "Authorization: Bearer $REINFER_TOKEN" \
-H "Content-Type: application/json" \
-d '{
"comments": [
{
"id": "0123456789abcdef",
"messages": [
{
"body": {
"text": "Hi Bob,\n\nCould you send me today'"'"'s figures?\n\nThanks,\nAlice"
},
"from": "alice@company.com",
"sent_at": "2011-12-11T11:02:03.000000+00:00",
"to": [
"bob@organisation.org"
]
},
{
"body": {
"text": "Alice,\n\nHere are the figures for today.\n\nRegards,\nBob"
},
"from": "bob@organisation.org",
"sent_at": "2011-12-11T11:05:10.000000+00:00",
"to": [
"alice@company.com"
]
},
{
"body": {
"text": "Hi Bob,\n\nI think these are the wrong numbers - could you check?\n\nThanks again,\nAlice"
},
"from": "alice@company.com",
"sent_at": "2011-12-11T11:18:43.000000+00:00",
"to": [
"bob@organisation.org"
]
}
],
"timestamp": "2011-12-11T01:02:03.000000+00:00"
},
{
"id": "abcdef0123456789",
"messages": [
{
"body": {
"text": "All,\n\nJust to let you know that processing is running late today.\n\nRegards,\nBob"
},
"from": "bob@organisation.org",
"sent_at": "2011-12-12T10:04:30.000000+00:00",
"to": [
"alice@company.com",
"carol@company.com"
]
},
{
"body": {
"text": "Hi Bob,\n\nCould you estimate when you'"'"'ll be finished?\n\nThanks,\nCarol"
},
"from": "carol@company.com",
"sent_at": "2011-12-12T10:06:22.000000+00:00",
"to": [
"alice@company.com",
"bob@organisation.org"
]
},
{
"body": {
"text": "Carol,\n\nWe should be done by 12pm. Sorry about the delay.\n\nBest,\nBob"
},
"from": "bob@organisation.org",
"sent_at": "2011-12-11T10:09:40.000000+00:00",
"to": [
"alice@company.com",
"carol@company.com"
]
}
],
"timestamp": "2011-12-11T02:03:04.000000+00:00",
"user_properties": {
"number:severity": 3,
"string:Recipient Domain": "company.com",
"string:Sender Domain": "organisation.org"
}
}
]
}'
节点
const request = require("request");
request.post(
{
url: "https://<my_api_endpoint>/api/v1/sources/<project>/example/sync",
headers: {
Authorization: "Bearer " + process.env.REINFER_TOKEN,
},
json: true,
body: {
comments: [
{
id: "0123456789abcdef",
messages: [
{
body: {
text: "Hi Bob,\n\nCould you send me today's figures?\n\nThanks,\nAlice",
},
from: "alice@company.com",
sent_at: "2011-12-11T11:02:03.000000+00:00",
to: ["bob@organisation.org"],
},
{
body: {
text: "Alice,\n\nHere are the figures for today.\n\nRegards,\nBob",
},
from: "bob@organisation.org",
sent_at: "2011-12-11T11:05:10.000000+00:00",
to: ["alice@company.com"],
},
{
body: {
text: "Hi Bob,\n\nI think these are the wrong numbers - could you check?\n\nThanks again,\nAlice",
},
from: "alice@company.com",
sent_at: "2011-12-11T11:18:43.000000+00:00",
to: ["bob@organisation.org"],
},
],
timestamp: "2011-12-11T01:02:03.000000+00:00",
},
{
id: "abcdef0123456789",
messages: [
{
body: {
text: "All,\n\nJust to let you know that processing is running late today.\n\nRegards,\nBob",
},
from: "bob@organisation.org",
sent_at: "2011-12-12T10:04:30.000000+00:00",
to: ["alice@company.com", "carol@company.com"],
},
{
body: {
text: "Hi Bob,\n\nCould you estimate when you'll be finished?\n\nThanks,\nCarol",
},
from: "carol@company.com",
sent_at: "2011-12-12T10:06:22.000000+00:00",
to: ["alice@company.com", "bob@organisation.org"],
},
{
body: {
text: "Carol,\n\nWe should be done by 12pm. Sorry about the delay.\n\nBest,\nBob",
},
from: "bob@organisation.org",
sent_at: "2011-12-11T10:09:40.000000+00:00",
to: ["alice@company.com", "carol@company.com"],
},
],
timestamp: "2011-12-11T02:03:04.000000+00:00",
user_properties: {
"number:severity": 3,
"string:Recipient Domain": "company.com",
"string:Sender Domain": "organisation.org",
},
},
],
},
},
function (error, response, json) {
// digest response
console.log(JSON.stringify(json, null, 2));
}
);
const request = require("request");
request.post(
{
url: "https://<my_api_endpoint>/api/v1/sources/<project>/example/sync",
headers: {
Authorization: "Bearer " + process.env.REINFER_TOKEN,
},
json: true,
body: {
comments: [
{
id: "0123456789abcdef",
messages: [
{
body: {
text: "Hi Bob,\n\nCould you send me today's figures?\n\nThanks,\nAlice",
},
from: "alice@company.com",
sent_at: "2011-12-11T11:02:03.000000+00:00",
to: ["bob@organisation.org"],
},
{
body: {
text: "Alice,\n\nHere are the figures for today.\n\nRegards,\nBob",
},
from: "bob@organisation.org",
sent_at: "2011-12-11T11:05:10.000000+00:00",
to: ["alice@company.com"],
},
{
body: {
text: "Hi Bob,\n\nI think these are the wrong numbers - could you check?\n\nThanks again,\nAlice",
},
from: "alice@company.com",
sent_at: "2011-12-11T11:18:43.000000+00:00",
to: ["bob@organisation.org"],
},
],
timestamp: "2011-12-11T01:02:03.000000+00:00",
},
{
id: "abcdef0123456789",
messages: [
{
body: {
text: "All,\n\nJust to let you know that processing is running late today.\n\nRegards,\nBob",
},
from: "bob@organisation.org",
sent_at: "2011-12-12T10:04:30.000000+00:00",
to: ["alice@company.com", "carol@company.com"],
},
{
body: {
text: "Hi Bob,\n\nCould you estimate when you'll be finished?\n\nThanks,\nCarol",
},
from: "carol@company.com",
sent_at: "2011-12-12T10:06:22.000000+00:00",
to: ["alice@company.com", "bob@organisation.org"],
},
{
body: {
text: "Carol,\n\nWe should be done by 12pm. Sorry about the delay.\n\nBest,\nBob",
},
from: "bob@organisation.org",
sent_at: "2011-12-11T10:09:40.000000+00:00",
to: ["alice@company.com", "carol@company.com"],
},
],
timestamp: "2011-12-11T02:03:04.000000+00:00",
user_properties: {
"number:severity": 3,
"string:Recipient Domain": "company.com",
"string:Sender Domain": "organisation.org",
},
},
],
},
},
function (error, response, json) {
// digest response
console.log(JSON.stringify(json, null, 2));
}
);
Python
import json
import os
import requests
response = requests.post(
"https://<my_api_endpoint>/api/v1/sources/<project>/example/sync",
headers={"Authorization": "Bearer " + os.environ["REINFER_TOKEN"]},
json={
"comments": [
{
"id": "0123456789abcdef",
"timestamp": "2011-12-11T01:02:03.000000+00:00",
"messages": [
{
"from": "alice@company.com",
"to": ["bob@organisation.org"],
"sent_at": "2011-12-11T11:02:03.000000+00:00",
"body": {
"text": "Hi Bob,\n\nCould you send me today's figures?\n\nThanks,\nAlice"
},
},
{
"from": "bob@organisation.org",
"to": ["alice@company.com"],
"sent_at": "2011-12-11T11:05:10.000000+00:00",
"body": {
"text": "Alice,\n\nHere are the figures for today.\n\nRegards,\nBob"
},
},
{
"from": "alice@company.com",
"to": ["bob@organisation.org"],
"sent_at": "2011-12-11T11:18:43.000000+00:00",
"body": {
"text": "Hi Bob,\n\nI think these are the wrong numbers - could you check?\n\nThanks again,\nAlice"
},
},
],
},
{
"id": "abcdef0123456789",
"timestamp": "2011-12-11T02:03:04.000000+00:00",
"messages": [
{
"from": "bob@organisation.org",
"to": ["alice@company.com", "carol@company.com"],
"sent_at": "2011-12-12T10:04:30.000000+00:00",
"body": {
"text": "All,\n\nJust to let you know that processing is running late today.\n\nRegards,\nBob"
},
},
{
"from": "carol@company.com",
"to": ["alice@company.com", "bob@organisation.org"],
"sent_at": "2011-12-12T10:06:22.000000+00:00",
"body": {
"text": "Hi Bob,\n\nCould you estimate when you'll be finished?\n\nThanks,\nCarol"
},
},
{
"from": "bob@organisation.org",
"to": ["alice@company.com", "carol@company.com"],
"sent_at": "2011-12-11T10:09:40.000000+00:00",
"body": {
"text": "Carol,\n\nWe should be done by 12pm. Sorry about the delay.\n\nBest,\nBob"
},
},
],
"user_properties": {
"string:Sender Domain": "organisation.org",
"string:Recipient Domain": "company.com",
"number:severity": 3,
},
},
]
},
)
print(json.dumps(response.json(), indent=2, sort_keys=True))
import json
import os
import requests
response = requests.post(
"https://<my_api_endpoint>/api/v1/sources/<project>/example/sync",
headers={"Authorization": "Bearer " + os.environ["REINFER_TOKEN"]},
json={
"comments": [
{
"id": "0123456789abcdef",
"timestamp": "2011-12-11T01:02:03.000000+00:00",
"messages": [
{
"from": "alice@company.com",
"to": ["bob@organisation.org"],
"sent_at": "2011-12-11T11:02:03.000000+00:00",
"body": {
"text": "Hi Bob,\n\nCould you send me today's figures?\n\nThanks,\nAlice"
},
},
{
"from": "bob@organisation.org",
"to": ["alice@company.com"],
"sent_at": "2011-12-11T11:05:10.000000+00:00",
"body": {
"text": "Alice,\n\nHere are the figures for today.\n\nRegards,\nBob"
},
},
{
"from": "alice@company.com",
"to": ["bob@organisation.org"],
"sent_at": "2011-12-11T11:18:43.000000+00:00",
"body": {
"text": "Hi Bob,\n\nI think these are the wrong numbers - could you check?\n\nThanks again,\nAlice"
},
},
],
},
{
"id": "abcdef0123456789",
"timestamp": "2011-12-11T02:03:04.000000+00:00",
"messages": [
{
"from": "bob@organisation.org",
"to": ["alice@company.com", "carol@company.com"],
"sent_at": "2011-12-12T10:04:30.000000+00:00",
"body": {
"text": "All,\n\nJust to let you know that processing is running late today.\n\nRegards,\nBob"
},
},
{
"from": "carol@company.com",
"to": ["alice@company.com", "bob@organisation.org"],
"sent_at": "2011-12-12T10:06:22.000000+00:00",
"body": {
"text": "Hi Bob,\n\nCould you estimate when you'll be finished?\n\nThanks,\nCarol"
},
},
{
"from": "bob@organisation.org",
"to": ["alice@company.com", "carol@company.com"],
"sent_at": "2011-12-11T10:09:40.000000+00:00",
"body": {
"text": "Carol,\n\nWe should be done by 12pm. Sorry about the delay.\n\nBest,\nBob"
},
},
],
"user_properties": {
"string:Sender Domain": "organisation.org",
"string:Recipient Domain": "company.com",
"number:severity": 3,
},
},
]
},
)
print(json.dumps(response.json(), indent=2, sort_keys=True))
响应
null
null
此示例显示如何添加包含多条消息的注释。 这通常用于添加电子邮件。
id
, timestamp
, and messages.body.text
. You can learn more about available fields in the Comment Reference.
user_properties
字段中。
The timestamp should be in UTC and refer to the time when the comment was recorded, for example, the survey was responded to, not the current time.
响应应确认已创建两个新注释。
添加单消息注释
重击
curl -X POST 'https://<my_api_endpoint>/api/v1/sources/<project>/example/sync' \
-H "Authorization: Bearer $REINFER_TOKEN" \
-H "Content-Type: application/json" \
-d '{
"comments": [
{
"id": "fedcba098765",
"messages": [
{
"body": {
"text": "I was impressed with the speed of your service, but the price is quite high.",
"translated_from": "J'"'"'ai \u00e9t\u00e9 impressionn\u00e9 par la rapidit\u00e9 de votre service, mais le prix est assez \u00e9lev\u00e9."
},
"language": "fr"
}
],
"timestamp": "2011-12-12T20:00:00.000000+00:00"
}
]
}'
curl -X POST 'https://<my_api_endpoint>/api/v1/sources/<project>/example/sync' \
-H "Authorization: Bearer $REINFER_TOKEN" \
-H "Content-Type: application/json" \
-d '{
"comments": [
{
"id": "fedcba098765",
"messages": [
{
"body": {
"text": "I was impressed with the speed of your service, but the price is quite high.",
"translated_from": "J'"'"'ai \u00e9t\u00e9 impressionn\u00e9 par la rapidit\u00e9 de votre service, mais le prix est assez \u00e9lev\u00e9."
},
"language": "fr"
}
],
"timestamp": "2011-12-12T20:00:00.000000+00:00"
}
]
}'
节点
const request = require("request");
request.post(
{
url: "https://<my_api_endpoint>/api/v1/sources/<project>/example/sync",
headers: {
Authorization: "Bearer " + process.env.REINFER_TOKEN,
},
json: true,
body: {
comments: [
{
id: "fedcba098765",
messages: [
{
body: {
text: "I was impressed with the speed of your service, but the price is quite high.",
translated_from:
"J'ai \u00e9t\u00e9 impressionn\u00e9 par la rapidit\u00e9 de votre service, mais le prix est assez \u00e9lev\u00e9.",
},
language: "fr",
},
],
timestamp: "2011-12-12T20:00:00.000000+00:00",
},
],
},
},
function (error, response, json) {
// digest response
console.log(JSON.stringify(json, null, 2));
}
);
const request = require("request");
request.post(
{
url: "https://<my_api_endpoint>/api/v1/sources/<project>/example/sync",
headers: {
Authorization: "Bearer " + process.env.REINFER_TOKEN,
},
json: true,
body: {
comments: [
{
id: "fedcba098765",
messages: [
{
body: {
text: "I was impressed with the speed of your service, but the price is quite high.",
translated_from:
"J'ai \u00e9t\u00e9 impressionn\u00e9 par la rapidit\u00e9 de votre service, mais le prix est assez \u00e9lev\u00e9.",
},
language: "fr",
},
],
timestamp: "2011-12-12T20:00:00.000000+00:00",
},
],
},
},
function (error, response, json) {
// digest response
console.log(JSON.stringify(json, null, 2));
}
);
Python
import json
import os
import requests
response = requests.post(
"https://<my_api_endpoint>/api/v1/sources/<project>/example/sync",
headers={"Authorization": "Bearer " + os.environ["REINFER_TOKEN"]},
json={
"comments": [
{
"id": "fedcba098765",
"timestamp": "2011-12-12T20:00:00.000000+00:00",
"messages": [
{
"language": "fr",
"body": {
"text": "I was impressed with the speed of your service, but the price is quite high.",
"translated_from": "J'ai été impressionné par la rapidité de votre service, mais le prix est assez élevé.",
},
}
],
}
]
},
)
print(json.dumps(response.json(), indent=2, sort_keys=True))
import json
import os
import requests
response = requests.post(
"https://<my_api_endpoint>/api/v1/sources/<project>/example/sync",
headers={"Authorization": "Bearer " + os.environ["REINFER_TOKEN"]},
json={
"comments": [
{
"id": "fedcba098765",
"timestamp": "2011-12-12T20:00:00.000000+00:00",
"messages": [
{
"language": "fr",
"body": {
"text": "I was impressed with the speed of your service, but the price is quite high.",
"translated_from": "J'ai été impressionné par la rapidité de votre service, mais le prix est assez élevé.",
},
}
],
}
]
},
)
print(json.dumps(response.json(), indent=2, sort_keys=True))
响应
{
"new": 1,
"status": "ok",
"unchanged": 0,
"updated": 0
}
{
"new": 1,
"status": "ok",
"unchanged": 0,
"updated": 0
}
This example shows how to add a comment that contains a single message. This format can suit data such as survey responses, customer reviews, and so on.
The required and available fields are same as in the emails example, with the only difference that the Messages field should contain a single entry. You can skip email-specific fields that do not fit your data, as they are not required.
响应应确认已创建一个新注释。
添加后,即可通过其 ID 检索注释。您应该会注意到上一部分中添加的注释。
重击
curl -X GET 'https://<my_api_endpoint>/api/v1/sources/<project>/example/comments/0123456789abcdef' \
-H "Authorization: Bearer $REINFER_TOKEN"
curl -X GET 'https://<my_api_endpoint>/api/v1/sources/<project>/example/comments/0123456789abcdef' \
-H "Authorization: Bearer $REINFER_TOKEN"
节点
const request = require("request");
request.get(
{
url: "https://<my_api_endpoint>/api/v1/sources/<project>/example/comments/0123456789abcdef",
headers: {
Authorization: "Bearer " + process.env.REINFER_TOKEN,
},
},
function (error, response, json) {
// digest response
console.log(JSON.stringify(json, null, 2));
}
);
const request = require("request");
request.get(
{
url: "https://<my_api_endpoint>/api/v1/sources/<project>/example/comments/0123456789abcdef",
headers: {
Authorization: "Bearer " + process.env.REINFER_TOKEN,
},
},
function (error, response, json) {
// digest response
console.log(JSON.stringify(json, null, 2));
}
);
Python
import json
import os
import requests
response = requests.get(
"https://<my_api_endpoint>/api/v1/sources/<project>/example/comments/0123456789abcdef",
headers={"Authorization": "Bearer " + os.environ["REINFER_TOKEN"]},
)
print(json.dumps(response.json(), indent=2, sort_keys=True))
import json
import os
import requests
response = requests.get(
"https://<my_api_endpoint>/api/v1/sources/<project>/example/comments/0123456789abcdef",
headers={"Authorization": "Bearer " + os.environ["REINFER_TOKEN"]},
)
print(json.dumps(response.json(), indent=2, sort_keys=True))
响应
{
"comment": {
"context": "0",
"id": "0123456789abcdef",
"last_modified": "2018-10-16T10:51:46.247000Z",
"messages": [
{
"body": {
"text": "Hi Bob,\n\nCould you send me today's figures?\n\nThanks,\nAlice"
},
"from": "alice@company.com",
"sent_at": "2011-12-11T11:02:03.000000+00:00",
"to": ["bob@organisation.org"]
},
{
"body": {
"text": "Alice,\n\nHere are the figures for today.\n\nRegards,\nBob"
},
"from": "bob@organisation.org",
"sent_at": "2011-12-11T11:05:10.000000+00:00",
"to": ["alice@company.com"]
},
{
"body": {
"text": "Hi Bob,\n\nI think these are the wrong numbers - could you check?\n\nThanks again,\nAlice"
},
"from": "alice@company.com",
"sent_at": "2011-12-11T11:18:43.000000+00:00",
"to": ["bob@organisation.org"]
}
],
"source_id": "22f0f76e82fd8867",
"text_format": "plain",
"timestamp": "2011-12-11T01:02:03Z",
"uid": "22f0f76e82fd8867.0123456789abcdef",
"user_properties": {}
},
"status": "ok"
}
{
"comment": {
"context": "0",
"id": "0123456789abcdef",
"last_modified": "2018-10-16T10:51:46.247000Z",
"messages": [
{
"body": {
"text": "Hi Bob,\n\nCould you send me today's figures?\n\nThanks,\nAlice"
},
"from": "alice@company.com",
"sent_at": "2011-12-11T11:02:03.000000+00:00",
"to": ["bob@organisation.org"]
},
{
"body": {
"text": "Alice,\n\nHere are the figures for today.\n\nRegards,\nBob"
},
"from": "bob@organisation.org",
"sent_at": "2011-12-11T11:05:10.000000+00:00",
"to": ["alice@company.com"]
},
{
"body": {
"text": "Hi Bob,\n\nI think these are the wrong numbers - could you check?\n\nThanks again,\nAlice"
},
"from": "alice@company.com",
"sent_at": "2011-12-11T11:18:43.000000+00:00",
"to": ["bob@organisation.org"]
}
],
"source_id": "22f0f76e82fd8867",
"text_format": "plain",
"timestamp": "2011-12-11T01:02:03Z",
"uid": "22f0f76e82fd8867.0123456789abcdef",
"user_properties": {}
},
"status": "ok"
}
Having successfully added some raw data to Communications Mining™, we can now start to add datasets. A dataset corresponds to a taxonomy of labels along with the training data supplied by applying those labels to the messages in a series of selected sources. You can create many datasets which refer to the same source without the act of labeling messages using the taxonomy of one dataset having any impact on the other datasets, or the underlying sources, allowing different teams to use Communications Mining to gather insights independently.
重击
curl -X PUT 'https://<my_api_endpoint>/api/v1/datasets/<project>/my-dataset' \
-H "Authorization: Bearer $REINFER_TOKEN" \
-H "Content-Type: application/json" \
-d '{
"dataset": {
"description": "An optional long form description.",
"source_ids": [
"22f0f76e82fd8867"
],
"title": "An Example Dataset"
}
}'
curl -X PUT 'https://<my_api_endpoint>/api/v1/datasets/<project>/my-dataset' \
-H "Authorization: Bearer $REINFER_TOKEN" \
-H "Content-Type: application/json" \
-d '{
"dataset": {
"description": "An optional long form description.",
"source_ids": [
"22f0f76e82fd8867"
],
"title": "An Example Dataset"
}
}'
节点
const request = require("request");
request.put(
{
url: "https://<my_api_endpoint>/api/v1/datasets/<project>/my-dataset",
headers: {
Authorization: "Bearer " + process.env.REINFER_TOKEN,
},
json: true,
body: {
dataset: {
description: "An optional long form description.",
source_ids: ["22f0f76e82fd8867"],
title: "An Example Dataset",
},
},
},
function (error, response, json) {
// digest response
console.log(JSON.stringify(json, null, 2));
}
);
const request = require("request");
request.put(
{
url: "https://<my_api_endpoint>/api/v1/datasets/<project>/my-dataset",
headers: {
Authorization: "Bearer " + process.env.REINFER_TOKEN,
},
json: true,
body: {
dataset: {
description: "An optional long form description.",
source_ids: ["22f0f76e82fd8867"],
title: "An Example Dataset",
},
},
},
function (error, response, json) {
// digest response
console.log(JSON.stringify(json, null, 2));
}
);
Python
import json
import os
import requests
response = requests.put(
"https://<my_api_endpoint>/api/v1/datasets/<project>/my-dataset",
headers={"Authorization": "Bearer " + os.environ["REINFER_TOKEN"]},
json={
"dataset": {
"title": "An Example Dataset",
"description": "An optional long form description.",
"source_ids": ["22f0f76e82fd8867"],
}
},
)
print(json.dumps(response.json(), indent=2, sort_keys=True))
import json
import os
import requests
response = requests.put(
"https://<my_api_endpoint>/api/v1/datasets/<project>/my-dataset",
headers={"Authorization": "Bearer " + os.environ["REINFER_TOKEN"]},
json={
"dataset": {
"title": "An Example Dataset",
"description": "An optional long form description.",
"source_ids": ["22f0f76e82fd8867"],
}
},
)
print(json.dumps(response.json(), indent=2, sort_keys=True))
响应
{
"dataset": {
"created": "2018-10-16T10:57:44.667000Z",
"description": "An optional long form description.",
"has_sentiment": true,
"id": "b2ad67f9dfd2e76b",
"last_modified": "2018-10-16T10:57:44.667000Z",
"limited_access": false,
"model_family": "english",
"name": "my-dataset",
"owner": "<project>",
"source_ids": ["22f0f76e82fd8867"],
"title": "An Example Dataset"
},
"status": "ok"
}
{
"dataset": {
"created": "2018-10-16T10:57:44.667000Z",
"description": "An optional long form description.",
"has_sentiment": true,
"id": "b2ad67f9dfd2e76b",
"last_modified": "2018-10-16T10:57:44.667000Z",
"limited_access": false,
"model_family": "english",
"name": "my-dataset",
"owner": "<project>",
"source_ids": ["22f0f76e82fd8867"],
"title": "An Example Dataset"
},
"status": "ok"
}
创建来源后,拥有适当权限的用户还可以在用户界面中创建数据集,这可能会更方便。
重击
curl -X GET 'https://<my_api_endpoint>/api/v1/datasets/<project>/my-dataset' \
-H "Authorization: Bearer $REINFER_TOKEN"
curl -X GET 'https://<my_api_endpoint>/api/v1/datasets/<project>/my-dataset' \
-H "Authorization: Bearer $REINFER_TOKEN"
节点
const request = require("request");
request.get(
{
url: "https://<my_api_endpoint>/api/v1/datasets/<project>/my-dataset",
headers: {
Authorization: "Bearer " + process.env.REINFER_TOKEN,
},
},
function (error, response, json) {
// digest response
console.log(JSON.stringify(json, null, 2));
}
);
const request = require("request");
request.get(
{
url: "https://<my_api_endpoint>/api/v1/datasets/<project>/my-dataset",
headers: {
Authorization: "Bearer " + process.env.REINFER_TOKEN,
},
},
function (error, response, json) {
// digest response
console.log(JSON.stringify(json, null, 2));
}
);
Python
import json
import os
import requests
response = requests.get(
"https://<my_api_endpoint>/api/v1/datasets/<project>/my-dataset",
headers={"Authorization": "Bearer " + os.environ["REINFER_TOKEN"]},
)
print(json.dumps(response.json(), indent=2, sort_keys=True))
import json
import os
import requests
response = requests.get(
"https://<my_api_endpoint>/api/v1/datasets/<project>/my-dataset",
headers={"Authorization": "Bearer " + os.environ["REINFER_TOKEN"]},
)
print(json.dumps(response.json(), indent=2, sort_keys=True))
响应
{
"dataset": {
"created": "2018-10-16T10:57:44.667000Z",
"description": "An optional long form description.",
"has_sentiment": true,
"id": "b2ad67f9dfd2e76b",
"last_modified": "2018-10-16T10:57:44.667000Z",
"limited_access": false,
"model_family": "random",
"name": "my-dataset",
"owner": "<project>",
"source_ids": ["22f0f76e82fd8867"],
"title": "An Example Dataset"
},
"status": "ok"
}
{
"dataset": {
"created": "2018-10-16T10:57:44.667000Z",
"description": "An optional long form description.",
"has_sentiment": true,
"id": "b2ad67f9dfd2e76b",
"last_modified": "2018-10-16T10:57:44.667000Z",
"limited_access": false,
"model_family": "random",
"name": "my-dataset",
"owner": "<project>",
"source_ids": ["22f0f76e82fd8867"],
"title": "An Example Dataset"
},
"status": "ok"
}
与源一样,数据集也有多个 GET 路由,对应于:
- 用户有权访问的所有数据集;
- 属于指定项目的数据集;
- 由项目和名称指定的单个数据集。
我们提供后者的实际应用示例。
has_sentiment
除外,该字段对于给定数据集是固定的。
重击
curl -X POST 'https://<my_api_endpoint>/api/v1/datasets/<project>/my-dataset' \
-H "Authorization: Bearer $REINFER_TOKEN" \
-H "Content-Type: application/json" \
-d '{
"dataset": {
"description": "An updated description."
}
}'
curl -X POST 'https://<my_api_endpoint>/api/v1/datasets/<project>/my-dataset' \
-H "Authorization: Bearer $REINFER_TOKEN" \
-H "Content-Type: application/json" \
-d '{
"dataset": {
"description": "An updated description."
}
}'
节点
const request = require("request");
request.post(
{
url: "https://<my_api_endpoint>/api/v1/datasets/<project>/my-dataset",
headers: {
Authorization: "Bearer " + process.env.REINFER_TOKEN,
},
json: true,
body: { dataset: { description: "An updated description." } },
},
function (error, response, json) {
// digest response
console.log(JSON.stringify(json, null, 2));
}
);
const request = require("request");
request.post(
{
url: "https://<my_api_endpoint>/api/v1/datasets/<project>/my-dataset",
headers: {
Authorization: "Bearer " + process.env.REINFER_TOKEN,
},
json: true,
body: { dataset: { description: "An updated description." } },
},
function (error, response, json) {
// digest response
console.log(JSON.stringify(json, null, 2));
}
);
Python
import json
import os
import requests
response = requests.post(
"https://<my_api_endpoint>/api/v1/datasets/<project>/my-dataset",
headers={"Authorization": "Bearer " + os.environ["REINFER_TOKEN"]},
json={"dataset": {"description": "An updated description."}},
)
print(json.dumps(response.json(), indent=2, sort_keys=True))
import json
import os
import requests
response = requests.post(
"https://<my_api_endpoint>/api/v1/datasets/<project>/my-dataset",
headers={"Authorization": "Bearer " + os.environ["REINFER_TOKEN"]},
json={"dataset": {"description": "An updated description."}},
)
print(json.dumps(response.json(), indent=2, sort_keys=True))
响应
{
"dataset": {
"created": "2018-10-16T10:57:44.667000Z",
"description": "An updated description.",
"has_sentiment": true,
"id": "b2ad67f9dfd2e76b",
"last_modified": "2018-10-16T10:57:44.667000Z",
"limited_access": false,
"model_family": "random",
"name": "my-dataset",
"owner": "<project>",
"source_ids": ["22f0f76e82fd8867"],
"title": "An Example Dataset"
},
"status": "ok"
}
{
"dataset": {
"created": "2018-10-16T10:57:44.667000Z",
"description": "An updated description.",
"has_sentiment": true,
"id": "b2ad67f9dfd2e76b",
"last_modified": "2018-10-16T10:57:44.667000Z",
"limited_access": false,
"model_family": "random",
"name": "my-dataset",
"owner": "<project>",
"source_ids": ["22f0f76e82fd8867"],
"title": "An Example Dataset"
},
"status": "ok"
}
删除数据集将完全删除关联的分类以及已应用于其来源的所有标签。 您将无法再根据此分类获得预测,并且必须从头开始注释消息的训练流程,才能反转此操作,因此请谨慎使用。
重击
curl -X DELETE 'https://<my_api_endpoint>/api/v1/datasets/<project>/my-dataset' \
-H "Authorization: Bearer $REINFER_TOKEN"
curl -X DELETE 'https://<my_api_endpoint>/api/v1/datasets/<project>/my-dataset' \
-H "Authorization: Bearer $REINFER_TOKEN"
节点
const request = require("request");
request.delete(
{
url: "https://<my_api_endpoint>/api/v1/datasets/<project>/my-dataset",
headers: {
Authorization: "Bearer " + process.env.REINFER_TOKEN,
},
},
function (error, response, json) {
// digest response
console.log(JSON.stringify(json, null, 2));
}
);
const request = require("request");
request.delete(
{
url: "https://<my_api_endpoint>/api/v1/datasets/<project>/my-dataset",
headers: {
Authorization: "Bearer " + process.env.REINFER_TOKEN,
},
},
function (error, response, json) {
// digest response
console.log(JSON.stringify(json, null, 2));
}
);
Python
import json
import os
import requests
response = requests.delete(
"https://<my_api_endpoint>/api/v1/datasets/<project>/my-dataset",
headers={"Authorization": "Bearer " + os.environ["REINFER_TOKEN"]},
)
print(json.dumps(response.json(), indent=2, sort_keys=True))
import json
import os
import requests
response = requests.delete(
"https://<my_api_endpoint>/api/v1/datasets/<project>/my-dataset",
headers={"Authorization": "Bearer " + os.environ["REINFER_TOKEN"]},
)
print(json.dumps(response.json(), indent=2, sort_keys=True))
响应
{
"status": "ok"
}
{
"status": "ok"
}
重击
curl -X POST 'https://<my_api_endpoint>/api/v1/datasets/<project>/<dataset>/labellers/<model_version>/predict' \
-H "Authorization: Bearer $REINFER_TOKEN" \
-H "Content-Type: application/json" \
-d '{
"documents": [
{
"messages": [
{
"body": {
"text": "Hi Bob, has my trade settled yet? Thanks, Alice"
},
"from": "alice@company.com",
"sent_at": "2011-12-11T11:02:03.000000+00:00",
"subject": {
"text": "Trade Ref: 8726387 Settlement"
},
"to": [
"bob@organisation.org"
]
}
],
"user_properties": {
"number:Deal Value": 12000,
"string:City": "London"
}
},
{
"messages": [
{
"body": {
"text": "All, just to let you know that processing is running late today. Regards, Bob"
},
"from": "bob@organisation.org",
"sent_at": "2011-12-12T10:04:30.000000+00:00",
"subject": {
"text": "Trade Processing Delay"
},
"to": [
"alice@company.com",
"carol@company.com"
]
}
],
"user_properties": {
"number:Deal Value": 4.9,
"string:City": "Luton"
}
}
],
"labels": [
{
"name": [
"Trade",
"Settlement"
],
"threshold": 0.8
},
{
"name": [
"Delay"
],
"threshold": 0.75
}
],
"threshold": 0
}'
curl -X POST 'https://<my_api_endpoint>/api/v1/datasets/<project>/<dataset>/labellers/<model_version>/predict' \
-H "Authorization: Bearer $REINFER_TOKEN" \
-H "Content-Type: application/json" \
-d '{
"documents": [
{
"messages": [
{
"body": {
"text": "Hi Bob, has my trade settled yet? Thanks, Alice"
},
"from": "alice@company.com",
"sent_at": "2011-12-11T11:02:03.000000+00:00",
"subject": {
"text": "Trade Ref: 8726387 Settlement"
},
"to": [
"bob@organisation.org"
]
}
],
"user_properties": {
"number:Deal Value": 12000,
"string:City": "London"
}
},
{
"messages": [
{
"body": {
"text": "All, just to let you know that processing is running late today. Regards, Bob"
},
"from": "bob@organisation.org",
"sent_at": "2011-12-12T10:04:30.000000+00:00",
"subject": {
"text": "Trade Processing Delay"
},
"to": [
"alice@company.com",
"carol@company.com"
]
}
],
"user_properties": {
"number:Deal Value": 4.9,
"string:City": "Luton"
}
}
],
"labels": [
{
"name": [
"Trade",
"Settlement"
],
"threshold": 0.8
},
{
"name": [
"Delay"
],
"threshold": 0.75
}
],
"threshold": 0
}'
节点
const request = require("request");
request.post(
{
url: "https://<my_api_endpoint>/api/v1/datasets/<project>/<dataset>/labellers/<model_version>/predict",
headers: {
Authorization: "Bearer " + process.env.REINFER_TOKEN,
},
json: true,
body: {
documents: [
{
messages: [
{
body: { text: "Hi Bob, has my trade settled yet? Thanks, Alice" },
from: "alice@company.com",
sent_at: "2011-12-11T11:02:03.000000+00:00",
subject: { text: "Trade Ref: 8726387 Settlement" },
to: ["bob@organisation.org"],
},
],
user_properties: {
"number:Deal Value": 12000,
"string:City": "London",
},
},
{
messages: [
{
body: {
text: "All, just to let you know that processing is running late today. Regards, Bob",
},
from: "bob@organisation.org",
sent_at: "2011-12-12T10:04:30.000000+00:00",
subject: { text: "Trade Processing Delay" },
to: ["alice@company.com", "carol@company.com"],
},
],
user_properties: { "number:Deal Value": 4.9, "string:City": "Luton" },
},
],
labels: [
{ name: ["Trade", "Settlement"], threshold: 0.8 },
{ name: ["Delay"], threshold: 0.75 },
],
threshold: 0,
},
},
function (error, response, json) {
// digest response
console.log(JSON.stringify(json, null, 2));
}
);
const request = require("request");
request.post(
{
url: "https://<my_api_endpoint>/api/v1/datasets/<project>/<dataset>/labellers/<model_version>/predict",
headers: {
Authorization: "Bearer " + process.env.REINFER_TOKEN,
},
json: true,
body: {
documents: [
{
messages: [
{
body: { text: "Hi Bob, has my trade settled yet? Thanks, Alice" },
from: "alice@company.com",
sent_at: "2011-12-11T11:02:03.000000+00:00",
subject: { text: "Trade Ref: 8726387 Settlement" },
to: ["bob@organisation.org"],
},
],
user_properties: {
"number:Deal Value": 12000,
"string:City": "London",
},
},
{
messages: [
{
body: {
text: "All, just to let you know that processing is running late today. Regards, Bob",
},
from: "bob@organisation.org",
sent_at: "2011-12-12T10:04:30.000000+00:00",
subject: { text: "Trade Processing Delay" },
to: ["alice@company.com", "carol@company.com"],
},
],
user_properties: { "number:Deal Value": 4.9, "string:City": "Luton" },
},
],
labels: [
{ name: ["Trade", "Settlement"], threshold: 0.8 },
{ name: ["Delay"], threshold: 0.75 },
],
threshold: 0,
},
},
function (error, response, json) {
// digest response
console.log(JSON.stringify(json, null, 2));
}
);
Python
import json
import os
import requests
response = requests.post(
"https://<my_api_endpoint>/api/v1/datasets/<project>/<dataset>/labellers/<model_version>/predict",
headers={"Authorization": "Bearer " + os.environ["REINFER_TOKEN"]},
json={
"documents": [
{
"messages": [
{
"body": {
"text": "Hi Bob, has my trade settled yet? Thanks, Alice"
},
"subject": {"text": "Trade Ref: 8726387 Settlement"},
"from": "alice@company.com",
"sent_at": "2011-12-11T11:02:03.000000+00:00",
"to": ["bob@organisation.org"],
}
],
"user_properties": {
"number:Deal Value": 12000,
"string:City": "London",
},
},
{
"messages": [
{
"body": {
"text": "All, just to let you know that processing is running late today. Regards, Bob"
},
"subject": {"text": "Trade Processing Delay"},
"from": "bob@organisation.org",
"sent_at": "2011-12-12T10:04:30.000000+00:00",
"to": ["alice@company.com", "carol@company.com"],
}
],
"user_properties": {
"number:Deal Value": 4.9,
"string:City": "Luton",
},
},
],
"labels": [
{"name": ["Trade", "Settlement"], "threshold": 0.8},
{"name": ["Delay"], "threshold": 0.75},
],
"threshold": 0,
},
)
print(json.dumps(response.json(), indent=2, sort_keys=True))
import json
import os
import requests
response = requests.post(
"https://<my_api_endpoint>/api/v1/datasets/<project>/<dataset>/labellers/<model_version>/predict",
headers={"Authorization": "Bearer " + os.environ["REINFER_TOKEN"]},
json={
"documents": [
{
"messages": [
{
"body": {
"text": "Hi Bob, has my trade settled yet? Thanks, Alice"
},
"subject": {"text": "Trade Ref: 8726387 Settlement"},
"from": "alice@company.com",
"sent_at": "2011-12-11T11:02:03.000000+00:00",
"to": ["bob@organisation.org"],
}
],
"user_properties": {
"number:Deal Value": 12000,
"string:City": "London",
},
},
{
"messages": [
{
"body": {
"text": "All, just to let you know that processing is running late today. Regards, Bob"
},
"subject": {"text": "Trade Processing Delay"},
"from": "bob@organisation.org",
"sent_at": "2011-12-12T10:04:30.000000+00:00",
"to": ["alice@company.com", "carol@company.com"],
}
],
"user_properties": {
"number:Deal Value": 4.9,
"string:City": "Luton",
},
},
],
"labels": [
{"name": ["Trade", "Settlement"], "threshold": 0.8},
{"name": ["Delay"], "threshold": 0.75},
],
"threshold": 0,
},
)
print(json.dumps(response.json(), indent=2, sort_keys=True))
响应
{
"entities": [
[
{
"formatted_value": "2019-01-01 00:00 UTC",
"kind": "date",
"span": {
"content_part": "body",
"message_index": 0,
"utf16_byte_end": 120,
"utf16_byte_start": 94
}
},
{
"formatted_value": "Bob",
"kind": "person",
"span": {
"content_part": "body",
"message_index": 0,
"utf16_byte_end": 6,
"utf16_byte_start": 12
}
}
],
[]
],
"model": {
"time": "2018-12-20T15:05:43.906000Z",
"version": "1"
},
"predictions": [
[
{
"name": ["Trade", "Settlement"],
"probability": 0.8668700814247131
}
],
[
{
"name": ["Delay"],
"probability": 0.26687008142471313
}
]
],
"status": "ok"
}
{
"entities": [
[
{
"formatted_value": "2019-01-01 00:00 UTC",
"kind": "date",
"span": {
"content_part": "body",
"message_index": 0,
"utf16_byte_end": 120,
"utf16_byte_start": 94
}
},
{
"formatted_value": "Bob",
"kind": "person",
"span": {
"content_part": "body",
"message_index": 0,
"utf16_byte_end": 6,
"utf16_byte_start": 12
}
}
],
[]
],
"model": {
"time": "2018-12-20T15:05:43.906000Z",
"version": "1"
},
"predictions": [
[
{
"name": ["Trade", "Settlement"],
"probability": 0.8668700814247131
}
],
[
{
"name": ["Delay"],
"probability": 0.26687008142471313
}
]
],
"status": "ok"
}
拥有经过训练的模型后,您现在可以使用此模型根据其他数据片段预测标签。 为此,您只需提供以下内容:
- Documents - An array of message data that the model will predict labels for and each message object can only contain one message along with any optional properties. For optimal model performance, the data provided needs to be consistent with the data and format that was annotated on the platform, as the model takes all available data and metadata into consideration. For example, emails should include the Subject, From, Bcc, Cc fields, and so on, if these were present in the training data. Additionally, user properties in the training dataset should also be included in the API request body.
- Labels - An array of the model trained labels that you want the model to predict in the data provided. Additionally, for each label a confidence threshold to filter labels by should be provided. The optimal threshold can be decided based on your precision vs recall trade off. Further information regarding how to choose a threshold can be found in the user guide, under the Using Validation section.
- Default threshold (optional) - A default threshold value that will be applied across all labels provided. Please note, if default and per-label thresholds are provided together in a request, the per-label thresholds will override the default threshold. As best practice, default thresholds can be used for testing or exploring data. For optimal results when using predictions for automated decision making, it is highly recommended to use per-label thresholds.
在 API URL 中,传递以下参数非常重要:
- Project name - An existing project you are a part of.
- Dataset name - Adataset the model has been trained on.
- Model version - The model version is a number that can be found on the Models page for your chosen dataset.
由于正在使用特定的模型版本,因此即使正在进一步训练模型,对同一请求的响应将始终返回相同的结果。 验证新模型的结果后,并希望提交针对新模型的请求,则应更新请求中的模型版本。 此外,您还应更新标签阈值以适应新模型。 对于每个新模型,您必须再次遍历这些步骤。
默认情况下,响应将始终为置信度高于提供的阈值级别的每条消息提供预测标签列表。
但是,如果为模型启用了实体识别和情感,则请求的响应可能会有所不同:
- General fields Enabled - The response will also provide a list of general fields that have been identified for each label (first response example)
- Sentiments Enabled - The response will also provide a sentiment score between -1 (perfectly negative) and 1 (perfectly positive) to every label object classified above the confidence threshold. (second response example)
{
"model": { "time": "2018-12-20T15:05:43.906000Z", "version": "1" },
"predictions": [
[
{
"name": ["Trade", "Settlement"],
"probability": 0.86687008142471313,
"sentiment": 0.8762539502232571
}
],
[
{
"name": ["Delay"],
"probability": 0.26687008142471313,
"sentiment": 0.8762539502232571
}
]
],
"status": "ok"
}
{
"model": { "time": "2018-12-20T15:05:43.906000Z", "version": "1" },
"predictions": [
[
{
"name": ["Trade", "Settlement"],
"probability": 0.86687008142471313,
"sentiment": 0.8762539502232571
}
],
[
{
"name": ["Delay"],
"probability": 0.26687008142471313,
"sentiment": 0.8762539502232571
}
]
],
"status": "ok"
}