Sentence-BERT: Sentence Embeddings using Siamese BERT-Networks
Paper • 1908.10084 • Published • 19
How to use Pranay0514/hr-bge-small-ft with sentence-transformers:
from sentence_transformers import SentenceTransformer
model = SentenceTransformer("Pranay0514/hr-bge-small-ft")
sentences = [
"Represent this sentence for searching relevant passages: What is the 30‑day deadline for filing a grievance for full‑time staff, and does it apply to interns?",
"Eligibility: Gratuity is payable to any employee who has completed a minimum of five (5) years of continuous service with the PSU. Employees who are terminated for any reason other than voluntary resignation, retirement, or death are also eligible. Employees on probation or contractual tenure of less than five years are not eligible unless the Board decides otherwise. Calculation: The gratuity is calculated as (15/26) × Last drawn basic salary × Years of service, rounded to the nearest rupee. For example, an employee with a last drawn basic of Rs. 80,000 and 12 years of service receives ₹ 15/26 × 80,000 × 12 = ₹ 44,200. The maximum payable amount is capped at Rs. 20 lakh as per the latest Central Government directive. Exception: Employees in hazardous or critical roles may",
"Grievances may be submitted by any full‑time employee (excluding interns and contractors) within 30 calendar days from the incident. The employee must lodge a written complaint with the HR HelpDesk, which will acknowledge receipt within 48 hours and assign a unique reference number. The first level of review (HR Manager) must be completed within 10 business days, with a written decision returned to the complainant. If the grievance remains unresolved, it is escalated to the Senior HR Director within 15 business days of the initial review, and a final decision is rendered within 7 days of escalation. \n\nAll complaints are treated confidentially; the complainant and respondent are notified of the outcome but names are disclosed only if the complainant consents or if required by law. Compensation claims under this policy are capped at 20% of the employee’s monthly salary, with a maximum of ₹2,00,000 per incident. \n\nExceptions: Grievances involving personal disputes outside the workplace, or those arising from disciplinary actions, are excluded from the formal grievance procedure and are handled per the Code of Conduct. Contractors may file grievances only through the designated Contractor Liaison Officer and are subject to a 60‑day filing window.",
"Employees are expected to report to their assigned store at least 30 minutes before the official shift start time. An employee is considered late if they arrive after the scheduled start time minus the 30‑minute grace period. For full‑time staff, a single late arrival is recorded as a 5% attendance penalty. If an employee accumulates more than three late arrivals in any 30‑day window, an attendance flag is raised and a formal warning will be issued. A total of six late arrivals within a calendar year will lead to a deduction of one day of paid leave from the employee’s annual leave balance. Employees with less than 6 months of continuous service are exempt from the penalty until they complete their probationary period; thereafter the same rules apply. Part‑time and shift employees are assessed on a pro‑rated basis, with a maximum of 2 late arrivals per month allowed before a warning is issued. Exceptions: medical emergencies, documented travel disruptions, or store‑wide operational disruptions (e.g., power outage) are excused if the employee submits a written notice within 24 hours or a medical"
]
embeddings = model.encode(sentences)
similarities = model.similarity(embeddings, embeddings)
print(similarities.shape)
# [4, 4]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 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': '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: If I’m a part‑time employee, how many late arrivals per month can I have before I get a warning?',
'Employees are expected to report to their assigned store at least 30 minutes before the official shift start time. An employee is considered late if they arrive after the scheduled start time minus the 30‑minute grace period. For full‑time staff, a single late arrival is recorded as a 5% attendance penalty. If an employee accumulates more than three late arrivals in any 30‑day window, an attendance flag is raised and a formal warning will be issued. A total of six late arrivals within a calendar year will lead to a deduction of one day of paid leave from the employee’s annual leave balance. Employees with less than 6 months of continuous service are exempt from the penalty until they complete their probationary period; thereafter the same rules apply. Part‑time and shift employees are assessed on a pro‑rated basis, with a maximum of 2 late arrivals per month allowed before a warning is issued. Exceptions: medical emergencies, documented travel disruptions, or store‑wide operational disruptions (e.g., power outage) are excused if the employee submits a written notice within 24 hours or a medical',
'All full‑time retail employees earning a monthly wage of ₹21,000 or less are covered under the Employees’ State Insurance (ESI) Scheme. Coverage begins after 30 consecutive days of employment and requires a minimum of 20 working hours per week. The employer contributes 4.75\u202f% of the employee’s wages (up to ₹21,000), while the employee contributes 1.75\u202f% toward the scheme. \n\nESI benefits include: \n• **Sickness benefits** – up to ₹15,000 for 91 days of sickness per year, payable after 15 days of medical certification. \n• **Maternity benefits** – ₹15,000 for 26 weeks, available to female employees after 90 days of employment. \n• **Disabled and dependent benefits** – up to ₹15,000 for permanent disability and ₹5,000 for dependent children per annum. \n\nEmployees on temporary, seasonal, or contractual arrangements, and those earning above ₹21,000 per month, are exempt from ESI coverage. All benefits are subject to the national ESI Act limits and can be accessed through the company’s designated ESI portal. The company will provide ESI insurance certificates upon completion of the 30‑day probation period.',
]
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.7235, 0.1534],
# [0.7235, 1.0000, 0.1642],
# [0.1534, 0.1642, 1.0000]])
anchor and positive| anchor | positive | |
|---|---|---|
| type | string | string |
| modality | text | text |
| details |
|
|
| anchor | positive |
|---|---|
Represent this sentence for searching relevant passages: How many compensatory off days can a new employee take after finishing their probation period? |
Employees are eligible for a maximum of 7 casual leave days per calendar year. Casual leave is granted on a first‑come, first‑served basis and must be applied through the HR portal at least 48 hours prior to the intended date, except in cases of medical emergencies where a doctor’s certificate may be submitted within 24 hours. |
Represent this sentence for searching relevant passages: What is the latest date by which unused casual leave days must be forfeited if they exceed the 5‑day carry‑over limit? |
Employees are eligible for a maximum of 7 casual leave days per calendar year. Casual leave is granted on a first‑come, first‑served basis and must be applied through the HR portal at least 48 hours prior to the intended date, except in cases of medical emergencies where a doctor’s certificate may be submitted within 24 hours. |
Represent this sentence for searching relevant passages: If I have a medical emergency, within how many hours must I submit a doctor's certificate to still count the day as casual leave? |
Employees are eligible for a maximum of 7 casual leave days per calendar year. Casual leave is granted on a first‑come, first‑served basis and must be applied through the HR portal at least 48 hours prior to the intended date, except in cases of medical emergencies where a doctor’s certificate may be submitted within 24 hours. |
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: 16learning_rate: 2e-05warmup_steps: 0.1fp16: Truebatch_sampler: no_duplicatesper_device_train_batch_size: 16num_train_epochs: 3max_steps: -1learning_rate: 2e-05lr_scheduler_type: linearlr_scheduler_kwargs: Nonewarmup_steps: 0.1optim: 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: 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: 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: 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: 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 |
|---|---|---|
| 0.4 | 10 | 1.1428 |
| 0.8 | 20 | 0.8053 |
| 1.2 | 30 | 0.5896 |
| 1.6 | 40 | 0.4737 |
| 2.0 | 50 | 0.4520 |
| 2.4 | 60 | 0.3825 |
| 2.8 | 70 | 0.5378 |
@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