Sentence-BERT: Sentence Embeddings using Siamese BERT-Networks
Paper
•
1908.10084
•
Published
•
9
This is a sentence-transformers model trained. 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}) with Transformer model: BertModel
(1): Pooling({'word_embedding_dimension': 768, 'pooling_mode_cls_token': True, 'pooling_mode_mean_tokens': False, '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("Detomo/cl-nagoya-sup-simcse-ja-nss-v_1_0_5")
# Run inference
sentences = [
'科目:タイル。名称:床磁器質タイル。',
'科目:ユニット及びその他。名称:#F薬渡し窓口カウンター。',
'科目:ユニット及びその他。名称:F-#c教員棚。',
]
embeddings = model.encode(sentences)
print(embeddings.shape)
# [3, 768]
# Get the similarity scores for the embeddings
similarities = model.similarity(embeddings, embeddings)
print(similarities.shape)
# [3, 3]
sentence and label| sentence | label | |
|---|---|---|
| type | string | int |
| details |
|
|
| sentence | label |
|---|---|
科目:コンクリート。名称:免震基礎天端グラウト注入。 |
0 |
科目:コンクリート。名称:免震基礎天端グラウト注入。 |
0 |
科目:コンクリート。名称:免震基礎天端グラウト注入。 |
0 |
sentence_transformer_lib.custom_batch_all_trip_loss.CustomBatchAllTripletLossper_device_train_batch_size: 512per_device_eval_batch_size: 512learning_rate: 1e-05weight_decay: 0.01num_train_epochs: 250warmup_ratio: 0.2fp16: Truebatch_sampler: group_by_labeloverwrite_output_dir: Falsedo_predict: Falseeval_strategy: noprediction_loss_only: Trueper_device_train_batch_size: 512per_device_eval_batch_size: 512per_gpu_train_batch_size: Noneper_gpu_eval_batch_size: Nonegradient_accumulation_steps: 1eval_accumulation_steps: Nonetorch_empty_cache_steps: Nonelearning_rate: 1e-05weight_decay: 0.01adam_beta1: 0.9adam_beta2: 0.999adam_epsilon: 1e-08max_grad_norm: 1.0num_train_epochs: 250max_steps: -1lr_scheduler_type: linearlr_scheduler_kwargs: {}warmup_ratio: 0.2warmup_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}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: group_by_labelmulti_dataset_batch_sampler: proportional| Epoch | Step | Training Loss |
|---|---|---|
| 2.24 | 50 | 0.0583 |
| 4.48 | 100 | 0.0626 |
| 6.72 | 150 | 0.0638 |
| 9.08 | 200 | 0.0659 |
| 11.32 | 250 | 0.0629 |
| 13.56 | 300 | 0.0608 |
| 15.8 | 350 | 0.0607 |
| 18.16 | 400 | 0.0584 |
| 20.4 | 450 | 0.0577 |
| 22.64 | 500 | 0.0566 |
| 24.88 | 550 | 0.0594 |
| 27.24 | 600 | 0.0552 |
| 29.48 | 650 | 0.0512 |
| 31.72 | 700 | 0.053 |
| 34.08 | 750 | 0.0538 |
| 36.32 | 800 | 0.0506 |
| 38.56 | 850 | 0.054 |
| 40.8 | 900 | 0.0498 |
| 43.16 | 950 | 0.0538 |
| 45.4 | 1000 | 0.0491 |
| 47.64 | 1050 | 0.0445 |
| 49.88 | 1100 | 0.0466 |
| 52.24 | 1150 | 0.0458 |
| 54.48 | 1200 | 0.0507 |
| 56.72 | 1250 | 0.0408 |
| 59.08 | 1300 | 0.0462 |
| 61.32 | 1350 | 0.0443 |
| 63.56 | 1400 | 0.0392 |
| 65.8 | 1450 | 0.0389 |
| 68.16 | 1500 | 0.0455 |
| 70.4 | 1550 | 0.049 |
| 72.64 | 1600 | 0.0435 |
| 74.88 | 1650 | 0.0416 |
| 77.24 | 1700 | 0.041 |
| 79.48 | 1750 | 0.0443 |
| 81.72 | 1800 | 0.0423 |
| 84.08 | 1850 | 0.0457 |
| 86.32 | 1900 | 0.0375 |
| 88.56 | 1950 | 0.0428 |
| 90.8 | 2000 | 0.037 |
| 93.16 | 2050 | 0.0441 |
| 95.4 | 2100 | 0.0382 |
| 97.64 | 2150 | 0.0424 |
| 99.88 | 2200 | 0.041 |
| 1.6667 | 50 | 0.0381 |
| 3.6111 | 100 | 0.0373 |
| 5.5556 | 150 | 0.0381 |
| 7.5 | 200 | 0.0394 |
| 9.4444 | 250 | 0.0399 |
| 11.3889 | 300 | 0.0405 |
| 13.3333 | 350 | 0.0409 |
| 15.2778 | 400 | 0.0408 |
| 17.2222 | 450 | 0.0404 |
| 19.1667 | 500 | 0.0396 |
| 21.1111 | 550 | 0.038 |
| 23.0556 | 600 | 0.0346 |
| 24.7222 | 650 | 0.0381 |
| 26.6667 | 700 | 0.0356 |
| 28.6111 | 750 | 0.0344 |
| 30.5556 | 800 | 0.0344 |
| 32.5 | 850 | 0.0365 |
| 34.4444 | 900 | 0.0354 |
| 36.3889 | 950 | 0.0324 |
| 38.3333 | 1000 | 0.0301 |
| 40.2778 | 1050 | 0.038 |
| 42.2222 | 1100 | 0.0351 |
| 44.1667 | 1150 | 0.0344 |
| 46.1111 | 1200 | 0.0339 |
| 48.0556 | 1250 | 0.0358 |
| 49.7222 | 1300 | 0.0312 |
| 51.6667 | 1350 | 0.0278 |
| 53.6111 | 1400 | 0.0342 |
| 55.5556 | 1450 | 0.0291 |
| 57.5 | 1500 | 0.03 |
| 59.4444 | 1550 | 0.03 |
| 61.3889 | 1600 | 0.0303 |
| 63.3333 | 1650 | 0.0339 |
| 65.2778 | 1700 | 0.0342 |
| 67.2222 | 1750 | 0.0283 |
| 69.1667 | 1800 | 0.0271 |
| 71.1111 | 1850 | 0.0327 |
| 73.0556 | 1900 | 0.0296 |
| 74.7222 | 1950 | 0.0295 |
| 76.6667 | 2000 | 0.0259 |
| 78.6111 | 2050 | 0.0296 |
| 80.5556 | 2100 | 0.0256 |
| 82.5 | 2150 | 0.0271 |
| 84.4444 | 2200 | 0.0287 |
| 86.3889 | 2250 | 0.028 |
| 88.3333 | 2300 | 0.0275 |
| 90.2778 | 2350 | 0.0294 |
| 92.2222 | 2400 | 0.0243 |
| 94.1667 | 2450 | 0.0275 |
| 96.1111 | 2500 | 0.0258 |
| 98.0556 | 2550 | 0.0215 |
| 99.7222 | 2600 | 0.0252 |
| 101.6667 | 2650 | 0.029 |
| 103.6111 | 2700 | 0.0265 |
| 105.5556 | 2750 | 0.0258 |
| 107.5 | 2800 | 0.0222 |
| 109.4444 | 2850 | 0.0263 |
| 111.3889 | 2900 | 0.0266 |
| 113.3333 | 2950 | 0.0211 |
| 115.2778 | 3000 | 0.0251 |
| 117.2222 | 3050 | 0.0224 |
| 119.1667 | 3100 | 0.0204 |
| 121.1111 | 3150 | 0.0226 |
| 123.0556 | 3200 | 0.025 |
| 124.7222 | 3250 | 0.0214 |
| 126.6667 | 3300 | 0.0237 |
| 128.6111 | 3350 | 0.0287 |
| 130.5556 | 3400 | 0.0229 |
| 132.5 | 3450 | 0.0171 |
| 134.4444 | 3500 | 0.0215 |
| 136.3889 | 3550 | 0.0236 |
| 138.3333 | 3600 | 0.0238 |
| 140.2778 | 3650 | 0.0168 |
| 142.2222 | 3700 | 0.0281 |
| 144.1667 | 3750 | 0.0247 |
| 146.1111 | 3800 | 0.02 |
| 148.0556 | 3850 | 0.0225 |
| 149.7222 | 3900 | 0.0189 |
| 151.6667 | 3950 | 0.0178 |
| 153.6111 | 4000 | 0.0174 |
| 155.5556 | 4050 | 0.0165 |
| 157.5 | 4100 | 0.0197 |
| 159.4444 | 4150 | 0.0226 |
| 161.3889 | 4200 | 0.0126 |
| 163.3333 | 4250 | 0.0224 |
| 165.2778 | 4300 | 0.0174 |
| 167.2222 | 4350 | 0.0214 |
| 169.1667 | 4400 | 0.0159 |
| 171.1111 | 4450 | 0.0121 |
| 173.0556 | 4500 | 0.0194 |
| 174.7222 | 4550 | 0.0216 |
| 176.6667 | 4600 | 0.0193 |
| 178.6111 | 4650 | 0.0157 |
| 180.5556 | 4700 | 0.0159 |
| 182.5 | 4750 | 0.016 |
| 184.4444 | 4800 | 0.0182 |
| 186.3889 | 4850 | 0.0181 |
| 188.3333 | 4900 | 0.0164 |
| 190.2778 | 4950 | 0.0204 |
| 192.2222 | 5000 | 0.0188 |
| 194.1667 | 5050 | 0.0155 |
| 196.1111 | 5100 | 0.0166 |
| 198.0556 | 5150 | 0.0165 |
| 199.7222 | 5200 | 0.0111 |
| 201.6667 | 5250 | 0.0181 |
| 203.6111 | 5300 | 0.0196 |
| 205.5556 | 5350 | 0.0164 |
| 207.5 | 5400 | 0.0125 |
| 209.4444 | 5450 | 0.0168 |
| 211.3889 | 5500 | 0.0174 |
| 213.3333 | 5550 | 0.0144 |
| 215.2778 | 5600 | 0.0169 |
| 217.2222 | 5650 | 0.019 |
| 219.1667 | 5700 | 0.0178 |
| 221.1111 | 5750 | 0.014 |
| 223.0556 | 5800 | 0.0154 |
| 224.7222 | 5850 | 0.0151 |
| 226.6667 | 5900 | 0.0105 |
| 228.6111 | 5950 | 0.013 |
| 230.5556 | 6000 | 0.0152 |
| 232.5 | 6050 | 0.0138 |
| 234.4444 | 6100 | 0.0133 |
| 236.3889 | 6150 | 0.015 |
| 238.3333 | 6200 | 0.0119 |
| 240.2778 | 6250 | 0.0185 |
| 242.2222 | 6300 | 0.0104 |
| 244.1667 | 6350 | 0.0155 |
| 246.1111 | 6400 | 0.0135 |
| 248.0556 | 6450 | 0.0141 |
| 249.7222 | 6500 | 0.0168 |
@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{hermans2017defense,
title={In Defense of the Triplet Loss for Person Re-Identification},
author={Alexander Hermans and Lucas Beyer and Bastian Leibe},
year={2017},
eprint={1703.07737},
archivePrefix={arXiv},
primaryClass={cs.CV}
}