"""Build inputs for the "part of the passage left untouched" conditions. python make_partial.py results/generated.jsonl results/partial-input-40.jsonl 0.4 For every watermarked passage, the opening sentences that make up about the given share of its words are kept exactly as they were (`keep`) and the rest (`text`) is sent for rewriting. rewrite.mjs joins the two parts again. This imitates a rewrite that leaves that share of the wording in place. """ import json import re import sys in_path, out_path, share = sys.argv[1], sys.argv[2], float(sys.argv[3]) with open(out_path, "w") as out: for line in open(in_path): if not line.strip(): continue row = json.loads(line) if row["scheme"] == "unmarked": continue # sentence-ish pieces, keeping their trailing whitespace so the text can be rejoined exactly pieces = re.findall(r"[^.!?\n]+(?:[.!?]+|\n+|$)\s*", row["text"]) total = len(row["text"].split()) keep, words = [], 0 while pieces and words < share * total: piece = pieces.pop(0) keep.append(piece) words += len(piece.split()) rest = "".join(pieces).strip() if len(rest.split()) < 20: # nothing meaningful left to rewrite continue out.write(json.dumps({"id": row["id"], "prompt": row["prompt"], "scheme": row["scheme"], "keep": "".join(keep).strip(), "text": rest}, ensure_ascii=False) + "\n") print("wrote", out_path)