Matryoshka Representation Learning
Paper • 2205.13147 • Published • 27
How to use fjavigv24/snoweu with sentence-transformers:
from sentence_transformers import SentenceTransformer
model = SentenceTransformer("fjavigv24/snoweu")
sentences = [
"What are the conditions that must be met for the appointment of a depositary established in a third country for non-EU AIFs?",
"(a)\n\nfor EU AIFs, in the home Member State of the AIF;\n\n(b)\n\nfor non-EU AIFs, in the third country where the AIF is established or in the home Member State of the AIFM managing the AIF or in the Member State of reference of the AIFM managing the AIF.\n\n6.\n\nWithout prejudice to the requirements set out in paragraph 3, the appointment of a depositary established in a third country shall, at all times, be subject to the following conditions:\n\n(a)",
"(c)\n\nthe financial soundness of the proposed acquirer, in particular in relation to the type of business pursued and envisaged in the investment firm in which the acquisition is proposed;\n\n(d)\n\nwhether the investment firm will be able to comply and continue to comply with the prudential requirements based on this Directive and, where applicable, other Directives, in particular Directives 2002/87/EC and 2013/36/EU, in particular, whether the group of which it will become a part has a structure that makes it possible to exercise effective supervision, effectively exchange information among the competent authorities and determine the allocation of responsibilities among the competent authorities;\n\n(e)",
"(f)\n\nthe undertaking shall describe the expected decarbonisation levers and their overall quantitative contributions to achieve the GHG emission reduction targets (e.g., energy or material efficiency and consumption reduction, fuel switching, use of renewable energy , phase out or substitution of product and process).\n\nDisclosure Requirement E1-5 – Energy consumption and mix\n\nThe undertaking shall provide information on its energy consumption and mix.\n\nThe objective of this Disclosure Requirement is to provide an understanding of the undertaking’s total energy consumption in absolute value, improvement in energy efficiency, exposure to coal, oil and gas-related activities, and the share of renewable energy in its overall energy mix."
]
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-m-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': 512, 'do_lower_case': False}) with Transformer model: BertModel
(1): Pooling({'word_embedding_dimension': 768, '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 = [
'What types of substances or mixtures should be listed in relation to their potential to react and create hazardous situations, and what additional information is required to manage the associated risks?',
'Families of substances or mixtures or specific substances, such as water, air, acids, bases, oxidising agents, with which the substance or mixture could react to produce a hazardous situation (like an explosion, a release of toxic or flammable materials, or a liberation of excessive heat), shall be listed and if appropriate a brief description of measures to be taken to manage risks associated with such hazards shall be given.\n\n10.6. Hazardous decomposition products\n\nKnown and reasonably anticipated hazardous decomposition products produced as a result of use, storage, spill and heating shall be listed. Hazardous combustion products shall be included in section 5 of the safety data sheet.\n\n11. SECTION 11: Toxicological information',
'The undertaking shall specify as part of the contextual information, whether the targets that it has set and presented are mandatory (required by legislation) or voluntary.\n\nDisclosure Requirement E2-4 – Pollution of air, water and soil\n\nThe undertaking shall disclose the pollutants that it emits through its own operations, as well as the microplastics it generates or uses.\n\nThe objective of this Disclosure Requirement is to provide an understanding of the emissions that the undertaking generates to air, water and soil in its own operations, and of its generation and use of microplastics.\n\nThe undertaking shall disclose the amounts of:\n\n(a)',
]
embeddings = model.encode(sentences)
print(embeddings.shape)
# [3, 768]
# Get the similarity scores for the embeddings
similarities = model.similarity(embeddings, embeddings)
print(similarities.shape)
# [3, 3]
InformationRetrievalEvaluator| Metric | Value |
|---|---|
| cosine_accuracy@1 | 0.7468 |
| cosine_accuracy@3 | 0.8989 |
| cosine_accuracy@5 | 0.9306 |
| cosine_accuracy@10 | 0.9605 |
| cosine_precision@1 | 0.7468 |
| cosine_precision@3 | 0.2996 |
| cosine_precision@5 | 0.1861 |
| cosine_precision@10 | 0.096 |
| cosine_recall@1 | 0.7468 |
| cosine_recall@3 | 0.8989 |
| cosine_recall@5 | 0.9306 |
| cosine_recall@10 | 0.9605 |
| cosine_ndcg@10 | 0.8608 |
| cosine_mrr@10 | 0.8281 |
| cosine_map@100 | 0.8298 |
InformationRetrievalEvaluator| Metric | Value |
|---|---|
| cosine_accuracy@1 | 0.7531 |
| cosine_accuracy@3 | 0.9079 |
| cosine_accuracy@5 | 0.9402 |
| cosine_accuracy@10 | 0.968 |
| cosine_precision@1 | 0.7531 |
| cosine_precision@3 | 0.3026 |
| cosine_precision@5 | 0.188 |
| cosine_precision@10 | 0.0968 |
| cosine_recall@1 | 0.7531 |
| cosine_recall@3 | 0.9079 |
| cosine_recall@5 | 0.9402 |
| cosine_recall@10 | 0.968 |
| cosine_ndcg@10 | 0.8682 |
| cosine_mrr@10 | 0.8354 |
| cosine_map@100 | 0.8368 |
InformationRetrievalEvaluator| Metric | Value |
|---|---|
| cosine_accuracy@1 | 0.8397 |
| cosine_accuracy@3 | 0.9556 |
| cosine_accuracy@5 | 0.9746 |
| cosine_accuracy@10 | 0.9897 |
| cosine_precision@1 | 0.8397 |
| cosine_precision@3 | 0.3185 |
| cosine_precision@5 | 0.1949 |
| cosine_precision@10 | 0.099 |
| cosine_recall@1 | 0.8397 |
| cosine_recall@3 | 0.9556 |
| cosine_recall@5 | 0.9746 |
| cosine_recall@10 | 0.9897 |
| cosine_ndcg@10 | 0.9226 |
| cosine_mrr@10 | 0.9002 |
| cosine_map@100 | 0.9008 |
sentence_0 and sentence_1| sentence_0 | sentence_1 | |
|---|---|---|
| type | string | string |
| details |
|
|
| sentence_0 | sentence_1 |
|---|---|
What are the key considerations the Commission must evaluate when assessing the feasibility of including municipal waste incineration installations in the EU ETS by 31 July 2026? |
By 31 July 2026, the Commission shall present a report to the European Parliament and to the Council in which it shall assess the feasibility of including municipal waste incineration installations in the EU ETS, including with a view to their inclusion from 2028 and with an assessment of the potential need for an option for a Member State to opt out until 31 December 2030. In that regard, the Commission shall take into account the importance of all sectors contributing to emission reductions and potential diversion of waste towards disposal by landfilling in the Union and waste exports to third countries. The Commission shall in addition take into account relevant criteria such as the effects on the internal market, potential distortions |
What are the conditions under which a registrant can withhold certain information from disclosure, and what steps must they take to justify this decision? |
NOTES |
What are the specific color indices and chemical identifiers for Pigment Red 112 and Pigment Yellow 14, and what is their respective concentration percentage? |
17 (PR17)/CI 12390 229-681-4 6655-84-1 0,1 % Pigment Red 112 (PR112)/CI 12370 229-440-3 6535-46-2 0,1 % Pigment Yellow 14 (PY14)/CI 21095 226-789-3 5468-75-7 0,1 % Pigment Yellow 55 (PY55)/CI 21096 226-789-3 6358-37-8 0,1 % Pigment Red 2 (PR2)/CI 12310 227-930-1 6041-94-7 0,1 % Pigment Red 22 (PR22)/CI 12315 229-245-3 6448-95-9 0,1 % Pigment Red 146 (PR146)/CI 12485 226-103-2 5280-68-2 0,1 % Pigment Red 269 (PR269)/CI 12466 268-028-8 67990-05-0 0,1 % Pigment Orange16 (PO16)/CI 21160 229-388-1 6505-28-8 0,1 % Pigment Yellow 1 (PY1)/CI 11680 219-730-8 2512-29-0 0,1 % Pigment Yellow 12 (PY12)/CI 21090 228-787-8 6358-85-6 0,1 % Pigment Yellow 87 (PY87)/CI 21107:1 239-160-3 15110-84-6, 14110-84-6 0,1 % Pigment Yellow 97 (PY97)/CI 11767 |
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: stepsper_device_train_batch_size: 6per_device_eval_batch_size: 6num_train_epochs: 4multi_dataset_batch_sampler: round_robinoverwrite_output_dir: Falsedo_predict: Falseeval_strategy: stepsprediction_loss_only: Trueper_device_train_batch_size: 6per_device_eval_batch_size: 6per_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: 4max_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}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: 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: Nonedispatch_batches: Nonesplit_batches: 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.0228 | 100 | - | 0.6723 |
| 0.0456 | 200 | - | 0.7870 |
| 0.0684 | 300 | - | 0.8397 |
| 0.0912 | 400 | - | 0.8608 |
| 0.1141 | 500 | 0.4135 | - |
| 0.0228 | 100 | - | 0.8669 |
| 0.0456 | 200 | - | 0.8682 |
| 0.0228 | 100 | - | 0.8699 |
| 0.0456 | 200 | - | 0.8733 |
| 0.0684 | 300 | - | 0.8759 |
| 0.0912 | 400 | - | 0.8802 |
| 0.1141 | 500 | 0.1122 | 0.8823 |
| 0.1369 | 600 | - | 0.8847 |
| 0.1597 | 700 | - | 0.8835 |
| 0.1825 | 800 | - | 0.8862 |
| 0.2053 | 900 | - | 0.8864 |
| 0.2281 | 1000 | 0.1299 | 0.8860 |
| 0.2509 | 1100 | - | 0.8837 |
| 0.2737 | 1200 | - | 0.8861 |
| 0.2965 | 1300 | - | 0.8882 |
| 0.3193 | 1400 | - | 0.8850 |
| 0.3422 | 1500 | 0.123 | 0.8916 |
| 0.3650 | 1600 | - | 0.8866 |
| 0.3878 | 1700 | - | 0.8917 |
| 0.4106 | 1800 | - | 0.8918 |
| 0.4334 | 1900 | - | 0.8904 |
| 0.4562 | 2000 | 0.0769 | 0.8896 |
| 0.4790 | 2100 | - | 0.8876 |
| 0.5018 | 2200 | - | 0.8956 |
| 0.5246 | 2300 | - | 0.8964 |
| 0.5474 | 2400 | - | 0.8901 |
| 0.5703 | 2500 | 0.0697 | 0.8888 |
| 0.5931 | 2600 | - | 0.8872 |
| 0.6159 | 2700 | - | 0.8839 |
| 0.6387 | 2800 | - | 0.8891 |
| 0.6615 | 2900 | - | 0.8890 |
| 0.6843 | 3000 | 0.0537 | 0.8867 |
| 0.7071 | 3100 | - | 0.8907 |
| 0.7299 | 3200 | - | 0.8916 |
| 0.7527 | 3300 | - | 0.8933 |
| 0.7755 | 3400 | - | 0.8933 |
| 0.7984 | 3500 | 0.0772 | 0.8924 |
| 0.8212 | 3600 | - | 0.8946 |
| 0.8440 | 3700 | - | 0.8953 |
| 0.8668 | 3800 | - | 0.8941 |
| 0.8896 | 3900 | - | 0.8939 |
| 0.9124 | 4000 | 0.065 | 0.8953 |
| 0.9352 | 4100 | - | 0.8969 |
| 0.9580 | 4200 | - | 0.8993 |
| 0.9808 | 4300 | - | 0.9020 |
| 1.0 | 4384 | - | 0.9040 |
| 1.0036 | 4400 | - | 0.9044 |
| 1.0265 | 4500 | 0.0329 | 0.9015 |
| 1.0493 | 4600 | - | 0.8999 |
| 1.0721 | 4700 | - | 0.9005 |
| 1.0949 | 4800 | - | 0.8976 |
| 1.1177 | 4900 | - | 0.9001 |
| 1.1405 | 5000 | 0.024 | 0.9014 |
| 1.1633 | 5100 | - | 0.8995 |
| 1.1861 | 5200 | - | 0.9022 |
| 1.2089 | 5300 | - | 0.9030 |
| 1.2318 | 5400 | - | 0.9027 |
| 1.2546 | 5500 | 0.016 | 0.9024 |
| 1.2774 | 5600 | - | 0.9012 |
| 1.3002 | 5700 | - | 0.9011 |
| 1.3230 | 5800 | - | 0.9049 |
| 1.3458 | 5900 | - | 0.9094 |
| 1.3686 | 6000 | 0.0553 | 0.9094 |
| 1.3914 | 6100 | - | 0.9028 |
| 1.4142 | 6200 | - | 0.9113 |
| 1.4370 | 6300 | - | 0.9118 |
| 1.4599 | 6400 | - | 0.9139 |
| 1.4827 | 6500 | 0.0416 | 0.9112 |
| 1.5055 | 6600 | - | 0.9102 |
| 1.5283 | 6700 | - | 0.9092 |
| 1.5511 | 6800 | - | 0.9098 |
| 1.5739 | 6900 | - | 0.9101 |
| 1.5967 | 7000 | 0.0283 | 0.9107 |
| 1.6195 | 7100 | - | 0.9114 |
| 1.6423 | 7200 | - | 0.9131 |
| 1.6651 | 7300 | - | 0.9130 |
| 1.6880 | 7400 | - | 0.9144 |
| 1.7108 | 7500 | 0.0268 | 0.9126 |
| 1.7336 | 7600 | - | 0.9119 |
| 1.7564 | 7700 | - | 0.9125 |
| 1.7792 | 7800 | - | 0.9111 |
| 1.8020 | 7900 | - | 0.9100 |
| 1.8248 | 8000 | 0.0252 | 0.9110 |
| 1.8476 | 8100 | - | 0.9151 |
| 1.8704 | 8200 | - | 0.9123 |
| 1.8932 | 8300 | - | 0.9118 |
| 1.9161 | 8400 | - | 0.9103 |
| 1.9389 | 8500 | 0.0288 | 0.9110 |
| 1.9617 | 8600 | - | 0.9106 |
| 1.9845 | 8700 | - | 0.9109 |
| 2.0 | 8768 | - | 0.9126 |
| 2.0073 | 8800 | - | 0.9117 |
| 2.0301 | 8900 | - | 0.9114 |
| 2.0529 | 9000 | 0.0232 | 0.9123 |
| 2.0757 | 9100 | - | 0.9113 |
| 2.0985 | 9200 | - | 0.9095 |
| 2.1214 | 9300 | - | 0.9086 |
| 2.1442 | 9400 | - | 0.9109 |
| 2.1670 | 9500 | 0.0188 | 0.9124 |
| 2.1898 | 9600 | - | 0.9125 |
| 2.2126 | 9700 | - | 0.9121 |
| 2.2354 | 9800 | - | 0.9122 |
| 2.2582 | 9900 | - | 0.9132 |
| 2.2810 | 10000 | 0.0182 | 0.9125 |
| 2.3038 | 10100 | - | 0.9142 |
| 2.3266 | 10200 | - | 0.9135 |
| 2.3495 | 10300 | - | 0.9084 |
| 2.3723 | 10400 | - | 0.9147 |
| 2.3951 | 10500 | 0.0111 | 0.9170 |
| 2.4179 | 10600 | - | 0.9142 |
| 2.4407 | 10700 | - | 0.9158 |
| 2.4635 | 10800 | - | 0.9174 |
| 2.4863 | 10900 | - | 0.9176 |
| 2.5091 | 11000 | 0.0153 | 0.9166 |
| 2.5319 | 11100 | - | 0.9172 |
| 2.5547 | 11200 | - | 0.9171 |
| 2.5776 | 11300 | - | 0.9168 |
| 2.6004 | 11400 | - | 0.9176 |
| 2.6232 | 11500 | 0.0241 | 0.9170 |
| 2.6460 | 11600 | - | 0.9177 |
| 2.6688 | 11700 | - | 0.9184 |
| 2.6916 | 11800 | - | 0.9196 |
| 2.7144 | 11900 | - | 0.9211 |
| 2.7372 | 12000 | 0.0172 | 0.9209 |
| 2.7600 | 12100 | - | 0.9212 |
| 2.7828 | 12200 | - | 0.9201 |
| 2.8057 | 12300 | - | 0.9194 |
| 2.8285 | 12400 | - | 0.9205 |
| 2.8513 | 12500 | 0.013 | 0.9202 |
| 2.8741 | 12600 | - | 0.9213 |
| 2.8969 | 12700 | - | 0.9210 |
| 2.9197 | 12800 | - | 0.9203 |
| 2.9425 | 12900 | - | 0.9200 |
| 2.9653 | 13000 | 0.03 | 0.9209 |
| 2.9881 | 13100 | - | 0.9212 |
| 3.0 | 13152 | - | 0.9200 |
| 3.0109 | 13200 | - | 0.9198 |
| 3.0338 | 13300 | - | 0.9192 |
| 3.0566 | 13400 | - | 0.9183 |
| 3.0794 | 13500 | 0.0133 | 0.9170 |
| 3.1022 | 13600 | - | 0.9181 |
| 3.125 | 13700 | - | 0.9180 |
| 3.1478 | 13800 | - | 0.9176 |
| 3.1706 | 13900 | - | 0.9168 |
| 3.1934 | 14000 | 0.0185 | 0.9175 |
| 3.2162 | 14100 | - | 0.9188 |
| 3.2391 | 14200 | - | 0.9182 |
| 3.2619 | 14300 | - | 0.9192 |
| 3.2847 | 14400 | - | 0.9199 |
| 3.3075 | 14500 | 0.0135 | 0.9195 |
| 3.3303 | 14600 | - | 0.9190 |
| 3.3531 | 14700 | - | 0.9187 |
| 3.3759 | 14800 | - | 0.9196 |
| 3.3987 | 14900 | - | 0.9202 |
| 3.4215 | 15000 | 0.0157 | 0.9214 |
| 3.4443 | 15100 | - | 0.9211 |
| 3.4672 | 15200 | - | 0.9211 |
| 3.4900 | 15300 | - | 0.9208 |
| 3.5128 | 15400 | - | 0.9195 |
| 3.5356 | 15500 | 0.015 | 0.9207 |
| 3.5584 | 15600 | - | 0.9210 |
| 3.5812 | 15700 | - | 0.9226 |
@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-m-v1.5