Views
No views yet
real vs. fake) for Spanish long-form news articles.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 |
pip install transformers torch1import torch
2from transformers import AutoModelForSequenceClassification, AutoTokenizer
3
4model = AutoModelForSequenceClassification.from_pretrained("Juanillaberia/spanish-fake-news-classifier")
5tokenizer = AutoTokenizer.from_pretrained("Juanillaberia/spanish-fake-news-classifier")1def predict_article(article_text: str):
2 """
3 Predicts whether a given article text is 'Real' or 'Fake' using the fine-tuned model.
4
5 Args:
6 article_text (str): The text of the article to classify.
7
8 Returns:
9 str: 'Real' if the article is predicted as real, 'Fake' otherwise.
10 """
11 # Tokenize the input text
12 inputs = tokenizer(article_text, truncation=True, max_length=512, padding="max_length", return_tensors="pt")
13
14 # Make prediction
15 with torch.no_grad():
16 outputs = model(**inputs)
17
18 # Get logits and convert to probabilities
19 logits = outputs.logits
20 probabilities = torch.softmax(logits, dim=-1)
21
22 # Get predicted label (1 for Real, 0 for Fake)
23 predicted_label_id = torch.argmax(probabilities, dim=-1).item()
24
25 # Map label ID to 'Real' or 'Fake'
26 return "Real" if predicted_label_id == 1 else "Fake"1text = "Your spanish article"
2predicted_label = predict_article(text)
3print(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.