skip to content

Why does CrossEncoder cross-encoder/ms-marco-MiniLM-L6-v2 return scores like 8.6 and -4.3, and how does activation_fn change them?

level: middleimportance: should knowfreq 16%

answer

  1. logits, not probabilities
  2. activation saved with the checkpoint
  3. Sigmoid default when num_labels is 1
  4. monotonic: ordering unchanged
  5. per-call activation_fn since v5.4

basics

~10 s

The MS MARCO cross-encoders ship with an identity activation, so predict returns raw logits, roughly -10 to 10. Passing activation_fn=torch.nn.Sigmoid() squashes them into 0 to 1 without changing the ranking order.

solid answer

~40 s

A CrossEncoder's head outputs a logit per pair, and `predict` then applies `activation_fn`. The activation is resolved in order: the one you pass, then the one saved in the checkpoint's Sentence Transformers config, then a default of `Sigmoid` for `num_labels=1` models and `Identity` for multi-label ones. The MS MARCO checkpoints are saved with an identity activation, so you see logits; loading with `activation_fn=torch.nn.Sigmoid()` gives 0 to 1 scores. Sigmoid is monotonic, so the order of the documents is the same either way. Other rerankers, such as `BAAI/bge-reranker-base`, can come back on a different scale, so a score is only meaningful relative to the same checkpoint. Since Sentence Transformers v5.4 an `activation_fn` passed to `predict` applies to that call only.

go deeper

for a junior

Recall that MS MARCO rerankers return raw logits and that activation_fn=torch.nn.Sigmoid() maps them into 0 to 1 without reordering the results.

for a middle

Explain the resolution order for the activation: call argument, constructor argument, the checkpoint's saved config, then Sigmoid for one label or Identity for several.

for a senior

Show you treat scores as checkpoint-specific, check model.activation_fn after loading, and never let a call-level activation leak into scores another code path compares.

for a principal

Weigh exposing raw logits against squashed scores to downstream consumers, and how to keep any score contract stable when the reranker checkpoint is replaced.

## Where a CrossEncoder score comes from A **CrossEncoder** feeds a (query, passage) pair through a transformer with a small classification head on top. For a reranker the head has **one output** (`num_labels=1`): a single unbounded real number called a **logit**. Higher means "more relevant", but the number itself has no fixed scale. After the forward pass, `predict` (and therefore `rank`) applies an **activation function** to that logit. The activation is what decides whether you see something like `8.6` or something like `0.9998`. ## How the activation is chosen Sentence Transformers resolves `activation_fn` in this order: 1. **An argument to the call** — `model.predict(pairs, activation_fn=...)` or `model.rank(..., activation_fn=...)`. Since v5.4 this applies to that call only and does not modify the model. 2. **An argument to the constructor** — `CrossEncoder(name, activation_fn=torch.nn.Sigmoid())` sets it on the instance. 3. **The checkpoint's saved configuration** — a trained CrossEncoder records its activation (for example `"activation_fn": "torch.nn.modules.linear.Identity"` in `config_sentence_transformers.json`). A path outside the `torch.` namespace is only loaded with `trust_remote_code=True`; otherwise the library warns and falls back to the default. 4. **The default** — `torch.nn.Sigmoid()` when `num_labels == 1`, `torch.nn.Identity()` otherwise. The `cross-encoder/ms-marco-*` checkpoints are saved with an identity activation, which is why the library's own examples print values such as `8.607138` and `-4.3200774`. The pretrained-models page notes that their raw values "can reasonably range between -10 and 10". ## What changes when you add Sigmoid | | Identity (logits) | Sigmoid | |---|---|---| | Range | unbounded, roughly -10 to 10 for MS MARCO models | 0 to 1 | | Order of documents | baseline | **identical** (sigmoid is monotonic) | | Looks like | `8.6`, `-4.3` | `0.9998`, `0.0131` | | Resolution near the top | good | compressed: very relevant passages crowd near 1.0 | The key point is that **ranking does not change**. Sigmoid maps a bigger logit to a bigger number, so sorting by either gives the same order. What changes is how the number *reads*: a 0 to 1 value is easier to log, display or compare against a threshold, but it is still not a calibrated probability of relevance — the model was trained to separate relevant from irrelevant passages, not to predict how often a 0.7 is right. Whether and where to cut off low scores is a separate retrieval-design question. ## Multi-label CrossEncoders Classifier checkpoints (for example `cross-encoder/nli-deberta-v3-base`, three labels) default to `Identity`, so `predict` returns one row of logits per pair. Use `apply_softmax=True` to get per-pair class probabilities. `rank` refuses these models because it needs exactly one score per document. ## Practical consequences - **Do not compare scores across checkpoints.** A `5.0` from an MS MARCO MiniLM reranker and a value from `BAAI/bge-reranker-base` are on unrelated scales. Swapping the model silently breaks any hard-coded threshold. - **Do not mix activations within one result set.** If one code path calls `predict(..., activation_fn=torch.nn.Sigmoid())` and another uses the model's default, their scores are not comparable. - **Check `model.activation_fn` after loading.** It tells you what the checkpoint resolved to; `model.num_labels` tells you whether you have a single-score reranker or a classifier. - **Before v5.4, a call-level activation stuck.** Passing `activation_fn` to `predict` used to persist on the instance, so a one-off call could change every later score. Code written for older releases sometimes relied on that. ## Checking a checkpoint you have not used before Before wiring a new reranker into anything that reads its numbers, spend two minutes on it: 1. Load it and print **`model.num_labels`** and **`model.activation_fn`** to see whether it is a single-score reranker and what scale it resolved to. 2. Score one pair you know is relevant and one you know is not, and look at the spread of the two values. 3. If a dashboard, log or threshold consumes the scores, **record the checkpoint and the activation next to it**, so a later model swap is visibly a contract change. 4. If you want 0 to 1 values everywhere, set `activation_fn` **in the constructor**, not per call, so every code path sees the same scale. ## A worked example ```python import torch from sentence_transformers import CrossEncoder model = CrossEncoder("cross-encoder/ms-marco-MiniLM-L6-v2") pairs = [("How many people live in Berlin?", "Berlin had a population of 3,520,031 registered inhabitants."), ("How many people live in Berlin?", "Berlin is well known for its museums.")] model.predict(pairs) # logits, roughly [8.6, -4.3] model.predict(pairs, activation_fn=torch.nn.Sigmoid()) # roughly [0.9998, 0.013], this call only ``` Both calls put the population passage first. Only the numbers' scale differs.

  • You swap ms-marco-MiniLM-L6-v2 for a different reranker and a hard-coded threshold of 0.0 now drops almost nothing. Why?
    The threshold was tuned on the old model's logit scale. A different checkpoint may resolve a different activation, for example Sigmoid, putting every score between 0 and 1, or simply produce logits on another scale. Scores are only comparable within one checkpoint and one activation, so a threshold must be re-derived after any model change.
  • Why might a CrossEncoder loaded from a third-party repo warn that its activation function path is not trusted?
    The saved config names an activation by dotted path. Sentence Transformers only imports paths starting with `torch.` unless you load with `trust_remote_code=True`; otherwise it warns and falls back to the default activation, Sigmoid for a single-label model.

  • A negative CrossEncoder score means the model failed
  • Adding Sigmoid changes which documents rank first
  • A sigmoid score of 0.9 means a 90 percent chance of relevance
  • Scores from two different rerankers can share one threshold
  • MS MARCO cross-encoders return 0 to 1 scores by default

Assumes Sentence Transformers v6; since v5.4 an activation_fn passed to predict or rank applies to that call only and no longer persists on the model.