AI_SENTIMENT mengklasifikasikan sentimen dari kolom teks menggunakan Large Language Model (LLM) serta mengembalikan skor, label, dan nilai kepercayaan untuk setiap baris.
Batasan
-
Memerlukan Ververica Runtime (VVR) 11.4 atau versi yang lebih baru.
-
Throughput dibatasi oleh rate limit platform model. Jika rate limit terlampaui, operator Flink mengalami backpressure dan menjadi bottleneck. Dalam kasus parah, hal ini memicu error timeout pada operator dan menyebabkan job restart.
Sintaksis
AI_SENTIMENT(
MODEL => MODEL <model_name>,
INPUT => <input_column>
)
Parameter input
| Parameter | Tipe data | Deskripsi |
|---|---|---|
MODEL <model_name> |
MODEL | Layanan model terdaftar yang akan digunakan. Daftarkan layanan model di Model Settings. Tipe output model harus berupa VARIANT. |
<input_column> |
STRING | Kolom teks yang akan dianalisis. |
Output
AI_SENTIMENT mengembalikan satu baris per baris input dengan kolom-kolom berikut:
| Kolom | Tipe data | Deskripsi |
|---|---|---|
score |
DOUBLE | Skor sentimen dari -1.0 hingga 1.0. Nilai referensi: -1.0 sangat negatif, -0.5 cukup negatif, 0.0 netral, 0.5 cukup positif, 1.0 sangat positif. |
label |
STRING | Klasifikasi sentimen. Nilai yang valid: positive, negative, neutral. |
confidence |
DOUBLE | Tingkat kepercayaan model terhadap label yang diprediksi, antara 0.0 dan 1.0. |
Contoh
Contoh berikut mendaftarkan model Qwen-Plus dan menggunakan AI_SENTIMENT untuk mengklasifikasikan sentimen komentar film.
Data uji
| 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 |
Pernyataan SQL
-- Register the model service
CREATE TEMPORARY MODEL general_model
INPUT (`input` STRING)
OUTPUT (`content` VARIANT)
WITH (
'provider' = 'openai-compat',
'task' = 'chat/completions',
'model' = 'qwen-plus'
);
-- Create a view with the test data
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');
-- Call AI_SENTIMENT using positional arguments
SELECT id, movie_name, actual_label, score, label, confidence
FROM movie_comment,
LATERAL TABLE(
AI_SENTIMENT(MODEL general_model, user_comment));
-- Call AI_SENTIMENT using named arguments
SELECT id, movie_name, actual_label, score, label, confidence
FROM movie_comment,
LATERAL TABLE(
AI_SENTIMENT(
MODEL => MODEL general_model,
INPUT => user_comment));
Ganti placeholder berikut dengan nilai aktual Anda:
| Placeholder | Deskripsi |
|---|
Output
label yang diprediksi sesuai dengan actual_label untuk kedua baris.
| 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 |