ms-marco-MiniLM-L12-v2

The cross‑encoder/ms‑marco‑MiniLM‑L12‑v2 is a pre‑trained cross‑encoder model designed specifically for text‑ranking and passage re‑ranking tasks. It takes a

cross-encoder 749K downloads apache-2.0 Text Ranking
Frameworkssentence-transformerspytorchjaxonnxsafetensorsopenvinotransformers
Languagesen
Datasetssentence-transformers/msmarco
Tagsberttext-classificationtext-rankingbase_model:microsoft/MiniLM-L12-H384-uncasedbase_model:quantized:microsoft/MiniLM-L12-H384-uncasedtext-embeddings-inference
Downloads
749K
License
apache-2.0
Pipeline
Text Ranking
Author
cross-encoder

Run ms-marco-MiniLM-L12-v2 locally on a Q4KM hard drive

Get the cross‑encoder/ms‑marco‑MiniLM‑L12‑v2 model pre‑installed on a high‑speed Q4KM hard drive for instant deployment. Shop now and accelerate your retrieval pipelines today. Additional resources:...

Shop Q4KM Drives

Technical Overview

The cross‑encoder/ms‑marco‑MiniLM‑L12‑v2 is a pre‑trained cross‑encoder model designed specifically for text‑ranking and passage re‑ranking tasks. It takes a query–passage pair as input and returns a single relevance score indicating how well the passage answers the query. Unlike bi‑encoders that embed queries and passages independently, this cross‑encoder processes the concatenated pair through a transformer, allowing rich cross‑attention between the two texts and delivering higher ranking quality.

Key features and capabilities include:

  • Built on the microsoft/MiniLM‑L12‑H384‑uncased backbone – a lightweight 12‑layer BERT‑style model (384‑dimensional hidden size) that balances speed and accuracy.
  • Fine‑tuned on the MS MARCO Passage Ranking dataset, the standard benchmark for information‑retrieval re‑ranking.
  • Supports the sentence‑transformers and transformers libraries, enabling one‑line inference with either CrossEncoder or AutoModelForSequenceClassification.
  • Optimized for both GPU and CPU inference; the model can be exported to ONNX, OpenVINO, or TensorFlow via the safetensors format.

Architecture highlights:

  • 12 transformer layers, 384 hidden units, 12 attention heads – a compact MiniLM architecture.
  • Classification head (single linear layer) that maps the [CLS] token to a scalar relevance score.
  • Trained with a pairwise ranking loss (e.g., CrossEntropyLoss over positive/negative passage pairs) to directly optimize ranking metrics.

Intended use cases revolve around any pipeline that requires a high‑quality re‑ranking step after an initial retrieval stage (e.g., ElasticSearch, BM25). Typical scenarios include:

  • Search‑engine result refinement.
  • Question‑answering systems that need to select the most relevant passage.
  • Legal or medical document retrieval where precision is critical.

Benchmark Performance

The most relevant benchmarks for a cross‑encoder in the retrieval domain are TREC Deep Learning 2019 (TREC‑DL‑19) and the MS MARCO Passage Re‑ranking development set. Both evaluate how well a model ranks a set of candidate passages for a query, using metrics such as NDCG@10 and MRR@10.

ModelNDCG@10 (TREC‑DL‑19)MRR@10 (MS MARCO Dev)Docs / Sec (V100)
cross‑encoder/ms‑marco‑MiniLM‑L12‑v274.3139.02960
cross‑encoder/ms‑marco‑MiniLM‑L6‑v274.3039.011 800
cross‑encoder/ms‑marco‑MiniLM‑L4‑v273.0437.702 500
cross‑encoder/ms‑marco‑MiniLM‑L2‑v271.0134.854 100

These numbers show that the MiniLM‑L12 variant achieves the highest MRR@10 among the MiniLM family while keeping inference speed (≈960 documents per second on a V100) competitive. The slight edge over the L6 model demonstrates the benefit of the extra layers for nuanced relevance judgments, making it a strong candidate for production‑grade re‑ranking pipelines.

Hardware Requirements

Because the model is a 12‑layer MiniLM with a classification head, its memory footprint is modest compared to larger BERT variants. Typical requirements are:

  • VRAM for inference: 2 GB–3 GB (FP32) or ~1.5 GB (FP16/INT8) is sufficient for a single batch.
  • Recommended GPU: NVIDIA V100, A100, or RTX 3090 – these provide the throughput reported in the benchmark (≈960 docs / sec on a V100).
  • CPU fallback: A modern 8‑core CPU (e.g., Intel i7‑12700K) can run the model at ~30–50 docs / sec; batch size and token length will affect speed.
  • Storage: The model files (weights, tokenizer, config) occupy roughly 300 MB (safetensors format). Additional space is needed for the MS MARCO dataset if you plan to fine‑tune.
  • Performance characteristics: Inference latency is ~1 ms per query‑passage pair on a V100 (batch size = 1). Larger batches improve throughput due to GPU parallelism.

Use Cases

The primary application is passage re‑ranking in information‑retrieval pipelines. After a fast first‑stage retriever (BM25, dense vector search, etc.) returns a shortlist of candidate passages, this cross‑encoder scores each pair to produce a final ordered list.

  • Search engines: Boost relevance for web or enterprise search by re‑ranking top‑k results.
  • Question‑answering platforms: Select the most accurate passage to feed into a downstream answer‑generation model.
  • Legal & medical document review: Prioritize the most pertinent excerpts from large corpora.
  • E‑commerce: Re‑rank product descriptions or reviews based on a shopper’s query.

Integration is straightforward with the sentence‑transformers library (single‑line CrossEncoder.predict) or via the transformers API for custom batching, ONNX export, or deployment on edge devices.

Training Details

Training followed the standard cross‑encoder recipe for MS MARCO passage ranking:

  • Dataset: sentence‑transformers/msmarco – the MS MARCO passage ranking training split (≈1 M query‑passage pairs).
  • Base model: microsoft/MiniLM‑L12‑H384‑uncased (12 layers, 384 hidden size).
  • Loss function: Pairwise cross‑entropy (softmax over positive and negative passages for each query).
  • Optimization: AdamW with a learning rate of 2e‑5, linear warm‑up over 10 % of steps, and weight decay of 0.01.
  • Compute: Trained on a single V100 GPU for ~12 hours (≈200 k steps, batch size = 32).
  • Fine‑tuning capability: Users can continue training on domain‑specific data by loading the model with CrossEncoder and calling fit on a new query‑passage collection.

Licensing Information

The model card lists the license as apache‑2.0 in the README, even though the Hugging Face license field is marked “unknown”. Apache 2.0 is a permissive open‑source license that:

  • Allows commercial and non‑commercial use without royalty.
  • Requires attribution – you must retain the copyright notice and license text in any distribution.
  • Provides an explicit patent grant, protecting downstream users from patent claims related to the contributed code.
  • Does not impose copyleft; you may combine the model with proprietary software.

If you redistribute the model (e.g., in a container or on a hardware device), include the Apache 2.0 license file and a clear attribution statement such as “Model cross‑encoder/ms‑marco‑MiniLM‑L12‑v2 © Microsoft, licensed under Apache 2.0”. No additional restrictions are imposed by the model author.

Pre-loaded AI models. Ready to run.

Skip the downloads. Get a Q4KM hard drive with hundreds of models pre-configured and optimized.

Shop Q4KM Hard Drives