Mova0.6 pre-release

qagen — LLM-generated training questions and answers for fairy-tale paragraphs

qagen makes training questions: for each paragraph of a public-domain tale, a large model writes question–answer pairs of the FairytaleQA types (Xu et al., ACL 2022, 2022.acl-long.34; card), which Mova's readers learn from. The large model writes the questions; Mova answers them on its own.

Problem statement: Context, layers and memory, section "Five-year-old test", paragraph "Training questions from the LLM". This is training data for the memory, narrative and motives of the SLM (small language model): it learns to answer from the md graph.

What

For each fairy-tale paragraph the LLM writes 3–6 question-answer pairs. Each pair has:

The pairs live in the database, in the qa table (migrations v3–v4 in tools/db/schema.sql). They are loaded by db qa; the view with names is qa_pairs, current pairs without replaced ones are qa_current.

How

qagen select $MOVA_DATA/db/mova.duckdb <dir> [--rule 2] [--exclude <other run dir>/paras.jsonl]
                                                # paragraph selection → paras.jsonl (with batches), pick.json
qagen prompt <dir> 0                            # batch prompt, no call
qagen run    <dir> [--batches 0] [--jobs 5] [--max-calls 20]   # LLM → raw/bNNN.txt, calls.jsonl
qagen gate   <dir>                              # gates → qa.tsv, rejects.tsv, params.json
qagen sample <dir> [--n 20] [--weak 0.5]        # sample for eyeballing → sample.md; explicit pairs with weak support → weak.md
db qa $MOVA_DATA/db/mova.duckdb <dir>/qa.tsv --run <name> --params <dir>/params.json --path <dir>

# bringing a run made without the span rule to it (src/fix.rs)
qagen fix select <pilot dir> <dir> [--batch 40]   # explicit non-span pairs → items.jsonl, paras.jsonl, select.json, doubt.tsv
qagen fix prompt <dir> 0
qagen fix run    <dir> [--jobs 5] [--max-calls 10]
qagen fix gate   <dir> --replaces <pilot run>    # → qa.tsv, rejects.tsv, changes.md, params.json
db qa $MOVA_DATA/db/mova.duckdb <dir>/qa.tsv --run <name> --replaces <pilot run> --params <dir>/params.json --path <dir>

Reused from existing code:

Database query: sql/paras.sql.

Selection (src/select.rs)

Gates (src/gate.rs; negative controls are in the tests)

LLM output is a 6-column TSV: p type ex anchors question answer.

Batch. A format rejection is the only reason for a retry, and there is exactly one retry. The format is rejected when:

Pair. Only this pair is rejected; the first reason goes to the log:

Paragraph. If there are no lines, the paragraph is rejected. If there are fewer than 3 questions, no implicit pair, or all of one type, a note goes to the log and the pairs stay.

Database (db qa). Checks integrity:

Type, explicitness, source and a non-empty answer are enforced by CHECKs on the qa table. Any error, and nothing in the database changes (tools/db/tests/qa.rs).

Rejection log: rejects.tsv; there are no blind retries. A call error stops the run. A rerun takes only unfinished batches. Ceiling: --max-calls calls per run directory (default 20).

The span rule: an explicit answer is a verbatim span

An explicit answer is a verbatim span of an anchor sentence, as in FairytaleQA. That way the SLM learns to extract the answer from the text rather than paraphrase. An implicit answer remains free text. The rule is stored in the run's pick.json ("rule": 2). A run without this field is gated without the span gate, so qagen gate on its directory reproduces it.

Prompt (prompt::RULES_V2). An explicit answer is a span copied from one sentence: the same words in the same order and form, nothing changed, added or skipped inside. Words at the edges may be dropped, and the shortest span that answers the question should be taken. The sentence the span comes from must be among the anchors. An implicit answer is in one's own words and is not a paraphrase of a single sentence. The prompt includes an example: a three-sentence paragraph and four pairs for it.

