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_idis provided, the score is the logit for that token. Iffalse_token_idis 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
CrossEncoderbacked 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"). IfNone, the score is the raw logit fortrue_token_idonly.module_input_name – The key in the features dictionary to read logits from. Defaults to
"causal_logits".