このトピックでは、大規模言語モデル (LLM) を使用して AI_SENTIMENT 関数で感情分析を行う方法について説明します。
制限事項
この関数は、リアルタイム計算エンジンの 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 | 子供が音を当てるシーンが大好きでした。映画で見た中で最もロマンチックな物語の一つです。とても優しく、愛に満ちています。 | POSITIVE |
2 | Dumpling Queen | 特筆すべきことはありません。 | 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 loved the part where the child guessed sounds. It was one of the most romantic narratives I\'ve seen in a movie. Very gentle and full of love.', 'positive'), (2, 'Dumpling Queen', 'Nothing remarkable.', 'negative');
-- Use positional argument to call AI_SENTIMENT
SELECT id, movie_name, actual_label, score, label, confidence FROM movie_comment,
LATERAL TABLE(
AI_SENTIMENT(
MODEL general_model, user_comment));
-- Use named argument to call 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 |