Sentence-BERT: Sentence Embeddings using Siamese BERT-Networks
Paper • 1908.10084 • Published • 17
How to use Shailu1492/roberta-base-mnrl-snli with sentence-transformers:
from sentence_transformers import SentenceTransformer
model = SentenceTransformer("Shailu1492/roberta-base-mnrl-snli")
sentences = [
"A man with sunglasses on is dancing in the casino",
"A man with sunglasses on is dancing in the casino",
"The lady in blue sweater with her breast showing walking in a busy street fanning.",
"The fresh pork is cut into bellies and scored to make it easier to cook and serve."
]
embeddings = model.encode(sentences)
similarities = model.similarity(embeddings, embeddings)
print(similarities.shape)
# [4, 4]This is a sentence-transformers model finetuned from FacebookAI/roberta-base. 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': 'RobertaModel'})
(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("Shailu1492/roberta-base-mnrl-snli")
# Run inference
sentences = [
"It's very cold at the top of the mountains, where the peaks are covered by clouds.",
"It's very cold at the top of the mountains, where the peaks are covered by clouds.",
'The man is organizing.',
]
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, 1.0000, -0.0760],
# [ 1.0000, 1.0000, -0.0760],
# [-0.0760, -0.0760, 1.0000]])
stsb_validEmbeddingSimilarityEvaluator| Metric | Value |
|---|---|
| pearson_cosine | 0.7302 |
| spearman_cosine | 0.7308 |
anchor and positive| anchor | positive | |
|---|---|---|
| type | string | string |
| modality | text | text |
| details |
|
|
| anchor | positive |
|---|---|
They wanted to make the neighborhood feel like a community. |
They wanted to make the neighborhood feel like a community. |
The procedures will block foreign corporations from offering satellite coverage. |
The procedures will block foreign corporations from offering satellite coverage. |
Wayne starred in over 50 films. |
Wayne starred in over 50 films. |
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: 128num_train_epochs: 4learning_rate: 2e-05bf16: Truedataloader_drop_last: Trueper_device_train_batch_size: 128num_train_epochs: 4max_steps: -1learning_rate: 2e-05lr_scheduler_type: linearlr_scheduler_kwargs: Nonewarmup_steps: 0optim: 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: Truefp16: Falsebf16_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: 8prediction_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: Truedataloader_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: batch_samplermulti_dataset_batch_sampler: proportionalrouter_mapping: {}learning_rate_mapping: {}| Epoch | Step | Training Loss | stsb_valid_spearman_cosine |
|---|---|---|---|
| 0.0557 | 500 | 0.0375 | 0.8074 |
| 0.1115 | 1000 | 0.0001 | 0.7911 |
| 0.1672 | 1500 | 0.0001 | 0.7826 |
| 0.2230 | 2000 | 0.0001 | 0.7695 |
| 0.2787 | 2500 | 0.0001 | 0.8121 |
| 0.3345 | 3000 | 0.0001 | 0.7634 |
| 0.3902 | 3500 | 0.0000 | 0.7860 |
| 0.4460 | 4000 | 0.0000 | 0.7601 |
| 0.5017 | 4500 | 0.0000 | 0.7915 |
| 0.5575 | 5000 | 0.0001 | 0.7655 |
| 0.6132 | 5500 | 0.0001 | 0.7542 |
| 0.6690 | 6000 | 0.0000 | 0.7636 |
| 0.7247 | 6500 | 0.0000 | 0.7467 |
| 0.7805 | 7000 | 0.0001 | 0.7563 |
| 0.8362 | 7500 | 0.0001 | 0.7610 |
| 0.8920 | 8000 | 0.0000 | 0.7314 |
| 0.9477 | 8500 | 0.0001 | 0.7707 |
| 1.0035 | 9000 | 0.0000 | 0.7652 |
| 1.0592 | 9500 | 0.0000 | 0.7541 |
| 1.1150 | 10000 | 0.0000 | 0.7655 |
| 1.1707 | 10500 | 0.0001 | 0.7720 |
| 1.2264 | 11000 | 0.0000 | 0.7621 |
| 1.2822 | 11500 | 0.0000 | 0.7576 |
| 1.3379 | 12000 | 0.0000 | 0.7665 |
| 1.3937 | 12500 | 0.0000 | 0.7597 |
| 1.4494 | 13000 | 0.0000 | 0.7707 |
| 1.5052 | 13500 | 0.0000 | 0.7537 |
| 1.5609 | 14000 | 0.0000 | 0.7520 |
| 1.6167 | 14500 | 0.0000 | 0.7574 |
| 1.6724 | 15000 | 0.0000 | 0.7627 |
| 1.7282 | 15500 | 0.0000 | 0.7549 |
| 1.7839 | 16000 | 0.0000 | 0.7633 |
| 1.8397 | 16500 | 0.0000 | 0.7574 |
| 1.8954 | 17000 | 0.0000 | 0.7517 |
| 1.9512 | 17500 | 0.0000 | 0.7307 |
| 2.0069 | 18000 | 0.0000 | 0.7356 |
| 2.0627 | 18500 | 0.0000 | 0.7378 |
| 2.1184 | 19000 | 0.0000 | 0.7537 |
| 2.1742 | 19500 | 0.0000 | 0.7442 |
| 2.2299 | 20000 | 0.0000 | 0.7421 |
| 2.2857 | 20500 | 0.0000 | 0.7517 |
| 2.3414 | 21000 | 0.0000 | 0.7494 |
| 2.3971 | 21500 | 0.0000 | 0.7513 |
| 2.4529 | 22000 | 0.0000 | 0.7463 |
| 2.5086 | 22500 | 0.0000 | 0.7458 |
| 2.5644 | 23000 | 0.0000 | 0.7259 |
| 2.6201 | 23500 | 0.0000 | 0.7337 |
| 2.6759 | 24000 | 0.0000 | 0.7330 |
| 2.7316 | 24500 | 0.0000 | 0.7306 |
| 2.7874 | 25000 | 0.0000 | 0.7317 |
| 2.8431 | 25500 | 0.0000 | 0.7285 |
| 2.8989 | 26000 | 0.0000 | 0.7301 |
| 2.9546 | 26500 | 0.0000 | 0.7220 |
| 3.0104 | 27000 | 0.0000 | 0.7302 |
| 3.0661 | 27500 | 0.0000 | 0.7239 |
| 3.1219 | 28000 | 0.0000 | 0.7233 |
| 3.1776 | 28500 | 0.0000 | 0.7360 |
| 3.2334 | 29000 | 0.0000 | 0.7152 |
| 3.2891 | 29500 | 0.0000 | 0.7298 |
| 3.3449 | 30000 | 0.0000 | 0.7323 |
| 3.4006 | 30500 | 0.0000 | 0.7183 |
| 3.4563 | 31000 | 0.0000 | 0.7277 |
| 3.5121 | 31500 | 0.0000 | 0.7300 |
| 3.5678 | 32000 | 0.0000 | 0.7332 |
| 3.6236 | 32500 | 0.0000 | 0.7384 |
| 3.6793 | 33000 | 0.0000 | 0.7375 |
| 3.7351 | 33500 | 0.0000 | 0.7363 |
| 3.7908 | 34000 | 0.0000 | 0.7358 |
| 3.8466 | 34500 | 0.0000 | 0.7333 |
| 3.9023 | 35000 | 0.0000 | 0.7314 |
| 3.9581 | 35500 | 0.0000 | 0.7309 |
| 4.0 | 35876 | - | 0.7308 |
@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
FacebookAI/roberta-base