Sentence-BERT: Sentence Embeddings using Siamese BERT-Networks
Paper • 1908.10084 • Published • 20
How to use TesNik369/bge-m3-tqa-lesson-split-merged with sentence-transformers:
from sentence_transformers import SentenceTransformer
model = SentenceTransformer("TesNik369/bge-m3-tqa-lesson-split-merged")
sentences = [
"layer of the atmosphere above the mesosphere",
"The three outer layers of the Sun are its atmosphere.",
"Photosynthesis occurs in two stages, called the light reactions and the Calvin cycle. Figure 4.10 sums up what happens in these two stages. Both stages are described below.",
"The mesosphere is the layer above the stratosphere. It rises to about 85 kilometers (53 miles) above the surface. Temperature decreases with altitude in this layer."
]
embeddings = model.encode(sentences)
similarities = model.similarity(embeddings, embeddings)
print(similarities.shape)
# [4, 4]This is a sentence-transformers model finetuned from BAAI/bge-m3 on the tqa-bge-m3-triplets-lesson-split dataset. It maps inputs to a 1024-dimensional dense vector space and can be used for semantic textual similarity, semantic search, paraphrase mining, classification, clustering, and more.
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({'module_input_name': 'sentence_embedding', 'module_output_name': 'sentence_embedding'})
)
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("TesNik369/bge-m3-tqa-lesson-split-merged")
# Run inference
queries = [
'differentiation',
]
documents = [
'When Earth was entirely molten, gravity drew denser elements to the center and lighter elements rose to the surface. The separation of Earth into layers based on density is known as differentiation. The densest material moved to the center to create the planets dense metallic core. Materials that are intermediate in density became part of the mantle (Figure 1.1).',
'1. Distinctive rock formations may be recognizable across large regions (Figure 1.1).',
'The mesosphere is the layer above the stratosphere. It rises to about 85 kilometers (53 miles) above the surface. Temperature decreases with altitude in this layer.',
]
query_embeddings = model.encode_query(queries)
document_embeddings = model.encode_document(documents)
print(query_embeddings.shape, document_embeddings.shape)
# [1, 1024] [3, 1024]
# Get the similarity scores for the embeddings
similarities = model.similarity(query_embeddings, document_embeddings)
print(similarities)
# tensor([[0.5101, 0.5188, 0.3545]])
tqa-dev-lesson-disjointInformationRetrievalEvaluator| Metric | Value |
|---|---|
| cosine_accuracy@1 | 0.5303 |
| cosine_accuracy@3 | 0.7778 |
| cosine_accuracy@5 | 0.8485 |
| cosine_accuracy@10 | 0.899 |
| cosine_precision@1 | 0.5303 |
| cosine_precision@3 | 0.346 |
| cosine_precision@5 | 0.2808 |
| cosine_precision@10 | 0.1992 |
| cosine_recall@1 | 0.1243 |
| cosine_recall@3 | 0.2431 |
| cosine_recall@5 | 0.3144 |
| cosine_recall@10 | 0.4124 |
| cosine_ndcg@10 | 0.3994 |
| cosine_mrr@10 | 0.6666 |
| cosine_map@100 | 0.3157 |
anchor, positive, and negative| anchor | positive | negative | |
|---|---|---|---|
| type | string | string | string |
| modality | text | text | text |
| details |
|
|
|
| anchor | positive | negative |
|---|---|---|
covalent bonds are weak; it does not take a lot of energy to break them apart. |
Ions come together to create a molecule so that electrical charges are balanced; the positive charges balance the negative charges and the molecule has no electrical charge. To balance electrical charge, an atom may share its electron with another atom, give it away, or receive an electron from another atom. The joining of ions to make molecules is called chemical bonding. There are three main types of chemical bonds that are important in our discussion of minerals and rocks: Ionic bond: Electrons are transferred between atoms. An ion will give one or more electrons to another ion. Table salt, sodium chloride (NaCl), is a common example of an ionic compound. Note that sodium is on the left side of the periodic table and that chlorine is on the right side of the periodic table. In the Figure 1.2, an atom of lithium donates an electron to an atom of fluorine to form an ionic compound. The transfer of the electron gives the lithium ion a net charge of +1, and the fluorine ion a net charge... |
A covalent bond is the force of attraction that holds together two atoms that share a pair of valence electrons. The shared electrons are attracted to the nuclei of both atoms. This forms a molecule consisting of two or more atoms. Covalent bonds form only between atoms of nonmetals. |
The human species first evolved about |
The earliest members of the human species evolved around 200,000 years ago in Africa. Early humans lived in small populations of nomadic hunters and gatherers. Human beings remained in Africa until about 40,000 years ago. After that, they spread throughout Europe, Asia, and Australia. By 10,000 years ago, the first human beings colonized the Americas. During this long period of time, the total number of human beings increased very slowly. Birth rates were fairly high but so were death rates, producing low rates of population growth. Human beings invented agriculture about 10,000 years ago. This provided a bigger, more dependable food supply. It also allowed people to settle down in villages and cities for the first time. Birth rates went up because there was more food and settled life had other advantages. Death rates also rose because of crowded living conditions and diseases that spread from domestic animals. Because the higher birth rates were matched by higher death rates, the huma... |
Humans evolved from primates, and apes and humans have a primate common ancestor. About 7 million years ago, chimpanzees (our closest living relatives) and humans shared their last common ancestor. |
hormones travel around your body in your blood. |
Your cardiovascular system has many jobs. At times the cardiovascular system can work like a pump, a heating system, or even a postal carrier. To do these tasks, your cardiovascular system works with other organ systems, such as the respiratory, endocrine, and nervous systems. The cardiovascular system (Figure 1.1) is made up of the heart, the blood vessels, and the blood. It moves nutrients, gases (like oxygen), and wastes to and from your cells. Every cell in your body depends on your cardiovascular system. If your cells dont receive nutrients, they cannot survive. The main function of the cardiovascular system is to deliver oxygen to each of your cells. Blood receives oxygen in your lungs (the main organs of the respiratory system) and then is pumped, by your heart, throughout your body. The oxygen then diffuses into your cells, and carbon dioxide, a waste product of cellular respiration, moves from your cells into your blood to be delivered back to your lungs and exhaled. Each cell... |
Endocrine hormones travel throughout the body in the blood. However, each endocrine hormone affects only certain cells, called target cells. |
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
}
per_device_train_batch_size: 16num_train_epochs: 2learning_rate: 2e-05lr_scheduler_type: cosinewarmup_steps: 0.05gradient_accumulation_steps: 8fp16: Trueper_device_eval_batch_size: 32seed: 3407batch_sampler: no_duplicatesper_device_train_batch_size: 16num_train_epochs: 2max_steps: -1learning_rate: 2e-05lr_scheduler_type: cosinelr_scheduler_kwargs: Nonewarmup_steps: 0.05optim: adamw_torch_fusedoptim_args: Noneweight_decay: 0.0adam_beta1: 0.9adam_beta2: 0.999adam_epsilon: 1e-08optim_target_modules: Nonegradient_accumulation_steps: 8average_tokens_across_devices: Truemax_grad_norm: 1.0label_smoothing_factor: 0.0bf16: Falsefp16: Truebf16_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: 32prediction_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: Falseignore_data_skip: Falserestore_callback_states_from_checkpoint: Falsefull_determinism: Falseseed: 3407data_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: Nonedataloader_multiprocessing_context: Nonedataloader_in_order: Trueremove_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: Nonefsdp_config: Nonedeepspeed: Nonedebug: []skip_memory_metrics: Truedo_predict: Falseresume_from_checkpoint: Nonelocal_rank: -1prompts: Nonebatch_sampler: no_duplicatesmulti_dataset_batch_sampler: proportionalrouter_mapping: {}learning_rate_mapping: {}warmup_ratio: None| Epoch | Step | Training Loss | tqa-dev-lesson-disjoint_cosine_ndcg@10 |
|---|---|---|---|
| -1 | -1 | - | 0.3891 |
| 0.0155 | 1 | 1.1003 | - |
| 0.3095 | 20 | 1.0544 | - |
| 0.6190 | 40 | 1.0563 | - |
| 0.9284 | 60 | 1.0275 | - |
| 1.0 | 65 | - | 0.3970 |
| 1.2321 | 80 | 1.0126 | - |
| 1.5416 | 100 | 0.9894 | - |
| 1.8511 | 120 | 0.9915 | - |
| 2.0 | 130 | - | 0.3994 |
| -1 | -1 | - | 0.3994 |
@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-m3