Instructions to use vzani/portuguese-fake-news-classifier-bilstm-combined with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- Keras
How to use vzani/portuguese-fake-news-classifier-bilstm-combined with Keras:
# Available backend options are: "jax", "torch", "tensorflow". import os os.environ["KERAS_BACKEND"] = "jax" import keras model = keras.saving.load_model("hf://vzani/portuguese-fake-news-classifier-bilstm-combined") - Notebooks
- Google Colab
- Kaggle
language:
- pt
license: apache-2.0
library_name: keras
pipeline_tag: text-classification
tags:
- bilstm
- portuguese
- pt
- fake-news
- binary-classification
metrics:
- accuracy
- precision
- recall
- f1-score
BiLSTM for Fake News Detection (Portuguese)
Model Overview
This repository contains BiLSTM models for fake news detection in Portuguese. Models are trained and evaluated on corpora derived from Brazilian Portuguese datasets Fake.br and FakeTrue.Br, as well as a combined/aligned corpus.
- Architecture: Bidirectional LSTM (Keras)
- Task: Binary text classification (Fake vs. True)
- Language: Portuguese (
pt) - Framework: Keras / TensorFlow
Available Variants
bilstm-combined Fine-tuned on the aligned combined corpus (
data/corpus_*at project root).bilstm-fake-br Fine-tuned on Fake.br. The corresponding corpus is available in
corpus/(including preprocessed and size-normalized texts when applicable).bilstm-faketrue-br Fine-tuned on FakeTrue.Br. Includes aligned splits and the original CSV when available.
Each variant ships with:
confusion_matrix.pngfinal_classification_report.parquetfinal_predictions.parquet
Training Details
{
"ngram_upper": 2,
"units": 120,
"dropout": 0.3374510345164157,
"recurrent_dropout": 0.1588638491073387,
"max_tokens": 96000,
"embed_dim": 71,
"embed_max_seq_len": 51,
"learning_rate": 0.00011662663429277272,
"batch_size": 16,
"epochs": 8,
}
Evaluation Results
Evaluation metrics are stored in the repo as:
confusion_matrix.pngfinal_classification_report.parquetfinal_predictions.parquet
These files provide per-class performance and prediction logs for reproducibility.
Corpus
The corpora used for training and evaluation are provided in the corpus/ folder.
- Combined (root folder):
corpus_train_df.parquet,corpus_test_df.parquet,corpus_df.parquet,corpus_alinhado_df.parquet. - Fake.br:
corpus_train_df.parquet,corpus_test_df.parquet,corpus_df.parquet,corpus_alinhado_df.parquet. - FakeTrue.Br:
corpus_train_df.parquet,corpus_test_df.parquet,corpus_df.parquet,corpus_alinhado_df.parquetandFakeTrueBr_corpus.csv.
How to Use
This model is a Keras model stored as final_bilstm_model.keras.
Load it with TensorFlow and apply the same preprocessing (tokenization + padding).
import keras
import tensorflow as tf
from huggingface_hub import hf_hub_download
repo_id = "vzani/portuguese-fake-news-classifier-bilstm-combined" # or fake-br / faketrue-br
filename = "final_bilstm_model.keras"
model_path = hf_hub_download(repo_id=repo_id, filename=filename)
model = keras.models.load_model(model_path)
def predict(text: str) -> tuple[bool, float]:
input_data = tf.convert_to_tensor([[text]], dtype=tf.string)
probs = model.predict(input_data) # type: ignore
prob = float(probs.flatten()[0]) # type: ignore
pred = int(prob >= 0.5)
return pred, prob # type: ignore
if __name__ == "__main__":
text = "BOMBA! A Dilma vai taxar ainda mais os pobres!"
print(predict(text))
Expected output:
(False, 0.xxx)
Interpreting the results:
- LABEL_0: Fake news
- LABEL_1: True news
License
Citation
Coming soon.