Sentence-BERT: Sentence Embeddings using Siamese BERT-Networks
Paper • 1908.10084 • Published • 19
How to use patzer-adi/bge-patent-mnrl with sentence-transformers:
from sentence_transformers import SentenceTransformer
model = SentenceTransformer("patzer-adi/bge-patent-mnrl")
sentences = [
"Title: METHOD AND APPARATUS FOR RECOMMENDING BUDDIES TO A CLIENT USER\nAbstract: According to various embodiments of the present disclosure, an electronic device analyzes shared contents of all members in a circle created by a client user and generates feature information of the circle. The electronic device analyzes shared contents of each member in a buddy list created by the client user and generates feature information of each member in the buddy list. The electronic device calculates a similarity between the feature information of each member in the buddy list and the feature information of the circle, generates a similarity set, and generates a recommended buddy of the circle based on the similarity set. The electronic device prompts the recommended buddy of the circle to the client user.",
"Title: POWER AMPLIFIER\nAbstract: A power amplifier include an amplifier including at least one field effect transistor (FET) that operates in an amplifying stage configured to amplify an input signal, and a body controller configured to control a bias voltage of a body terminal of the FET based on a power of the input signal. The body controller performs controlling so that the bias voltage of the body terminal is reduced in response to the power of the input signal being increased. Accordingly, such a power amplifier exhibits improved linearity.",
"Title: OPTIMIZER MODULE IN HIGH LOAD CLIENT/SERVER SYSTEMS\nAbstract: An optimizer module can function as a proxy between clients and a server that provides access to a service via a REST API. As a proxy, the optimizer module can receive requests from the clients and can combine the requests into a single bulk request that is then submitted to the server. By combining multiple independent requests into a single bulk request, the optimizer module can reduce the total number of concurrent requests and thereby increase the total number of clients that can concurrently submit requests. In some cases, the optimizer module may be configured to apply optimizing rules when generating a bulk request.",
"Title: FACILITATING DATA MODEL ACCELERATION IN ASSOCIATION WITH AN EXTERNAL DATA SYSTEM\nAbstract: Embodiments of the present invention are directed to facilitating data model acceleration in association with an external data system. In accordance with aspects of the present disclosure, at a core engine, a search request associated with a data model is received. The data model generally designates one or more fields, from among a plurality of fields, that are of interest for subsequent searches. Thereafter, it is determined that an accelerated data model summary associated with the data model is stored at an external data system remote from the core engine that received the search request. The accelerated data model summary includes field values associated with the one or more fields designated in the data model. A search for the received search request is initiated using the accelerated data model summary at the external data. A set of search results relevant to the search request is obtained and provided to a user device for display to a user."
]
embeddings = model.encode(sentences)
similarities = model.similarity(embeddings, embeddings)
print(similarities.shape)
# [4, 4]This is a sentence-transformers model finetuned from BAAI/bge-base-en-v1.5. It maps sentences & paragraphs to a 768-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': 768, '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 = [
'Title: HOT-ROLLED STEEL SHEET, COLD-ROLLED STEEL SHEET, GALVANIZED STEEL SHEET, AND METHODS OF MANUFACTURING THE SAME\nAbstract: A hot-rolled steel sheet has an average value of the X-ray random intensity ratio of a {100}<011> to {223}<110> orientation group at least in a sheet thickness central portion that is in a sheet thickness range of ⅝ to ⅜ from a steel sheet surface of 1.0 to 6.0, an X-ray random intensity ratio of a {332}<113> crystal orientation of 1.0 to 5.0, rC which is an r value in a direction perpendicular to a rolling direction of 0.70 to 1.10, and r30 which is an r value in a direction that forms an angle of 30° with respect to the rolling direction of 0.70 to 1.10.',
'Title: METHOD FOR PRODUCING A FLAT PRODUCT FROM AN IRON-BASED SHAPE MEMORY ALLOY\nAbstract: Methods for producing a flat product from an iron-based shape memory alloy may involve casting a melt comprised of iron, alloying elements, and impurities into a strip having a thickness of 1-30 mm and cooling the melt as the strip is formed. A twin-roll caster may be employed to help cool and form the melt into the strip. The resultant flat product is highly resistant to bending and is robust under pressure and torsion.',
'Title: AUTOMATED NETWORK CONNECTION SHARING\nAbstract: Concepts and technologies are described herein for providing automated network connection sharing. Techniques disclosed herein can initiate Internet connection sharing between a first computer and a second computer, wherein the Internet connection sharing enables the first computer to function as a host to provide Internet access to the second computer. If there is a break in the connection, a system determines if the second computer is in proximity to the first computer. If it is determined that the first computer is in proximity to the second computer, the techniques disclosed herein verify access rights. Once the access rights are verified, the system automatically establishes Internet connection sharing between the first computer and the second computer. The techniques disclosed herein enable access to a service for sharing a network connection without requiring user interaction.',
]
embeddings = model.encode(sentences)
print(embeddings.shape)
# [3, 768]
# Get the similarity scores for the embeddings
similarities = model.similarity(embeddings, embeddings)
print(similarities)
# tensor([[1.0000, 0.5762, 0.0685],
# [0.5762, 1.0000, 0.0148],
# [0.0685, 0.0148, 1.0000]])
anchor and positive| anchor | positive | |
|---|---|---|
| type | string | string |
| modality | text | text |
| details |
|
|
| anchor | positive |
|---|---|
Title: METHOD FOR PROCESS OPERATORS TO PERSONALIZE SETTINGS FOR ENABLING DETECTION OF ABNORMAL PROCESS BEHAVIORS |
Title: DIGITAL MOTOR CONTROLLER STABILITY ANALYSIS TOOL |
Title: Terminal mechanism, Permanent Magnet Adjustable-Speed Motor and Centrifugal Refrigeration Compressor |
Title: METHOD FOR MAKING A POWER CONNECTION |
Title: METHOD, DEVICE AND SYSTEM FOR PROJECTION ON SCREEN |
Title: Multiband Wireless Communication Method, Coordinating Device, and Network |
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: 1learning_rate: 2e-05warmup_steps: 0.1fp16: Truedataloader_num_workers: 2batch_sampler: no_duplicatesper_device_train_batch_size: 16num_train_epochs: 1max_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: 2dataloader_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.0407 | 50 | 1.5115 |
| 0.0814 | 100 | 1.0744 |
| 0.1221 | 150 | 0.9523 |
| 0.1629 | 200 | 0.9376 |
| 0.2036 | 250 | 0.9118 |
| 0.2443 | 300 | 0.9300 |
| 0.2850 | 350 | 0.9179 |
| 0.3257 | 400 | 0.8813 |
| 0.3664 | 450 | 0.8283 |
| 0.4072 | 500 | 0.8399 |
| 0.4479 | 550 | 0.8350 |
| 0.4886 | 600 | 0.8227 |
| 0.5293 | 650 | 0.8668 |
| 0.5700 | 700 | 0.7845 |
| 0.6107 | 750 | 0.7699 |
| 0.6515 | 800 | 0.8075 |
| 0.6922 | 850 | 0.8143 |
| 0.7329 | 900 | 0.7978 |
| 0.7736 | 950 | 0.8160 |
| 0.8143 | 1000 | 0.8105 |
| 0.8550 | 1050 | 0.7341 |
| 0.8958 | 1100 | 0.7515 |
| 0.9365 | 1150 | 0.7128 |
| 0.9772 | 1200 | 0.6976 |
@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-base-en-v1.5