SingleVectorBiEncoderConfig

class lightning_ir.bi_encoder.bi_encoder_config.SingleVectorBiEncoderConfig(query_length: int = 32, doc_length: int = 512, similarity_function: Literal['cosine', 'dot'] = 'dot', normalize: bool = False, sparsification: Literal['relu', 'relu_log'] | None = None, add_marker_tokens: bool = False, query_pooling_strategy: Literal['first', 'mean', 'max', 'sum'] = 'mean', doc_pooling_strategy: Literal['first', 'mean', 'max', 'sum'] = 'mean', **kwargs)[source]

Bases: BiEncoderConfig

Configuration class for a single-vector bi-encoder model.

__init__(query_length: int = 32, doc_length: int = 512, similarity_function: Literal['cosine', 'dot'] = 'dot', normalize: bool = False, sparsification: Literal['relu', 'relu_log'] | None = None, add_marker_tokens: bool = False, query_pooling_strategy: Literal['first', 'mean', 'max', 'sum'] = 'mean', doc_pooling_strategy: Literal['first', 'mean', 'max', 'sum'] = 'mean', **kwargs)[source]

Configuration class for a single-vector bi-encoder model. A single-vector bi-encoder model pools the representations of queries and documents into a single vector before computing a similarity score.

Parameters:
  • query_length (int, optional) – Maximum query length, defaults to 32

  • doc_length (int, optional) – Maximum document length, defaults to 512

  • similarity_function (Literal['cosine', 'dot'], optional) – Similarity function to compute scores between query and document embeddings, defaults to “dot”

  • normalize (bool, optional) – Whether to normalize query and document embeddings, defaults to False

  • sparsification (Literal['relu', 'relu_log'] | None, optional) – Whether and which sparsification function to apply, defaults to None

  • add_marker_tokens (bool, optional) – Whether to preprend extra marker tokens [Q] / [D] to queries / documents, defaults to False

  • query_pooling_strategy (Literal['first', 'mean', 'max', 'sum'] | None, optional) – Whether and how to pool the query token embeddings, defaults to “mean”

  • doc_pooling_strategy (Literal['first', 'mean', 'max', 'sum'] | None, optional) – Whether and how to pool document token embeddings, defaults to “mean”

Methods

__init__([query_length, doc_length, ...])

Configuration class for a single-vector bi-encoder model.

Attributes

model_type

Model type for single-vector bi-encoder models.

backbone_model_type: str | None = None

Backbone model type for the configuration. Set by LightningIRModelClassFactory().

classmethod from_pretrained(pretrained_model_name_or_path: str | Path, *args, **kwargs) LightningIRConfig

Loads the configuration from a pretrained model. Wraps the transformers.PretrainedConfig.from_pretrained

Parameters:

pretrained_model_name_or_path (str | Path) – Pretrained model name or path

Raises:

ValueError – If pre_trained_model_name_or_path is not a Lightning IR model and no LightningIRConfig is passed

Returns:

Derived LightningIRConfig class

Return type:

LightningIRConfig

get_tokenizer_kwargs(Tokenizer: Type[LightningIRTokenizer]) Dict[str, Any]

Returns the keyword arguments for the tokenizer. This method is used to pass the configuration parameters to the tokenizer.

Parameters:

Tokenizer (Type[LightningIRTokenizer]) – Class of the tokenizer to be used

Returns:

Keyword arguments for the tokenizer

Return type:

Dict[str, Any]

model_type: str = 'single-vector-bi-encoder'

Model type for single-vector bi-encoder models.

to_dict() Dict[str, Any]

Overrides the transformers.PretrainedConfig.to_dict method to include the added arguments and the backbone model type.

Returns:

Configuration dictionary

Return type:

Dict[str, Any]