muscari.data¶
Dataset rows to (kind, text) pairs: columns and prompts, deduplication and the held-out split.
Columns¶
TextColumn
dataclass
¶
A dataset column, the prompt the encoder expects for its texts, and what kind of text it holds.
Statistics are reported per kind of text, for example separately for queries and
documents. The prompt usually tells the kinds apart. An encoder that takes no prompt needs
a label instead, and so do two kinds that share a prompt.
kind
property
¶
The name the texts of this column are grouped under: the label, or else the prompt.
parse
classmethod
¶
parse(spec: str) -> TextColumn
Parse name, name=prompt, name:label or name:label=prompt.
Everything after the first = is the prompt, verbatim, so a trailing space such as
the one in "query: " is kept. A column whose name contains : cannot be given
this way; construct the TextColumn directly.
Raises:
-
ValueError–if the column name or a label announced by
:is empty.
Source code in src/muscari/data/columns.py
prompt_of_kind
¶
prompt_of_kind(
columns: Iterable[TextColumn],
) -> dict[str, str]
Map each kind of text to the prompt its columns prepend.
Raises:
-
ValueError–if two columns of the same kind prepend different prompts.
Source code in src/muscari/data/columns.py
Texts¶
iter_texts
¶
iter_texts(
rows: Iterable[Mapping[str, Any]],
columns: Sequence[TextColumn],
*,
dedup: bool = True,
min_chars: int = 1,
holdout_pct: float = 0.0,
split: str = "train",
) -> Iterator[tuple[str, str]]
Yield (kind, text) for every text in the requested columns.
The kind is the column's prompt, or its label if it has one. An activation source prepends a kind as the prompt unless it was told which prompt a label stands for.
Parameters:
-
rows(Iterable[Mapping[str, Any]]) –dataset rows. Missing columns and
Nonecells are skipped. -
columns(Sequence[TextColumn]) –which columns to read, with the prompt and optional label of each.
-
dedup(bool, default:True) –drop exact repeats of
(kind, text). Retrieval datasets repeat documents heavily (shared negatives), which would otherwise over-weight them. This keeps one 64-bit hash per distinct text in memory. -
min_chars(int, default:1) –skip texts shorter than this many characters.
-
holdout_pct(float, default:0.0) –percentage of distinct texts reserved for evaluation.
-
split(str, default:'train') –"train"yields the texts outside the held-out part,"holdout"the held-out ones,"all"ignoresholdout_pct.
Raises:
-
ValueError–on an unknown
splitor an out-of-rangeholdout_pct.
Source code in src/muscari/data/texts.py
is_holdout
¶
Deterministically assign a text to the held-out split by its content hash.
The same text always lands on the same side, whatever row or column it appears in, so a
document that recurs as a negative in many rows cannot leak from training into evaluation.
holdout_pct is a percentage with a resolution of 0.01.
Source code in src/muscari/data/texts.py
repeat_texts
¶
repeat_texts(
make_iter: Callable[[], Iterable[tuple[str, str]]],
max_epochs: int | None = None,
) -> Iterator[tuple[str, str]]
Re-run make_iter() each time it is exhausted, forever or for max_epochs passes.
Deduplication inside make_iter restarts on every pass, so each pass is one epoch over
the distinct texts.
Raises:
-
ValueError–if a pass yields nothing, which would otherwise loop forever.
Source code in src/muscari/data/texts.py
Rows¶
load_rows
¶
load_rows(
*,
dataset: str | None,
subsets: Sequence[str] | None,
data_files: Sequence[str] | None,
split: str,
column_names: Sequence[str],
seed: int,
) -> Iterable[dict[str, Any]]
Load rows, keep the wanted columns and shuffle the row order.
Local data_files take precedence over dataset. Several subsets are concatenated
before shuffling so that training does not walk through them one after another.
Raises:
-
ValueError–on an unsupported file extension, mixed file types, or when none of the requested columns exists.
Source code in src/muscari/data/rows.py
public_name
¶
Record a local path by its last component so that outputs carry no directory layout.