Update README.md
Browse files
README.md
CHANGED
@@ -37,23 +37,19 @@ 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])
|
|
|
37 |
import numpy as np
|
38 |
from scipy.special import expit
|
39 |
|
|
|
40 |
MODEL = "PavanDeepak/Topic_Classification"
|
41 |
tokenizer = AutoTokenizer.from_pretrained(MODEL)
|
42 |
model = AutoModelForSequenceClassification.from_pretrained(MODEL)
|
43 |
class_mapping = model.config.id2label
|
44 |
|
|
|
45 |
text = "I love chicken manchuria"
|
46 |
tokens = tokenizer(text, return_tensors="pt")
|
47 |
output = model(**tokens)
|
48 |
|
|
|
49 |
scores = output.logits[0][0].detach().numpy()
|
50 |
scores = expit(scores)
|
51 |
predictions = (scores >= 0.5) * 1
|
52 |
|
|
|
53 |
for i in range(len(predictions)):
|
54 |
if predictions[i]:
|
55 |
print(class_mapping[i])
|