全部产品

情绪识别服务

更新时间:2020-08-26 14:23

情绪识别服务适用于电销、在线接待等应用场景,识别客户或客服的情绪。使用示例如下。

Java代码示例

  1. DefaultProfile defaultProfile = DefaultProfile.getProfile("cn-hangzhou","your-access-key-id","your-access-id-secret");
  2. IAcsClient client = new DefaultAcsClient(defaultProfile);
  3. String content = "{\"input\": {\"content\":\"图形验证码输入老是错误\" } }";
  4. RunPreTrainServiceRequest request = new RunPreTrainServiceRequest();
  5. request.setServiceName("DeepEmotion");
  6. request.setPredictContent(content);
  7. RunPreTrainServiceResponse response = client.getAcsResponse(request);
  8. System.out.println(response.getPredictResult());

Python代码示例

  1. # 安装依赖
  2. pip install aliyun-python-sdk-core
  3. pip install aliyun-python-sdk-nlp-automl
  1. # -*- coding: utf8 -*-
  2. import json
  3. from aliyunsdkcore.client import AcsClient
  4. from aliyunsdkcore.acs_exception.exceptions import ClientException
  5. from aliyunsdkcore.acs_exception.exceptions import ServerException
  6. from aliyunsdknlp_automl.request.v20191111 import RunPreTrainServiceRequest
  7. # Initialize AcsClient instance
  8. client = AcsClient(
  9. "<your-access-key-id>",
  10. "<your-access-key-secret>",
  11. "cn-hangzhou"
  12. );
  13. content ={"input":{"content":"图形验证码输入老是错误"}}
  14. # Initialize a request and set parameters
  15. request = RunPreTrainServiceRequest.RunPreTrainServiceRequest()
  16. request.set_ServiceName('DeepEmotion')
  17. request.set_PredictContent(json.dumps(content))
  18. # Print response
  19. response = client.do_action_with_exception(request)
  20. resp_obj = json.loads(response)
  21. predict_result = json.loads(resp_obj['PredictResult'])
  22. print(predict_result['result'])

PredictContent内容示例

  1. {
  2. "input": {
  3. "content": "图形验证码输入老是错误"
  4. }
  5. }

PredictResult内容示例

  1. {
  2. "output": {
  3. "content": "图形验证码输入老是错误",
  4. "sentiment": [
  5. {
  6. "key": "高兴",
  7. "score": 0.0
  8. },
  9. {
  10. "key": "喜好",
  11. "score": 0.0
  12. },
  13. {
  14. "key": "悲伤",
  15. "score": 0.001
  16. },
  17. {
  18. "key": "愤怒",
  19. "score": 0.051
  20. },
  21. {
  22. "key": "厌恶",
  23. "score": 0.866
  24. },
  25. {
  26. "key": "惊讶",
  27. "score": 0.004
  28. },
  29. {
  30. "key": "恐惧",
  31. "score": 0.0
  32. },
  33. {
  34. "key": "认可",
  35. "score": 0.0
  36. }
  37. ]
  38. }
  39. }

入参说明

参数 说明
content 待检测的文本样例
role 可选参数,待检测的角色类型,当前支持[客服,客户]两种类型

出参说明

说明 支持文本同时命中多种情绪的情况
参数 说明
content 来自入参,检测的文本样例
sentiment 识别到的情绪列表,当前包含8种情绪(高兴、喜好、悲伤、愤怒、厌恶、惊讶、恐惧,认可)
key 情绪名称
score 情绪概率,0-1之间,大于0.5可认为命中该情绪类型。