许可证: mit
语言:
- 印尼语
评估指标:
- 准确率
- F1值
基础模型:
- indobenchmark/indobert-base-p2
任务标签: 文本分类
库名称: transformers
标签:
- 金融
数据集:
- siRendy/dataset-analisis-sentimen-review-produk
新版本: siRendy/indobert-analisis-sentimen-review-produk-p2
印尼语情感分类模型 - 双类别
本模型是基于indobenchmark/indobert-base-p2
微调而成,专用于印尼语产品评论的情感分类任务,包含两个标签(正面和负面)。训练数据集包含10,600条来自Tokopedia电商平台的产品评论。
🎯 目标
该模型旨在将用户评论划分为两类情感:正面(POSITIF)
和负面(NEGATIF)
。
🧪 评估指标
模型采用以下指标进行评估:
� 基础模型
⚙️ 训练参数
训练配置参数如下(TrainingArguments
):
from transformers import TrainingArguments
training_args = TrainingArguments(
output_dir="./results",
num_train_epochs=3,
per_device_train_batch_size=4,
gradient_accumulation_steps=4,
per_device_eval_batch_size=4,
weight_decay=0.05,
eval_strategy="epoch",
save_strategy="epoch",
seed=42,
load_best_model_at_end=True,
metric_for_best_model="f1",
logging_dir="./logs",
report_to="tensorboard",
logging_steps=100,
warmup_ratio=0.05,
)
📊 评估结果
模型在3个训练周期内通过准确率和F1值进行评估。各周期表现如下:
周期 |
训练损失 |
验证损失 |
准确率 |
F1值 |
1 |
0.2674 |
0.1647 |
0.9415 |
0.9416 |
2 |
0.2427 |
0.2902 |
0.9263 |
0.9258 |
3 |
0.2387 |
0.2082 |
0.9443 |
0.9442 |
根据最高F1值,最终选择第3周期的模型为最佳模型。
👨💻 推理示例
from transformers import AutoTokenizer, AutoModelForSequenceClassification, pipeline
import torch
model = AutoModelForSequenceClassification.from_pretrained("siRendy/indobert-analisis-sentimen-review-produk")
tokenizer = AutoTokenizer.from_pretrained("siRendy/indobert-analisis-sentimen-review-produk")
def predict_sentiment(text):
classifier = pipeline(
"text-classification",
model=model,
tokenizer=tokenizer,
device=0 if torch.cuda.is_available() else -1
)
result = classifier(text)[0]
return {
"情感倾向": str(result["label"]),
"置信度": round(result["score"], 4)
}
text = "这个产品非常糟糕,完全不值得购买。"
prediction = predict_sentiment(text)
print(prediction)