Download vision/append_release.py from tasksource/tasksource-jev-typed-decisions: direct link, hf CLI and curl.
- Browser
- Download file 7.33 kB
-
https://huggingface.co/datasets/tasksource/tasksource-jev-typed-decisions/resolve/main/vision/append_release.py
- Command line
-
hf download hf://datasets/tasksource/tasksource-jev-typed-decisions/vision/append_release.py
-
curl -L -o append_release.py https://huggingface.co/datasets/tasksource/tasksource-jev-typed-decisions/resolve/main/vision/append_release.py
7.33 kB
| """One bounded release operation: append new shards, preserving existing Hub files.""" | |
| import hashlib,json,math,re,sys | |
| from collections import Counter | |
| from pathlib import Path | |
| import yaml | |
| from datasets import DatasetDict,load_from_disk,disable_progress_bars | |
| from huggingface_hub import HfApi,hf_hub_download,CommitOperationAdd,DatasetCard | |
| from scripts.audit_vision_quality import audit | |
| ROOT=Path('build/vision-append-release'); ADD=Path('build/vision-additions-1000') | |
| BASE=Path('build/vision-expanded-5000'); REPO='tasksource/tasksource-jev-typed-decisions' | |
| PARENT='5d3d8a557f62809d690f22c2c696b44c266d1ada'; TAG='20261009' | |
| disable_progress_bars() | |
| def read(path):return json.loads(path.read_text()) | |
| def dump(path,value):path.write_text(json.dumps(value,indent=2,ensure_ascii=False)+'\n') | |
| def identities(metadata): | |
| m=json.loads(metadata);keys=set(m['image_ids']);original=m.get('augmentation',{}).get('original_image_sha256') | |
| if original:keys.add(original) | |
| return keys | |
| def stage(): | |
| api=HfApi();assert api.dataset_info(REPO).sha==PARENT,'Hub changed: review the new parent first' | |
| remote=Path(hf_hub_download(REPO,'vision/release-audit.json',repo_type='dataset',revision=PARENT)) | |
| old_audit=read(remote);assert old_audit==read(BASE/'release-audit.json') | |
| base_ids=read(ADD/'base-identities.json');old_eval=set().union(*(set(v['image_keys']) for s,v in base_ids.items() if s!='train')) | |
| old_train=set(base_ids['train']['image_keys']);all_ids=set().union(*(set(v['ids']) for v in base_ids.values())) | |
| raw=load_from_disk(str(ADD/'dataset')); selected={};drops={} | |
| for split in ['train',*(s for s in raw if s!='train')]: | |
| conflict=old_eval if split=='train' else old_train | |
| kept=[];reasons=Counter() | |
| for i,r in enumerate(raw[split].select_columns(['metadata','id','source'])): | |
| assert 'mind2web' not in r['source'] and r['id'] not in all_ids | |
| assert json.loads(r['metadata']).get('source_redistribution')!='restricted' | |
| keys=identities(r['metadata']) | |
| if keys.intersection(conflict):reasons['image_overlap_with_existing_release']+=1;continue | |
| kept.append(i);all_ids.add(r['id']) | |
| if split=='train':old_train.update(keys) | |
| selected[split]=raw[split].select(kept);drops[split]=dict(reasons) | |
| data=DatasetDict(selected);(ROOT/'additions').mkdir(exist_ok=True) | |
| data.save_to_disk(str(ROOT/'additions/dataset')) | |
| quality=audit(ROOT/'additions',ROOT/'addition-quality-audit.json',sample_per_source=2) | |
| import runpy | |
| runpy.run_path(str(ROOT/'check_gold.py'),run_name='__main__') | |
| quality['native_gold_alignment']=read(ROOT/'gold-alignment.json') | |
| files=[] | |
| for split,rows in data.items(): | |
| n=max(1,math.ceil(rows.data.nbytes/256_000_000)) | |
| for i in range(n): | |
| path=ROOT/f'{split}-addition-{TAG}-{i:05d}-of-{n:05d}.parquet' | |
| rows.shard(n,i,contiguous=True).to_parquet(path) | |
| files.append({'local':str(path),'remote':'vision/'+path.name,'bytes':path.stat().st_size, | |
| 'sha256':hashlib.sha256(path.read_bytes()).hexdigest()}) | |
| release=old_audit | |
| for split,rows in data.items(): | |
| info=release['splits'].setdefault(split,{'rows':0,'sources':{},'families':{}}) | |
| info['rows']+=len(rows) | |
| for field,values in [('sources',rows['source']),('families',('/'.join(s.split('/')[:2]) for s in rows['source']))]: | |
| total=Counter(info[field]);total.update(values);info[field]=dict(total) | |
| release['incremental_update']={'parent_revision':PARENT,'new_rows':{s:len(r) for s,r in data.items()},'excluded':drops} | |
| dump(ROOT/'release-audit.json',release) | |
| old_sources=yaml.safe_load((BASE/'sources.yaml').read_text());new_sources=yaml.safe_load((ADD/'sources.yaml').read_text()) | |
| assert not set(old_sources['sources'])&set(new_sources['sources']) | |
| for source,info in new_sources['sources'].items(): | |
| info['rows']={s:Counter(rows['source'])[source] for s,rows in data.items() if source in set(rows['source'])} | |
| old_sources['sources'].update(new_sources['sources']);old_sources['datasets']=sorted(set(old_sources['datasets'])|set(new_sources['datasets'])) | |
| old_sources['parent_tasksource_commit']=old_sources['tasksource_commit'];old_sources['tasksource_commit']=new_sources['tasksource_commit'] | |
| (ROOT/'sources.yaml').write_text(yaml.safe_dump(old_sources,sort_keys=False)) | |
| manifest={'operation_script_sha256':hashlib.sha256(Path(__file__).read_bytes()).hexdigest(),'operation':'append native visual families without rebuilding existing shards','parent_revision':PARENT, | |
| 'base_manifest':read(BASE/'build-manifest.json'),'addition_manifest':read(ADD/'build-manifest.json'), | |
| 'new_shards':files,'cross_release_exclusions':drops,'new_family_cap':{'train':1000,'evaluation':100}} | |
| dump(ROOT/'build-manifest.json',manifest) | |
| dump(ROOT/'quality-audit.json',{'base_revision':PARENT,'base_audit':read(BASE/'quality-audit.json'), | |
| 'addition_audit':quality,'manual_review':'New-source manual audits: region-audit.json and superclevr-audit.json at the tasksource Git commit in addition_manifest. This is a coarse review, not independent reannotation.'}) | |
| card=DatasetCard.load(hf_hub_download(REPO,'README.md',repo_type='dataset',revision=PARENT)) | |
| info=next(d for d in card.data.dataset_info if d['config_name']=='vision') | |
| for split,rows in data.items(): | |
| stat=next(v for v in info['splits'] if v['name']==split);stat['num_examples']+=len(rows);stat['num_bytes']+=rows.data.nbytes | |
| info['download_size']+=sum(f['bytes'] for f in files);info['dataset_size']=sum(s['num_bytes'] for s in info['splits']) | |
| counts=', '.join(f"{d['rows']:,} {s}" for s,d in release['splits'].items()) | |
| card.text=re.sub(r'(for the multimodal pilot \()[^)]+(\)\.)',lambda m:m[1]+counts+m[2],card.text) | |
| names=', '.join(sorted(old_sources['sources'])) .replace('vision/','') | |
| card.text=re.sub(r'It covers [^\n]+, with genuine source labels\.',lambda m:'It covers '+names+', with genuine source labels.',card.text) | |
| card.text=card.text.replace('unless `metadata.augmentation` records SoM rendering','unless `metadata.augmentation` records rendering (SoM, region highlighting or source keypoint marks)') | |
| card.text+='\nThe 2026-10-09 selective update adds at most 1,000 train rows per new family while preserving the existing rows and caps. Mind2Web remains excluded. HTML-only browser tasks are not part of this config.\n' | |
| card.save(ROOT/'README.md') | |
| dump(ROOT/'staged.json',{'parent':PARENT,'files':files,'new_rows':{s:len(r) for s,r in data.items()},'total_rows':{s:d['rows'] for s,d in release['splits'].items()}}) | |
| print(read(ROOT/'staged.json'),flush=True) | |
| def publish(): | |
| staged=read(ROOT/'staged.json');api=HfApi();assert api.dataset_info(REPO).sha==PARENT | |
| ops=[CommitOperationAdd(path_in_repo=f['remote'],path_or_fileobj=f['local']) for f in staged['files']] | |
| for name in ['sources.yaml','build-manifest.json','release-audit.json','quality-audit.json','append_release.py','gold-alignment.json','check_gold.py']: | |
| ops.append(CommitOperationAdd(path_in_repo='vision/'+name,path_or_fileobj=ROOT/name)) | |
| ops.append(CommitOperationAdd(path_in_repo='README.md',path_or_fileobj=ROOT/'README.md')) | |
| result=api.create_commit(REPO,repo_type='dataset',parent_commit=PARENT,operations=ops, | |
| commit_message='Expand vision selectively with audited region, preference, correspondence and Super-CLEVR families') | |
| dump(ROOT/'published.json',{'revision':result.oid,**staged});print(result,flush=True) | |
| (stage if sys.argv[1]=='stage' else publish)() | |