Download open_swe/scripts/restore_solution_originality.py from Min-Li/marin-sft-data-audit: direct link, hf CLI and curl.
- Browser
- Download file 2.46 kB
-
https://huggingface.co/datasets/Min-Li/marin-sft-data-audit/resolve/main/open_swe/scripts/restore_solution_originality.py
- Command line
-
hf download hf://datasets/Min-Li/marin-sft-data-audit/open_swe/scripts/restore_solution_originality.py
-
curl -L -o restore_solution_originality.py https://huggingface.co/datasets/Min-Li/marin-sft-data-audit/resolve/main/open_swe/scripts/restore_solution_originality.py
2.46 kB
| """Put the missing "## Solution Originality" section back into the task message (messages[1]) of the pinned | |
| Qwen3.8-27B mini-swe-agent traces of nvidia/Open-SWE-Traces (revision f967cba3). | |
| Source of the section: NVIDIA NeMo-Skills, commit 592ebaec5a80e17a3535623d0f5704d29e13a64f, | |
| nemo_skills/prompt/config/eval/swe-bench/mini-swe-agent/swebench.yaml (lines 113-127, Apache-2.0). | |
| In that template the section sits between </CRITICAL> and </instructions>. In the released traces messages[1] | |
| ends with "</CRITICAL>\\n</instructions>", so the section was cut out. After restore_messages() the tail reads | |
| exactly as the template renders: "</CRITICAL>\\n\\n## Solution Originality\\n\\n...correctness!\\n</instructions>". | |
| Usage: python3 -I restore_solution_originality.py <shard.parquet> | |
| Prints how many resolved == 1 rows of the shard can be restored, and the restored tail of the first one. | |
| """ | |
| import os | |
| import sys | |
| SECTION_PATH = os.path.join(os.path.dirname(os.path.abspath(__file__)), "..", "pinned_f967cba3", | |
| "solution_originality_section.txt") | |
| SECTION = open(SECTION_PATH).read().strip("\n") | |
| ANCHOR = "</CRITICAL>\n</instructions>" | |
| HEAD = "## Solution Originality" | |
| def restore_messages(messages): | |
| """Return a copy of messages with the section inserted into messages[1]; raise if the anchor is not the tail.""" | |
| task = messages[1]["content"] | |
| if HEAD in task: | |
| raise ValueError("already_present") | |
| if task.count(ANCHOR) != 1: | |
| raise ValueError("anchor_count_%d" % task.count(ANCHOR)) | |
| if not task.endswith(ANCHOR): | |
| raise ValueError("anchor_not_at_end") | |
| out = list(messages) | |
| out[1] = {**messages[1], "content": task[: -len(ANCHOR)] + "</CRITICAL>\n\n" + SECTION + "\n</instructions>"} | |
| return out | |
| def main(): | |
| import pyarrow.parquet as pq | |
| t = pq.read_table(sys.argv[1], columns=["trajectory_id", "resolved", "messages"]) | |
| ok, bad, first = 0, 0, None | |
| for tid, res, msgs in zip(*(t.column(c).to_pylist() for c in ("trajectory_id", "resolved", "messages"))): | |
| if res != 1: | |
| continue | |
| try: | |
| new = restore_messages(msgs) | |
| ok += 1 | |
| first = first or (tid, new[1]["content"][-1600:]) | |
| except ValueError: | |
| bad += 1 | |
| print("restored", ok, "failed", bad) | |
| if first: | |
| print("\n--- tail of messages[1] after restore,", first[0], "---\n" + first[1]) | |
| if __name__ == "__main__": | |
| main() | |