Views
No views yet
bert-base-uncased model on a balanced dataset of real and fake news.Trainer API with the following hyperparameters:transformers library:1from transformers import AutoTokenizer, AutoModelForSequenceClassification
2import torch
3
4# Load the model and tokenizer
5model_id = "ahmednawaz8813/BERT_Fine_Tuned"
6tokenizer = AutoTokenizer.from_pretrained(model_id)
7model = AutoModelForSequenceClassification.from_pretrained(model_id)
8
9# Test with an article snippet
10article_text = "Scientists have discovered a new species of deep-sea jellyfish."
11inputs = tokenizer(article_text, return_tensors="pt", truncation=True, max_length=512, padding="max_length")
12
13# Get prediction
14with torch.no_grad():
15 logits = model(**inputs).logits
16 predicted_class_id = logits.argmax().item()
17
18label_map = {0: "Fake News", 1: "Real News"}
19print(f"Prediction: {label_map[predicted_class_id]}")