Download scripts/build_splits.py from Januka2009/INVESTIGA-ES: direct link, hf CLI and curl.
- Browser
- Download file 1.36 kB
-
https://huggingface.co/datasets/Januka2009/INVESTIGA-ES/resolve/main/scripts/build_splits.py
- Command line
-
hf download hf://datasets/Januka2009/INVESTIGA-ES/scripts/build_splits.py
-
curl -L -o build_splits.py https://huggingface.co/datasets/Januka2009/INVESTIGA-ES/resolve/main/scripts/build_splits.py
1.36 kB
| """Connected components by normalized scenario/topic/entity/template; no random row split.""" | |
| from common import * | |
| def split_sft(records): | |
| parent={r['id']:r['id'] for r in records} | |
| def find(a): | |
| while a!=parent[a]:parent[a]=parent[parent[a]];a=parent[a] | |
| return a | |
| def union(a,b): | |
| a,b=find(a),find(b) | |
| if a!=b:parent[max(a,b)]=min(a,b) | |
| seen={} | |
| for r in records: | |
| for k in ['scenario_family','topic_family','entity_family','template_family']: | |
| key=(k,norm(r[k])) | |
| if key in seen:union(r['id'],seen[key]) | |
| else:seen[key]=r['id'] | |
| for signature in template_signatures('sft',r): | |
| key=('observed_template',signature) | |
| if key in seen:union(r['id'],seen[key]) | |
| else:seen[key]=r['id'] | |
| groups={} | |
| for r in records:groups.setdefault(find(r['id']),[]).append(r) | |
| splits={'train':[],'validation':[]};assignment=[] | |
| for gid,group in sorted(groups.items()): | |
| split='validation' if int(digest('investiga-es-v4:'+gid)[:8],16)%10==0 else 'train' | |
| for r in group: | |
| splits[split].append(r);assignment.append({'id':r['id'],'group_id':gid,'split':split}) | |
| for seq in splits.values():seq.sort(key=lambda r:r['id']) | |
| return splits,assignment | |
| if __name__=='__main__':print('Group split is executed by build_v4.py.') | |