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

MaxCompute:AI_CLASSIFY

最終更新日:Jul 25, 2026

AI_CLASSIFY は MaxCompute の AI 関数であり、モデルを呼び出して、指定されたセットの中から入力に最も一致するラベルを返します。

構文

STRING AI_CLASSIFY(
  STRING <model_name>,
  STRING <version_name>,
  STRING <input>,
  ARRAY<STRING> <labels>
  [, STRING <model_parameters>]
);

パラメーター

  • model_name:必須。STRING。使用するモデルの名前。詳細については、「SQL AI 関数」をご参照ください。

  • version_name:必須。STRING。使用するモデルのバージョン名。デフォルトバージョンを呼び出すには、DEFAULT_VERSION を指定します。

  • input:必須。STRING。分類したいテキスト。

  • labels:必須。ARRAY<STRING>。分類用の候補ラベルのリスト。このパラメーターは定数と列入力を受け入れます。定数を使用する場合、ラベルの数は 2 以上 20 以下である必要があります。

  • model_parameters:任意。STRING。`max_tokens`、`temperature`、`top_p` などのモデルパラメーターを指定します。フォーマットは JSON 文字列です:

    '{"max_tokens": 500, "temperature": 0.6, "top_p": 0.95}'

    • max_tokens:1 回のモデル呼び出しで生成されるトークンの最大数。MaxCompute パブリックモデルの場合、デフォルト値は 4,096 です。

    • temperature:0 から 1 までの値で、出力のランダム性を制御します。値が高いほど、より創造的で多様な出力になり、値が低いほど、より決定的で保守的な出力になります。

    • top_p:0 から 1 までの値で、モデルが選択できる候補ラベルの範囲を制限します。値が高いほど範囲が広がり多様性が増し、値が低いほど範囲が狭まり、より焦点の合った結果になります。

戻り値

入力に最も一致するラベルを表す STRING 値を返します。

  • `input` が STRING でない場合、または `labels` が ARRAY<STRING> でない場合は、エラーを返します。

  • `labels` が定数で、ラベルの数が 1 または 20 を超える場合は、エラーを返します。

  • `input` または `labels` が NULL または空文字列 ("") の場合は、NULL を返します。

例 1:定数テキストの分類

MaxCompute が提供するパブリックモデル qwen3.7-max を呼び出して入力テキストを分類し、指定されたラベルの中から最も一致する結果を返します。

SET odps.namespace.schema=true;

SELECT AI_CLASSIFY(
    bigdata_public_modelset.default.`qwen3.7-max`,
    DEFAULT_VERSION,
    'MaxCompute is a fully managed, high-performance big data computing platform that provides fast and scalable data warehousing and analysis capabilities.',
    ARRAY('Technology', 'Sports', 'Finance', 'Healthcare', 'Education')
) AS classified_label;
-- 結果
+------------------+
| classified_label |
+------------------+
| Technology       |
+------------------+

例 2:テーブルデータの分類

MaxCompute パブリックモデル deepseek-v4-pro を呼び出して、テーブル内の複数のテキストデータエントリをバッチ分類できます。

-- サンプルデータ
CREATE TABLE news_articles (
    content STRING
);

INSERT INTO news_articles VALUES
    ('Artificial intelligence is changing the healthcare industry with new diagnostic tools.'),
    ('Driven by a rally in the tech sector, the stock market hit a record high today.'),
    ('The team won the championship after a thrilling overtime.'),
    ('Cloud computing enables businesses to scale their infrastructure on demand.');

-- モデルを使用してテーブル内のテキストを分類
SET odps.namespace.schema=true;

SELECT
    content,
    AI_CLASSIFY(
        bigdata_public_modelset.default.`deepseek-v4-pro`,
        DEFAULT_VERSION,
        content,
        ARRAY('Technology', 'Sports', 'Finance', 'Healthcare')
    ) AS category
FROM news_articles;

-- 結果
+------------------------------------------------------------------------------------------+------------+
| content                                                                                  | category   |
+------------------------------------------------------------------------------------------+------------+
| Artificial intelligence is changing the healthcare industry with new diagnostic tools.   | Healthcare |
| Driven by a rally in the tech sector, the stock market hit a record high today.          | Finance    |
| The team won the championship after a thrilling overtime.                                | Sports     |
| Cloud computing enables businesses to scale their infrastructure on demand.              | Technology |
+------------------------------------------------------------------------------------------+------------+

よくある質問

パブリックモデルに関する問題のトラブルシューティング

現象:MaxCompute Model Computing Service がサポートするパブリックモデルを呼び出すと、サービスから次のエラーメッセージが返されます:

FAILED: ODPS-0130071:[1,8] Semantic analysis exception - inference quota status check failed, error message: region cn-shanghai not found in inference quota

原因:プロジェクトが所在するリージョン (例:cn-shanghai) で MaxCompute Model Computing Service が有効になっていません。そのため、AI 推論リソースを呼び出すことができません。

解決策:Alibaba Cloud コンソールに移動し、プロジェクトが所在するリージョンで MaxCompute Model Computing Service を有効にします。詳細については、「MaxCompute Model Computing Service の購入と使用」をご参照ください。