| """ |
| Faz 1 / Adım 2 — Shard doğrulama. |
| Manifest + parquet shard'ları yükle, dizi uzunluklarını kontrol et, bir diziyi |
| geri-decode et (tokenizer sağlam mı), token/dizi istatistiği. |
| |
| Kullanım: python kod/faz1_02_verify.py --source en_fineweb_edu |
| """ |
| import os, sys, json, glob, argparse |
| sys.path.insert(0, os.path.dirname(os.path.abspath(__file__))) |
| import pyarrow.parquet as pq |
| from sc_tokenizer import SCTokenizer |
|
|
|
|
| def main(): |
| ap = argparse.ArgumentParser() |
| ap.add_argument("--source", required=True) |
| ap.add_argument("--dir", default="kod/data/shards") |
| args = ap.parse_args() |
| d = os.path.join(args.dir, args.source) |
| man = json.load(open(os.path.join(d, "manifest.json"), encoding="utf-8")) |
| seq_len = man["seq_len"] |
| print(f"manifest: {man['source']} lang={man['lang']} | {man['n_seqs']} dizi " |
| f"| {man['n_tokens']/1e6:.2f}M token | {len(man['shards'])} shard") |
|
|
| files = sorted(glob.glob(os.path.join(d, "shard_*.parquet"))) |
| tok = SCTokenizer() |
| total, bad = 0, 0 |
| for fp in files: |
| t = pq.read_table(fp) |
| ids_col = t.column("input_ids").to_pylist() |
| for row in ids_col: |
| total += 1 |
| if len(row) != seq_len: |
| bad += 1 |
| |
| if fp == files[0]: |
| first = ids_col[0] |
| print(f" ilk dizi: {len(first)} token | min={min(first)} max={max(first)} " |
| f"(vocab={tok.vocab_size})") |
| print(" decode örnek (ilk 60 token):") |
| print(" ", repr(tok.decode(first[:60])[:220])) |
| print(f"[verify] {len(files)} shard, {total} dizi okundu | " |
| f"yanlış-uzunluk: {bad} | {'TUM OK' if bad == 0 else 'UYARI'}") |
|
|
|
|
| if __name__ == "__main__": |
| main() |
|
|