Technical Overview
What is this model? cross-encoder/ms-marco-MiniLM-L4-v2 is a
cross‑encoder built on the MiniLM‑L4 architecture that has been fine‑tuned on the
MS MARCO Passage Ranking dataset.
It takes a query–passage pair as input and outputs a single relevance score,
making it ideal for re‑ranking candidate passages in information‑retrieval pipelines.
Key features and capabilities
- Fast inference with a lightweight 4‑layer MiniLM backbone (≈ 22 M parameters).
- Optimised for the
text‑rankingpipeline tag in Sentence‑Transformers. - Supports PyTorch, TensorFlow (via
transformers), ONNX, OpenVINO and Safetensors for flexible deployment. - Compatible with Hugging Face
Endpointsandtext‑embeddings‑inferenceservices. - Apache‑2.0 licence (see Licensing section).
Architecture highlights
- Base model:
cross-encoder/ms-marco-MiniLM-L12-v2(12‑layer MiniLM) reduced to a 4‑layer version for lower latency. - Transformer encoder with 4 hidden layers, 256 hidden size, 4 attention heads.
- Classification head (single linear layer) that maps the [CLS] token to a scalar relevance logit.
- Trained with a pairwise cross‑entropy loss on query–passage triples (positive vs. negative passages).
Intended use cases
- Re‑ranking the top‑k results returned by a first‑stage retriever (e.g., BM25, ElasticSearch).
- Passage‑level relevance scoring for question answering, chat‑bots, and conversational search.
- Feature extraction for downstream ranking models (the raw logit can be combined with other signals).
Benchmark Performance
The most relevant benchmarks for cross‑encoders are TREC Deep Learning 2019 (NDCG@10) and MS MARCO Passage Reranking (MRR@10). Both evaluate how well a model can reorder a set of candidate passages given a query.
| Model | NDCG@10 (TREC DL 19) | MRR@10 (MS MARCO Dev) | Docs / Sec (V100) |
|---|---|---|---|
cross-encoder/ms-marco-MiniLM-L4-v2 |
73.04 | 37.70 | 2 500 |
Why these numbers matter NDCG@10 captures ranking quality at the top‑10 positions, which is critical for user‑facing search experiences. MRR@10 reflects the probability that the first relevant passage appears within the top‑10, directly influencing answer‑retrieval latency.
Compared with its siblings, the L4‑variant strikes a balance between speed and accuracy: it outperforms the MiniLM‑L2 version (71.01 NDCG@10, 34.85 MRR@10) while being roughly twice as fast as the MiniLM‑L6 (1 800 docs / sec). It is only marginally behind the full‑size MiniLM‑L12 (74.31 NDCG@10, 39.02 MRR@10) but processes 2‑3× more documents per second, making it a practical choice for real‑time re‑ranking.
Hardware Requirements
- VRAM for inference: The model fits comfortably in 2 GB of GPU memory (≈ 1.3 GB for the weights + activation overhead). 4 GB GPUs (e.g., RTX 3050, T4) provide ample headroom for batch processing.
- Recommended GPU: NVIDIA V100, A100, RTX 3080/3090, or any GPU with ≥ 4 GB VRAM and FP16 support for optimal throughput.
- CPU requirements: A modern 8‑core CPU (e.g., Intel i7‑10700K, AMD Ryzen 7 3700X) is sufficient for tokenisation and batching when the GPU is the bottleneck.
- Storage: Model files (weights, tokenizer, config) total ≈ 300 MB. Storing the Safetensors or ONNX variant adds a few megabytes.
- Performance characteristics: On a V100 GPU, the model processes about 2 500 query‑passage pairs per second (batch size = 32, FP16). Latency per pair is ~0.4 ms, making it suitable for high‑throughput retrieval pipelines.
Use Cases
- Search Engine Re‑ranking: After an initial BM25 or dense retriever returns a candidate set, the cross‑encoder scores each candidate to produce a final ordered list.
- Question Answering Systems: Rank passages that might contain the answer before feeding the top‑k into a reader model.
- Chatbot Knowledge‑Base Retrieval: Quickly surface the most relevant FAQ or documentation snippet for a user query.
- Enterprise Document Search: Apply the model to internal knowledge bases, legal documents, or support tickets to improve relevance.
- Hybrid Retrieval Pipelines: Combine with vector‑based dense retrievers (e.g., Sentence‑Transformers) to first narrow down candidates, then apply the cross‑encoder for fine‑grained ranking.
Training Details
Methodology: The model was fine‑tuned as a cross‑encoder on the MS MARCO passage ranking dataset. Each training example consists of a query, a relevant passage (positive), and a non‑relevant passage (negative). The model learns to assign higher logits to positive pairs.
- Dataset:
sentence‑transformers/msmarco– the standard MS MARCO passage ranking set (≈ 1 M query‑passage pairs). - Base checkpoint:
cross‑encoder/ms‑marco‑MiniLM‑L12‑v2– a 12‑layer MiniLM model that was distilled down to 4 layers for this variant. - Training compute: Typically performed on a single V100 GPU for 2–3 days, using a batch size of 32–64, learning rate 2e‑5, and mixed‑precision (FP16) to accelerate training.
- Fine‑tuning capabilities: Users can continue training on domain‑specific
relevance data via the
CrossEncoderAPI in Sentence‑Transformers, or adapt the model with Hugging FaceTrainerfor custom loss functions.
Licensing Information
The model is released under the Apache‑2.0 licence (the README lists it explicitly, despite the “unknown” tag on the hub). Apache‑2.0 is a permissive open‑source licence that grants the following rights:
- Free use, modification, and distribution for both commercial and non‑commercial purposes.
- Ability to incorporate the model into proprietary software without the requirement to open‑source your own code.
- Obligation to retain the original copyright notice and provide a copy of the licence.
- No warranty; the model is provided “as is”.
Commercial usage: Fully allowed. Companies can embed the model in SaaS products, on‑premise search engines, or any other commercial offering. The only restriction is the standard Apache‑2.0 attribution requirement.