nemo_automodel.components.datasets.llm.retrieval_collator
nemo_automodel.components.datasets.llm.retrieval_collator
Module Contents
Classes
Functions
API
Collator for encoder retrieval training.
This collator handles tokenization of queries and documents at batch time, which is more memory-efficient than pre-tokenization and allows for dynamic padding based on batch max length.
Based on EncoderCollator from nemo-retriever-research but adapted for Automodel.
Collate a batch of examples.
Parameters:
List of examples, each with ‘question’, ‘doc_text’, ‘doc_image’ keys
Returns: Dict[str, torch.Tensor]
Dictionary with:
Convert dictionary of lists to list of dictionaries.
Example: Input: {‘a’: [1, 2], ‘b’: [3, 4]} Output: [{‘a’: 1, ‘b’: 3}, {‘a’: 2, ‘b’: 4}]
Merge query and document batches into a single dictionary.
Adapted from nemo-retriever-research/src/loaders/loader_utils.py
Bases: DataCollatorWithPadding
Collate query-document pairs for cross-encoder reranking.
Save the training format as a standard named tokenizer chat template.
The reranking template accepts flat query/document messages. It includes
the tokenizer’s single-sequence special-token prefix and suffix because
tokenizer chat templates bypass automatic special-token insertion.
Sentence Transformers restores the special-token suffix after truncation.
Raises:
ValueError: If truncation is not right-sided, the prompt ends in fixed text, or the tokenizer does not use a portable special-token prefix/suffix with zero token type IDs.
Expose one method of a multimodal processor as a dataloader collator.
Return the passage prefix owned by the underlying processor.
Return the query prefix owned by the underlying processor.
Collate retrieval examples with the resolved processor method.
Parameters:
Retrieval examples for one local batch.
Returns: dict[str, object]
Processor-produced tensor batch.
Unpack document lists into individual examples.
Example: Input: [{‘input_ids’: [[1,2], [3,4]], ‘attention_mask’: [[1,1], [1,1]]}] Output: [{‘input_ids’: [1,2], ‘attention_mask’: [1,1]}, {‘input_ids’: [3,4], ‘attention_mask’: [1,1]}]
Turns a method of a processor into a collator function.
Parameters:
The processor instance.
The name of the processor method to turn into a collator function.
Returns: Callable[[list[dict[str, object]]], dict[str, object]]
A collator for vision/multimodal retrieval datasets.