🚀 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許可證。