Sentence-BERT: Sentence Embeddings using Siamese BERT-Networks
Paper • 1908.10084 • Published • 12
This is a sentence-transformers model finetuned from TaylorAI/bge-micro-v2. It maps sentences & paragraphs to a 384-dimensional dense vector space and can be used for semantic textual similarity, semantic search, paraphrase mining, text classification, clustering, and more.
SentenceTransformer(
(0): Transformer({'max_seq_length': 512, 'do_lower_case': False}) with Transformer model: BertModel
(1): Pooling({'word_embedding_dimension': 384, 'pooling_mode_cls_token': False, 'pooling_mode_mean_tokens': True, 'pooling_mode_max_tokens': False, 'pooling_mode_mean_sqrt_len_tokens': False, 'pooling_mode_weightedmean_tokens': False, 'pooling_mode_lasttoken': False, '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 = [
'Founded by some 30 leaders of the Christian Right, the Alliance Defending Freedom is a legal advocacy and training group that has supported the recriminalization of sexual acts between consenting LGBTQ adults in the U.S. and criminalization abroad; has defended state-sanctioned sterilization of trans people abroad; has contended that LGBTQ people are more likely to engage in pedophilia; and claims that a ‘homosexual agenda’ will destroy Christianity and society. ADF also works to develop “religious liberty” legislation and case law that will allow the denial of goods and services to LGBTQ people on the basis of religion. Since the election of President Trump, ADF has become one of the most influential groups informing the administration’s attack on LGBTQ rights.',
'Fossil fuels have powered centuries of progress, lifted billions out of poverty, and remain the backbone of global energy, while alternatives, though promising, cannot yet match their scale, reliability, or affordability.',
'Climate change is nothing more than a fabricated agenda pushed by corrupt elites, politicians, and scientists to control the masses, gain wealth, and suppress freedom.',
]
embeddings = model.encode(sentences)
print(embeddings.shape)
# [3, 384]
# Get the similarity scores for the embeddings
similarities = model.similarity(embeddings, embeddings)
print(similarities.shape)
# [3, 3]
sentence_0, sentence_1, and label| sentence_0 | sentence_1 | label | |
|---|---|---|---|
| type | string | string | float |
| details |
|
|
|
| sentence_0 | sentence_1 | label |
|---|---|---|
To that end, we have been working on the Murdoch press of late, with good initial results. |
The so-called consensus on climate change relies on flawed models, manipulated data, and a refusal to address legitimate scientific uncertainties, all to serve a predetermined political narrative. |
0.0 |
Scientists who dare question the almost religious belief in climate change, and yes, they do exist, are ignored or undermined in news reports as are policy makers and pundits who take similar views. |
The Earth's climate has always changed due to natural cycles and external factors, and the role of human activity or CO2 emissions in driving these changes is negligible or unsupported by evidence. |
0.0 |
What about ‘global warming?’ What matters is the degree and rate of change. There have been times on earth when it has been much warmer than today, and times when it’s been much colder. The latter are called ice ages. One of the former is called ‘The Climate Optimum.’ It was a time of higher average global temperature and high CO2. |
The Earth's climate has always changed due to natural cycles and external factors, and the role of human activity or CO2 emissions in driving these changes is negligible or unsupported by evidence. |
1.0 |
CosineSimilarityLoss with these parameters:{
"loss_fct": "torch.nn.modules.loss.MSELoss"
}
per_device_train_batch_size: 16per_device_eval_batch_size: 16num_train_epochs: 20multi_dataset_batch_sampler: round_robinoverwrite_output_dir: Falsedo_predict: Falseeval_strategy: noprediction_loss_only: Trueper_device_train_batch_size: 16per_device_eval_batch_size: 16per_gpu_train_batch_size: Noneper_gpu_eval_batch_size: Nonegradient_accumulation_steps: 1eval_accumulation_steps: Nonetorch_empty_cache_steps: Nonelearning_rate: 5e-05weight_decay: 0.0adam_beta1: 0.9adam_beta2: 0.999adam_epsilon: 1e-08max_grad_norm: 1num_train_epochs: 20max_steps: -1lr_scheduler_type: linearlr_scheduler_kwargs: {}warmup_ratio: 0.0warmup_steps: 0log_level: passivelog_level_replica: warninglog_on_each_node: Truelogging_nan_inf_filter: Truesave_safetensors: Truesave_on_each_node: Falsesave_only_model: Falserestore_callback_states_from_checkpoint: Falseno_cuda: Falseuse_cpu: Falseuse_mps_device: Falseseed: 42data_seed: Nonejit_mode_eval: Falseuse_ipex: Falsebf16: Falsefp16: Falsefp16_opt_level: O1half_precision_backend: autobf16_full_eval: Falsefp16_full_eval: Falsetf32: Nonelocal_rank: 0ddp_backend: Nonetpu_num_cores: Nonetpu_metrics_debug: Falsedebug: []dataloader_drop_last: Falsedataloader_num_workers: 0dataloader_prefetch_factor: Nonepast_index: -1disable_tqdm: Falseremove_unused_columns: Truelabel_names: Noneload_best_model_at_end: Falseignore_data_skip: Falsefsdp: []fsdp_min_num_params: 0fsdp_config: {'min_num_params': 0, 'xla': False, 'xla_fsdp_v2': False, 'xla_fsdp_grad_ckpt': False}fsdp_transformer_layer_cls_to_wrap: Noneaccelerator_config: {'split_batches': False, 'dispatch_batches': None, 'even_batches': True, 'use_seedable_sampler': True, 'non_blocking': False, 'gradient_accumulation_kwargs': None}deepspeed: Nonelabel_smoothing_factor: 0.0optim: adamw_torchoptim_args: Noneadafactor: Falsegroup_by_length: Falselength_column_name: lengthddp_find_unused_parameters: Noneddp_bucket_cap_mb: Noneddp_broadcast_buffers: Falsedataloader_pin_memory: Truedataloader_persistent_workers: Falseskip_memory_metrics: Trueuse_legacy_prediction_loop: Falsepush_to_hub: Falseresume_from_checkpoint: Nonehub_model_id: Nonehub_strategy: every_savehub_private_repo: Nonehub_always_push: Falsegradient_checkpointing: Falsegradient_checkpointing_kwargs: Noneinclude_inputs_for_metrics: Falseinclude_for_metrics: []eval_do_concat_batches: Truefp16_backend: autopush_to_hub_model_id: Nonepush_to_hub_organization: Nonemp_parameters: auto_find_batch_size: Falsefull_determinism: Falsetorchdynamo: Noneray_scope: lastddp_timeout: 1800torch_compile: Falsetorch_compile_backend: Nonetorch_compile_mode: Nonedispatch_batches: Nonesplit_batches: Noneinclude_tokens_per_second: Falseinclude_num_input_tokens_seen: Falseneftune_noise_alpha: Noneoptim_target_modules: Nonebatch_eval_metrics: Falseeval_on_start: Falseuse_liger_kernel: Falseeval_use_gather_object: Falseaverage_tokens_across_devices: Falseprompts: Nonebatch_sampler: batch_samplermulti_dataset_batch_sampler: round_robin| Epoch | Step | Training Loss |
|---|---|---|
| 0.1482 | 500 | 0.2358 |
| 0.2965 | 1000 | 0.0696 |
| 0.4447 | 1500 | 0.0618 |
| 0.5929 | 2000 | 0.0597 |
| 0.7412 | 2500 | 0.0586 |
| 0.8894 | 3000 | 0.0549 |
| 1.0377 | 3500 | 0.0587 |
| 1.1859 | 4000 | 0.0549 |
| 1.3341 | 4500 | 0.0521 |
| 1.4824 | 5000 | 0.0504 |
| 1.6306 | 5500 | 0.0501 |
| 1.7788 | 6000 | 0.0489 |
| 1.9271 | 6500 | 0.0493 |
| 2.0753 | 7000 | 0.0456 |
| 2.2235 | 7500 | 0.0398 |
| 2.3718 | 8000 | 0.0416 |
| 2.5200 | 8500 | 0.0411 |
| 2.6682 | 9000 | 0.0396 |
| 2.8165 | 9500 | 0.0373 |
| 2.9647 | 10000 | 0.04 |
| 3.1130 | 10500 | 0.0319 |
| 3.2612 | 11000 | 0.0325 |
| 3.4094 | 11500 | 0.0284 |
| 3.5577 | 12000 | 0.0292 |
| 3.7059 | 12500 | 0.0302 |
| 3.8541 | 13000 | 0.0287 |
| 4.0024 | 13500 | 0.0287 |
| 4.1506 | 14000 | 0.0205 |
| 4.2988 | 14500 | 0.0204 |
| 4.4471 | 15000 | 0.023 |
| 4.5953 | 15500 | 0.0223 |
| 4.7436 | 16000 | 0.0214 |
| 4.8918 | 16500 | 0.0208 |
| 5.0400 | 17000 | 0.0186 |
| 5.1883 | 17500 | 0.0133 |
| 5.3365 | 18000 | 0.0148 |
| 5.4847 | 18500 | 0.0131 |
| 5.6330 | 19000 | 0.0151 |
| 5.7812 | 19500 | 0.0135 |
| 5.9294 | 20000 | 0.0151 |
| 6.0777 | 20500 | 0.0108 |
| 6.2259 | 21000 | 0.0095 |
| 6.3741 | 21500 | 0.0088 |
| 6.5224 | 22000 | 0.01 |
| 6.6706 | 22500 | 0.0113 |
| 6.8189 | 23000 | 0.0122 |
| 6.9671 | 23500 | 0.0091 |
| 7.1153 | 24000 | 0.007 |
| 7.2636 | 24500 | 0.0076 |
| 7.4118 | 25000 | 0.0072 |
| 7.5600 | 25500 | 0.007 |
| 7.7083 | 26000 | 0.0079 |
| 7.8565 | 26500 | 0.0064 |
| 8.0047 | 27000 | 0.0078 |
| 8.1530 | 27500 | 0.0053 |
| 8.3012 | 28000 | 0.0054 |
| 8.4495 | 28500 | 0.0046 |
| 8.5977 | 29000 | 0.0046 |
| 8.7459 | 29500 | 0.0055 |
| 8.8942 | 30000 | 0.0046 |
| 9.0424 | 30500 | 0.0039 |
| 9.1906 | 31000 | 0.0043 |
| 9.3389 | 31500 | 0.0036 |
| 9.4871 | 32000 | 0.004 |
| 9.6353 | 32500 | 0.0034 |
| 9.7836 | 33000 | 0.0034 |
| 9.9318 | 33500 | 0.0036 |
| 10.0800 | 34000 | 0.0033 |
| 10.2283 | 34500 | 0.0024 |
| 10.3765 | 35000 | 0.0023 |
| 10.5248 | 35500 | 0.0031 |
| 10.6730 | 36000 | 0.0033 |
| 10.8212 | 36500 | 0.0031 |
| 10.9695 | 37000 | 0.0033 |
| 11.1177 | 37500 | 0.0021 |
| 11.2659 | 38000 | 0.002 |
| 11.4142 | 38500 | 0.0021 |
| 11.5624 | 39000 | 0.0024 |
| 11.7106 | 39500 | 0.0023 |
| 11.8589 | 40000 | 0.0018 |
| 12.0071 | 40500 | 0.0034 |
| 12.1554 | 41000 | 0.0019 |
| 12.3036 | 41500 | 0.0016 |
| 12.4518 | 42000 | 0.0017 |
| 12.6001 | 42500 | 0.0016 |
| 12.7483 | 43000 | 0.0015 |
| 12.8965 | 43500 | 0.0018 |
| 13.0448 | 44000 | 0.0017 |
| 13.1930 | 44500 | 0.0013 |
| 13.3412 | 45000 | 0.0016 |
| 13.4895 | 45500 | 0.0012 |
| 13.6377 | 46000 | 0.0016 |
| 13.7859 | 46500 | 0.0019 |
| 13.9342 | 47000 | 0.0018 |
| 14.0824 | 47500 | 0.0014 |
| 14.2307 | 48000 | 0.0019 |
| 14.3789 | 48500 | 0.0017 |
| 14.5271 | 49000 | 0.0009 |
| 14.6754 | 49500 | 0.0009 |
| 14.8236 | 50000 | 0.0009 |
| 14.9718 | 50500 | 0.0018 |
| 15.1201 | 51000 | 0.0014 |
| 15.2683 | 51500 | 0.0012 |
| 15.4165 | 52000 | 0.0012 |
| 15.5648 | 52500 | 0.001 |
| 15.7130 | 53000 | 0.0014 |
| 15.8613 | 53500 | 0.0018 |
| 16.0095 | 54000 | 0.0014 |
| 16.1577 | 54500 | 0.0011 |
| 16.3060 | 55000 | 0.001 |
| 16.4542 | 55500 | 0.0009 |
| 16.6024 | 56000 | 0.0013 |
| 16.7507 | 56500 | 0.0015 |
| 16.8989 | 57000 | 0.0011 |
| 17.0471 | 57500 | 0.0007 |
| 17.1954 | 58000 | 0.0007 |
| 17.3436 | 58500 | 0.001 |
| 17.4918 | 59000 | 0.0011 |
| 17.6401 | 59500 | 0.0011 |
| 17.7883 | 60000 | 0.001 |
| 17.9366 | 60500 | 0.0012 |
| 18.0848 | 61000 | 0.001 |
| 18.2330 | 61500 | 0.0007 |
| 18.3813 | 62000 | 0.0009 |
| 18.5295 | 62500 | 0.001 |
| 18.6777 | 63000 | 0.0009 |
| 18.8260 | 63500 | 0.0011 |
| 18.9742 | 64000 | 0.0007 |
| 19.1224 | 64500 | 0.0012 |
| 19.2707 | 65000 | 0.0005 |
| 19.4189 | 65500 | 0.0008 |
| 19.5672 | 66000 | 0.001 |
| 19.7154 | 66500 | 0.0009 |
| 19.8636 | 67000 | 0.001 |
@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",
}