The user intent recognition service identifies user intents in manual and intelligent outbound telemarketing scenarios.
This service is provided by the NLP Self-Learning Platform. To use this service, call the API directly.
Activate the service and purchase a resource plan
Before you begin, you must activate the service. After the service is activated, you must purchase a resource plan.
Activate the service: Activation URL
Purchase a resource plan: Purchase URL
Service invocation and debugging
For more information, see Model Invocation.
For more information, see SDK Examples.
Debug
Configure access credentials using environment variables
Notes:
An AccessKey for an Alibaba Cloud account provides full access to all APIs, which poses a high security risk. We recommend that you create and use a Resource Access Management (RAM) user for API access or daily O&M. To create a RAM user, log on to the RAM console.
Do not hardcode your AccessKey ID and AccessKey secret in your code. This practice can lead to key leakage. Instead, use environment variables to store and access your AccessKey ID and AccessKey secret.
Configuring Linux and macOS
export NLP_AK_ENV=<access_key_id> export NLP_SK_ENV=<access_key_secret>Replace <access_key_id> with your AccessKey ID and <access_key_secret> with your AccessKey secret. For more information about how to obtain an AccessKey ID and AccessKey secret, see Step 2: Obtain an AccessKey for an account.
Windows System Configuration
Create an environment variable file. Add the
NLP_AK_ENVandNLP_SK_ENVenvironment variables, and then set their values to your AccessKey ID and AccessKey secret.Restart the Windows operating system.
Java code example
/**
* An AccessKey for an Alibaba Cloud account has full API access, which is a high security threat.
* We recommend that you create and use a RAM user for API access or daily O&M. Log on to the RAM console to create a RAM user.
* This example shows how to store the AccessKey ID and AccessKey secret in environment variables. You can also store them in a configuration file based on your business needs.
* Do not hardcode your AccessKey ID and AccessKey secret in your code. This can cause key leakage.
*/
String accessKeyId = System.getenv("NLP_AK_ENV");
String accessKeySecret = System.getenv("NLP_SK_ENV");
DefaultProfile defaultProfile = DefaultProfile.getProfile("cn-hangzhou",accessKeyId,accessKeySecret);
IAcsClient client = new DefaultAcsClient(defaultProfile);
Map<String, Object> input = new HashMap();
input.put("b_say","Are you considering buying a house recently?");
input.put("c_say","I don't need it.");
input.put("domain","common");
Map<String, Object> map = new HashMap<>();
map.put("input", input);
RunPreTrainServiceRequest request = new RunPreTrainServiceRequest();
request.setServiceName("NLP-Key-Intent");
request.setPredictContent(JSON.toJSONString(map));
RunPreTrainServiceResponse response = client.getAcsResponse(request);
System.out.println(response.getPredictResult());Python code example
# Install dependencies
pip install aliyun-python-sdk-core
pip install aliyun-python-sdk-nlp-automl# -*- coding: utf8 -*-
import json
import os
from aliyunsdkcore.client import AcsClient
from aliyunsdkcore.acs_exception.exceptions import ClientException
from aliyunsdkcore.acs_exception.exceptions import ServerException
from aliyunsdknlp_automl.request.v20191111 import RunPreTrainServiceRequest
"""
An AccessKey for an Alibaba Cloud account has full API access, which is a high security threat.
We recommend that you use a RAM user for API access or daily O&M. Log on to the RAM console to create a RAM user.
This example shows how to store the AccessKey ID and AccessKey secret in environment variables.
You can also store them in a configuration file based on your business needs.
Do not hardcode your AccessKey ID and AccessKey secret in your code. This can cause key leakage.
"""
access_key_id = os.environ['NLP_AK_ENV']
access_key_secret = os.environ['NLP_SK_ENV']
# Initialize AcsClient instance
client = AcsClient(
access_key_id,
access_key_secret,
"cn-hangzhou"
);
content ={"input": {"b_say": "Are you considering buying a house recently?", "c_say": "I don't need it.", "domain": "common"}}
# Initialize a request and set parameters
request = RunPreTrainServiceRequest.RunPreTrainServiceRequest()
request.set_ServiceName('NLP-Key-Intent')
request.set_PredictContent(json.dumps(content))
# Print response
response = client.do_action_with_exception(request)
resp_obj = json.loads(response)
predict_result = json.loads(resp_obj['PredictResult'])
print(predict_result['result'])PredictContent example
{
"input": {
"b_say": "Are you considering buying a house recently?",
"c_say": "I don't need it.",
"domain": "common"
}
}PredictResult example
{
"code": 1000,
"data": {
"cost": "3.622ms",
"intent": {
"intent": "Negative"
}
},
"message": "OK",
"tracerID": "2020-09-17 15:41:28.461691"
}Request parameters
Parameter | Description |
b_say | Optional. The content spoken by the customer service representative. |
c_say | Required. The content spoken by the user. |
domain | Optional. The realm. The default value is common. |
Response parameters
Parameter | Description |
intent | The detected intent. The supported intents are: Affirmative, Negative, Reject, Who is this, Busy, Did not hear clearly, Wait a moment, and Other. |
Intent descriptions
Intent name | Description |
Affirmative | The user expresses affirmation or agreement. |
Negative | The user expresses negation. |
Reject | The user expresses rejection. |
Who is this | The user inquires about the identity. |
Busy | The user says they are busy. |
Did not hear clearly | The user says they did not hear clearly. |
Wait a moment | The user asks to wait a moment. |
Other | Any intent other than those listed above. |