Views
No views yet
SentenceTransformer(
(0): Transformer({'max_seq_length': 512, 'do_lower_case': False}) with Transformer model: RobertaModel
(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})
)pip install -U sentence-transformers1from sentence_transformers import SentenceTransformer
2
3# Download from the 🤗 Hub
4model = SentenceTransformer("tomaarsen/distilroberta-base-nli-2d-matryoshka")
5# Run inference
6sentences = [
7 'A plane in the sky.',
8 'Two airplanes in the sky.',
9 'Nelson Mandela undergoes surgery',
10]
11embeddings = model.encode(sentences)
12print(embeddings.shape)
13# [3, 768]
14
15# Get the similarity scores for the embeddings
16similarities = model.similarity(embeddings)
17print(similarities.shape)
18# [3, 3]sts-devEmbeddingSimilarityEvaluator| Metric | Value |
|---|---|
| pearson_cosine | 0.8395 |
| spearman_cosine | 0.8425 |
| pearson_manhattan | 0.8433 |
| spearman_manhattan | 0.8436 |
| pearson_euclidean | 0.8441 |
| spearman_euclidean | 0.8449 |
| pearson_dot | 0.7638 |
| spearman_dot | 0.757 |
| pearson_max | 0.8441 |
| spearman_max | 0.8449 |
sts-testEmbeddingSimilarityEvaluator| Metric | Value |
|---|---|
| pearson_cosine | 0.8187 |
| spearman_cosine | 0.8171 |
| pearson_manhattan | 0.8117 |
| spearman_manhattan | 0.8049 |
| pearson_euclidean | 0.8127 |
| spearman_euclidean | 0.8058 |
| pearson_dot | 0.7396 |
| spearman_dot | 0.7256 |
| pearson_max | 0.8187 |
| spearman_max | 0.8171 |
anchor, positive, and negative| anchor | positive | negative | |
|---|---|---|---|
| type | string | string | string |
| details |
|
|
|
| anchor | positive | negative |
|---|---|---|
A person on a horse jumps over a broken down airplane. | A person is outdoors, on a horse. | A person is at a diner, ordering an omelette. |
Children smiling and waving at camera | There are children present | The kids are frowning |
A boy is jumping on skateboard in the middle of a red bridge. | The boy does a skateboarding trick. | The boy skates down the sidewalk. |
Matryoshka2dLoss with these parameters:
1{
2 "loss": "MultipleNegativesRankingLoss",
3 "n_layers_per_step": 1,
4 "last_layer_weight": 1.0,
5 "prior_layers_weight": 1.0,
6 "kl_div_weight": 1.0,
7 "kl_temperature": 0.3,
8 "matryoshka_dims": [
9 768,
10 512,
11 256,
12 128,
13 64
14 ],
15 "matryoshka_weights": [
16 1,
17 1,
18 1,
19 1,
20 1
21 ],
22 "n_dims_per_step": 1
23}sentence1, sentence2, and score| sentence1 | sentence2 | score | |
|---|---|---|---|
| type | string | string | float |
| details |
|
|
|
| sentence1 | sentence2 | score |
|---|---|---|
A man with a hard hat is dancing. | A man wearing a hard hat is dancing. | 1.0 |
A young child is riding a horse. | A child is riding a horse. | 0.95 |
A man is feeding a mouse to a snake. | The man is feeding a mouse to the snake. | 1.0 |
Matryoshka2dLoss with these parameters:
1{
2 "loss": "MultipleNegativesRankingLoss",
3 "n_layers_per_step": 1,
4 "last_layer_weight": 1.0,
5 "prior_layers_weight": 1.0,
6 "kl_div_weight": 1.0,
7 "kl_temperature": 0.3,
8 "matryoshka_dims": [
9 768,
10 512,
11 256,
12 128,
13 64
14 ],
15 "matryoshka_weights": [
16 1,
17 1,
18 1,
19 1,
20 1
21 ],
22 "n_dims_per_step": 1
23}eval_strategy: stepsper_device_train_batch_size: 128per_device_eval_batch_size: 128num_train_epochs: 1warmup_ratio: 0.1fp16: Truebatch_sampler: no_duplicatesoverwrite_output_dir: Falsedo_predict: Falseeval_strategy: stepsprediction_loss_only: Falseper_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: 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: 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: Nonedataloader_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: Falsehub_always_push: Falsegradient_checkpointing: Falsegradient_checkpointing_kwargs: Noneinclude_inputs_for_metrics: Falseeval_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: Nonedispatch_batches: Nonesplit_batches: Noneinclude_tokens_per_second: Falseinclude_num_input_tokens_seen: Falseneftune_noise_alpha: Noneoptim_target_modules: Nonebatch_sampler: no_duplicatesmulti_dataset_batch_sampler: proportional| Epoch | Step | Training Loss | loss | sts-dev_spearman_cosine | sts-test_spearman_cosine |
|---|---|---|---|---|---|
| 0.0229 | 100 | 6.2779 | 3.9959 | 0.8008 | - |
| 0.0459 | 200 | 4.3212 | 3.5818 | 0.7956 | - |
| 0.0688 | 300 | 3.7135 | 3.4422 | 0.7940 | - |
| 0.0918 | 400 | 3.5567 | 3.5458 | 0.7951 | - |
| 0.1147 | 500 | 3.1297 | 3.1253 | 0.8050 | - |
| 0.1376 | 600 | 2.7001 | 3.4366 | 0.7996 | - |
| 0.1606 | 700 | 2.8664 | 3.6609 | 0.8033 | - |
| 0.1835 | 800 | 2.6656 | 3.3736 | 0.7975 | - |
| 0.2065 | 900 | 2.633 | 3.3735 | 0.8076 | - |
| 0.2294 | 1000 | 2.4335 | 3.6499 | 0.7996 | - |
| 0.2524 | 1100 | 2.4165 | 3.6301 | 0.8015 | - |
| 0.2753 | 1200 | 2.2942 | 3.1541 | 0.7994 | - |
| 0.2982 | 1300 | 2.2402 | 3.4284 | 0.7977 | - |
| 0.3212 | 1400 | 2.2148 | 3.3775 | 0.7988 | - |
| 0.3441 | 1500 | 2.2285 | 3.6097 | 0.8016 | - |
| 0.3671 | 1600 | 2.0591 | 3.3839 | 0.7926 | - |
| 0.3900 | 1700 | 2.0253 | 3.1113 | 0.7981 | - |
| 0.4129 | 1800 | 2.0244 | 3.8289 | 0.7954 | - |
| 0.4359 | 1900 | 1.8582 | 3.3515 | 0.8000 | - |
| 0.4588 | 2000 | 1.977 | 3.3054 | 0.7917 | - |
| 0.4818 | 2100 | 1.9028 | 3.2166 | 0.7927 | - |
| 0.5047 | 2200 | 1.8316 | 3.6504 | 0.7955 | - |
| 0.5276 | 2300 | 1.8404 | 3.2822 | 0.7843 | - |
| 0.5506 | 2400 | 1.8455 | 3.2583 | 0.7941 | - |
| 0.5735 | 2500 | 1.9488 | 3.3970 | 0.7971 | - |
| 0.5965 | 2600 | 1.9403 | 2.8948 | 0.7959 | - |
| 0.6194 | 2700 | 1.8884 | 3.2227 | 0.8008 | - |
| 0.6423 | 2800 | 1.8655 | 3.1948 | 0.7920 | - |
| 0.6653 | 2900 | 1.8567 | 3.4374 | 0.7913 | - |
| 0.6882 | 3000 | 1.8423 | 3.1118 | 0.7949 | - |
| 0.7112 | 3100 | 1.7475 | 3.1359 | 0.8062 | - |
| 0.7341 | 3200 | 1.8166 | 2.9927 | 0.7984 | - |
| 0.7571 | 3300 | 1.5626 | 3.5143 | 0.8405 | - |
| 0.7800 | 3400 | 1.2038 | 3.3909 | 0.8411 | - |
| 0.8029 | 3500 | 1.1579 | 3.2458 | 0.8413 | - |
| 0.8259 | 3600 | 1.0978 | 3.1592 | 0.8404 | - |
| 0.8488 | 3700 | 1.0283 | 2.9557 | 0.8408 | - |
| 0.8718 | 3800 | 0.9993 | 3.4073 | 0.8430 | - |
| 0.8947 | 3900 | 0.9727 | 3.0570 | 0.8434 | - |
| 0.9176 | 4000 | 0.9692 | 2.9357 | 0.8439 | - |
| 0.9406 | 4100 | 0.9412 | 2.9494 | 0.8428 | - |
| 0.9635 | 4200 | 1.0063 | 3.4047 | 0.8422 | - |
| 0.9865 | 4300 | 0.9678 | 3.4299 | 0.8425 | - |
| 1.0 | 4359 | - | - | - | 0.8171 |
1@inproceedings{reimers-2019-sentence-bert,
2 title = "Sentence-BERT: Sentence Embeddings using Siamese BERT-Networks",
3 author = "Reimers, Nils and Gurevych, Iryna",
4 booktitle = "Proceedings of the 2019 Conference on Empirical Methods in Natural Language Processing",
5 month = "11",
6 year = "2019",
7 publisher = "Association for Computational Linguistics",
8 url = "https://arxiv.org/abs/1908.10084",
9}1@misc{li20242d,
2 title={2D Matryoshka Sentence Embeddings},
3 author={Xianming Li and Zongxi Li and Jing Li and Haoran Xie and Qing Li},
4 year={2024},
5 eprint={2402.14776},
6 archivePrefix={arXiv},
7 primaryClass={cs.CL}
8}1@misc{kusupati2024matryoshka,
2 title={Matryoshka Representation Learning},
3 author={Aditya Kusupati and Gantavya Bhatt and Aniket Rege and Matthew Wallingford and Aditya Sinha and Vivek Ramanujan and William Howard-Snyder and Kaifeng Chen and Sham Kakade and Prateek Jain and Ali Farhadi},
4 year={2024},
5 eprint={2205.13147},
6 archivePrefix={arXiv},
7 primaryClass={cs.LG}
8}1@misc{henderson2017efficient,
2 title={Efficient Natural Language Response Suggestion for Smart Reply},
3 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},
4 year={2017},
5 eprint={1705.00652},
6 archivePrefix={arXiv},
7 primaryClass={cs.CL}
8}