CISCai commited on
Commit
afe8ab5
1 Parent(s): ee7df4f

Show token value for token_id in metadata table

Browse files
Files changed (1) hide show
  1. app.py +10 -3
app.py CHANGED
@@ -33,6 +33,8 @@ def init_state(
33
 
34
 
35
  def human_readable_metadata(
 
 
36
  typ: int,
37
  val: Any,
38
  ) -> tuple[str, Any]:
@@ -47,8 +49,13 @@ def human_readable_metadata(
47
  val = str(val[:8])[:-1] + ', ...]'
48
  else:
49
  val = str(val)
 
 
 
 
 
50
 
51
- return typ, val
52
 
53
 
54
  with gr.Blocks(
@@ -318,7 +325,7 @@ with gr.Blocks(
318
  meta.var['branch'] = branch
319
 
320
  for k, v in progress.tqdm(metadata, desc = 'Reading metadata...', total = num_metadata, unit = f' of {num_metadata} metadata keys...'):
321
- m.append([k, *human_readable_metadata(v.type, v.value)])
322
  meta.key[k] = (v.type, v.value)
323
 
324
  # FIXME
@@ -481,7 +488,7 @@ with gr.Blocks(
481
 
482
  m = []
483
  for k, v in meta.key.items():
484
- m.append([k, *human_readable_metadata(v[0], v[1])])
485
 
486
  link = str(request.request.url_for('download', repo_file = meta.var['repo_file']).include_query_params(branch = meta.var['branch']))
487
  if link.startswith('http:'):
 
33
 
34
 
35
  def human_readable_metadata(
36
+ meta: MetadataState,
37
+ key: str,
38
  typ: int,
39
  val: Any,
40
  ) -> tuple[str, Any]:
 
49
  val = str(val[:8])[:-1] + ', ...]'
50
  else:
51
  val = str(val)
52
+ elif key.endswith('_token_id'):
53
+ tokens = meta.key.get('tokenizer.ggml.tokens', (-1, []))[1]
54
+
55
+ if isinstance(val, int) and val >= 0 and val < len(tokens):
56
+ val = f'{tokens[val]} ({val})'
57
 
58
+ return key, typ, val
59
 
60
 
61
  with gr.Blocks(
 
325
  meta.var['branch'] = branch
326
 
327
  for k, v in progress.tqdm(metadata, desc = 'Reading metadata...', total = num_metadata, unit = f' of {num_metadata} metadata keys...'):
328
+ m.append([*human_readable_metadata(meta, k, v.type, v.value)])
329
  meta.key[k] = (v.type, v.value)
330
 
331
  # FIXME
 
488
 
489
  m = []
490
  for k, v in meta.key.items():
491
+ m.append([*human_readable_metadata(meta, k, v[0], v[1])])
492
 
493
  link = str(request.request.url_for('download', repo_file = meta.var['repo_file']).include_query_params(branch = meta.var['branch']))
494
  if link.startswith('http:'):