Matryoshka Representation Learning
Paper • 2205.13147 • Published • 30
How to use suh4s/insightflow-balanced-team-embed-v1-7099e82c-e4c8-48ed-88a8-36bd9255036b with sentence-transformers:
from sentence_transformers import SentenceTransformer
model = SentenceTransformer("suh4s/insightflow-balanced-team-embed-v1-7099e82c-e4c8-48ed-88a8-36bd9255036b")
sentences = [
"How did he feel when the birds were finally out of his sight? ",
"LV. He that feareth death, either feareth that he shall have no sense at\nall, or that his senses will not be the same. Whereas, he should rather\ncomfort himself, that either no sense at all, and so no sense of evil;\nor if any sense, then another life, and so no death properly.\n\nLVI. All men are made one for another: either then teach them better, or\nbear with them.\n\nLVII. The motion of the mind is not as the motion of a dart. For\nthe mind when it is wary and cautelous, and by way of diligent\ncircumspection turneth herself many ways, may then as well be said to\ngo straight on to the object, as when it useth no such circumspection.",
"beautiful, happy birds! And when at last they were out of his sight, he\ndived under the water and rose again almost beside himself with\nexcitement. He knew not the names of these birds nor where they had\nflown, but he felt towards them as he had never felt towards any other\nbird in the world.",
"[Illustration]\n\n\n\n\nLITTLE IDA'S FLOWERS\n\n\n\"MY POOR flowers are quite faded!\" said little Ida. \"Only yesterday\nevening they were so pretty, and now all the leaves are drooping. Why do\nthey do that?\" she asked of the student, who sat on the sofa. He was a\ngreat favorite with her, because he used to tell her the prettiest of\nstories and cut out the most amusing things in paper--hearts with little\nladies dancing in them, and high castles with doors which one could open\nand shut. He was a merry student. \"Why do the flowers look so wretched\nto-day?\" asked she again, showing him a bouquet of faded flowers.\n\n\"Do you not know?\" replied the student. \"The flowers went to a ball last\nnight, and are tired. That's why they hang their heads.\""
]
embeddings = model.encode(sentences)
similarities = model.similarity(embeddings, embeddings)
print(similarities.shape)
# [4, 4]This is a sentence-transformers model finetuned from Snowflake/snowflake-arctic-embed-l. It maps sentences & paragraphs to a 1024-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': 1024, '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})
(2): Normalize()
)
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("suh4s/insightflow-balanced-team-embed-v1-7099e82c-e4c8-48ed-88a8-36bd9255036b")
# Run inference
sentences = [
'What benefits are mentioned for those who comply with the terms of the Project Gutenberg agreement?',
'1.B. "Project Gutenberg" is a registered trademark. It may only be\nused on or associated in any way with an electronic work by people who\nagree to be bound by the terms of this agreement. There are a few\nthings that you can do with most Project Gutenberg-tm electronic works\neven without complying with the full terms of this agreement. See\nparagraph 1.C below. There are a lot of things you can do with Project\nGutenberg-tm electronic works if you follow the terms of this\nagreement and help preserve free future access to Project Gutenberg-tm\nelectronic works. See paragraph 1.E below.',
'This is about all that he has to say. He will not entreat the judges to\nspare his life; neither will he present a spectacle of weeping\nchildren, although he, too, is not made of “rock or oak.” Some of the\njudges themselves may have complied with this practice on similar\noccasions, and he trusts that they will not be angry with him for not\nfollowing their example. But he feels that such conduct brings\ndiscredit on the name of Athens: he feels too, that the judge has sworn\nnot to give away justice; and he cannot be guilty of the impiety of\nasking the judge to break his oath, when he is himself being tried for\nimpiety.',
]
embeddings = model.encode(sentences)
print(embeddings.shape)
# [3, 1024]
# Get the similarity scores for the embeddings
similarities = model.similarity(embeddings, embeddings)
print(similarities.shape)
# [3, 3]
InformationRetrievalEvaluator| Metric | Value |
|---|---|
| cosine_accuracy@1 | 0.5729 |
| cosine_accuracy@3 | 0.7271 |
| cosine_accuracy@5 | 0.7792 |
| cosine_accuracy@10 | 0.8417 |
| cosine_precision@1 | 0.5729 |
| cosine_precision@3 | 0.2424 |
| cosine_precision@5 | 0.1558 |
| cosine_precision@10 | 0.0842 |
| cosine_recall@1 | 0.5729 |
| cosine_recall@3 | 0.7271 |
| cosine_recall@5 | 0.7792 |
| cosine_recall@10 | 0.8417 |
| cosine_ndcg@10 | 0.7066 |
| cosine_mrr@10 | 0.6635 |
| cosine_map@100 | 0.6715 |
InformationRetrievalEvaluator| Metric | Value |
|---|---|
| cosine_accuracy@1 | 0.5458 |
| cosine_accuracy@3 | 0.725 |
| cosine_accuracy@5 | 0.7833 |
| cosine_accuracy@10 | 0.8667 |
| cosine_precision@1 | 0.5458 |
| cosine_precision@3 | 0.2417 |
| cosine_precision@5 | 0.1567 |
| cosine_precision@10 | 0.0867 |
| cosine_recall@1 | 0.5458 |
| cosine_recall@3 | 0.725 |
| cosine_recall@5 | 0.7833 |
| cosine_recall@10 | 0.8667 |
| cosine_ndcg@10 | 0.7036 |
| cosine_mrr@10 | 0.6518 |
| cosine_map@100 | 0.6594 |
sentence_0 and sentence_1| sentence_0 | sentence_1 | |
|---|---|---|
| type | string | string |
| details |
|
|
| sentence_0 | sentence_1 |
|---|---|
What causes Kay to burst into tears in the passage? |
"Roses bloom and fade away, |
How does Kay react upon recognizing Gerda? |
"Roses bloom and fade away, |
What editions were compared to prepare the text mentioned in the context? |
The text itself has been prepared by a comparison of the editions of |
MatryoshkaLoss with these parameters:{
"loss": "MultipleNegativesRankingLoss",
"matryoshka_dims": [
768,
512,
256,
128,
64
],
"matryoshka_weights": [
1,
1,
1,
1,
1
],
"n_dims_per_step": -1
}
eval_strategy: stepsnum_train_epochs: 10multi_dataset_batch_sampler: round_robinoverwrite_output_dir: Falsedo_predict: Falseeval_strategy: stepsprediction_loss_only: Trueper_device_train_batch_size: 8per_device_eval_batch_size: 8per_gpu_train_batch_size: Noneper_gpu_eval_batch_size: Nonegradient_accumulation_steps: 1eval_accumulation_steps: Nonetorch_empty_cache_steps: Nonelearning_rate: 5e-05weight_decay: 0.0adam_beta1: 0.9adam_beta2: 0.999adam_epsilon: 1e-08max_grad_norm: 1num_train_epochs: 10max_steps: -1lr_scheduler_type: linearlr_scheduler_kwargs: {}warmup_ratio: 0.0warmup_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: Falsefp16_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: batch_samplermulti_dataset_batch_sampler: round_robin| Epoch | Step | Training Loss | cosine_ndcg@10 |
|---|---|---|---|
| 0.0561 | 50 | - | 0.5573 |
| 0.1122 | 100 | - | 0.6540 |
| 0.1684 | 150 | - | 0.6854 |
| 0.2245 | 200 | - | 0.7066 |
| 0.1121 | 50 | - | 0.7155 |
| 0.2242 | 100 | - | 0.7171 |
| 0.3363 | 150 | - | 0.7278 |
| 0.4484 | 200 | - | 0.7270 |
| 0.5605 | 250 | - | 0.7112 |
| 0.6726 | 300 | - | 0.7238 |
| 0.7848 | 350 | - | 0.7255 |
| 0.8969 | 400 | - | 0.7120 |
| 1.0 | 446 | - | 0.7164 |
| 1.0090 | 450 | - | 0.7170 |
| 1.1211 | 500 | 0.4113 | 0.7293 |
| 1.2332 | 550 | - | 0.7032 |
| 1.3453 | 600 | - | 0.7130 |
| 1.4574 | 650 | - | 0.6967 |
| 1.5695 | 700 | - | 0.7132 |
| 1.6816 | 750 | - | 0.7089 |
| 1.7937 | 800 | - | 0.7106 |
| 1.9058 | 850 | - | 0.7148 |
| 2.0 | 892 | - | 0.7118 |
| 2.0179 | 900 | - | 0.7072 |
| 2.1300 | 950 | - | 0.7111 |
| 2.2422 | 1000 | 0.2493 | 0.7178 |
| 2.3543 | 1050 | - | 0.7102 |
| 2.4664 | 1100 | - | 0.7090 |
| 2.5785 | 1150 | - | 0.7098 |
| 2.6906 | 1200 | - | 0.7136 |
| 2.8027 | 1250 | - | 0.7059 |
| 2.9148 | 1300 | - | 0.7131 |
| 3.0 | 1338 | - | 0.7166 |
| 3.0269 | 1350 | - | 0.7076 |
| 3.1390 | 1400 | - | 0.7101 |
| 3.2511 | 1450 | - | 0.7095 |
| 3.3632 | 1500 | 0.1173 | 0.6990 |
| 3.4753 | 1550 | - | 0.7016 |
| 3.5874 | 1600 | - | 0.6802 |
| 3.6996 | 1650 | - | 0.6917 |
| 3.8117 | 1700 | - | 0.7028 |
| 3.9238 | 1750 | - | 0.6976 |
| 4.0 | 1784 | - | 0.7015 |
| 4.0359 | 1800 | - | 0.6949 |
| 4.1480 | 1850 | - | 0.6894 |
| 4.2601 | 1900 | - | 0.6926 |
| 4.3722 | 1950 | - | 0.6929 |
| 4.4843 | 2000 | 0.052 | 0.6984 |
| 4.5964 | 2050 | - | 0.7068 |
| 4.7085 | 2100 | - | 0.7101 |
| 4.8206 | 2150 | - | 0.6962 |
| 4.9327 | 2200 | - | 0.6968 |
| 5.0 | 2230 | - | 0.7083 |
| 5.0448 | 2250 | - | 0.7026 |
| 5.1570 | 2300 | - | 0.7023 |
| 5.2691 | 2350 | - | 0.7032 |
| 5.3812 | 2400 | - | 0.7087 |
| 5.4933 | 2450 | - | 0.7171 |
| 5.6054 | 2500 | 0.0291 | 0.7056 |
| 5.7175 | 2550 | - | 0.6969 |
| 5.8296 | 2600 | - | 0.7000 |
| 5.9417 | 2650 | - | 0.7012 |
| 6.0 | 2676 | - | 0.7068 |
| 6.0538 | 2700 | - | 0.7084 |
| 6.1659 | 2750 | - | 0.7002 |
| 6.2780 | 2800 | - | 0.7015 |
| 6.3901 | 2850 | - | 0.6974 |
| 6.5022 | 2900 | - | 0.6903 |
| 6.6143 | 2950 | - | 0.6943 |
| 6.7265 | 3000 | 0.0304 | 0.6938 |
| 6.8386 | 3050 | - | 0.6988 |
| 6.9507 | 3100 | - | 0.7001 |
| 7.0 | 3122 | - | 0.7004 |
| 7.0628 | 3150 | - | 0.7004 |
| 7.1749 | 3200 | - | 0.6950 |
| 7.2870 | 3250 | - | 0.6975 |
| 7.3991 | 3300 | - | 0.6927 |
| 7.5112 | 3350 | - | 0.6974 |
| 7.6233 | 3400 | - | 0.6928 |
| 7.7354 | 3450 | - | 0.6963 |
| 7.8475 | 3500 | 0.0207 | 0.6930 |
| 7.9596 | 3550 | - | 0.6938 |
| 8.0 | 3568 | - | 0.6952 |
| 8.0717 | 3600 | - | 0.6936 |
| 8.1839 | 3650 | - | 0.7045 |
| 8.2960 | 3700 | - | 0.6964 |
| 8.4081 | 3750 | - | 0.6940 |
| 8.5202 | 3800 | - | 0.6989 |
| 8.6323 | 3850 | - | 0.6991 |
| 8.7444 | 3900 | - | 0.6992 |
| 8.8565 | 3950 | - | 0.6997 |
| 8.9686 | 4000 | 0.0228 | 0.7004 |
| 9.0 | 4014 | - | 0.6993 |
| 9.0807 | 4050 | - | 0.7030 |
| 9.1928 | 4100 | - | 0.7040 |
| 9.3049 | 4150 | - | 0.7071 |
| 9.4170 | 4200 | - | 0.7059 |
| 9.5291 | 4250 | - | 0.7049 |
| 9.6413 | 4300 | - | 0.7037 |
| 9.7534 | 4350 | - | 0.7037 |
| 9.8655 | 4400 | - | 0.7038 |
| 9.9776 | 4450 | - | 0.7036 |
| 10.0 | 4460 | - | 0.7036 |
@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{kusupati2024matryoshka,
title={Matryoshka Representation Learning},
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},
year={2024},
eprint={2205.13147},
archivePrefix={arXiv},
primaryClass={cs.LG}
}
@misc{henderson2017efficient,
title={Efficient Natural Language Response Suggestion for Smart Reply},
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},
year={2017},
eprint={1705.00652},
archivePrefix={arXiv},
primaryClass={cs.CL}
}
Base model
Snowflake/snowflake-arctic-embed-l