Span gate (gate::span_reason; pair rejection). The answer and the sentence are normalized:

Then the answer must occur in the anchor sentence as a substring on word boundaries: "the king" in "the king's garden" — yes, "the kin" — no. The rejection reason is one of three:

"Doubtful implicit" (lemma::doubt; a log flag with level doubt, the pair stays). If at least 80% of the content words of an implicit answer are covered by lemmas or forms of a single anchor sentence, it is most likely a paraphrase of an explicit answer. The verbatim gate does not catch this: "because he had tasted the king's white snake" vs "…had tasted the white snake". Lemmas and parts of speech come from en. Content words are NOUN, PROPN, VERB, ADJ, ADV, NUM, INTJ, X.

Negative controls are in the tests gate::span_gate_v2, lemma::doubt_flags_restated_implicit_answers (lemma stub), lemma::doubt_with_en_model (real model) and fix::fix_gate_and_negative_controls.

Fixing a run (src/fix.rs)

Explicit pairs of a run without the span rule that fail the span gate go to the LLM in batches of 40 paragraphs. The prompt contains the paragraph, question, type, anchors and the old answer. The LLM returns an item anchors span line: a verbatim span, or implicit if no sentence states it directly. In that case the pair keeps the old answer but becomes implicit. The source of pairs is that run's qa.tsv, i.e. exactly what is in the database.

Output gate:

Database, migration v4. Fixed pairs are a separate run (db qa --replaces <pilot run>) with the same document, paragraph and question number. The new row carries replaces — the qid of the old one. The old row is not deleted; in the same transaction it gets replaced_by — the qid of the new one. Current pairs: view qa_current.

Example: "Hansel and Gretel", paragraph 1

typeexplicitnessanchorsquestionanswer
characterexplicit1, 2Who lived by the great forest?a poor wood-cutter, his wife, and children Hansel and Gretel
causal relationshipexplicit3Why could the wood-cutter no longer get daily bread?a great dearth fell on the land
actionexplicit6What was the wife's plan for the children?leave them alone where the forest is thickest
causal relationshipimplicit9What made the wood-cutter finally agree to the wife's plan?she kept nagging him, saying they would all starve
characterimplicit6, 7, 9What kind of person was the wood-cutter's wife?cruel and selfish
feelingexplicit10How did the wood-cutter feel about the plan?very sorry for the poor children

More examples of implicit pairs:

This example comes from a run without the span rule; under the span rule the explicit answers are verbatim spans of an anchor sentence.

Database

Runs that replace pairs of another run need migration v4 (db migrate).

Run files

filecontents
paras.jsonlselected paragraphs with sentences (sent_id), context and batch number
pick.jsonselection parameters and rule (rule: 2 is the span rule; absent — no span gate)
raw/bNNN.prompt.txt, raw/bNNN.txtprompt and raw LLM output; the retry, if any, is raw/bNNN.retry.txt
calls.jsonlaccounting: time, tokens and price per call
qa.tsvaccepted pairs for db qa; anchors are comma-separated sent_ids
rejects.tsvlog of rejections and flags: level batch, para, pair, note or doubt ("doubtful implicit")
params.jsonaccounting and distributions; stored in the database's runs.params
sample.md, weak.mdsamples for eyeballing
run.logexecution log: one line per batch

The fix (fix/) has the same paras.jsonl, raw/, calls.jsonl, qa.tsv, rejects.tsv, params.json and run.log, plus:

filecontents
items.jsonlexplicit pairs to fix, with the span gate's rejection reason and batch number
select.jsonselection summary: how many passed as is, reasons, "doubtful implicit" pairs of the old run
doubt.tsvimplicit pairs of the old run flagged "doubtful implicit"
changes.mdeach change: question, before → after, anchors, explicitness

Limits

Licence

Elamur Cosmic License (Elamur Cosmic License). Third-party data keeps its own terms, as noted where it is used.

This page in Markdown https://md.mova.elamur.ai/free/en/docs/qagen/