Matryoshka Representation Learning
Paper
•
2205.13147
•
Published
•
25
This is a sentence-transformers model finetuned from truro7/vn-law-embedding. 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: XLMRobertaModel
(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})
(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 = [
'nghĩa vụ đăng ký tạm trú được quy định như thế nào đối với hssv ngoại trú và hssv nội trú ?',
'hiện hành của Nhà nước. 7. HSSV nữ. 8. HSSV tích cực tham gia các hoạt động do nhà trường, Đoàn TNCS Hồ Chí Minh, Hội Sinh viên, khu nội trú hoặc các tổ chức xã hội tổ chức. 156 \n \nĐiều 5. Quyền của học sinh, sinh viên nội trú \n1. Được tôn trọng và đối xử bình đẳng; được ở và sử dụng các trang thiết bị \ntrong khu nội trú theo hợp đồng nội trú đã ký với nhà trường (hoặc Trưởng ban quản \nlý khu nội trú) để phục vụ học tập và sinh hoạt. \n2. Được tham gia các hoạt động phục vụ đời sống văn hoá, tinh thần do nhà \ntrường tổ chức trong khu nội trú. \n3. Được đảm bảo an ninh, trật tự, an toàn và vệ sinh môi trường trong khu nội \ntrú. \n4. Được kiến nghị với Trưởng ban quản lý khu nội trú và nhà trường các giải \npháp để góp phần xây dựng khu nội trú văn minh, sạch đẹp, an toàn; được đề đạt \nnguyện vọng và khiếu nại lên trưởng ban quản lý khu nội trú của nhà trường giải \nquyết các vấn đề có liên quan đến quyền, lợi ích chính đáng của HSSV trong khu \nnội trú. \nĐiều 6. Nghĩa vụ của học sinh, sinh viên nội trú \n1. Thực hiện đăng ký tạm trú theo đúng quy định của Luật Cư trú hiện hành. \nNếu vắng mặt tại khu nội trú quá 1 ngày phải báo với Ban quản lý khu nội trú. \n2. Chấp hành các quy định của khu nội trú về việc tiếp khách trong phòng ở, \ngiờ tự học, tổ chức các sinh hoạt văn hóa, văn nghệ, không gây ảnh hưởng đến việc \nhọc tập, sinh hoạt của HSSV khác trong phòng ở và khu nội trú. Đoàn kết thực hiện \nnếp sống văn minh, văn hóa trong khu nội trú. \n3. Tiết kiệm điện, nước, phòng chống cháy nổ, có ý thức giữ gìn và bảo vệ tài \nsản chung trong khu nội trú. \n4. Nộp đủ và đúng hạn phí nội trú theo quy định trong hợp đồng. \n5. Nếu làm hư hỏng, mất mát tài sản của khu nội trú phải bồi thường theo quy \nđịnh của Ban quản lý khu nội trú.',
'Trở thành một trường đại học hàng đầu tại Việt Nam và \nĐông Nam Á về đào tạo, nghiên cứu khoa học, công nghệ \nnền tảng của kinh tế tri thức và kinh tế số.\nTẦM NHÌN 2030\nTrường Đại học Khoa học tự nhiên là trung tâm đào tạo, \nnghiên cứu, phát triển và triển khai ứng dụng khoa học \ncông nghệ, cung cấp nguồn nhân lực và sản phẩm khoa học \ncông nghệ đáp ứng yêu cầu phát triển kinh tế - xã hội đất nước.\nSỨ MẠNG\nSỨ MẠNG, TẦM NHÌN,\nTRIẾT LÝ GIÁO DỤC\n1',
]
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]
dim_128InformationRetrievalEvaluator| Metric | Value |
|---|---|
| cosine_accuracy@1 | 0.9013 |
| cosine_accuracy@3 | 0.9893 |
| cosine_accuracy@5 | 0.9987 |
| cosine_accuracy@10 | 0.9987 |
| cosine_precision@1 | 0.9013 |
| cosine_precision@3 | 0.4636 |
| cosine_precision@5 | 0.2877 |
| cosine_precision@10 | 0.1447 |
| cosine_recall@1 | 0.7172 |
| cosine_recall@3 | 0.9693 |
| cosine_recall@5 | 0.9922 |
| cosine_recall@10 | 0.996 |
| cosine_ndcg@10 | 0.9526 |
| cosine_mrr@10 | 0.9443 |
| cosine_map@100 | 0.9335 |
anchors and positives| anchors | positives | |
|---|---|---|
| type | string | string |
| details |
|
|
| anchors | positives |
|---|---|
vi phạm nội trú thì xử lý theo quy chế nào |
đủ và đúng hạn phí nội trú theo quy định trong hợp đồng. 5. Nếu làm hư hỏng, mất mát tài sản của khu nội trú phải bồi thường theo quy định của Ban quản lý khu nội trú. 157 |
vi phạm nội trú thì xử lý theo quy chế nào |
1. Các sở giáo dục và đào tạo, các cơ quan có liên quan và các nhà trường theo thẩm quyền tổ chức kiểm tra, sơ kết, tổng kết, đánh giá việc thực hiện công tác HSSV nội trú. 158 |
những quy định nào giúp đảm bảo sinh viên không bị quá tải học phần ? |
trí đều trong các tuần của học kỳ. Trong trường hợp cần thiết phải xếp lịch học tập trung thời gian, số giờ giảng đối với một học phần bất kỳ không vượt quá 15 giờ/tuần và 4 giờ/ngày. 64 |
MatryoshkaLoss with these parameters:{
"loss": "MultipleNegativesRankingLoss",
"matryoshka_dims": [
768,
512,
256,
128
],
"matryoshka_weights": [
1,
1,
1,
1
],
"n_dims_per_step": -1
}
eval_strategy: stepsper_device_train_batch_size: 4per_device_eval_batch_size: 4gradient_accumulation_steps: 4learning_rate: 3e-05num_train_epochs: 10lr_scheduler_type: cosinewarmup_ratio: 0.15bf16: Trueload_best_model_at_end: Trueoptim: adamw_torch_fusedbatch_sampler: no_duplicatesoverwrite_output_dir: Falsedo_predict: Falseeval_strategy: stepsprediction_loss_only: Trueper_device_train_batch_size: 4per_device_eval_batch_size: 4per_gpu_train_batch_size: Noneper_gpu_eval_batch_size: Nonegradient_accumulation_steps: 4eval_accumulation_steps: Nonetorch_empty_cache_steps: Nonelearning_rate: 3e-05weight_decay: 0.0adam_beta1: 0.9adam_beta2: 0.999adam_epsilon: 1e-08max_grad_norm: 1.0num_train_epochs: 10max_steps: -1lr_scheduler_type: cosinelr_scheduler_kwargs: {}warmup_ratio: 0.15warmup_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: Truefp16: 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: Trueignore_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_torch_fusedoptim_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: no_duplicatesmulti_dataset_batch_sampler: proportional| Epoch | Step | Training Loss | dim_128_cosine_ndcg@10 |
|---|---|---|---|
| -1 | -1 | - | 0.6107 |
| 0.1085 | 30 | 9.8551 | 0.6259 |
| 0.2170 | 60 | 9.0754 | 0.6484 |
| 0.3255 | 90 | 6.8585 | 0.6729 |
| 0.4340 | 120 | 6.1144 | 0.6971 |
| 0.5425 | 150 | 5.6528 | 0.7277 |
| 0.6510 | 180 | 4.1877 | 0.7421 |
| 0.7595 | 210 | 4.7228 | 0.7576 |
| 0.8680 | 240 | 4.0221 | 0.7697 |
| 0.9765 | 270 | 3.9123 | 0.7772 |
| 1.0832 | 300 | 3.5228 | 0.7999 |
| 1.1917 | 330 | 2.4771 | 0.8097 |
| 1.3002 | 360 | 3.1504 | 0.8105 |
| 1.4087 | 390 | 2.9297 | 0.8127 |
| 1.5172 | 420 | 2.7076 | 0.8229 |
| 1.6257 | 450 | 2.7434 | 0.8452 |
| 1.7342 | 480 | 2.561 | 0.8357 |
| 1.8427 | 510 | 2.4285 | 0.8446 |
| 1.9512 | 540 | 2.2157 | 0.8451 |
| 2.0579 | 570 | 1.8836 | 0.8546 |
| 2.1664 | 600 | 1.5806 | 0.8517 |
| 2.2749 | 630 | 1.445 | 0.8616 |
| 2.3834 | 660 | 1.5858 | 0.8754 |
| 2.4919 | 690 | 1.7178 | 0.8708 |
| 2.6004 | 720 | 2.048 | 0.8683 |
| 2.7089 | 750 | 1.9854 | 0.8690 |
| 2.8174 | 780 | 1.7509 | 0.8744 |
| 2.9259 | 810 | 1.7643 | 0.8781 |
| 3.0325 | 840 | 1.3132 | 0.8870 |
| 3.1410 | 870 | 1.4164 | 0.8856 |
| 3.2495 | 900 | 1.3193 | 0.8870 |
| 3.3580 | 930 | 1.176 | 0.8973 |
| 3.4665 | 960 | 1.1743 | 0.8947 |
| 3.5750 | 990 | 1.0814 | 0.8951 |
| 3.6835 | 1020 | 1.0118 | 0.9051 |
| 3.7920 | 1050 | 1.5867 | 0.9089 |
| 3.9005 | 1080 | 1.4378 | 0.9092 |
| 4.0072 | 1110 | 1.0735 | 0.9066 |
| 4.1157 | 1140 | 0.8998 | 0.9089 |
| 4.2242 | 1170 | 0.9332 | 0.9100 |
| 4.3327 | 1200 | 1.2196 | 0.9123 |
| 4.4412 | 1230 | 1.08 | 0.9104 |
| 4.5497 | 1260 | 1.0907 | 0.9057 |
| 4.6582 | 1290 | 0.8068 | 0.9099 |
| 4.7667 | 1320 | 1.1293 | 0.9115 |
| 4.8752 | 1350 | 0.8142 | 0.9229 |
| 4.9837 | 1380 | 1.0416 | 0.9265 |
| 5.0904 | 1410 | 0.742 | 0.9270 |
| 5.1989 | 1440 | 0.6726 | 0.9245 |
| 5.3074 | 1470 | 0.7095 | 0.9283 |
| 5.4159 | 1500 | 0.8308 | 0.9261 |
| 5.5244 | 1530 | 0.8933 | 0.9280 |
| 5.6329 | 1560 | 0.9554 | 0.9254 |
| 5.7414 | 1590 | 1.0155 | 0.9275 |
| 5.8499 | 1620 | 0.7671 | 0.9278 |
| 5.9584 | 1650 | 1.0426 | 0.9298 |
| 6.0651 | 1680 | 0.8879 | 0.9345 |
| 6.1736 | 1710 | 0.6999 | 0.9339 |
| 6.2821 | 1740 | 0.7144 | 0.9354 |
| 6.3906 | 1770 | 1.0946 | 0.9336 |
| 6.4991 | 1800 | 0.5136 | 0.9391 |
| 6.6076 | 1830 | 0.3708 | 0.9392 |
| 6.7161 | 1860 | 0.6965 | 0.9391 |
| 6.8246 | 1890 | 0.618 | 0.9384 |
| 6.9331 | 1920 | 1.137 | 0.9394 |
| 7.0398 | 1950 | 0.5326 | 0.9406 |
| 7.1483 | 1980 | 0.804 | 0.9402 |
| 7.2568 | 2010 | 0.7989 | 0.9433 |
| 7.3653 | 2040 | 0.6908 | 0.9422 |
| 7.4738 | 2070 | 0.6518 | 0.9448 |
| 7.5823 | 2100 | 0.4915 | 0.9469 |
| 7.6908 | 2130 | 0.4586 | 0.9473 |
| 7.7993 | 2160 | 0.4537 | 0.9470 |
| 7.9078 | 2190 | 0.5117 | 0.9475 |
| 8.0145 | 2220 | 0.6986 | 0.9486 |
| 8.1230 | 2250 | 0.439 | 0.9472 |
| 8.2315 | 2280 | 0.7161 | 0.9472 |
| 8.3400 | 2310 | 0.6017 | 0.9474 |
| 8.4485 | 2340 | 0.5401 | 0.9484 |
| 8.5570 | 2370 | 0.5061 | 0.9504 |
| 8.6655 | 2400 | 0.6934 | 0.9502 |
| 8.7740 | 2430 | 0.4517 | 0.9518 |
| 8.8825 | 2460 | 0.572 | 0.9526 |
| 8.9910 | 2490 | 0.443 | 0.9528 |
| 9.0976 | 2520 | 0.5398 | 0.9523 |
| 9.2061 | 2550 | 0.6212 | 0.9517 |
| 9.3146 | 2580 | 0.649 | 0.9518 |
| 9.4231 | 2610 | 0.3859 | 0.9523 |
| 9.5316 | 2640 | 0.4697 | 0.9526 |
@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
intfloat/multilingual-e5-base