LightningIRModel
- class lightning_ir.base.model.LightningIRModel(config: LightningIRConfig, *args, **kwargs)[source]
Bases:
object
Base class for Lightning IR models. Derived classes implement the forward method for handling query and document embeddings. It acts as mixin for a transformers.PreTrainedModel backbone model.
- __init__(config: LightningIRConfig, *args, **kwargs) None [source]
Initializes the model.
- Parameters:
config (LightningIRConfig) – Configuration class for the model
Methods
__init__
(config, *args, **kwargs)Initializes the model.
forward
(*args, **kwargs)Forward method of the model.
from_pretrained
(model_name_or_path, *args, ...)Loads a pretrained model. Wraps the transformers.PreTrainedModel.from_pretrained method and to return a
Attributes
Flag to allow mini batches of documents for a single query.
- ALLOW_SUB_BATCHING = True
Flag to allow mini batches of documents for a single query. Set to false for listwise models to ensure correctness.
- config_class
Configuration class for the model.
alias of
LightningIRConfig
- forward(*args, **kwargs) LightningIROutput [source]
Forward method of the model. Must be implemented by the derived class.
- classmethod from_pretrained(model_name_or_path: str | Path, *args, **kwargs) LightningIRModel [source]
- Loads a pretrained model. Wraps the transformers.PreTrainedModel.from_pretrained method and to return a
derived LightningIRModel. See
LightningIRModelClassFactory
for more details.
- param model_name_or_path:
Name or path of the pretrained model
- type model_name_or_path:
str | Path
- raises ValueError:
If called on the abstract class
LightningIRModel
and no config is passed- return:
A derived LightningIRModel consisting of a backbone model and a LightningIRModel mixin
- rtype:
LightningIRModel
>>> # Loading using model class and backbone checkpoint >>> type(CrossEncoderModel.from_pretrained("bert-base-uncased")) <class 'lightning_ir.base.class_factory.CrossEncoderBertModel'> >>> # Loading using base class and backbone checkpoint >>> type(LightningIRModel.from_pretrained("bert-base-uncased", config=CrossEncoderConfig())) <class 'lightning_ir.base.class_factory.CrossEncoderBertModel'>