Sentence-BERT: Sentence Embeddings using Siamese BERT-Networks
Paper • 1908.10084 • Published • 19
How to use sjmeis/skills-embedding-base-v1 with sentence-transformers:
from sentence_transformers import SentenceTransformer
model = SentenceTransformer("sjmeis/skills-embedding-base-v1")
sentences = [
"That is a happy person",
"That is a happy dog",
"That is a very happy person",
"Today is a sunny day"
]
embeddings = model.encode(sentences)
similarities = model.similarity(embeddings, embeddings)
print(similarities.shape)
# [4, 4]This is a sentence-transformers model trained. It maps sentences & paragraphs to a 768-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': 'ModernBertModel'})
(1): Pooling({'embedding_dimension': 768, 'pooling_mode': 'mean', '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("sentence_transformers_model_id")
# Run inference
sentences = [
'client service specialist.',
'Great work environment and the company overall really care about their employees. Good work life balance.',
'service desk agent.',
]
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.2197, 0.4225],
# [0.2197, 1.0000, 0.1708],
# [0.4225, 0.1708, 1.0000]])
per_device_train_batch_size: 128warmup_steps: 0.1weight_decay: 0.01bf16: Trueper_device_eval_batch_size: 256load_best_model_at_end: Truebatch_sampler: no_duplicatesper_device_train_batch_size: 128num_train_epochs: 3max_steps: -1learning_rate: 5e-05lr_scheduler_type: linearlr_scheduler_kwargs: Nonewarmup_steps: 0.1optim: adamw_torch_fusedoptim_args: Noneweight_decay: 0.01adam_beta1: 0.9adam_beta2: 0.999adam_epsilon: 1e-08optim_target_modules: Nonegradient_accumulation_steps: 1average_tokens_across_devices: Truemax_grad_norm: 1.0label_smoothing_factor: 0.0bf16: Truefp16: 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: 256prediction_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: Trueignore_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: Nonedataloader_multiprocessing_context: Nonedataloader_in_order: Trueremove_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: Nonelocal_rank: -1prompts: Nonebatch_sampler: no_duplicatesmulti_dataset_batch_sampler: proportionalrouter_mapping: {}learning_rate_mapping: {}warmup_ratio: None| Epoch | Step | Training Loss | Validation Loss |
|---|---|---|---|
| 0.0209 | 500 | 3.6895 | - |
| 0.0419 | 1000 | 2.3065 | - |
| 0.0628 | 1500 | 1.8563 | - |
| 0.0837 | 2000 | 1.6056 | - |
| 0.1047 | 2500 | 1.4109 | - |
| 0.1256 | 3000 | 1.2946 | - |
| 0.1465 | 3500 | 1.2113 | - |
| 0.1674 | 4000 | 1.1580 | - |
| 0.1884 | 4500 | 1.0953 | - |
| 0.2093 | 5000 | 1.0467 | - |
| 0.2302 | 5500 | 1.0212 | - |
| 0.2512 | 6000 | 0.9830 | - |
| 0.2721 | 6500 | 0.9593 | - |
| 0.2930 | 7000 | 0.9313 | - |
| 0.3140 | 7500 | 0.9142 | - |
| 0.3349 | 8000 | 0.8902 | - |
| 0.3558 | 8500 | 0.8603 | - |
| 0.3767 | 9000 | 0.8384 | - |
| 0.3977 | 9500 | 0.8204 | - |
| 0.4186 | 10000 | 0.8079 | 1.0798 |
| 0.4395 | 10500 | 0.7997 | - |
| 0.4605 | 11000 | 0.7773 | - |
| 0.4814 | 11500 | 0.7731 | - |
| 0.5023 | 12000 | 0.7582 | - |
| 0.5233 | 12500 | 0.7416 | - |
| 0.5442 | 13000 | 0.7435 | - |
| 0.5651 | 13500 | 0.7376 | - |
| 0.5860 | 14000 | 0.7251 | - |
| 0.6070 | 14500 | 0.7280 | - |
| 0.6279 | 15000 | 0.7155 | - |
| 0.6488 | 15500 | 0.7068 | - |
| 0.6698 | 16000 | 0.7080 | - |
| 0.6907 | 16500 | 0.7056 | - |
| 0.7116 | 17000 | 0.6951 | - |
| 0.7326 | 17500 | 0.6890 | - |
| 0.7535 | 18000 | 0.6936 | - |
| 0.7744 | 18500 | 0.6822 | - |
| 0.7953 | 19000 | 0.6753 | - |
| 0.8163 | 19500 | 0.6756 | - |
| 0.8372 | 20000 | 0.6706 | 0.9167 |
| 0.8581 | 20500 | 0.6631 | - |
| 0.8791 | 21000 | 0.6582 | - |
| 0.9000 | 21500 | 0.6601 | - |
| 0.9209 | 22000 | 0.6536 | - |
| 0.9419 | 22500 | 0.6626 | - |
| 0.9628 | 23000 | 0.6451 | - |
| 0.9837 | 23500 | 0.6555 | - |
| 1.0046 | 24000 | 0.6280 | - |
| 1.0256 | 24500 | 0.6008 | - |
| 1.0465 | 25000 | 0.5898 | - |
| 1.0674 | 25500 | 0.5943 | - |
| 1.0884 | 26000 | 0.5936 | - |
| 1.1093 | 26500 | 0.5898 | - |
| 1.1302 | 27000 | 0.5887 | - |
| 1.1512 | 27500 | 0.5859 | - |
| 1.1721 | 28000 | 0.5944 | - |
| 1.1930 | 28500 | 0.5864 | - |
| 1.2139 | 29000 | 0.5835 | - |
| 1.2349 | 29500 | 0.5867 | - |
| 1.2558 | 30000 | 0.5927 | 0.8757 |
| 1.2767 | 30500 | 0.5942 | - |
| 1.2977 | 31000 | 0.5787 | - |
| 1.3186 | 31500 | 0.5840 | - |
| 1.3395 | 32000 | 0.5743 | - |
| 1.3605 | 32500 | 0.5757 | - |
| 1.3814 | 33000 | 0.5678 | - |
| 1.4023 | 33500 | 0.5650 | - |
| 1.4232 | 34000 | 0.5676 | - |
| 1.4442 | 34500 | 0.5642 | - |
| 1.4651 | 35000 | 0.5533 | - |
| 1.4860 | 35500 | 0.5589 | - |
| 1.5070 | 36000 | 0.5547 | - |
| 1.5279 | 36500 | 0.5506 | - |
| 1.5488 | 37000 | 0.5542 | - |
| 1.5698 | 37500 | 0.5491 | - |
| 1.5907 | 38000 | 0.5472 | - |
| 1.6116 | 38500 | 0.5507 | - |
| 1.6326 | 39000 | 0.5444 | - |
| 1.6535 | 39500 | 0.5452 | - |
| 1.6744 | 40000 | 0.5434 | 0.7943 |
| 1.6953 | 40500 | 0.5374 | - |
| 1.7163 | 41000 | 0.5392 | - |
| 1.7372 | 41500 | 0.5329 | - |
| 1.7581 | 42000 | 0.5415 | - |
| 1.7791 | 42500 | 0.5339 | - |
| 1.8000 | 43000 | 0.5248 | - |
| 1.8209 | 43500 | 0.5391 | - |
| 1.8419 | 44000 | 0.5316 | - |
| 1.8628 | 44500 | 0.5304 | - |
| 1.8837 | 45000 | 0.5314 | - |
| 1.9046 | 45500 | 0.5293 | - |
| 1.9256 | 46000 | 0.5274 | - |
| 1.9465 | 46500 | 0.5293 | - |
| 1.9674 | 47000 | 0.5216 | - |
| 1.9884 | 47500 | 0.5146 | - |
| 2.0093 | 48000 | 0.5007 | - |
| 2.0302 | 48500 | 0.4781 | - |
| 2.0512 | 49000 | 0.4818 | - |
| 2.0721 | 49500 | 0.4735 | - |
| 2.0930 | 50000 | 0.4658 | 0.7542 |
| 2.1139 | 50500 | 0.4645 | - |
| 2.1349 | 51000 | 0.4724 | - |
| 2.1558 | 51500 | 0.4655 | - |
| 2.1767 | 52000 | 0.4682 | - |
| 2.1977 | 52500 | 0.4721 | - |
| 2.2186 | 53000 | 0.4600 | - |
| 2.2395 | 53500 | 0.4614 | - |
| 2.2605 | 54000 | 0.4708 | - |
| 2.2814 | 54500 | 0.4596 | - |
| 2.3023 | 55000 | 0.4542 | - |
| 2.3232 | 55500 | 0.4581 | - |
| 2.3442 | 56000 | 0.4616 | - |
| 2.3651 | 56500 | 0.4567 | - |
| 2.3860 | 57000 | 0.4572 | - |
| 2.4070 | 57500 | 0.4618 | - |
| 2.4279 | 58000 | 0.4557 | - |
| 2.4488 | 58500 | 0.4528 | - |
| 2.4698 | 59000 | 0.4459 | - |
| 2.4907 | 59500 | 0.4531 | - |
| 2.5116 | 60000 | 0.4445 | 0.7255 |
| 2.5325 | 60500 | 0.4523 | - |
| 2.5535 | 61000 | 0.4514 | - |
| 2.5744 | 61500 | 0.4512 | - |
| 2.5953 | 62000 | 0.4576 | - |
| 2.6163 | 62500 | 0.4500 | - |
| 2.6372 | 63000 | 0.4509 | - |
| 2.6581 | 63500 | 0.4408 | - |
| 2.6791 | 64000 | 0.4432 | - |
| 2.7000 | 64500 | 0.4413 | - |
| 2.7209 | 65000 | 0.4410 | - |
| 2.7418 | 65500 | 0.4352 | - |
| 2.7628 | 66000 | 0.4379 | - |
| 2.7837 | 66500 | 0.4459 | - |
| 2.8046 | 67000 | 0.4419 | - |
| 2.8256 | 67500 | 0.4411 | - |
| 2.8465 | 68000 | 0.4433 | - |
| 2.8674 | 68500 | 0.4360 | - |
| 2.8884 | 69000 | 0.4391 | - |
| 2.9093 | 69500 | 0.4399 | - |
| 2.9302 | 70000 | 0.4306 | 0.7062 |
| 2.9511 | 70500 | 0.4370 | - |
| 2.9721 | 71000 | 0.4339 | - |
| 2.9930 | 71500 | 0.4361 | - |
| 3.0 | 71667 | - | 0.7051 |
@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},
}