Datasets:
Download load_dataset.py from walled120/VDEBench: direct link, hf CLI and curl.
- Browser
- Download file 1.92 kB
-
https://huggingface.co/datasets/walled120/VDEBench/resolve/main/load_dataset.py
- Command line
-
hf download hf://datasets/walled120/VDEBench/load_dataset.py
-
curl -L -o load_dataset.py https://huggingface.co/datasets/walled120/VDEBench/resolve/main/load_dataset.py
1.92 kB
| """Read local VDE-compatible JSON; no network, OCR, models or writes.""" | |
| import argparse,json | |
| from pathlib import Path | |
| def read_records(root,region=None,edit_type=None,source_dataset=None,data_source=None,source_group=None): | |
| root=Path(root);provenance={} | |
| for path in [root/'provenance_and_validation.json',root/'metadata/provenance_and_validation.json']: | |
| if path.is_file(): | |
| obj=json.loads(path.read_text(encoding='utf-8-sig'));rows=obj if isinstance(obj,list) else obj.get('records',[]);provenance={str(r['id']):r for r in rows};break | |
| if source_dataset is not None or source_group is not None: | |
| if not provenance:raise ValueError('Source filter requires a per-ID provenance sidecar; no source identity is inferred from data_source.') | |
| result=[] | |
| for kind in (['text','table'] if region is None else [region]): | |
| if kind not in ['text','table']:raise ValueError('region must be text or table') | |
| rows=json.loads((root/(kind+'_info_all.json')).read_text(encoding='utf-8-sig')) | |
| for r in rows: | |
| meta=provenance.get(str(r['id']),{});typ=r.get('instruction type') if kind=='text' else r.get('edit_type') | |
| if edit_type is not None and typ!=edit_type:continue | |
| if source_dataset is not None and meta.get('source_dataset')!=source_dataset:continue | |
| if source_group is not None and meta.get('source_group')!=source_group:continue | |
| if data_source is not None and r.get('data_source')!=data_source:continue | |
| result.append(dict(r,_region=kind,_provenance=meta)) | |
| return result | |
| if __name__=='__main__': | |
| p=argparse.ArgumentParser();p.add_argument('--root',default='.');p.add_argument('--region',choices=['text','table']);p.add_argument('--edit',dest='edit_type');p.add_argument('--source-dataset');p.add_argument('--source-group');p.add_argument('--data-source');a=p.parse_args();rows=read_records(**vars(a));print(json.dumps({'count':len(rows),'example_ids':[r['id'] for r in rows[:10]]},ensure_ascii=False)) | |