clhuang commited on
Commit
66c789c
1 Parent(s): 71b2877

Update README.md

Browse files
Files changed (1) hide show
  1. README.md +5 -7
README.md CHANGED
@@ -20,21 +20,19 @@ metrics:
20
  # get category probability
21
  def get_category_proba( text ):
22
  max_length = 250
23
- # prepare our text into tokenized sequence
24
  inputs = tokenizer([text], padding=True, truncation=True, max_length=max_length, return_tensors="pt")
25
- # perform inference to our model
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
- # label_index = np.argmax(probs.detach(), axis=1)
34
-
35
  label = idx2cate[ label_index ]
36
 
37
- # Note that result is numpy format and it should be convert to float
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}