Downloads · 30 days
9
7% of all-time downloads
MartaAguilarMorcillo/gemma-fakenews-classifier
gemma-fakenews-classifier is a machine learning model from MartaAguilarMorcillo. Use it for the machine learning task on the model card, and read the license before you ship it in a product.
Binary fake news classifier fine-tuned from Google's Gemma 3 1B pretrained model (google/gemma-3-1b-pt). The model classifies news articles as REAL (0) or FAKE (1) based on their title and body text. It was developed…
Downloads · 30 days
9
7% of all-time downloads
All-time downloads
128
Public
Parameters
1000M
6 GB on disk
Likes
0
Public
Click a slice to open those files.
.safetensors2 GB · 98%
From the Hugging Face model README
Binary fake news classifier fine-tuned from Google's Gemma 3 1B pretrained model
(google/gemma-3-1b-pt). The model classifies news articles as REAL (0) or
FAKE (1) based on their title and body text. It was developed as part of the
BuloCheck project, a Chrome extension for automatic fake news detection.
google/gemma-3-1b-ptThis model is intended to classify English-language news articles as real or fake based on their textual content (title + body). It is used as the inference backend of the BuloCheck Chrome extension via a Gradio Space API.
Users should treat model predictions as a probabilistic signal, not a definitive verdict. The confidence score should be taken into account alongside other sources of verification. The model should not be the sole basis for editorial or legal decisions.
from transformers import AutoModelForSequenceClassification, AutoTokenizer
import torch
repo_id = "MartaAguilarMorcillo/gemma-fakenews-classifier"
tokenizer = AutoTokenizer.from_pretrained(repo_id)
tokenizer.pad_token = tokenizer.eos_token
model = AutoModelForSequenceClassification.from_pretrained(repo_id)
model.eval()
def predict(title: str, body: str, max_length: int = 256):
text = title + " " + body
inputs = tokenizer(
text,
truncation=True,
max_length=max_length,
return_tensors="pt"
)
with torch.no_grad():
outputs = model(**inputs)
probas = torch.softmax(outputs.logits, dim=-1)
predicted = torch.argmax(probas, dim=-1).item()
label = model.config.id2label[predicted]
confidence = probas[0][predicted].item()
return {
"label": label,
"confidence": round(confidence, 4),
"probas": {
"REAL": round(probas[0][0].item(), 4),
"FAKE": round(probas[0][1].item(), 4)
}
}
result = predict(
title="Scientists confirm the Earth is flat",
body="A new NASA study reveals the Earth has been flat all along."
)
print(result)
# {'label': 'FAKE', 'confidence': 0.8367, 'probas': {'REAL': 0.1633, 'FAKE': 0.8367}}
The model was fine-tuned on a custom dataset combining three publicly available fake news datasets:
| Dataset | Source | Instances used |
|---|---|---|
| ISOT Fake News Dataset | University of Victoria (Ahmed et al., 2017) | 3,000 real + 3,000 fake |
| FakeNewsNet | Arizona State University (Shu et al., 2018) | Full dataset |
| WELFake | Verma et al., IEEE TCSS (2021) | 3,000 real + 3,000 fake |
Each instance consists of the concatenation of the article title and body text, labelled as 0 (REAL) or 1 (FAKE). The final dataset contains 9,422 instances (4,797 real, 4,625 fake), split as follows:
Split was performed with random_state=123 for reproducibility.
google/gemma-3-1b-pt tokenizer; pad_token set to eos_token.DataCollatorWithPadding.All backbone parameters were frozen except the last 8 transformer layers and
the classification head (model.score: Linear(1152, 2)). This corresponds to
13.42% of total parameters being trainable (134,212,864 / 999,888,256).
| Parameter | Value |
|---|---|
| Base model | google/gemma-3-1b-pt |
| Number of unfrozen layers | 5 (+ classification head) |
| Optimizer | AdamW |
| Learning rate | 2e-5 |
| Weight decay | 0.01 |
| Batch size | 4 |
| Number of epochs | 3 |
| Scheduler | Cosine with warmup (10% warmup) |
| Total training steps | 4,947 |
| Warmup steps | 494 |
| Gradient clipping | max_norm = 1.0 |
| Evaluation frequency | Every 50 steps |
| Evaluation batches (val) | 100 batches per evaluation |
| Best model checkpoint | Saved at minimum validation loss |
| Random seed | 123 |
| Training precision | BF16 |
Held-out test split of the combined dataset described above (≈ 1,885 instances, never seen during training or hyperparameter tuning).
Accuracy (percentage of correctly classified instances).
Results obtained after restoring the best model checkpoint (step 1,950, val_loss = 0.558):
| Split | Accuracy |
|---|---|
| Train | 88.40% |
| Validation | 85.14% |
| Test | 84.19% |
The gap of less than 2 percentage points between validation and test accuracy indicates good generalisation to unseen data with no significant overfitting.
google/gemma-3-1b-pt) — decoder-only transformer,
hidden size 1152, 26 transformer layers.AutoModelForSequenceClassification.Marta Aguilar Morcillo