sentence-transformers/all-nli
Viewer • Updated • 2.86M • 3.03k • 51
How to use kwondw/mpnet-base-all-nli-triplet with sentence-transformers:
from sentence_transformers import SentenceTransformer
model = SentenceTransformer("kwondw/mpnet-base-all-nli-triplet")
sentences = [
"A man is jumping unto his filthy bed.",
"A young male is looking at a newspaper while 2 females walks past him.",
"The bed is dirty.",
"The man is on the moon."
]
embeddings = model.encode(sentences)
similarities = model.similarity(embeddings, embeddings)
print(similarities.shape)
# [4, 4]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 retrieval.
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})
)
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("kwondw/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.5718, 0.5598],
# [0.5718, 1.0000, 0.5422],
# [0.5598, 0.5422, 1.0000]])
all-nli-devTripletEvaluator| Metric | Value |
|---|---|
| cosine_accuracy | 0.9154 |
anchor, positive, and negative| anchor | positive | negative | |
|---|---|---|---|
| type | string | string | string |
| modality | text | text | text |
| details |
|
|
|
| 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 camera |
There are children present |
The kids are frowning |
A boy is jumping on skateboard in the middle of a red bridge. |
The boy does a skateboarding trick. |
The boy skates down the sidewalk. |
MultipleNegativesRankingLoss with 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
}
anchor, positive, and negative| anchor | positive | negative | |
|---|---|---|---|
| type | string | string | string |
| modality | text | text | text |
| details |
|
|
|
| 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 Angeles |
A man selling donuts to a customer. |
A woman drinks her coffee in a small cafe. |
MultipleNegativesRankingLoss with 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
}
per_device_train_batch_size: 16num_train_epochs: 1learning_rate: 2e-05warmup_steps: 0.1fp16: Trueper_device_eval_batch_size: 16batch_sampler: no_duplicatesper_device_train_batch_size: 16num_train_epochs: 1max_steps: -1learning_rate: 2e-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: Noneremove_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: Nonewarmup_ratio: Nonelocal_rank: -1prompts: Nonebatch_sampler: no_duplicatesmulti_dataset_batch_sampler: proportionalrouter_mapping: {}learning_rate_mapping: {}| Epoch | Step | Training Loss | Validation Loss | all-nli-dev_cosine_accuracy |
|---|---|---|---|---|
| -1 | -1 | - | - | 0.6211 |
| 0.016 | 100 | 3.1300 | 1.4117 | 0.7506 |
| 0.032 | 200 | 1.5028 | 0.7034 | 0.8044 |
| 0.048 | 300 | 1.1036 | 0.6180 | 0.8247 |
| 0.064 | 400 | 1.0011 | 0.6082 | 0.8253 |
| 0.08 | 500 | 0.9326 | 0.5667 | 0.8372 |
| 0.096 | 600 | 0.9038 | 0.5407 | 0.8501 |
| 0.112 | 700 | 0.8183 | 0.5173 | 0.8548 |
| 0.128 | 800 | 0.8704 | 0.5138 | 0.8638 |
| 0.144 | 900 | 0.8125 | 0.4933 | 0.8688 |
| 0.16 | 1000 | 0.7368 | 0.4607 | 0.8770 |
| 0.176 | 1100 | 0.6957 | 0.4930 | 0.8806 |
| 0.192 | 1200 | 0.7251 | 0.4160 | 0.8972 |
| 0.208 | 1300 | 0.6322 | 0.4211 | 0.8931 |
| 0.224 | 1400 | 0.6312 | 0.4382 | 0.8893 |
| 0.24 | 1500 | 0.6207 | 0.4303 | 0.8872 |
| 0.256 | 1600 | 0.5900 | 0.4217 | 0.8903 |
| 0.272 | 1700 | 0.5724 | 0.4101 | 0.8978 |
| 0.288 | 1800 | 0.6214 | 0.3930 | 0.9049 |
| 0.304 | 1900 | 0.6223 | 0.3848 | 0.9007 |
| 0.32 | 2000 | 0.5789 | 0.3959 | 0.8998 |
| 0.336 | 2100 | 0.5334 | 0.3794 | 0.9033 |
| 0.352 | 2200 | 0.4986 | 0.3804 | 0.8988 |
| 0.368 | 2300 | 0.5138 | 0.3787 | 0.9026 |
| 0.384 | 2400 | 0.5372 | 0.3827 | 0.9048 |
| 0.4 | 2500 | 0.5093 | 0.3773 | 0.9029 |
| 0.416 | 2600 | 0.4898 | 0.3765 | 0.9034 |
| 0.432 | 2700 | 0.5248 | 0.3842 | 0.9040 |
| 0.448 | 2800 | 0.5014 | 0.3754 | 0.9067 |
| 0.464 | 2900 | 0.4801 | 0.3785 | 0.9034 |
| 0.48 | 3000 | 0.4678 | 0.3668 | 0.9074 |
| 0.496 | 3100 | 0.4869 | 0.3606 | 0.9067 |
| 0.512 | 3200 | 0.4709 | 0.3712 | 0.9069 |
| 0.528 | 3300 | 0.4705 | 0.3737 | 0.9036 |
| 0.544 | 3400 | 0.4548 | 0.3696 | 0.9014 |
| 0.56 | 3500 | 0.4678 | 0.3558 | 0.9075 |
| 0.576 | 3600 | 0.4083 | 0.3563 | 0.9104 |
| 0.592 | 3700 | 0.4366 | 0.3588 | 0.9086 |
| 0.608 | 3800 | 0.4224 | 0.3540 | 0.9101 |
| 0.624 | 3900 | 0.4056 | 0.3549 | 0.9108 |
| 0.64 | 4000 | 0.3687 | 0.3543 | 0.9119 |
| 0.656 | 4100 | 0.3982 | 0.3518 | 0.9078 |
| 0.672 | 4200 | 0.4383 | 0.3477 | 0.9099 |
| 0.688 | 4300 | 0.4362 | 0.3443 | 0.9140 |
| 0.704 | 4400 | 0.3842 | 0.3491 | 0.9134 |
| 0.72 | 4500 | 0.4117 | 0.3441 | 0.9098 |
| 0.736 | 4600 | 0.3886 | 0.3440 | 0.9128 |
| 0.752 | 4700 | 0.3776 | 0.3450 | 0.9157 |
| 0.768 | 4800 | 0.4158 | 0.3397 | 0.9119 |
| 0.784 | 4900 | 0.3924 | 0.3408 | 0.9125 |
| 0.8 | 5000 | 0.3763 | 0.3425 | 0.9121 |
| 0.816 | 5100 | 0.3689 | 0.3428 | 0.9134 |
| 0.832 | 5200 | 0.4122 | 0.3415 | 0.9130 |
| 0.848 | 5300 | 0.3442 | 0.3377 | 0.9142 |
| 0.864 | 5400 | 0.3567 | 0.3342 | 0.9142 |
| 0.88 | 5500 | 0.3597 | 0.3383 | 0.9136 |
| 0.896 | 5600 | 0.3571 | 0.3351 | 0.9145 |
| 0.912 | 5700 | 0.3519 | 0.3332 | 0.9143 |
| 0.928 | 5800 | 0.3305 | 0.3323 | 0.9145 |
| 0.944 | 5900 | 0.4017 | 0.3317 | 0.9145 |
| 0.96 | 6000 | 0.3943 | 0.3322 | 0.9140 |
| 0.976 | 6100 | 0.3530 | 0.3320 | 0.9149 |
| 0.992 | 6200 | 0.1762 | 0.3319 | 0.9154 |
@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",
}
@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},
}
Base model
microsoft/mpnet-base