SamLowe commited on
Commit
82dad17
1 Parent(s): 7fca91d

Update README.md

Browse files
Files changed (1) hide show
  1. README.md +10 -3
README.md CHANGED
@@ -58,6 +58,9 @@ import numpy as np # only used for the postprocessing sigmoid
58
 
59
  sentences = ["hello world"] # for example a batch of 1
60
 
 
 
 
61
  tokenizer = Tokenizer.from_pretrained("SamLowe/roberta-base-go_emotions")
62
 
63
  # optional - set pad to only pad to longest in batch, not a fixed length. Without this, the model will run slower, esp for shorter input strings.
@@ -83,10 +86,14 @@ input_feed_dict = {
83
  def sigmoid(_outputs):
84
  return 1.0 / (1.0 + np.exp(-_outputs))
85
 
86
- model_output = model.run(output_names=output_names, input_feed=input_feed_dict)[0]
 
 
87
 
88
- embeddings = sigmoid(model_output)
89
- print(embeddings)
 
 
90
  ```
91
 
92
  ### Example notebook: showing usage, accuracy & performance
 
58
 
59
  sentences = ["hello world"] # for example a batch of 1
60
 
61
+ # labels as (ordered) list - from the go_emotions dataset
62
+ labels = ['admiration', 'amusement', 'anger', 'annoyance', 'approval', 'caring', 'confusion', 'curiosity', 'desire', 'disappointment', 'disapproval', 'disgust', 'embarrassment', 'excitement', 'fear', 'gratitude', 'grief', 'joy', 'love', 'nervousness', 'optimism', 'pride', 'realization', 'relief', 'remorse', 'sadness', 'surprise', 'neutral']
63
+
64
  tokenizer = Tokenizer.from_pretrained("SamLowe/roberta-base-go_emotions")
65
 
66
  # optional - set pad to only pad to longest in batch, not a fixed length. Without this, the model will run slower, esp for shorter input strings.
 
86
  def sigmoid(_outputs):
87
  return 1.0 / (1.0 + np.exp(-_outputs))
88
 
89
+ logits = model.run(output_names=output_names, input_feed=input_feed_dict)[0]
90
+
91
+ model_outputs = sigmoid(logits) # produces a numpy array, one row per input item, one col per label
92
 
93
+ # for example, just to show the top result per input item
94
+ for probas in model_outputs:
95
+ top_result_index = np.argmax(probas)
96
+ print(labels[top_result_index], "with score:", probas[top_result_index])
97
  ```
98
 
99
  ### Example notebook: showing usage, accuracy & performance