Skip to content

Export

Converts the raw predictions.jsonl of a run into the released format.

retexo.export

Predicted edit scripts in the released format.

A run of the driver writes one predictions.jsonl per test fold, with the model's raw scores, the gold it was scored against, and the code's internal tags (NOP for a copy, MORPH for an inflection). This module turns such a file into one self-contained record per pair, with the labels of the paper and no gold, so the predictions can be shared and read without the code that produced them.

One record, in SCHEMA_VERSION 2 (the paper's operations of 2026-10-09)::

{
  "id": "p0001", "benchmark_id": 1, "fold": 4, "reference_type": "cf.",
  "source": {"author": "verg", "work": "verg. aen.", "citation": "<verg. aen. 6.847.1>", "tokens": [...]},
  "reuse":  {"author": "hier", "work": "hier. epist.", "citation": "<hier. epist. 117.7.1.1>", "tokens": [...]},
  "links": [{"reuse": 5, "source": 2, "label": "COPY", "relation": null, "confidence": 0.9994}, ...],
  "mark": [{"start": 0, "end": 6}],
  "insertions": [6, 7],
  "new_text": [0, 1, 2, ...],
  "deletions": [3],
  "not_taken_up": [0, 1, 5, ...],
  "patterns": {"quote": [{"start": 9, "end": 14}], "reorder": [], "disperse": []}
}

Indices are word positions in tokens. links has one entry per linked reuse word; label is one of COPY, INFLECT, SUBST, SPLIT and MERGE, and a SUBST link may name its relation (SYN, DERIV, ...). mark lists the citing formulas as half-open ranges of reuse words. The words without a link are split by the reused stretch, which runs from the first to the last linked word of a passage: insertions and new_text are the unlinked reuse words inside and outside it (INS, NEW), deletions and not_taken_up the source words no link claims inside and outside it (DEL, OUT). patterns holds the QUOTE runs and the REORDER and DISPERSE reuse words. All of these follow retexo.operations.unlinked.

SCHEMA_VERSION 1 (until 2026-10-12) named the citing formulas frame, the derivational relative POS, and listed every unlinked word under insertions or deletions.

convert_record

convert_record(raw: Dict[str, Any], *, fold: Optional[int] = None) -> Dict[str, Any]

One raw prediction record as a released record.

Raises ValueError when the record contradicts itself (a link without a tag, a deletion that a link claims), so a corrupt file fails here and not in somebody's analysis.

read_predictions

read_predictions(path: Path | str, *, fold: Optional[int] = None) -> Iterator[Dict[str, Any]]

The released records of one raw predictions.jsonl.

export_folds

export_folds(sources: Sequence[Path | str], out_dir: Path | str, *, fmt: str = 'jsonl') -> Dict[int, int]

Convert one raw file per test fold into out_dir/fold_<k>.<fmt>; returns pairs per fold.

The fold is read from the records themselves, so the order of sources does not matter.

label_shares

label_shares(records: Iterable[Dict[str, Any]]) -> Dict[str, float]

The share of each label among all links, as a sanity check against a paper table.

label_of

label_of(tag: str) -> tuple[str, Optional[str]]

The label and the relation a code tag stands for; ("SUBST", "SYN") for SYN, ("SUBST", "DERIV") for the code's POS.