全部产品

商品标题类目预测

更新时间:2020-10-19 15:32:40

商品标题类目预测服务适用于针对电商场景的商品标题,预测所属的类目,类目体系和淘宝一致。使用示例如下。

Java代码示例

  1. DefaultProfile defaultProfile = DefaultProfile.getProfile("cn-hangzhou","your-access-id-key","your-access-id-secret");
  2. IAcsClient client = new DefaultAcsClient(defaultProfile);
  3. Map<String, Object> map = new HashMap<>();
  4. map.put("input", "壁纸");
  5. map.put("topk", 1);
  6. RunPreTrainServiceRequest request = new RunPreTrainServiceRequest();
  7. request.setServiceName("NLP-E-Commerce-Category");
  8. request.setPredictContent(JSON.toJSONString(map));
  9. RunPreTrainServiceResponse response = client.getAcsResponse(request);
  10. 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": "壁纸","topk":1}
  14. # Initialize a request and set parameters
  15. request = RunPreTrainServiceRequest.RunPreTrainServiceRequest()
  16. request.set_ServiceName('NLP-E-Commerce-Category')
  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. "topk":1
  4. }

PredictResult内容示例

  1. {
  2. "label": [
  3. {
  4. "score": 0.8,
  5. "key": "家装主材-墙纸-纯纸墙纸",
  6. "id":"27-50013322-50024689"
  7. }
  8. ]
  9. }

入参说明

参数 说明
input 商品标题
topk 必填,数字类型,返回指定数量的预测类目,概率从高到低

出参说明

参数 说明
key 识别到的类目,层次结构,结构为一级类目[-二级类目-三级类目-四级类目-叶子类目],最少为一级类目,最多为五级类目
id key对应的ID
score 预测类目的概率,数字范围为(0-1]之间