Sentence-BERT: Sentence Embeddings using Siamese BERT-Networks
Paper • 1908.10084 • Published • 12
This is a sentence-transformers model finetuned from google/embeddinggemma-300m on the nz-hansard-triplets dataset. It maps sentences & paragraphs to a 768-dimensional dense vector space and can be used for semantic textual similarity, semantic search, paraphrase mining, text classification, clustering, and more.
SentenceTransformer(
(0): Transformer({'max_seq_length': 2048, 'do_lower_case': False, 'architecture': 'Gemma3TextModel'})
(1): Pooling({'word_embedding_dimension': 768, 'pooling_mode_cls_token': False, 'pooling_mode_mean_tokens': True, 'pooling_mode_max_tokens': False, 'pooling_mode_mean_sqrt_len_tokens': False, 'pooling_mode_weightedmean_tokens': False, 'pooling_mode_lasttoken': False, 'include_prompt': True})
(2): Dense({'in_features': 768, 'out_features': 3072, 'bias': False, 'activation_function': 'torch.nn.modules.linear.Identity'})
(3): Dense({'in_features': 3072, 'out_features': 768, 'bias': False, 'activation_function': 'torch.nn.modules.linear.Identity'})
(4): 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("dinushiTJ/nz-hansard-embedding-gemma-zeroshot")
# Run inference
queries = [
"non_maori_origin",
]
documents = [
'The significance lies in the fundamental activities of government: ownership, expenditure, and the regulation of private property. While our oversight mechanisms for state-owned assets are reasonably robust, despite frequently yielding unsatisfactory returns—indeed, the government often proves to be an inefficient proprietor, yet its performance is adequately reported, highlighting deficiencies. Furthermore, our framework for monitoring public spending is globally recognised as exemplary, largely due to the Fiscal Responsibility Act, now integrated into the Public Finance Act. This ensures comprehensive scrutiny of governmental outlays. Although some may argue spending is excessive, sound fiscal regulations foster a strong political aversion to deficit-running administrations, owing to enhanced transparency.',
"It matters profoundly because Government's activities—ownership, spending, and regulation—often intersect with Māori property, including whenua, taonga, and intellectual property, which it neither owns nor has a right to tax without Treaty partnership. While there is some oversight for Crown ownership of assets, the returns for Māori on Treaty settlements or co-governance arrangements are often disappointing, reflecting a failure to uphold rangatiratanga. We have some regimes for oversight of Government expenditure, but these often lack specific mechanisms to ensure equitable distribution or Treaty-consistent investment in Māori development. There is a strong need for fiscal rules that explicitly account for Treaty obligations and ensure transparency in spending that impacts Māori, fostering accountability for outcomes for tangata whenua.",
"Consequently, this initiative serves to align New Zealand's parliamentary procedures with international best practices and comparable systems globally. Experience from other jurisdictions where this approach has been piloted or adopted indicates a frequent rise in petition submissions. Furthermore, it has consistently highlighted to legislative bodies—irrespective of their global location—matters that, while perhaps not central to the legislators' immediate focus, are undeniably paramount for a substantial portion of the citizenry. Thus, this will unequivocally strengthen our nation's democratic framework.",
]
query_embeddings = model.encode_query(queries)
document_embeddings = model.encode_document(documents)
print(query_embeddings.shape, document_embeddings.shape)
# [1, 768] [3, 768]
# Get the similarity scores for the embeddings
similarities = model.similarity(query_embeddings, document_embeddings)
print(similarities)
# tensor([[ 0.8994, -0.7277, 0.9108]])
nz-hansard-triplet-evalTripletEvaluator| Metric | Value |
|---|---|
| cosine_accuracy | 1.0 |
anchor, positive, and negative| anchor | positive | negative | |
|---|---|---|---|
| type | string | string | string |
| details |
|
|
|
| anchor | positive | negative |
|---|---|---|
non_maori_origin |
A primary objective of these legislative changes involves modifying the Court Security Act of 1999, specifically by broadening the authority of court security personnel. This expanded mandate permits them to refuse admission, remove, and hold individuals found with illicit substances, or those exhibiting aggressive or abusive behaviour, or committing minor infractions within court facilities. This aspect of the legislation is crucial, as it provides explicit guidelines and specific powers for security officers to enforce order within the court environment. It grants them the necessary discretion to intervene, whether proceedings are active or not, against individuals bringing prohibited items or drugs into the courts, thereby ensuring swift and proper resolution of such incidents. Furthermore, the bill refines the legal definition of 'court' and clarifies the geographical scope within which these powers can be exercised. |
A critical aspect of ensuring justice for all involves addressing the cultural safety and appropriate engagement of Māori within court settings. This legislation should have considered specific protocols for court security officers when interacting with Māori individuals, particularly those who may be unfamiliar with the Pākehā justice system or who are experiencing cultural distress. It is vital to ensure that security measures do not inadvertently create barriers or exacerbate existing inequities for Māori. This includes training for officers on Te Reo Māori, tikanga, and the historical context of Māori interactions with the justice system, to prevent misunderstandings and ensure respectful treatment. Furthermore, the definition of 'court premises' should acknowledge areas where Māori cultural practices, such as karakia or waiata, might occur, ensuring these are accommodated respectfully within security frameworks, rather than being seen as disruptive. |
non_maori_origin |
Perhaps the most compelling aspect of the Tribunals Powers and Procedures Legislation Bill concerns the Human Rights Review Tribunal, where the compelling submissions from its chairperson, Mr Rodger Haines QC, warrant particular acknowledgement. I commend Mr Haines for his valuable input. As highlighted by Mr Haines, the Human Rights Act 1993's structural limitations have led to a substantial accumulation of cases over recent years. This backlog, and the resulting frustration, is evident in media reports detailing how individuals seeking to uphold their human rights endure 'unacceptable' delays of two to three years for resolution, despite persistent calls for legislative reform. Mr Haines' submission further revealed that for several years, the tribunal's entire workload, intended for five full-time decision-makers, has been managed by the chairperson alone. Consequently, a severe backlog continues to grow annually, rendering the tribunal effectively non-functional for many parties. T... |
A critical concern within the human rights framework is the persistent challenge Māori face in accessing justice for breaches of their Treaty rights and cultural protections. The Human Rights Review Tribunal, while vital, often struggles to adequately address the unique dimensions of Māori human rights, which are intrinsically linked to Te Tiriti o Waitangi. The existing backlog disproportionately affects Māori claimants, who may already face systemic barriers in navigating the Pākehā legal system. Future legislative reforms must specifically consider how to enhance the tribunal's capacity to hear and resolve cases involving Māori cultural rights, land rights, and the Crown's Treaty obligations. This includes ensuring culturally competent processes, the availability of Te Reo Māori services, and a deeper understanding of tikanga within the tribunal's operations, to ensure that justice delayed is not justice denied for Māori. |
non_maori_origin |
These legislative amendments deserve praise for their potential to shorten the duration required to hear and conclude disputes. They are designed to foster greater uniformity in tribunal operations, thereby solidifying tribunals' position as the preferred initial avenue for prompt and expert resolution of significant issues. This reinforces the vital function of tribunals in offering an alternative dispute resolution framework distinct from the traditional court system. The bill's emphasis on simplifying and standardising statutory authorities is crucial, as it translates into a more straightforward process for individuals involved in disputes. This enables them to resolve their issues more quickly, move past the conflict, and resume their normal lives, which is ultimately the core objective of a functioning justice system—to empower citizens to contribute positively to society. |
While enhancing the efficiency of general tribunals is valuable, it is equally imperative to ensure that dispute resolution mechanisms adequately serve Māori communities, respecting tikanga and Te Ao Māori principles. The current system often fails to provide culturally appropriate pathways for resolving disputes that arise within or affect Māori, such as those concerning whānau, hapū, or iwi. Future legislative efforts should explore strengthening or establishing specific Māori dispute resolution bodies, or integrating tikanga-based processes more deeply into existing tribunals, to ensure that Māori can access justice in a manner that aligns with their cultural values. This would not only improve access to justice but also affirm the Crown's Treaty obligations by recognising and supporting Māori self-determination in dispute resolution, moving beyond a one-size-fits-all approach to justice. |
TripletLoss with these parameters:{
"distance_metric": "TripletDistanceMetric.COSINE",
"triplet_margin": 0.3
}
eval_strategy: stepsper_device_train_batch_size: 1learning_rate: 2e-05num_train_epochs: 1warmup_ratio: 0.1warmup_steps: 0.1load_best_model_at_end: Trueeval_on_start: Trueprompts: task: classification | query:do_predict: Falseeval_strategy: stepsprediction_loss_only: Trueper_device_train_batch_size: 1per_device_eval_batch_size: 8gradient_accumulation_steps: 1eval_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: 1max_steps: -1lr_scheduler_type: linearlr_scheduler_kwargs: Nonewarmup_ratio: 0.1warmup_steps: 0.1log_level: passivelog_level_replica: warninglog_on_each_node: Truelogging_nan_inf_filter: Trueenable_jit_checkpoint: Falsesave_on_each_node: Falsesave_only_model: Falserestore_callback_states_from_checkpoint: Falseuse_cpu: Falseseed: 42data_seed: Nonebf16: Falsefp16: Falsebf16_full_eval: Falsefp16_full_eval: Falsetf32: Nonelocal_rank: -1ddp_backend: Nonedebug: []dataloader_drop_last: Falsedataloader_num_workers: 0dataloader_prefetch_factor: Nonedisable_tqdm: Falseremove_unused_columns: Truelabel_names: Noneload_best_model_at_end: Trueignore_data_skip: Falsefsdp: []fsdp_config: {'min_num_params': 0, 'xla': False, 'xla_fsdp_v2': False, 'xla_fsdp_grad_ckpt': False}accelerator_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: Nonegroup_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: Truepush_to_hub: Falseresume_from_checkpoint: Nonehub_model_id: Nonehub_strategy: every_savehub_private_repo: Nonehub_always_push: Falsehub_revision: Nonegradient_checkpointing: Falsegradient_checkpointing_kwargs: Noneinclude_for_metrics: []eval_do_concat_batches: Trueauto_find_batch_size: Falsefull_determinism: Falseddp_timeout: 1800torch_compile: Falsetorch_compile_backend: Nonetorch_compile_mode: Noneinclude_num_input_tokens_seen: noneftune_noise_alpha: Noneoptim_target_modules: Nonebatch_eval_metrics: Falseeval_on_start: Trueuse_liger_kernel: Falseliger_kernel_config: Noneeval_use_gather_object: Falseaverage_tokens_across_devices: Trueuse_cache: Falseprompts: task: classification | query: batch_sampler: batch_samplermulti_dataset_batch_sampler: proportionalrouter_mapping: {}learning_rate_mapping: {}| Epoch | Step | Training Loss | nz-hansard-triplet-eval_cosine_accuracy |
|---|---|---|---|
| 0 | 0 | - | 0.1594 |
| 0.0181 | 50 | 0.1438 | - |
| 0.0361 | 100 | 0.0038 | - |
| 0.0542 | 150 | 0.0041 | - |
| 0.0722 | 200 | 0.0104 | 0.8486 |
| 0.0903 | 250 | 0.0113 | - |
| 0.1083 | 300 | 0.0039 | - |
| 0.1264 | 350 | 0.0149 | - |
| 0.1444 | 400 | 0.0088 | 0.9980 |
| 0.1625 | 450 | 0.0057 | - |
| 0.1805 | 500 | 0.0038 | - |
| 0.1986 | 550 | 0.0081 | - |
| 0.2166 | 600 | 0.0 | 0.8526 |
| 0.2347 | 650 | 0.0011 | - |
| 0.2527 | 700 | 0.0 | - |
| 0.2708 | 750 | 0.0041 | - |
| 0.2888 | 800 | 0.0072 | 0.8665 |
| 0.3069 | 850 | 0.0078 | - |
| 0.3249 | 900 | 0.0 | - |
| 0.3430 | 950 | 0.0 | - |
| 0.3610 | 1000 | 0.0 | 0.8506 |
| 0.3791 | 1050 | 0.0 | - |
| 0.3971 | 1100 | 0.0 | - |
| 0.4152 | 1150 | 0.0 | - |
| 0.4332 | 1200 | 0.0062 | 0.9124 |
| 0.4513 | 1250 | 0.0175 | - |
| 0.4693 | 1300 | 0.0142 | - |
| 0.4874 | 1350 | 0.0 | - |
| 0.5054 | 1400 | 0.0089 | 0.9940 |
| 0.5235 | 1450 | 0.0 | - |
| 0.5415 | 1500 | 0.0 | - |
| 0.5596 | 1550 | 0.0098 | - |
| 0.5776 | 1600 | 0.0031 | 0.8486 |
| 0.5957 | 1650 | 0.0 | - |
| 0.6137 | 1700 | 0.0 | - |
| 0.6318 | 1750 | 0.0085 | - |
| 0.6498 | 1800 | 0.0046 | 0.8705 |
| 0.6679 | 1850 | 0.0 | - |
| 0.6859 | 1900 | 0.0045 | - |
| 0.7040 | 1950 | 0.0 | - |
| 0.7220 | 2000 | 0.0011 | 0.8665 |
| 0.7401 | 2050 | 0.0043 | - |
| 0.7581 | 2100 | 0.0 | - |
| 0.7762 | 2150 | 0.0 | - |
| 0.7942 | 2200 | 0.0017 | 0.8606 |
| 0.8123 | 2250 | 0.0034 | - |
| 0.8303 | 2300 | 0.0049 | - |
| 0.8484 | 2350 | 0.0 | - |
| 0.8664 | 2400 | 0.0059 | 0.8665 |
| 0.8845 | 2450 | 0.0006 | - |
| 0.9025 | 2500 | 0.0 | - |
| 0.9206 | 2550 | 0.0 | - |
| 0.9386 | 2600 | 0.0 | 1.0 |
| 0.9567 | 2650 | 0.0 | - |
| 0.9747 | 2700 | 0.0 | - |
| 0.9928 | 2750 | 0.0 | - |
@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{hermans2017defense,
title={In Defense of the Triplet Loss for Person Re-Identification},
author={Alexander Hermans and Lucas Beyer and Bastian Leibe},
year={2017},
eprint={1703.07737},
archivePrefix={arXiv},
primaryClass={cs.CV}
}
Base model
google/embeddinggemma-300m