API examples for getting model prediction results

Updated at:

This document provides examples of how to use the model prediction API to obtain prediction results for different model types.

Example code for an API call

Java code example

    DefaultProfile defaultProfile = DefaultProfile.getProfile("cn-hangzhou","your-access-id-key","your-access-id-secret");
    IAcsClient client = new DefaultAcsClient(defaultProfile);
        CommonRequest request = new CommonRequest();
        request.setMethod(MethodType.POST);
        request.setDomain("nlp-automl.cn-hangzhou.aliyuncs.com");
        request.setVersion("2019-11-11");
        request.setAction("GetPredictResult");
        request.putQueryParameter("RegionId", "cn-hangzhou");
        request.putQueryParameter("ModelId", modelId);
        request.putQueryParameter("Content", content);
        request.putQueryParameter("ModelVersion", version);
    CommonResponse response = client.getCommonResponse(request);
        System.out.println(response.getData());

For more code examples, see GetPredictResult.

Content input for the short text matching model type

For the short text matching model type, pass the content parameter as a string. See the following example:

[["What materials are needed for a property certificate for a new house","How to apply for a property certificate"]]

Java code example

    JSONArray items = new JSONArray();
        JSONArray item = new JSONArray();
        item.add("What materials are needed for a property certificate for a new house");
        item.add("How to apply for a property certificate");
        items.add(item);
        String content = items.toString();
        System.out.println(content);

Model result examples

Text entity extraction

content

Model type

Xindali (Fuzhou) Enterprise Management Consulting Co., Ltd. Chongqing First Branch was established in 2008. It is now located next to the Hongqihegou light rail station in Jiangbei District, with convenient transportation, an excellent office environment, and a strong work atmosphere.

LSTM-CRF Chinese entity extraction

Returned result

[{
 "id": 0,
 "sent_offsets": 0,
 "sentence": "Xindali (Fuzhou) Enterprise Management Consulting Co., Ltd. Chongqing First Branch was established in 2008. It is now located next to the Hongqihegou light rail station in Jiangbei District, with convenient transportation, an excellent office environment, and a strong work atmosphere",
 "tags": [{
  "class": "companyName",
  "conf": 0.6834408044815063,
  "end": 17,
  "source": "model",
  "span": "Xindali (Fuzhou) Enterprise Management Consulting Co., Ltd.",
  "start": 0
 }]
}]

The returned result is a JSONArray string. You need to deserialize and parse it. The prediction results are in the tags field.

tags field parameters

Field name

Field value description

class

Name of the extracted entity object

conf

Confidence level

start

Start position of the entity object in the text

end

End position of the entity object in the text

source

Source

span

Predicted entity object

Text classification

content

Model type

I've had it for two days and it feels pretty good. The system is fast, but it has the common problem of Windows 10: the font is too small and the screen is large, which makes it uncomfortable to look at. I hope Windows 10 can be improved later. Also, the non-removable battery is a bit annoying.

Long text classification fusion model

Returned result

The returned result is a JSON string. You need to deserialize and parse it.

{
 "Experience": [{
  "score": 0.8428525328636169,
  "children": [{
   "score": 0.8173030018806458,
   "children": [{
    "score": 0.7761349081993103,
    "key": "Workmanship"
   }],
   "key": "Quality"
  }, {
   "score": 0.7761349081993103,
   "key": "Workmanship"
  }],
  "key": "Product Experience"
 }]
}

Returned fields

Field name

Field description

score

Score value

key

Classification label

children

Child nodes in a multi-level classification

Key phrase extraction

content

Model type

The fresh aroma of green tangerine peel plus the mellow taste of Pu'er tea is worth a try for tea lovers. A friend recommended it after buying, and it's really worth it! After brewing it for a while, you can use a tea boiler to cook it again, and the tea's flavor is still very rich. I'll be drinking this mainly this winter.

Key phrase extraction

Returned result

["Green tangerine peel", "Fresh aroma", "Pu'er"]
Note

The returned result is an array string.

Short text matching

content

Model type

[["Credit card repayment, order of fund repayment","Credit card repayment order"]]

Short text matching

Returned result

The result is returned as a string in JSONArray format, which you can then deserialize and parse.

[{
 "match": "1",
 "sent_a": "Credit card repayment, order of fund repayment",
 "sent_b": "Credit card repayment order",
 "value": "0.5989755"
}]

Response fields

Field name

Field value description

match

Indicates whether the texts match. 0: No match. 1: Match.

sent_a

Short text a

sent_b

Short text b

value

Text matching value

Sentiment analysis

content

Model type

I opened a bag and half of it was spoiled. It tastes terrible, not as good as the ones I had before.

Chinese CNN sentiment analysis

Return value

The response is a JSON string. You must deserialize and parse it.

