全部产品

情绪识别服务

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

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("DeepEmotionBert");
  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('DeepEmotionBert')
  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. "sentiment": [
  4. {
  5. "score": 0.7712000012397766,
  6. "key": "抱怨"
  7. },
  8. {
  9. "score": 0.014100000262260437,
  10. "key": "愤怒"
  11. },
  12. {
  13. "score": 0.014000000432133675,
  14. "key": "厌恶"
  15. },
  16. {
  17. "score": 0.005499999970197678,
  18. "key": "悲伤"
  19. },
  20. {
  21. "score": 0.004100000020116568,
  22. "key": "投诉"
  23. },
  24. {
  25. "score": 0.0008999999845400453,
  26. "key": "惊讶"
  27. },
  28. {
  29. "score": 0.0007999999797903001,
  30. "key": "恐惧"
  31. },
  32. {
  33. "score": 0.00039999998989515007,
  34. "key": "喜好"
  35. },
  36. {
  37. "score": 0.00019999999494757503,
  38. "key": "高兴"
  39. },
  40. {
  41. "score": 0.00009999999747378752,
  42. "key": "认可"
  43. },
  44. {
  45. "score": 0.0,
  46. "key": "感谢"
  47. }
  48. ],
  49. "content": "图形验证码输入老是错误"
  50. },
  51. "code": 0,
  52. "cost": 2.271,
  53. "message": "SUCCESS"
  54. }

服务说明

说明 服务名称(ServiceName)当前支持高性能版和高精度版两个版本,可以按需选择
服务名称(ServiceName) 说明
DeepEmotion 高性能版,速度较快,精度略低
DeepEmotionBert 高精度版,精度较高,速度略慢

入参说明

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

出参说明

说明 支持文本同时命中多种情绪的情况
参数 说明
code 状态码,0表示正常;1002表示参数错误(通常需检查输入是否符合json格式);10016表示请求超过长度限制(1000字),减小请求长度;10015表示缺少必选参数
content 来自入参,检测的文本样例,长度不超过1000字
sentiment 识别到的情绪列表,当前包含8种常规情绪(高兴、喜好、悲伤、愤怒、厌恶、惊讶、恐惧,认可)和3种业务场景常用情绪(感谢、抱怨、投诉)
key 情绪名称
score 情绪概率,0-1之间,大于0.5可认为命中该情绪类型。