Views
No views yet
1from transformers import AutoModelForSequenceClassification, AutoTokenizer
2import torch
3
4model_path = "your-huggingface-username/newsguard-ai-fake-news"
5tokenizer = AutoTokenizer.from_pretrained(model_path)
6model = AutoModelForSequenceClassification.from_pretrained(model_path)
7
8text = "Some news article text here..."
9inputs = tokenizer(text, return_tensors="pt", truncation=True, padding=True, max_length=512)
10
11with torch.no_grad():
12 outputs = model(**inputs)
13 probs = torch.nn.functional.softmax(outputs.logits, dim=-1)
14
15prediction = "Fake" if torch.argmax(probs) == 0 else "Real"
16print(f"Prediction: {prediction}, Confidence: {probs.tolist()[0]}")