Download tools/export_dataset.py from PureOne/Nhoshiyalun72-Soryuma-Conserved-Task-Memory: direct link, hf CLI and curl.
- Browser
- Download file 6.12 kB
-
https://huggingface.co/datasets/PureOne/Nhoshiyalun72-Soryuma-Conserved-Task-Memory/resolve/main/tools/export_dataset.py
- Command line
-
hf download hf://datasets/PureOne/Nhoshiyalun72-Soryuma-Conserved-Task-Memory/tools/export_dataset.py
-
curl -L -o export_dataset.py https://huggingface.co/datasets/PureOne/Nhoshiyalun72-Soryuma-Conserved-Task-Memory/resolve/main/tools/export_dataset.py
6.12 kB
| """Build flat, viewer-friendly JSONL views from released raw research records. | |
| Rational numbers stay strings. Matrices and heterogeneous structures are JSON | |
| strings, preserving exact data without inconsistent Arrow nested schemas. | |
| Requires only the standard library. No random generation or network access. | |
| """ | |
| from pathlib import Path | |
| from fractions import Fraction | |
| import argparse,json,hashlib | |
| ROOT=Path(__file__).resolve().parents[1] | |
| def read(relative):return json.loads((ROOT/'research/v5'/relative).read_text()) | |
| def packed(x):return json.dumps(x,ensure_ascii=False,sort_keys=True,separators=(',',':'),allow_nan=False) | |
| def optional_packed(record,key):return packed(record[key]) if key in record else None | |
| def sid(x):return f"s{x['seed']:02d}_n{x['dimension']:02d}_r{x['constraint_rank']:02d}" | |
| def gid(x):return f"s{x['seed']:02d}_n{x['dimension']:02d}_c{x['condition']}" | |
| def export(output): | |
| output.mkdir(parents=True,exist_ok=True) | |
| acquisitions=[];edits=[] | |
| for a in read('constraint_impl/results/raw.json'): | |
| source_id=sid(a);n=a['dimension'];r=a['constraint_rank'] | |
| acquisitions.append(dict(record_id=source_id,seed=a['seed'],dimension=n,constraint_rank=r, | |
| source_queries=a['source_queries'],gain_rank=a['gain_rank'],task_response_rank=a['task_response_rank'], | |
| compressed_learned_scalars=a['compressed_learned_scalar_count'],expected_learned_scalars=a['compressed_expected_scalar_count'], | |
| full_affine_offset_conserved=a['full_affine_offset_conserved'],all_probe_norms_valid=a['all_probe_norms_valid'], | |
| query_optimality_regime='sharp_reusable_projector' if 2*r<=n else 'upper_bound_high_rank_gap', | |
| source_details_available='H' in a, | |
| hessian_json=optional_packed(a,'H'),constraints_json=optional_packed(a,'A'),initial_mean_json=optional_packed(a,'theta0'), | |
| probe_trace_json=optional_packed(a,'trace'),gain_basis_json=optional_packed(a,'observed_gain_basis'), | |
| physical_forgetting_json=packed(a['physical_forgetting']),physical_weights_json=packed(a['physical_weights']))) | |
| for t in a['targets']: | |
| ratio=t['euclidean_over_optimal_ratio'] | |
| edits.append(dict(record_id=f"{source_id}_t{t['target_index']:02d}",acquisition_id=source_id, | |
| seed=a['seed'],dimension=n,constraint_rank=r,target_index=t['target_index'],source_queries=a['source_queries'], | |
| oracle_exact=t['oracle_exact'],feasible=t['feasible'],stationary=t['stationarity'], | |
| compiled_decoder_exact=t['compressed_decoder_exact'],initial_final_anchor_equal=t['preprobe_anchor_edit_equal'], | |
| additional_target_queries=t['target_reuse_additional_queries'], | |
| optimal_objective_exact=t['optimal_objective'],euclidean_objective_excess_exact=t['euclidean_objective_excess'], | |
| euclidean_over_optimal_ratio=None if ratio is None else float(Fraction(ratio)), | |
| euclidean_ratio_exact=ratio,raw_probe_state_feasible=t['raw_probe_state_feasible'], | |
| target_json=packed(t['target']),edited_mean_json=packed(t['edited_theta']))) | |
| independent=[] | |
| for x in read('constraint_check_results.json')['rows']: | |
| independent.append(dict(record_id=f"s{x['seed']:02d}_n{x['n']:02d}_r{x['m']:02d}",seed=x['seed'],dimension=x['n'], | |
| constraint_rank=x['m'],source_queries=x['queries'],exact_projector=x['exact_projector'], | |
| exact_targets=x['exact_targets'],projector_error_bound_verified=x['projector_error_bound'],output_error_bounds_verified=x['output_error_bounds'])) | |
| autonomous=[] | |
| for x in read('impl/results/raw.json'): | |
| u=x['methods']['autonomous_union'];iso=x['methods']['isotropic'];oracle=x['methods']['oracle_union'] | |
| autonomous.append(dict(record_id=gid(x)+'_'+x['task'],geometry_recovery_id=gid(x),seed=x['seed'],dimension=x['dimension'], | |
| condition=x['condition'],task_family=x['task'],future_steps=x['steps'], | |
| union_square_loss=u['aggregate_loss'],isotropic_square_loss=iso['aggregate_loss'],oracle_union_square_loss=oracle['aggregate_loss'], | |
| best_union_expert_loss=u['best_expert_loss'],regret_to_best_expert=u['regret_to_best_expert'], | |
| max_prefix_regret=u['max_prefix_regret_to_best_expert'],theorem_allowance=u['theorem_allowance'], | |
| regret_check_passed=u['bound_satisfied_float_tolerance'],all_prefix_checks_passed=u['all_prefix_bounds_satisfied_float_tolerance'], | |
| max_oracle_prediction_difference=x['max_recovered_oracle_prediction_difference'], | |
| source_queries_for_geometry=x['source_queries_for_geometry'],future_source_updates=x['future_source_updates'], | |
| future_factors_received=u['future_transition_parameters_received'],stream_metadata_json=packed(x['stream_metadata']), | |
| methods_json=packed(x['methods']))) | |
| geometries=[dict(record_id=gid(x),**x) for x in read('impl/results/source_migrations.json')] | |
| views={'task_edits':edits,'acquisitions':acquisitions,'independent_checks':independent,'autonomous_runs':autonomous,'geometry_recoveries':geometries} | |
| expected={'task_edits':324,'acquisitions':108,'independent_checks':36,'autonomous_runs':648,'geometry_recoveries':216} | |
| report={} | |
| for name,rows in views.items(): | |
| assert len(rows)==expected[name] | |
| assert len({x['record_id'] for x in rows})==len(rows) | |
| columns=set(rows[0]);assert all(set(x)==columns for x in rows) | |
| path=output/(name+'.jsonl') | |
| path.write_text(''.join(packed(x)+'\n' for x in rows),encoding='utf-8') | |
| report[name]={'rows':len(rows),'bytes':path.stat().st_size,'sha256':hashlib.sha256(path.read_bytes()).hexdigest(),'columns':list(rows[0])} | |
| assert sum(x['rows'] for x in report.values())==1332 | |
| return report | |
| if __name__=='__main__': | |
| ap=argparse.ArgumentParser();ap.add_argument('--output',type=Path,required=True);ap.add_argument('--report',type=Path) | |
| args=ap.parse_args();report=export(args.output) | |
| if args.report:args.report.write_text(json.dumps(report,indent=2)+'\n') | |
| print(json.dumps({k:v['rows'] for k,v in report.items()},indent=2)) | |