Classify the sentiment of social media comments and extract geographic entities using a single SQL query — no model deployment required. MaxCompute's built-in AI_GENERATE function lets you call the public large language model (LLM) Qwen3-0.6B-GGUF directly from SQL, keeping all processing within the platform.
Use cases
Public opinion monitoring: Identify sentiment trends across regions to track brand perception or policy response.
E-commerce review analysis: Classify product reviews at scale to surface quality issues or highlight positive feedback.
Social media analytics: Extract the geographic distribution of comments alongside their sentiment for regional insight.
Customer support triage: Route negative feedback automatically by detecting sentiment labels in incoming comments.
Content moderation: Flag negative or sensitive content for human review before it surfaces publicly.
How it works
Load the sample comment data into a MaxCompute table.
Run a SQL query that calls
AI_GENERATEtwice in a single pass — once to map each city to its province, and once to classify the comment sentiment.The model returns structured labels (
Positive,Negative, orNeutral) and province names, ready for downstream aggregation or export.
All processing runs within MaxCompute. No data leaves the platform, and no external model endpoint is required.
Prerequisites
Before you begin, make sure you have:
The local client (odpscmd) installed and configured
Prepare data
Create a table
The following SQL creates the table used throughout this tutorial. 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'
);Load sample data
Download demo_comment.csv, then upload it to the table using the TUNNEL command.
TUNNEL UPLOAD demo_comment.csv emotional_comment;Verify the upload by previewing the first 10 rows.
SELECT * FROM emotional_comment LIMIT 10;Expected output:
+------------------+--------------------------------------------------------------------------------------------------+---------------+------------+----------------+-------------+--------------+---------------+-------------+
| 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 |
+------------------+--------------------------------------------------------------------------------------------------+---------------+------------+----------------+-------------+--------------+---------------+-------------+Verify the public model
Run the following SQL to confirm the model is available and review its configuration.
-- Set the required flags to access the public model.
SET odps.task.major.version=flighting;
SET odps.sql.using.public.model=true;
SET odps.namespace.schema=false;
-- View model details.
DESC MODEL bigdata_public_modelset.Qwen3-0.6B-GGUF;Expected output:
+------------------------------------------------------------------------------------+
| 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 | |
+------------------------------------------------------------------------------------+The model accepts two inputs:
| Input | Type | Description |
|---|---|---|
prompt | string | The instruction passed to the LLM. |
settings | string | A JSON string that overrides default inference parameters, such as max_tokens and temperature. |
Run sentiment analysis
The following query calls AI_GENERATE twice within a single SQL statement — once to infer the province from the city name, and once to classify the comment sentiment. For the full function syntax, see AI_GENERATE.
Set the three session flags shown in the Verify the public model section before running queries that use AI_GENERATE with the public model.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;Expected output:
+------------------------------------+----------------+--------------------+--------------------------------------------------------------------------------------------------+
| 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. |
+------------------------------------+----------------+--------------------+--------------------------------------------------------------------------------------------------+What's next
AI_GENERATE — full function reference, including all supported inference parameters
Create and delete tables — manage tables in MaxCompute