Commit
•
a7fd4bf
1
Parent(s):
c4cec93
Update README.md
Browse files
README.md
CHANGED
@@ -11,5 +11,42 @@ The model classifies the input text into one of 6 target classes.
|
|
11 |
|
12 |
Bias: The model may inherit biases present in the training data, and it's important to be aware of potential biases in the predictions.
|
13 |
|
|
|
|
|
|
|
14 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
15 |
|
|
|
11 |
|
12 |
Bias: The model may inherit biases present in the training data, and it's important to be aware of potential biases in the predictions.
|
13 |
|
14 |
+
### Code Implementation
|
15 |
+
```python
|
16 |
+
from transformers import AutoTokenizer, AutoModelForSequenceClassification
|
17 |
|
18 |
+
# Load model directly
|
19 |
+
tokenizer = AutoTokenizer.from_pretrained(
|
20 |
+
"Arjun24420/BERT-FakeNews-Classification")
|
21 |
+
model = AutoModelForSequenceClassification.from_pretrained(
|
22 |
+
"Arjun24420/BERT-FakeNews-Classification")
|
23 |
+
|
24 |
+
# Define class labels mapping
|
25 |
+
class_mapping = {
|
26 |
+
0: 'half-true',
|
27 |
+
1: 'mostly-true',
|
28 |
+
2: 'false',
|
29 |
+
3: 'true',
|
30 |
+
4: 'barely-true',
|
31 |
+
5: 'pants-fire'
|
32 |
+
}
|
33 |
+
|
34 |
+
|
35 |
+
def predict(text):
|
36 |
+
# Tokenize the input text and move tensors to the GPU if available
|
37 |
+
inputs = tokenizer(text, padding=True, truncation=True,
|
38 |
+
max_length=512, return_tensors="pt")
|
39 |
+
|
40 |
+
# Get model output (logits)
|
41 |
+
outputs = model(**inputs)
|
42 |
+
|
43 |
+
probs = outputs.logits.softmax(1)
|
44 |
+
# Get the probabilities for each class
|
45 |
+
class_probabilities = {class_mapping[i]: probs[0, i].item()
|
46 |
+
for i in range(probs.shape[1])}
|
47 |
+
|
48 |
+
return class_probabilities
|
49 |
+
|
50 |
+
|
51 |
+
```
|
52 |
|