🚀 微調後的RoBERTa情感分析模型
該模型基於RoBERTa架構,針對YouTube評論數據進行微調,能精準分析評論情感傾向,為視頻推薦、內容分析等應用提供有力支持。
🚀 快速開始
本模型可通過API端點使用,也能使用Hugging Face Transformers庫在本地加載。以下是使用Python的示例代碼:
from transformers import AutoTokenizer, AutoModelForSequenceClassification
import torch
model_name = "AmaanP314/youtube-xlm-roberta-base-sentiment-multilingual"
tokenizer = AutoTokenizer.from_pretrained(model_name)
model = AutoModelForSequenceClassification.from_pretrained(model_name)
comments = [
"This video aged like honey.",
"This video aged like milk.",
"It was just okay."
]
inputs = tokenizer(comments, return_tensors="pt", padding=True, truncation=True)
with torch.no_grad():
outputs = model(**inputs)
predictions = torch.argmax(outputs.logits, dim=1)
label_mapping = {0: "Negative", 1: "Neutral", 2: "Positive"}
sentiments = [label_mapping[p.item()] for p in predictions]
print(sentiments)
✨ 主要特性
- 領域適配性強:基於YouTube評論數據微調,能更好地處理YouTube評論中的獨特語氣、俚語和結構。
- 高精度:在YouTube評論情感分析任務上,準確率達到80.17%。
- 應用廣泛:可用於視頻推薦系統、內容分析儀表盤等需要理解觀眾情感的數據分析任務。
📦 安裝指南
使用該模型前,需安裝Hugging Face Transformers庫,可使用以下命令進行安裝:
pip install transformers torch
💻 使用示例
基礎用法
from transformers import AutoTokenizer, AutoModelForSequenceClassification
import torch
model_name = "AmaanP314/youtube-xlm-roberta-base-sentiment-multilingual"
tokenizer = AutoTokenizer.from_pretrained(model_name)
model = AutoModelForSequenceClassification.from_pretrained(model_name)
comments = [
"This video aged like honey.",
"This video aged like milk.",
"It was just okay."
]
inputs = tokenizer(comments, return_tensors="pt", padding=True, truncation=True)
with torch.no_grad():
outputs = model(**inputs)
predictions = torch.argmax(outputs.logits, dim=1)
label_mapping = {0: "Negative", 1: "Neutral", 2: "Positive"}
sentiments = [label_mapping[p.item()] for p in predictions]
print(sentiments)
高級用法
如果你需要處理大量評論數據,可以考慮使用批量處理的方式,以提高效率。以下是一個簡單的示例:
from transformers import AutoTokenizer, AutoModelForSequenceClassification
import torch
from tqdm import tqdm
model_name = "AmaanP314/youtube-xlm-roberta-base-sentiment-multilingual"
tokenizer = AutoTokenizer.from_pretrained(model_name)
model = AutoModelForSequenceClassification.from_pretrained(model_name)
comments = ["This is a comment."] * 1000
batch_size = 32
sentiments = []
for i in tqdm(range(0, len(comments), batch_size)):
batch = comments[i:i+batch_size]
inputs = tokenizer(batch, return_tensors="pt", padding=True, truncation=True)
with torch.no_grad():
outputs = model(**inputs)
predictions = torch.argmax(outputs.logits, dim=1)
label_mapping = {0: "Negative", 1: "Neutral", 2: "Positive"}
batch_sentiments = [label_mapping[p.item()] for p in predictions]
sentiments.extend(batch_sentiments)
print(sentiments)
📚 詳細文檔
模型概述
該模型是cardiffnlp/twitter-xlm-roberta-base-sentiment-multilingual模型的微調版本,在自定義的YouTube評論數據集上進行了微調。微調過程旨在提高模型在YouTube評論情感分析任務上的性能,因為YouTube評論在語氣、俚語和結構上與其他社交媒體平臺有所不同。微調後,模型的準確率達到了80.17%。
預期用途
該模型專為YouTube評論情感分析而設計。它接受一個文本輸入列表(評論),併為每條評論返回一個情感標籤:
該模型可用於視頻推薦系統、內容分析儀表盤等需要理解觀眾情感的數據分析任務。
訓練方式
評估
該模型在一個預留的YouTube評論測試集上進行了評估。與在Twitter數據上微調時約69.3%的基線準確率相比,該模型在這個數據集上的準確率提高到了80.17%。這一改進證明了特定領域微調的優勢。
🔧 技術細節
該模型基於RoBERTa架構,通過在自定義的YouTube評論數據集上進行微調,學習到了YouTube評論中的獨特特徵。在微調過程中,使用了數據清洗和預處理技術,以提高數據質量;同時,採用了評估和測試環節,以確保模型的性能。
📄 許可證
本模型採用CC BY 4.0許可證。
相關信息表格
屬性 |
詳情 |
模型類型 |
文本分類模型 |
基礎模型 |
cardiffnlp/twitter-xlm-roberta-base-sentiment-multilingual |
訓練數據 |
AmaanP314/youtube-comment-sentiment |
評估指標 |
準確率 |
引用信息
如果你在研究中使用了該模型,請引用原始基礎模型和本項目:
@misc{cardiffnlp,
title={Twitter-XLM-RoBERTa-Base-Sentiment-Multilingual},
author={Cardiff NLP},
year={2020},
publisher={Hugging Face},
howpublished={\url{https://huggingface.co/cardiffnlp/twitter-xlm-roberta-base-sentiment-multilingual}}
}
@misc{AmaanP314,
title={Youtube-XLM-RoBERTa-Base-Sentiment-Multilingual},
author={Amaan Poonawala},
year={2025},
howpublished={\url{https://huggingface.co/AmaanP314/youtube-xlm-roberta-base-sentiment-multilingual}}
}