Sentence-transformers/all-mpnet-base-v2 model
all-mpnet-base-v2 is a sentence-embedding model that maps an English sentence or short paragraph to a vector of 768 numbers. It encodes each text independently. A search engine can therefore encode its passages once, store their vectors, and compare each new query with the stored passages using cosine similarity. The same model can compare two phrases or group a collection of texts by meaning. [1][2]
The Sentence Transformers team fine-tuned Microsoft's mpnet-base encoder on related texts drawn from a collection of about 1.17 billion training examples. The checkpoint appeared on Hugging Face on August 30, 2021. Its name on the Hub is sentence-transformers/all-mpnet-base-v2, and its weights carry the Apache 2.0 license. [1][3][4]
Identity and provenance
| Field | Published specification |
|---|---|
| Base checkpoint | microsoft/mpnet-base [1][4] |
| Model family | General-purpose English sentence encoders from the 2021 Hugging Face community project [1][5] |
| Architecture | MPNet encoder, mean pooling, and vector normalization [6][7][8] |
| Parameters | Approximately 110 million [9] |
| Output | One 768-dimensional vector per sentence or passage [1][7] |
| Default input limit | 384 tokens per encoded sequence [10] |
| Published formats | PyTorch weights, Safetensors weights, ONNX exports, and OpenVINO exports [9] |
| License | Apache 2.0 [1] |
Two earlier research projects contributed different parts of this model. In 2019, Nils Reimers and Iryna Gurevych introduced Sentence-BERT, a way to train an encoder so that independently computed sentence vectors can be compared. In 2020, Kaitao Song and colleagues introduced MPNet, the token-level pre-training method behind the Microsoft checkpoint. The 2021 community project adapted that checkpoint to the sentence-level task. [2][4][5][11]
The project took place during the Hugging Face JAX/Flax community sprint. Its title referred to a billion training pairs, and it produced several models. The library documentation uses all-* for the original models trained on the broad collection of available data. Other Sentence Transformers releases were trained for narrower tasks, including question-to-passage search. Nils Reimers started the library at TU Darmstadt in 2019. Tom Aarsen took over its maintenance in late 2023, and the university's UKP Lab transferred the library to Hugging Face in October 2025. [5][12][13]
Architecture
The encoder retains the dimensions of microsoft/mpnet-base. Its 12 transformer layers compute a contextual representation for each token. The output for a token such as "bank" can therefore depend on the words around it. A separate pooling layer combines those token vectors into one vector for the whole sequence. [4][6][7]
| Component | Checkpoint setting |
|---|---|
| Transformer layers | 12 [6] |
| Hidden size | 768 [6] |
| Attention heads per layer | 12 [6] |
| Feed-forward intermediate size | 3,072 [6] |
| Position embedding table | 514 entries [6] |
| Vocabulary | 30,527 entries [6] |
| Tokenizer | Lowercasing MPNet WordPiece tokenizer [14][15] |
| Sentence pooling | Mean of the unpadded token representations [1][7] |
| Final module | L2 normalization [1][8] |
MPNet pre-training
Microsoft's model learned to predict masked tokens in a permuted order. A prediction can use earlier predictions in that order, so the model can learn dependencies among multiple missing words. It also receives position information for the entire input, including the positions whose words are still hidden. Song and colleagues developed this objective to address limitations of masked language modeling in BERT and permuted language modeling in XLNet. Their experiments evaluated the base encoder on language understanding benchmarks including GLUE and SQuAD. The sentence-model team then trained the weights on a different problem, identifying related texts. [1][4][11]
Pooling and normalization
The pooling stage sums the token vectors at positions where the attention mask is 1 and divides by the number of those positions. A short sentence gets the same set of terms in its average whether it is encoded alone or padded to match a longer sentence in a batch. The saved configuration enables mean pooling and disables the first-token and maximum-pooling alternatives. [1][7]
The next module divides the pooled vector by its Euclidean length. For two unit vectors, their dot product equals their cosine similarity. A search index that uses the inner product can thus reproduce cosine rankings with this checkpoint's normalized vectors. The library's similarity function defaults to cosine, and the dot product avoids an extra normalization when vectors already have unit length. [1][8][16]
Input length
Three configuration values matter when reproducing an embedding. The reported fine-tuning limit was 128 tokens. Sentence Transformers sets max_seq_length to 384 for inference. The standalone tokenizer declares a maximum of 512, and the encoder's position embedding table contains 514 entries. The latter two values describe the underlying components. Loading the complete Sentence Transformers checkpoint applies the 384-token setting. [1][6][10][14][17]
Truncation applies after tokenization. A word can occupy several pieces, and the tokenizer also inserts boundary tokens. Consequently, 384 words of prose can exceed the limit. In a direct Transformers implementation, specifying max_length=384 makes the truncation match the sentence encoder. Otherwise, two implementations may agree on short sentences and produce different vectors for the same long paragraph. [10][14][15]
Training
Hardware and optimization
The project account describes seven TPU v3-8 systems available to the community project. The checkpoint card describes fine-tuning this model on one TPU v3-8. The card and the training script agree on the optimizer, learning rate, warmup, and input length. They differ on the number of steps and the size of a batch. [1][5][17]
| Setting | Reported value |
|---|---|
| Optimizer | AdamW [1][17] |
| Learning rate | 0.00002 [1][17] |
| Learning-rate warmup | 500 steps [1][17] |
| Maximum training sequence length | 128 tokens [1][17] |
| Model card's training schedule | 100,000 steps with 1,024 examples per batch, 128 per TPU core [1] |
| Invocation recorded in the training script | 1,000,000 requested steps with 64 examples per process, or 512 across the default eight processes [17] |
The community sprint's name identifies its wider JAX/Flax setting. The training script committed with this checkpoint uses PyTorch and PyTorch/XLA. Its last line records the command passed to the trainer. A requested step count describes a run configuration. The two published accounts leave the number of updates that produced the released weights uncertain. [1][5][17]
Contrastive loss
The fine-tuning objective rewards the encoder for distinguishing a known match from other texts in the same batch. For example, an anchor can be a question and its match the passage that answers it. For a batch of paired examples, the script builds a square matrix. Entry (i, j) is the dot product of normalized anchor vector i and candidate vector j, multiplied by a scale whose default is 20. The known matches lie on the diagonal. [1][5][17]
The script uses cross-entropy to reward a high diagonal score relative to the competing scores. For two-column examples it averages the loss in both directions, first asking each anchor to identify its partner, then asking each partner to identify its anchor. For three-column examples the training data supplies an anchor, a positive, and an explicit negative. The script adds the negative vectors to the candidate set and computes the loss from the anchor side. This distinction matters for sources such as MS MARCO, which supplied triplets. [1][17]
This form of contrastive learning uses the other examples in a batch as additional negatives. In the paired case, doubling the batch increases the number of alternatives each anchor competes with. The training code gathers vectors from the TPU processes before scoring them. It also checks for repeated texts while assembling the batch, so an identical string does not appear twice with competing labels. The scale factor belongs to the training loss. The released encoder can score a pair directly by cosine similarity. [5][16][17]
Training datasets
The model card lists 1,170,060,424 training tuples. Some entries pair a question with its answer, others pair passages related by a citation, and several contain explicit negatives. The table combines the card's entries with the Amazon question-answer file listed in the data configuration. Its 2,448,839 pairs account for the difference between the printed rows and the card's total. The counts describe how many examples were available from each source. The training script drew from source files using separately assigned sampling weights. [1][17][18]
| Dataset and relation | Training tuples |
|---|---|
| Reddit comments, 2015-2018 | 726,484,430 |
| S2ORC citation-linked abstracts | 116,288,806 |
| WikiAnswers duplicate questions | 77,427,422 |
| PAQ question and answer | 64,371,441 |
| S2ORC citation-linked titles | 52,603,982 |
| S2ORC title and abstract | 41,769,185 |
| Stack Exchange title and body | 25,316,456 |
| Stack Exchange title plus body and answer | 21,396,559 |
| Stack Exchange title and answer | 21,396,559 |
| MS MARCO triplets | 9,144,553 |
| GOOAQ | 3,012,496 |
| Amazon question-answer pairs | 2,448,839 |
| Yahoo Answers title and answer | 1,198,260 |
| Code Search | 1,151,414 |
| COCO captions | 828,395 |
| SPECTER citation triplets | 684,100 |
| Yahoo Answers question and answer | 681,164 |
| Yahoo Answers title and question | 659,896 |
| SearchQA | 582,261 |
| ELI5 | 325,475 |
| Flickr30k captions | 317,695 |
| Stack Exchange duplicate question titles | 304,525 |
| AllNLI, from SNLI and MultiNLI | 277,230 |
| Stack Exchange duplicate question bodies | 250,519 |
| Stack Exchange duplicate question titles plus bodies | 250,460 |
| Sentence Compression | 180,000 |
| WikiHow | 128,542 |
| AltLex | 112,696 |
| Quora question triplets | 103,663 |
| Simple Wikipedia | 102,225 |
| Natural Questions | 100,231 |
| SQuAD 2.0 | 87,599 |
| TriviaQA | 73,346 |
| Total | 1,170,060,424 |
Reddit accounts for about 62 percent of the listed examples. That proportion alone cannot establish how often training saw a Reddit example. For instance, the configuration gives each of the four yearly Reddit files a sampling weight of 82 and the single MS MARCO file a weight of 247. The sampler draws file indices by weight and requires examples within a batch to share the same two- or three-column format. [1][17][18]
The relation within a pair also affects what a high similarity score means. A duplicate question can express almost the same proposition in different words. A cited paper and its citing paper can discuss the same subject while making different claims. A question and its answer generally serve different functions. All three relationships provided positive examples during fine-tuning. [1][5]
How to use it
Sentence Transformers
SentenceTransformer.encode runs the checkpoint's tokenizer, encoder, pooling, and normalization stages. The example computes one query vector and two independently reusable passage vectors. The resulting similarity tensor has one row for the query and one column per passage. [1][8][16]
from sentence_transformers import SentenceTransformer
model = SentenceTransformer("sentence-transformers/all-mpnet-base-v2")
passages = [
"Library books can be returned at the front desk.",
"The pool offers swimming lessons on Friday.",
]
query = "Where can I take back a borrowed book?"
passage_vectors = model.encode(passages)
query_vector = model.encode([query])
scores = model.similarity(query_vector, passage_vectors)
print(passage_vectors.shape) # (2, 768)
print(scores.shape) # torch.Size([1, 2])
print(passages[scores.argmax().item()])
Transformers with manual pooling
Loading AutoModel gives access to the contextual vector for every token position. The code below reproduces the sentence-level stages explicitly. Expanding the attention mask by one dimension lets PyTorch broadcast each token's mask value across its 768 features. Summing over the token dimension then leaves one row per passage. [1][7][8][10]
import torch
import torch.nn.functional as F
from transformers import AutoModel, AutoTokenizer
checkpoint = "sentence-transformers/all-mpnet-base-v2"
tokenizer = AutoTokenizer.from_pretrained(checkpoint)
encoder = AutoModel.from_pretrained(checkpoint).eval()
texts = ["Library books can be returned at the front desk.", "The pool is open."]
batch = tokenizer(
texts, padding=True, truncation=True, max_length=384, return_tensors="pt"
)
with torch.inference_mode():
tokens = encoder(**batch).last_hidden_state
mask = batch["attention_mask"].unsqueeze(-1).to(tokens.dtype)
pooled = (tokens * mask).sum(dim=1) / mask.sum(dim=1).clamp_min(1)
embeddings = F.normalize(pooled, p=2, dim=1)
For a local copy, the Hub command hf download sentence-transformers/all-mpnet-base-v2 downloads the repository and returns its cache location. The --revision option accepts a commit hash so another installation can retrieve the same checkpoint files. The model repository includes the module definitions and tokenizer configuration alongside its weights. [9][19]
Performance
Original English MTEB evaluation
The original Massive Text Embedding Benchmark paper, first circulated in 2022 and published at EACL in 2023, reports a score of 57.78 for this checkpoint across 56 English datasets. Table 10 of that paper identifies the row abbreviated "MPNet" as sentence-transformers/all-mpnet-base-v2. Table 1 breaks the results down by task. These scores correspond to that evaluation and its dataset versions. [20]
| Task group | English datasets | Published score |
|---|---|---|
| Classification | 12 | 65.07 |
| Clustering | 11 | 43.69 |
| Pair classification | 3 | 83.04 |
| Reranking | 4 | 59.36 |
| Retrieval | 15 | 43.81 |
| Semantic textual similarity | 10 | 80.28 |
| Summarization evaluation | 1 | 27.49 |
| All groups | 56 | 57.78 |
Each dataset contributes its main metric to the overall average. For retrieval, the main metric is nDCG@10, which rewards putting relevant documents near the top of the first ten results. For semantic textual similarity it is the Spearman correlation between cosine scores and human similarity ratings. The summarization task asks how well embedding comparisons predict human ratings of summaries that have already been written. These score scales answer different questions. [20]
Comparison with other Sentence Transformers models
On the same 56 datasets, all-MiniLM-L12-v2 averaged 56.53 and all-MiniLM-L6-v2 averaged 56.26. The project documentation describes the six-layer MiniLM checkpoint as about five times faster than this MPNet model in its comparison of the original general-purpose models. MiniLM-L6 also returns 384 numbers per embedding. At the same numerical precision, a collection of its raw vectors occupies half the space of the corresponding 768-dimensional MPNet vectors. [12][20][21]
The benchmark also illustrates how a choice can depend on the task. In the original English evaluation, MPNet scored 80.28 on semantic textual similarity and 43.81 on retrieval. GTR-Base scored 77.07 and 44.67 on those same groups. For a search application, results on queries and passages resembling the intended collection give a more direct test than the average across all seven groups. [12][20]
Use cases and limitations
In semantic search, the encoder can represent a query and each passage separately, then return the passages with the highest similarity. A vector database can store the vectors with references to the original passages. A retrieval-augmented generation system can pass the selected text to a separate language model. A question-answer index, for example, can rank the passages that might contain an answer before any answer text is generated. [1][2][22][23]
The same scoring operation supports paraphrase mining and FAQ matching. Encoding questions in advance allows a new question to be compared with the collection using only one additional encoder pass. For clustering, the downstream algorithm groups points in the embedding space. In both settings a score close to 1 describes the direction of two vectors. Because the training data contains replies and citations as well as paraphrases, a high score alone does not establish that two statements mean exactly the same thing. [1][2][5][16]
The intended unit is a sentence or short paragraph. When indexing a long article, a search system can split it into passages and record the source article with each vector. This lets a fact in a later paragraph participate in retrieval even when it falls beyond the first 384 tokens of the article. The library's retrieve-and-rerank example follows this approach with Wikipedia paragraphs. A second-stage cross-encoder reads each shortlisted query and passage together, which lets tokens in the query attend directly to tokens in that candidate. [1][10][22]
The checkpoint card identifies English as its language. The similarly named paraphrase-multilingual-mpnet-base-v2 is a separate multilingual checkpoint. The original MTEB study evaluated both models in separate rows. Interchanging the names when reproducing a benchmark or building a multilingual index changes the model being tested. [1][12][20]
Continue reading
- Sentence-BERT (SBERT)Sentence-BERT (SBERT) is a modification of the pretrained BERT transformer network that produces semantically meaningful, fixed-size sentence embeddings comparable with simple cosine similarity.Listed in See also
- Contrastive LearningContrastive learning is a family of machine learning methods that learn representations by pulling similar (positive) pairs of data points closer together in an embedding space while pushing dissimilar…Listed in See also
- Retrieval-Augmented GenerationRetrieval-augmented generation (RAG) is a family of methods that retrieves information from an external collection and conditions a generative model on that information when producing an output.Listed in See also
- Sentence Similarity ModelsSentence similarity models are machine learning systems that map natural language sentences to fixed-length numerical vectors (sentence embeddings) so that semantically related sentences sit close together in…Listed in See also
- Feature ExtractionFeature extraction is the process of transforming raw data into a smaller set of derived, informative numerical variables called features that capture the essential structure of the input while discarding…Listed in See also
- Cosine similarityCosine similarity is a measure of similarity between two non-zero vectors that calculates the cosine of the angle between them, defined as the dot product of the vectors divided by the product of their…Mentioned 3 times above
More from See also
More to read
References
- ^1 ^2 ^3 ^4 ^5 ^6 ^7 ^8 ^9 ^10 ^11 ^12 ^13 ^14 ^15 ^16 ^17 ^18 ^19 ^20 ^21 ^22 ^23 ^24 ^25 ^26 ^27 ^28 ^29 ^30Sentence Transformers. all-mpnet-base-v2 model card, training inventory and examples. Hugging Face Hub.
- ^1 ^2 ^3 ^4Nils Reimers and Iryna Gurevych. Sentence-BERT: Sentence Embeddings using Siamese BERT-Networks. EMNLP-IJCNLP, 2019.
- ^Nils Reimers. Initial upload of the all-mpnet-base-v2 weights and configuration. Hugging Face Hub, August 30, 2021.
- ^1 ^2 ^3 ^4 ^5Microsoft. mpnet-base model card. Hugging Face Hub.
- ^1 ^2 ^3 ^4 ^5 ^6 ^7 ^8 ^9Antoine Simoulin. Train a Sentence Embedding Model with 1 Billion Training Pairs. Hugging Face, October 25, 2021.
- ^1 ^2 ^3 ^4 ^5 ^6 ^7 ^8 ^9Sentence Transformers. MPNet encoder configuration. Hugging Face Hub.
- ^1 ^2 ^3 ^4 ^5 ^6Sentence Transformers. Pooling configuration. Hugging Face Hub.
- ^1 ^2 ^3 ^4 ^5Sentence Transformers. Ordered module definitions for all-mpnet-base-v2. Hugging Face Hub.
- ^1 ^2 ^3Hugging Face Hub. Checkpoint metadata, published files and Safetensors parameter count.
- ^1 ^2 ^3 ^4 ^5Sentence Transformers. Sequence-length configuration. Hugging Face Hub.
- ^1 ^2Kaitao Song, Xu Tan, Tao Qin, Jianfeng Lu, and Tie-Yan Liu. MPNet: Masked and Permuted Pre-training for Language Understanding. NeurIPS, 2020.
- ^1 ^2 ^3 ^4Sentence Transformers. Pretrained Models. Documentation, section on original models.
- ^Tom Aarsen. Sentence Transformers is joining Hugging Face!. Hugging Face, October 22, 2025.
- ^1 ^2 ^3Sentence Transformers. MPNet tokenizer configuration. Hugging Face Hub.
- ^1 ^2Hugging Face Transformers. MPNet tokenizer and model documentation.
- ^1 ^2 ^3 ^4Sentence Transformers. Semantic Textual Similarity. Documentation, section on similarity calculation.
- ^1 ^2 ^3 ^4 ^5 ^6 ^7 ^8 ^9 ^10 ^11 ^12 ^13Sentence Transformers. Training script and recorded command. Hugging Face Hub.
- ^1 ^2Sentence Transformers. Training-data file counts and sampling weights. Hugging Face Hub.
- ^Hugging Face Hub. Download files from the Hub. Hub client documentation.
- ^1 ^2 ^3 ^4 ^5Niklas Muennighoff, Nouamane Tazi, Loïc Magne, and Nils Reimers. MTEB: Massive Text Embedding Benchmark. EACL, 2023, tables 1 and 10.
- ^Sentence Transformers. all-MiniLM-L6-v2 model card. Hugging Face Hub.
- ^1 ^2Sentence Transformers. Retrieve & Re-Rank. Documentation, Simple English Wikipedia example.
- ^Patrick Lewis and colleagues. Retrieval-Augmented Generation for Knowledge-Intensive NLP Tasks. NeurIPS, 2020.
Improve this article
Add missing citations, update stale details, or write a clearer explanation. Anyone can edit: changes go live when you publish, and every edit is checked by an editor.
7 revisions · v7 · 2,976 words · full history
Fact-checks are independent of edits: a reviewer re-verifies the article against its sources and stamps the date. How we verify
Research and drafting on this wiki are AI-assisted, under named human editorial standards. How AI is used here
Cite this page: AI Wiki. "Sentence-transformers/all-mpnet-base-v2 model." aiwiki.ai, updated 1 Dec 2026. CC BY 4.0. https://aiwiki.ai/wiki/sentence-transformers_all-mpnet-base-v2_model



