Datasets:
Download components/openai-math/verification/tools/prepare_proof_review.py from MMLA-ORG/Cayley-Math: direct link, hf CLI and curl.
- Browser
- Download file 5.63 kB
-
https://huggingface.co/datasets/MMLA-ORG/Cayley-Math/resolve/main/components/openai-math/verification/tools/prepare_proof_review.py
- Command line
-
hf download hf://datasets/MMLA-ORG/Cayley-Math/components/openai-math/verification/tools/prepare_proof_review.py
-
curl -L -o prepare_proof_review.py https://huggingface.co/datasets/MMLA-ORG/Cayley-Math/resolve/main/components/openai-math/verification/tools/prepare_proof_review.py
5.63 kB
| #!/usr/bin/env python3 | |
| """Prepare complete extracted primary papers for independent OMP proof review.""" | |
| import collections | |
| import hashlib | |
| import json | |
| from pathlib import Path | |
| import re | |
| ROOT = Path('/Users/zxy/Cayley-Math/components/openai-math') | |
| MATH = Path('/Users/zxy/math') | |
| OUT = Path(__file__).resolve().parent / 'proof-review' | |
| def sha(p): | |
| return hashlib.sha256(p.read_bytes()).hexdigest() | |
| def jsonl(p): | |
| with p.open() as f: | |
| return [json.loads(line) for line in f if line.strip()] | |
| def dump(p, value): | |
| p.parent.mkdir(parents=True, exist_ok=True) | |
| p.write_text(json.dumps(value, ensure_ascii=False, indent=2) + '\n') | |
| def main(): | |
| OUT.mkdir(parents=True, exist_ok=True) | |
| families = json.loads((ROOT / 'audit/families.json').read_text()) | |
| inventory = {r['paper_id']: r for r in jsonl(ROOT / 'audit/manuscripts.jsonl') if r['status'] == 'current'} | |
| records = collections.defaultdict(list) | |
| for r in jsonl(ROOT / 'data/source-records.jsonl'): | |
| records[r['paper_id']].append(r) | |
| macro = {r['paper_id']: r for r in jsonl(ROOT / 'data/macro-contexts.jsonl')} | |
| primary, family_papers = {}, {} | |
| for line in (MATH / 'overview.tex').read_text().splitlines(): | |
| m = re.match(r'\\resultentry\{(\d+)\}', line) | |
| if not m: | |
| continue | |
| paths = re.findall(r'\\href\{https://github.com/openai/math/blob/main/(preprints/[^{}]+?\.pdf)\}', line) | |
| ids = list(dict.fromkeys(Path(p).parts[1] for p in paths)) | |
| if ids: | |
| primary[m[1]] = ids[0] | |
| family_papers[m[1]] = ids | |
| assert set(primary) == set(families), (len(primary), len(families)) | |
| inputs = [] | |
| for fid in sorted(families): | |
| pid = primary[fid] | |
| assert pid in inventory | |
| paper = inventory[pid] | |
| selected = sorted(records[pid], key=lambda x: x['chunk_index']) | |
| source_lines, provenance = [], [] | |
| for record in selected: | |
| first_line = len(source_lines) + 1 | |
| for line in record['text'].splitlines(): | |
| lid = f'L{len(source_lines)+1:06d}' | |
| source_lines.append({'line_id': lid, 'text': line}) | |
| provenance.append({'first_line': f'L{first_line:06d}', 'last_line': f'L{len(source_lines):06d}', | |
| 'record_id': record['id'], 'source_spans': record['source_spans']}) | |
| companion_context = [] | |
| for other in family_papers[fid][1:]: | |
| m = inventory[other] | |
| companion_context.append({'paper_id': other, 'title': m['title'], 'abstract': m['abstract'], | |
| 'scope': 'abstract_only_companion_not_proof_verified'}) | |
| scope_file = MATH / f'lean/docs/{fid}.md' | |
| formal_note = {'formal_verification_executed': False, | |
| 'note': 'Any supplied scope document is an upstream claim about artifact coverage; no Lean or Comparator result is established by this review.'} | |
| if scope_file.exists(): | |
| formal_note.update(source_path=str(scope_file.relative_to(MATH)), sha256=sha(scope_file), text=scope_file.read_text()) | |
| item = {'family_id': fid, 'paper_id': pid, 'title': paper['title'], 'discipline': families[fid]['discipline'], | |
| 'source_commit': paper['source_commit'], 'input_scope': 'complete_extracted_primary_body_plus_macro_context', | |
| 'main_claim_catalog': families[fid]['source_claim_summary'], 'abstract': paper['abstract'], | |
| 'source_lines': source_lines, 'macro_context': macro[pid]['contexts'], | |
| 'companion_context': companion_context, 'formalization_scope_note': formal_note, | |
| 'source_dependencies': paper['source_dependencies'], 'main_tex_source': paper['main_tex_source'], | |
| 'extraction_exclusions': paper['excluded_ranges'], 'extraction_flags': paper['extraction_flags'], | |
| 'limits': ['Primary paper selected as first manuscript in fixed upstream family catalog.', | |
| 'All extracted primary body lines and preserved preamble contexts are supplied.', | |
| 'Bibliographies, drawing code and layout commands are excluded according to extraction audit.', | |
| 'Companion proofs and external references are not fully supplied or verified.', | |
| 'L identifiers refer to this review snapshot, mapped to original source spans in separate audit.']} | |
| inputs.append(item) | |
| dump(OUT / 'line-maps' / (fid + '.json'), {'family_id': fid, 'paper_id': pid, 'lines': provenance}) | |
| with (OUT / 'inputs.jsonl').open('w') as f: | |
| for item in inputs: | |
| f.write(json.dumps(item, ensure_ascii=False, separators=(',', ':')) + '\n') | |
| manifest = {'families': len(inputs), 'unique_primary_papers': len({r['paper_id'] for r in inputs}), | |
| 'current_papers_in_source_collection': len(inventory), 'primary_selection': 'first manuscript listed in upstream overview resultentry', | |
| 'input_scope': 'complete_extracted_primary_body_plus_macro_context', | |
| 'source_body_characters': sum(sum(len(l['text']) for l in r['source_lines']) for r in inputs), | |
| 'inputs_sha256': sha(OUT / 'inputs.jsonl'), 'source_commit': inputs[0]['source_commit'], | |
| 'formal_verification': False, | |
| 'input_files': {p: sha(ROOT / p) for p in ['audit/families.json','audit/manuscripts.jsonl','data/source-records.jsonl','data/macro-contexts.jsonl']}} | |
| dump(OUT / 'input-manifest.json', manifest) | |
| print(json.dumps(manifest)) | |
| if __name__ == '__main__': | |
| main() | |