Views
No views yet
| Precision | Recall | F-1 Score | Support | |
|---|---|---|---|---|
| Not Hate Speech (0) | 0.99 | 0.99 | 0.99 | 4335 |
| Hate Speech (1) | 0.99 | 0.99 | 0.99 | 3782 |
| accuracy | 0.99 | 8117 | ||
| macro avg | 0.99 | 0.99 | 0.99 | 8117 |
| weighted avg | 0.99 | 0.99 | 0.99 | 8117 |
| Epoch | Training Loss | Validation Loss |
|---|---|---|
| 1 | 0.099100 | 0.042086 |
| 2 | 0.030200 | 0.028448 |
| 3 | 0.017500 | 0.024397 |
1from transformers import AutoTokenizer, AutoModelForSequenceClassification
2import torch.nn as nn
3tokenizer = AutoTokenizer.from_pretrained("vikram71198/distilroberta-base-finetuned-fake-news-detection")
4model = AutoModelForSequenceClassification.from_pretrained("vikram71198/distilroberta-base-finetuned-fake-news-detection")
5#Following the same truncation & padding strategy used while training
6encoded_input = tokenizer("Enter any news article to be classified. Can be a list of articles too.", truncation = True, padding = "max_length", max_length = 512, return_tensors='pt')
7output = model(**encoded_input)["logits"]
8#detaching the output from the computation graph
9detached_output = output.detach()
10#Applying softmax here for single label classification
11softmax = nn.Softmax(dim = 1)
12prediction_probabilities = list(softmax(detached_output).detach().numpy())
13predictions = []
14for x,y in prediction_probabilities:
15 predictions.append("not_fake_news") if x > y else predictions.append("fake_news")
16print(predictions)