The Generate weather report welcome messages (Chinese) service is based on the PALM 2.0 base model for Chinese product description generation. It generates in-vehicle startup welcome messages from specified weather information fields.
The PALM model has the following features:
Stronger comprehension: A pre-training task designed specifically for conditional generation enhances the model's contextual understanding.
Fewer annotations required: The model is pre-trained on massive text corpora. 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 self-developed pre-training objectives adapted for Natural Language Generation (NLG) tasks.
Adaptable to various generation tasks: PALM can be used for a variety of generation tasks, such as summarization, question generation, and paraphrasing.
Easy to use: The model is easy to use for downstream tasks and is based on the traditional encoder-decoder framework for generation.
This service is provided by the NLP Self-Learning Platform. To use the service, call the API directly.
Activate the service and purchase a resource plan
Before you start, confirm that the service is activated. After activation, you can purchase a resource plan.
Activate the service: Activation page
Purchase a resource plan: Purchase page
Invoke and test the service
For information about how to invoke the model, see Model invocation.
For information about software development kit (SDK) examples, see SDK examples.
Debug
Configure access credentials using environment variables
Notes:
An AccessKey of an Alibaba Cloud account has permissions to access all APIs. This poses a high security risk. We recommend that you create and use a Resource Access Management (RAM) user to make API calls or perform O&M. To create a RAM user, log on to the RAM console.
Do not save your AccessKey ID and AccessKey secret in your code to avoid security risks. Instead, configure environment variables to store and access your credentials.
Configure on 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 information about how to obtain an AccessKey ID and an AccessKey secret, see Step 2: Obtain an AccessKey.
Configure on Windows
Create a file for environment variables. 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 of an Alibaba Cloud account has permissions to access all APIs. This poses a high security risk.
* We recommend that you create and use a RAM user to make API calls or perform 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.
* Do not save your AccessKey ID and AccessKey secret in your code to avoid security risks.
*/
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_weather");
request.setPredictContent("today_weather_type='floating_dust'&air_quality_level='heavy_pollution'&uv_index='moderate'");
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 permissions to access all APIs. This poses a high security risk.
# We recommend that you create and use a RAM user to make API calls or perform 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.
# Do not save your AccessKey ID and AccessKey secret in your code to avoid security risks.
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 = "today_weather_type='floating_dust'&air_quality_level='heavy_pollution'&uv_index='moderate'"
# Initialize a request and set parameters
request = RunPreTrainServiceRequest.RunPreTrainServiceRequest()
request.set_ServiceName('text_generation_weather')
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
today_weather_type='floating_dust'&air_quality_level='heavy_pollution'&uv_index='moderate'PredictResult example
{
"RequestId": "63A1724A-74D8-56B5-8B60-0B06FFADA76B",
"PredictResult": "[{\"output\":\"Today, there is floating dust, and the air is heavily polluted. The UV index is moderate. Apply sunscreen. The dust can reduce visibility, so drive safely.\",\"cost\":\"4580.771ms\"}]"
}Request parameters
Parameter | Description |
content | Required. The content to process. The content cannot exceed 500 characters. If the content exceeds 500 characters, the service truncates it. For the required format, see the example. |
Response parameters
Parameter | Description |
output | The generated welcome message for the weather report. |
cost | The time it takes for the service to process the request. |