すべてのプロダクト
Search
ドキュメントセンター

MaxCompute:MaxCompute パブリックモデルを使用してオンラインコメントの感情分析を実行する

最終更新日:Nov 09, 2025

このトピックでは、MaxCompute パブリックモデルを使用してオンラインコメントの感情分析を実行する方法について説明します。

シナリオの説明

ソーシャルメディアと e コマースの急速な成長により、オンラインユーザーのコメントが急増しています。これらのコメントには、世論や意見が豊富に含まれています。これらのコメントの感情分析は、世論のモニタリング、ブランド管理、およびプロダクトの最適化にとって不可欠なツールとなっています。このトピックでは、MaxCompute で SQL を使用して AI 関数を呼び出す実際の例を示します。Qwen3-0.6B-GGUF などの組み込みパブリック large モデルを使用すると、コメントから感情を直接分類し、地理情報を抽出できます。このプロセスは、安全で管理された環境内で実行されます。モデルのデプロイ、外部サービスの使用、データの移動は不要です。これにより、分析の効率と利便性が大幅に向上します。

利点

  • MaxCompute パブリックモデルと AI 関数を備えたシンプルな SQL を使用して、テキストの感情分析などの複雑なデータ分析タスクを実行できます。モデルのデプロイや関数の開発は必要ありません。

  • 分析プロセスは完全にプラットフォーム内で実行されます。データ移行や外部サービスが不要なため、データのセキュリティとコンプライアンスが保証されます。

  • このアプローチは、参入障壁を下げ、分析効率を向上させます。静的なマッピングテーブルや正規表現などの従来の方法と比較して、より優れた拡張性と柔軟性を提供します。高いメンテナンスコストをかけずに複雑な関係を処理できるため、使いやすく、ビジネスフレンドリです。

前提条件

MaxCompute の有効化MaxCompute プロジェクトの作成を行います。すでにこの操作を完了している場合は、このステップをスキップしてください。

データの準備

この例のコマンドは、ローカルクライアント (odpscmd) で実行されます。

テーブルの作成

詳細については、「テーブルの作成と削除」をご参照ください。

CREATE TABLE IF NOT EXISTS emotional_comment
(
    content_id      STRING COMMENT 'コメント ID',
    text            STRING COMMENT 'コメント内容',
    publish_time    STRING COMMENT 'コメント時間',
    user_id         STRING COMMENT 'ユーザー ID',
    user_followers  STRING COMMENT 'ユーザーフォロワー数',
    user_region     STRING COMMENT 'ユーザーリージョン',
    repost_count    STRING COMMENT 'リポスト数',
    comment_count   STRING COMMENT 'コメント数',
    quote_count     STRING COMMENT '引用数'
);

データのインポート

サンプルデータファイルをダウンロードします: 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         |
+------------------+--------------------------------------------------------------------------------------------------+---------------+------------+----------------+-------------+--------------+---------------+-------------+

パブリックモデルの表示

SQL コマンドを実行して、パブリックモデル Qwen3-0.6B を表示します。

-- フラグを設定します。
SET odps.task.major.version=flighting;
SET odps.sql.using.public.model=true;
SET odps.namespace.schema=false;

-- パブリックモデルの詳細を表示します。
DESC MODEL bigdata_public_modelset.Qwen3-0.6B-GGUF;

+------------------------------------------------------------------------------------+
|                  モデル情報                                                        |
+------------------------------------------------------------------------------------+
| 所有者:                   ALIYUN$od**@aliyun-inner.com                             |
| プロジェクト:             bigdata_public_modelset                                  |
| モデル名:                 Qwen3-0.6B-GGUF                                          |
| モデルタイプ:             LLM                                                      |
| ソースタイプ:             IMPORT                                                   |
| デフォルトバージョン:     v1                                                       |
| 作成時間:                 2025-09-25 23:35:31                                      |
| 最終変更日時:             2025-09-25 23:35:31                                      |
| コメント:                 8 ビット混合量子化 (Q8_0) を使用した MaxCompute パブリック LLM モデル Qwen3-0.6B-GGUF、デフォルト設定 {"max_tokens": 500, "temperature": 0.6, "top_p": 0.95} を使用。ソース:https://huggingface.co/unsloth/Qwen3-0.6B-GGUF |
+------------------------------------------------------------------------------------+
|                バージョン情報                                                      |
+------------------------------------------------------------------------------------+
| 所有者:                   ALIYUN$****@aliyun-inner.com                             |
| プロジェクト:             bigdata_public_modelset                                  |
| モデル名:                 Qwen3-0.6B-GGUF                                          |
| モデルタイプ:             LLM                                                      |
| ソースタイプ:             IMPORT                                                   |
| バージョン名:             v1                                                       |
| パス:                                                                              |
| 作成時間:                 2025-09-25 23:35:31                                      |
| 最終変更日時:             2025-09-25 23:35:31                                      |
+------------------------------------------------------------------------------------+
| 入力            | タイプ     | コメント                                            |
+------------------------------------------------------------------------------------+
| prompt          | string     |                                                     |
| settings        | string     |                                                     |
+------------------------------------------------------------------------------------+

データ分析

次のサンプルコードは、MaxCompute でパブリック large モデル Qwen3-0.6B-GGUF と共に AI_GENERATE 関数を使用する方法を示しています。1 つの SQL クエリで 2 つの AI 推論タスクを実行できます:

  1. 地理情報の解析: ユーザーコメントの都市名 (「西安」など) から省レベルの行政区 (「陝西省」など) を自動的に推測します。

  2. 感情分類: コメントテキストの感情分析を実行し、標準化されたラベル (「肯定的」、「否定的」、または「中立」) を出力します。

関数の使用方法の詳細については、「AI_GENERATE」をご参照ください。

-- AI_GENERATE 関数を使用して組み込みの Qwen3 モデルを呼び出し、省名と感情分析ラベルを生成します。
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.                       |
+------------------------------------+----------------+--------------------+--------------------------------------------------------------------------------------------------+