The product description generation (Chinese) service is based on the PALM 2.0 Chinese base model. You can use this service to generate product descriptions that highlight specific selling points for a given product.
The PALM model has the following features:
Enhanced comprehension: Pre-training tasks are specifically designed for conditional generation to enhance the model's contextual understanding.
Less annotation required: The model is pre-trained on a massive text corpus. This greatly reduces the amount of labeled data required for downstream generation tasks.
Excellent performance: Both the Chinese and English models are trained on large-scale data. They use a self-developed pre-training objective adapted for Natural Language Generation (NLG) tasks.
Adaptable to various generation tasks: PALM can be used for different generation tasks, such as summarization, question generation, and paraphrasing.
Easy to use: The model is based on the traditional encoder-decoder framework for generation, which makes it easy to apply to downstream tasks.
This service is provided by the NLP Self-Learning Platform. You can use the service by calling the API directly.
Service activation and resource plan purchase
Before you start, ensure that the service is activated. After activation, you can purchase a resource plan.
Activate service: Activation link
Purchase resource plan: Purchase link
Service invocation and debugging
For more information about how to call the model, see Model invocation.
For software development kit (SDK) examples, see SDK examples.
Debug
Configure access credentials (AKSK) using environment variables
Notes:
The AccessKey of an Alibaba Cloud account provides full access permissions to all APIs. This poses a high security risk. We strongly recommend that you create and use a Resource Access Management (RAM) user to make API calls or perform routine operations and maintenance (O&M). To create a RAM user, log on to the RAM console.
To avoid security risks that can arise from leaked keys, do not hard-code your AccessKey ID and AccessKey secret in your code. Instead, use environment variables to store and access your AccessKey pair.
Configuration 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 ID and an AccessKey secret, see Step 2: Obtain an AccessKey.
Configuration method for Windows
Create a file for the environment variables. Add the
NLP_AK_ENVandNLP_SK_ENVenvironment variables and set their values to your AccessKey ID and AccessKey secret.Restart Windows.
Java code example
/**
* An AccessKey of an Alibaba Cloud account has full access permissions to all APIs. This poses a high security risk. We strongly recommend that you create and use a RAM user to make API calls or perform routine O&M. To create a RAM user, log on to the RAM console.
* 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.
* To avoid security risks, do not hard-code your AccessKey ID and AccessKey secret in your code.
*/
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);
RunPreTrainServiceRequest request = new RunPreTrainServiceRequest();
request.setServiceName("text_generation_commodity");
request.setPredictContent("Trash can, double-layer, detachable, heightened, heightened double-layer, handle, trash can, built-in, universal wheel");
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 of an Alibaba Cloud account has full access permissions to all APIs. This poses a high security risk. We strongly recommend that you create and use a RAM user to make API calls or perform routine O&M. To create a RAM user, log on to the RAM console.
# 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.
# To avoid security risks, do not hard-code your AccessKey ID and AccessKey secret in your code.
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 = "Trash can, double-layer, detachable, heightened, heightened double-layer, handle, trash can, built-in, universal wheel"
# Initialize a request and set parameters
request = RunPreTrainServiceRequest.RunPreTrainServiceRequest()
request.set_ServiceName('text_generation_commodity')
request.set_PredictContent(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)PredictContent example
Trash can, double-layer, detachable, heightened, heightened double-layer, handle, trash can, built-in, universal wheelPredictResult example
{
"RequestId": "A398D3B4-5B85-5ADB-89AD-ED39023952B7",
"PredictResult": "[{\"output\":\"Heightened double-layer trash can with a built-in detachable handle for easy movement. The universal wheel design at the bottom makes it convenient to move.\",\"cost\":\"3181.234ms\"}]"
}Request parameters
Parameter | Description |
content | Required. The content of the document to be processed. We recommend that the content does not exceed 500 characters. If the content exceeds 500 characters, the service truncates it. |
Response parameters
Parameter | Description |
output | The generated product description. |
cost | The time consumed by the service. |