Update README.md
Browse files
README.md
CHANGED
@@ -20,21 +20,19 @@ metrics:
|
|
20 |
# get category probability
|
21 |
def get_category_proba( text ):
|
22 |
max_length = 250
|
23 |
-
# prepare
|
24 |
inputs = tokenizer([text], padding=True, truncation=True, max_length=max_length, return_tensors="pt")
|
25 |
-
# perform inference
|
26 |
outputs = model(**inputs)
|
27 |
# get output probabilities by doing softmax
|
28 |
probs = outputs[0].softmax(1)
|
29 |
|
30 |
-
# executing argmax function to get the candidate label
|
31 |
-
# probs.argmax()
|
32 |
label_index = probs.argmax(dim=1)[0].tolist() # convert tensor to int
|
33 |
-
#
|
34 |
-
|
35 |
label = idx2cate[ label_index ]
|
36 |
|
37 |
-
#
|
38 |
proba = round(float(probs.tolist()[0][label_index]),2)
|
39 |
|
40 |
response = {'label': label, 'proba': proba}
|
|
|
20 |
# get category probability
|
21 |
def get_category_proba( text ):
|
22 |
max_length = 250
|
23 |
+
# prepare token sequence
|
24 |
inputs = tokenizer([text], padding=True, truncation=True, max_length=max_length, return_tensors="pt")
|
25 |
+
# perform inference
|
26 |
outputs = model(**inputs)
|
27 |
# get output probabilities by doing softmax
|
28 |
probs = outputs[0].softmax(1)
|
29 |
|
30 |
+
# executing argmax function to get the candidate label index
|
|
|
31 |
label_index = probs.argmax(dim=1)[0].tolist() # convert tensor to int
|
32 |
+
# get the label name
|
|
|
33 |
label = idx2cate[ label_index ]
|
34 |
|
35 |
+
# get the label probability
|
36 |
proba = round(float(probs.tolist()[0][label_index]),2)
|
37 |
|
38 |
response = {'label': label, 'proba': proba}
|