AI_Text_Classification

更新时间:
复制 MD 格式

Calls a text comprehension model to perform tasks such as sentiment classification, topic classification, or information extraction on the input text.

Important

Currently, only PolarDB for PostgreSQL Standard Edition clusters in the China (Beijing) region can call the built-in model.

Syntax

text AI_Text_Classification(text content);
text AI_Text_Classification(text content, text model_id);

Parameters

Parameter Name

Description

content

The text that you want to classify.

model_id

The ID of the model. If you do not specify a model, the function calls the built-in model _dashscope/text-classification/opennlu-v1.

Return values

Returns the classification or extraction result.

Description

  • You can call the function without the need to specify a model. If you do not specify a model, the function calls the built-in model _dashscope/text-classfication/opennlu-v1 to perform tasks such as topic classification, sentiment classification, and information extraction.

  • You can specify the model_id parameter to call other existing text understanding models.

  • For more information about the built-in model _dashscope/text-classfication/opennlu-v1, see OpenNLU.

Preparations

The built-in model integrates Natural Language Processing models from Alibaba Cloud Model Studio.

  1. Set the model token: Use the AI_SetModelToken function to set your API key from Alibaba Cloud Model Studio.

  2. Modify the model endpoint: Use the AI_AlterModel function to modify the endpoint of the built-in model. Replace the original endpoint with the PrivateLink endpoint for Alibaba Cloud Model Studio. Change https://dashscope.aliyuncs.com to http://vpc-cn-beijing.dashscope.aliyuncs.com. For example:

    SELECT polar_ai.AI_AlterModel('_dashscope/text-classfication/opennlu-v1', model_url=>'http://vpc-cn-beijing.dashscope.aliyuncs.com/api/v1/services/nlp/nlu/understanding');

Examples

  • Call the function without specifying a model.

    SELECT polar_ai.ai_text_classification ('Teacher praised me today');

    The following shows the result:

    ---
    Positive
  • You can set the model_id parameter to _dashscope/text-classfication/opennlu-v1, which is a built-in model.

    SELECT polar_ai.ai_text_classification ('The food at this restaurant is bad', '_dashscope/text-classfication/opennlu-v1');

    The following is the result:

    ---
    Negative