Views
No views yet
roberta-base fine-tuned on fake-and-real-news-dataset. It has a 100% accuracy on that dataset.
The model takes a news article and predicts if it is true or fake.
The format of the input should be:<title> TITLE HERE <content> CONTENT HERE <end>1from transformers import AutoTokenizer, AutoModelForSequenceClassification
2
3tokenizer = AutoTokenizer.from_pretrained("hamzab/roberta-fake-news-classification")
4
5model = AutoModelForSequenceClassification.from_pretrained("hamzab/roberta-fake-news-classification")1import torch
2def predict_fake(title,text):
3 input_str = "<title>" + title + "<content>" + text + "<end>"
4 input_ids = tokenizer.encode_plus(input_str, max_length=512, padding="max_length", truncation=True, return_tensors="pt")
5 device = 'cuda' if torch.cuda.is_available() else 'cpu'
6 model.to(device)
7 with torch.no_grad():
8 output = model(input_ids["input_ids"].to(device), attention_mask=input_ids["attention_mask"].to(device))
9 return dict(zip(["Fake","Real"], [x.item() for x in list(torch.nn.Softmax()(output.logits)[0])] ))
10
11print(predict_fake(<HEADLINE-HERE>,<CONTENT-HERE>))1import gradio as gr
2iface = gr.Interface(fn=predict_fake, inputs=[gr.inputs.Textbox(lines=1,label="headline"),gr.inputs.Textbox(lines=6,label="content")], outputs="label").launch(share=True)