Sentence-BERT: Sentence Embeddings using Siamese BERT-Networks
Paper • 1908.10084 • Published • 16
How to use semaj83/ctmatch-retriever-v2 with sentence-transformers:
from sentence_transformers import SentenceTransformer
model = SentenceTransformer("semaj83/ctmatch-retriever-v2")
sentences = [
"A 57-year-old man was admitted to the clinic because of weight loss and persistent dry cough 4 months ago. Chest computed topography showed bilateral multiple infiltrates in the upper lobes and thickened bronchial walls. There is a documented positive serum MPO-ANCA in his medical record. Transbronchial biopsy revealed necrotic granulomas with multinucleated giant cells and the Wegener's granulomatosis was diagnosed for him. He is treating with corticosteroid and cyclophosphamides since 4 months ago. His Birmingham Vasculitis Activity Score (BVAS) is above 4 since the beginning of his disease. His last physical exam and lab study was performed yesterday and showed the results bellow: A wellbeing, well-nourished man, non-icteric, cooperative and alert Weight: 73 kg Height: 177 BP: 120/80 HR: 90/min RR: 22/min Hgb: 13 g/dl WBC: 8000 /mm3 (Neutrophil: 2700/mm3) Plt: 300000 /ml AST: 40 U/L ALT: 56 U/L Alk P: 147 U/L Bill total: 1.2 mg/dl ESR: 120 mm/hr MPO-ANCA: 153 EU",
"Inclusion Criteria: Adult participants, >/= 18 years of age Granulomatosis with polyangiitis (GPA) or microscopic polyangiitis (MPA), according to Chapel Hill Consensus Conference Definitions for MPA and American College of Rheumatology (ACR) for the Classification of GPA Disease severity requiring rituximab treatment per the investigator's assessment, Exclusion Criteria: Prior use of rituximab (except if received within 4 weeks of screening) Known hypersensitivity to rituximab, to any component of the product, or to murine proteins Pregnant or breastfeeding women Diagnosis of Churg-Strauss syndrome",
"Inclusion Criteria: Body mass index (BMI) >40 Kg/m2 BMI >35 Kg/m2 and obesity associated comorbidities Patients undergoing laparoscopic Roux en Y gastric bypass, Exclusion Criteria: Patients undergoing other bariatric procedures, different than Roux en Y gastric bypass Patients undergoing open bariatric surgery",
"Inclusion Criteria: Patient is male or female ≥18 years of age 2. Patient voluntarily signed written, informed consent agreement. 3. If patient is female and not more than 1 year post-menopausal, or surgically sterile, must use medically accepted form of contraception or abstain from sexual activities during study 4. Patient has acute pancreatitis as defined by the Atlanta Classification of 2012 5. No evidence of obstructive pancreatitis on available cross-sectional imaging, Exclusion Criteria: Pancreatitis with duct obstruction or severe acute pancreatitis defined by Atlanta Classification 2. Pregnant woman, nursing mothers, or women of childbearing potential not on birth control 3. Known adverse reaction to human secretin"
]
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 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': 'BertModel'})
(1): Pooling({'embedding_dimension': 384, '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("semaj83/ctmatch-retriever-v2")
# Run inference
sentences = [
"A 39-year-old man came to the clinic with cough and shortness of breath that was not relieved by his inhaler. He had these symptoms for 5 days during the past 2 weeks. He doubled his oral corticosteroids in the past week. He is a chef with a history of asthma for 3 years, suffering from frequent cough, wheezing, and shortness of breath and chest tightness. The symptoms become more bothersome within 1-2 hours of starting work every day and worsen throughout the work week. His symptoms improve within 1-2 hours outside the workplace. Spirometry was performed revealing a forced expiratory volume in the first second (FEV1) of 63% of the predicted. His past medical history is significant for seasonal allergic rhinitis in the summer. He doesn't smoke or use illicit drugs. His family history is significant for asthma in his father and sister. He currently uses inhaled corticosteroid (ICS) and fluticasone 500 mcg/salmeterol 50 mcg, one puff twice daily.",
'Inclusion Criteria: for all subjects Age between 18 and 45 years old Smoking history ≤2 packyears. Specific for the two groups Group 1. Patients with ongoing asthma Age of onset of asthmatic symptoms: 0 years Documented history of asthma diagnosed according to latest GINA guidelines, i.e. respiratory symptoms and either bronchodilator reversibility (improvement in FEV1 of more than 12% of baseline (and at least 200 mL) after inhalation of 800 µg salbutamol) Use of inhaled corticosteroids or either persistent symptoms of wheeze, cough, or dyspnea or regular use of β2 agonists at least once a week during the last 2 months PC20 methacholine < 8 mg/ml Group 2. Non-asthmatic controls No history of asthma No use of inhaled corticosteroids or β2-agonists for a period longer than 1 month No symptoms of wheeze, nocturnal dyspnea, or bronchial hyperresponsiveness PC20 methacholine > 8 mg/ml, FEV1/FVC > 70% and FEV1 > 80% predicted, Exclusion Criteria: FEV1 <1.2 L Subjects must be able to adhere to the study visit schedule and other protocol requirements A subject is not eligible to enter and participate if he has not signed and dated a written informed consent form prior to participation in the study A subjects is not eligible to enter and participate if he does not agree that we inform his general practitioner Upper respiratory tract infection (e.g. colds), within 6 weeks Serious acute infections (such as hepatitis, pneumonia or pyelonephritis) in the previous 3 months Signs or symptoms of severe, progressive or uncontrolled renal, hepatic, hematologic, endocrine, pulmonary, cardiac, neurologic or cerebral disease Malignancy within the past 5 years (except for squamous or basal cell carcinoma of the skin that has been treated with no evidence of recurrence) Known recent substance abuse (drug or alcohol) Females of childbearing potential without an efficient contraception unless they meet the following definition of post-menopausal: 12 months of natural (spontaneous) amenorrhea or 6 months of spontaneous amenorrhea with serum FSH >40 mIU/mL or the use of one or more of the following acceptable methods of contraception: 1. Surgical sterilization (e.g. bilateral tubal ligation, hysterectomy). 2. Hormonal contraception (implantable, patch, oral, injectable). 3. Barrier methods of contraception: condom or occlusive cap (diaphragm or cervical/vault caps) with spermicidal foam/gel/cream/suppository. 4. Continuous abstinence',
'Inclusion Criteria: Type 1 diabetes mellitus (T1DM) for at least 1 year and using insulin glargine for at least 6 months with a maximum daily dose of 1 unit per kilogram (U/kg) Hemoglobin A1c (HbA1c) of no greater than 10.5% before randomization Body mass index (BMI) 19 to 45 kilogram per square meter (kg/m²) Capable and willing to prepare and inject insulin with a syringe, monitor own blood glucose, complete the study diary, be receptive to diabetes education, comply with study requirements, and receive telephone calls during treatment Women of childbearing potential must test negative for pregnancy before receiving treatment and agree to use reliable birth control until completing the follow-up, Exclusion Criteria: Twice daily use of insulin glargine within 30 days prior to the study Use of any oral or injectable medication intended for the treatment of diabetes mellitus other than insulins in the 3 months prior to the study Use of an insulin pump More than 1 episode of severe hypoglycemia within 3 months prior to the study, or currently diagnosed as having hypoglycemia unawareness or more emergency room visits or hospitalizations due to poor glucose control in the 6 months preceding the study Known hypersensitivity or allergy to any of the study insulins or their excipients Blood transfusion or severe blood loss within 3 months prior to the study or known hemoglobinopathy, hemolytic anemia, or sickle cell anemia, or any other traits of hemoglobin abnormalities known to interfere with the HbA1c methodology Irregular sleep/wake cycle Pregnant or intend to become pregnant during the study Women who are breastfeeding Use of prescription or over-the-counter medications to promote weight loss within 3 months prior to the study Current participation in a weight loss program or plans to do so during the study Use of chronic (lasting longer than 14 consecutive days) systemic glucocorticoid therapy currently or within 4 weeks prior to the study Cardiac disease with a marked impact on physical functioning Clinically significant electrocardiogram (ECG) abnormalities at screening Fasting triglycerides greater than 500 milligram per deciliter (mg/dL) Liver disease History of renal transplantation, current renal dialysis, or creatinine greater than 2.0 mg/dL (177 micromole per liter [μmol/L]) Malignancy other than basal cell or squamous cell skin cancer, currently or within the last 5 years Treatment with any antibody-based therapy within 6 months prior to the study',
]
embeddings = model.encode(sentences)
print(embeddings.shape)
# [3, 384]
# Get the similarity scores for the embeddings
similarities = model.similarity(embeddings, embeddings)
print(similarities)
# tensor([[1.0000, 0.7314, 0.2627],
# [0.7314, 1.0000, 0.2874],
# [0.2627, 0.2874, 1.0000]])
sentence_0 and sentence_1| sentence_0 | sentence_1 | |
|---|---|---|
| type | string | string |
| modality | text | text |
| details |
|
|
| sentence_0 | sentence_1 |
|---|---|
Patient A is a 30-year-old male who was admitted to the hospital after 10 days of cough, profuse nocturnal sweating and loss of appetite. He had traveled to India 1 months ago and has not any positive history of TB vaccination. He is a previously healthy man, working as an engineer in a high tech company. He doesn't smoke o use any illicit drugs. He was febrile (38 c) with heart rate of 115 b/min, respiratory rate of 22, BP of 125/75 mmHg and O2 sat of 97%. Chest X-ray showed infiltrate in the middle of left lung with diameter of 1.8 cm with signs of cavitation. The sputum smear revealed positive sputum culture for Mycobacterium tuberculosis which are sensitive of the first-line TB drugs (isoniazid, streptomycin, rifampicin and ethambutol). Lab study is reported bellow: Hgb: 13 g/dl WBC: 14000 /mm3 Plt: 300000 /ml AST: 13 U/L ALT: 15 U/L Alk P: 53 U/L Bill total: 0.6 mg/dl Na: 137 mEq/l K: 4 mEq/l Creatinine: 0.5 mg/dl BUN: 10 mg/dl ESR: 120 mm/hr |
Inclusion Criteria: Any patient requiring Tuberculosis treatment, Exclusion Criteria: Those refusing consent; the healthcare professional deems the patient that will not be able to comply with VOT |
A 44-year-old man was recently in an automobile accident where he sustained a skull fracture. In the emergency room, he noted clear fluid dripping from his nose. The following day he started complaining of severe headache and fever. Nuchal rigidity was found on physical examination. |
Inclusion Criteria: Probable bacterial meningitis patients: Clinical manifestation (Any person with sudden onset of fever (> 38.5 °C rectal or 38.0 °C axillary) and one of the following signs: neck stiffness, altered consciousness or other meningeal sign) with cerebrospinal fluid examination showing at least one of the following: A. turbid appearance; B.leukocytosis (> 100 cells/mm3); C.leukocytosis (10-100 cells/ mm3) AND either an elevated protein (> 100 mg/dl) or decreased glucose (< 40 mg/dl) Confirmed bacterial meningitis patients: A case that is laboratory-confirmed by growing (i.e. culturing) or identifying (i.e. by Gram stain or antigen detection methods) a bacterial pathogen (Hib, pneumococcus or meningococcus) in the cerebrospinal fluid or from the blood in a child with a clinical syndrome consistent with bacterial meningitis, Exclusion Criteria: Congenital immunodeficiency patients HIV patients Patients with corticosteroid treatment for long time Patients with disorders in a... |
A 38 year old woman complains of severe premenstrual and menstrual pelvic pain, heavy, irregular periods and occasional spotting between periods. Past medical history remarkable for two years of infertility treatment and an ectopic pregnancy at age 26. |
Inclusion Criteria: female >18 years fluent German Cases: diagnosis of endometriosis Control 1: no endometriosis, no chronic pain Control 2: no endometriosis, chronic abdominal/pelvic pain, Exclusion Criteria: male (Except for partner questionnaires) <18years not fluent in German |
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: 64multi_dataset_batch_sampler: round_robinper_device_train_batch_size: 64num_train_epochs: 3max_steps: -1learning_rate: 5e-05lr_scheduler_type: linearlr_scheduler_kwargs: Nonewarmup_steps: 0optim: adamw_torch_fusedoptim_args: Noneweight_decay: 0.0adam_beta1: 0.9adam_beta2: 0.999adam_epsilon: 1e-08optim_target_modules: Nonegradient_accumulation_steps: 1average_tokens_across_devices: Truemax_grad_norm: 1label_smoothing_factor: 0.0bf16: Falsefp16: Falsebf16_full_eval: Falsefp16_full_eval: Falsetf32: Nonegradient_checkpointing: Falsegradient_checkpointing_kwargs: Nonetorch_compile: Falsetorch_compile_backend: Nonetorch_compile_mode: Noneuse_liger_kernel: Falseliger_kernel_config: Noneuse_cache: Falseneftune_noise_alpha: Nonetorch_empty_cache_steps: Noneauto_find_batch_size: Falselog_on_each_node: Truelogging_nan_inf_filter: Trueinclude_num_input_tokens_seen: nolog_level: passivelog_level_replica: warningdisable_tqdm: Falseproject: huggingfacetrackio_space_id: Nonetrackio_bucket_id: Nonetrackio_static_space_id: Noneper_device_eval_batch_size: 64prediction_loss_only: Trueeval_on_start: Falseeval_do_concat_batches: Trueeval_use_gather_object: Falseeval_accumulation_steps: Noneinclude_for_metrics: []batch_eval_metrics: Falsesave_only_model: Falsesave_on_each_node: Falseenable_jit_checkpoint: Falsepush_to_hub: Falsehub_private_repo: Nonehub_model_id: Nonehub_strategy: every_savehub_always_push: Falsehub_revision: Noneload_best_model_at_end: Falseignore_data_skip: Falserestore_callback_states_from_checkpoint: Falsefull_determinism: Falseseed: 42data_seed: Noneuse_cpu: Falseaccelerator_config: {'split_batches': False, 'dispatch_batches': None, 'even_batches': True, 'use_seedable_sampler': True, 'non_blocking': False, 'gradient_accumulation_kwargs': None}parallelism_config: Nonedataloader_drop_last: Falsedataloader_num_workers: 0dataloader_pin_memory: Truedataloader_persistent_workers: Falsedataloader_prefetch_factor: Noneremove_unused_columns: Truelabel_names: Nonetrain_sampling_strategy: randomlength_column_name: lengthddp_find_unused_parameters: Noneddp_bucket_cap_mb: Noneddp_broadcast_buffers: Falseddp_static_graph: Noneddp_backend: Noneddp_timeout: 1800fsdp: Nonefsdp_config: Nonedeepspeed: Nonedebug: []skip_memory_metrics: Truedo_predict: Falseresume_from_checkpoint: Nonewarmup_ratio: Nonelocal_rank: -1prompts: Nonebatch_sampler: batch_samplermulti_dataset_batch_sampler: round_robinrouter_mapping: {}learning_rate_mapping: {}@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
nreimers/MiniLM-L6-H384-uncased