模型:
neuraly/bert-base-italian-cased-sentiment
该模型对意大利语句子进行情感分析。它是从 bert-base-italian-cased 的一个实例开始训练的,并在意大利推文数据集上进行了微调,准确率达到82%。
import torch
from torch import nn
from transformers import AutoTokenizer, AutoModelForSequenceClassification
# Load the tokenizer
tokenizer = AutoTokenizer.from_pretrained("neuraly/bert-base-italian-cased-sentiment")
# Load the model, use .cuda() to load it on the GPU
model = AutoModelForSequenceClassification.from_pretrained("neuraly/bert-base-italian-cased-sentiment")
sentence = 'Huggingface è un team fantastico!'
input_ids = tokenizer.encode(sentence, add_special_tokens=True)
# Create tensor, use .cuda() to transfer the tensor to GPU
tensor = torch.tensor(input_ids).long()
# Fake batch dimension
tensor = tensor.unsqueeze(0)
# Call the model and get the logits
logits, = model(tensor)
# Remove the fake batch dimension
logits = logits.squeeze(0)
# The model was trained with a Log Likelyhood + Softmax combined loss, hence to extract probabilities we need a softmax on top of the logits tensor
proba = nn.functional.softmax(logits, dim=0)
# Unpack the tensor to obtain negative, neutral and positive probabilities
negative, neutral, positive = proba
,限制和偏见 该模型可能的缺点(或偏见)与其在推文数据集上训练有关,具有相关的局限性。该领域与足球运动员和球队密切相关,但即使在其他主题上也表现出色。
我们将来自 Sentipolc EVALITA 2016 的两个推文数据集组合起来进行训练。总体上,数据集包含45K个经过预处理的推文。
模型权重来自预训练的 bert-base-italian-cased 实例。非常感谢那个团队,做得很出色!
我们试图尽可能保存尽可能多的信息,因为BERT非常有效地捕捉复杂文本序列的语义。总体上,我们只移除了每个推文中的@提及、URL和电子邮件,而保留了几乎其他所有内容。
硬件早停在经过3个周期后触发。
该模型在测试集上实现了82%的整体准确率。测试集是整个数据集的20%分割。
Neuraly 是一家年轻而充满活力的初创公司,致力于通过最先进的机器学习和数据科学技术设计基于人工智能的解决方案和服务。您可以在我们的 website 上了解更多关于我们是谁以及我们在做什么的信息。
感谢 Hugging Face 团队的慷慨支持,我们可以从他们的S3存储中下载模型并通过他们的推理API进行实时测试 🤗。