Edit model card

SentenceTransformer based on jangedoo/all-MiniLM-L6-v2-nepali

This is a sentence-transformers model finetuned from sentence-transformers/all-MiniLM-L6-v2 on the momo22/eng2nep, NepaliAI/Nepali-Health-Fact, wikimedia/wikipedia, wisewizer/nepali-news dataset. It maps sentences & paragraphs to a 384-dimensional dense vector space and can be used for semantic textual similarity, semantic search, paraphrase mining, text classification, clustering, and more.

Two step approach was taken to fine-tune this model. First I took sentence-transformers/all-MiniLM-L6-v2 model and then made it multi-lingual (English and Nepali). The approach is describe here Making Monolingual Sentence Embeddings Multilingual using Knowledge Distillation. The basic idea is that we need a parallel corpus. In this case I took momo22/eng2nep which contains English to Nepali sentence pairs. Then the sentence-transformers/all-MiniLM-L6-v2 was used to generate embeddings for English sentences. While training, the model was fine-tuned in a way that it produces embeddings for Nepali sentences to be similar to the corresponding English embeddings. The loss function used was MSELoss.

Next, this new multi-lingual model was further fine tuned on datasets like Nepali Wikipedia articles, Nepali News, Nepali Health Q&A. I took the title and body from those datasets and treat them as anchor and positive for computing pair-wise similarity. Specifically, the MultipleNegativesSymmetricRankingLoss was used. Basically this will force the embeddings of anchor to be similar to positive and vice-versa. The negative samples are automatically mined from a batch and the objective is to make sure similarity between anchor and positive is higher than anchor and negative.

The rest of the content was generated automatically by sentence-transformers library.

Model Details

Model Description

Model Sources

Full Model Architecture

