Download runs/scripts/tok_hook_run.py from BlueSourceJY/ERCBench-MultiShotMaster-400: direct link, hf CLI and curl.
- Browser
- Download file 1.07 kB
-
https://huggingface.co/datasets/BlueSourceJY/ERCBench-MultiShotMaster-400/resolve/main/runs/scripts/tok_hook_run.py
- Command line
-
hf download hf://datasets/BlueSourceJY/ERCBench-MultiShotMaster-400/runs/scripts/tok_hook_run.py
-
curl -L -o tok_hook_run.py https://huggingface.co/datasets/BlueSourceJY/ERCBench-MultiShotMaster-400/resolve/main/runs/scripts/tok_hook_run.py
1.07 kB
| # Log-only wrapper: records every string the model's own HuggingfaceTokenizer receives (raw + cleaned + untruncated | |
| # token count), then runs the unmodified-entry script. Does not change any tensor or argument. | |
| import importlib, json, os, runpy, sys | |
| mod_name, log_path, script = sys.argv[1], sys.argv[2], sys.argv[3] | |
| sys.argv = [script] + sys.argv[4:] | |
| sys.path.insert(0, os.path.dirname(os.path.abspath(script))) | |
| mod = importlib.import_module(mod_name) | |
| cls = mod.HuggingfaceTokenizer; orig = cls.__call__ | |
| def logged(self, sequence, **kw): | |
| seqs = [sequence] if isinstance(sequence, str) else list(sequence) | |
| with open(log_path, "a", encoding="utf-8") as f: | |
| for s in seqs: | |
| c = self._clean(s) if self.clean else s | |
| n = len(self.tokenizer(c, add_special_tokens=kw.get("add_special_tokens", True)).input_ids) | |
| f.write(json.dumps({"raw": s, "cleaned": c, "n_tokens": n, "seq_len": self.seq_len}, ensure_ascii=False) + "\n") | |
| return orig(self, sequence, **kw) | |
| cls.__call__ = logged | |
| runpy.run_path(script, run_name="__main__") | |