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-2-epochs")
# Run inference
sentences = [
'In what year did CBS sell CBS Songs?',
'In 1986, CBS sold its music publishing arm, CBS Songs, to Stephen Swid, Martin Bandier, and Charles Koppelman for $125 million making it the foundation of their SBK Entertainment.',
'On November 17, 1987, SCA acquired CBS Records, which hosted such acts as Michael Jackson, for US$2 billion. CBS Inc., now CBS Corporation, retained the rights to the CBS name for music recordings but granted Sony a temporary license to use the CBS name. CBS Corporation founded a new CBS Records in 2006, which is distributed by Sony through its RED subsidiary.',
]
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.4062 |
question, context, and negative| question | context | negative | |
|---|---|---|---|
| type | string | string | string |
| details |
|
|
|
| question | context | negative |
|---|---|---|
Who was the first governor of Saint Helena? |
In 1657, Oliver Cromwell granted the English East India Company a charter to govern Saint Helena and the following year the company decided to fortify the island and colonise it with planters. The first governor, Captain John Dutton, arrived in 1659, making Saint Helena one of Britain's oldest colonies outside North America and the Caribbean. A fort and houses were built. After the Restoration of the English monarchy in 1660, the East India Company received a royal charter giving it the sole right to fortify and colonise the island. The fort was renamed James Fort and the town Jamestown, in honour of the Duke of York, later James II of England. |
In 2012, the government of St. Helena funded the creation of the St. Helena Human Rights Action Plan 2012-2015. Work is being done under this action plan, including publishing awareness-raising articles in local newspapers, providing support for members of the public with human rights queries, and extending several UN Conventions on human rights to St. Helena. |
When was the Chapultepec Zoo opened? |
Mexico City has three zoos. Chapultepec Zoo, the San Juan de Aragon Zoo and Los Coyotes Zoo. Chapultepec Zoo is located in the first section of Chapultepec Park in the Miguel Hidalgo. It was opened in 1924. Visitors can see about 243 specimens of different species including kangaroos, giant panda, gorillas, caracal, hyena, hippos, jaguar, giraffe, lemur, lion, among others. Zoo San Juan de Aragon is near the San Juan de Aragon Park in the Gustavo A. Madero. In this zoo, opened in 1964, there are species that are in danger of extinction such as the jaguar and the Mexican wolf. Other guests are the golden eagle, pronghorn, bighorn sheep, caracara, zebras, African elephant, macaw, hippo, among others. Zoo Los Coyotes is a 27.68-acre (11.2 ha) zoo located south of Mexico City in the Coyoacan. It was inaugurated on February 2, 1999. It has more than 301 specimens of 51 species of wild native or endemic fauna from the Mexico City. You can admire eagles, ajolotes, coyotes, macaws, bobcats, Me... |
Chapultepec Park houses the Chapultepec Castle, now a museum on a hill that overlooks the park and its numerous museums, monuments and the national zoo and the National Museum of Anthropology (which houses the Aztec Calendar Stone). Another piece of architecture is the Fine Arts Palace, a white marble theatre/museum whose weight is such that it has gradually been sinking into the soft ground below. Its construction began during the presidency of Porfirio Díaz and ended in 1934, after being interrupted by the Mexican Revolution in the 1920s. The Plaza of the Three Cultures in the Tlatelolco neighbourhood, and the shrine and Basilicas of Our Lady of Guadalupe are also important sites. There is a double-decker bus, known as the "Turibus", that circles most of these sites, and has timed audio describing the sites in multiple languages as they are passed. |
Which season three contestant on American Idol was the recipient of reported death threats? |
Much media attention on the season had been focused on the three black singers, Fantasia Barrino, LaToya London, and Jennifer Hudson, dubbed the Three Divas. All three unexpectedly landed on the bottom three on the top seven result show, with Hudson controversially eliminated. Elton John, who was one of the mentors that season, called the results of the votes "incredibly racist". The prolonged stays of John Stevens and Jasmine Trias in the finals, despite negative comments from the judges, had aroused resentment, so much so that John Stevens reportedly received a death threat, which he dismissed as a joke 'blown out of proportion'. |
The winner receives a record deal with a major label, which may be for up to six albums, and secures a management contract with American Idol-affiliated 19 Management (which has the right of first refusal to sign all contestants), as well as various lucrative contracts. All winners prior to season nine reportedly earned at least $1 million in their first year as winner. All the runners-up of the first ten seasons, as well as some of other finalists, have also received record deals with major labels. However, starting in season 11, the runner-up may only be guaranteed a single-only deal. BMG/Sony (seasons 1–9) and UMG (season 10–) had the right of first refusal to sign contestants for three months after the season's finale. Starting in the fourteenth season, the winner was signed with Big Machine Records. Prominent music mogul Clive Davis also produced some of the selected contestants' albums, such as Kelly Clarkson, Clay Aiken, Fantasia Barrino and Diana DeGarmo. All top 10 (11 in seas... |
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 |
|---|---|---|
Stain-resistant fabrics are coated with chemicals to reduce what? |
The world of clothing is always changing, as new cultural influences meet technological innovations. Researchers in scientific labs have been developing prototypes for fabrics that can serve functional purposes well beyond their traditional roles, for example, clothes that can automatically adjust their temperature, repel bullets, project images, and generate electricity. Some practical advances already available to consumers are bullet-resistant garments made with kevlar and stain-resistant fabrics that are coated with chemical mixtures that reduce the absorption of liquids. |
The world of clothing is always changing, as new cultural influences meet technological innovations. Researchers in scientific labs have been developing prototypes for fabrics that can serve functional purposes well beyond their traditional roles, for example, clothes that can automatically adjust their temperature, repel bullets, project images, and generate electricity. Some practical advances already available to consumers are bullet-resistant garments made with kevlar and stain-resistant fabrics that are coated with chemical mixtures that reduce the absorption of liquids. |
What explorer led the Nimrod Expedition into Antarctica? |
During the Nimrod Expedition led by Ernest Shackleton in 1907, parties led by Edgeworth David became the first to climb Mount Erebus and to reach the South Magnetic Pole. Douglas Mawson, who assumed the leadership of the Magnetic Pole party on their perilous return, went on to lead several expeditions until retiring in 1931. In addition, Shackleton himself and three other members of his expedition made several firsts in December 1908 – February 1909: they were the first humans to traverse the Ross Ice Shelf, the first to traverse the Transantarctic Mountains (via the Beardmore Glacier), and the first to set foot on the South Polar Plateau. An expedition led by Norwegian polar explorer Roald Amundsen from the ship Fram became the first to reach the geographic South Pole on 14 December 1911, using a route from the Bay of Whales and up the Axel Heiberg Glacier. One month later, the doomed Scott Expedition reached the pole. |
During the Nimrod Expedition led by Ernest Shackleton in 1907, parties led by Edgeworth David became the first to climb Mount Erebus and to reach the South Magnetic Pole. Douglas Mawson, who assumed the leadership of the Magnetic Pole party on their perilous return, went on to lead several expeditions until retiring in 1931. In addition, Shackleton himself and three other members of his expedition made several firsts in December 1908 – February 1909: they were the first humans to traverse the Ross Ice Shelf, the first to traverse the Transantarctic Mountains (via the Beardmore Glacier), and the first to set foot on the South Polar Plateau. An expedition led by Norwegian polar explorer Roald Amundsen from the ship Fram became the first to reach the geographic South Pole on 14 December 1911, using a route from the Bay of Whales and up the Axel Heiberg Glacier. One month later, the doomed Scott Expedition reached the pole. |
When was the first female ascent on Mont Blanc? |
The first British Mont Blanc ascent was in 1788; the first female ascent in 1819. By the mid-1850s Swiss mountaineers had ascended most of the peaks and were eagerly sought as mountain guides. Edward Whymper reached the top of the Matterhorn in 1865 (after seven attempts), and in 1938 the last of the six great north faces of the Alps was climbed with the first ascent of the Eiger Nordwand (north face of the Eiger). |
The first British Mont Blanc ascent was in 1788; the first female ascent in 1819. By the mid-1850s Swiss mountaineers had ascended most of the peaks and were eagerly sought as mountain guides. Edward Whymper reached the top of the Matterhorn in 1865 (after seven attempts), and in 1938 the last of the six great north faces of the Alps was climbed with the first ascent of the Eiger Nordwand (north face of the Eiger). |
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: 2warmup_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: 2max_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.3286 |
| 0.5780 | 100 | 0.5372 | 0.8373 | 0.4002 |
| 1.1561 | 200 | 0.4631 | 0.8101 | 0.4034 |
| 1.7341 | 300 | 0.3993 | 0.8093 | 0.4078 |
| -1 | -1 | - | - | 0.4062 |
@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