nemo_automodel.components.datasets.llm.retrieval_dataset_inline
nemo_automodel.components.datasets.llm.retrieval_dataset_inline
Module Contents
Classes
Functions
Data
API
Inline retrieval dataset that also carries per-query context columns.
Same pos_doc/neg_doc schema and loader as make_retrieval_dataset,
plus two things it does not provide:
reasoning_column/global_query_columnare passed through asreasoningandglobal_query.Qwen3ContextAwareRerankerCollatorreads both with.get()and selects its prompt mode from whichever survive its drop probabilities, so rows missing them simply train in a narrower mode.validation_fractioncarves a held-out slice at the level ofvalidation_group_keyrather than the row, so rows sharing a group cannot land on opposite sides.
Path(s) to inline JSON/JSONL with query/pos_doc/neg_doc.
"train", or "validation"/"eval" for the held-out side.
Shuffle before subsetting (train only).
Column holding the originating question.
Cap on training rows, applied after the split.
"cross_encoder" or "bi_encoder".
Passages per query (1 positive + n_passages - 1 negatives).
Column holding the reasoning trace.
Seeds the split and any shuffle.
Offset of the selected window.
Fraction of groups held out, in [0, 1). 0 uses the whole split; values outside the range are rejected.
Column defining a group; None groups by row.
Build the dataset with normalized context and a group-aware split.
Returns: Dataset
Dataset whose transform emits question/doc_text plus the context columns.
Construction-time configuration for inline retrieval datasets.
Build the inline retrieval dataset from this config.
Create transform function with specified number of negative documents.
Create transform function with specified number of negative documents.
Transform function to convert from raw format to cross-encoder training format.
Flatten a bi-encoder batch and repeat the extra per-query columns per document.
flatten_bi_encoder_to_cross_encoder returns a fixed set of keys, so any column
beyond question/doc_text is dropped. Context fields are per-query, so they repeat
exactly like the question does.
Carve a deterministic held-out slice, keeping rows that share a group together.
Splitting on rows alone leaks when one query contributes several rows — a mixed
dataset holding two labelings of the same query is the case that motivated this.
Grouping on group_key puts every row of a group on the same side.
Load a JSON file, falling back to JSONL (one JSON object per line).
Normalize an inline doc (text/image provided) into a canonical dict shape.
Resolve a doc reference into an example dict with keys: text, image, nr_ocr.
Supported doc forms:
str: interpreted as inline document textdict: must includetext(optionallyimage,nr_ocr)
Transform function to convert from raw format to training format. Args: examples: Batch of examples with question, corpus_id, pos_doc, neg_doc num_neg_docs: Number of negative documents to use corpus_dict: Dictionary mapping corpus_id to corpus objects use_dataset_instruction: Whether to use instruction from dataset’s metadata
Flatten grouped bi-encoder output into cross-encoder format.
Takes bi-encoder-style data (queries with grouped doc lists) and flattens it so each query-doc pair becomes a separate entry. Used by cross-encoder transforms in both retrieval_dataset.py and retrieval_dataset_inline.py.
Load retrieval datasets from JSON/JSONL files.
Copied from nemo-retriever-research/src/data/datasets.py
Columns named in extra_columns are carried through verbatim; every other key outside the normalized set is dropped. Absent values become None so the column stays present on every row.
Returns:
Tuple of (dataset, corpus_dict)
Load and return dataset in retrieval format for encoder training.
This function loads data from JSON files and returns it ready for training. Uses set_transform() for lazy evaluation - tokenization is handled by collator.
Parameters:
Path(s) to JSON file(s) containing training data
“bi_encoder” (default) or “cross_encoder”
Type of data (“train” or “eval”)
Number of passages (1 positive + n-1 negatives)
Number of negative documents for evaluation
Random seed for reproducibility (for shuffling if needed)
Whether to shuffle the dataset
Maximum number of training samples to use
Offset for selecting training samples
Returns:
A HuggingFace Dataset where each example is a dict with keys:
Tokenization should be handled by a collator (e.g., BiEncoderCollator) which is more efficient for batch padding and supports dynamic processing.