Views
No views yet
SentenceTransformer(
(0): Transformer({'max_seq_length': 512, 'do_lower_case': False}) with Transformer model: DistilBertModel
(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/distilbert-base-uncased-sts-matryoshka")
5# Run inference
6sentences = [
7 'A woman is dancing.',
8 'A woman is dancing in railway station.',
9 'The flag was moving in the air.',
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-dev-768EmbeddingSimilarityEvaluator| Metric | Value |
|---|---|
| pearson_cosine | 0.8648 |
| spearman_cosine | 0.8748 |
| pearson_manhattan | 0.8628 |
| spearman_manhattan | 0.8658 |
| pearson_euclidean | 0.8627 |
| spearman_euclidean | 0.8658 |
| pearson_dot | 0.7443 |
| spearman_dot | 0.7514 |
| pearson_max | 0.8648 |
| spearman_max | 0.8748 |
sts-dev-512EmbeddingSimilarityEvaluator| Metric | Value |
|---|---|
| pearson_cosine | 0.8628 |
| spearman_cosine | 0.8741 |
| pearson_manhattan | 0.862 |
| spearman_manhattan | 0.8651 |
| pearson_euclidean | 0.8623 |
| spearman_euclidean | 0.8653 |
| pearson_dot | 0.7464 |
| spearman_dot | 0.7541 |
| pearson_max | 0.8628 |
| spearman_max | 0.8741 |
sts-dev-256EmbeddingSimilarityEvaluator| Metric | Value |
|---|---|
| pearson_cosine | 0.8589 |
| spearman_cosine | 0.8714 |
| pearson_manhattan | 0.8591 |
| spearman_manhattan | 0.8634 |
| pearson_euclidean | 0.8592 |
| spearman_euclidean | 0.8629 |
| pearson_dot | 0.7186 |
| spearman_dot | 0.7289 |
| pearson_max | 0.8592 |
| spearman_max | 0.8714 |
sts-dev-128EmbeddingSimilarityEvaluator| Metric | Value |
|---|---|
| pearson_cosine | 0.8529 |
| spearman_cosine | 0.8688 |
| pearson_manhattan | 0.8509 |
| spearman_manhattan | 0.8576 |
| pearson_euclidean | 0.8532 |
| spearman_euclidean | 0.8581 |
| pearson_dot | 0.697 |
| spearman_dot | 0.7059 |
| pearson_max | 0.8532 |
| spearman_max | 0.8688 |
sts-dev-64EmbeddingSimilarityEvaluator| Metric | Value |
|---|---|
| pearson_cosine | 0.834 |
| spearman_cosine | 0.8587 |
| pearson_manhattan | 0.8352 |
| spearman_manhattan | 0.8446 |
| pearson_euclidean | 0.8387 |
| spearman_euclidean | 0.8461 |
| pearson_dot | 0.6579 |
| spearman_dot | 0.6713 |
| pearson_max | 0.8387 |
| spearman_max | 0.8587 |
sts-test-768EmbeddingSimilarityEvaluator| Metric | Value |
|---|---|
| pearson_cosine | 0.8337 |
| spearman_cosine | 0.847 |
| pearson_manhattan | 0.8485 |
| spearman_manhattan | 0.847 |
| pearson_euclidean | 0.8493 |
| spearman_euclidean | 0.8475 |
| pearson_dot | 0.6702 |
| spearman_dot | 0.6526 |
| pearson_max | 0.8493 |
| spearman_max | 0.8475 |
sts-test-512EmbeddingSimilarityEvaluator| Metric | Value |
|---|---|
| pearson_cosine | 0.8326 |
| spearman_cosine | 0.8468 |
| pearson_manhattan | 0.8474 |
| spearman_manhattan | 0.8463 |
| pearson_euclidean | 0.8482 |
| spearman_euclidean | 0.8466 |
| pearson_dot | 0.6737 |
| spearman_dot | 0.6572 |
| pearson_max | 0.8482 |
| spearman_max | 0.8468 |
sts-test-256EmbeddingSimilarityEvaluator| Metric | Value |
|---|---|
| pearson_cosine | 0.8226 |
| spearman_cosine | 0.8403 |
| pearson_manhattan | 0.8421 |
| spearman_manhattan | 0.842 |
| pearson_euclidean | 0.8435 |
| spearman_euclidean | 0.8429 |
| pearson_dot | 0.623 |
| spearman_dot | 0.6062 |
| pearson_max | 0.8435 |
| spearman_max | 0.8429 |
sts-test-128EmbeddingSimilarityEvaluator| Metric | Value |
|---|---|
| pearson_cosine | 0.815 |
| spearman_cosine | 0.835 |
| pearson_manhattan | 0.8352 |
| spearman_manhattan | 0.8361 |
| pearson_euclidean | 0.8376 |
| spearman_euclidean | 0.8376 |
| pearson_dot | 0.5958 |
| spearman_dot | 0.5793 |
| pearson_max | 0.8376 |
| spearman_max | 0.8376 |
sts-test-64EmbeddingSimilarityEvaluator| Metric | Value |
|---|---|
| pearson_cosine | 0.7981 |
| spearman_cosine | 0.827 |
| pearson_manhattan | 0.8239 |
| spearman_manhattan | 0.8289 |
| pearson_euclidean | 0.8279 |
| spearman_euclidean | 0.8315 |
| pearson_dot | 0.5206 |
| spearman_dot | 0.5067 |
| pearson_max | 0.8279 |
| spearman_max | 0.8315 |
sentence1, sentence2, and score| sentence1 | sentence2 | score | |
|---|---|---|---|
| type | string | string | float |
| details |
|
|
|
| sentence1 | sentence2 | score |
|---|---|---|
A plane is taking off. | An air plane is taking off. | 1.0 |
A man is playing a large flute. | A man is playing a flute. | 0.76 |
A man is spreading shreded cheese on a pizza. | A man is spreading shredded cheese on an uncooked pizza. | 0.76 |
MatryoshkaLoss with these parameters:
1{
2 "loss": "CoSENTLoss",
3 "matryoshka_dims": [
4 768,
5 512,
6 256,
7 128,
8 64
9 ],
10 "matryoshka_weights": [
11 1,
12 1,
13 1,
14 1,
15 1
16 ],
17 "n_dims_per_step": -1
18}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 |
MatryoshkaLoss with these parameters:
1{
2 "loss": "CoSENTLoss",
3 "matryoshka_dims": [
4 768,
5 512,
6 256,
7 128,
8 64
9 ],
10 "matryoshka_weights": [
11 1,
12 1,
13 1,
14 1,
15 1
16 ],
17 "n_dims_per_step": -1
18}eval_strategy: stepsper_device_train_batch_size: 16per_device_eval_batch_size: 16num_train_epochs: 4warmup_ratio: 0.1fp16: Trueoverwrite_output_dir: Falsedo_predict: Falseeval_strategy: stepsprediction_loss_only: Falseper_device_train_batch_size: 16per_device_eval_batch_size: 16per_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: 4max_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: batch_samplermulti_dataset_batch_sampler: proportional| Epoch | Step | Training Loss | loss | sts-dev-128_spearman_cosine | sts-dev-256_spearman_cosine | sts-dev-512_spearman_cosine | sts-dev-64_spearman_cosine | sts-dev-768_spearman_cosine | sts-test-128_spearman_cosine | sts-test-256_spearman_cosine | sts-test-512_spearman_cosine | sts-test-64_spearman_cosine | sts-test-768_spearman_cosine |
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| 0.2778 | 100 | 23.266 | 21.5517 | 0.8305 | 0.8355 | 0.8361 | 0.8157 | 0.8366 | - | - | - | - | - |
| 0.5556 | 200 | 21.8736 | 21.6172 | 0.8327 | 0.8388 | 0.8446 | 0.8206 | 0.8453 | - | - | - | - | - |
| 0.8333 | 300 | 21.6241 | 22.0565 | 0.8475 | 0.8538 | 0.8556 | 0.8345 | 0.8565 | - | - | - | - | - |
| 1.1111 | 400 | 21.075 | 23.6719 | 0.8545 | 0.8581 | 0.8634 | 0.8435 | 0.8644 | - | - | - | - | - |
| 1.3889 | 500 | 20.4122 | 22.5926 | 0.8592 | 0.8624 | 0.8650 | 0.8436 | 0.8656 | - | - | - | - | - |
| 1.6667 | 600 | 20.6586 | 22.5999 | 0.8514 | 0.8563 | 0.8595 | 0.8389 | 0.8597 | - | - | - | - | - |
| 1.9444 | 700 | 20.3262 | 22.2965 | 0.8582 | 0.8631 | 0.8666 | 0.8465 | 0.8667 | - | - | - | - | - |
| 2.2222 | 800 | 19.7948 | 23.1844 | 0.8621 | 0.8659 | 0.8688 | 0.8499 | 0.8694 | - | - | - | - | - |
| 2.5 | 900 | 19.2826 | 23.1351 | 0.8653 | 0.8687 | 0.8703 | 0.8547 | 0.8710 | - | - | - | - | - |
| 2.7778 | 1000 | 19.1063 | 23.7141 | 0.8641 | 0.8672 | 0.8691 | 0.8531 | 0.8695 | - | - | - | - | - |
| 3.0556 | 1100 | 19.4575 | 23.0055 | 0.8673 | 0.8702 | 0.8726 | 0.8574 | 0.8728 | - | - | - | - | - |
| 3.3333 | 1200 | 18.0727 | 24.9288 | 0.8659 | 0.8692 | 0.8715 | 0.8565 | 0.8722 | - | - | - | - | - |
| 3.6111 | 1300 | 18.1698 | 25.3114 | 0.8675 | 0.8701 | 0.8728 | 0.8576 | 0.8734 | - | - | - | - | - |
| 3.8889 | 1400 | 18.2321 | 25.3777 | 0.8688 | 0.8714 | 0.8741 | 0.8587 | 0.8748 | - | - | - | - | - |
| 4.0 | 1440 | - | - | - | - | - | - | - | 0.8350 | 0.8403 | 0.8468 | 0.8270 | 0.8470 |
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{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@online{kexuefm-8847,
2 title={CoSENT: A more efficient sentence vector scheme than Sentence-BERT},
3 author={Su Jianlin},
4 year={2022},
5 month={Jan},
6 url={https://kexue.fm/archives/8847},
7}