Skip to main content
A tagger works best in one language, but ladyGraph’s rule is that evidence must be a verbatim span of the original text. The 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

If the model forgets a line, that line is translated again on its own. A small model may not follow the numbered format. The missing lines are translated one by one, and that is counted in 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.
Passing the number check does not make a translation right. It catches only the most expensive slip.

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 a Glossary, plus any checks of your own. The gate was written for one language pair, so pass a glossary only when it fits yours.
  • A Step can have a before hook 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.
Each 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.
A verdict that does not echo the first characters of its source is not trusted, so a confused model that attaches a verdict to the wrong pair is marked 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.
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.
Correctness was not judged beyond a read-through. Some quotes were the right segment but partly the wrong words: a concept “Board of Directors” quoted the words for the Executive Board. The small tagger produced generic concepts such as “plan” and “business”. Treat it as a working path with measured plumbing, not as measured quality.It can still fail when the quote is the wrong words in the right segment, when a translation passes the number check and is still wrong, or when a small model does not follow the numbered format.

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_MODEL is the alias the gateway serves, such as claude-cli in the example, not an Anthropic model id.
  • The gateway key is LITELLM_MASTER_KEY. The proxy script and hello_compare.py both read it, and both default to sk-anything.
  • The claude-cli alias starts a new claude -p process 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.
See Local models for the device setting.
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.