AI_SENTIMENT は、大規模言語モデル (LLM) を使用してテキストカラムの感情を分類し、各行に対してスコア、ラベル、および信頼度を返します。
制限事項
-
Ververica Runtime (VVR) 11.4 以降が必要です。
-
スループットはモデルプラットフォームのレート制限によって制約されます。レート制限を超えると、Flink 演算子にバックプレッシャーが発生し、ボトルネックとなります。深刻な場合は、演算子のタイムアウトエラーがトリガーされ、ジョブが再起動します。
構文
AI_SENTIMENT(
MODEL => MODEL <model_name>,
INPUT => <input_column>
)
入力パラメーター
| パラメーター | データ型 | 説明 |
|---|---|---|
MODEL <model_name> |
MODEL | 使用する登録済みのモデルサービスです。モデル設定項目でモデルサービスを登録してください。モデルの出力タイプは VARIANT である必要があります。 |
<input_column> |
STRING | 分析対象のテキストカラムです。 |
出力
AI_SENTIMENT は、入力の各行に対して以下のカラムを含む 1 行を返します。
| カラム | データ型 | 説明 |
|---|---|---|
score |
DOUBLE | 感情スコア(-1.0 ~ 1.0)。参考値:-1.0(極めて否定的)、-0.5(やや否定的)、0.0(中立)、0.5(やや肯定的)、1.0(極めて肯定的)。 |
label |
STRING | 感情分類。有効な値:positive、negative、neutral。 |
confidence |
DOUBLE | 予測されたラベルに対するモデルの信頼度(0.0 ~ 1.0 の範囲)。 |
例
以下の例では、Qwen-Plus モデルを登録し、AI_SENTIMENT を使用して映画レビューの感情を分類します。
テストデータ
| id | movie_name | comment | actual_label |
|---|---|---|---|
| 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 |
SQL ステートメント
-- モデルサービスを登録
CREATE TEMPORARY MODEL general_model
INPUT (`input` STRING)
OUTPUT (`content` VARIANT)
WITH (
'provider' = 'openai-compat',
'task' = 'chat/completions',
'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');
-- 位置引数を使用して 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 |