translation module lets you translate first and still point back. It cuts the original into lines with their positions, translates them as numbered lines, and keeps the numbering, so line 2 of the translation is line 2 of the original.
Three more parts make that safe and cheap: escalation (a cheap model first, a stronger one only when a check fails), verification (a second model reports errors), and term hints from a glossary.
No part imports a model SDK. A model is a function ask(prompt) -> text, or an LlmClient. The wording is data.
Aligned translation
extractor.stats.
The offsets index the passage as ladyGraph reads it, so an original span found through line n can become evidence. Lesson 7 (hello_aligned.py) runs this on a toy translator that forgets a line.
Escalation
An escalation is a list of steps and a check. A later step’s answer replaces the current one only if it has no more problems, so escalating can never make a result worse by the check’s own count.make_check(glossary=None, extra=())is the basic check, plus the glossary gate when you pass aGlossary, plus any checks of your own. The gate was written for one language pair, so pass a glossary only when it fits yours.- A
Stepcan have abeforehook that returns a hint, for example a term-search result for a name the small model got wrong. The search itself stays outside the runtime, as the term-list builder does. - Lesson 7 (
hello_escalate.py) shows four cases: escalate, do not escalate, a stronger step that does no better is not kept, and a step that adds a search result to the hint.
Verification
A second model reports errors in (id, source, translation) pairs.Verdict has an id, a verdict (ok, minor, major or unchecked), and a list of errors. An error has one of these types: untranslated, name_mistranslated, wrong_term, number_dropped_or_changed, meaning_changed, added_text or missing_text.
verifier_check(verifier, fail_on=("major",)) turns a verdict into an escalation check.
A checker is a report. A verdict never edits a translation and never marks a concept verified. “Claude as the verifier” means a Claude model served by a gateway you run. ladyGraph does not call Claude directly, and it does not run Claude Code for this.
unchecked.
Tag a translation, ground in the original
extractor.kind: translate_ner translates the passage, tags the translation, and maps each find back to a verbatim quote of the original. See Extractors for the config.
- The evidence rule does not change. The concept’s word is in the tagger’s language, but its evidence is a quote found in the original. The back-quote is accepted only if it is in the segment and occurs once in the passage. In the measured document, 65% of exact spans repeated within a passage, and a repeated quote could point at the wrong copy. Otherwise the whole segment is the evidence.
- Plain text for a local model. The numbered translation and the back-quote use
complete_text, with no JSON wrapper. Wrapped in a schema, the E2B model answered""for every back-quote, and one numbered answer was cut before its closing brace.
What was measured, and where it still fails
What was measured, and where it still fails
Measured once, on 3 real chunks with the real local models (Gemma E2B translates, quotes and places, and GLiNER tags; 9 segments):
- The numbered translation was valid on all 3 first tries, with no line re-translated.
- 16 concepts were found. Every evidence span matched its fingerprint, and the contribution validated.
- 14 of 16 quotes were exact words of the original. 2 were refused as ambiguous, so the whole segment was used.
- It took 172 s and 35 model calls, almost all of it the local model and not the tagger.
Compare a local model with Claude
Lesson 7 has an experiment,hello_compare.py, that translates the same passage with a local model and with a model behind a gateway, and shows the result line by line with each line’s number check. Both sides use the same AlignedTranslator, prompts and passage, so a difference comes from the model.
It runs on two stand-ins by default. To use a real local model and Claude, you need a LiteLLM gateway and the variables below. Claude goes through the gateway, never directly.
CLAUDE_MODELis the alias the gateway serves, such asclaude-cliin the example, not an Anthropic model id.- The gateway key is
LITELLM_MASTER_KEY. The proxy script andhello_compare.pyboth read it, and both default tosk-anything. - The
claude-clialias starts a newclaude -pprocess for every call, so it is slow, and each call is capped at $1. - The number check only catches changed numbers. Read lines that differ against the original yourself.
Lesson 7 has its own dependency table in its
BRIEF.md. A real run needs google-adk, litellm[proxy] and litert-lm-api, which docs/requirements.txt installs.