Downloads · 30 days
253
0% of all-time downloads
VerificadoProfesional/SaBERT-Spanish-Sentiment-Analysis
SaBERT-Spanish-Sentiment-Analysis is a text classification model from VerificadoProfesional. Use it when you need a label for a piece of text. It is set up for transformers. The card lists the license as apache-2.0.
This BERT-based text classifier was developed as a thesis project for the Computer Engineering degree at Universidad de Buenos Aires (UBA). The model is designed to detect sentiments in Spanish and was fine-tuned on t…
Downloads · 30 days
253
0% of all-time downloads
All-time downloads
57.4K
Public
Parameters
110M
879 MB on disk
Likes
20
Public
Click a slice to open those files.
.safetensors439 MB · 100%
From the Hugging Face model README
This BERT-based text classifier was developed as a thesis project for the Computer Engineering degree at Universidad de Buenos Aires (UBA). The model is designed to detect sentiments in Spanish and was fine-tuned on the dccuchile/bert-base-spanish-wwm-uncased model using a specific set of hyperparameters. It was trained on a dataset containing 11,500 Spanish tweets collected from various regions, both positive and negative. These tweets were sourced from a well-curated combination of TASS datasets.
Base Mode: dccuchile/bert-base-spanish-wwm-uncased
Hyperparameters:
Dataset: 11,500 Spanish tweets (Positive and Negative)
The model's performance was evaluated using the following metrics:
You can install the required dependencies using pip:
pip install transformers torch
from transformers import BertForSequenceClassification, BertTokenizer
model = BertForSequenceClassification.from_pretrained("VerificadoProfesional/SaBERT-Spanish-Sentiment-Analysis")
tokenizer = BertTokenizer.from_pretrained("VerificadoProfesional/SaBERT-Spanish-Sentiment-Analysis")
def predict(model,tokenizer,text,threshold = 0.5):
inputs = tokenizer(text, return_tensors="pt", padding=True, truncation=True, max_length=128)
with torch.no_grad():
outputs = model(**inputs)
logits = outputs.logits
probabilities = torch.softmax(logits, dim=1).squeeze().tolist()
predicted_class = torch.argmax(logits, dim=1).item()
if probabilities[predicted_class] <= threshold and predicted_class == 1:
predicted_class = 0
return bool(predicted_class), probabilities
text = "Your Spanish news text here"
predicted_label,probabilities = predict(model,tokenizer,text)
print(f"Text: {text}")
print(f"Predicted Class: {predicted_label}")
print(f"Probabilities: {probabilities}")
Special thanks to DCC UChile for the base Spanish BERT model and to all contributors to the dataset used for training.