SentenceTransformer based on BAAI/bge-small-en-v1.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.
Model Details
Model Description
- Model Type: Sentence Transformer
- Base model: BAAI/bge-small-en-v1.5
- Maximum Sequence Length: 512 tokens
- Output Dimensionality: 384 dimensions
- Similarity Function: Cosine Similarity
- Supported Modality: Text
Model Sources
- Documentation: Sentence Transformers Documentation
- Repository: Sentence Transformers on GitHub
- Hugging Face: Sentence Transformers on Hugging Face
Full Model Architecture
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({})
)
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("sentence_transformers_model_id")
# Run inference
queries = [
'web application behaves unexpectedly when submitting forms',
]
documents = [
'Cross-site scripting (XSS) vulnerability in cgi/client.py in Roundup before 1.4.20 allows remote attackers to inject arbitrary web script or HTML via the @action parameter to support/issue1.',
"Internet Starter, one of SoftCOM iKSORIS system modules, is vulnerable to Reflected XSS (Cross-site Scripting) attacks. An attacker might craft a link containing a malicious script, which then gets directly embedded in references to other resources, what causes the script to run in user's context multiple times.\xa0\nThis vulnerability has been patched in version 79.0",
'XnView Classic for Windows Version 2.40 might allow attackers to cause a denial of service or possibly have unspecified other impact via a crafted .rle file, related to "Data from Faulting Address controls Branch Selection starting at ntdll_77df0000!RtlpCoalesceFreeBlocks+0x00000000000001b6."',
]
query_embeddings = model.encode_query(queries)
document_embeddings = model.encode_document(documents)
print(query_embeddings.shape, document_embeddings.shape)
# [1, 384] [3, 384]
# Get the similarity scores for the embeddings
similarities = model.similarity(query_embeddings, document_embeddings)
print(similarities)
# tensor([[ 0.4764, 0.2721, -0.1170]])
Evaluation
Metrics
Information Retrieval
- Dataset:
validation - Evaluated with InformationRetrievalEvaluator
| Metric | Value |
|---|---|
| cosine_accuracy@1 | 0.7662 |
| cosine_accuracy@3 | 0.8624 |
| cosine_accuracy@5 | 0.8904 |
| cosine_accuracy@10 | 0.9229 |
| cosine_precision@1 | 0.7662 |
| cosine_precision@3 | 0.2875 |
| cosine_precision@5 | 0.1781 |
| cosine_precision@10 | 0.0923 |
| cosine_recall@1 | 0.7662 |
| cosine_recall@3 | 0.8624 |
| cosine_recall@5 | 0.8904 |
| cosine_recall@10 | 0.9229 |
| cosine_ndcg@10 | 0.8457 |
| cosine_mrr@10 | 0.8209 |
| cosine_map@100 | 0.8239 |
Training Details
Training Dataset
Unnamed Dataset
- Size: 861,607 training samples
- Columns: sentence_0 and sentence_1
- Approximate statistics based on the first 100 samples:
sentence_0 sentence_1 type string string modality text text details min: 7 tokensmean: 12.11 tokensmax: 26 tokens min: 23 tokensmean: 97.13 tokensmax: 512 tokens - Samples:
sentence_0 sentence_1 Windows Broadcast DVR User Service use after free Use after free in Windows Broadcast DVR User Service allows an authorized attacker to elevate privileges locally. missing authorization in AnalyticsWP 2.0.0 Missing Authorization vulnerability in Solid Plugins AnalyticsWP allows Accessing Functionality Not Properly Constrained by ACLs.This issue affects AnalyticsWP: from n/a through 2.0.0. authenticated users can access sensitive database information The Jquery news ticker plugin for WordPress is vulnerable to SQL Injection via the plugin's shortcode in versions up to, and including, 3.0 due to insufficient escaping on the user supplied parameter and lack of sufficient preparation on the existing SQL query. This makes it possible for authenticated attackers with subscriber-level and above permissions to append additional SQL queries into already existing queries that can be used to extract sensitive information from the database. - Loss: 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 }
Training Hyperparameters
Non-Default Hyperparameters
per_device_train_batch_size: 32num_train_epochs: 1fp16: Trueper_device_eval_batch_size: 32multi_dataset_batch_sampler: round_robin
All Hyperparameters
per_device_train_batch_size: 32num_train_epochs: 1max_steps: -1learning_rate: 5e-05lr_scheduler_type: linearlr_scheduler_kwargs: Nonewarmup_steps: 0optim: adamw_torch_fusedoptim_args: Noneweight_decay: 0.0adam_beta1: 0.9adam_beta2: 0.999adam_epsilon: 1e-08optim_target_modules: Nonegradient_accumulation_steps: 1average_tokens_across_devices: Truemax_grad_norm: 1label_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: 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: round_robinrouter_mapping: {}learning_rate_mapping: {}
Training Logs
| Epoch | Step | Training Loss | validation_cosine_ndcg@10 |
|---|---|---|---|
| 0.0186 | 500 | 0.5360 | - |
| 0.0371 | 1000 | 0.2580 | - |
| 0.0557 | 1500 | 0.2020 | - |
| 0.0743 | 2000 | 0.1800 | - |
| 0.0928 | 2500 | 0.1690 | - |
| 0.1114 | 3000 | 0.1648 | - |
| 0.1300 | 3500 | 0.1546 | - |
| 0.1486 | 4000 | 0.1523 | - |
| 0.1671 | 4500 | 0.1444 | - |
| 0.1857 | 5000 | 0.1457 | 0.8294 |
| 0.2043 | 5500 | 0.1441 | - |
| 0.2228 | 6000 | 0.1379 | - |
| 0.2414 | 6500 | 0.1292 | - |
| 0.2600 | 7000 | 0.1260 | - |
| 0.2785 | 7500 | 0.1270 | - |
| 0.2971 | 8000 | 0.1213 | - |
| 0.3157 | 8500 | 0.1234 | - |
| 0.3342 | 9000 | 0.1193 | - |
| 0.3528 | 9500 | 0.1148 | - |
| 0.3714 | 10000 | 0.1213 | 0.8352 |
| 0.3900 | 10500 | 0.1158 | - |
| 0.4085 | 11000 | 0.1183 | - |
| 0.4271 | 11500 | 0.1141 | - |
| 0.4457 | 12000 | 0.1164 | - |
| 0.4642 | 12500 | 0.1047 | - |
| 0.4828 | 13000 | 0.1115 | - |
| 0.5014 | 13500 | 0.1100 | - |
| 0.5199 | 14000 | 0.1084 | - |
| 0.5385 | 14500 | 0.1039 | - |
| 0.5571 | 15000 | 0.1089 | 0.8388 |
| 0.5757 | 15500 | 0.1020 | - |
| 0.5942 | 16000 | 0.1111 | - |
| 0.6128 | 16500 | 0.1124 | - |
| 0.6314 | 17000 | 0.1064 | - |
| 0.6499 | 17500 | 0.1049 | - |
| 0.6685 | 18000 | 0.1032 | - |
| 0.6871 | 18500 | 0.1106 | - |
| 0.7056 | 19000 | 0.1110 | - |
| 0.7242 | 19500 | 0.1023 | - |
| 0.7428 | 20000 | 0.0964 | 0.8434 |
| 0.7613 | 20500 | 0.0957 | - |
| 0.7799 | 21000 | 0.1010 | - |
| 0.7985 | 21500 | 0.0991 | - |
| 0.8171 | 22000 | 0.0983 | - |
| 0.8356 | 22500 | 0.1027 | - |
| 0.8542 | 23000 | 0.0940 | - |
| 0.8728 | 23500 | 0.0967 | - |
| 0.8913 | 24000 | 0.0924 | - |
| 0.9099 | 24500 | 0.1010 | - |
| 0.9285 | 25000 | 0.0961 | 0.8457 |
Training Time
- Training: 1.0 hours
- Evaluation: 25.6 seconds
- Total: 1.0 hours
Framework Versions
- Python: 3.12.10
- Sentence Transformers: 5.5.1
- Transformers: 5.9.0
- PyTorch: 2.11.0+cu128
- Accelerate: 1.13.0
- Datasets: 4.8.5
- Tokenizers: 0.22.2
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",
}
MultipleNegativesRankingLoss
@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},
}