Update README.md
Browse files
README.md
CHANGED
@@ -10,7 +10,7 @@ In Transformers
|
|
10 |
```python
|
11 |
from transformers import AutoTokenizer, AutoModelForSequenceClassification
|
12 |
import torch
|
13 |
-
from
|
14 |
|
15 |
device = "cuda" if torch.cuda.is_available() else "cpu"
|
16 |
|
@@ -27,9 +27,11 @@ features = tokenizer([[sentence, l] for l in labels], padding=True, truncation=T
|
|
27 |
model.eval()
|
28 |
with torch.no_grad():
|
29 |
scores = model(**features).logits
|
30 |
-
print(
|
31 |
-
print(softmax(scores)) #Single-Label Classification
|
32 |
-
|
|
|
|
|
33 |
```
|
34 |
|
35 |
|
|
|
10 |
```python
|
11 |
from transformers import AutoTokenizer, AutoModelForSequenceClassification
|
12 |
import torch
|
13 |
+
from torch.nn.functional import softmax, sigmoid
|
14 |
|
15 |
device = "cuda" if torch.cuda.is_available() else "cpu"
|
16 |
|
|
|
27 |
model.eval()
|
28 |
with torch.no_grad():
|
29 |
scores = model(**features).logits
|
30 |
+
print("Multi-Label:", sigmoid(scores)) #Multi-Label Classification
|
31 |
+
print("Single-Label:", softmax(scores, dim=0)) #Single-Label Classification
|
32 |
+
|
33 |
+
#Multi-Label: tensor([[0.0412],[0.2436],[0.0394],[0.0020],[0.0050],[0.1424]])
|
34 |
+
#Single-Label: tensor([[0.0742],[0.5561],[0.0709],[0.0035],[0.0087],[0.2867]])
|
35 |
```
|
36 |
|
37 |
|