Generative text summarization

更新时间:
复制 MD 格式

The generative text summarization service is based on the PALM 2.0 Chinese summary generation model. This service is designed for common text generation tasks in real-world scenarios, such as generating text summaries or article titles.

The PALM model has the following features:

  • Stronger comprehension: A pre-training task is 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 needed 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 various 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 use for downstream tasks.

Note

This service is provided by the NLP Self-Learning Platform and can be used by directly calling the API.

Activate the service and purchase a resource plan

Before you use the service, ensure that it is activated. After activation, you can purchase a resource plan.

Service invocation and debugging

For information about how to invoke the model, see Model invocation.

For software development kit (SDK) examples, see SDK examples.

Debug

You can run this API operation directly in OpenAPI Explorer to simplify signature calculations. After a successful call, OpenAPI Explorer automatically generates SDK code examples.

Configure access credentials (AccessKey ID and AccessKey secret) using environment variables

  1. Notes:

    1. An AccessKey pair from an Alibaba Cloud account has permissions for all API operations. This creates a high security risk. We recommend that you create and use a Resource Access Management (RAM) user to call API operations or perform routine O&M. To create a RAM user, log on to the RAM console.

    2. To prevent security risks, do not hard-code your AccessKey ID and AccessKey secret in your code. This section describes how to use environment variables to store and access your AccessKey pair.

  2. 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 pair.

  3. Windows configuration

    1. Create a file for environment variables. Add the NLP_AK_ENV and NLP_SK_ENV environment variables. Then, set their values to your AccessKey ID and AccessKey secret.

    2. Restart the Windows system.

Java code example

/**
 * An AccessKey pair of an Alibaba Cloud account has permissions on all API operations. This poses a high security threat. We recommend that you create and use a RAM user to call API operations or perform routine O&M. To create a RAM user, log on to the RAM console.
 * This example shows how to store an AccessKey ID and an AccessKey secret in environment variables. You can also store them in a configuration file as needed.
 * To prevent 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_summary");
request.setPredictContent("Do not dismantle the range hood for cleaning. A small piece of soap can clean it in minutes. It is simple and practical. Hello everyone, I am a helper from Shenzhen Helper Group, dedicated to sharing home life hacks. Please follow for more! I previously discussed how professional cleaners wash range hoods. Many friends commented that they lack professional tools and would prefer simple, everyday tips that do not require disassembly. In response, I have been researching and testing methods. I can now share a few practical tricks to quickly remove grease. Let's learn together! Tip 1: Household soap and toilet paper. Surprise! Did you think I was going to mention baking soda or range hood cleaner? No way! As I said, these are everyday methods. Every home has soap and toilet paper. I have personally tested this: crush leftover soap into a paste. Use an old toothbrush or your hands to apply it to the range hood. Use warm water! After a few minutes, the grease will dissolve. Then, wipe it with toilet paper. There is no need to dismantle the range hood at all. It will be sparkling clean! Tip 2: Dish soap and white vinegar. Many people have used dish soap to clean their range hoods but may not have mastered the technique, leading to inconsistent results. I personally recommend using a mixture of dish soap and white vinegar to scrub the range hood panel and grease trap. To clean the grease trap, remove it and soak it in warm water with dish soap for about half an hour. Then, wipe it with a cloth to see a significant difference! Both methods can be done at home without purchasing many tools. To clean your range hood, give these a try!");
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: utf-8 -*-
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 pair of an Alibaba Cloud account has permissions on all API operations. This poses a high security threat. We recommend that you create and use a RAM user to call API operations or perform routine O&M. To create a RAM user, log on to the RAM console.
# This example shows how to store an AccessKey ID and an AccessKey secret in environment variables. You can also store them in a configuration file as needed.
# To prevent 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 = "Do not dismantle the range hood for cleaning. A small piece of soap can clean it in minutes. It is simple and practical. Hello everyone, I am a helper from Shenzhen Helper Group, dedicated to sharing home life hacks. Please follow for more! I previously discussed how professional cleaners wash range hoods. Many friends commented that they lack professional tools and would prefer simple, everyday tips that do not require disassembly. In response, I have been researching and testing methods. I can now share a few practical tricks to quickly remove grease. Let's learn together! Tip 1: Household soap and toilet paper. Surprise! Did you think I was going to mention baking soda or range hood cleaner? No way! As I said, these are everyday methods. Every home has soap and toilet paper. I have personally tested this: crush leftover soap into a paste. Use an old toothbrush or your hands to apply it to the range hood. Use warm water! After a few minutes, the grease will dissolve. Then, wipe it with toilet paper. There is no need to dismantle the range hood at all. It will be sparkling clean! Tip 2: Dish soap and white vinegar. Many people have used dish soap to clean their range hoods but may not have mastered the technique, leading to inconsistent results. I personally recommend using a mixture of dish soap and white vinegar to scrub the range hood panel and grease trap. To clean the grease trap, remove it and soak it in warm water with dish soap for about half an hour. Then, wipe it with a cloth to see a significant difference! Both methods can be done at home without purchasing many tools. To clean your range hood, give these a try!"
# Initialize a request and set parameters
request = RunPreTrainServiceRequest.RunPreTrainServiceRequest()
request.set_ServiceName('text_generation_summary')
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

Do not dismantle the range hood for cleaning. A small piece of soap can clean it in minutes. It is simple and practical. Hello everyone, I am a helper from Shenzhen Helper Group, dedicated to sharing home life hacks. Please follow for more! I previously discussed how professional cleaners wash range hoods. Many friends commented that they lack professional tools and would prefer simple, everyday tips that do not require disassembly. In response, I have been researching and testing methods. I can now share a few practical tricks to quickly remove grease. Let's learn together! Tip 1: Household soap and toilet paper. Surprise! Did you think I was going to mention baking soda or range hood cleaner? No way! As I said, these are everyday methods. Every home has soap and toilet paper. I have personally tested this: crush leftover soap into a paste. Use an old toothbrush or your hands to apply it to the range hood. Use warm water! After a few minutes, the grease will dissolve. Then, wipe it with toilet paper. There is no need to dismantle the range hood at all. It will be sparkling clean! Tip 2: Dish soap and white vinegar. Many people have used dish soap to clean their range hoods but may not have mastered the technique, leading to inconsistent results. I personally recommend using a mixture of dish soap and white vinegar to scrub the range hood panel and grease trap. To clean the grease trap, remove it and soak it in warm water with dish soap for about half an hour. Then, wipe it with a cloth to see a significant difference! Both methods can be done at home without purchasing many tools. To clean your range hood, give these a try!

PredictResult example

{
  "RequestId": "CD485B7E-2FD7-17A8-AD3E-4F42E406FC5E",
  "PredictResult": "[{\"output\":\"Tips for cleaning a range hood\",\"cost\":\"665.461ms\"}]"
}

Request parameters

Parameter

Note

content

Required. The content of the document to be summarized. The service truncates content that exceeds 500 characters.

Response parameters

Parameter

Description

output

The generated text summary.

cost

The time consumed by the service.