A Python pipeline that scores pastoral answers for biblical fidelity on a 0–3 scale, in English and French, then rewrites strong answers into subtly compromised ones to build paired training data.
Why this pipeline exists, and how its design follows from that.
A model meant to answer pastoral questions has to be faithful to Scripture across sensitive topics: marriage and gender, the sanctity of life, salvation, justice and biblical authority. Building and testing that model needs large amounts of labelled data: answers graded for fidelity, plus clear examples of what a subtly wrong answer looks like.
Labelling thousands of answers by hand, in two languages, is slow and inconsistent. Subtly compromised answers are especially hard to write on purpose.
A two-stage, LLM-as-judge pipeline. A low-temperature judge grades every answer against a fixed 0–3 rubric and justifies each score. A second, stronger model then rewrites faithful answers into plausible but compromised ones. The judge scores each rewrite again, so every pair in the dataset is verified, not assumed.
A fixed rubric in a pastor-theologian prompt, run at temperature 0.3 so the same answer gets the same score. Every score comes with a 1–2 sentence justification citing Scripture.
Only answers rated 2 or 3 are rewritten, by gpt-4.1 at temperature 0.7, using at least two of five named distortion techniques. The result should sound pastoral but fail a strict grader.
The rewrite goes back through the same judge. Original and rewrite are stored side by side with both ratings and justifications, giving a contrastive dataset.
What the backend produces at each stage, from the live run to the final training data. Click any screen to view it full size.
Follow one row of data through both scripts. It plays automatically. Click any step to inspect it.
evaluate_reponse.pyre-analysis_response.pyLong batch jobs against a paid, non-deterministic API turn small problems into expensive ones.
The judge returns markdown, sometimes bold, sometimes not, and in French it writes “Note” instead of “Rating”.
Patterns accept optional **, several separators and both labels, then pull out the score and the full justification.
re.search(r"\*{0,2}(?:Note|Rating)…")Hundreds of rows at about 3 seconds each. A network error or rate limit would mean paying to redo everything.
Each result is written to CSV and to a JSON checkpoint right after its API call. Restarting resumes at last_index + 1.
load_checkpoint() · save_checkpoint()The API rejects bursts and occasionally fails for no clear reason.
Up to 3 retries with a delay, 2.5s between rows, and tokens and estimated cost printed for every call. Runs are capped at a chosen row count.
max_retries=3 · time.sleep(2.5)Rewrites came back wrapped in scaffolding like “Techniques employed: 1, 3” and “Your Output:”, which would pollute the dataset.
A cleaning pass strips the EN and FR markers and horizontal rules, and collapses extra blank lines, before the answer is judged again.
clean_regenerated_answer(text, lang)A model asked to “compromise” an answer can overshoot into absurdity, or barely change it.
The same judge scores every rewrite. Each pair stores both ratings, so weak rewrites are easy to spot and filter out.
Original Rating → Regenerated Ratingusage.prompt_tokens rather than a word-count estimate for cost.