SentenceTransformer(
  (0): Transformer({'max_seq_length': 256, 'do_lower_case': False}) with Transformer model: BertModel 
  (1): Pooling({'word_embedding_dimension': 384, '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()
)

Usage

Direct Usage (Sentence Transformers)

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("jangedoo/all-MiniLM-L6-v2-nepali")
# Run inference
sentences = [
    'अर्थवेद',
    'अर्थवेद\nचार वेदका चार उपवेद मानिन्छ-\nधनुर्वेद, \nगान्धर्ववेद, \nआयुर्वेद, र \nअर्थवेद \nपं. धनराज शास्त्रीले अर्थवेदका चार ठूला र दुइ ाना ग्रन्थको उल्लेख गरेका छन्\n\nठूला ग्रन्थ\nचार ठूला ग्रन्थ यस प्रकार छन् \n १. अर्थोपवेद– यसको श्लोक संख्या एक लाख बताइएको छ । \n २.अर्थवेद– यसको श्लोक संख्या ३० हजार बताइएको छ । \n ३. अर्थ चन्द्रोदय– यसको श्लोक संख्या २० हजार बताइएको छ ।',
    'डा. फेल, डिटेक्टिभ, एन्ड अदर स्टोरिज अमेरिकन उपन्यासकार तथा लेखक जोन डिक्सन कारद्वारा लिखित लघुकथा सङ्ग्रह हो । \n\nसन्दर्भ सूची\n\nलघुकथा संग्रहहरू\nपुस्तकहरू\nजोन डिक्सन कारका लघुकथा संग्रहहरू',
]
embeddings = model.encode(sentences)
print(embeddings.shape)
# [3, 384]

# Get the similarity scores for the embeddings
similarities = model.similarity(embeddings, embeddings)
print(similarities.shape)
# [3, 3]

Evaluation

Metrics

Information Retrieval

Metric Value
cosine_accuracy@1 0.5404
cosine_accuracy@3 0.6196
cosine_accuracy@5 0.654
cosine_accuracy@10 0.6962
cosine_precision@1 0.5404
cosine_precision@3 0.2065
cosine_precision@5 0.1308
cosine_precision@10 0.0696
cosine_recall@1 0.5404
cosine_recall@3 0.6196
cosine_recall@5 0.654
cosine_recall@10 0.6962
cosine_ndcg@10 0.6146
cosine_mrr@10 0.5889
cosine_mrr@20 0.5918
cosine_mrr@50 0.5937
cosine_map@100 0.5944

Training Details

Training Dataset

wikimedia/wikipedia

  • Dataset: wikimedia/wikipedia at b04c8d1
  • Size: 50,049 training samples
  • Columns: anchor and positive
  • Approximate statistics based on the first 1000 samples:
    anchor positive
    type string string
    details
    • min: 3 tokens
    • mean: 49.45 tokens
    • max: 256 tokens
    • min: 17 tokens
    • mean: 166.52 tokens
    • max: 256 tokens
  • Samples:
    anchor positive
    पहिलो पटक फेस वेक्सिङ गर्ने प्रयास गरेपछि मेरो गालामा दागहरू देखा परे। मेरो डाक्टरले clindac A जेल सिफारिस गर्नुभयो। के मेरो छाला निको हुन लामो समय लाग्छ वा केहि दिनमा यो राम्रो हुन सक्छ? डाक्टरबाट सुझावहरू:

    1. उचित परीक्षणको लागि छाला विशेषज्ञसँग परामर्श गर्नुहोस्।
    2. वाक्सिङ पछि तपाईंको अनुहारमा दागहरू सम्पर्क डर्मेटाइटिस वा एलर्जी प्रतिक्रियाको कारण हुन सक्छ।
    3. डाक्टरले एन्टिहिस्टामिन औषधि र कोर्टिकोस्टेरोइड मलम लेख्न सक्छ।
    4. रातो दागहरू छुन वा चुम्बन नगर्नुहोस्।
    5. अहिलेको लागि प्रत्यक्ष सूर्यको जोखिम र कस्मेटिक उत्पादनहरूबाट बच्नुहोस्।
    विश्व व्यापार केन्द्र वर्ल्ड ट्रेड सेन्टर न्यु योर्क सहरको मैनछटनमा बनेका दुई टावर रूपी भवनहरूको जोडी थियो, जसलाई आतंकवादी सङ्गठन अल कायदासंग सम्बन्धित आतंकवादिहरूले ११ सितंबर, २००१मा नष्ट गरिदिएका थिए।

    मूल वर्ल्ड ट्रेड सेन्टर तल्लो मैनहट्टन, न्यु योर्क सिटी, संयुक्त राज्य अमेरिकामा मीलको पत्थर जुडुवा टावरहरूको विशेषता सात भवनहरुका साथ एक जटिल थियो। जटिल ४ अप्रिल, १९७३लाई खोला, र ११ सेप्टेम्बरका हमलाको समयमा २००१मा नष्ट गरेको थियो।
    एम्बुलेन्स एम्बुलेन्स बिरामी वा घाइते मान्छेलाई रोग वा चोट लागि उपचार गर्नको लागि अस्पताल सम्म पुर्याउन प्रयोग हुने सवारी साधन हो।

    यो पनि हेर्नुहोस

    सन्दर्भ सामग्रीहरू

    बाह्य कडीहरू

    आकस्मिक स्वास्थ्य सेवा
    एम्बुलेन्स
  • Loss: MultipleNegativesSymmetricRankingLoss with these parameters:
    {
        "scale": 20.0,
        "similarity_fct": "cos_sim"
    }
    

Evaluation Dataset

wikimedia/wikipedia

  • Dataset: wikimedia/wikipedia at b04c8d1
  • Size: 3,000 evaluation samples
  • Columns: anchor and positive
  • Approximate statistics based on the first 1000 samples:
    anchor positive
    type string string
    details
    • min: 3 tokens
    • mean: 50.5 tokens
    • max: 256 tokens
    • min: 22 tokens
    • mean: 170.43 tokens
    • max: 256 tokens
  • Samples:
    anchor positive
    जनसाङ्ख्यिकीय लाभांश जनसाङ्ख्यिकीय लाभांश (Demographic dividend) अर्थ व्यवस्थामा मानव संसाधनका सकारात्मक र सतत विकासलाई दर्शाउँदछ। यो जनसङ्ख्या ढाँचामा बढदो युवा एवं कार्यशील जनसङ्ख्या (१५ वर्षदेखि ६४ वर्ष आयु वर्ग) तथा घट्तो आश्रितता अनुपातका परिणामस्वरूप उत्पादनमा ठूलो मात्राका सृजनलाई प्रदर्शित गर्दछ। यस स्थितिमा जनसङ्ख्या पिरामिड उल्टा बन्नेछ अर्थात यसमा कम जनसङ्ख्या आधार भन्दा माथि ठूलो जनसङ्ख्यातर्फ बढ्दछन्।
    साडी गाविस साडी गाविस नेपालको पश्चिमाञ्चल विकास क्षेत्रको लुम्बिनी अञ्चल, रूपन्देही जिल्लामा अवस्थित गाउँ विकास समिति हो ।

    रूपन्देही जिल्लाका ठाउँहरू
    हेप सी र सिरोसिस भएको मेरो साथीले नाकबाट रगत बग्नेलाई गम्भीरतापूर्वक लिनु पर्छ र जेलमा विशेषज्ञलाई भेट्न माग गर्नु पर्छ? – लिभर सिरोसिसले नाकबाट रगत बगाउन सक्छ
    – सिरोसिसमा कलेजोले राम्रोसँग काम गर्दैन
    - यसले कोगुलेसन कारकहरूको उत्पादनलाई असर गर्छ, जुन रगत जम्मा गर्न जिम्मेवार हुन्छ
    - फलस्वरूप, क्लोटिंग प्रणाली प्रभावित हुन्छ र नाक रगत हुन सक्छ
    - तपाईंको साथीले उचित मूल्याङ्कन र उपचारको लागि डाक्टरसँग परामर्श गर्नुपर्छ
    - केहि अवस्थामा, पोर्टल हाइपरटेन्सन व्यवस्थापन गर्न TIPS जस्ता शल्यक्रियाहरू वा बीटा ब्लकरहरू जस्तै औषधिहरू सिफारिस गर्न सकिन्छ।
    - सिरोसिसको अन्तिम उपचार कलेजो प्रत्यारोपण हो
    - यदि varices (अन्ननलीमा असामान्य नसहरू) बाट कुनै पनि रक्तस्राव भएमा, ब्यान्डिङ जस्ता प्रक्रियाहरूको लागि तत्काल चिकित्सा ध्यान आवश्यक छ।
    - यो तपाईंको साथीसँग कुराकानी जारी राख्न र यस प्रक्रिया मार्फत तिनीहरूलाई समर्थन गर्न महत्त्वपूर्ण छ
  • Loss: MultipleNegativesSymmetricRankingLoss with these parameters:
    {
        "scale": 20.0,
        "similarity_fct": "cos_sim"
    }
    

Training Hyperparameters

Non-Default Hyperparameters

  • eval_strategy: steps
  • per_device_train_batch_size: 128
  • per_device_eval_batch_size: 128
  • learning_rate: 2e-05
  • num_train_epochs: 1
  • warmup_ratio: 0.1
  • bf16: True

All Hyperparameters

Click to expand
  • overwrite_output_dir: False
  • do_predict: False
  • eval_strategy: steps
  • prediction_loss_only: True
  • per_device_train_batch_size: 128
  • per_device_eval_batch_size: 128
  • per_gpu_train_batch_size: None
  • per_gpu_eval_batch_size: None
  • gradient_accumulation_steps: 1
  • eval_accumulation_steps: None
  • torch_empty_cache_steps: None
  • learning_rate: 2e-05
  • weight_decay: 0.0
  • adam_beta1: 0.9
  • adam_beta2: 0.999
  • adam_epsilon: 1e-08
  • max_grad_norm: 1.0
  • num_train_epochs: 1
  • max_steps: -1
  • lr_scheduler_type: linear
  • lr_scheduler_kwargs: {}
  • warmup_ratio: 0.1
  • warmup_steps: 0
  • log_level: passive
  • log_level_replica: warning
  • log_on_each_node: True
  • logging_nan_inf_filter: True
  • save_safetensors: True
  • save_on_each_node: False
  • save_only_model: False
  • restore_callback_states_from_checkpoint: False
  • no_cuda: False
  • use_cpu: False
  • use_mps_device: False
  • seed: 42
  • data_seed: None
  • jit_mode_eval: False
  • use_ipex: False
  • bf16: True
  • fp16: False
  • fp16_opt_level: O1
  • half_precision_backend: auto
  • bf16_full_eval: False
  • fp16_full_eval: False
  • tf32: None
  • local_rank: 0
  • ddp_backend: None
  • tpu_num_cores: None
  • tpu_metrics_debug: False
  • debug: []
  • dataloader_drop_last: False
  • dataloader_num_workers: 0
  • dataloader_prefetch_factor: None
  • past_index: -1
  • disable_tqdm: False
  • remove_unused_columns: True
  • label_names: None
  • load_best_model_at_end: False
  • ignore_data_skip: False
  • fsdp: []
  • fsdp_min_num_params: 0
  • fsdp_config: {'min_num_params': 0, 'xla': False, 'xla_fsdp_v2': False, 'xla_fsdp_grad_ckpt': False}
  • fsdp_transformer_layer_cls_to_wrap: None
  • accelerator_config: {'split_batches': False, 'dispatch_batches': None, 'even_batches': True, 'use_seedable_sampler': True, 'non_blocking': False, 'gradient_accumulation_kwargs': None}
  • deepspeed: None
  • label_smoothing_factor: 0.0
  • optim: adamw_torch
  • optim_args: None
  • adafactor: False
  • group_by_length: False
  • length_column_name: length
  • ddp_find_unused_parameters: None
  • ddp_bucket_cap_mb: None
  • ddp_broadcast_buffers: False
  • dataloader_pin_memory: True
  • dataloader_persistent_workers: False
  • skip_memory_metrics: True
  • use_legacy_prediction_loop: False
  • push_to_hub: False
  • resume_from_checkpoint: None
  • hub_model_id: None
  • hub_strategy: every_save
  • hub_private_repo: False
  • hub_always_push: False
  • gradient_checkpointing: False
  • gradient_checkpointing_kwargs: None
  • include_inputs_for_metrics: False
  • eval_do_concat_batches: True
  • fp16_backend: auto
  • push_to_hub_model_id: None
  • push_to_hub_organization: None
  • mp_parameters:
  • auto_find_batch_size: False
  • full_determinism: False
  • torchdynamo: None
  • ray_scope: last
  • ddp_timeout: 1800
  • torch_compile: False
  • torch_compile_backend: None
  • torch_compile_mode: None
  • dispatch_batches: None
  • split_batches: None
  • include_tokens_per_second: False
  • include_num_input_tokens_seen: False
  • neftune_noise_alpha: None
  • optim_target_modules: None
  • batch_eval_metrics: False
  • eval_on_start: False
  • eval_use_gather_object: False
  • batch_sampler: batch_sampler
  • multi_dataset_batch_sampler: proportional

Framework Versions

  • Python: 3.11.9
  • Sentence Transformers: 3.0.1
  • Transformers: 4.44.0
  • PyTorch: 2.4.0+cu121
  • Accelerate: 0.33.0
  • Datasets: 2.21.0
  • Tokenizers: 0.19.1

Citation

BibTeX

Sentence Transformers

@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",
}

Authors

  • Sanjaya Subedi
Downloads last month
119
Safetensors
Model size
22.7M params
Tensor type
F32
·
Inference Examples
Inference API (serverless) is not available, repository is disabled.

Model tree for jangedoo/all-MiniLM-L6-v2-nepali

Unable to build the model tree, the base model loops to the model itself. Learn more.

Datasets used to train jangedoo/all-MiniLM-L6-v2-nepali

Space using jangedoo/all-MiniLM-L6-v2-nepali 1

Evaluation results