Matryoshka Representation Learning
Paper • 2205.13147 • Published • 30
How to use ysharma/embeddinggemma-2-lora-finder with sentence-transformers:
from sentence_transformers import SentenceTransformer
model = SentenceTransformer("ysharma/embeddinggemma-2-lora-finder")
sentences = [
"https://huggingface.co/furaidosu/dott4kv2-qwen-image-lora/resolve/main/images/070b.png",
"arkh v1. tags: - text-to-image - lora - diffusers - template:diffusion-lora widget: - output: url: images/dc312eca-8240-457d-962c-c8485c94eaa0 min.webp text: '-' base model: Qwen/Qwen-Image instance prompt: null license: creativeml-openrail-m --- arkh v1 <Gallery / Download model Download /Ric13/arkh v1/tree/main them in the Files & versions tab.",
"dott4k qitl. tags: - text-to-image - lora - diffusers - template:diffusion-lora widget: - output: url: images/070b.png text: '-' base model: Qwen/Qwen-Image instance prompt: null --- dott4k-qitl <Gallery / Download model Download /lichorosario/dott4k-qitl/tree/main them in the Files & versions tab.",
"flat color. tags: - text-to-image - lora - diffusers - template:diffusion-lora widget: - text: - , a woman sitting under the night sky, blue hair, blue eyes, stars, off shoulder, she is releasing a star with the text \"夢\" written on it output: url: images/ComfyUI 00852 .png - text: - no 1girl medium pink hair frilled shirt outdoors cherry blossom tree shade sitting"
]
embeddings = model.encode(sentences)
similarities = model.similarity(embeddings, embeddings)
print(similarities.shape)
# [4, 4]This is a sentence-transformers model finetuned from google/embeddinggemma-2 on the img2img and img2text datasets. It maps inputs to a 768-dimensional dense vector space and can be used for semantic textual similarity, semantic search, paraphrase mining, classification, clustering, and more.
SentenceTransformer(
(0): Transformer({'transformer_task': 'feature-extraction', 'modality_config': {'text': {'method': 'forward', 'method_output_name': 'last_hidden_state'}, 'image': {'method': 'forward', 'method_output_name': 'last_hidden_state'}, 'audio': {'method': 'forward', 'method_output_name': 'last_hidden_state'}, 'video': {'method': 'forward', 'method_output_name': 'last_hidden_state'}, 'message': {'method': 'forward', 'method_output_name': 'last_hidden_state', 'format': 'structured'}}, 'module_output_name': 'token_embeddings', 'architecture': 'EmbeddingGemma2Model'})
(1): Pooling({'embedding_dimension': 768, 'pooling_mode': 'mean', 'include_prompt': True})
(2): Normalize({'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 = [
'https://huggingface.co/AIFurryArt/Furrender4/resolve/main/images/image_20260429_124316_00001_.png',
]
documents = [
'https://huggingface.co/AIFurryArt/Furrender4/resolve/main/images/image_20260429_143546_00001_.png',
'https://huggingface.co/Airmongsity/Qwen-Image-2.1-Sts2-Cards-Drawer/resolve/main/samples/bicycle_cfg3.png',
'https://huggingface.co/Alex995647/loras-qwen-image/resolve/main/luisap-cyber-hard-edge-refiner-qwen-sd-1-5/example_images/01_poster.jpg',
]
query_embeddings = model.encode_query(queries)
document_embeddings = model.encode_document(documents)
print(query_embeddings.shape, document_embeddings.shape)
# [1, 768] [3, 768]
# Get the similarity scores for the embeddings
similarities = model.similarity(query_embeddings, document_embeddings)
print(similarities)
# tensor([[0.7789, 0.2734, 0.3807]])
anchor, positive, and label| anchor | positive | label | |
|---|---|---|---|
| type | string | string | int |
| modality | image | image | |
| details |
|
MatryoshkaLoss with these parameters:{
"loss": "CachedMultipleNegativesRankingLoss",
"matryoshka_dims": [
768,
512,
256,
128
],
"matryoshka_weights": [
1,
1,
1,
1
],
"n_dims_per_step": -1
}
anchor, positive, and label| anchor | positive | label | |
|---|---|---|---|
| type | string | string | int |
| modality | image | text | |
| details |
|
|
| anchor | positive | label |
|---|---|---|
https://huggingface.co/1G1/model_1/resolve/main/images/DreamShaper_v7_bugatti_chiron_car_gold_black_and_brown_color_f_1.jpg |
model 1. tags: - text-to-image - lora - diffusers - template:diffusion-lora widget: - output: url: - images/DreamShaper v7 bugatti chiron car gold black and brown color f 0.jpg text: '-' - output: url: - images/DreamShaper v7 bugatti chiron car gold black and brown color f 1.jpg text: '-' base model: Qwen/Qwen-Image instance prompt: null license: unknown --- model |
0 |
https://huggingface.co/AIFurryArt/Furrender4/resolve/main/images/image_20260429_124316_00001_.png |
Furrender4. tags: - text-to-image - lora - diffusers - template:diffusion-lora widget: - output: url: images/image 20260429 143400 00001 .png text: '-' - output: url: images/image 20260429 143546 00001 .png text: '-' - output: url: images/image 20260429 124316 00001 .png text: '-' - output: url: images/image 20260429 144246 00001 .png text: '-' base model: Qwen/Qwen-Image-2512 instance prompt: null licens |
1 |
https://huggingface.co/AIFurryArt/Furrender4/resolve/main/images/image_20260429_143400_00001_.png |
Furrender4. tags: - text-to-image - lora - diffusers - template:diffusion-lora widget: - output: url: images/image 20260429 143400 00001 .png text: '-' - output: url: images/image 20260429 143546 00001 .png text: '-' - output: url: images/image 20260429 124316 00001 .png text: '-' - output: url: images/image 20260429 144246 00001 .png text: '-' base model: Qwen/Qwen-Image-2512 instance prompt: null licens |
1 |
MatryoshkaLoss with these parameters:{
"loss": "CachedMultipleNegativesRankingLoss",
"matryoshka_dims": [
768,
512,
256,
128
],
"matryoshka_weights": [
1,
1,
1,
1
],
"n_dims_per_step": -1
}
warmup_steps: 0.1gradient_accumulation_steps: 4gradient_checkpointing: Truegradient_checkpointing_kwargs: {'use_reentrant': False}seed: 0dataloader_num_workers: 2prompts: {'positive': 'title: none | text: '}multi_dataset_batch_sampler: round_robinper_device_train_batch_size: 8num_train_epochs: 3max_steps: -1learning_rate: 5e-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: 4average_tokens_across_devices: Truemax_grad_norm: 1.0label_smoothing_factor: 0.0bf16: Falsefp16: Falsebf16_full_eval: Falsefp16_full_eval: Falsetf32: Nonegradient_checkpointing: Truegradient_checkpointing_kwargs: {'use_reentrant': False}torch_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: Nonetrackio_bucket_id: Nonetrackio_static_space_id: Noneper_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: 0data_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: 2dataloader_pin_memory: Truedataloader_persistent_workers: Falsedataloader_prefetch_factor: Nonedataloader_multiprocessing_context: Nonedataloader_in_order: Trueremove_unused_columns: Truelabel_names: Nonetrain_sampling_strategy: randomlength_column_name: lengthddp_find_unused_parameters: Noneddp_bucket_cap_mb: Noneddp_broadcast_buffers: Falseddp_static_graph: Noneddp_backend: Noneddp_timeout: 1800fsdp: Nonefsdp_config: Nonedeepspeed: Nonedebug: []skip_memory_metrics: Truedo_predict: Falseresume_from_checkpoint: Nonelocal_rank: -1prompts: {'positive': 'title: none | text: '}multi_dataset_batch_sampler: round_robinrouter_mapping: {}learning_rate_mapping: {}warmup_ratio: None| Epoch | Step | Training Loss |
|---|---|---|
| 0.0270 | 1 | 4.9033 |
| 0.0541 | 2 | 4.8180 |
| 0.0811 | 3 | 4.5931 |
| 0.1081 | 4 | 4.9924 |
| 0.1351 | 5 | 4.7250 |
| 0.1622 | 6 | 4.4046 |
| 0.1892 | 7 | 4.1512 |
| 0.2162 | 8 | 4.9469 |
| 0.2432 | 9 | 3.9789 |
| 0.2703 | 10 | 3.4333 |
| 0.2973 | 11 | 4.5601 |
| 0.3243 | 12 | 3.5051 |
| 0.3514 | 13 | 3.8203 |
| 0.3784 | 14 | 3.2145 |
| 0.4054 | 15 | 3.1062 |
| 0.4324 | 16 | 3.4170 |
| 0.4595 | 17 | 1.7697 |
| 0.4865 | 18 | 2.3831 |
| 0.5135 | 19 | 2.9564 |
| 0.5405 | 20 | 2.9502 |
| 0.5676 | 21 | 2.0586 |
| 0.5946 | 22 | 0.9950 |
| 0.6216 | 23 | 2.1131 |
| 0.6486 | 24 | 1.4838 |
| 0.6757 | 25 | 3.4937 |
| 0.7027 | 26 | 3.6294 |
| 0.7297 | 27 | 3.0332 |
| 0.7568 | 28 | 2.4071 |
| 0.7838 | 29 | 1.1775 |
| 0.8108 | 30 | 2.8131 |
| 0.8378 | 31 | 1.5081 |
| 0.8649 | 32 | 2.3825 |
| 0.8919 | 33 | 2.8080 |
| 0.9189 | 34 | 4.0398 |
| 0.9459 | 35 | 3.8710 |
| 0.9730 | 36 | 2.6129 |
| 1.0 | 37 | 2.2913 |
| 1.0270 | 38 | 1.2656 |
| 1.0541 | 39 | 1.2016 |
| 1.0811 | 40 | 1.4087 |
| 1.1081 | 41 | 1.7025 |
| 1.1351 | 42 | 0.9100 |
| 1.1622 | 43 | 0.7910 |
| 1.1892 | 44 | 0.5866 |
| 1.2162 | 45 | 0.7964 |
| 1.2432 | 46 | 0.6482 |
| 1.2703 | 47 | 0.4225 |
| 1.2973 | 48 | 0.9907 |
| 1.3243 | 49 | 1.1700 |
| 1.3514 | 50 | 1.0258 |
| 1.3784 | 51 | 0.3217 |
| 1.4054 | 52 | 0.7180 |
| 1.4324 | 53 | 0.6770 |
| 1.4595 | 54 | 0.1851 |
| 1.4865 | 55 | 0.5854 |
| 1.5135 | 56 | 0.3662 |
| 1.5405 | 57 | 0.5529 |
| 1.5676 | 58 | 0.2490 |
| 1.5946 | 59 | 0.0477 |
| 1.6216 | 60 | 0.3383 |
| 1.6486 | 61 | 0.2384 |
| 1.6757 | 62 | 0.8208 |
| 1.7027 | 63 | 0.5681 |
| 1.7297 | 64 | 1.5960 |
| 1.7568 | 65 | 0.3041 |
| 1.7838 | 66 | 0.2878 |
| 1.8108 | 67 | 0.9916 |
| 1.8378 | 68 | 0.1962 |
| 1.8649 | 69 | 0.4185 |
| 1.8919 | 70 | 0.5600 |
| 1.9189 | 71 | 1.4224 |
| 1.9459 | 72 | 1.5598 |
| 1.9730 | 73 | 0.6204 |
| 2.0 | 74 | 0.6017 |
| 2.0270 | 75 | 0.2693 |
| 2.0541 | 76 | 0.6998 |
| 2.0811 | 77 | 0.8660 |
| 2.1081 | 78 | 0.6217 |
| 2.1351 | 79 | 0.4224 |
| 2.1622 | 80 | 0.1109 |
| 2.1892 | 81 | 0.1001 |
| 2.2162 | 82 | 0.1740 |
| 2.2432 | 83 | 0.1012 |
| 2.2703 | 84 | 0.0775 |
| 2.2973 | 85 | 0.1709 |
| 2.3243 | 86 | 0.1938 |
| 2.3514 | 87 | 0.2603 |
| 2.3784 | 88 | 0.0836 |
| 2.4054 | 89 | 0.2129 |
| 2.4324 | 90 | 0.2166 |
| 2.4595 | 91 | 0.0363 |
| 2.4865 | 92 | 0.1695 |
| 2.5135 | 93 | 0.0991 |
| 2.5405 | 94 | 0.1143 |
| 2.5676 | 95 | 0.0511 |
| 2.5946 | 96 | 0.0108 |
| 2.6216 | 97 | 0.0765 |
| 2.6486 | 98 | 0.0521 |
| 2.6757 | 99 | 0.3322 |
| 2.7027 | 100 | 0.1612 |
| 2.7297 | 101 | 1.0232 |
| 2.7568 | 102 | 0.1001 |
| 2.7838 | 103 | 0.1492 |
| 2.8108 | 104 | 0.5836 |
| 2.8378 | 105 | 0.0797 |
| 2.8649 | 106 | 0.1807 |
| 2.8919 | 107 | 0.2683 |
| 2.9189 | 108 | 0.8831 |
| 2.9459 | 109 | 1.1199 |
| 2.9730 | 110 | 0.3995 |
| 3.0 | 111 | 0.3393 |
@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{gao2021scaling,
title={Scaling Deep Contrastive Learning Batch Size under Memory Limited Setup},
author={Luyu Gao and Yunyi Zhang and Jiawei Han and Jamie Callan},
year={2021},
eprint={2101.06983},
archivePrefix={arXiv},
primaryClass={cs.LG}
}
@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},
}
Base model
google/embeddinggemma-2