Sentence-BERT: Sentence Embeddings using Siamese BERT-Networks
Paper • 1908.10084 • Published • 13
How to use NilsML/fine_tuned_miniLM with sentence-transformers:
from sentence_transformers import SentenceTransformer
model = SentenceTransformer("NilsML/fine_tuned_miniLM")
sentences = [
"Structurally, diplomonads have two equal-sized what and multiple flagella?",
"deciding when to buy or sell a stock is not an easy task because the market is hard to predict, being influenced by political and economic factors. thus, methodologies based on computational intelligence have been applied to this challenging problem. in this work, every day the stocks are ranked by technique for order preference by similarity to ideal solution ( topsis ) using technical analysis criteria, and the most suitable stock is selected for purchase. even so, it may occur that the market is not favorable to purchase on certain days, or even, the topsis make an incorrect selection. to improve the selection, another method should be used. so, a hybrid",
"we present the analysis of the brightest flare that was recorded in the \\ emph { insight } - hmxt data set, in a broad energy range ( 2 $ - $ 200 kev ) from the microquasar grs ~ 1915 + 105 during an unusual low - luminosity state. this flare was detected by \\ emph { insight } - hxmt among a series of flares during 2 june 2019 utc 16 : 37 : 06 to 20 : 11 : 36, with a 2 - 200 kev luminosity of 3. 4 $ - $ 7. 27 $ \\ times10 ^ { 38 } $ er",
"nuclei"
]
embeddings = model.encode(sentences)
similarities = model.similarity(embeddings, embeddings)
print(similarities.shape)
# [4, 4]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("sentence_transformers_model_id")
# Run inference
sentences = [
'How many different main types of diabetes are there?',
'two',
'a connection between relativistic quantum mechanics in the foldy - wouthuysen representation and the paraxial equations is established for a dirac particle in external fields. the paraxial form of the landau eigenfunction for a relativistic electron in a uniform magnetic field is determined. the obtained wave function contains the gouy phase and significantly approaches to the paraxial wave function for a free electron.',
]
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]
sciq-evalInformationRetrievalEvaluator| Metric | Value |
|---|---|
| cosine_accuracy@1 | 0.084 |
| cosine_accuracy@3 | 0.192 |
| cosine_accuracy@5 | 0.26 |
| cosine_accuracy@10 | 0.367 |
| cosine_precision@1 | 0.084 |
| cosine_precision@3 | 0.064 |
| cosine_precision@5 | 0.052 |
| cosine_precision@10 | 0.0367 |
| cosine_recall@1 | 0.084 |
| cosine_recall@3 | 0.192 |
| cosine_recall@5 | 0.26 |
| cosine_recall@10 | 0.367 |
| cosine_ndcg@10 | 0.2077 |
| cosine_mrr@10 | 0.1589 |
| cosine_map@100 | 0.1741 |
sentence_0, sentence_1, and label| sentence_0 | sentence_1 | label | |
|---|---|---|---|
| type | string | string | float |
| details |
|
|
|
| sentence_0 | sentence_1 | label |
|---|---|---|
Unlike plants, animal species rely almost exclusively on what type of reproduction? |
0. 4, \ sim 4, and \ sim 300 \ mum are stronger than 10 ^ 5, 10 ^ 8, and 10 ^ 4 times those of the local interstellar radiation field ( isrf ). below these values, the chemical pumping is the dominant source of excitation of the j > 1 levels, even at high kinetic temperatures ( \ sim 1000 k ). the far - infrared emission lines of ch + observed in the orion bar and the ngc 7027 pdrs are consistent with the predictions of our excitation model assuming an incident far - ultraviolet ( fuv ) radiation field of \ sim 3 \ times 10 |
0.0 |
What type of energy occurs by splitting the nuclei of radioactive uranium? |
we study the potential of future electron - ion collider ( eic ) data to probe four - fermion operators in the standard model effective field theory ( smeft ). the ability to perform measurements with both polarized electron and proton beams at the eic provides a powerful tool that can disentangle the effects from different smeft operators. we compare the potential constraints from an eic with those obtained from drell - yan data at the large hadron collider. we show that eic data plays an important complementary role since it probes combinations of wilson coefficients not accessible through available drell - yan measurements. |
0.0 |
What element, which often forms polymers, has a unique ability to form covalent bonds with many other atoms? |
some divergent series $ f $. the convergence sets on $ \ gamma : = \ { [ 1 : z : \ psi ( z ) ] : z \ in \ mathbb { c } \ } \ subset \ mathbb { c } ^ 2 \ subset \ mathbb { p } ^ 2 $, where $ \ psi $ is a transcendental entire holomorphic function, are also studied and we obtain that a subset on $ \ gamma $ is a convergence set in $ \ mathbb { p } ^ 2 $ if and only if it is a countable union of compact projectively convex sets, and |
0.0 |
MultipleNegativesRankingLoss with these parameters:{
"scale": 20.0,
"similarity_fct": "cos_sim"
}
eval_strategy: stepsper_device_train_batch_size: 32per_device_eval_batch_size: 32num_train_epochs: 1multi_dataset_batch_sampler: round_robinoverwrite_output_dir: Falsedo_predict: Falseeval_strategy: stepsprediction_loss_only: Trueper_device_train_batch_size: 32per_device_eval_batch_size: 32per_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: 1max_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}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: 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 | sciq-eval_cosine_ndcg@10 |
|---|---|---|---|
| 0.0685 | 100 | - | 0.1200 |
| 0.1370 | 200 | - | 0.1562 |
| 0.2055 | 300 | - | 0.1780 |
| 0.2740 | 400 | - | 0.1811 |
| 0.3425 | 500 | 3.1705 | 0.1909 |
| 0.4110 | 600 | - | 0.1904 |
| 0.4795 | 700 | - | 0.1955 |
| 0.5479 | 800 | - | 0.2031 |
| 0.6164 | 900 | - | 0.2014 |
| 0.6849 | 1000 | 2.9054 | 0.2002 |
| 0.7534 | 1100 | - | 0.2058 |
| 0.8219 | 1200 | - | 0.2083 |
| 0.8904 | 1300 | - | 0.2084 |
| 0.9589 | 1400 | - | 0.2076 |
| 1.0 | 1460 | - | 0.2077 |
@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
nreimers/MiniLM-L6-H384-uncased