Sentence-BERT: Sentence Embeddings using Siamese BERT-Networks
Paper • 1908.10084 • Published • 15
How to use SriRamanaAtmic/AtmicQuoterv1 with sentence-transformers:
from sentence_transformers import SentenceTransformer
model = SentenceTransformer("SriRamanaAtmic/AtmicQuoterv1")
sentences = [
"Represent this sentence for searching relevant passages: In Aksharamanamalai, which verse contains the prayer asking Arunachala to rule over the devotee graciously through his Holy Feet?",
"[Aksharamanamalai] Verse 4: Arunachala! For whose sake dids’t Thou claim me? Thou, who ruled over me happily earlier were to abandon me thereafter with disdain the whole world will heap calumny on Thee.",
"[Aksharamanamalai] Verse 63: Holy Feet and be pleased to rule over me graciously.",
"[Aksharamanamalai] Verse 105: May Thou live for all eternity protecting forever the poor and hapless devotees like me all over, bestowing on all the infinite and rapturous bliss in Siva.",
"[The Legend of King Ballala] In this holy place was the seat of the kingdom of King Ballala... Arunachala came in the form of a Child and played in this King’s lap... the Lord said that as the King had no progeny He would Himself perform his annual ceremonies (sraddha) for all eternity | Topics: arunachala_kshetra"
]
embeddings = model.encode(sentences)
similarities = model.similarity(embeddings, embeddings)
print(similarities.shape)
# [5, 5]This is a sentence-transformers model finetuned from BAAI/bge-small-en-v1.5. It maps sentences & paragraphs to a 384-dimensional dense vector space and can be used for retrieval.
SentenceTransformer(
(0): Transformer({'transformer_task': 'feature-extraction', 'modality_config': {'text': {'method': 'forward', 'method_output_name': 'last_hidden_state'}}, 'module_output_name': 'token_embeddings', 'architecture': 'BertModel'})
(1): Pooling({'embedding_dimension': 384, 'pooling_mode': 'cls', '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 = [
'Represent this sentence for searching relevant passages: In Guru Vachaka Kovai, how does the ego dissolve and what does the jiva become when it merges with Siva?',
'[Verse 514] If the jiva’s head but merges / In Siva’s Feet, the jiva shines / As Siva Himself. The ego-ripple dies / And gains the stillness of true Being | Topics: guru_vachaka_kovai',
'[Verse 406] By the transmuting touch of daily, / Methodical, untiring self-enquiry, / The base metal jiva shines forth clear / As Siva, freed from the mental rust, / The demon ego | Topics: guru_vachaka_kovai',
]
embeddings = model.encode(sentences)
print(embeddings.shape)
# [3, 384]
# Get the similarity scores for the embeddings
similarities = model.similarity(embeddings, embeddings)
print(similarities)
# tensor([[1.0000, 0.7078, 0.5582],
# [0.7078, 1.0000, 0.5088],
# [0.5582, 0.5088, 1.0000]])
atmic-valInformationRetrievalEvaluator| Metric | Value |
|---|---|
| cosine_accuracy@1 | 0.6785 |
| cosine_accuracy@3 | 0.8372 |
| cosine_accuracy@5 | 0.8841 |
| cosine_accuracy@10 | 0.9301 |
| cosine_precision@1 | 0.6785 |
| cosine_precision@3 | 0.2791 |
| cosine_precision@5 | 0.1768 |
| cosine_precision@10 | 0.093 |
| cosine_recall@1 | 0.6785 |
| cosine_recall@3 | 0.8372 |
| cosine_recall@5 | 0.8841 |
| cosine_recall@10 | 0.9301 |
| cosine_ndcg@3 | 0.7719 |
| cosine_ndcg@10 | 0.8065 |
| cosine_mrr@3 | 0.7493 |
| cosine_mrr@10 | 0.7666 |
| cosine_map@100 | 0.7698 |
anchor, positive, negative_1, negative_2, and negative_3| anchor | positive | negative_1 | negative_2 | negative_3 | |
|---|---|---|---|---|---|
| type | string | string | string | string | string |
| details |
|
|
|
|
|
| anchor | positive | negative_1 | negative_2 | negative_3 |
|---|---|---|---|---|
Represent this sentence for searching relevant passages: What is Jnana according to Ramana Maharshi? |
[] This knowledge that there is nothing but God or the Self... is Jnana | Topics: citation_sentences |
[Upadesa Saram] Verse 30: All ego gone, Living as That alone Is penance good for growth, Sings Ramana, the Self. | Topics: ego-extinction, self-abidance, tapas, ramana |
[Birth name and family] Bhagavan Sri Ramana Maharshi, born Venkataraman Iyer, was the second of four children born to a devout family in Tiruchuzhi, Tamil Nadu, India. |
[] Everything happens according to each individual’s karma | Topics: citation_sentences |
Represent this sentence for searching relevant passages: What does it mean to have the knowledge that nothing exists except God? |
[] This knowledge that there is nothing but God or the Self... is Jnana | Topics: citation_sentences |
[] That silence could not be understood except by the very advanced | Topics: citation_sentences |
[] What exists apart from yourself? You ought to understand that by the Self neither the physical body nor the subtle body is meant | Topics: citation_sentences |
[] The flag of vairagya will never move. What greater sign does a Jnani require than that? | Topics: citation_sentences |
Represent this sentence for searching relevant passages: What did the Guru say a disciple should do to repay his Guru's grace? |
[] When the disciple asked what he could do in return for his Guru’s grace, the Guru said that he should always be in meditation | Topics: citation_sentences |
[Verse 304] The service rendered to the Guru / By the chela called and chosen by him / Should be respectful and correct, / Like a woman’s to her husband / In company | Topics: guru_vachaka_kovai |
[] The Guru’s grace... is beyond words or thoughts | Topics: citation_sentences |
[Verse 165] Why did the three-eyed Lord ordain / That Kannappa should pluck and plant / Those eyes of which he was so proud? / It was to save him from the death, / The deadly folly of deeming he / Was flesh inert. Such is the might / Of Siva’s grace, of love for Him | Topics: guru_vachaka_kovai |
MultipleNegativesRankingLoss with these parameters:{
"scale": 20.0,
"similarity_fct": "cos_sim",
"gather_across_devices": false,
"directions": [
"query_to_doc"
],
"partition_mode": "joint",
"hardness_mode": null,
"hardness_strength": 0.0
}
num_train_epochs: 2.0learning_rate: 2e-05warmup_steps: 0.1weight_decay: 0.01load_best_model_at_end: Trueper_device_train_batch_size: 8num_train_epochs: 2.0max_steps: -1learning_rate: 2e-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: Falsefp16: 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: 8prediction_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: Falsehub_private_repo: Nonehub_model_id: Nonehub_strategy: every_savehub_always_push: Falsehub_revision: Noneload_best_model_at_end: Trueignore_data_skip: Falserestore_callback_states_from_checkpoint: Falsefull_determinism: Falseseed: 42data_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: batch_samplermulti_dataset_batch_sampler: proportionalrouter_mapping: {}learning_rate_mapping: {}| Epoch | Step | Training Loss | atmic-val_cosine_ndcg@10 |
|---|---|---|---|
| 0.1044 | 50 | 1.2508 | - |
| 0.2088 | 100 | 0.6565 | - |
| 0.3132 | 150 | 0.4788 | - |
| 0.4175 | 200 | 0.4233 | - |
| 0.5219 | 250 | 0.4443 | - |
| 0.6263 | 300 | 0.4010 | - |
| 0.7307 | 350 | 0.3524 | - |
| 0.8351 | 400 | 0.3802 | - |
| 0.9395 | 450 | 0.3525 | - |
| 1.0 | 479 | - | 0.8065 |
@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{oord2019representationlearningcontrastivepredictive,
title={Representation Learning with Contrastive Predictive Coding},
author={Aaron van den Oord and Yazhe Li and Oriol Vinyals},
year={2019},
eprint={1807.03748},
archivePrefix={arXiv},
primaryClass={cs.LG},
url={https://arxiv.org/abs/1807.03748},
}
Base model
BAAI/bge-small-en-v1.5