この Topic では、AI_SENTIMENT 関数を使用して大規模 AI モデルで感情分析を実行する方法について説明します。
制限事項
この関数は、Ververica Runtime (VVR) 11.4 以降でのみサポートされています。
AI_SENTIMENT 文の Flink オペレーターのスループットは、モデルプラットフォームのトラフィック速度制限によって制限されます。トラフィックがプラットフォームの上限に達すると、Flink ジョブにバックプレッシャーが発生し、このオペレーターがボトルネックになります。深刻な速度制限は、オペレーターのタイムアウトエラーやジョブの再起動を引き起こす可能性があります。
構文
AI_SENTIMENT(
MODEL => MODEL <MODEL NAME>,
INPUT => <INPUT COLUMN NAME>
)入力パラメーター
パラメーター | データ型 | 説明 |
MODEL <MODEL NAME> | MODEL | 登録済みのモデルサービスの名前。詳細については、「モデル設定」をご参照ください。 注意:モデルの出力タイプは VARIANT である必要があります。 |
<INPUT COLUMN NAME> | STRING | モデルで分析されるデータ。 |
出力
パラメーター | データ型 | 説明 |
score | DOUBLE | モデルによって決定される感情スコア。-1.0 から 1.0 の範囲です:
|
label | STRING | 感情ラベル (positive、negative、または neutral)。 |
confidence | DOUBLE | モデルの出力の信頼度。 |
例
サンプルデータ
id | movie_name | comment | actual_label |
1 | Good Stuff | I love the part where the child guesses the voice. It's one of the most romantic narratives I've seen in a movie. Very gentle and full of love. | POSITIVE |
2 | Dumpling Queen | Unremarkable | NEGATIVE |
サンプル文
次のサンプル SQL 文は、Qwen-Plus モデルを作成し、AI_SENTIMENT 関数を使用して映画レビューの感情分類を予測します。
CREATE TEMPORARY MODEL general_model
INPUT (`input` STRING)
OUTPUT (`content` VARIANT)
WITH (
'provider' = 'openai-compat',
'endpoint'='<YOUR ENDPOINT>',
'apiKey' = '<YOUR KEY>',
'model' = 'qwen-plus'
);
CREATE TEMPORARY VIEW movie_comment(id, movie_name, user_comment, actual_label)
AS VALUES (1, 'Good Stuff', 'I love the part where the child guesses the voice. It''s one of the most romantic narratives I''ve seen in a movie. Very gentle and full of love.', 'positive'), (2, 'Dumpling Queen', 'Unremarkable', 'negative');
-- 位置引数を使用して AI_SENTIMENT を呼び出す
SELECT id, movie_name, actual_label, score, label, confidence FROM movie_comment,
LATERAL TABLE(
AI_SENTIMENT(
MODEL general_model, user_comment));
-- 名前付き引数を使用して AI_SENTIMENT を呼び出す
SELECT id, movie_name, actual_label, score, label, confidence FROM movie_comment,
LATERAL TABLE(
AI_SENTIMENT(
MODEL => MODEL general_model,
INPUT => user_comment)); 出力結果
label 列の予測結果は、actual_label 列の実際の結果と一致します。
id | movie_name | actual_label | score | label | confidence |
1 | Good Stuff | positive | 0.8 | positive | 0.95 |
2 | Dumpling Queen | negative | -1.0 | negative | 0.95 |