RankCallback
- class lightning_ir.callbacks.callbacks.RankCallback(save_dir: Path | str | None = None, run_name: str | None = None, overwrite: bool = False)[source]
Bases:
Callback,_GatherMixin,_OverwriteMixin- __init__(save_dir: Path | str | None = None, run_name: str | None = None, overwrite: bool = False) None[source]
Callback to write run file of ranked documents to disk.
- Parameters:
save_dir (Path | str | None) – Directory to save run files to. If None, run files will be saved in the models’ directory. Defaults to None.
run_name (str | None) – Name of the run file. If None, the dataset’s dataset_id or file name will be used. Defaults to None.
overwrite (bool) – Whether to skip or overwrite already existing run files. Defaults to False.
Methods
__init__([save_dir, run_name, overwrite])Callback to write run file of ranked documents to disk.
on_test_batch_end(trainer, pl_module, ...[, ...])Hook to aggregate and write ranking to file.
setup(trainer, pl_module, stage)Hook to setup the callback.
teardown(trainer, pl_module, stage)Hook to cleanup the callback.
Attributes
- on_test_batch_end(trainer: Trainer, pl_module: LightningIRModule, outputs: LightningIROutput, batch: Any, batch_idx: int, dataloader_idx: int = 0) None[source]
Hook to aggregate and write ranking to file.
- Parameters:
trainer (Trainer) – PyTorch Lightning Trainer.
pl_module (LightningIRModule) – LightningIR module.
outputs (LightningIROutput) – Scored query documents pairs.
batch (Any) – Batch of input data.
batch_idx (int) – Index of batch in the current dataset.
dataloader_idx (int | None) – Index of the dataloader. Defaults to 0.
- Raises:
ValueError – If the batch does not have query_ids.
- setup(trainer: Trainer, pl_module: LightningIRModule, stage: str) None[source]
Hook to setup the callback.
- Parameters:
trainer (Trainer) – PyTorch Lightning Trainer.
pl_module (LightningIRModule) – LightningIR module.
stage (str) – Stage of the trainer, must be “test”.
- Raises:
ValueError – If the stage is not “test”.
ValueError – If no save_dir is provided and model_name_or_path is not a path (the model is not local).
- teardown(trainer: Trainer, pl_module: BiEncoderModule, stage: str) None[source]
Hook to cleanup the callback.
- Parameters:
trainer (Trainer) – PyTorch Lightning Trainer.
pl_module (LightningIRModule) – LightningIR bi-encoder module used for indexing.
stage (str) – Stage of the trainer, must be “test”.