Update README.md
Browse files
README.md
CHANGED
|
@@ -34,28 +34,27 @@ The model leverages the BertForSequenceClassification architecture, It has been
|
|
| 34 |
## Example
|
| 35 |
|
| 36 |
```python
|
| 37 |
-
|
| 38 |
-
|
| 39 |
-
|
| 40 |
|
| 41 |
-
|
| 42 |
-
|
| 43 |
-
|
| 44 |
-
|
| 45 |
|
| 46 |
-
|
| 47 |
-
|
| 48 |
-
|
| 49 |
|
| 50 |
-
|
| 51 |
-
|
| 52 |
-
|
| 53 |
-
|
| 54 |
-
>>> for i in range(len(predictions)):
|
| 55 |
-
>>> if predictions[i]:
|
| 56 |
-
>>> print(class_mapping[i])
|
| 57 |
-
```python
|
| 58 |
|
|
|
|
|
|
|
|
|
|
|
|
|
| 59 |
|
| 60 |
## Output:
|
| 61 |
|
|
|
|
| 34 |
## Example
|
| 35 |
|
| 36 |
```python
|
| 37 |
+
from transformers import AutoModelForSequenceClassification, AutoTokenizer
|
| 38 |
+
import numpy as np
|
| 39 |
+
from scipy.special import expit
|
| 40 |
|
| 41 |
+
MODEL = "PavanDeepak/Topic_Classification"
|
| 42 |
+
tokenizer = AutoTokenizer.from_pretrained(MODEL)
|
| 43 |
+
model = AutoModelForSequenceClassification.from_pretrained(MODEL)
|
| 44 |
+
class_mapping = model.config.id2label
|
| 45 |
|
| 46 |
+
text = "I love chicken manchuria"
|
| 47 |
+
tokens = tokenizer(text, return_tensors="pt")
|
| 48 |
+
output = model(**tokens)
|
| 49 |
|
| 50 |
+
scores = output.logits[0][0].detach().numpy()
|
| 51 |
+
scores = expit(scores)
|
| 52 |
+
predictions = (scores >= 0.5) * 1
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 53 |
|
| 54 |
+
for i in range(len(predictions)):
|
| 55 |
+
if predictions[i]:
|
| 56 |
+
print(class_mapping[i])
|
| 57 |
+
```
|
| 58 |
|
| 59 |
## Output:
|
| 60 |
|