Datasets:
Download tokenize_preview.py from ivanleomk/bigcode-gptj-sft-preview: direct link, hf CLI and curl.
- Browser
- Download file 1.56 kB
-
https://huggingface.co/datasets/ivanleomk/bigcode-gptj-sft-preview/resolve/main/tokenize_preview.py
- Command line
-
hf download hf://datasets/ivanleomk/bigcode-gptj-sft-preview/tokenize_preview.py
-
curl -L -o tokenize_preview.py https://huggingface.co/datasets/ivanleomk/bigcode-gptj-sft-preview/resolve/main/tokenize_preview.py
1.56 kB
| """Inspect shared NTP/NextLat inputs; no model loading or training.""" | |
| import json | |
| from pathlib import Path | |
| from transformers import AutoTokenizer | |
| ROOT=Path(__file__).resolve().parent | |
| REV='47e169305d2e8376be1d31e765533382721b2cc1' | |
| tok=AutoTokenizer.from_pretrained('EleutherAI/gpt-j-6b',revision=REV) | |
| output=[] | |
| for line in (ROOT/'reviewed-preview.jsonl').read_text().splitlines(): | |
| row=json.loads(line); text=row['prompt']+row['completion']; boundary=len(row['prompt']) | |
| encoded=tok(text,return_offsets_mapping=True,add_special_tokens=False) | |
| ids=encoded['input_ids']+[tok.eos_token_id] | |
| answer=[a>=boundary and b>a for a,b in encoded['offset_mapping']]+[True] | |
| labels=[token if mask else -100 for token,mask in zip(ids,answer)] | |
| # Conceptual eligible adjacent solution-state pairs; no EOS or example-boundary crossing. | |
| latent_pairs=[answer[i] and answer[i+1] and ids[i]!=tok.eos_token_id and ids[i+1]!=tok.eos_token_id for i in range(len(ids)-1)] | |
| assert len(ids)<=2048 and len(ids)==len(labels) | |
| output.append(dict(source_id=row['source_id'],input_ids=ids,labels=labels,attention_mask=[1]*len(ids),nextlat_candidate_pair_mask=latent_pairs,prompt_tokens_masked=labels.count(-100),supervised_tokens=sum(v!=-100 for v in labels),note='Labels use standard causal-LM internal shift. Pair mask is a preview, not a full NextLat loss implementation.')) | |
| (ROOT/'tokenized-preview.jsonl').write_text(''.join(json.dumps(x)+'\n' for x in output)) | |
| print([{k:r[k] for k in ['source_id','prompt_tokens_masked','supervised_tokens']} for r in output]) | |