Sentence-BERT: Sentence Embeddings using Siamese BERT-Networks
Paper • 1908.10084 • Published • 18
How to use TesNik369/bge-m3-tqa-merged-epoch-3 with sentence-transformers:
from sentence_transformers import SentenceTransformer
model = SentenceTransformer("TesNik369/bge-m3-tqa-merged-epoch-3")
sentences = [
"el nio and la nia make a cycle called the los nios oscillation.",
"Short-term changes in climate are common and they have many causes (Figure 1.1). The largest and most important of these is the oscillation between El Nio and La Nia conditions. This cycle is called the ENSO (El Nio Southern Oscillation). The ENSO drives changes in climate that are felt around the world about every two to seven years.",
"Your respiratory system is made up of the tissues and organs that allow oxygen to enter your body and carbon dioxide to leave your body. Organs in your respiratory system include your: Nose. Mouth. Larynx. Pharynx. Lungs. Diaphragm. The organs of the respiratory system move air into and out of the body. These structures are shown below (Figure 1.1). What do you think is the purpose of each of these organs? The nose and the nasal cavity filter, warm, and moisten the air you breathe. The nose hairs and the mucus produced by the cells in the nose catch particles in the air and keep them from entering the lungs. Behind the nasal cavity, air passes through the pharynx, a long tube. Both food and air pass through the pharynx. The larynx, also called the \"voice box,\" is found just below the pharynx. Your voice comes from your larynx. Air from the lungs passes across thin tissues in the larynx and produces sound. The trachea, or windpipe, is a long tube that leads down to the lungs, where it divides into the right and left bronchi. The bronchi branch out into smaller bronchioles in each lung. There is small flap called the epiglottis that covers your trachea when you eat or drink. The muscle controlling the epiglottis is involuntary and prevents food from entering your lungs or wind pipe. The bronchioles lead to the alveoli. Alveoli are the little sacs at the end of the bronchioles (Figure 1.2). They look like little bunches of grapes. Oxygen is exchanged for carbon dioxide in the alveoli. That means oxygen enters the blood, and carbon dioxide moves out of the blood. The gases are exchanged between the blood and alveoli by simple diffusion. The diaphragm is a sheet of muscle that spreads across the bottom of the rib cage. When the diaphragm contracts, the chest volume gets larger, and the lungs take in air. When the diaphragm relaxes, the chest volume gets smaller, and air is pushed out of the lungs. \"Grape-like\" alveoli in the lungs.",
"Youve probably heard of El Nio and La Nia. These terms refer to certain short-term changes in climate. The changes are natural and occur in cycles. To understand the changes, you first need to know what happens in normal years. This is shown in Figure 17.24."
]
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-finetune-triplets dataset. It maps sentences & paragraphs to a 1024-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': 'XLMRobertaModel'})
(1): Pooling({'embedding_dimension': 1024, '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("TesNik369/bge-m3-tqa-merged-epoch-3")
# Run inference
queries = [
'A map in which all the lines of latitude and longitude are straight lines is a',
]
documents = [
'Most maps use a grid of lines to help you to find your location. This grid system is called a geographic coordinate system. Using this system you can define your location by two numbers, latitude and longitude. Both numbers are angles between your location, the center of Earth, and a reference line (Figure 2.20).',
'Topographic maps represent the locations of geographical features, such as hills and valleys. Topographic maps use contour lines to show different elevations. A contour line is a line of equal elevation. If you walk along a contour line you will not go uphill or downhill. Topographic maps are also called contour maps. The rules of topographic maps are: Each line connects all points of a specific elevation. Contour lines never cross since a single point can only have one elevation. Every fifth contour line is bolded and labeled. Adjacent contour lines are separated by a constant difference in elevation (such as 20 ft or 100 ft). The difference in elevation is the contour interval, which is indicated in the map legend. Scales indicate horizontal distance and are also found on the map legend. Old Faithful erupting, Yellowstone Na- tional Park. While the Figure 1.1 isnt exactly the same view as the map at the top of this concept, it is easy to see the main features. Hills, forests, development, and trees are all seen around Old Faithful.',
'In addition to sunlight, aquatic producers also need dissolved oxygen and nutrients. Water near the surface generally contains more dissolved oxygen than deeper water. Many nutrients enter the water from the land. Therefore, water nearer shore usually contains more dissolved nutrients than water farther from shore.',
]
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.5938, 0.6104, 0.2369]])
tqa-devInformationRetrievalEvaluator| Metric | Value |
|---|---|
| cosine_accuracy@1 | 0.4319 |
| cosine_accuracy@3 | 0.7621 |
| cosine_accuracy@5 | 0.8776 |
| cosine_accuracy@10 | 0.9515 |
| cosine_precision@1 | 0.4319 |
| cosine_precision@3 | 0.254 |
| cosine_precision@5 | 0.1755 |
| cosine_precision@10 | 0.0952 |
| cosine_recall@1 | 0.4319 |
| cosine_recall@3 | 0.7621 |
| cosine_recall@5 | 0.8776 |
| cosine_recall@10 | 0.9515 |
| cosine_ndcg@10 | 0.6987 |
| cosine_mrr@10 | 0.6165 |
| cosine_map@100 | 0.6189 |
anchor, positive, and negative| anchor | positive | negative | |
|---|---|---|---|
| type | string | string | string |
| modality | text | text | text |
| details |
|
|
|
| anchor | positive | negative |
|---|---|---|
maximum distance the particles of a medium move from their resting position |
The speed of most waves depends on the medium through which they are traveling. Generally, waves travel fastest through solids and slowest through gases. Thats because particles are closest together in solids and farthest apart in gases. When particles are farther apart, it takes longer for the energy of the disturbance to pass from particle to particle. |
The speed of most waves depends on the medium, or the matter through which the waves are traveling. Generally, waves travel fastest through solids and slowest through gases. Thats because particles are closest together in solids and farthest apart in gases. When particles are farther apart, it takes longer for the energy of the disturbance to pass from particle to particle through the medium. Click image to the left or use the URL below. URL: |
One function of the cornea is to protect the eye. |
The structure of the human eye is shown in Figure 22.24. Find each structure in the diagram as you read about it below. The cornea is the transparent outer covering of the eye. It protects the eye and also acts as a convex lens, helping to focus light that enters the eye. The pupil is an opening in the front of the eye. It looks black because it doesnt reflect any light. It allows light to enter the eye. The pupil automatically gets bigger or smaller to let more or less light in as needed. The iris is the colored part of the eye. It controls the size of the pupil. The lens is a convex lens that fine-tunes the focus so an image forms on the back of the eye. Tiny muscles control the shape of the lens to focus images of close or distant objects. The retina is a membrane lining the back of the eye. The retina has nerve cells called rods and cones that change images to electrical signals. Rods are good at sensing dim light but cant distinguish different colors of light. Cones can sense colo... |
The function of the eye is to focus light and form images. We see some objects, such as stars and light bulbs, because they give off their own light. However, we see most objects because they reflect light from another source such as the sun. We form images of the objects when some of the reflected light enters our eyes. Look at the parts of the eye in Figure 20.12. Follow the path of light through the eye as you read about it below. 1. Light from an object passes first through the cornea. This is a clear, protective covering on the outside of the eye. 2. Then light passes through the pupil, an opening in the center of the eye. The pupil, which looks black, is surrounded by the colored part of the eye, called the iris. 3. Light entering through the pupil next passes through the lens. The lens is a clear, curved structure, like the lens of a magnifying glass. Along with the cornea, the lens focuses the light on the back of the eye. 4. The back of the eye is covered by a thin layer calle... |
part of the ear that transmits and amplifies vibrations from the eardrum |
The outer ear includes the pinna, ear canal, and eardrum. The pinna is the only part of the ear that extends outward from the head. Its position and shape make it good at catching sound waves and funneling them into the ear canal. The ear canal is a tube that carries sound waves into the ear. The sound waves travel through the air inside the ear canal to the eardrum. The eardrum is like the head of a drum. Its a thin membrane stretched tight across the end of the ear canal. The eardrum vibrates when sound waves strike it, and it sends the vibrations on to the middle ear. |
The outer ear includes the pinna, ear canal, and eardrum. The pinna is the only part of the ear that extends outward from the head. Its position and shape make it good at catching sound waves and funneling them into the ear canal. The ear canal is a tube that carries sound waves into the ear. The sound waves travel through the air inside the ear canal to the eardrum. The eardrum is like the head of a drum. It is a thin membrane stretched tight across the end of the ear canal. The eardrum vibrates when sound waves strike it, and it sends the vibrations on to the middle ear. Q: How might cupping his hands behind his ears help the boy pictured in the opening image hear better? A: His hands might help the pinna of his ears catch sound waves and direct them into the ear canal. |
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: 16per_device_eval_batch_size: 32gradient_accumulation_steps: 8learning_rate: 2e-05lr_scheduler_type: cosinewarmup_ratio: 0.05seed: 3407fp16: Truegradient_checkpointing: Truebatch_sampler: no_duplicatesoverwrite_output_dir: Falsedo_predict: Falseprediction_loss_only: Trueper_device_train_batch_size: 16per_device_eval_batch_size: 32per_gpu_train_batch_size: Noneper_gpu_eval_batch_size: Nonegradient_accumulation_steps: 8eval_accumulation_steps: Nonetorch_empty_cache_steps: Nonelearning_rate: 2e-05weight_decay: 0.0adam_beta1: 0.9adam_beta2: 0.999adam_epsilon: 1e-08max_grad_norm: 1.0num_train_epochs: 3max_steps: -1lr_scheduler_type: cosinelr_scheduler_kwargs: {}warmup_ratio: 0.05warmup_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: 3407data_seed: Nonejit_mode_eval: Falsebf16: Falsefp16: Truefp16_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: Falseignore_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}parallelism_config: Nonedeepspeed: Nonelabel_smoothing_factor: 0.0optim: adamw_torch_fusedoptim_args: Noneadafactor: Falsegroup_by_length: Falselength_column_name: lengthproject: huggingfacetrackio_space_id: trackioddp_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: Falsehub_revision: Nonegradient_checkpointing: Truegradient_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: noneftune_noise_alpha: Noneoptim_target_modules: Nonebatch_eval_metrics: Falseeval_on_start: Falseuse_liger_kernel: Falseliger_kernel_config: Noneeval_use_gather_object: Falseaverage_tokens_across_devices: Trueprompts: Nonebatch_sampler: no_duplicatesmulti_dataset_batch_sampler: proportionalrouter_mapping: {}learning_rate_mapping: {}| Epoch | Step | Training Loss | tqa-dev_cosine_ndcg@10 |
|---|---|---|---|
| 0.0156 | 1 | 1.129 | - |
| 0.3113 | 20 | 1.0796 | - |
| 0.6226 | 40 | 1.047 | - |
| 0.9339 | 60 | 1.0395 | - |
| 1.0 | 65 | - | 0.7032 |
| 1.2335 | 80 | 1.0342 | - |
| 1.5447 | 100 | 0.9842 | - |
| 1.8560 | 120 | 0.972 | - |
| 2.0 | 130 | - | 0.7020 |
| 2.1556 | 140 | 0.9788 | - |
| 2.4669 | 160 | 0.9826 | - |
| 2.7782 | 180 | 0.9577 | - |
| 3.0 | 195 | - | 0.6987 |
| -1 | -1 | - | 0.6987 |
@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