Text Classification
Transformers
PyTorch
roberta
text-embeddings-inference
FakeWatch / README.md
shainaraza's picture
Update README.md
1ad0976
metadata
datasets:
  - newsmediabias/fake_news_elections_labelled_data
  - newsmediabias/FAKE-NEWS-BIASES-LABELLED
from transformers import AutoTokenizer, AutoModelForSequenceClassification, pipeline

# Load model and tokenizer
tokenizer = AutoTokenizer.from_pretrained("newsmediabias/fake-news-classifier-elections")
model = AutoModelForSequenceClassification.from_pretrained("newsmediabias/fake-news-classifier-elections")

# Initialize the pipeline for sequence classification with the model and tokenizer
fake_news_classifier = pipeline(
    "text-classification",
    model=model,
    tokenizer=tokenizer
)

# Define label mapping based on the model's training
label_mapping = {
    "LABEL_0": "REAL",
    "LABEL_1": "FAKE"
}

# Example text to classify
example_text = "The election was rigged and full of fraud."

# Perform inference
predictions = fake_news_classifier(example_text)
predicted_class = label_mapping[predictions[0]['label']]
confidence_score = predictions[0]['score'] * 100

# Output the results
print(f"Predicted Class: {predicted_class}")
print(f"Confidence Score: {confidence_score:.2f}%")