twitter-roberta-base-sentiment-latest
cardiffnlp
text-classification
transformers
en
cardiffnlp/twitter-roberta-base-sentiment-latest
3,301,402
下载量
796
收藏数
11
浏览量
cc-by-4.0
许可
简介
用于情感分析的Twitter-roBERTa-base模型 - 已更新(2022)
模型卡片
许可协议
cc-by-4.0
语言
en
数据集
tweet_eval
模型配置
模型类型
roberta
架构
RobertaForSequenceClassification
模型详情
已翻译Twitter-roBERTa-base 情感分析模型 - 更新版 (2022)
这是一个基于 RoBERTa-base 的模型,使用 2018 年 1 月至 2021 年 12 月期间约 1.24 亿条推文进行训练,并针对 TweetEval 基准进行了情感分析微调。
原始的基于 Twitter 的 RoBERTa 模型可在此处找到,原始参考论文为 TweetEval。该模型适用于英文文本。
- 参考论文:TimeLMs 论文
- Git 仓库:TimeLMs 官方仓库
标签:
0 -> 负面;
1 -> 中性;
2 -> 正面
该情感分析模型已集成到 TweetNLP 中。您可以在此处访问演示。
示例 Pipeline
from transformers import pipeline
sentiment_task = pipeline("sentiment-analysis", model=model_path, tokenizer=model_path)
sentiment_task("Covid cases are increasing fast!")
[{'label': 'Negative', 'score': 0.7236}]
完整分类示例
from transformers import AutoModelForSequenceClassification
from transformers import TFAutoModelForSequenceClassification
from transformers import AutoTokenizer, AutoConfig
import numpy as np
from scipy.special import softmax
# Preprocess text (username and link placeholders)
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 = f"cardiffnlp/twitter-roberta-base-sentiment-latest"
tokenizer = AutoTokenizer.from_pretrained(MODEL)
config = AutoConfig.from_pretrained(MODEL)
# PT
model = AutoModelForSequenceClassification.from_pretrained(MODEL)
#model.save_pretrained(MODEL)
text = "Covid cases are increasing fast!"
text = preprocess(text)
encoded_input = tokenizer(text, return_tensors='pt')
output = model(**encoded_input)
scores = output[0][0].detach().numpy()
scores = softmax(scores)
# # TF
# model = TFAutoModelForSequenceClassification.from_pretrained(MODEL)
# model.save_pretrained(MODEL)
# text = "Covid cases are increasing fast!"
# encoded_input = tokenizer(text, return_tensors='tf')
# output = model(encoded_input)
# scores = output[0][0].numpy()
# scores = softmax(scores)
# Print labels and 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)}")
输出:
1) Negative 0.7236
2) Neutral 0.2287
3) Positive 0.0477
参考文献
@inproceedings{camacho-collados-etal-2022-tweetnlp,
title = "{T}weet{NLP}: Cutting-Edge Natural Language Processing for Social Media",
author = "Camacho-collados, Jose and
Rezaee, Kiamehr and
Riahi, Talayeh and
Ushio, Asahi and
Loureiro, Daniel and
Antypas, Dimosthenis and
Boisson, Joanne and
Espinosa Anke, Luis and
Liu, Fangyu and
Mart{\'\i}nez C{\'a}mara, Eugenio" and others,
booktitle = "Proceedings of the 2022 Conference on Empirical Methods in Natural Language Processing: System Demonstrations",
month = dec,
year = "2022",
address = "Abu Dhabi, UAE",
publisher = "Association for Computational Linguistics",
url = "https://aclanthology.org/2022.emnlp-demos.5",
pages = "38--49"
}
@inproceedings{loureiro-etal-2022-timelms,
title = "{T}ime{LM}s: Diachronic Language Models from {T}witter",
author = "Loureiro, Daniel and
Barbieri, Francesco and
Neves, Leonardo and
Espinosa Anke, Luis and
Camacho-collados, Jose",
booktitle = "Proceedings of the 60th Annual Meeting of the Association for Computational Linguistics: System Demonstrations",
month = may,
year = "2022",
address = "Dublin, Ireland",
publisher = "Association for Computational Linguistics",
url = "https://aclanthology.org/2022.acl-demo.25",
doi = "10.18653/v1/2022.acl-demo.25",
pages = "251--260"
}
正在翻译中,请稍候...
标签
tf
roberta
en
dataset:tweet_eval
arxiv:2202.03829
license:cc-by-4.0
endpoints_compatible
deploy:azure
操作
详细信息
- 厂商
- cardiffnlp
- 任务
- text-classification
- 框架
- transformers
- 模型类型
- roberta
- 许可(HF)
- cc-by-4.0
- 语言
- en