The customer inquiry analysis service is designed for online chat scenarios between customer service agents and consumers in industries such as E-commerce. The service parses consumer messages to identify intent, emotion, sentiment, points of interest, and fine-grained sentiment.
This service is provided by the NLP Self-Learning Platform. You can use the service by calling the API directly.
Activate the service and purchase a resource plan
Before you start, ensure that the service is activated. After activation, you can purchase a resource plan.
Activate the service: Activation page
Purchase a resource plan: Purchase page
Service invocation and testing
For more information about model invocation, see Model invocation.
For software development kit (SDK) examples, see SDK examples.
Debugging
Configure access credentials using environment variables
Notes:
An AccessKey for an Alibaba Cloud account has permissions for 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 operations and maintenance (O&M). You can log on to the RAM console to create a RAM user.
Do not save your AccessKey ID and AccessKey secret in your code. This can lead to credential leaks. Instead, configure environment variables to store and access your credentials.
Configure for 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, see Step 2: Obtain an AccessKey for your account.
Configure for Windows
Create a new environment variable file. Add the
NLP_AK_ENVandNLP_SK_ENVenvironment variables. Then, set their values to your AccessKey ID and AccessKey secret.Restart your Windows system.
Java code example
/**
* An AccessKey for an Alibaba Cloud account has permissions for all APIs. This is a high security risk.
* 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 as needed.
* Do not hardcode the AccessKey ID and AccessKey secret in your code. This can lead to credential leaks.
*/
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> map = new HashMap<>();
map.put("input", "Your service attitude is poor. Is this how you provide service?");
RunPreTrainServiceRequest request = new RunPreTrainServiceRequest();
request.setServiceName("Dialog-Analysis");
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 permissions for all APIs. This is a high security risk.
# 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 as needed.
# Do not hardcode the AccessKey ID and AccessKey secret in your code. This can lead to credential leaks.
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"
);
# The input can also include preceding (context_above) and succeeding (context_below) context information to improve the algorithm's performance. This information is optional. See the input example.
content = {
"input": "Your service attitude is poor. Is this how you provide service?",
}
# Initialize a request and set parameters
request = RunPreTrainServiceRequest.RunPreTrainServiceRequest()
request.set_ServiceName('Dialog-Analysis')
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
# This is a complete example that includes preceding (context_above) and succeeding (context_below) context data. This data helps improve the algorithm's performance, but it is optional.
{
"context_above": [
{
"role": "User",
"context": "I asked you to change the price and you just canceled my order?"
},
{
"role": "Agent",
"context": "Orders cannot be modified after they are placed."
}
],
"input": "Your service attitude is poor. Is this how you provide service?",
"context_below": [
{
"role": "Agent",
"context": "I'm sorry, but that is the policy."
},
{
"role": "User",
"context": "Goodbye. I'm never coming back."
}
]
}PredictResult example
{
"emotion": {
"key": "Complaint",
"score": 0.4929790496826172
},
"intent": {
"key": "None",
"score": 0.756518542766571
},
"category": {
"key": "Other-Other",
"score": 0.4580000042915344
},
"sentiment": {
"key": "Negative",
"score": 1.0
},
"aspectItem": [
{
"aspectCategory": "Agent-Service",
"aspectPolarity": "Negative",
"negativeProb": 1.0,
"positiveProb": 0.0,
"terms": [
{
"aspectTerm": "Service attitude",
"opinionTerm": "Poor"
}
]
}
]
}Input parameters
Parameter | Description |
input | The customer's current message in an online chat with a customer service agent. |
context_above | The context before the customer's current message. It can include multiple previous messages. |
context_below | The context after the customer's current message. It can include multiple subsequent messages. |
role | The speaker's role. Currently, only 'Agent' and 'User' are supported. |
context | The content of the speaker's message. |
Response parameters
Parameter | Description |
emotion | The customer's emotion. |
intent | The customer's intent. |
category | The customer's point of interest. |
sentiment | The positive or negative sentiment of the customer's message. |
aspectItem | The fine-grained sentiment analysis of the customer's message. |
aspectCategory | The fine-grained aspect dimension. |
aspectPolarity | The fine-grained sentiment polarity. |
negativeProb | Fine-grained positive sentiment probability |
positiveProb | Negative sentiment probability |
terms | The aspect and opinion terms that correspond to the fine-grained sentiment. |
aspectTerm | The aspect term that corresponds to the fine-grained sentiment. |
opinionTerm | The opinion term that corresponds to the fine-grained sentiment. |