Sentence-BERT: Sentence Embeddings using Siamese BERT-Networks
Paper • 1908.10084 • Published • 12
This is a sentence-transformers model finetuned from sentence-transformers/all-MiniLM-L6-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': 256, '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})
(2): Normalize()
)
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("ayushexel/emb-all-MiniLM-L6-v2-squad-4-epochs")
# Run inference
sentences = [
'In the Papal States, what is the name for the specified neighborhoods where Jews were required to live?',
'In the Papal States, which existed until 1870, Jews were required to live only in specified neighborhoods called ghettos. In the 19th and (before the end of World War II) 20th centuries, the Roman Catholic Church adhered to a distinction between "good antisemitism" and "bad antisemitism". The "bad" kind promoted hatred of Jews because of their descent. This was considered un-Christian because the Christian message was intended for all of humanity regardless of ethnicity; anyone could become a Christian. The "good" kind criticized alleged Jewish conspiracies to control newspapers, banks, and other institutions, to care only about accumulation of wealth, etc.',
'In the Papal States, which existed until 1870, Jews were required to live only in specified neighborhoods called ghettos. In the 19th and (before the end of World War II) 20th centuries, the Roman Catholic Church adhered to a distinction between "good antisemitism" and "bad antisemitism". The "bad" kind promoted hatred of Jews because of their descent. This was considered un-Christian because the Christian message was intended for all of humanity regardless of ethnicity; anyone could become a Christian. The "good" kind criticized alleged Jewish conspiracies to control newspapers, banks, and other institutions, to care only about accumulation of wealth, etc.',
]
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]
gooqa-devTripletEvaluator| Metric | Value |
|---|---|
| cosine_accuracy | 0.4078 |
question, context, and negative| question | context | negative | |
|---|---|---|---|
| type | string | string | string |
| details |
|
|
|
| question | context | negative |
|---|---|---|
Aside from lodging, what amenities are often offered at inns? |
Inns are buildings where travellers can seek lodging and, usually, food and drink. They are typically located in the country or along a highway. In Europe, they possibly first sprang up when the Romans built a system of roads two millennia ago.[citation needed] Some inns in Europe are several centuries old. In addition to providing for the needs of travellers, inns traditionally acted as community gathering places. |
The Inns of Court and Inns of Chancery in London started as ordinary inns where barristers met to do business, but became institutions of the legal profession in England and Wales. |
The results of which battle allowed the British to blockade French coasts? |
After returning from Egypt, Napoleon engineered a coup in November 1799 and became First Consul of the Republic. Another victory over the Austrians at the Battle of Marengo in 1800 secured his political power. With the Concordat of 1801, Napoleon restored the religious privileges of the Catholic Church while keeping the lands seized by the Revolution. The state continued to nominate the bishops and to control church finances. He extended his political control over France until the Senate declared him Emperor of the French in 1804, launching the French Empire. Intractable differences with the British meant that the French were facing a Third Coalition by 1805. Napoleon shattered this coalition with decisive victories in the Ulm Campaign and a historic triumph at the Battle of Austerlitz, which led to the elimination of the Holy Roman Empire. In October 1805, however, a Franco-Spanish fleet was destroyed at the Battle of Trafalgar, allowing Britain to impose a naval blockade of the Frenc... |
By 17 May, the main Austrian army under Charles had arrived on the Marchfeld. Charles kept the bulk of his troops several miles away from the river bank in hopes of concentrating them at the point where Napoleon decided to cross. On 21 May, the French made their first major effort to cross the Danube, precipitating the Battle of Aspern-Essling. The Austrians enjoyed a comfortable numerical superiority over the French throughout the battle; on the first day, Charles disposed of 110,000 soldiers against only 31,000 commanded by Napoleon. By the second day, reinforcements had boosted French numbers up to 70,000. The battle was characterized by a vicious back-and-forth struggle for the two villages of Aspern and Essling, the focal points of the French bridgehead. By the end of the fighting, the French had lost Aspern but still controlled Essling. A sustained Austrian artillery bombardment eventually convinced Napoleon to withdraw his forces back onto Lobau Island. Both sides inflicted abou... |
What is an example of bad treatment causing resistance? |
Inappropriate antibiotic treatment and overuse of antibiotics have contributed to the emergence of antibiotic-resistant bacteria. Self prescription of antibiotics is an example of misuse. Many antibiotics are frequently prescribed to treat symptoms or diseases that do not respond to antibiotics or that are likely to resolve without treatment. Also, incorrect or suboptimal antibiotics are prescribed for certain bacterial infections. The overuse of antibiotics, like penicillin and erythromycin, has been associated with emerging antibiotic resistance since the 1950s. Widespread usage of antibiotics in hospitals has also been associated with increases in bacterial strains and species that no longer respond to treatment with the most common antibiotics. |
Possible improvements include clarification of clinical trial regulations by FDA. Furthermore, appropriate economic incentives could persuade pharmaceutical companies to invest in this endeavor. Antibiotic Development to Advance Patient Treatment (ADAPT) Act aims to fast track the drug development to combat the growing threat of 'superbugs'. Under this Act, FDA can approve antibiotics and antifungals treating life-threatening infections based on smaller clinical trials. The CDC will monitor the use of antibiotics and the emerging resistance, and publish the data. The FDA antibiotics labeling process, 'Susceptibility Test Interpretive Criteria for Microbial Organisms' or 'breakpoints', will provide accurate data to healthcare professionals. According to Allan Coukell, senior director for health programs at The Pew Charitable Trusts, "By allowing drug developers to rely on smaller datasets, and clarifying FDA's authority to tolerate a higher level of uncertainty for these drugs when maki... |
MultipleNegativesRankingLoss with these parameters:{
"scale": 20.0,
"similarity_fct": "cos_sim"
}
question, context, and negative_1| question | context | negative_1 | |
|---|---|---|---|
| type | string | string | string |
| details |
|
|
|
| question | context | negative_1 |
|---|---|---|
What is the name for the collection of formal rules in Catholicism? |
In the Catholic Church, canon law is the system of laws and legal principles made and enforced by the Church's hierarchical authorities to regulate its external organization and government and to order and direct the activities of Catholics toward the mission of the Church. |
In the Catholic Church, canon law is the system of laws and legal principles made and enforced by the Church's hierarchical authorities to regulate its external organization and government and to order and direct the activities of Catholics toward the mission of the Church. |
Where is Mount Tangjia? |
The most precarious of these quake-lakes was the one located in the extremely difficult terrain at Mount Tangjia in Beichuan County, Sichuan, accessible only by foot or air; an Mi-26T heavy lift helicopter belonging to the China Flying Dragon Special Aviation Company was used to bring heavy earthmoving tractors to the affected location. This operation was coupled with the work done by PLAAF Mi-17 helicopters bringing in PLA engineering corps, explosive specialists and other personnel to join 1,200 soldiers who arrived on site by foot. Five tons of fuel to operate the machinery was airlifted to the site, where a sluice was constructed to allow the safe discharge of the bottlenecked water. Downstream, more than 200,000 people were evacuated from Mianyang by June 1 in anticipation of the dam bursting. |
Tibet was once a strong power contemporaneous with Tang China (618–907). Until the Tibetan Empire's collapse in the 9th century, it was the Tang's major rival in dominating Inner Asia. The Yarlung rulers of Tibet also signed various peace treaties with the Tang, culminating in a treaty in 821 that fixed the borders between Tibet and China. |
What century did Aretas III Philhellene reign? |
The Nabatean Kingdom was an Arab state located between the Sinai Peninsula and the Arabian Peninsula. Its capital was the city of Petra, an important trading city on the incense route. The Nabateans resisted the attacks of Antigonous and were allies of the Hasmoneans in their struggle against the Seleucids, but later fought against Herod the great. The hellenization of the Nabateans accured relatively late in comparison to the surrounding regions. Nabatean material culture does not show any Greek influence until the reign of Aretas III Philhellene in the 1st century BCE. Aretas captured Damascus and built the Petra pool complex and gardens in the Hellenistic style. Though the Nabateans originally worshipped their traditional gods in symbolic form such as stone blocks or pillars, during the Hellenistic period they began to identify their gods with Greek gods and depict them in figurative forms influenced by Greek sculpture. Nabatean art shows Greek influences and paintings have been fou... |
The Nabatean Kingdom was an Arab state located between the Sinai Peninsula and the Arabian Peninsula. Its capital was the city of Petra, an important trading city on the incense route. The Nabateans resisted the attacks of Antigonous and were allies of the Hasmoneans in their struggle against the Seleucids, but later fought against Herod the great. The hellenization of the Nabateans accured relatively late in comparison to the surrounding regions. Nabatean material culture does not show any Greek influence until the reign of Aretas III Philhellene in the 1st century BCE. Aretas captured Damascus and built the Petra pool complex and gardens in the Hellenistic style. Though the Nabateans originally worshipped their traditional gods in symbolic form such as stone blocks or pillars, during the Hellenistic period they began to identify their gods with Greek gods and depict them in figurative forms influenced by Greek sculpture. Nabatean art shows Greek influences and paintings have been fou... |
MultipleNegativesRankingLoss with these parameters:{
"scale": 20.0,
"similarity_fct": "cos_sim"
}
eval_strategy: stepsper_device_train_batch_size: 256per_device_eval_batch_size: 256num_train_epochs: 4warmup_ratio: 0.1fp16: Truebatch_sampler: no_duplicatesoverwrite_output_dir: Falsedo_predict: Falseeval_strategy: stepsprediction_loss_only: Trueper_device_train_batch_size: 256per_device_eval_batch_size: 256per_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: 1.0num_train_epochs: 4max_steps: -1lr_scheduler_type: linearlr_scheduler_kwargs: {}warmup_ratio: 0.1warmup_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: Truefp16_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}tp_size: 0fsdp_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: no_duplicatesmulti_dataset_batch_sampler: proportional| Epoch | Step | Training Loss | Validation Loss | gooqa-dev_cosine_accuracy |
|---|---|---|---|---|
| -1 | -1 | - | - | 0.3294 |
| 0.5780 | 100 | 0.5447 | 0.8324 | 0.3926 |
| 1.1561 | 200 | 0.4731 | 0.8196 | 0.3952 |
| 1.7341 | 300 | 0.3978 | 0.8026 | 0.4026 |
| 2.3121 | 400 | 0.3496 | 0.7996 | 0.4046 |
| 2.8902 | 500 | 0.3252 | 0.7948 | 0.4040 |
| 3.4682 | 600 | 0.2958 | 0.7955 | 0.4070 |
| -1 | -1 | - | - | 0.4078 |
@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{henderson2017efficient,
title={Efficient Natural Language Response Suggestion for Smart Reply},
author={Matthew Henderson and Rami Al-Rfou and Brian Strope and Yun-hsuan Sung and Laszlo Lukacs and Ruiqi Guo and Sanjiv Kumar and Balint Miklos and Ray Kurzweil},
year={2017},
eprint={1705.00652},
archivePrefix={arXiv},
primaryClass={cs.CL}
}
Base model
sentence-transformers/all-MiniLM-L6-v2