Modules

sentence_transformers.cross_encoder.modules defines building blocks that can be used to create CrossEncoder networks from scratch. For more details, see Creating Custom CrossEncoder Models.

See also the modules from sentence_transformers.base.modules in Base > Modules.

LogitScore

class sentence_transformers.cross_encoder.modules.LogitScore(true_token_id: int, false_token_id: int | None = None, module_input_name: str = 'causal_logits')[source]

Converts language model logits into a relevance score for reranking.

Extracts the logits at the last token position and computes a score based on specific vocabulary token IDs. If only true_token_id is provided, the score is the logit for that token. If false_token_id is also provided, the score is the log-odds: logit[true_token_id] - logit[false_token_id].

This module is used as the post-processing step in a CrossEncoder backed by a causal language model (e.g. Qwen, Llama).

Parameters:
  • true_token_id – Vocabulary ID of the token representing a positive/relevant match (e.g. "yes" or "1").

  • false_token_id – Vocabulary ID of the token representing a negative/irrelevant match (e.g. "no" or "0"). If None, the score is the raw logit for true_token_id only.

  • module_input_name – The key in the features dictionary to read logits from. Defaults to "causal_logits".