Fix Code Example in README
Browse files
README.md
CHANGED
|
@@ -30,14 +30,15 @@ The table connects the position of the predicted probability to its dimension.
|
|
| 30 |
# Usage Example
|
| 31 |
|
| 32 |
```python
|
| 33 |
-
|
|
|
|
| 34 |
from transformers import AutoTokenizer
|
| 35 |
|
| 36 |
# load tokenizer
|
| 37 |
tokenizer = AutoTokenizer.from_pretrained("luerhard/PopBERT")
|
| 38 |
|
| 39 |
# load model
|
| 40 |
-
model =
|
| 41 |
|
| 42 |
# define text to be predicted
|
| 43 |
text = (
|
|
@@ -47,7 +48,7 @@ text = (
|
|
| 47 |
)
|
| 48 |
|
| 49 |
# encode text with tokenizer
|
| 50 |
-
encodings = tokenizer(text)
|
| 51 |
|
| 52 |
# predict
|
| 53 |
with torch.inference_mode():
|
|
@@ -59,7 +60,7 @@ print(probs.detach().numpy())
|
|
| 59 |
```
|
| 60 |
|
| 61 |
```
|
| 62 |
-
|
| 63 |
```
|
| 64 |
|
| 65 |
|
|
@@ -71,7 +72,7 @@ To maximize performance, it is recommended to use the following thresholds per d
|
|
| 71 |
[0.415961, 0.295400, 0.429109, 0.302714]
|
| 72 |
```
|
| 73 |
|
| 74 |
-
Using these thresholds, the model achieves the
|
| 75 |
|
| 76 |
| Dimension | Precision | Recall | F1 |
|
| 77 |
|---------------------|---------------|---------------|---------------|
|
|
|
|
| 30 |
# Usage Example
|
| 31 |
|
| 32 |
```python
|
| 33 |
+
import torch
|
| 34 |
+
from transformers import AutoModelForSequenceClassification
|
| 35 |
from transformers import AutoTokenizer
|
| 36 |
|
| 37 |
# load tokenizer
|
| 38 |
tokenizer = AutoTokenizer.from_pretrained("luerhard/PopBERT")
|
| 39 |
|
| 40 |
# load model
|
| 41 |
+
model = AutoModelForSequenceClassification.from_pretrained("luerhard/PopBERT")
|
| 42 |
|
| 43 |
# define text to be predicted
|
| 44 |
text = (
|
|
|
|
| 48 |
)
|
| 49 |
|
| 50 |
# encode text with tokenizer
|
| 51 |
+
encodings = tokenizer(text, return_tensors="pt")
|
| 52 |
|
| 53 |
# predict
|
| 54 |
with torch.inference_mode():
|
|
|
|
| 60 |
```
|
| 61 |
|
| 62 |
```
|
| 63 |
+
[[0.8765146 0.34838045 0.983123 0.02148379]]
|
| 64 |
```
|
| 65 |
|
| 66 |
|
|
|
|
| 72 |
[0.415961, 0.295400, 0.429109, 0.302714]
|
| 73 |
```
|
| 74 |
|
| 75 |
+
Using these thresholds, the model achieves the following performance on the test set:
|
| 76 |
|
| 77 |
| Dimension | Precision | Recall | F1 |
|
| 78 |
|---------------------|---------------|---------------|---------------|
|