🚀 IndoBERT情感分类ID - 二分类
本模型是基于indobenchmark/indobert-base-p2
进行微调得到的,用于对印尼语产品评论进行二分类情感分析(积极和消极)。所使用的数据集包含了来自电商平台Tokopedia的10600条产品评论。
🚀 快速开始
本模型旨在将评论或评价分为两种情感类别:积极
和消极
。
✨ 主要特性
📦 安装指南
文档未提及安装步骤,暂不展示。
💻 使用示例
基础用法
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 {
"sentiment": str(result["label"]),
"confidence": round(result["score"], 4)
}
text = "Produk ini sangat buruk dan tidak layak dibeli."
prediction = predict_sentiment(text)
print(prediction)
📚 详细文档
训练参数配置
以下是训练时使用的训练参数配置(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个周期。
📄 许可证
本项目采用MIT许可证。