Calls a text comprehension model to perform tasks such as sentiment classification, topic classification, or information extraction on the input text.
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 |
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-v1to 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.
Set the model token: Use the AI_SetModelToken function to set your API key from Alibaba Cloud Model Studio.
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.comtohttp://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:
--- PositiveYou 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