Tarul commited on
Commit
c8e9e8a
·
verified ·
1 Parent(s): f001fd1

Upload pxg_tiny/tokenizer.py with huggingface_hub

Browse files
Files changed (1) hide show
  1. pxg_tiny/tokenizer.py +16 -0
pxg_tiny/tokenizer.py ADDED
@@ -0,0 +1,16 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ """Tokenizer utilities for PXG-Tiny (text <-> ids), thin wrapper over config."""
2
+ import sys
3
+ from pathlib import Path
4
+
5
+ sys.path.insert(0, str(Path(__file__).resolve().parents[1] / "src"))
6
+ from pxg_tiny import config as C # noqa: E402,E501
7
+
8
+ encode_caption = C.encode_caption
9
+ decode_caption = C.decode_caption
10
+ CAP_LEN = C.CAP_LEN
11
+
12
+
13
+ def sanitize(text: str) -> str:
14
+ """Lowercase + fold unsupported glyphs (mirrors byte-fallback philosophy)."""
15
+ return "".join(ch if C.decode_char(C.encode_char(ch)) == ch
16
+ else "?" for ch in text.lower())