MidhunKanadan commited on
Commit
f973d86
·
verified ·
1 Parent(s): 86dc496

Update README.md

Browse files
Files changed (1) hide show
  1. README.md +12 -12
README.md CHANGED
@@ -83,22 +83,22 @@ For more detailed control over predictions:
83
  ```python
84
  import torch
85
  from transformers import AutoTokenizer, AutoModelForSequenceClassification
 
86
 
87
- # Load model and tokenizer, set device
88
- model_path = "MidhunKanadan/roberta-large-fallacy-classification"
89
- device = torch.device("cuda" if torch.cuda.is_available() else "cpu")
90
- model = AutoModelForSequenceClassification.from_pretrained(model_path).to(device).eval()
91
- tokenizer = AutoTokenizer.from_pretrained(model_path, use_fast=False)
92
-
93
- # Tokenize input and get probabilities
94
  text = "The rooster crows always before the sun rises, therefore the crowing rooster causes the sun to rise."
95
- inputs = tokenizer(text, return_tensors="pt").to(device)
 
 
 
 
96
  with torch.no_grad():
97
- probabilities = torch.nn.functional.softmax(model(**inputs).logits, dim=1)[0]
 
98
 
99
- # Output sorted results
100
- for label, score in sorted(zip(model.config.id2label.values(), probabilities), key=lambda x: x[1], reverse=True):
101
- print(f"{label}: {score.item():.4f}")
102
  ```
103
 
104
  Expected Output:
 
83
  ```python
84
  import torch
85
  from transformers import AutoTokenizer, AutoModelForSequenceClassification
86
+ import torch.nn.functional as F
87
 
88
+ model_path = "MidhunKanadan/roberta-large-logical-fallacy-classifier"
 
 
 
 
 
 
89
  text = "The rooster crows always before the sun rises, therefore the crowing rooster causes the sun to rise."
90
+
91
+ tokenizer = AutoTokenizer.from_pretrained(model_path)
92
+ model = AutoModelForSequenceClassification.from_pretrained(model_path).to("cuda")
93
+ inputs = tokenizer(text, return_tensors="pt", truncation=True, padding=True, max_length=128).to("cuda")
94
+
95
  with torch.no_grad():
96
+ probs = F.softmax(model(**inputs).logits, dim=-1)
97
+ results = {model.config.id2label[i]: score.item() for i, score in enumerate(probs[0])}
98
 
99
+ # Print scores for all labels
100
+ for label, score in sorted(results.items(), key=lambda x: x[1], reverse=True):
101
+ print(f"{label}: {score:.4f}")
102
  ```
103
 
104
  Expected Output: