All Products
Search
Document Center

MaxCompute:Perform sentiment analysis on online comments using a MaxCompute public model

Last Updated:Feb 27, 2026

This topic shows how to use a MaxCompute public model to perform sentiment analysis on online comments.

Use case

The rapid growth of social media and e-commerce has led to a surge in online user comments. These comments are rich in public sentiment and opinions. Sentiment analysis of these comments has become a vital tool for public opinion monitoring, brand management, and product optimization. This topic shows a real-world example of how to use SQL in MaxCompute to call an AI function. Using a built-in public large model, such as Qwen3-0.6B-GGUF, you can directly classify sentiment and extract geographic information from comments. This process occurs within a secure and controlled environment. You do not need to deploy models, use external services, or move data. This greatly improves the efficiency and convenience of your analysis.

Advantages

  • You can perform complex data analysis tasks, such as text sentiment analysis, using simple SQL with MaxCompute public models and AI functions. No model deployment or function development is required.

  • The analysis process runs entirely within the platform. This ensures data security and compliance because no data migration or external services are needed.

  • This approach lowers the barrier to entry and improves analysis efficiency. Compared to traditional methods such as static mapping tables or regular expressions, it offers greater extensibility and flexibility. It can handle complex relationships without high maintenance costs, making it easier to use and more business-friendly.

Prerequisites

Activate MaxCompute and create a MaxCompute project. If you have already done this, skip this step.

Prepare data

The commands in this example are run on a local client (odpscmd).

Create a table

For more information, see Create and delete tables.

CREATE TABLE IF NOT EXISTS emotional_comment
(
    content_id      STRING COMMENT 'Comment ID',
    text            STRING COMMENT 'Comment content',
    publish_time    STRING COMMENT 'Comment time',
    user_id         STRING COMMENT 'User ID',
    user_followers  STRING COMMENT 'Number of user followers',
    user_region     STRING COMMENT 'User region',
    repost_count    STRING COMMENT 'Number of reposts',
    comment_count   STRING COMMENT 'Number of comments',
    quote_count     STRING COMMENT 'Number of likes'
);

Import data

Download the sample data file: demo_comment.csv.

TUNNEL UPLOAD demo_comment.csv emotional_comment;

SELECT * FROM emotional_comment LIMIT 10;

+------------------+--------------------------------------------------------------------------------------------------+---------------+------------+----------------+-------------+--------------+---------------+-------------+
| content_id       | text                                                                                             | publish_time  | user_id    | user_followers | user_region | repost_count | comment_count | quote_count |
+------------------+--------------------------------------------------------------------------------------------------+---------------+------------+----------------+-------------+--------------+---------------+-------------+
| 5087a5a3c22e3f4c | The weather is great today, and I'm in a good mood! It's sunny and perfect for a walk.             | 2025/5/27 12:49 | user_918561 | 132169         | Xi'an       | 1015         | 3197          | 1300        |
| 299aa8f97b6fee2f | The weather is great today, and I'm in a good mood! It's sunny and perfect for a walk.             | 2025/5/31 07:46 | user_403208 | 669019         | Hohhot      | 6616         | 4876          | 201         |
| e7ee00dec51b28f6 | Technology is advancing rapidly, and artificial intelligence is changing lives.                    | 2025/5/17 11:39 | user_291936 | 840757         | Nanning     | 264          | 3668          | 174         |
| 0c0d61608cabbac3 | The control measures are excellent. Kudos to the medical staff!                                    | 2025/5/18 03:29 | user_154572 | 925604         | Fuzhou      | 2154         | 652           | 470         |
| 106b979787b580d1 | The weather is great today, and I'm in a good mood! It's sunny and perfect for a walk.             | 2025/5/28 14:45 | user_528807 | 656952         | Qingdao     | 6617         | 3890          | 1275        |
| 05b0e2ef4636d5c9 | Environmental awareness needs to be further raised to protect our planet.                          | 2025/5/16 09:06 | user_693289 | 211093         | Foshan      | 4283         | 1592          | 1792        |
| c9773c4a632a8839 | The service at this restaurant is great, and the food is delicious. Highly recommended.            | 2025/5/21 19:19 | user_850376 | 817461         | Shenyang    | 9552         | 3974          | 1740        |
| 089e0c5dddc53198 | Environmental awareness needs to be further raised to protect our planet.                          | 2025/5/17 10:58 | user_800324 | 716599         | Harbin      | 5725         | 4437          | 939         |
| 04fd7323a957d978 | The effects of education reform measures need more time to be observed.                            | 2025/5/26 01:25 | user_544689 | 416372         | Hefei       | 1440         | 4185          | 416         |
| 04cf4066c5c1e9c7 | The service at this restaurant is great, and the food is delicious. Highly recommended.            | 2025/5/27 03:49 | user_373334 | 722353         | Changchun   | 1134         | 3936          | 773         |
+------------------+--------------------------------------------------------------------------------------------------+---------------+------------+----------------+-------------+--------------+---------------+-------------+

View the public model

Run the SQL command to view the public model Qwen3-0.6B.

-- Set flags.
SET odps.task.major.version=flighting;
SET odps.sql.using.public.model=true;
SET odps.namespace.schema=false;

-- View details of the public model.
DESC MODEL bigdata_public_modelset.Qwen3-0.6B-GGUF;

