Matryoshka Representation Learning
Paper
• 2205.13147 • Published
• 25
This is a sentence-transformers model finetuned from nomic-ai/nomic-embed-text-v1.5. It maps sentences & paragraphs to a 768-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': 128, 'do_lower_case': False, 'architecture': 'NomicBertModel'})
(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})
)
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 = [
'search_query: whats collected by litfx??',
'search_document: Privacy policy: LITFX collects account information (name, email), usage data (course progress, journal entries, chat messages), and device information for security. Card details are NOT stored on LITFX servers — payments are handled by a secure payment processor. AI Mentor and journal analysis use your data only for generating responses — your data is NOT used to train AI models. The platform uses industry-standard encryption and security protections.',
'search_document: A shooting star has a small body at the bottom with a long upper wick (at least 2x the body). When it appears after an uptrend near resistance, it suggests sellers rejected higher prices. The same shape at the bottom of a downtrend is called an inverted hammer and can signal potential buying interest. Always confirm with the next candle close and surrounding structure.',
]
embeddings = model.encode(sentences)
print(embeddings.shape)
# [3, 768]
# Get the similarity scores for the embeddings
similarities = model.similarity(embeddings, embeddings)
print(similarities)
# tensor([[ 1.0000, 0.4414, -0.1091],
# [ 0.4414, 1.0000, -0.0413],
# [-0.1091, -0.0413, 1.0000]])
anchor, positive, and negative| anchor | positive | negative | |
|---|---|---|---|
| type | string | string | string |
| details |
|
|
|
| anchor | positive | negative |
|---|---|---|
search_query: Why is the previous close important when calculating True Range? |
search_document: Average True Range (ATR) is a volatility indicator that measures the average range of price movement over a specified period, typically 14 periods. Unlike most indicators, ATR does not indicate direction. It measures how much an instrument moves on average per period, providing a volatility baseline. True Range is the greatest of: current high minus current low, absolute value of current high minus previous close, or absolute value of current low minus previous close. The inclusion of the previous close accounts for gaps between periods. ATR is then the average of True Range values over the lookback period. ATR is practical for position sizing and stop loss placement. If an instrument has an ATR of 80 pips on the daily chart, a stop loss of 15 pips is likely too tight relative to normal daily movement and has a high probability of being hit by normal price fluctuation. A stop loss of 1 to 1.5 times ATR provides room for normal volatility while still defining risk. ATR-... |
search_document: NFP releases can trigger rapid repricing and volatility spikes. Traders should plan for uncertainty and avoid impulsive execution around high-impact data. |
search_query: Can I post multiple images in a single message? |
search_document: Community has 9 or more channels organized by topic. Trading channels: entries, analysis, front-testing, crypto, stock, questions, stop-losses, fundamental-analysis, trade-ideas. General channels: announcement, general-chat, homework. Results channel and sunday-talk (weekly mindset). Premium-gated channels: homework, front-testing, entries, stop-losses, questions. Features include text plus multiple images, trade result cards, emoji reactions, reply threads, pinned messages, message editing, and admin moderation tools. Exclusive premium community channels are English-language. |
search_document: Community moderation features: Google Cloud Vision SafeSearch auto-rejects adult, violent, or racy uploaded images. Messages with 3 or more reports are auto-hidden pending review. Community bot with engagement scheduler, filters, and slash commands. Admin audit trails for all moderation actions. User presence shows online, idle, and DND states. Community profiles display role (CEO, admin, moderator, student), subscription tier, TQS score, and badges. |
search_query: What qualities or considerations should I keep in mind when choosing a trading style? |
search_document: Scalping uses very short timeframes (M1-M5) for quick small profits, requiring fast execution. Day trading opens and closes positions within the same day, avoiding overnight risk. Swing trading holds positions for days to weeks, capturing larger price moves. Position trading holds for weeks to months based on higher timeframe trends. Each style suits different schedules, risk tolerances, and personalities. |
search_document: The forex market operates 24 hours a day, five days a week, through four major trading sessions that overlap across global time zones. The Sydney session opens first (22:00 UTC) and is typically the quietest, with lower volatility and tighter ranges on most pairs. The Tokyo session (00:00 UTC) brings more activity to JPY pairs and Asia-Pacific currencies, with moderate volatility. The London session (08:00 UTC) is the most liquid and volatile session, accounting for the largest share of daily forex volume. Major pairs like EURUSD and GBPUSD see their strongest moves during London. The New York session (13:00 UTC) overlaps with London for several hours, creating the highest-activity window of the day. This London-New York overlap (13:00-17:00 UTC) typically produces the most significant price movements, widest ranges, and highest trading volume. Understanding sessions matters because spread costs, volatility, and liquidity all change throughout the day. Trading during l... |
MatryoshkaLoss with these parameters:{
"loss": "MultipleNegativesRankingLoss",
"matryoshka_dims": [
768,
512,
256,
128
],
"matryoshka_weights": [
1,
1,
1,
1
],
"n_dims_per_step": -1
}
per_device_train_batch_size: 4gradient_accumulation_steps: 4learning_rate: 2e-05num_train_epochs: 5warmup_ratio: 0.1fp16: Truegradient_checkpointing: Truebatch_sampler: no_duplicatesoverwrite_output_dir: Falsedo_predict: Falseeval_strategy: noprediction_loss_only: Trueper_device_train_batch_size: 4per_device_eval_batch_size: 8per_gpu_train_batch_size: Noneper_gpu_eval_batch_size: Nonegradient_accumulation_steps: 4eval_accumulation_steps: Nonetorch_empty_cache_steps: Nonelearning_rate: 2e-05weight_decay: 0.0adam_beta1: 0.9adam_beta2: 0.999adam_epsilon: 1e-08max_grad_norm: 1.0num_train_epochs: 5max_steps: -1lr_scheduler_type: linearlr_scheduler_kwargs: Nonewarmup_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: Falserestore_callback_states_from_checkpoint: Falseno_cuda: Falseuse_cpu: Falseuse_mps_device: Falseseed: 42data_seed: Nonejit_mode_eval: 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}parallelism_config: Nonedeepspeed: Nonelabel_smoothing_factor: 0.0optim: adamw_torch_fusedoptim_args: Noneadafactor: Falsegroup_by_length: Falselength_column_name: lengthproject: huggingfacetrackio_space_id: trackioddp_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: Falsehub_revision: Nonegradient_checkpointing: Truegradient_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: noneftune_noise_alpha: Noneoptim_target_modules: Nonebatch_eval_metrics: Falseeval_on_start: Falseuse_liger_kernel: Falseliger_kernel_config: Noneeval_use_gather_object: Falseaverage_tokens_across_devices: Trueprompts: Nonebatch_sampler: no_duplicatesmulti_dataset_batch_sampler: proportionalrouter_mapping: {}learning_rate_mapping: {}| Epoch | Step | Training Loss |
|---|---|---|
| 0.0787 | 10 | 1.7278 |
| 0.1575 | 20 | 1.36 |
| 0.2362 | 30 | 1.3364 |
| 0.3150 | 40 | 1.0988 |
| 0.3937 | 50 | 0.8147 |
| 0.4724 | 60 | 0.7897 |
| 0.5512 | 70 | 1.0812 |
| 0.6299 | 80 | 0.6983 |
| 0.7087 | 90 | 1.0156 |
| 0.7874 | 100 | 0.7213 |
| 0.8661 | 110 | 1.0232 |
| 0.9449 | 120 | 0.9498 |
| 1.0236 | 130 | 0.9438 |
| 1.1024 | 140 | 0.3809 |
| 1.1811 | 150 | 0.305 |
| 1.2598 | 160 | 0.2767 |
| 1.3386 | 170 | 0.2916 |
| 1.4173 | 180 | 0.4454 |
| 1.4961 | 190 | 0.1269 |
| 1.5748 | 200 | 0.5194 |
| 1.6535 | 210 | 0.2117 |
| 1.7323 | 220 | 0.3201 |
| 1.8110 | 230 | 0.2843 |
| 1.8898 | 240 | 0.2896 |
| 1.9685 | 250 | 0.3519 |
| 2.0472 | 260 | 0.306 |
| 2.1260 | 270 | 0.0523 |
| 2.2047 | 280 | 0.0743 |
| 2.2835 | 290 | 0.1769 |
| 2.3622 | 300 | 0.0635 |
| 2.4409 | 310 | 0.1496 |
| 2.5197 | 320 | 0.1572 |
| 2.5984 | 330 | 0.2366 |
| 2.6772 | 340 | 0.0982 |
| 2.7559 | 350 | 0.201 |
| 2.8346 | 360 | 0.0738 |
| 2.9134 | 370 | 0.1147 |
| 2.9921 | 380 | 0.1934 |
| 3.0709 | 390 | 0.0377 |
| 3.1496 | 400 | 0.0868 |
| 3.2283 | 410 | 0.1168 |
| 3.3071 | 420 | 0.0919 |
| 3.3858 | 430 | 0.0835 |
| 3.4646 | 440 | 0.0841 |
| 3.5433 | 450 | 0.1205 |
| 3.6220 | 460 | 0.0294 |
| 3.7008 | 470 | 0.0525 |
| 3.7795 | 480 | 0.0754 |
| 3.8583 | 490 | 0.3049 |
| 3.9370 | 500 | 0.3836 |
| 4.0157 | 510 | 0.029 |
| 4.0945 | 520 | 0.1829 |
| 4.1732 | 530 | 0.1849 |
| 4.2520 | 540 | 0.113 |
| 4.3307 | 550 | 0.0212 |
| 4.4094 | 560 | 0.0111 |
| 4.4882 | 570 | 0.1175 |
| 4.5669 | 580 | 0.0695 |
| 4.6457 | 590 | 0.222 |
| 4.7244 | 600 | 0.0206 |
| 4.8031 | 610 | 0.0396 |
| 4.8819 | 620 | 0.0366 |
| 4.9606 | 630 | 0.2206 |
@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
nomic-ai/nomic-embed-text-v1.5