Sentence-BERT: Sentence Embeddings using Siamese BERT-Networks
Paper • 1908.10084 • Published • 15
How to use 2ADT-Consulting/susu-sentence-encoder-v1 with sentence-transformers:
from sentence_transformers import SentenceTransformer
model = SentenceTransformer("2ADT-Consulting/susu-sentence-encoder-v1")
sentences = [
"Il leur donna cet ordre: «Vous transmettrez ce message à mon seigneur Esaü: Voici ce que dit ton serviteur Jacob: J'ai séjourné chez Laban et j'y suis resté jusqu'à maintenant.",
"I na fe nde to, i naxa gbata sigafe ra kiiti banxi, barima xa fe gbɛtɛ minima i mu naxan kolon, na nɔma i rayaagide i dɔxɔboore ya xɔri.",
"Wo xa sɔɔrie luxi nɛ alɔ tugumi naxee na tɛtɛ fari gɛɛsɛgɛ, kɔnɔ soge na te, e tugan, e siga yire mixi mu dɛnnaxɛ kolon.",
"A naxa a fala e bɛ, «Wo yi nan falama n marigi Esayu bɛ, ‹I xa konyi di Yaxuba naxɛ, N bara bu Laban xɔnyi han ya."
]
embeddings = model.encode(sentences)
similarities = model.similarity(embeddings, embeddings)
print(similarities.shape)
# [4, 4]This is a sentence-transformers model finetuned from sentence-transformers/paraphrase-multilingual-MiniLM-L12-v2. It maps sentences & paragraphs to a 384-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': 'BertModel'})
(1): Pooling({'embedding_dimension': 384, '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("sentence_transformers_model_id")
# Run inference
sentences = [
'Les navires de Hiram, qui apportèrent de lor dOphir, amenèrent aussi dOphir une grande quantité de bois de sandal et des pierres précieuses.',
'Xirami nun Sulemani xa walikɛe naxee fa xɛɛma ra kelife Ofiri bɔxi ma, nee man naxa fa wuri nun gɛmɛ tofanyie ra.',
'Won a kolon won nun Ala na a ra, barima a bara a Xaxili fi won ma.',
]
embeddings = model.encode(sentences)
print(embeddings.shape)
# [3, 384]
# Get the similarity scores for the embeddings
similarities = model.similarity(embeddings, embeddings)
print(similarities)
# tensor([[1.0000, 0.6592, 0.1617],
# [0.6592, 1.0000, 0.0717],
# [0.1617, 0.0717, 1.0000]])
anchor and positive| anchor | positive | |
|---|---|---|
| type | string | string |
| modality | text | text |
| details |
|
|
| anchor | positive |
|---|---|
He made it according to the instructions that Moses, the Lord 's servant, had given the Israelites, as it says in the Law of Moses: an altar made of stones which have not been cut with iron tools. On it they offered burnt sacrifices to the Lord , and they also presented their fellowship offerings. |
alɔ Alatala xa konyi Munsa a fala Isirayilakae bɛ ki naxɛ. E naxa sɛrɛxɛbade gɛmɛ daaxi ti, wure mu nu din naxan na, alɔ a sɛbɛxi Tawureta Munsa kitaabui kui ki naxɛ. E naxa sɛrɛxɛ gan daaxie nun xanunteya sɛrɛxɛe ba Alatala bɛ na fari. |
Celle-ci ordonna à Hathac de rapporter sa réponse à Mardochée :. |
Esita to na mɛ, a man naxa Hataki xɛɛ Morodekayi xɔn ma, a xa sa yi fala a bɛ. |
But there is something you do that is right—you hate the things that the Nicolaitans do. I also hate what they do. |
«Kɔnɔ wo bara fe nde raba naxan fan. Wo bara Nikolasi xa ɲama xa fe xɔn, alɔ n fan a xɔnxi ki naxɛ.». |
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: 64learning_rate: 2e-05num_train_epochs: 4warmup_steps: 0.1fp16: Truedo_predict: Falseprediction_loss_only: Trueper_device_train_batch_size: 64per_device_eval_batch_size: 8gradient_accumulation_steps: 1eval_accumulation_steps: Nonetorch_empty_cache_steps: Nonelearning_rate: 2e-05weight_decay: 0.0adam_beta1: 0.9adam_beta2: 0.999adam_epsilon: 1e-08max_grad_norm: 1.0num_train_epochs: 4max_steps: -1lr_scheduler_type: linearlr_scheduler_kwargs: Nonewarmup_ratio: Nonewarmup_steps: 0.1log_level: passivelog_level_replica: warninglog_on_each_node: Truelogging_nan_inf_filter: Trueenable_jit_checkpoint: Falsesave_on_each_node: Falsesave_only_model: Falserestore_callback_states_from_checkpoint: Falseuse_cpu: Falseseed: 42data_seed: Nonebf16: Falsefp16: Truebf16_full_eval: Falsefp16_full_eval: Falsetf32: Nonelocal_rank: -1ddp_backend: Nonedebug: []dataloader_drop_last: Falsedataloader_num_workers: 0dataloader_prefetch_factor: Nonedisable_tqdm: Falseremove_unused_columns: Truelabel_names: Noneload_best_model_at_end: Falseignore_data_skip: Falsefsdp: []fsdp_config: {'min_num_params': 0, 'xla': False, 'xla_fsdp_v2': False, 'xla_fsdp_grad_ckpt': False}accelerator_config: {'split_batches': False, 'dispatch_batches': None, 'even_batches': True, 'use_seedable_sampler': True, 'non_blocking': False, 'gradient_accumulation_kwargs': None}parallelism_config: Nonedeepspeed: Nonelabel_smoothing_factor: 0.0optim: adamw_torch_fusedoptim_args: Nonegroup_by_length: Falselength_column_name: lengthproject: huggingfacetrackio_space_id: trackioddp_find_unused_parameters: Noneddp_bucket_cap_mb: Noneddp_broadcast_buffers: Falsedataloader_pin_memory: Truedataloader_persistent_workers: Falseskip_memory_metrics: Truepush_to_hub: Falseresume_from_checkpoint: Nonehub_model_id: Nonehub_strategy: every_savehub_private_repo: Nonehub_always_push: Falsehub_revision: Nonegradient_checkpointing: Falsegradient_checkpointing_kwargs: Noneinclude_for_metrics: []eval_do_concat_batches: Trueauto_find_batch_size: Falsefull_determinism: Falseddp_timeout: 1800torch_compile: Falsetorch_compile_backend: Nonetorch_compile_mode: Noneinclude_num_input_tokens_seen: noneftune_noise_alpha: Noneoptim_target_modules: Nonebatch_eval_metrics: Falseeval_on_start: Falseuse_liger_kernel: Falseliger_kernel_config: Noneeval_use_gather_object: Falseaverage_tokens_across_devices: Trueuse_cache: Falseprompts: Nonebatch_sampler: batch_samplermulti_dataset_batch_sampler: proportionalrouter_mapping: {}learning_rate_mapping: {}| Epoch | Step | Training Loss |
|---|---|---|
| 0.0284 | 50 | 5.0351 |
| 0.0568 | 100 | 4.5387 |
| 0.0851 | 150 | 4.0088 |
| 0.1135 | 200 | 3.2828 |
| 0.1419 | 250 | 2.6326 |
| 0.1703 | 300 | 2.0852 |
| 0.1986 | 350 | 1.6870 |
| 0.2270 | 400 | 1.4379 |
| 0.2554 | 450 | 1.2296 |
| 0.2838 | 500 | 1.0465 |
| 0.3121 | 550 | 0.8908 |
| 0.3405 | 600 | 0.8758 |
| 0.3689 | 650 | 0.7199 |
| 0.3973 | 700 | 0.6701 |
| 0.4257 | 750 | 0.6193 |
| 0.4540 | 800 | 0.5435 |
| 0.4824 | 850 | 0.5279 |
| 0.5108 | 900 | 0.4810 |
| 0.5392 | 950 | 0.4594 |
| 0.5675 | 1000 | 0.4344 |
| 0.5959 | 1050 | 0.3961 |
| 0.6243 | 1100 | 0.3767 |
| 0.6527 | 1150 | 0.3601 |
| 0.6810 | 1200 | 0.3690 |
| 0.7094 | 1250 | 0.3448 |
| 0.7378 | 1300 | 0.3396 |
| 0.7662 | 1350 | 0.3242 |
| 0.7946 | 1400 | 0.3236 |
| 0.8229 | 1450 | 0.2961 |
| 0.8513 | 1500 | 0.2853 |
| 0.8797 | 1550 | 0.2933 |
| 0.9081 | 1600 | 0.2625 |
| 0.9364 | 1650 | 0.2758 |
| 0.9648 | 1700 | 0.2617 |
| 0.9932 | 1750 | 0.2720 |
| 1.0216 | 1800 | 0.2535 |
| 1.0499 | 1850 | 0.2366 |
| 1.0783 | 1900 | 0.2097 |
| 1.1067 | 1950 | 0.2183 |
| 1.1351 | 2000 | 0.2201 |
| 1.1635 | 2050 | 0.2284 |
| 1.1918 | 2100 | 0.2259 |
| 1.2202 | 2150 | 0.2125 |
| 1.2486 | 2200 | 0.2059 |
| 1.2770 | 2250 | 0.1950 |
| 1.3053 | 2300 | 0.2066 |
| 1.3337 | 2350 | 0.1944 |
| 1.3621 | 2400 | 0.2019 |
| 1.3905 | 2450 | 0.2051 |
| 1.4188 | 2500 | 0.1903 |
| 1.4472 | 2550 | 0.1958 |
| 1.4756 | 2600 | 0.1869 |
| 1.5040 | 2650 | 0.1827 |
| 1.5323 | 2700 | 0.1804 |
| 1.5607 | 2750 | 0.1692 |
| 1.5891 | 2800 | 0.2033 |
| 1.6175 | 2850 | 0.1740 |
| 1.6459 | 2900 | 0.1810 |
| 1.6742 | 2950 | 0.1785 |
| 1.7026 | 3000 | 0.1737 |
| 1.7310 | 3050 | 0.1914 |
| 1.7594 | 3100 | 0.1779 |
| 1.7877 | 3150 | 0.1670 |
| 1.8161 | 3200 | 0.1744 |
| 1.8445 | 3250 | 0.1647 |
| 1.8729 | 3300 | 0.1720 |
| 1.9012 | 3350 | 0.1746 |
| 1.9296 | 3400 | 0.1559 |
| 1.9580 | 3450 | 0.1571 |
| 1.9864 | 3500 | 0.1655 |
| 2.0148 | 3550 | 0.1342 |
| 2.0431 | 3600 | 0.1304 |
| 2.0715 | 3650 | 0.1335 |
| 2.0999 | 3700 | 0.1290 |
| 2.1283 | 3750 | 0.1486 |
| 2.1566 | 3800 | 0.1274 |
| 2.1850 | 3850 | 0.1384 |
| 2.2134 | 3900 | 0.1257 |
| 2.2418 | 3950 | 0.1277 |
| 2.2701 | 4000 | 0.1372 |
| 2.2985 | 4050 | 0.1329 |
| 2.3269 | 4100 | 0.1347 |
| 2.3553 | 4150 | 0.1332 |
| 2.3837 | 4200 | 0.1322 |
| 2.4120 | 4250 | 0.1208 |
| 2.4404 | 4300 | 0.1311 |
| 2.4688 | 4350 | 0.1248 |
| 2.4972 | 4400 | 0.1246 |
| 2.5255 | 4450 | 0.1155 |
| 2.5539 | 4500 | 0.1243 |
| 2.5823 | 4550 | 0.1160 |
| 2.6107 | 4600 | 0.1143 |
| 2.6390 | 4650 | 0.1275 |
| 2.6674 | 4700 | 0.1258 |
| 2.6958 | 4750 | 0.1196 |
| 2.7242 | 4800 | 0.1068 |
| 2.7526 | 4850 | 0.1167 |
| 2.7809 | 4900 | 0.1181 |
| 2.8093 | 4950 | 0.1057 |
| 2.8377 | 5000 | 0.1169 |
| 2.8661 | 5050 | 0.1287 |
| 2.8944 | 5100 | 0.1108 |
| 2.9228 | 5150 | 0.1110 |
| 2.9512 | 5200 | 0.1145 |
| 2.9796 | 5250 | 0.1161 |
| 3.0079 | 5300 | 0.1172 |
| 3.0363 | 5350 | 0.1005 |
| 3.0647 | 5400 | 0.0977 |
| 3.0931 | 5450 | 0.1045 |
| 3.1215 | 5500 | 0.1021 |
| 3.1498 | 5550 | 0.1059 |
| 3.1782 | 5600 | 0.1026 |
| 3.2066 | 5650 | 0.0998 |
| 3.2350 | 5700 | 0.0982 |
| 3.2633 | 5750 | 0.1003 |
| 3.2917 | 5800 | 0.1015 |
| 3.3201 | 5850 | 0.0966 |
| 3.3485 | 5900 | 0.0971 |
| 3.3768 | 5950 | 0.1033 |
| 3.4052 | 6000 | 0.1001 |
| 3.4336 | 6050 | 0.0942 |
| 3.4620 | 6100 | 0.1028 |
| 3.4904 | 6150 | 0.0934 |
| 3.5187 | 6200 | 0.0918 |
| 3.5471 | 6250 | 0.0993 |
| 3.5755 | 6300 | 0.0943 |
| 3.6039 | 6350 | 0.1046 |
| 3.6322 | 6400 | 0.0941 |
| 3.6606 | 6450 | 0.0999 |
| 3.6890 | 6500 | 0.0998 |
| 3.7174 | 6550 | 0.0987 |
| 3.7457 | 6600 | 0.1078 |
| 3.7741 | 6650 | 0.0972 |
| 3.8025 | 6700 | 0.1008 |
| 3.8309 | 6750 | 0.1070 |
| 3.8593 | 6800 | 0.0878 |
| 3.8876 | 6850 | 0.0966 |
| 3.9160 | 6900 | 0.0909 |
| 3.9444 | 6950 | 0.0991 |
| 3.9728 | 7000 | 0.0969 |
@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},
}