Sentence-BERT: Sentence Embeddings using Siamese BERT-Networks
Paper • 1908.10084 • Published • 15
How to use fihus/jobbert-v3-trilingual with sentence-transformers:
from sentence_transformers import SentenceTransformer
model = SentenceTransformer("fihus/jobbert-v3-trilingual")
sentences = [
"špecialistka v oblasti rozvoja podnikania",
"odborník v oblasti rozvoja podnikania",
"zelený podnikateľka",
"sportovní reportér"
]
embeddings = model.encode(sentences)
similarities = model.similarity(embeddings, embeddings)
print(similarities.shape)
# [4, 4]This is a sentence-transformers model finetuned from TechWolf/JobBERT-v3. It maps sentences & paragraphs to a 1024-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': 'XLMRobertaModel'})
(1): Pooling({'embedding_dimension': 768, 'pooling_mode': 'mean', 'include_prompt': True})
(2): Router(
default_route='anchor'
(sub_modules): ModuleDict(
(anchor): Sequential(
(0): Dense({'in_features': 768, 'out_features': 1024, 'bias': True, 'activation_function': 'torch.nn.modules.activation.Tanh', 'module_input_name': 'sentence_embedding', 'module_output_name': 'sentence_embedding'})
)
(positive): Sequential(
(0): Dense({'in_features': 768, 'out_features': 1024, 'bias': True, 'activation_function': 'torch.nn.modules.activation.Tanh', 'module_input_name': 'sentence_embedding', 'module_output_name': 'sentence_embedding'})
)
)
)
)
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
queries = [
'cybersecurity risk manager',
]
documents = [
'cybersecurity risk assurance consultant',
'konfigurátorka aplikácií',
'vedúci predajne obuvi a koženej galantérie',
]
query_embeddings = model.encode_query(queries)
document_embeddings = model.encode_document(documents)
print(query_embeddings.shape, document_embeddings.shape)
# [1, 1024] [3, 1024]
# Get the similarity scores for the embeddings
similarities = model.similarity(query_embeddings, document_embeddings)
print(similarities.shape)
# [1, 3]
anchor and positive| anchor | positive | |
|---|---|---|
| type | string | string |
| details |
|
|
| anchor | positive |
|---|---|
laborant botanik |
laborantka botanička |
průvodčí vlaků v osobní dopravě |
průvodčí osobní přepravy |
vývojářka softwaru vestavěných systémů |
vývojářka softwaru vestavěných zařízení |
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
}
anchor and positive| anchor | positive | |
|---|---|---|
| type | string | string |
| details |
|
|
| anchor | positive |
|---|---|
instruktorka řízení osobních automobilů |
instruktor řízení osobních automobilů |
technička námořní mechatroniky |
technolog námořní mechatroniky |
specialista zahraničního obchodu v oblasti kancelářského nábytku |
špecialistka v oblasti dovozu a vývozu kancelárskeho nábytku |
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: 128learning_rate: 2e-05warmup_steps: 0.1fp16: Trueper_device_eval_batch_size: 128load_best_model_at_end: Truedataloader_drop_last: Truedataloader_num_workers: 4router_mapping: {'anchor': 'anchor', 'positive': 'positive'}per_device_train_batch_size: 128num_train_epochs: 3max_steps: -1learning_rate: 2e-05lr_scheduler_type: linearlr_scheduler_kwargs: Nonewarmup_steps: 0.1optim: 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: 1.0label_smoothing_factor: 0.0bf16: Falsefp16: Truebf16_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: trackioper_device_eval_batch_size: 128prediction_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: Truedataloader_num_workers: 4dataloader_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_backend: Noneddp_timeout: 1800fsdp: []fsdp_config: {'min_num_params': 0, 'xla': False, 'xla_fsdp_v2': False, 'xla_fsdp_grad_ckpt': False}deepspeed: Nonedebug: []skip_memory_metrics: Truedo_predict: Falseresume_from_checkpoint: Nonewarmup_ratio: Nonelocal_rank: -1prompts: Nonebatch_sampler: batch_samplermulti_dataset_batch_sampler: proportionalrouter_mapping: {'anchor': 'anchor', 'positive': 'positive'}learning_rate_mapping: {}| Epoch | Step | Training Loss | Validation Loss |
|---|---|---|---|
| 0.0686 | 50 | 1.1902 | - |
| 0.1372 | 100 | 0.9478 | - |
| 0.2058 | 150 | 0.7830 | - |
| 0.2743 | 200 | 0.7300 | - |
| 0.3429 | 250 | 0.6671 | 0.9028 |
| 0.4115 | 300 | 0.6276 | - |
| 0.4801 | 350 | 0.5243 | - |
| 0.5487 | 400 | 0.5387 | - |
| 0.6173 | 450 | 0.5103 | - |
| 0.6859 | 500 | 0.4896 | 0.8111 |
| 0.7545 | 550 | 0.4634 | - |
| 0.8230 | 600 | 0.4549 | - |
| 0.8916 | 650 | 0.4426 | - |
| 0.9602 | 700 | 0.4225 | - |
| 1.0288 | 750 | 0.3886 | 0.8071 |
| 1.0974 | 800 | 0.3586 | - |
| 1.1660 | 850 | 0.3403 | - |
| 1.2346 | 900 | 0.3548 | - |
| 1.3032 | 950 | 0.3572 | - |
| 1.3717 | 1000 | 0.3491 | 0.7716 |
| 1.4403 | 1050 | 0.3446 | - |
| 1.5089 | 1100 | 0.3374 | - |
| 1.5775 | 1150 | 0.3297 | - |
| 1.6461 | 1200 | 0.2979 | - |
| 1.7147 | 1250 | 0.3281 | 0.7645 |
| 1.7833 | 1300 | 0.3010 | - |
| 1.8519 | 1350 | 0.3111 | - |
| 1.9204 | 1400 | 0.3072 | - |
| 1.9890 | 1450 | 0.3178 | - |
| 2.0576 | 1500 | 0.2969 | 0.7676 |
| 2.1262 | 1550 | 0.2701 | - |
| 2.1948 | 1600 | 0.2561 | - |
| 2.2634 | 1650 | 0.2661 | - |
| 2.3320 | 1700 | 0.2525 | - |
| 2.4005 | 1750 | 0.262 | 0.7628 |
@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},
}