[Feature] Add support for Qwen3 Reranker with Sequence Classifier head #698
All Vouch review confidence checks passed
Residual risk 0.17 = Change Risk (0.39) × (1 − Review Confidence (0.57)).
Review depth and reviewer attention state are adequate.
Model 1 · Change Risk (XGBoost)
Score: 0.39 · 262 lines diff across 3 files
Model 2 · Review Depth (DistilBERT)
Depth Score: 0.17 · 1 substantive comment(s)
Model 3 · Review Timing & Attention
Session adequacy: 100% · Reviewer familiarity: 35%
Bedrock Claude 3 · Risk Narration
(disconnected)
Groq Risk Narration
AWS Bedrock is currently disconnected. Generate high-confidence PR triage narration on-demand using Groq.
Model 1 · Change Risk Attribution
SHAP Weights
Diff Size
diff_size
0.333
Shallow Review Depth
shallow_review_depth
0.289
Real PR Conversation Timeline
1 comments
"Review active on #698"
general
weight: 0.35
realsigridjin
I totally missed #695 and ended up coding this in a hurry today.
@OlivierDehaene or @Narsil: Happy to work with @sigridjineth if helpful
Summary
Adds support for Qwen3 reranker models (e.g., tomaarsen/Qwen3-Reranker-0.6B-seq-cls) that have been converted from causal LM to sequence classification architecture. These models require specific chat templates for optimal performance. Functionality was added to support custom instructions.
How Qwen3 Reranking (with Seq Classification conversion) Works
Conversion adds a classification head (score.weight) on top of base model
- This PR enables TEI to recognize these models as classifier/reranker
- Works with /rerank endpoint
- Process:
a. Takes query-document pair formatted as conversation
b. Uses LastToken pooling to extract representations
c. Passes through classification head (single linear layer, no bias)
d. Returns logit score (sigmoid applied for probability)
# Key Changes
1. Template Support
- New templates module implementing Qwen3 chat format:
<|im_start|>systemJudge whether the Document meets the requirements...
<|im_start|>user
<Instruct>: {instruction}
<Query>: {query}
<Document>: {document}<|im_end|>
<|im_start|>assistant
<think>
- Added
instructionanduse_templatefields to RerankRequest (HTTP & gRPC)- Auto-detects Qwen3 seq-cls models for template application
- Default instruction: "Select only the Documents that are semantically similar to the Query."
2. Model Loading
- Flexible tensor loading for score.weight pattern (no bias tensor)
- Uses LastToken pooling for classification models
- Available via /rerank endpoint for Classifier models
Testing
Notes
The model is highly sensitive to the instruction and template format. Without the template, results can be somewhat random. Tuning the Instruction can result in significantly improved discrimination.