Download test_encode.py from DevGwardo/minicpm5-toolcall-code: direct link, hf CLI and curl.
- Browser
- Download file 732 Bytes
-
https://huggingface.co/datasets/DevGwardo/minicpm5-toolcall-code/resolve/main/test_encode.py
- Command line
-
hf download hf://datasets/DevGwardo/minicpm5-toolcall-code/test_encode.py
-
curl -L -o test_encode.py https://huggingface.co/datasets/DevGwardo/minicpm5-toolcall-code/resolve/main/test_encode.py
732 Bytes
| import json | |
| import sys | |
| sys.path.insert(0, "pipeline") | |
| from transformers import AutoTokenizer | |
| import train_eval as te | |
| tok = AutoTokenizer.from_pretrained(te.MODEL_ID) | |
| tok.pad_token = tok.eos_token | |
| for name in ("data_native/train.jsonl", "data_native/mt_train.jsonl", "data_native/mt_test.jsonl"): | |
| rows = [json.loads(l) for l in open(name, encoding="utf-8")][:60] | |
| ok = [e for e in (te.encode(tok, r, 1024) for r in rows) if e] | |
| sup = [sum(1 for x in e["labels"] if x != -100) for e in ok] | |
| print(f"{name}: accepted {len(ok)}/{len(rows)} supervised tokens avg={sum(sup)//max(1,len(sup))}") | |
| if ok: | |
| e = ok[-1] | |
| print(" sample target:", repr(tok.decode([x for x in e["labels"] if x != -100])[:220])) | |