Sentence-BERT: Sentence Embeddings using Siamese BERT-Networks
Paper
•
1908.10084
•
Published
•
9
This is a sentence-transformers model finetuned from google-bert/bert-base-cased on the csv 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': 'BertModel'})
(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("cafierom/905_Statin_Contrastive")
# Run inference
sentences = [
'CC(C)n1c(CC[C@@H](O)C[C@@H](O)CC([O-])=O)c(c(c1C(=O)NCc1cccc(c1)C(N)=O)-c1ccccc1)-c1ccc(F)cc1',
'CC(C)c1nc(c(-c2ccc(F)cc2)n1\\C=C\\[C@@H](O)C[C@@H](O)CC(O)=O)-c1ccc(F)cc1',
'CCn1nnc(n1)C(\\C=C\\[C@@H](O)C[C@@H](O)CC([O-])=O)=C(c1ccc(F)cc1)c1ccc(F)cc1',
]
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.9994, -0.0483],
# [ 0.9994, 1.0000, -0.0453],
# [-0.0483, -0.0453, 1.0000]])
premise, hypothesis, and label| premise | hypothesis | label | |
|---|---|---|---|
| type | string | string | int |
| details |
|
|
|
SoftmaxLosspremise, hypothesis, and label| premise | hypothesis | label | |
|---|---|---|---|
| type | string | string | int |
| details |
|
|
|
| premise | hypothesis | label |
|---|---|---|
COC(=O)CC@HCC@H\C=C\n1c(C(C)C)c(Br)c(c1-c1ccc(F)cc1)-c1ccc(F)cc1 |
CC@H[C@H]1CC[C@H]2[C@@H]3C@@HOC(C)=O |
2 |
CC(C)n1c(CCC@@HCC@@HCC([O-])=O)c(c(c1C(=O)Nc1ccc(O)cc1)-c1ccccc1)-c1ccc(F)cc1 |
CCC@HC(=O)O[C@H]1CC@HC=C2C=CC@HC@H[C@@H]12 |
0 |
CC(C)C(=O)O[C@H]1CC@@HC=C2C=CC@HC@HC12 |
CC(C)c1c(nc(-c2ccc(F)cc2)n1\C=C[C@@H](O)CC@@HCC([O-])=O)-c1ccc(F)cc1 |
0 |
SoftmaxLossper_device_train_batch_size: 128per_device_eval_batch_size: 128weight_decay: 0.01num_train_epochs: 10warmup_steps: 100fp16: Trueoverwrite_output_dir: Falsedo_predict: Falseeval_strategy: noprediction_loss_only: Trueper_device_train_batch_size: 128per_device_eval_batch_size: 128per_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.01adam_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.0warmup_steps: 100log_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}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 |
|---|---|---|
| 0.1094 | 100 | 0.4346 |
| 0.2188 | 200 | 0.0656 |
| 0.3282 | 300 | 0.0082 |
| 0.4376 | 400 | 0.007 |
| 0.5470 | 500 | 0.0056 |
| 0.6565 | 600 | 0.0054 |
| 0.7659 | 700 | 0.0006 |
| 0.8753 | 800 | 0.0005 |
| 0.9847 | 900 | 0.0004 |
| 1.0941 | 1000 | 0.0004 |
| 1.2035 | 1100 | 0.0003 |
| 1.3129 | 1200 | 0.0003 |
| 1.4223 | 1300 | 0.0003 |
| 1.5317 | 1400 | 0.0003 |
| 1.6411 | 1500 | 0.0002 |
| 1.7505 | 1600 | 0.0002 |
| 1.8600 | 1700 | 0.0002 |
| 1.9694 | 1800 | 0.0002 |
| 2.0788 | 1900 | 0.0002 |
| 2.1882 | 2000 | 0.0002 |
| 2.2976 | 2100 | 0.0001 |
| 2.4070 | 2200 | 0.0001 |
| 2.5164 | 2300 | 0.0001 |
| 2.6258 | 2400 | 0.0001 |
| 2.7352 | 2500 | 0.0001 |
| 2.8446 | 2600 | 0.0001 |
| 2.9540 | 2700 | 0.0001 |
| 3.0635 | 2800 | 0.0001 |
| 3.1729 | 2900 | 0.0001 |
| 3.2823 | 3000 | 0.0001 |
| 3.3917 | 3100 | 0.0001 |
| 3.5011 | 3200 | 0.0001 |
| 3.6105 | 3300 | 0.0001 |
| 3.7199 | 3400 | 0.0001 |
| 3.8293 | 3500 | 0.0001 |
| 3.9387 | 3600 | 0.0001 |
| 4.0481 | 3700 | 0.0001 |
| 4.1575 | 3800 | 0.0001 |
| 4.2670 | 3900 | 0.0001 |
| 4.3764 | 4000 | 0.0 |
| 4.4858 | 4100 | 0.0 |
| 4.5952 | 4200 | 0.0 |
| 4.7046 | 4300 | 0.0 |
| 4.8140 | 4400 | 0.0 |
| 4.9234 | 4500 | 0.0 |
| 5.0328 | 4600 | 0.0 |
| 5.1422 | 4700 | 0.0 |
| 5.2516 | 4800 | 0.0 |
| 5.3611 | 4900 | 0.0 |
| 5.4705 | 5000 | 0.0 |
| 5.5799 | 5100 | 0.0 |
| 5.6893 | 5200 | 0.0 |
| 5.7987 | 5300 | 0.0 |
| 5.9081 | 5400 | 0.0 |
| 6.0175 | 5500 | 0.0002 |
| 6.1269 | 5600 | 0.0 |
| 6.2363 | 5700 | 0.0 |
| 6.3457 | 5800 | 0.0 |
| 6.4551 | 5900 | 0.0 |
| 6.5646 | 6000 | 0.0 |
| 6.6740 | 6100 | 0.0 |
| 6.7834 | 6200 | 0.0 |
| 6.8928 | 6300 | 0.0 |
| 7.0022 | 6400 | 0.0 |
| 7.1116 | 6500 | 0.0 |
| 7.2210 | 6600 | 0.0 |
| 7.3304 | 6700 | 0.0 |
| 7.4398 | 6800 | 0.0 |
| 7.5492 | 6900 | 0.0 |
| 7.6586 | 7000 | 0.0 |
| 7.7681 | 7100 | 0.0 |
| 7.8775 | 7200 | 0.0 |
| 7.9869 | 7300 | 0.0 |
| 8.0963 | 7400 | 0.0 |
| 8.2057 | 7500 | 0.0 |
| 8.3151 | 7600 | 0.0 |
| 8.4245 | 7700 | 0.0 |
| 8.5339 | 7800 | 0.0 |
| 8.6433 | 7900 | 0.0 |
| 8.7527 | 8000 | 0.0 |
| 8.8621 | 8100 | 0.0 |
| 8.9716 | 8200 | 0.0 |
| 9.0810 | 8300 | 0.0022 |
| 9.1904 | 8400 | 0.0019 |
| 9.2998 | 8500 | 0.0001 |
| 9.4092 | 8600 | 0.0 |
| 9.5186 | 8700 | 0.0 |
| 9.6280 | 8800 | 0.0 |
| 9.7374 | 8900 | 0.0 |
| 9.8468 | 9000 | 0.0 |
| 9.9562 | 9100 | 0.0 |
@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",
}
Base model
google-bert/bert-base-cased