Cion-lab commited on
Commit
c9ea4eb
·
verified ·
1 Parent(s): b2ba2a9

mirror probes/ so the kept code is self-contained

Browse files
Files changed (2) hide show
  1. probes/tok_shape.py +13 -0
  2. probes/tok_unk_check.py +20 -0
probes/tok_shape.py ADDED
@@ -0,0 +1,13 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import json
2
+
3
+ d = json.load(open("tmp_tok.json", encoding="utf-8"))
4
+ v = (d.get("model") or {}).get("vocab") or {}
5
+ lt, gt = chr(60), chr(62)
6
+ unk = lt + "unk" + gt
7
+ endo = lt + "endoftext" + gt
8
+ print("model type:", (d.get("model") or {}).get("type"), "| vocab size:", len(v))
9
+ print("added ids:", [t.get("id") for t in d.get("added_tokens", [])])
10
+ print("added:", [t.get("content") for t in d.get("added_tokens", [])])
11
+ print("unk in vocab:", unk in v, "| endoftext in vocab:", endo in v)
12
+ print("id of endoftext:", v.get(endo))
13
+ print("contiguous 0..N-1:", sorted(int(i) for i in v.values()) == list(range(len(v))))
probes/tok_unk_check.py ADDED
@@ -0,0 +1,20 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import json
2
+
3
+ vocab = json.load(open("tmp_tok.json", encoding="utf-8"))["model"]["vocab"]
4
+
5
+
6
+ def content(d, key):
7
+ v = d.get(key)
8
+ return v.get("content") if isinstance(v, dict) else v
9
+
10
+
11
+ for f in ("code/config/smolm2_tokenizer_config.json", "code/config/smolm2_special_tokens_map.json"):
12
+ d = json.load(open(f, encoding="utf-8"))
13
+ u = content(d, "unk_token")
14
+ e = content(d, "eos_token")
15
+ b = content(d, "bos_token")
16
+ print(f)
17
+ print(" unk:", repr(u), "in_vocab:", (u in vocab) if u else None,
18
+ "-> would null it:", bool(u) and u not in vocab)
19
+ print(" eos:", repr(e), "in_vocab:", (e in vocab) if e else None, "id:", vocab.get(e) if e else None)
20
+ print(" bos:", repr(b), "in_vocab:", (b in vocab) if b else None, "id:", vocab.get(b) if b else None)