Datasets:
Tasks:
Text Generation
Modalities:
Text
Formats:
csv
Size:
< 1K
Tags:
scientific-hypothesis-generation
multi-agent-debate
knowledge-graph
diamond-nv-center
quantum-sensing
llm-as-judge
License:
Download scripts/postprocess.py from eduzrh/nv-kgmad: direct link, hf CLI and curl.
- Browser
- Download file 1.15 kB
-
https://huggingface.co/datasets/eduzrh/nv-kgmad/resolve/main/scripts/postprocess.py
- Command line
-
hf download hf://datasets/eduzrh/nv-kgmad/scripts/postprocess.py
-
curl -L -o postprocess.py https://huggingface.co/datasets/eduzrh/nv-kgmad/resolve/main/scripts/postprocess.py
1.15 kB
| #!/usr/bin/env python3 | |
| """Normalise generated hypotheses before evaluation. | |
| * converts LaTeX inline delimiters ``\\( ... \\)`` to ``$ ... $`` so that the | |
| Markdown and DOCX renderers agree; | |
| * collapses excessive blank lines and trailing spaces; | |
| * keeps the original text in ``text_raw`` on first run for auditability. | |
| """ | |
| from __future__ import annotations | |
| import json | |
| import re | |
| from pathlib import Path | |
| ROOT = Path(__file__).resolve().parents[1] | |
| HYPO = ROOT / "outputs" / "hypotheses" | |
| def clean(text: str) -> str: | |
| text = text.replace("\\(", "$").replace("\\)", "$") | |
| text = text.replace("\\[", "$$").replace("\\]", "$$") | |
| text = re.sub(r"\n{3,}", "\n\n", text) | |
| text = re.sub(r"[ \t]+\n", "\n", text) | |
| return text.strip() | |
| def main() -> None: | |
| n = 0 | |
| for path in sorted(HYPO.glob("*.json")): | |
| rec = json.loads(path.read_text(encoding="utf-8")) | |
| rec.setdefault("text_raw", rec["text"]) | |
| rec["text"] = clean(rec["text"]) | |
| path.write_text(json.dumps(rec, ensure_ascii=False, indent=1), encoding="utf-8") | |
| n += 1 | |
| print(f"normalised {n} records") | |
| if __name__ == "__main__": | |
| main() |