Pendrokar commited on
Commit
f631ef8
1 Parent(s): 0eefaf8

label output

Browse files
Files changed (2) hide show
  1. README.md +1 -1
  2. app.py +13 -13
README.md CHANGED
@@ -7,7 +7,7 @@ sdk: gradio
7
  sdk_version: 4.8.0
8
  python_version: 3.8
9
  model_name: hf-deepmoji
10
- base_model: Pendrokar/TorchMoji
11
  app_file: app.py
12
  pinned: false
13
  license: gpl-3.0
 
7
  sdk_version: 4.8.0
8
  python_version: 3.8
9
  model_name: hf-deepmoji
10
+ base_model: Uberduck/torchmoji
11
  app_file: app.py
12
  pinned: false
13
  license: gpl-3.0
app.py CHANGED
@@ -17,13 +17,16 @@ model_name = "Uberduck/torchmoji"
17
  model_path = hf_hub_download(repo_id=model_name, filename="pytorch_model.bin")
18
  vocab_path = hf_hub_download(repo_id=model_name, filename="vocabulary.json")
19
 
 
 
 
 
20
  def top_elements(array, k):
21
  ind = np.argpartition(array, -k)[-k:]
22
  return ind[np.argsort(array[ind])][::-1]
23
 
24
  maxlen = 30
25
 
26
- print('Tokenizing using dictionary from {}'.format(vocab_path))
27
  with open(vocab_path, 'r') as f:
28
  vocabulary = json.load(f)
29
 
@@ -32,7 +35,7 @@ st = SentenceTokenizer(vocabulary, maxlen)
32
  model = torchmoji_emojis(model_path)
33
 
34
  def predict(deepmoji_analysis, emoji_count):
35
- output_text = "\n"
36
  tokenized, _, _ = st.tokenize_sentences([deepmoji_analysis])
37
  prob = model(tokenized)
38
 
@@ -42,24 +45,21 @@ def predict(deepmoji_analysis, emoji_count):
42
  # at the root of the torchMoji repo.
43
  scores = []
44
  for i, t in enumerate([deepmoji_analysis]):
45
- t_tokens = tokenized[i]
46
- t_score = [t]
47
  t_prob = prob[i]
48
- ind_top = top_elements(t_prob, emoji_count)
49
- t_score.append(sum(t_prob[ind_top]))
50
- t_score.extend(ind_top)
51
- t_score.extend([t_prob[ind] for ind in ind_top])
52
- scores.append(t_score)
53
- output_text += str(t_score)
54
 
55
- return str(tokenized) + output_text
56
 
57
  input_textbox = gr.Textbox(
58
  label="English Text",
59
  lines=1,
60
  value=""
61
  )
62
- slider = gr.Slider(1, 64, value=5, step=1, label="Top # Emoji", info="Choose between 1 and 64")
63
 
64
  gradio_app = gr.Interface(
65
  predict,
@@ -67,7 +67,7 @@ gradio_app = gr.Interface(
67
  input_textbox,
68
  slider,
69
  ],
70
- outputs="text",
71
  examples=[
72
  ["You love hurting me, huh?", 5],
73
  ["I know good movies, this ain't one", 5],
 
17
  model_path = hf_hub_download(repo_id=model_name, filename="pytorch_model.bin")
18
  vocab_path = hf_hub_download(repo_id=model_name, filename="vocabulary.json")
19
 
20
+ emoji_codes = []
21
+ with open('./data/emoji_codes.json', 'r') as f:
22
+ emoji_codes = json.load(f)
23
+
24
  def top_elements(array, k):
25
  ind = np.argpartition(array, -k)[-k:]
26
  return ind[np.argsort(array[ind])][::-1]
27
 
28
  maxlen = 30
29
 
 
30
  with open(vocab_path, 'r') as f:
31
  vocabulary = json.load(f)
32
 
 
35
  model = torchmoji_emojis(model_path)
36
 
37
  def predict(deepmoji_analysis, emoji_count):
38
+ return_label = dict[str, float]
39
  tokenized, _, _ = st.tokenize_sentences([deepmoji_analysis])
40
  prob = model(tokenized)
41
 
 
45
  # at the root of the torchMoji repo.
46
  scores = []
47
  for i, t in enumerate([deepmoji_analysis]):
 
 
48
  t_prob = prob[i]
49
+ # sort top
50
+ ind_top_ids = top_elements(t_prob, emoji_count)
51
+
52
+ for ind in ind_top_ids:
53
+ return_label[emoji_codes[ind]] = t_prob[ind]
 
54
 
55
+ return return_label
56
 
57
  input_textbox = gr.Textbox(
58
  label="English Text",
59
  lines=1,
60
  value=""
61
  )
62
+ slider = gr.Slider(1, 64, value=5, step=1, label="Top # Emoji", info="Choose between 1 and 64 top emojis to show")
63
 
64
  gradio_app = gr.Interface(
65
  predict,
 
67
  input_textbox,
68
  slider,
69
  ],
70
+ outputs="label",
71
  examples=[
72
  ["You love hurting me, huh?", 5],
73
  ["I know good movies, this ain't one", 5],