hamzab commited on
Commit
68aecd3
1 Parent(s): 9dcdabb

Update README.md

Browse files
Files changed (1) hide show
  1. README.md +32 -2
README.md CHANGED
@@ -1,10 +1,40 @@
1
  ---
2
  license: mit
3
  ---
4
-
5
  The model takes a news article and predicts if it true or fake.
6
- The format should be:
7
 
8
  ```
9
  <title> TITLE HERE <content> CONTENT HERE <end>
10
  ```
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
  ---
2
  license: mit
3
  ---
4
+ ## Overview
5
  The model takes a news article and predicts if it true or fake.
6
+ The format of the input should be:
7
 
8
  ```
9
  <title> TITLE HERE <content> CONTENT HERE <end>
10
  ```
11
+
12
+ ## Using this model in your code:
13
+ To use this model, first download it from the hugginface website:
14
+ ```python
15
+ from transformers import AutoTokenizer, AutoModelForSequenceClassification
16
+
17
+ tokenizer = AutoTokenizer.from_pretrained("hamzab/roberta-fake-news-classification")
18
+
19
+ model = AutoModelForSequenceClassification.from_pretrained("hamzab/roberta-fake-news-classification")
20
+ ```
21
+
22
+ Then, make a prediction like follows:
23
+ ```python
24
+ import torch
25
+ def predict_fake(title,text):
26
+ input_str = "<title>" + title + "<content>" + text + "<end>"
27
+ input_ids = tokenizer.encode_plus(input_str, max_length=512, padding="max_length", truncation=True, return_tensors="pt")
28
+ device = 'cuda' if torch.cuda.is_available() else 'cpu'
29
+ model.to(device)
30
+ with torch.no_grad():
31
+ output = model(input_ids["input_ids"].to(device), attention_mask=input_ids["attention_mask"].to(device))
32
+ return dict(zip(["Fake","Real"], [x.item() for x in list(torch.nn.Softmax()(output.logits)[0])] ))
33
+
34
+ print(predict_fake(<HEADLINE-HERE>,<CONTENT-HERE>))
35
+ ```
36
+ You can also use Gradio to test the model on real-time:
37
+ ```python
38
+ import gradio as gr
39
+ iface = 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)
40
+ ```