OPEN SOURCE
software/scripts/evaluate_verse_sample.py
Read on this site and download the files you need.
Nichijoyaku was created using AI. A complete review by human biblical-language and biblical-studies specialists has not been established. Read alongside established translations and original-language resources.
← Back to the open-source guide
1"""Evaluate a specific verse sample with the project's evaluator.23Writes per-verse dimension scores to a JSON file WITHOUT touching the4canonical chapter eval files — the harness used for all A/B experiments5(register calibration, morphology, translator-model comparisons).67Usage:8uv run python scripts/evaluate_verse_sample.py <out.json> book:ch:v [...]9"""10import json, subprocess, sys11sys.path.insert(0, str(__import__("pathlib").Path(__file__).parent.parent))12from src.context.builder import ContextBuilder13from src.context.glossary import GlossaryManager14from src.data.loader import DataLoader15from src.data.storage import Storage16from src.evaluation.evaluator import (17EVALUATION_SYSTEM_PROMPT, TranslationEvaluator, parse_evaluation_response,18)19from src.models.verse import VerseReference20from src.pipeline.translator import DEFAULT_MODEL2122if len(sys.argv) < 3:23print(__doc__)24raise SystemExit(2)25out_path, refs = sys.argv[1], " ".join(sys.argv[2:]).split()26loader = DataLoader("data")27glossary = GlossaryManager(loader.load_glossary())28builder = ContextBuilder(loader, glossary)29storage = Storage("data")30evaluator = TranslationEvaluator(data_dir="data")3132results = {}33for r in refs:34book, ch, v = r.split(":")35ref = VerseReference(book=book, chapter=int(ch), verse=int(v))36t = storage.load_translation(ref)37if not t:38print(f"{r}: no translation"); continue39ctx = builder.build_context(ref)40prompt = evaluator.build_verse_prompt(t.text, ctx)41full = f"{EVALUATION_SYSTEM_PROMPT}\n\n{prompt}"42p = subprocess.run(["claude", "--print", "-p", full, "--model", DEFAULT_MODEL],43capture_output=True, text=True, timeout=300)44if p.returncode != 0:45print(f"{r}: eval failed: {p.stderr[:100]}"); continue46try:47scores = parse_evaluation_response(p.stdout.strip())48except ValueError as e:49print(f"{r}: parse failed: {e}"); continue50results[r] = {51"text": t.text,52"scores": {k: {"score": s.score, "reasoning": s.reasoning} for k, s in scores.items()},53"avg": sum(s.score for s in scores.values()) / len(scores),54}55print(f"{r}: avg={results[r]['avg']:.1f}")56json.dump(results, open(out_path, "w"), ensure_ascii=False, indent=1)57print(f"saved {len(results)} to {out_path}")58