Matryoshka Representation Learning
Paper • 2205.13147 • Published • 25
This is a sentence-transformers model finetuned from BAAI/bge-small-en-v1.5. It maps sentences & paragraphs to a 384-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': True, 'architecture': 'BertModel'})
(1): Pooling({'word_embedding_dimension': 384, '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("sentence_transformers_model_id")
# Run inference
sentences = [
'Omar | Kelly | Cunningham, Williams and Williams | omar.kelly@icloud.com | Germany',
'Omar | Kully | | omar.kelly@icloud.com | Germany',
'Karen | Williams | Cunningham Ltd | kwilliams@cunningham-ltd.com | USA',
]
embeddings = model.encode(sentences)
print(embeddings.shape)
# [3, 384]
# Get the similarity scores for the embeddings
similarities = model.similarity(embeddings, embeddings)
print(similarities)
# tensor([[ 1.0000, 0.8342, 0.1965],
# [ 0.8342, 1.0000, -0.0804],
# [ 0.1965, -0.0804, 1.0000]])
anchor, positive, and negative| anchor | positive | negative | |
|---|---|---|---|
| type | string | string | string |
| details |
|
|
|
| anchor | positive | negative |
|---|---|---|
Shelby | Carlson | May, Hobbs and Morrow | shelby.carlson@may-hobbs-and-morrow.com | USA |
Shelbyx | Carlson | May, Hobbs and Morrow | shelby.carlson@may-hobbs-and-morrow.com | USA |
Becky | Woods | Peterson, Brown and Copeland | becky.woods@yahoo.com | USA |
Jessica | Howard | Walton, Floyd and Roth | jessica_howard@walton-floyd-and-rot.com | Germany |
Jexssica | Howard | | jessica_howard@walton-floyd-and-rot.com | Germany |
Benjamin | Herrera | Walton, Herring and Cruz | benjamin.herrera@gmail.com | USA |
Sean | Glover | Davis, Munoz and Robinson | sean_glover@davis-munoz-and-robi.com | USA |
Sean | Glo | Davis, Munoz and Robinson | sean_glover@davis-munoz-and-robi.com | USA |
Jeremy | Brown | Davis-Murray | jeremy.brown@davis-murray.com | USA |
MatryoshkaLoss with these parameters:{
"loss": "MultipleNegativesRankingLoss",
"matryoshka_dims": [
384,
256,
128,
64
],
"matryoshka_weights": [
1,
1,
1,
1
],
"n_dims_per_step": -1
}
per_device_train_batch_size: 256learning_rate: 2e-05warmup_steps: 704weight_decay: 0.01fp16: Truedataloader_num_workers: 4per_device_train_batch_size: 256num_train_epochs: 3max_steps: -1learning_rate: 2e-05lr_scheduler_type: linearlr_scheduler_kwargs: Nonewarmup_steps: 704optim: adamw_torchoptim_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: 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: trackioeval_strategy: noper_device_eval_batch_size: 8prediction_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: Falseignore_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: 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: {}learning_rate_mapping: {}| Epoch | Step | Training Loss |
|---|---|---|
| 0.0213 | 50 | 7.2551 |
| 0.0426 | 100 | 1.3914 |
| 0.0639 | 150 | 0.1792 |
| 0.0851 | 200 | 0.1088 |
| 0.1064 | 250 | 0.0880 |
| 0.1277 | 300 | 0.0769 |
| 0.1490 | 350 | 0.0676 |
| 0.1703 | 400 | 0.0551 |
| 0.1916 | 450 | 0.0486 |
| 0.2129 | 500 | 0.0488 |
| 0.2341 | 550 | 0.0449 |
| 0.2554 | 600 | 0.0408 |
| 0.2767 | 650 | 0.0417 |
| 0.2980 | 700 | 0.0505 |
| 0.3193 | 750 | 0.0402 |
| 0.3406 | 800 | 0.0424 |
| 0.3619 | 850 | 0.0355 |
| 0.3831 | 900 | 0.0372 |
| 0.4044 | 950 | 0.0326 |
| 0.4257 | 1000 | 0.0314 |
| 0.4470 | 1050 | 0.0314 |
| 0.4683 | 1100 | 0.0310 |
| 0.4896 | 1150 | 0.0265 |
| 0.5109 | 1200 | 0.0399 |
| 0.5321 | 1250 | 0.0334 |
| 0.5534 | 1300 | 0.0256 |
| 0.5747 | 1350 | 0.0253 |
| 0.5960 | 1400 | 0.0250 |
| 0.6173 | 1450 | 0.0302 |
| 0.6386 | 1500 | 0.0233 |
| 0.6599 | 1550 | 0.0283 |
| 0.6811 | 1600 | 0.0275 |
| 0.7024 | 1650 | 0.0264 |
| 0.7237 | 1700 | 0.0341 |
| 0.7450 | 1750 | 0.0263 |
| 0.7663 | 1800 | 0.0244 |
| 0.7876 | 1850 | 0.0235 |
| 0.8089 | 1900 | 0.0270 |
| 0.8301 | 1950 | 0.0225 |
| 0.8514 | 2000 | 0.0260 |
| 0.8727 | 2050 | 0.0225 |
| 0.8940 | 2100 | 0.0230 |
| 0.9153 | 2150 | 0.0260 |
| 0.9366 | 2200 | 0.0228 |
| 0.9579 | 2250 | 0.0259 |
| 0.9791 | 2300 | 0.0266 |
| 1.0004 | 2350 | 0.0201 |
| 1.0217 | 2400 | 0.0172 |
| 1.0430 | 2450 | 0.0189 |
| 1.0643 | 2500 | 0.0200 |
| 1.0856 | 2550 | 0.0216 |
| 1.1069 | 2600 | 0.0224 |
| 1.1281 | 2650 | 0.0205 |
| 1.1494 | 2700 | 0.0236 |
| 1.1707 | 2750 | 0.0231 |
| 1.1920 | 2800 | 0.0182 |
| 1.2133 | 2850 | 0.0275 |
| 1.2346 | 2900 | 0.0262 |
| 1.2559 | 2950 | 0.0230 |
| 1.2771 | 3000 | 0.0176 |
| 1.2984 | 3050 | 0.0224 |
| 1.3197 | 3100 | 0.0222 |
| 1.3410 | 3150 | 0.0245 |
| 1.3623 | 3200 | 0.0192 |
| 1.3836 | 3250 | 0.0168 |
| 1.4049 | 3300 | 0.0216 |
| 1.4261 | 3350 | 0.0160 |
| 1.4474 | 3400 | 0.0174 |
| 1.4687 | 3450 | 0.0161 |
| 1.4900 | 3500 | 0.0207 |
| 1.5113 | 3550 | 0.0238 |
| 1.5326 | 3600 | 0.0155 |
| 1.5539 | 3650 | 0.0185 |
| 1.5751 | 3700 | 0.0170 |
| 1.5964 | 3750 | 0.0202 |
| 1.6177 | 3800 | 0.0176 |
| 1.6390 | 3850 | 0.0237 |
| 1.6603 | 3900 | 0.0171 |
| 1.6816 | 3950 | 0.0211 |
| 1.7029 | 4000 | 0.0180 |
| 1.7241 | 4050 | 0.0162 |
| 1.7454 | 4100 | 0.0169 |
| 1.7667 | 4150 | 0.0200 |
| 1.7880 | 4200 | 0.0170 |
| 1.8093 | 4250 | 0.0178 |
| 1.8306 | 4300 | 0.0210 |
| 1.8519 | 4350 | 0.0232 |
| 1.8731 | 4400 | 0.0180 |
| 1.8944 | 4450 | 0.0173 |
| 1.9157 | 4500 | 0.0191 |
| 1.9370 | 4550 | 0.0203 |
| 1.9583 | 4600 | 0.0155 |
| 1.9796 | 4650 | 0.0184 |
| 2.0009 | 4700 | 0.0173 |
| 2.0221 | 4750 | 0.0151 |
| 2.0434 | 4800 | 0.0170 |
| 2.0647 | 4850 | 0.0185 |
| 2.0860 | 4900 | 0.0146 |
| 2.1073 | 4950 | 0.0159 |
| 2.1286 | 5000 | 0.0225 |
| 2.1499 | 5050 | 0.0152 |
| 2.1711 | 5100 | 0.0219 |
| 2.1924 | 5150 | 0.0166 |
| 2.2137 | 5200 | 0.0190 |
| 2.2350 | 5250 | 0.0184 |
| 2.2563 | 5300 | 0.0182 |
| 2.2776 | 5350 | 0.0241 |
| 2.2989 | 5400 | 0.0164 |
| 2.3201 | 5450 | 0.0168 |
| 2.3414 | 5500 | 0.0203 |
| 2.3627 | 5550 | 0.0184 |
| 2.3840 | 5600 | 0.0176 |
| 2.4053 | 5650 | 0.0204 |
| 2.4266 | 5700 | 0.0156 |
| 2.4479 | 5750 | 0.0223 |
| 2.4691 | 5800 | 0.0216 |
| 2.4904 | 5850 | 0.0139 |
| 2.5117 | 5900 | 0.0179 |
| 2.5330 | 5950 | 0.0180 |
| 2.5543 | 6000 | 0.0164 |
| 2.5756 | 6050 | 0.0181 |
| 2.5968 | 6100 | 0.0212 |
| 2.6181 | 6150 | 0.0209 |
| 2.6394 | 6200 | 0.0157 |
| 2.6607 | 6250 | 0.0203 |
| 2.6820 | 6300 | 0.0157 |
| 2.7033 | 6350 | 0.0171 |
| 2.7246 | 6400 | 0.0163 |
| 2.7458 | 6450 | 0.0182 |
| 2.7671 | 6500 | 0.0174 |
| 2.7884 | 6550 | 0.0158 |
| 2.8097 | 6600 | 0.0163 |
| 2.8310 | 6650 | 0.0134 |
| 2.8523 | 6700 | 0.0189 |
| 2.8736 | 6750 | 0.0154 |
| 2.8948 | 6800 | 0.0117 |
| 2.9161 | 6850 | 0.0136 |
| 2.9374 | 6900 | 0.0150 |
| 2.9587 | 6950 | 0.0170 |
| 2.9800 | 7000 | 0.0137 |
@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
BAAI/bge-small-en-v1.5