bglearning commited on
Commit
0fde90f
1 Parent(s): f9dd31c

Move the token counts to the front

Browse files
Files changed (1) hide show
  1. tapas_visualizer.py +6 -4
tapas_visualizer.py CHANGED
@@ -120,9 +120,9 @@ class TapasVisualizer:
120
  row_html += f"<{cell_element}>{cell_html}</{cell_element}>"
121
  row_token_cnt += len(cur_cell_tokens)
122
  cumulative_cnt += row_token_cnt
123
- # cnt_str = f'{row_token_cnt} | {cumulative_cnt}'
124
- row_html += f'<td style="border: none;" align="right">{self.style_span(str(row_token_cnt), ["non-token", "count"])}</td>'
125
- row_html += f'<td style="border: none;" align="right">{self.style_span(str(cumulative_cnt), ["non-token", "count"])}</td>'
126
  table_html += f'<tr>{row_html}</tr>'
127
 
128
  return table_html, cumulative_cnt
@@ -141,12 +141,14 @@ class TapasVisualizer:
141
  if int(segment_id) == 1:
142
  cell_tokens[(row_id, col_id)].append(token_text)
143
 
 
 
144
  table_html, cumulative_cnt = self.cells_to_html(cell_vals=[table.columns],
145
  cell_tokens=cell_tokens,
146
  row_id_start=0,
147
  cell_element="th",
148
  cumulative_cnt=0,
149
- table_html="")
150
 
151
  table_html, cumulative_cnt = self.cells_to_html(cell_vals=table.values,
152
  cell_tokens=cell_tokens,
 
120
  row_html += f"<{cell_element}>{cell_html}</{cell_element}>"
121
  row_token_cnt += len(cur_cell_tokens)
122
  cumulative_cnt += row_token_cnt
123
+ cnt_html = (f'<td style="border: none;" align="right">{self.style_span(str(cumulative_cnt), ["non-token", "count"])}</td>'
124
+ f'<td style="border: none;" align="right">{self.style_span(f"<+{row_token_cnt}", ["non-token", "count"])}</td>')
125
+ row_html = cnt_html + row_html
126
  table_html += f'<tr>{row_html}</tr>'
127
 
128
  return table_html, cumulative_cnt
 
141
  if int(segment_id) == 1:
142
  cell_tokens[(row_id, col_id)].append(token_text)
143
 
144
+ table_html = '<tr><td style="border: none;" colspan="2" align="left">#Tokens</td></tr>'
145
+
146
  table_html, cumulative_cnt = self.cells_to_html(cell_vals=[table.columns],
147
  cell_tokens=cell_tokens,
148
  row_id_start=0,
149
  cell_element="th",
150
  cumulative_cnt=0,
151
+ table_html=table_html)
152
 
153
  table_html, cumulative_cnt = self.cells_to_html(cell_vals=table.values,
154
  cell_tokens=cell_tokens,