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