SentenceTransformer(
(0): Transformer({'transformer_task': 'feature-extraction', 'modality_config': {'text': {'method': 'forward', 'method_output_name': 'last_hidden_state'}}, 'module_output_name': 'token_embeddings', 'architecture': 'XLMRobertaModel'})
(1): Pooling({'embedding_dimension': 1024, 'pooling_mode': 'cls', 'include_prompt': True})
(2): Normalize({})
)pip install -U sentence-transformers1from sentence_transformers import SentenceTransformer
2
3# Download from the 🤗 Hub
4model = SentenceTransformer("wahi-quran-bge-m3-v3")
5# Run inference
6queries = [
7 'Mikä on tahattoman tapon rangaistus?',
8]
9documents = [
10 "And never is it for a believer to kill a believer except by mistake. And whoever kills a believer by mistake - then the freeing of a believing slave and a compensation payment presented to the deceased's family [is required] unless they give [up their right as] charity. But if the deceased was from a people at war with you and he was a believer - then [only] the freeing of a believing slave; and if he was from a people with whom you have a treaty - then a compensation payment presented to his family and the freeing of a believing slave. And whoever does not find [one or cannot afford to buy one] - then [instead], a fast for two months consecutively, [seeking] acceptance of repentance from Allah. And Allah is ever Knowing and Wise But whoever kills a believer intentionally - his recompense is Hell, wherein he will abide eternally, and Allah has become angry with him and has cursed him and has prepared for him a great punishment",
11 'By the star when it descends Your companion [Muhammad] has not strayed, nor has he erred Nor does he speak from [his own] inclination It is not but a revelation revealed Taught to him by one intense in strength One of soundness. And he rose to [his] true form While he was in the higher [part of the] horizon Then he approached and descended And was at a distance of two bow lengths or nearer And he revealed to His Servant what he revealed The heart did not lie [about] what it saw So will you dispute with him over what he saw And he certainly saw him in another descent At the Lote Tree of the Utmost Boundary Near it is the Garden of Refuge When there covered the Lote Tree that which covered [it] The sight [of the Prophet] did not swerve, nor did it transgress [its limit] He certainly saw of the greatest signs of his Lord',
12 'وآتوا اليتامى أموالهم ولا تتبدلوا الخبيث بالطيب ولا تأكلوا أموالهم إلى أموالكم إنه كان حوبا كبيرا. وإن خفتم ألا تقسطوا في اليتامى فانكحوا ما طاب لكم من النساء مثنى وثلاث ورباع فإن خفتم ألا تعدلوا فواحدة أو ما ملكت أيمانكم ذلك أدنى ألا تعولوا. وآتوا النساء صدقاتهن نحلة فإن طبن لكم عن شيء منه نفسا فكلوه هنيئا مريئا. ولا تؤتوا السفهاء أموالكم التي جعل الله لكم قياما وارزقوهم فيها واكسوهم وقولوا لهم قولا معروفا. وابتلوا اليتامى حتى إذا بلغوا النكاح فإن آنستم منهم رشدا فادفعوا إليهم أموالهم ولا تأكلوها إسرافا وبدارا أن يكبروا ومن كان غنيا فليستعفف ومن كان فقيرا فليأكل بالمعروف فإذا دفعتم إليهم أموالهم فأشهدوا عليهم وكفى بالله حسيبا.',
13]
14query_embeddings = model.encode_query(queries)
15document_embeddings = model.encode_document(documents)
16print(query_embeddings.shape, document_embeddings.shape)
17# [1, 1024] [3, 1024]
18
19# Get the similarity scores for the embeddings
20similarities = model.similarity(query_embeddings, document_embeddings)
21print(similarities)
22# tensor([[ 0.6212, -0.0095, 0.3688]])quranqa-devInformationRetrievalEvaluator| Metric | Value |
|---|---|
| cosine_accuracy@1 | 0.2857 |
| cosine_accuracy@5 | 0.5714 |
| cosine_accuracy@10 | 0.6667 |
| cosine_precision@1 | 0.2857 |
| cosine_precision@3 | 0.2381 |
| cosine_precision@5 | 0.1905 |
| cosine_precision@10 | 0.1381 |
| cosine_recall@1 | 0.1627 |
| cosine_recall@3 | 0.282 |
| cosine_recall@5 | 0.316 |
| cosine_recall@10 | 0.4217 |
| cosine_ndcg@10 | 0.3647 |
| cosine_mrr@10 | 0.406 |
| cosine_map@10 | 0.2891 |
anchor and positive| anchor | positive | |
|---|---|---|
| type | string | string |
| modality | text | text |
| details |
|
|
| anchor | positive |
|---|---|
من هم قوم شعيب؟ | And to [the people of] Madyan [We sent] their brother Shu'ayb. He said, "O my people, worship Allah; you have no deity other than Him. There has come to you clear evidence from your Lord. So fulfill the measure and weight and do not deprive people of their due and cause not corruption upon the earth after its reformation. That is better for you, if you should be believers And do not sit on every path, threatening and averting from the way of Allah those who believe in Him, seeking to make it [seem] deviant. And remember when you were few and He increased you. And see how was the end of the corrupters And if there should be a group among you who has believed in that with which I have been sent and a group that has not believed, then be patient until Allah judges between us. And He is the best of judges Said the eminent ones who were arrogant among his people, "We will surely evict you, O Shu'ayb, and those who have believed with you from our city, or you must return to our religion." He... |
من هم قوم شعيب؟ | وإلى مدين أخاهم شعيبا قال يا قوم اعبدوا الله ما لكم من إله غيره قد جاءتكم بينة من ربكم فأوفوا الكيل والميزان ولا تبخسوا الناس أشياءهم ولا تفسدوا في الأرض بعد إصلاحها ذلكم خير لكم إن كنتم مؤمنين. ولا تقعدوا بكل صراط توعدون وتصدون عن سبيل الله من آمن به وتبغونها عوجا واذكروا إذ كنتم قليلا فكثركم وانظروا كيف كان عاقبة المفسدين. وإن كان طائفة منكم آمنوا بالذي أرسلت به وطائفة لم يؤمنوا فاصبروا حتى يحكم الله بيننا وهو خير الحاكمين. قال الملأ الذين استكبروا من قومه لنخرجنك يا شعيب والذين آمنوا معك من قريتنا أو لتعودن في ملتنا قال أولو كنا كارهين. قد افترينا على الله كذبا إن عدنا في ملتكم بعد إذ نجانا الله منها وما يكون لنا أن نعود فيها إلا أن يشاء الله ربنا وسع ربنا كل شيء علما على الله توكلنا ربنا افتح بيننا وبين قومنا بالحق وأنت خير الفاتحين. وقال الملأ الذين كفروا من قومه لئن اتبعتم شعيبا إنكم إذا لخاسرون. فأخذتهم الرجفة فأصبحوا في دارهم جاثمين. الذين كذبوا شعيبا كأن لم يغنوا فيها الذين كذبوا شعيبا كانوا هم الخاسرين. فتولى عنهم وقال يا قوم لقد أبلغتكم رسالات ربي ونصحت لكم فكيف آسى على قوم ... |
Who are the people of Shu'ayb? | And to [the people of] Madyan [We sent] their brother Shu'ayb. He said, "O my people, worship Allah; you have no deity other than Him. There has come to you clear evidence from your Lord. So fulfill the measure and weight and do not deprive people of their due and cause not corruption upon the earth after its reformation. That is better for you, if you should be believers And do not sit on every path, threatening and averting from the way of Allah those who believe in Him, seeking to make it [seem] deviant. And remember when you were few and He increased you. And see how was the end of the corrupters And if there should be a group among you who has believed in that with which I have been sent and a group that has not believed, then be patient until Allah judges between us. And He is the best of judges Said the eminent ones who were arrogant among his people, "We will surely evict you, O Shu'ayb, and those who have believed with you from our city, or you must return to our religion." He... |
MultipleNegativesRankingLoss with these parameters:
1{
2 "scale": 20.0,
3 "similarity_fct": "cos_sim",
4 "gather_across_devices": false,
5 "directions": [
6 "query_to_doc"
7 ],
8 "partition_mode": "joint",
9 "hardness_mode": null,
10 "hardness_strength": 0.0
11}per_device_train_batch_size: 24num_train_epochs: 4learning_rate: 1.5e-05warmup_steps: 0.1weight_decay: 0.01bf16: Trueper_device_eval_batch_size: 64push_to_hub: Truehub_private_repo: Truehub_model_id: wahi-quran-bge-m3-v3load_best_model_at_end: Trueseed: 12batch_sampler: no_duplicatesper_device_train_batch_size: 24num_train_epochs: 4max_steps: -1learning_rate: 1.5e-05lr_scheduler_type: linearlr_scheduler_kwargs: Nonewarmup_steps: 0.1optim: adamw_torch_fusedoptim_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: Truefp16: Falsebf16_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: Nonetrackio_bucket_id: Nonetrackio_static_space_id: Noneper_device_eval_batch_size: 64prediction_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: Truehub_private_repo: Truehub_model_id: wahi-quran-bge-m3-v3hub_strategy: every_savehub_always_push: Falsehub_revision: Noneload_best_model_at_end: Trueignore_data_skip: Falserestore_callback_states_from_checkpoint: Falsefull_determinism: Falseseed: 12data_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: 0dataloader_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_static_graph: Noneddp_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: no_duplicatesmulti_dataset_batch_sampler: proportionalrouter_mapping: {}learning_rate_mapping: {}| Epoch | Step | Training Loss | quranqa-dev_cosine_ndcg@10 |
|---|---|---|---|
| -1 | -1 | - | 0.3555 |
| 0.0021 | 1 | 2.0450 | - |
| 0.2009 | 94 | 1.6053 | - |
| 0.4017 | 188 | 1.1429 | 0.3612 |
| 0.6026 | 282 | 0.8229 | - |
| 0.8034 | 376 | 0.6913 | 0.3673 |
| 1.0043 | 470 | 0.6307 | - |
| 1.2051 | 564 | 0.4171 | 0.3578 |
| 1.4060 | 658 | 0.4558 | - |
| 1.6068 | 752 | 0.4316 | 0.3647 |
1@inproceedings{reimers-2019-sentence-bert,
2 title = "Sentence-BERT: Sentence Embeddings using Siamese BERT-Networks",
3 author = "Reimers, Nils and Gurevych, Iryna",
4 booktitle = "Proceedings of the 2019 Conference on Empirical Methods in Natural Language Processing",
5 month = "11",
6 year = "2019",
7 publisher = "Association for Computational Linguistics",
8 url = "https://arxiv.org/abs/1908.10084",
9}1@misc{oord2019representationlearningcontrastivepredictive,
2 title={Representation Learning with Contrastive Predictive Coding},
3 author={Aaron van den Oord and Yazhe Li and Oriol Vinyals},
4 year={2019},
5 eprint={1807.03748},
6 archivePrefix={arXiv},
7 primaryClass={cs.LG},
8 url={https://arxiv.org/abs/1807.03748},
9}