+------------------------------------------------------------------------------------+
|                  Model Information                                                 |
+------------------------------------------------------------------------------------+
| Owner:                    ALIYUN$od**@aliyun-inner.com                             |
| Project:                  bigdata_public_modelset                                  |
| Model Name:               Qwen3-0.6B-GGUF                                          |
| Model Type:               LLM                                                      |
| Source Type:              IMPORT                                                   |
| Default Version:          v1                                                       |
| CreateTime:               2025-09-25 23:35:31                                      |
| LastModifiedTime:         2025-09-25 23:35:31                                      |
| Comment:                  MaxCompute Public LLM Model Qwen3-0.6B-GGUF with 8-bit mixed quantization (Q8_0), using default settings {"max_tokens": 500, "temperature": 0.6, "top_p": 0.95}. Source:https://huggingface.co/unsloth/Qwen3-0.6B-GGUF |
+------------------------------------------------------------------------------------+
|                Version Information                                                 |
+------------------------------------------------------------------------------------+
| Owner:                    ALIYUN$****@aliyun-inner.com                             |
| Project:                  bigdata_public_modelset                                  |
| Model Name:               Qwen3-0.6B-GGUF                                          |
| Model Type:               LLM                                                      |
| Source Type:              IMPORT                                                   |
| Version Name:             v1                                                       |
| Path:                                                                              |
| CreateTime:               2025-09-25 23:35:31                                      |
| LastModifiedTime:         2025-09-25 23:35:31                                      |
+------------------------------------------------------------------------------------+
| Input           | Type       | Comment                                             |
+------------------------------------------------------------------------------------+
| prompt          | string     |                                                     |
| settings        | string     |                                                     |
+------------------------------------------------------------------------------------+

Data analysis

The following example code shows how to use the AI_GENERATE function in MaxCompute with the public large model Qwen3-0.6B-GGUF. You can perform two AI inference tasks in a single SQL query:

  1. Geographic information parsing: Automatically infer the provincial administrative region (such as "Shaanxi Province") from the city name in the user comment (such as "Xi'an").

  2. Sentiment classification: Perform sentiment analysis on the comment text and output a standardized label ("Positive", "Negative", or "Neutral").

For more information about how to use the function, see AI_GENERATE.

-- Call the built-in Qwen3 model using the AI_GENERATE function to generate province names and sentiment analysis labels.
SELECT 
  AI_GENERATE(
    bigdata_public_modelset.Qwen3-0.6B-GGUF,
    default_version,
    CONCAT(
      'Provide the province for the following city. If the city is a municipality or a special administrative region, display the city name directly. The output should only contain the province name. City name:',user_region),
    '{"max_tokens": 1000, "temperature": 0.7}'
  ) as province,
  user_region,
  AI_GENERATE(
    bigdata_public_modelset.Qwen3-0.6B-GGUF,
    default_version,
    CONCAT(
      'Perform sentiment analysis and classification on the following comment. The output must be one of these three options: Positive, Negative, or Neutral. Comment to analyze:', text),
    '{"max_tokens": 1000, "temperature": 0.7}'
  ) as sentiment_label,
  text
  FROM emotional_comment limit 20
;

+------------------------------------+----------------+--------------------+--------------------------------------------------------------------------------------------------+
| province                           | user_region    | sentiment_label    | text                                                                                             |
+------------------------------------+----------------+--------------------+--------------------------------------------------------------------------------------------------+
| "Shaanxi Province"                 | Xi'an          | "Positive"         | The weather is great today, and I'm in a good mood! It's sunny and perfect for a walk.             |
| "Inner Mongolia Autonomous Region" | Hohhot         | "Positive"         | The weather is great today, and I'm in a good mood! It's sunny and perfect for a walk.             |
| "Guangxi"                          | Nanning        | "Positive"         | Technology is advancing rapidly, and artificial intelligence is changing lives.                    |
| "Fujian Province"                  | Fuzhou         | "Positive"         | The control measures are excellent. Kudos to the medical staff!                                    |
| "Hebei Province"                   | Qingdao        | "Positive"         | The weather is great today, and I'm in a good mood! It's sunny and perfect for a walk.             |
| "Gansu Province"                   | Lanzhou        | "Neutral"          | The effects of education reform measures need more time to be observed.                            |
| "Fujian Province"                  | Fuzhou         | "Positive"         | Technology is advancing rapidly, and artificial intelligence is changing lives.                    |
| "Hunan Province"                   | Changsha       | "Negative"         | I strongly protest this measure. It's completely unreasonable!                                   |
| "Sichuan Province"                 | Chongqing      | "Positive"         | The control measures are excellent. Kudos to the medical staff!                                    |
| "Guangdong Province"               | Guangzhou      | "Positive"         | Food safety issues cannot be ignored. Regulation must be stricter.                               |
| "Shaanxi Province"                 | Xi'an          | "Negative"         | The stock market has been very volatile recently. Invest with caution.                              |
| "Shandong Province"                | Jinan          | "Positive"         | The weather is great today, and I'm in a good mood! It's sunny and perfect for a walk.             |
| "Hebei Province"                   | Tianjin        | "Positive"         | The new product launch was a success. Looking forward to future developments.                      |
| "Hebei Province"                   | Tianjin        | "Positive"         | The weather is great today, and I'm in a good mood! It's sunny and perfect for a walk.             |
| "Xinjiang"                         | Urumqi         | "Negative"         | Housing prices have gone up again. The pressure on young people to buy a home is increasing.        |
| "Guangxi"                          | Nanning        | "Positive"         | The new product launch was a success. Looking forward to future developments.                      |
| "Qinghai Province"                 | Xining         | "Positive"         | The sporting events are spectacular. Go athletes!                                                  |
| "Heilongjiang Province"            | Harbin         | "Negative"         | The stock market has been very volatile recently. Invest with caution.                             |
| "Heilongjiang Province"            | Harbin         | "Positive"         | The sporting events are spectacular. Go athletes!                                                  |
| "Jiangsu Province"                 | Nanjing        | "Negative"         | The traffic jam was terrible. I was half an hour late for work. So annoying.                       |
+------------------------------------+----------------+--------------------+--------------------------------------------------------------------------------------------------+