Downloads · 30 days
24
11% of all-time downloads
Juanillaberia/spanish-fake-news-classifier
spanish-fake-news-classifier is a text classification model from Juanillaberia. 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.
Paper: https://openreview.net/forum?id=ARX3eBpHgq
Downloads · 30 days
24
11% of all-time downloads
All-time downloads
226
Public
Parameters
110M
439 MB on disk
Likes
0
Public
Click a slice to open those files.
.safetensors439 MB · 100%
From the Hugging Face model README
Paper: https://openreview.net/forum?id=ARX3eBpHgq
This model is a binary classifier (real vs. fake) for Spanish long-form news articles.
It uses a sequential fine-tuning approach to overcome dataset imbalance between short and long articles:
The base architecture is bert-base-spanish-wwm-uncased.
dccuchile/bert-base-spanish-wwm-uncased| Metric | Value |
|---|---|
| Accuracy | 0.8205 |
| Precision | 0.7835 |
| Recall | 0.8702 |
| F1-score | 0.8246 |
| Loss | 0.4183 |
You can install the required dependencies using pip:
pip install transformers torch
import torch
from transformers import AutoModelForSequenceClassification, AutoTokenizer
model = AutoModelForSequenceClassification.from_pretrained("Juanillaberia/spanish-fake-news-classifier")
tokenizer = AutoTokenizer.from_pretrained("Juanillaberia/spanish-fake-news-classifier")
def predict_article(article_text: str):
"""
Predicts whether a given article text is 'Real' or 'Fake' using the fine-tuned model.
Args:
article_text (str): The text of the article to classify.
Returns:
str: 'Real' if the article is predicted as real, 'Fake' otherwise.
"""
# Tokenize the input text
inputs = tokenizer(article_text, truncation=True, max_length=512, padding="max_length", return_tensors="pt")
# Make prediction
with torch.no_grad():
outputs = model(**inputs)
# Get logits and convert to probabilities
logits = outputs.logits
probabilities = torch.softmax(logits, dim=-1)
# Get predicted label (1 for Real, 0 for Fake)
predicted_label_id = torch.argmax(probabilities, dim=-1).item()
# Map label ID to 'Real' or 'Fake'
return "Real" if predicted_label_id == 1 else "Fake"
text = "Your spanish article"
predicted_label = predict_article(text)
print(f"Predicted Label: {predicted_label}")
Note: Label (1) is for "Real" articles and label (0) is for "Fake" articles. This is how the model was train.
Apache License 2.0
Thanks to DCC UChile for the base Spanish BERT model.