MPNet base trained on AllNLI triplets
This is a sentence-transformers model finetuned from microsoft/mpnet-base on the all-nli dataset. It maps sentences & paragraphs to a 768-dimensional dense vector space and can be used for semantic textual similarity, semantic search, paraphrase mining, classification, clustering, and more.
Model Details
Model Description
- Model Type: Sentence Transformer
- Base model: microsoft/mpnet-base
- Maximum Sequence Length: 512 tokens
- Output Dimensionality: 768 dimensions
- Similarity Function: Cosine Similarity
- Supported Modality: Text
- Training Dataset:
- all-nli
- Language: en
- License: apache-2.0
Model Sources
- Documentation: Sentence Transformers Documentation
- Repository: Sentence Transformers on GitHub
- Hugging Face: Sentence Transformers on Hugging Face
Full Model Architecture
SentenceTransformer(
(0): Transformer({'transformer_task': 'feature-extraction', 'modality_config': {'text': {'method': 'forward', 'method_output_name': 'last_hidden_state'}}, 'module_output_name': 'token_embeddings', 'architecture': 'MPNetModel'})
(1): Pooling({'embedding_dimension': 768, 'pooling_mode': 'mean', 'include_prompt': True})
)
Usage
Direct Usage (Sentence Transformers)
First install the Sentence Transformers library:
pip install -U sentence-transformers
Then you can load this model and run inference.
from sentence_transformers import SentenceTransformer
# Download from the 🤗 Hub
model = SentenceTransformer("kokitabayashi/mpnet-base-all-nli-triplet")
# Run inference
sentences = [
'A construction worker peeking out of a manhole while his coworker sits on the sidewalk smiling.',
'A worker is looking out of a manhole.',
'The workers are both inside the manhole.',
]
embeddings = model.encode(sentences)
print(embeddings.shape)
# [3, 768]
# Get the similarity scores for the embeddings
similarities = model.similarity(embeddings, embeddings)
print(similarities)
# tensor([[1.0000, 0.5627, 0.4903],
# [0.5627, 1.0000, 0.5322],
# [0.4903, 0.5322, 1.0000]])
Evaluation
Metrics
Triplet
- Datasets:
all-nli-devandall-nli-test - Evaluated with
TripletEvaluator
| Metric | all-nli-dev | all-nli-test |
|---|---|---|
| cosine_accuracy | 0.9148 | 0.9277 |
Training Details
Training Dataset
all-nli
- Dataset: all-nli
- Size: 100,000 training samples
- Columns:
anchor,positive, andnegative - Approximate statistics based on the first 100 samples:
anchor positive negative type string string string modality text text text details - min: 8 tokens
- mean: 14.59 tokens
- max: 30 tokens
- min: 6 tokens
- mean: 13.96 tokens
- max: 28 tokens
- min: 5 tokens
- mean: 15.1 tokens
- max: 30 tokens
- Samples:
anchor positive negative A person on a horse jumps over a broken down airplane.A person is outdoors, on a horse.A person is at a diner, ordering an omelette.Children smiling and waving at cameraThere are children presentThe kids are frowningA boy is jumping on skateboard in the middle of a red bridge.The boy does a skateboarding trick.The boy skates down the sidewalk. - Loss:
MultipleNegativesRankingLosswith these parameters:{ "scale": 20.0, "similarity_fct": "cos_sim", "gather_across_devices": false, "directions": [ "query_to_doc" ], "partition_mode": "joint", "hardness_mode": null, "hardness_strength": 0.0 }
Evaluation Dataset
all-nli
- Dataset: all-nli
- Size: 6,584 evaluation samples
- Columns:
anchor,positive, andnegative - Approximate statistics based on the first 100 samples:
anchor positive negative type string string string modality text text text details - min: 7 tokens
- mean: 17.57 tokens
- max: 36 tokens
- min: 5 tokens
- mean: 9.98 tokens
- max: 28 tokens
- min: 5 tokens
- mean: 10.38 tokens
- max: 18 tokens
- Samples:
anchor positive negative Two women are embracing while holding to go packages.Two woman are holding packages.The men are fighting outside a deli.Two young children in blue jerseys, one with the number 9 and one with the number 2 are standing on wooden steps in a bathroom and washing their hands in a sink.Two kids in numbered jerseys wash their hands.Two kids in jackets walk to school.A man selling donuts to a customer during a world exhibition event held in the city of AngelesA man selling donuts to a customer.A woman drinks her coffee in a small cafe. - Loss:
MultipleNegativesRankingLosswith these parameters:{ "scale": 20.0, "similarity_fct": "cos_sim", "gather_across_devices": false, "directions": [ "query_to_doc" ], "partition_mode": "joint", "hardness_mode": null, "hardness_strength": 0.0 }
Training Hyperparameters
Non-Default Hyperparameters
per_device_train_batch_size: 16num_train_epochs: 1warmup_steps: 0.1fp16: Trueper_device_eval_batch_size: 16batch_sampler: no_duplicates
All Hyperparameters
Click to expandper_device_train_batch_size: 16num_train_epochs: 1max_steps: -1learning_rate: 5e-05lr_scheduler_type: linearlr_scheduler_kwargs: Nonewarmup_steps: 0.1optim: adamw_torch_fusedoptim_args: Noneweight_decay: 0.0adam_beta1: 0.9adam_beta2: 0.999adam_epsilon: 1e-08optim_target_modules: Nonegradient_accumulation_steps: 1average_tokens_across_devices: Truemax_grad_norm: 1.0label_smoothing_factor: 0.0bf16: Falsefp16: Truebf16_full_eval: Falsefp16_full_eval: Falsetf32: Nonegradient_checkpointing: Falsegradient_checkpointing_kwargs: Nonetorch_compile: Falsetorch_compile_backend: Nonetorch_compile_mode: Noneuse_liger_kernel: Falseliger_kernel_config: Noneuse_cache: Falseneftune_noise_alpha: Nonetorch_empty_cache_steps: Noneauto_find_batch_size: Falselog_on_each_node: Truelogging_nan_inf_filter: Trueinclude_num_input_tokens_seen: nolog_level: passivelog_level_replica: warningdisable_tqdm: Falseproject: huggingfacetrackio_space_id: Nonetrackio_bucket_id: Nonetrackio_static_space_id: Noneper_device_eval_batch_size: 16prediction_loss_only: Trueeval_on_start: Falseeval_do_concat_batches: Trueeval_use_gather_object: Falseeval_accumulation_steps: Noneinclude_for_metrics: []batch_eval_metrics: Falsesave_only_model: Falsesave_on_each_node: Falseenable_jit_checkpoint: Falsepush_to_hub: Falsehub_private_repo: Nonehub_model_id: Nonehub_strategy: every_savehub_always_push: Falsehub_revision: Noneload_best_model_at_end: Falseignore_data_skip: Falserestore_callback_states_from_checkpoint: Falsefull_determinism: Falseseed: 42data_seed: Noneuse_cpu: Falseaccelerator_config: {'split_batches': False, 'dispatch_batches': None, 'even_batches': True, 'use_seedable_sampler': True, 'non_blocking': False, 'gradient_accumulation_kwargs': None}parallelism_config: Nonedataloader_drop_last: Falsedataloader_num_workers: 0dataloader_pin_memory: Truedataloader_persistent_workers: Falsedataloader_prefetch_factor: Nonedataloader_multiprocessing_context: Nonedataloader_in_order: Trueremove_unused_columns: Truelabel_names: Nonetrain_sampling_strategy: randomlength_column_name: lengthddp_find_unused_parameters: Noneddp_bucket_cap_mb: Noneddp_broadcast_buffers: Falseddp_static_graph: Noneddp_backend: Noneddp_timeout: 1800fsdp: Nonefsdp_config: Nonedeepspeed: Nonedebug: []skip_memory_metrics: Truedo_predict: Falseresume_from_checkpoint: Nonelocal_rank: -1prompts: Nonebatch_sampler: no_duplicatesmulti_dataset_batch_sampler: proportionalrouter_mapping: {}learning_rate_mapping: {}warmup_ratio: None
Training Logs
| Epoch | Step | Training Loss | Validation Loss | all-nli-dev_cosine_accuracy | all-nli-test_cosine_accuracy |
|---|---|---|---|---|---|
| -1 | -1 | - | - | 0.6211 | - |
| 0.016 | 100 | 2.6314 | 0.8039 | 0.7934 | - |
| 0.032 | 200 | 1.1723 | 0.6012 | 0.8261 | - |
| 0.048 | 300 | 0.9531 | 0.5721 | 0.8410 | - |
| 0.064 | 400 | 0.9413 | 0.5973 | 0.8492 | - |
| 0.08 | 500 | 0.8828 | 0.5413 | 0.8533 | - |
| 0.096 | 600 | 0.9049 | 0.5252 | 0.8817 | - |
| 0.112 | 700 | 0.8044 | 0.5486 | 0.8656 | - |
| 0.128 | 800 | 0.8473 | 0.5315 | 0.8885 | - |
| 0.144 | 900 | 0.7852 | 0.4986 | 0.8872 | - |
| 0.16 | 1000 | 0.7240 | 0.4632 | 0.8984 | - |
| 0.176 | 1100 | 0.7091 | 0.5730 | 0.8776 | - |
| 0.192 | 1200 | 0.7190 | 0.4791 | 0.8824 | - |
| 0.208 | 1300 | 0.6759 | 0.4487 | 0.8879 | - |
| 0.224 | 1400 | 0.6142 | 0.4760 | 0.8861 | - |
| 0.24 | 1500 | 0.6174 | 0.4568 | 0.8941 | - |
| 0.256 | 1600 | 0.5711 | 0.4768 | 0.8823 | - |
| 0.272 | 1700 | 0.5712 | 0.4612 | 0.8940 | - |
| 0.288 | 1800 | 0.6068 | 0.4424 | 0.8998 | - |
| 0.304 | 1900 | 0.6044 | 0.4528 | 0.8931 | - |
| 0.32 | 2000 | 0.5651 | 0.4495 | 0.8879 | - |
| 0.336 | 2100 | 0.5131 | 0.4218 | 0.8932 | - |
| 0.352 | 2200 | 0.4761 | 0.4170 | 0.8963 | - |
| 0.368 | 2300 | 0.5232 | 0.4702 | 0.8955 | - |
| 0.384 | 2400 | 0.5334 | 0.4402 | 0.8981 | - |
| 0.4 | 2500 | 0.4902 | 0.4122 | 0.9064 | - |
| 0.416 | 2600 | 0.4758 | 0.4281 | 0.8985 | - |
| 0.432 | 2700 | 0.5149 | 0.4204 | 0.8993 | - |
| 0.448 | 2800 | 0.4827 | 0.4091 | 0.9025 | - |
| 0.464 | 2900 | 0.4671 | 0.4213 | 0.9031 | - |
| 0.48 | 3000 | 0.4279 | 0.4059 | 0.9033 | - |
| 0.496 | 3100 | 0.4475 | 0.4152 | 0.9042 | - |
| 0.512 | 3200 | 0.4425 | 0.4138 | 0.8976 | - |
| 0.528 | 3300 | 0.4280 | 0.4184 | 0.8995 | - |
| 0.544 | 3400 | 0.3937 | 0.3999 | 0.8988 | - |
| 0.56 | 3500 | 0.4064 | 0.3921 | 0.9025 | - |
| 0.576 | 3600 | 0.3750 | 0.3906 | 0.9096 | - |
| 0.592 | 3700 | 0.3741 | 0.3877 | 0.9063 | - |
| 0.608 | 3800 | 0.3874 | 0.3693 | 0.9101 | - |
| 0.624 | 3900 | 0.3556 | 0.3946 | 0.9070 | - |
| 0.64 | 4000 | 0.3488 | 0.3795 | 0.9075 | - |
| 0.656 | 4100 | 0.3638 | 0.4024 | 0.9022 | - |
| 0.672 | 4200 | 0.4250 | 0.3905 | 0.9051 | - |
| 0.688 | 4300 | 0.3812 | 0.3822 | 0.9070 | - |
| 0.704 | 4400 | 0.3419 | 0.3945 | 0.9099 | - |
| 0.72 | 4500 | 0.3347 | 0.3944 | 0.9040 | - |
| 0.736 | 4600 | 0.3440 | 0.3744 | 0.9067 | - |
| 0.752 | 4700 | 0.3251 | 0.4056 | 0.9064 | - |
| 0.768 | 4800 | 0.3411 | 0.3943 | 0.9108 | - |
| 0.784 | 4900 | 0.3115 | 0.3693 | 0.9080 | - |
| 0.8 | 5000 | 0.3129 | 0.3777 | 0.9031 | - |
| 0.816 | 5100 | 0.3130 | 0.3694 | 0.9051 | - |
| 0.832 | 5200 | 0.3354 | 0.3583 | 0.9101 | - |
| 0.848 | 5300 | 0.2678 | 0.3564 | 0.9113 | - |
| 0.864 | 5400 | 0.2989 | 0.3596 | 0.9146 | - |
| 0.88 | 5500 | 0.2750 | 0.3692 | 0.9125 | - |
| 0.896 | 5600 | 0.2772 | 0.3605 | 0.9140 | - |
| 0.912 | 5700 | 0.2766 | 0.3590 | 0.9139 | - |
| 0.928 | 5800 | 0.2631 | 0.3609 | 0.9162 | - |
| 0.944 | 5900 | 0.3205 | 0.3568 | 0.9151 | - |
| 0.96 | 6000 | 0.3228 | 0.3565 | 0.9142 | - |
| 0.976 | 6100 | 0.2673 | 0.3540 | 0.9143 | - |
| 0.992 | 6200 | 0.1322 | 0.3539 | 0.9145 | - |
| 1.0 | 6250 | - | 0.3538 | 0.9148 | - |
| -1 | -1 | - | - | - | 0.9277 |
Training Time
- Training: 19.0 minutes
Framework Versions
- Python: 3.13.16
- Sentence Transformers: 5.7.0
- Transformers: 5.20.2
- PyTorch: 2.11.0+cu130
- Accelerate: 1.15.0
- Datasets: 4.8.5
- Tokenizers: 0.23.3
Additional Resources
- Training and Finetuning Embedding Models with Sentence Transformers: the end-to-end guide for training or finetuning Sentence Transformer models.
- Introduction to Matryoshka Embedding Models: variable-size embeddings that can be truncated with minimal quality loss.
- Binary and Scalar Embedding Quantization for Significantly Faster & Cheaper Retrieval: post-training compression of embedding vectors.
- Multimodal Embedding & Reranker Models with Sentence Transformers: use text, image, audio, and video models through the same API.
- Training and Finetuning Multimodal Embedding & Reranker Models with Sentence Transformers: train multimodal embedding models, with a Visual Document Retrieval walkthrough.
Citation
BibTeX
Sentence Transformers
@inproceedings{reimers-2019-sentence-bert,
title = "Sentence-BERT: Sentence Embeddings using Siamese BERT-Networks",
author = "Reimers, Nils and Gurevych, Iryna",
booktitle = "Proceedings of the 2019 Conference on Empirical Methods in Natural Language Processing",
month = "11",
year = "2019",
publisher = "Association for Computational Linguistics",
url = "https://arxiv.org/abs/1908.10084",
}
MultipleNegativesRankingLoss
@misc{oord2019representationlearningcontrastivepredictive,
title={Representation Learning with Contrastive Predictive Coding},
author={Aaron van den Oord and Yazhe Li and Oriol Vinyals},
year={2019},
eprint={1807.03748},
archivePrefix={arXiv},
primaryClass={cs.LG},
url={https://arxiv.org/abs/1807.03748},
}