Sentence-BERT: Sentence Embeddings using Siamese BERT-Networks
Paper • 1908.10084 • Published • 13
How to use sahithkumar7/mpnet-base-finetuned-iter01 with sentence-transformers:
from sentence_transformers import SentenceTransformer
model = SentenceTransformer("sahithkumar7/mpnet-base-finetuned-iter01")
sentences = [
"How many different active substances were detected in surface water across all catchment areas?",
"metabolites were not detected in the water bodies.\n2.1.1. Antibiotics/Enzyme-Inhibitors and\nAbacavir in Surface-Water\nFifty detections were found in all catchment areas in surface water, which corresponds to 15 different active substances:\n12 antibiotics, two enzyme inhibitors, and one antiviral. The number of detections per sampling station ranged from 0 to 7\ndifferent active substances. The Ave river-Prazins (Santo Tirso) and Serzedelo I and II (Guimar ã es) as well as Ria\nFormosa-coastal water (Faro and Olh ã o), each one with two sampling sites, showed the most detected compounds in",
"2. Results\n2.1. Frequency of Detections:\nAntibiotics/Enzyme-Inhibitors and Abacavir\nin Surface-Groundwater\nDuring the screening framework beyond the antibiotics/enzyme-inhibitors, the antiviral abacavir was detected. Therefore,\ngiven the relevance of this compound, it was included in the present study. Although enzyme inhibitors belong to the\nantibiotic group, their specific pharmacological properties and detection were sorted apart. In the present study, antibiotic\nmetabolites were not detected in the water bodies.\n2.1.1. Antibiotics/Enzyme-Inhibitors and\nAbacavir in Surface-Water",
"surface water. The relatively higher detection of substances downstream of the effluent discharge points compared with a\nlow detection in upstream samples could be attributed to the low efficiency in urban wastewater treatment plants or\nagricultural pressure. The environmental impact is more critical due to active substances in drinking water or premix\nmedicated feeds in the veterinary site.\nFurthermore, the detection of substances of exclusive human use (abacavir, tazobactam and cilastatin) prove the weak"
]
embeddings = model.encode(sentences)
similarities = model.similarity(embeddings, embeddings)
print(similarities.shape)
# [4, 4]This is a sentence-transformers model finetuned from microsoft/mpnet-base on the json dataset. It maps sentences & paragraphs to a 768-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': 512, 'do_lower_case': False, 'architecture': 'MPNetModel'})
(1): Pooling({'word_embedding_dimension': 768, '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})
)
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("sahithkumar7/mpnet-base-finetuned-iter01")
# Run inference
sentences = [
'What was the most frequently identified pharmaceutical in the groundwater samples?',
'from one to five compounds. The most frequently identified pharmaceuticals, in decreasing order, were ciprofloxacin 43%\n(3/7), enrofloxacin, norfloxacin, trimethoprim, lincomycin (29% (2/7), abacavir and tetracycline 14% (1/7). The enzyme\ninhibitors, namely clavulanic acid and cilastatin, were detected once in an urban region located well. This catchment point\nshowed the most significant number of pharmaceuticals. West/Tejo and Centre were the regions with the most\nconsiderable number of substances in groundwater, accounting for 43%. All groundwater samples were contaminated by',
'Pharmacokinetic characteristics may represent key features in understanding antibiotics occurrence [62]. Most antibiotics\nare not completely metabolised in humans and animals; thus, a high percentage of the active substance (40-90%) is\nexcreted in urine/faeces in the unchanged form. These molecules are discharged into water and soil through wastewater,\nanimal manure, and sewage sludge, frequently used as fertilisers to agricultural lands. Also, it is expected that the\nhospital effluent will contribute partly to the pharmaceutical load in the wastewater treatment plant influence [63].',
]
embeddings = model.encode(sentences)
print(embeddings.shape)
# [3, 768]
# Get the similarity scores for the embeddings
similarities = model.similarity(embeddings, embeddings)
print(similarities)
# tensor([[ 1.0000, 0.4988, -0.0391],
# [ 0.4988, 1.0000, 0.0047],
# [-0.0391, 0.0047, 1.0000]])
initial_test, final_test, final_test, final_test, final_test, final_test, final_test, final_test, final_test, final_test, final_test and final_testTripletEvaluator| Metric | initial_test | final_test |
|---|---|---|
| cosine_accuracy | 0.96 | 0.98 |
anchor, positive, and negative| anchor | positive | negative | |
|---|---|---|---|
| type | string | string | string |
| details |
|
|
|
| anchor | positive | negative |
|---|---|---|
Which two macrolide antibiotics are frequently detected in surface water samples? |
seems to undertake a similar fate in the environment. |
Nonetheless, besides the sorption capacity, these antibiotics have high solubility in water. Crucial routes for these |
What antimicrobial drugs were identified in the survey besides macrolides? |
is one of the most frequently pharmaceutical in representative rivers [74,75]. The three macrolides identified in our |
upstream samples obtained in rural locations was demonstrated and could be attributed to a low efficiency in the urban |
How long was the observational period of the antibiotic survey in Portugal? |
of antibiotics and their metabolites in surface- groundwater. It seeks to reflect the current demographic, spatial, drug |
despite being influenced by sorption processes. They were not readily degraded; instead, the input into groundwater |
MultipleNegativesRankingLoss with these parameters:{
"scale": 20.0,
"similarity_fct": "cos_sim"
}
anchor, positive, and negative| anchor | positive | negative | |
|---|---|---|---|
| type | string | string | string |
| details |
|
|
|
| anchor | positive | negative |
|---|---|---|
What percentage of unchanged excretion did the most significant number of detected substances show? |
coefficients were not available for lincomycin, clavulanic acid and cilastatin. |
1. Introduction |
How many kilograms of abacavir were detected in Portugal in 2017? |
Regarding the different regions, it has been concluded that North and West/Tejo were the regions with the higher |
43% |
What must marketing authorisation procedures for medicines include since 2006? |
substances in passive samplers [7]. Since 2006, marketing authorisation procedures for both human and veterinary |
clarithromycin/erythromycin, tetracycline, sulfamethoxazole, and abacavir. In groundwater, enrofloxacin/ciprofloxacin, |
MultipleNegativesRankingLoss with these parameters:{
"scale": 20.0,
"similarity_fct": "cos_sim"
}
eval_strategy: stepsper_device_train_batch_size: 16per_device_eval_batch_size: 16num_train_epochs: 1warmup_ratio: 0.1fp16: Truebatch_sampler: no_duplicatesoverwrite_output_dir: Falsedo_predict: Falseeval_strategy: stepsprediction_loss_only: Trueper_device_train_batch_size: 16per_device_eval_batch_size: 16per_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: 1max_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}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}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: no_duplicatesmulti_dataset_batch_sampler: proportionalrouter_mapping: {}learning_rate_mapping: {}| Epoch | Step | Training Loss | Validation Loss | initial_test_cosine_accuracy | final_test_cosine_accuracy |
|---|---|---|---|---|---|
| -1 | -1 | - | - | 0.7800 | - |
| 0.2 | 1 | 3.3315 | - | - | - |
| 0.4 | 2 | 3.0922 | - | - | - |
| 0.6 | 3 | 3.2635 | - | - | - |
| 0.8 | 4 | 3.0702 | - | - | - |
| 1.0 | 5 | 3.3282 | - | - | - |
| -1 | -1 | - | - | - | 0.6800 |
| 0.2 | 1 | 2.9487 | - | - | - |
| 0.4 | 2 | 2.9845 | - | - | - |
| 0.6 | 3 | 2.935 | - | - | - |
| 0.8 | 4 | 3.0702 | - | - | - |
| 1.0 | 5 | 3.0039 | - | - | - |
| 1.2 | 6 | 2.4806 | - | - | - |
| 1.4 | 7 | 2.2646 | - | - | - |
| 1.6 | 8 | 1.8101 | - | - | - |
| 1.8 | 9 | 1.3463 | - | - | - |
| 2.0 | 10 | 1.942 | - | - | - |
| -1 | -1 | - | - | - | 0.9000 |
| 0.2 | 1 | 2.2356 | - | - | - |
| 0.4 | 2 | 1.0123 | - | - | - |
| 0.6 | 3 | 1.2411 | - | - | - |
| 0.8 | 4 | 0.9194 | - | - | - |
| 1.0 | 5 | 0.891 | - | - | - |
| 1.2 | 6 | 0.602 | - | - | - |
| 1.4 | 7 | 0.5426 | - | - | - |
| 1.6 | 8 | 0.5738 | - | - | - |
| 1.8 | 9 | 0.2678 | - | - | - |
| 2.0 | 10 | 0.7113 | - | - | - |
| 2.2 | 11 | 0.2911 | - | - | - |
| 2.4 | 12 | 0.4745 | - | - | - |
| 2.6 | 13 | 0.4188 | - | - | - |
| 2.8 | 14 | 0.3708 | - | - | - |
| 3.0 | 15 | 0.2882 | - | - | - |
| -1 | -1 | - | - | - | 0.9200 |
| 0.2 | 1 | 0.5156 | - | - | - |
| 0.4 | 2 | 0.0749 | - | - | - |
| 0.6 | 3 | 0.0634 | - | - | - |
| 0.8 | 4 | 0.0534 | - | - | - |
| 1.0 | 5 | 0.019 | - | - | - |
| 1.2 | 6 | 0.0682 | - | - | - |
| 1.4 | 7 | 0.0381 | - | - | - |
| 1.6 | 8 | 0.171 | - | - | - |
| 1.8 | 9 | 0.1188 | - | - | - |
| 2.0 | 10 | 0.1861 | - | - | - |
| 2.2 | 11 | 0.0895 | - | - | - |
| 2.4 | 12 | 0.2492 | - | - | - |
| 2.6 | 13 | 0.0964 | - | - | - |
| 2.8 | 14 | 0.2424 | - | - | - |
| 3.0 | 15 | 0.1096 | - | - | - |
| 3.2 | 16 | 0.1981 | - | - | - |
| 3.4 | 17 | 0.1438 | - | - | - |
| 3.6 | 18 | 0.3454 | - | - | - |
| 3.8 | 19 | 0.4011 | - | - | - |
| 4.0 | 20 | 0.1591 | 0.5567 | 0.9400 | - |
| -1 | -1 | - | - | - | 0.9400 |
| 0.125 | 1 | 0.0594 | - | - | - |
| 0.25 | 2 | 0.0584 | - | - | - |
| 0.375 | 3 | 0.0146 | - | - | - |
| 0.5 | 4 | 0.0542 | - | - | - |
| 0.625 | 5 | 0.0965 | - | - | - |
| 0.75 | 6 | 0.2209 | - | - | - |
| 0.875 | 7 | 0.0312 | - | - | - |
| 1.0 | 8 | 0.1142 | - | - | - |
| -1 | -1 | - | - | - | 0.9600 |
| 0.125 | 1 | 0.0082 | - | - | - |
| 0.25 | 2 | 0.004 | - | - | - |
| 0.375 | 3 | 0.001 | - | - | - |
| 0.5 | 4 | 0.0118 | - | - | - |
| 0.625 | 5 | 0.0508 | - | - | - |
| 0.75 | 6 | 0.0816 | - | - | - |
| 0.875 | 7 | 0.0149 | - | - | - |
| 1.0 | 8 | 0.0163 | - | - | - |
| 1.125 | 9 | 0.038 | - | - | - |
| 1.25 | 10 | 0.0618 | - | - | - |
| 1.375 | 11 | 0.0097 | - | - | - |
| 1.5 | 12 | 0.0368 | - | - | - |
| 1.625 | 13 | 0.0212 | - | - | - |
| 1.75 | 14 | 0.0072 | - | - | - |
| 1.875 | 15 | 0.0037 | - | - | - |
| 2.0 | 16 | 0.128 | - | - | - |
| -1 | -1 | - | - | - | 0.9600 |
| 0.125 | 1 | 0.0012 | - | - | - |
| 0.25 | 2 | 0.0003 | - | - | - |
| 0.375 | 3 | 0.0008 | - | - | - |
| 0.5 | 4 | 0.0008 | - | - | - |
| 0.625 | 5 | 0.0013 | - | - | - |
| 0.75 | 6 | 0.0743 | - | - | - |
| 0.875 | 7 | 0.0024 | - | - | - |
| 1.0 | 8 | 0.001 | - | - | - |
| 1.125 | 9 | 0.0024 | - | - | - |
| 1.25 | 10 | 0.01 | - | - | - |
| 1.375 | 11 | 0.0009 | - | - | - |
| 1.5 | 12 | 0.1912 | - | - | - |
| 1.625 | 13 | 0.0024 | - | - | - |
| 1.75 | 14 | 0.002 | - | - | - |
| 1.875 | 15 | 0.0038 | - | - | - |
| 2.0 | 16 | 0.1492 | - | - | - |
| 2.125 | 17 | 0.004 | - | - | - |
| 2.25 | 18 | 0.0123 | - | - | - |
| 2.375 | 19 | 0.0348 | - | - | - |
| 2.5 | 20 | 0.0068 | 0.5351 | 0.9600 | - |
| 2.625 | 21 | 0.1679 | - | - | - |
| 2.75 | 22 | 0.0123 | - | - | - |
| 2.875 | 23 | 0.0934 | - | - | - |
| 3.0 | 24 | 0.0048 | - | - | - |
| -1 | -1 | - | - | - | 0.9600 |
| 0.2 | 1 | 0.0763 | - | - | - |
| 0.4 | 2 | 0.0119 | - | - | - |
| 0.6 | 3 | 0.0019 | - | - | - |
| 0.8 | 4 | 0.0034 | - | - | - |
| 1.0 | 5 | 0.001 | - | - | - |
| -1 | -1 | - | - | - | 0.9800 |
@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
microsoft/mpnet-base