Text-to-Image
English
numpy
machine-learning
deep-learning
generative-ai
text-2-image
image-generation
open-weights
model-weights
ai-art
pixel-art
game-development
gamedev
game-assets
asset-generator
sprite-generator
offline
tiny-model
numpy-runtime
int8-quantization
self-supervised
procedural-data
gpt
english-prompts
awesome-ai
Upload pxg_tiny/tokenizer.py with huggingface_hub
Browse files- 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())
|