{
 "Sentiment": [{
  "score": 0.730135977268219,
  "key": "Negative"
 }, {
  "score": 0.5031050443649292,
  "key": "Positive"
 }]
}

Response fields

Note

The sentiment with the highest score is the analysis result.

Field name

Field description

score

Sentiment score predicted by the model

key

Sentiment: Positive, Negative

Product review analysis

content

Model type

The box was packaged very tightly, but the suction cup has turned yellow. The transparent ring is quite oxidized. It must be an old product. For this price, I can't ask for too much.

Product review analysis

Return value

The response is a JSON string that you can deserialize and parse.

{
 "Logistics": [{
  "score": 0.9994128942489624,
  "key": "Not mentioned"
 }, {
  "score": 0.0004609959723893553,
  "key": "Positive"
 }, {
  "score": 0.00006164848309708759,
  "key": "Negative"
 }, {
  "score": 0.000018525688574300148,
  "key": "Neutral"
 }],
 "Quality": [{
  "score": 0.033323273062705994,
  "key": "Not mentioned"
 }, {
  "score": 0.08673246949911118,
  "key": "Positive"
 }, {
  "score": 0.7257013916969299,
  "key": "Negative"
 }, {
  "score": 0.7785664796829224,
  "key": "Neutral"
 }]
}

Response fields

Field name

Field value description

score

Score value from the product attribute analysis

key

Indicates if the attribute is mentioned in the text and its sentiment.

Resume extraction

content

Model type

Name: Li Mou Work experience: 3 years Phone: 1390000**** Gender: Male Email: 1390000****@sina.cn Household registration: Linfen, Shanxi Province Position applied for: web frontend engineer Current residence: Beijing Current status: Resigned, available to start immediately

Resume extraction self-trained model (Chinese)

Return value

The returned value is a string in JSONArray format. You can deserialize and parse the string.

[{
 "sentence": "Name: Li Mou Work experience: 3 years",
 "sent_offsets": 0,
 "id": 0,
 "tags": [{
  "source": "rule",
  "class": "Name",
  "span": "Li Mou"
 }]
}, {
 "sentence": "Phone: 1390000****",
 "sent_offsets": 1,
 "id": 0,
 "tags": [{
  "start": 4,
  "conf": 0,
  "end": 15,
  "source": "model",
  "class": "Phone number",
  "span": "1390000****"
 }]
}, {
 "sentence": "Gender: Male",
 "sent_offsets": 2,
 "id": 0,
 "tags": [{
  "source": "rule",
  "class": "Gender",
  "span": "Male"
 }]
}, {
 "sentence": "Email: 1390000****@sina.cn Household registration: Linfen, Shanxi Province",
 "sent_offsets": 3,
 "id": 0,
 "tags": [{
  "start": 5,
  "conf": 0,
  "end": 16,
  "source": "model",
  "class": "Phone number",
  "span": "1390000****"
 }, {
  "source": "rule",
  "class": "Email",
  "span": "1390000****@sina.cn"
 }, {
  "source": "rule",
  "class": "Household registration location",
  "span": "Shanxi"
 }]
}, {
 "sentence": "Position applied for: web frontend engineer Current residence: Beijing",
 "sent_offsets": 4,
 "id": 0,
 "tags": [{
  "start": 5,
  "conf": 0,
  "end": 13,
  "source": "model",
  "class": "Position name",
  "span": "web frontend engineer"
 }, {
  "source": "rule",
  "class": "Current residence",
  "span": "Beijing"
 }]
}, {
 "sentence": "Current status: Resigned, available to start immediately",
 "sent_offsets": 5,
 "id": 0,
 "tags": []
}]

Response fields

Field name

Field value description

sentence

Content of the analyzed statement

sent_offsets

Statement position

"tags": [{
"start": 5,
"conf": 0,
"end": 16,
"source": "model",
  "class": "Phone number",
"span": "1390000****"
}, {
"source": "rule",
  "class": "Email",
"span": "1390000****@sina.cn"
}, {
"source": "rule",
"class": "Household registration location",
  "span": "Shanxi"
}]

Resume information obtained after statement analysis and extraction

Sentence pair text classification

content

Model type

{"content": "AI: I'd like to confirm with you, are you the owner, A, and is the entire apartment for rent?","content_pair": "Yes"}

Two-sentence classification high-performance version

Return value

The response is a JSON string that you must deserialize and parse.

{
  "result": "{\"Intent\":[{\"score\":0.5135,\"key\":\"Not the owner\"},{\"score\":0.491,\"key\":\"Is the owner\"}]}",
  "retCode": "0",
  "type": "NLP_text_pair_classification_cross_attn"
 }

Returned fields

Field

Field description

type

Model type

key

Classification result

score

Confidence level

result-key

Classification name