Repository Public Research preview
1"""Versioned rewrite prompts (variants A–E). Changing any string here requires bumping PROMPT_VERSION; the2version is logged with every request so that held-out-prompt experiments are well defined."""3from __future__ import annotations45PROMPT_VERSION = "rw-1.0"67PRESERVE = (8 "Preserve every scientific proposition exactly: all numbers, units, statistical values, named entities, "9 "species, genes, drugs, places, dates, citation markers (e.g. [12], (Smith et al., 2015), ⟦C1⟧), equations and "10 "math tokens (e.g. $x$, ⟦M1⟧), URLs/DOIs (⟦U1⟧), negations, hedges and expressions of uncertainty. Do not add, "11 "remove or reorder facts. Do not add commentary, headings, bullet points or notes. Keep the passage as a single "12 "paragraph in English. Output only the rewritten passage."13)1415SYSTEM = (16 "You rewrite passages of scientific writing for a research study on how language models transform prose. "17 "You never invent information. Placeholders of the form ⟦C1⟧, ⟦M1⟧ and ⟦U1⟧ stand for citations, equations and "18 "links; copy each of them verbatim, exactly once per occurrence in the source, in the position where it belongs."19)2021VARIANTS: dict[str, dict[str, str]] = {22 "A": {23 "name": "neutral_paraphrase",24 "instruction": "Paraphrase the following passage in neutral academic English. Change the wording and sentence structure freely while keeping the meaning identical.",25 },26 "B": {27 "name": "polished_standardized",28 "instruction": "Rewrite the following passage as polished, standardized contemporary academic prose: improve clarity, flow and concision, use conventional modern scientific phrasing, and correct awkward constructions.",29 },30 "C": {31 "name": "concise",32 "instruction": "Rewrite the following passage more concisely (aim for about 70% of the original length) without dropping any fact, number, citation or qualification.",33 },34 "D": {35 "name": "structure_preserving",36 "instruction": "Rewrite the following passage sentence by sentence: keep the same number of sentences and the same order of ideas, but rephrase each sentence in your own words.",37 },38 "E": {39 "name": "diverse_sampling",40 "instruction": "Rewrite the following passage in your own words as a fluent academic paragraph. Vary the wording naturally.",41 },42}4344HELD_OUT_VARIANTS: dict[str, dict[str, str]] = {45 # Used ONLY for the held-out-prompt generalisation test (never in training).46 "H1": {"name": "plain_language_expert", "instruction": "Rewrite the following passage for an expert reader in plain, direct language with short sentences."},47 "H2": {"name": "editorial_polish", "instruction": "You are a copy-editor at a scientific journal. Edit the following passage for publication: fix style, tighten the prose, keep the author's meaning."},48}495051def build_messages(passage_text: str, variant: str, metadata: dict | None = None) -> tuple[str, list[dict]]:52 spec = {**VARIANTS, **HELD_OUT_VARIANTS}[variant]53 user = f"{spec['instruction']}\n\n{PRESERVE}\n\n<passage>\n{passage_text}\n</passage>"54 return SYSTEM, [{"role": "user", "content": user}]555657def prompt_fingerprint() -> str:58 import hashlib59 import json6061 blob = json.dumps({"v": PROMPT_VERSION, "system": SYSTEM, "preserve": PRESERVE, "variants": VARIANTS}, sort_keys=True)62 return hashlib.sha256(blob.encode()).hexdigest()[:16]63