"""Wave 2: Shome/hr-curated-text — all curated Croatian prose except the non-commercial Riznica (PUBLISH-PLAN.md). python build_wave2.py -> hr-curated-text/data//-NNNNN.parquet, hr-curated-text/stats.json - Configs: classla-web, wikipedia, wikisource, wikibooks (curated-v1 release), fineweb2, finepdfs, parlamint (curated-v2 release); splits train / validation (= release dev) / test. - Curated-v1 training documents flagged by the extended evaluation screen (curated-v2 work/v1-rescreen.json) are dropped. - Web configs (classla-web, fineweb2, finepdfs): e-mail addresses -> , phone numbers -> ; counts kept. - Columns: id, text, source, license. """ import gzip import json import re import sys from pathlib import Path import pandas as pd HERE = Path(__file__).resolve().parent DS = HERE.parent / 'datasets' V1, V2 = DS / 'minimind-pretrain-curated-v1/release', DS / 'minimind-pretrain-curated-v2/release' OUT = HERE / 'hr-curated-text' CONFIGS = { 'classla-web': (V1, 'hr-classla-web', 'CC0-1.0', True), 'fineweb2': (V2, 'hr-fineweb2', 'ODC-By-1.0', True), 'finepdfs': (V2, 'hr-finepdfs', 'ODC-By-1.0', True), 'wikipedia': (V1, 'hr-wikipedia', 'CC-BY-SA-4.0', False), 'wikisource': (V1, 'hr-wikisource', 'CC-BY-SA-4.0', False), 'wikibooks': (V1, 'hr-wikibooks', 'CC-BY-SA-4.0', False), 'parlamint': (V2, 'hr-parlamint', 'CC-BY-4.0', False), } SPLITS = {'train': 'train', 'validation': 'dev', 'test': 'test'} EMAIL = re.compile(r'[\w.+-]+ ?@ ?\w+(?:- ?\w+)*(?: ?\. ?\w+(?:- ?\w+)*)*(?: ?\. ?)(?:hr|com|net|org|eu|info|ba|si|rs|de|at|it|edu|gov|biz|me|io|uk|ch|fr|hu)\b', re.I) PHONE = re.compile(r'(?' if intl or mobile or keyed else t return PHONE.sub(phone, text) SHARD_CHARS = 180_000_000 def mask(t, c): t, a = EMAIL.subn('', t) n0 = t.count('') t = phone_sub(t) c['emails'] += a c['phones'] += t.count('') - n0 return t def main(): skip = {k: set(v) for k, v in json.loads((DS / 'minimind-pretrain-curated-v2/work/v1-rescreen.json').read_text()).items()} stats = {} for cfg, (root, src, lic, web) in CONFIGS.items(): for split, rel in SPLITS.items(): path = root / rel / f'{src}.jsonl.gz' if not path.exists(): continue c = dict(documents=0, words=0, emails=0, phones=0, dropped_screen=0) shard, chars, k = [], 0, 0 d = OUT / 'data' / cfg d.mkdir(parents=True, exist_ok=True) def flush(): nonlocal shard, chars, k if shard: pd.DataFrame(shard).to_parquet(d / f'{split}-{k:05d}.parquet', index=False) shard, chars, k = [], 0, k + 1 for line in gzip.open(path, 'rt'): r = json.loads(line) if split == 'train' and root == V1 and r['id'] in skip.get(src, ()): c['dropped_screen'] += 1 continue t = mask(r['text'], c) if web else r['text'] shard.append(dict(id=r['id'], text=t, source=cfg, license=lic)) c['documents'] += 1 c['words'] += len(t.split()) chars += len(t) if chars >= SHARD_CHARS: flush() flush() c['shards'] = k stats[f'{cfg}/{split}'] = c print(cfg, split, c, flush=True) (OUT / 'stats.json').write_text(json.dumps(stats, indent=1)) if __name__ == '__main__': main()