🚀 用於情感分析的twitter-XLM-roBERTa-base模型
本模型用於對西班牙語推文進行情感分析,基於在約1.98億條推文上預訓練的XLM-roBERTa-base模型微調而來。它能有效將西班牙語推文分類為七種不同的情感類別,為情感分析任務提供了強大的支持。
🚀 快速開始
示例代碼
本示例使用了來自@JaSantaolalla的推文進行情感分析。
from transformers import pipeline
model_path = "daveni/twitter-xlm-roberta-emotion-es"
emotion_analysis = pipeline("text-classification", framework="pt", model=model_path, tokenizer=model_path)
emotion_analysis("Einstein dijo: Solo hay dos cosas infinitas, el universo y los pinches anuncios de bitcoin en Twitter. Paren ya carajo aaaaaaghhgggghhh me quiero murir")
輸出結果:
[{'label': 'anger', 'score': 0.48307016491889954}]
完整分類示例
from transformers import AutoModelForSequenceClassification
from transformers import AutoTokenizer, AutoConfig
import numpy as np
from scipy.special import softmax
def preprocess(text):
new_text = []
for t in text.split(" "):
t = '@user' if t.startswith('@') and len(t) > 1 else t
t = 'http' if t.startswith('http') else t
new_text.append(t)
return " ".join(new_text)
model_path = "daveni/twitter-xlm-roberta-emotion-es"
tokenizer = AutoTokenizer.from_pretrained(model_path )
config = AutoConfig.from_pretrained(model_path )
model = AutoModelForSequenceClassification.from_pretrained(model_path )
text = "Se ha quedao bonito día para publicar vídeo, ¿no? Hoy del tema más diferente que hemos tocado en el canal."
text = preprocess(text)
print(text)
encoded_input = tokenizer(text, return_tensors='pt')
output = model(**encoded_input)
scores = output[0][0].detach().numpy()
scores = softmax(scores)
ranking = np.argsort(scores)
ranking = ranking[::-1]
for i in range(scores.shape[0]):
l = config.id2label[ranking[i]]
s = scores[ranking[i]]
print(f"{i+1}) {l} {np.round(float(s), 4)}")
輸出結果:
Se ha quedao bonito día para publicar vídeo, ¿no? Hoy del tema más diferente que hemos tocado en el canal.
1) joy 0.7887
2) others 0.1679
3) surprise 0.0152
4) sadness 0.0145
5) anger 0.0077
6) disgust 0.0033
7) fear 0.0027
✨ 主要特性
- 強大的情感分類能力:該模型能夠將西班牙語推文準確分類為七種不同的情感類別,包括憤怒、厭惡、恐懼、喜悅、悲傷、驚訝和其他。
- 優秀的競賽表現:在EmoEvalEs競賽中,該模型取得了71.70%的宏平均F1分數,獲得了第一名。
📦 相關鏈接
🔧 技術細節
模型基礎
本模型基於finetuned XLM-T for Sentiment Analysis,預訓練權重與cardiffnlp發佈的原始模型相同。
訓練數據
使用EmoEvalEs數據集進行微調訓練。
侷限性和偏差
- 微調所用的數據集存在不平衡問題,近一半的記錄屬於其他類別,因此模型可能對該類別存在偏差。
BibTeX引用
@inproceedings{vera2021gsi,
title={GSI-UPM at IberLEF2021: Emotion Analysis of Spanish Tweets by Fine-tuning the XLM-RoBERTa Language Model},
author={Vera, D and Araque, O and Iglesias, CA},
booktitle={Proceedings of the Iberian Languages Evaluation Forum (IberLEF 2021). CEUR Workshop Proceedings, CEUR-WS, M{\'a}laga, Spain},
year={2021}
}