Download tests/tokenizer/test_export.py from Kolgrim/hades: direct link, hf CLI and curl.
- Browser
- Download file 1.17 kB
-
https://huggingface.co/Kolgrim/hades/resolve/main/tests/tokenizer/test_export.py
- Command line
-
hf download hf://Kolgrim/hades/tests/tokenizer/test_export.py
-
curl -L -o test_export.py https://huggingface.co/Kolgrim/hades/resolve/main/tests/tokenizer/test_export.py
1.17 kB
| from hades.tokenizer.export import encode_fast, export_hf, load_fast | |
| from tests.conftest import FIXTURE_LINES | |
| def test_parity_on_fixture(trained_small, tmp_path): | |
| export_hf(trained_small, tmp_path / "t.json") | |
| fast = load_fast(tmp_path / "t.json") | |
| texts = FIXTURE_LINES + ["<|eos|> literal", "", " ", "é漢字 CVE-2024-3094", "\x00\x1b[31m", "á ①②"] | |
| assert encode_fast(fast, texts) == [trained_small.encode(t) for t in texts] | |
| def test_fast_decode_matches(trained_small, tmp_path): | |
| export_hf(trained_small, tmp_path / "t.json") | |
| fast = load_fast(tmp_path / "t.json") | |
| ids = trained_small.encode(FIXTURE_LINES[0]) | |
| assert fast.decode(ids) == FIXTURE_LINES[0] | |
| def test_parity_random_unicode(trained_small, tmp_path): | |
| import random | |
| export_hf(trained_small, tmp_path / "t.json") | |
| fast = load_fast(tmp_path / "t.json") | |
| rng = random.Random(1) | |
| pool = "ab Z9 \t\n\r é́漢①٣_-./[]:;<>|" + "".join(chr(c) for c in range(0x80, 0x100)) | |
| texts = ["".join(rng.choice(pool) for _ in range(rng.randint(0, 40))) for _ in range(500)] | |
| assert encode_fast(fast, texts) == [trained_small.encode(t) for t in texts] | |