Sentence-BERT: Sentence Embeddings using Siamese BERT-Networks
Paper • 1908.10084 • Published • 14
How to use MinhPhuc0804/me5-256-kiem-tra-di-t1-v2.2-epoch-10 with sentence-transformers:
from sentence_transformers import SentenceTransformer
model = SentenceTransformer("MinhPhuc0804/me5-256-kiem-tra-di-t1-v2.2-epoch-10")
sentences = [
"query: Travel restrictions showed up after the fact, but physical distancing, case isolation, & testing did the trick for #FlattenTheCurve. Our global crew's analysis (co-led by @user & @user) of data from >30,000 #COVID19 cases is out in @ScienceMagazine. 1/12",
"passage: title: The effect of human mobility and control measures on the COVID-19 epidemic in China\nabstract: The ongoing coronavirus disease 2019 (COVID-19) outbreak expanded rapidly throughout China. Major behavioral, clinical, and state interventions were undertaken to mitigate the epidemic and prevent the persistence of the virus in human populations in China and worldwide. It remains unclear how these unprecedented interventions, including travel restrictions, affected COVID-19 spread in China. We used real-time mobility data from Wuhan and detailed case data including travel history to elucidate the role of case importation in transmission in cities across China and to ascertain the impact of control measures. Early on, the spatial distribution of COVID-19 cases in China was explained well by human mobility data. After the implementation of control measures, this correlation dropped and growth rates became negative in most locations, although shifts in the demographics of reported cases were still indicative of local chains of transmission outside of Wuhan. This study shows that the drastic control measures implemented in China substantially mitigated the spread of COVID-19.",
"passage: title: Reverse-transcribed SARS-CoV-2 RNA can integrate into the genome of cultured human cells and can be expressed in patient-derived tissues\nabstract: Prolonged detection of severe acute respiratory syndrome coronavirus 2 (SARS-CoV-2) RNA and recurrence of PCR-positive tests have been widely reported in patients after recovery from COVID-19, but some of these patients do not appear to shed infectious virus. We investigated the possibility that SARS-CoV-2 RNAs can be reverse-transcribed and integrated into the DNA of human cells in culture and that transcription of the integrated sequences might account for some of the positive PCR tests seen in patients. In support of this hypothesis, we found that DNA copies of SARS-CoV-2 sequences can be integrated into the genome of infected human cells.",
"passage: title: Covid-19 and alcohol—a dangerous cocktail\nabstract: The principal aim of this work was to better understand how regenerating muscle fibers become innervated in adult animals. To induce muscle regeneration, individual identified muscle fibers in a mouse were damaged with a laser focused through a microscope. The muscle fiber that degenerated and the muscle fiber that was formed in its place were followed by viewing the same site repeatedly over a period of 2 d to 40 weeks. Commonly, the nerve terminal innervating the irradiated muscle fiber partially retracted during muscle fiber degeneration, and then sprouted to innervate the regenerating muscle fiber at the same site it had previously innervated the muscle fiber that was damaged. During the early phase of muscle regeneration we also observed sprouts originating from nerve terminals on adjacent muscle fibers. The new nerve growth was a response to the regenerating muscle fiber rather than to the degenerated fiber it replaced because repeated damage of the same site every 2–3 d over a 10 d period (to prevent regeneration) did not cause any sprouting."
]
embeddings = model.encode(sentences)
similarities = model.similarity(embeddings, embeddings)
print(similarities.shape)
# [4, 4]This is a sentence-transformers model finetuned from intfloat/multilingual-e5-large-instruct on the clef-me5-mined-pairs-train-pairs dataset. It maps sentences & paragraphs to a 1024-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': 'XLMRobertaModel'})
(1): Pooling({'embedding_dimension': 1024, 'pooling_mode': 'mean', '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("MinhPhuc0804/me5-256-kiem-tra-di-t1-v2.2-epoch-10")
# Run inference
sentences = [
'query: @user That’s not what some of the data suggests. 25% of those who had a light infection the first time required an ER visit the 2nd time. And we know there is a mounting load with reinfections.',
"passage: diagnoses occur closer to the index date for infection or reinfection in the Omicron BA epoch.\n\ntitle: SARS-CoV-2 Reinfection is Preceded by Unique Biomarkers and Related to Initial Infection Timing and Severity: an N3C RECOVER EHR-Based Cohort Study\nWe report lower albumin levels leading up to reinfection and a statistically significant association of severity between first infection and reinfection (chi-squared value: 9446.2, p-value: 0) with a medium effect size (Cramer's V: 0.18, DoF = 4).",
'passage: randomization to hospital discharge.\n\ntitle: Effect of a Single High Dose of Vitamin D<sub>3</sub> on Hospital Length of Stay in Patients With Moderate to Severe COVID-19\nPrespecified secondary outcomes included mortality during hospitalization; the number of patients admitted to the intensive care unit; the number of patients who required mechanical ventilation and the duration of mechanical ventilation; and serum levels of 25-hydroxyvitamin D, total calcium, creatinine, and C-reactive protein.Of 240 randomized patients, 237 were included in the primary analysis (mean [SD] age, 56.2 [14.4] years; 104 [43.9%] women; mean [SD] baseline 25-hydroxyvitamin D level, 20.9 [9.2] ng/mL). Median (interquartile range) length of stay was not significantly different between the vitamin D3 (7.0 [4.0-10.0] days) and placebo groups (7.0 [5.0-13.0] days) (log-rank P = .59; unadjusted hazard ratio for hospital discharge, 1.07 [95% CI, 0.82-1.39]; P = .62).',
]
embeddings = model.encode(sentences)
print(embeddings.shape)
# [3, 1024]
# Get the similarity scores for the embeddings
similarities = model.similarity(embeddings, embeddings)
print(similarities)
# tensor([[1.0000, 0.5041, 0.1662],
# [0.5041, 1.0000, 0.0334],
# [0.1662, 0.0334, 1.0000]])
CT26-dev-splitInformationRetrievalEvaluator| Metric | Value |
|---|---|
| cosine_accuracy@1 | 0.6926 |
| cosine_accuracy@3 | 0.8577 |
| cosine_accuracy@5 | 0.8982 |
| cosine_accuracy@10 | 0.9273 |
| cosine_precision@1 | 0.6926 |
| cosine_precision@3 | 0.2859 |
| cosine_precision@5 | 0.1796 |
| cosine_precision@10 | 0.0927 |
| cosine_recall@1 | 0.6926 |
| cosine_recall@3 | 0.8577 |
| cosine_recall@5 | 0.8982 |
| cosine_recall@10 | 0.9273 |
| cosine_ndcg@10 | 0.818 |
| cosine_mrr@10 | 0.782 |
| cosine_map@100 | 0.7847 |
anchor and positive| anchor | positive | |
|---|---|---|
| type | string | string |
| details |
|
|
| anchor | positive |
|---|---|
query: Peer-reviewed scientific studies project universal mask use would spare nearly 130,000 U.S. lives by February. But Utah carries on with a baffling, lax patchwork of feeble mask rules. If elected, I’ll shield your family. #PetersonProtects #utpol |
passage: 469,578–578,347) lives could be lost to COVID-19 across the United States by 28 February 2021. |
query: "Seroprevalence studies may fail to detect people who have had mild covid-19. Consideration should be given to [...] calibration of assay thresholds, the breadth of the antibody response, and the role of mucosal antibodies" |
passage: was used to analyse the data. |
query: Rebuilding of October #Arctic sea ice volume spanning over the past 100 years... [Side-by-side look between PIOMAS-20C and PIOMAS data sets now refreshed through October 2021. Model details available at |
passage: title: Arctic Sea Ice Volume Variability over 1901–2010: A Model-Based Reconstruction |
| abstract: Abstract PIOMAS-20C, an Arctic sea ice reconstruction for 1901–2010, is produced by forcing the Pan-Arctic Ice Ocean Modeling and Assimilation System (PIOMAS) with ERA-20C atmospheric data. ERA-20C performance over Arctic sea ice is assessed by comparisons with measurements and data from other reanalyses. ERA-20C performs similarly with respect to the annual cycle of downwelling radiation, air temperature, and wind speed compared to reanalyses with more extensive data assimilation such as ERA-Interim and MERRA. PIOMAS-20C sea ice thickness and volume are then compared with in situ and aircraft remote sensing observations for the period of ~1950–2010. Error statistics are similar to those for PIOMAS. We compare the magnitude and patterns of sea ice variability between the first half of the twentieth century (1901–40) and the more recent period (1980–2010), both marked by sea ice decl... |
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
}
anchor and positive| anchor | positive | |
|---|---|---|
| type | string | string |
| details |
|
|
| anchor | positive |
|---|---|
query: I reckon we’ll be hearing more about plitidepsin, which (in vitro, at least) is 27.5 times stronger than remdesivir #COVID19 |
passage: title: Plitidepsin has potent preclinical efficacy against SARS-CoV-2 by targeting the host protein eEF1A |
query: 2020 research on #LongCovid. Pre‑vaccine era. “Young, low risk patients with ongoing symptoms of #covid19 had signs of damage to multiple organs four months after initially being infected.” |
passage: title: Long covid: Damage to multiple organs presents in young, low risk patients |
query: L'inflammation indépendante provoquée par les macrophages encourage-t-elle les lésions alvéolaires dans la COVID-19 ? |
passage: title: Does autonomous macrophage-driven inflammation promote alveolar damage in COVID-19? |
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: 64per_device_eval_batch_size: 64learning_rate: 1.6e-05num_train_epochs: 10warmup_ratio: 0.1fp16: Truedataloader_num_workers: 8overwrite_output_dir: Falsedo_predict: Falseprediction_loss_only: Trueper_device_train_batch_size: 64per_device_eval_batch_size: 64per_gpu_train_batch_size: Noneper_gpu_eval_batch_size: Nonegradient_accumulation_steps: 1eval_accumulation_steps: Nonetorch_empty_cache_steps: Nonelearning_rate: 1.6e-05weight_decay: 0.0adam_beta1: 0.9adam_beta2: 0.999adam_epsilon: 1e-08max_grad_norm: 1.0num_train_epochs: 10max_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: 8dataloader_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}parallelism_config: Nonedeepspeed: Nonelabel_smoothing_factor: 0.0optim: adamw_torch_fusedoptim_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: Falsehub_revision: Nonegradient_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: Falseliger_kernel_config: Noneeval_use_gather_object: Falseaverage_tokens_across_devices: Falseprompts: Nonebatch_sampler: batch_samplermulti_dataset_batch_sampler: proportionalrouter_mapping: {}learning_rate_mapping: {}| Epoch | Step | Training Loss | Validation Loss | CT26-dev-split_cosine_ndcg@10 |
|---|---|---|---|---|
| 0.3497 | 100 | 1.412 | - | - |
| 0.6993 | 200 | 0.4583 | - | - |
| 1.0 | 286 | - | 0.3687 | 0.8100 |
| 1.0490 | 300 | 0.4552 | - | - |
| 1.3986 | 400 | 0.3449 | - | - |
| 1.7483 | 500 | 0.334 | - | - |
| 2.0 | 572 | - | 0.3241 | 0.8166 |
| 2.0979 | 600 | 0.2666 | - | - |
| 2.4476 | 700 | 0.1872 | - | - |
| 2.7972 | 800 | 0.2041 | - | - |
| 3.0 | 858 | - | 0.3176 | 0.8194 |
| 3.1469 | 900 | 0.1789 | - | - |
| 3.4965 | 1000 | 0.1246 | - | - |
| 3.8462 | 1100 | 0.1279 | - | - |
| 4.0 | 1144 | - | 0.3149 | 0.8181 |
| 4.1958 | 1200 | 0.1071 | - | - |
| 4.5455 | 1300 | 0.0869 | - | - |
| 4.8951 | 1400 | 0.0895 | - | - |
| 5.0 | 1430 | - | 0.3100 | 0.8152 |
| 5.2448 | 1500 | 0.0773 | - | - |
| 5.5944 | 1600 | 0.0726 | - | - |
| 5.9441 | 1700 | 0.0767 | - | - |
| 6.0 | 1716 | - | 0.2971 | 0.8175 |
| 6.2937 | 1800 | 0.0625 | - | - |
| 6.6434 | 1900 | 0.06 | - | - |
| 6.9930 | 2000 | 0.0667 | - | - |
| 7.0 | 2002 | - | 0.2981 | 0.8210 |
| 7.3427 | 2100 | 0.0609 | - | - |
| 7.6923 | 2200 | 0.0549 | - | - |
| 8.0 | 2288 | - | 0.3009 | 0.8222 |
| 8.0420 | 2300 | 0.0503 | - | - |
| 8.3916 | 2400 | 0.0487 | - | - |
| 8.7413 | 2500 | 0.0498 | - | - |
| 9.0 | 2574 | - | 0.3020 | 0.8210 |
| 9.0909 | 2600 | 0.0456 | - | - |
| 9.4406 | 2700 | 0.0496 | - | - |
| 9.7902 | 2800 | 0.0521 | - | - |
| 10.0 | 2860 | - | 0.2993 | 0.8180 |
@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},
}
Base model
intfloat/multilingual-e5-large-instruct