Citation and evidence

Sentence-transformers/all-mpnet-base-v2 model

Report a problem with this article

Edit article
More

Use this article

Raw MarkdownExplore connections

Improve this page

Revision historyDiscuss this article

Topics

AI ModelsNatural Language ProcessingOpen Source AI

Cite this article

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

FieldPublished specification
Base checkpointmicrosoft/mpnet-base [1][4]
Model familyGeneral-purpose English sentence encoders from the 2021 Hugging Face community project [1][5]
ArchitectureMPNet encoder, mean pooling, and vector normalization [6][7][8]
ParametersApproximately 110 million [9]
OutputOne 768-dimensional vector per sentence or passage [1][7]
Default input limit384 tokens per encoded sequence [10]
Published formatsPyTorch weights, Safetensors weights, ONNX exports, and OpenVINO exports [9]
LicenseApache 2.0 [1]

Expanded article table

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]

ComponentCheckpoint setting
Transformer layers12 [6]
Hidden size768 [6]
Attention heads per layer12 [6]
Feed-forward intermediate size3,072 [6]
Position embedding table514 entries [6]
Vocabulary30,527 entries [6]
TokenizerLowercasing MPNet WordPiece tokenizer [14][15]
Sentence poolingMean of the unpadded token representations [1][7]
Final moduleL2 normalization [1][8]

Expanded article table

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]

SettingReported value
OptimizerAdamW [1][17]
Learning rate0.00002 [1][17]
Learning-rate warmup500 steps [1][17]
Maximum training sequence length128 tokens [1][17]
Model card's training schedule100,000 steps with 1,024 examples per batch, 128 per TPU core [1]
Invocation recorded in the training script1,000,000 requested steps with 64 examples per process, or 512 across the default eight processes [17]

Expanded article table

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 relationTraining tuples
Reddit comments, 2015-2018726,484,430
S2ORC citation-linked abstracts116,288,806
WikiAnswers duplicate questions77,427,422
PAQ question and answer64,371,441
S2ORC citation-linked titles52,603,982
S2ORC title and abstract41,769,185
Stack Exchange title and body25,316,456
Stack Exchange title plus body and answer21,396,559
Stack Exchange title and answer21,396,559
MS MARCO triplets9,144,553
GOOAQ3,012,496
Amazon question-answer pairs2,448,839
Yahoo Answers title and answer1,198,260
Code Search1,151,414
COCO captions828,395
SPECTER citation triplets684,100
Yahoo Answers question and answer681,164
Yahoo Answers title and question659,896
SearchQA582,261
ELI5325,475
Flickr30k captions317,695
Stack Exchange duplicate question titles304,525
AllNLI, from SNLI and MultiNLI277,230
Stack Exchange duplicate question bodies250,519
Stack Exchange duplicate question titles plus bodies250,460
Sentence Compression180,000
WikiHow128,542
AltLex112,696
Quora question triplets103,663
Simple Wikipedia102,225
Natural Questions100,231
SQuAD 2.087,599
TriviaQA73,346
Total1,170,060,424

Expanded article table

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 groupEnglish datasetsPublished score
Classification1265.07
Clustering1143.69
Pair classification383.04
Reranking459.36
Retrieval1543.81
Semantic textual similarity1080.28
Summarization evaluation127.49
All groups5657.78

Expanded article table

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

More from See also

More to read

Topics:AI ModelsNatural Language ProcessingOpen Source AI

References

  1. ^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.
  2. ^1 ^2 ^3 ^4Nils Reimers and Iryna Gurevych. Sentence-BERT: Sentence Embeddings using Siamese BERT-Networks. EMNLP-IJCNLP, 2019.
  3. ^Nils Reimers. Initial upload of the all-mpnet-base-v2 weights and configuration. Hugging Face Hub, August 30, 2021.
  4. ^1 ^2 ^3 ^4 ^5Microsoft. mpnet-base model card. Hugging Face Hub.
  5. ^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.
  6. ^1 ^2 ^3 ^4 ^5 ^6 ^7 ^8 ^9Sentence Transformers. MPNet encoder configuration. Hugging Face Hub.
  7. ^1 ^2 ^3 ^4 ^5 ^6Sentence Transformers. Pooling configuration. Hugging Face Hub.
  8. ^1 ^2 ^3 ^4 ^5Sentence Transformers. Ordered module definitions for all-mpnet-base-v2. Hugging Face Hub.
  9. ^1 ^2 ^3Hugging Face Hub. Checkpoint metadata, published files and Safetensors parameter count.
  10. ^1 ^2 ^3 ^4 ^5Sentence Transformers. Sequence-length configuration. Hugging Face Hub.
  11. ^1 ^2Kaitao Song, Xu Tan, Tao Qin, Jianfeng Lu, and Tie-Yan Liu. MPNet: Masked and Permuted Pre-training for Language Understanding. NeurIPS, 2020.
  12. ^1 ^2 ^3 ^4Sentence Transformers. Pretrained Models. Documentation, section on original models.
  13. ^Tom Aarsen. Sentence Transformers is joining Hugging Face!. Hugging Face, October 22, 2025.
  14. ^1 ^2 ^3Sentence Transformers. MPNet tokenizer configuration. Hugging Face Hub.
  15. ^1 ^2Hugging Face Transformers. MPNet tokenizer and model documentation.
  16. ^1 ^2 ^3 ^4Sentence Transformers. Semantic Textual Similarity. Documentation, section on similarity calculation.
  17. ^1 ^2 ^3 ^4 ^5 ^6 ^7 ^8 ^9 ^10 ^11 ^12 ^13Sentence Transformers. Training script and recorded command. Hugging Face Hub.
  18. ^1 ^2Sentence Transformers. Training-data file counts and sampling weights. Hugging Face Hub.
  19. ^Hugging Face Hub. Download files from the Hub. Hub client documentation.
  20. ^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.
  21. ^Sentence Transformers. all-MiniLM-L6-v2 model card. Hugging Face Hub.
  22. ^1 ^2Sentence Transformers. Retrieve & Re-Rank. Documentation, Simple English Wikipedia example.
  23. ^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

Edit article