m-ric HF staff commited on
Commit
fe4c0f1
β€’
1 Parent(s): f6daa90

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +12 -17
app.py CHANGED
@@ -35,6 +35,7 @@ STYLE = """
35
  padding-right: 2px;
36
  padding-top: 0;
37
  padding-bottom: 0;
 
38
  }
39
  .tree {
40
  padding: 0px;
@@ -137,10 +138,10 @@ a:before {
137
  text-decoration-line: none;
138
  border-radius: 5px;
139
  transition: .5s;
140
- width: 280px;
141
  display: flex;
142
  align-items: center;
143
- justify-content: space-around;
 
144
  }
145
  .tree li a span {
146
  padding: 5px;
@@ -157,13 +158,19 @@ a:before {
157
  }
158
  .end-of-text, .chosen {
159
  background-color: #ea580c;
 
 
160
  width:auto!important;
161
  }
 
 
 
 
162
  """
163
 
164
 
165
  def clean(s):
166
- return s.replace("\n", r"\n").replace("\t", r"\t")
167
 
168
 
169
  def generate_markdown_table(
@@ -197,10 +204,10 @@ def generate_nodes(token_ix, node, step):
197
  token = tokenizer.decode([token_ix])
198
 
199
  if node.is_final:
200
- return f"<li> <a href='#' class='end-of-text'> <span> <b>{token_ix}:<br>{clean(token)}</b> <br> Total score: {node.total_score:.2f} </span> </a> </li>"
201
 
202
  html_content = (
203
- f"<li> <a href='#'> <span> <b>{token_ix}:<br>{clean(token)}</b> </span>"
204
  )
205
  if node.table is not None:
206
  html_content += node.table
@@ -265,8 +272,6 @@ def generate_beams(start_sentence, scores, sequences, length_penalty):
265
  n_beams = len(scores[0])
266
  beam_trees = [original_tree] * n_beams
267
 
268
- candidate_nodes = []
269
-
270
  for step, step_scores in enumerate(scores):
271
  (
272
  top_token_indexes,
@@ -359,16 +364,6 @@ def generate_beams(start_sentence, scores, sequences, length_penalty):
359
  ),
360
  )
361
 
362
- # Check this child should be selected as a top beam.
363
- # Is it a final step or an EOS token?
364
- if (
365
- step == len(scores) - 1
366
- or current_token_choice_ix == tokenizer.eos_token_id
367
- ):
368
- candidate_nodes.append(
369
- beam_trees[source_beam_ix].children[current_token_choice_ix]
370
- )
371
-
372
  # Reassign all beams at once
373
  beam_trees = [
374
  beam_trees[int(top_df_selected.iloc[beam_ix]["beam_index"])]
 
35
  padding-right: 2px;
36
  padding-top: 0;
37
  padding-bottom: 0;
38
+ text-wrap:nowrap;
39
  }
40
  .tree {
41
  padding: 0px;
 
138
  text-decoration-line: none;
139
  border-radius: 5px;
140
  transition: .5s;
 
141
  display: flex;
142
  align-items: center;
143
+ justify-content: space-between;
144
+ overflow: hidden;
145
  }
146
  .tree li a span {
147
  padding: 5px;
 
158
  }
159
  .end-of-text, .chosen {
160
  background-color: #ea580c;
161
+ }
162
+ .end-of-text {
163
  width:auto!important;
164
  }
165
+ .nonfinal {
166
+ width:280px;
167
+ min-width: 280px;
168
+ }
169
  """
170
 
171
 
172
  def clean(s):
173
+ return s.replace("\n", r"\n").replace("\t", r"\t").strip()
174
 
175
 
176
  def generate_markdown_table(
 
204
  token = tokenizer.decode([token_ix])
205
 
206
  if node.is_final:
207
+ return f"<li> <a href='#' class='end-of-text'> <span> <b>{clean(token)}</b> <br>Total score: {node.total_score:.2f}</span> </a> </li>"
208
 
209
  html_content = (
210
+ f"<li> <a href='#' class='nonfinal'> <span> <b>{clean(token)}</b> </span>"
211
  )
212
  if node.table is not None:
213
  html_content += node.table
 
272
  n_beams = len(scores[0])
273
  beam_trees = [original_tree] * n_beams
274
 
 
 
275
  for step, step_scores in enumerate(scores):
276
  (
277
  top_token_indexes,
 
364
  ),
365
  )
366
 
 
 
 
 
 
 
 
 
 
 
367
  # Reassign all beams at once
368
  beam_trees = [
369
  beam_trees[int(top_df_selected.iloc[beam_ix]["beam_index"])]