Sentence-BERT: Sentence Embeddings using Siamese BERT-Networks
Paper • 1908.10084 • Published • 14
How to use steerrec/bge-reranker-v2-m3-query-note with sentence-transformers:
from sentence_transformers import CrossEncoder
model = CrossEncoder("steerrec/bge-reranker-v2-m3-query-note")
query = "Which planet is known as the Red Planet?"
passages = [
"Venus is often called Earth's twin because of its similar size and proximity.",
"Mars, known for its reddish appearance, is often referred to as the Red Planet.",
"Jupiter, the largest planet in our solar system, has a prominent red spot.",
"Saturn, famous for its rings, is sometimes mistaken for the Red Planet."
]
scores = model.predict([(query, passage) for passage in passages])
print(scores)This is a Cross Encoder model finetuned from BAAI/bge-reranker-v2-m3 using the sentence-transformers library. It computes scores for pairs of texts, which can be used for text reranking and semantic search.
CrossEncoder(
(0): Transformer({'transformer_task': 'sequence-classification', 'modality_config': {'text': {'method': 'forward', 'method_output_name': 'logits'}}, 'module_output_name': 'scores', 'architecture': 'XLMRobertaForSequenceClassification'})
)
First install the Sentence Transformers library:
pip install -U sentence-transformers
Then you can load this model and run inference.
from sentence_transformers import CrossEncoder
# Download from the 🤗 Hub
model = CrossEncoder("steerrec/bge-reranker-v2-m3-query-note")
# Get scores for pairs of inputs
pairs = [
['infp男和infj女', '谁懂啊啊啊‼️💗INFP×INFJ相处好戳我\n绿老头和小蝴蝶都是高敏易碎人群,消息秒回啊,朋友圈点赞啊,这种细微且偏爱的行为,都能让对方感到安心和减少内耗。\n小蝴蝶的话,有事情就不要藏着掖着,对绿老头也不要有过多的试探行为,有问题就直接问,直接说,只要把事情拖到情绪都上来了,那这问题就更难解决了。因为绿老头只是看起来淡然,但其实他们的内心是很火热躁动的,他们只是不好意思主动表达。绿老头得学会调整,明知道小蝴蝶容易想多内耗,那就多主动表现情绪,不要让小蝴蝶觉得你对他淡淡的,要是能偶尔打个只球,明确的表达一下内心,那就更好了。#心理[话题]# #mbti[话题]# #infp[话题]# #infp日常[话题]# #infp和infj[话题]# #INFJ[话题]# #infj的世界[话题]# #我的日常[话题]# #温暖治愈[话题]# '],
['电动车远光灯刺眼反击', '电动车在这些情况下是全责哦!注意了哦!\n骑电动车一定要小心这些情况哦![暗中观察R]#交通事故理赔[话题]# #交通事故[话题]# #法律求助[话题]# #电动车[话题]# #法律咨询[话题]# #交通安全[话题]# '],
['电动车远光灯刺眼反击', '支付宝上这个骑行险有用吗\n#车险[话题]# #电动车骑行险[话题]# #支付宝[话题]# '],
['牛奶品牌排名', '注意❗注意❗杯子到货,买就送📢\n杯子已经到货啦📣\n依然还是35.9到手2瓶4斤装的鲜奶,在额外赠送2个mini玻璃杯哦~\n顺丰冷链发货,包邮到家📦\n\xa0#乍甸牛奶[话题]#\xa0\xa0#云南游[话题]#\xa0\xa0#鲜奶[话题]#\xa0\xa0#可爱杯子[话题]#\xa0\xa0#杯子分享[话题]#\xa0\xa0#杯子控必入系列[话题]#\xa0\xa0#我就是个杯子控[话题]#\xa0\xa0#杯子[话题]#\xa0\xa0#鲜奶酸奶怎么挑[话题]#\xa0\xa0#鲜奶推荐[话题]#\xa0\xa0#鲜牛乳[话题]#\xa0\xa0#乍甸牛奶福利种草官[话题]#\xa0\xa0#乍甸牛奶也很好喝[话题]#\xa0\xa0#乍甸鲜奶[话题]#\xa0\t\n'],
['mbti人格', 'INFP小蝴蝶🦋请谨慎破防😅\n感觉本infp的确心灵上有些许脆弱,在面对朋友或者家人,别人的一句批评或者不认同,会影响我一天的心情~感觉这个习惯跟刻在骨子里一样,一边安慰自己,却一边焦虑😮\u200d💨很难想象有时候自己却很开朗乐观,其实内心很脆弱,一点就破⊙﹏⊙\n\t\n内容纯属娱乐🌚如有雷同纯属巧合🌚\n请大家对号入座哈哈哈哈😂#MBTI16型人格[话题]# #mbti梗图[话题]# #infp精神世界[话题]# #infp日常[话题]# '],
]
scores = model.predict(pairs)
print(scores)
# [0.3757 0.2134 0.1656 0.179 0.272 ]
# Or rank different texts based on similarity to a single text
ranks = model.rank(
'infp男和infj女',
[
'谁懂啊啊啊‼️💗INFP×INFJ相处好戳我\n绿老头和小蝴蝶都是高敏易碎人群,消息秒回啊,朋友圈点赞啊,这种细微且偏爱的行为,都能让对方感到安心和减少内耗。\n小蝴蝶的话,有事情就不要藏着掖着,对绿老头也不要有过多的试探行为,有问题就直接问,直接说,只要把事情拖到情绪都上来了,那这问题就更难解决了。因为绿老头只是看起来淡然,但其实他们的内心是很火热躁动的,他们只是不好意思主动表达。绿老头得学会调整,明知道小蝴蝶容易想多内耗,那就多主动表现情绪,不要让小蝴蝶觉得你对他淡淡的,要是能偶尔打个只球,明确的表达一下内心,那就更好了。#心理[话题]# #mbti[话题]# #infp[话题]# #infp日常[话题]# #infp和infj[话题]# #INFJ[话题]# #infj的世界[话题]# #我的日常[话题]# #温暖治愈[话题]# ',
'电动车在这些情况下是全责哦!注意了哦!\n骑电动车一定要小心这些情况哦![暗中观察R]#交通事故理赔[话题]# #交通事故[话题]# #法律求助[话题]# #电动车[话题]# #法律咨询[话题]# #交通安全[话题]# ',
'支付宝上这个骑行险有用吗\n#车险[话题]# #电动车骑行险[话题]# #支付宝[话题]# ',
'注意❗注意❗杯子到货,买就送📢\n杯子已经到货啦📣\n依然还是35.9到手2瓶4斤装的鲜奶,在额外赠送2个mini玻璃杯哦~\n顺丰冷链发货,包邮到家📦\n\xa0#乍甸牛奶[话题]#\xa0\xa0#云南游[话题]#\xa0\xa0#鲜奶[话题]#\xa0\xa0#可爱杯子[话题]#\xa0\xa0#杯子分享[话题]#\xa0\xa0#杯子控必入系列[话题]#\xa0\xa0#我就是个杯子控[话题]#\xa0\xa0#杯子[话题]#\xa0\xa0#鲜奶酸奶怎么挑[话题]#\xa0\xa0#鲜奶推荐[话题]#\xa0\xa0#鲜牛乳[话题]#\xa0\xa0#乍甸牛奶福利种草官[话题]#\xa0\xa0#乍甸牛奶也很好喝[话题]#\xa0\xa0#乍甸鲜奶[话题]#\xa0\t\n',
'INFP小蝴蝶🦋请谨慎破防😅\n感觉本infp的确心灵上有些许脆弱,在面对朋友或者家人,别人的一句批评或者不认同,会影响我一天的心情~感觉这个习惯跟刻在骨子里一样,一边安慰自己,却一边焦虑😮\u200d💨很难想象有时候自己却很开朗乐观,其实内心很脆弱,一点就破⊙﹏⊙\n\t\n内容纯属娱乐🌚如有雷同纯属巧合🌚\n请大家对号入座哈哈哈哈😂#MBTI16型人格[话题]# #mbti梗图[话题]# #infp精神世界[话题]# #infp日常[话题]# ',
]
)
# [{'corpus_id': ..., 'score': ...}, {'corpus_id': ..., 'score': ...}, ...]
query_note_test and query_note_valCrossEncoderRerankingEvaluator with these parameters:{
"at_k": 10
}
| Metric | query_note_test | query_note_val |
|---|---|---|
| map | 0.4565 | 0.4572 |
| mrr@10 | 0.5284 | 0.5247 |
| ndcg@10 | 0.5271 | 0.5328 |
sentence1, sentence2, and label| sentence1 | sentence2 | label | |
|---|---|---|---|
| type | string | string | float |
| modality | text | text | |
| details |
|
|
|
| sentence1 | sentence2 | label |
|---|---|---|
infp男和infj女 |
谁懂啊啊啊‼️💗INFP×INFJ相处好戳我 |
0.0 |
电动车远光灯刺眼反击 |
电动车在这些情况下是全责哦!注意了哦! |
0.0 |
电动车远光灯刺眼反击 |
支付宝上这个骑行险有用吗 |
0.0 |
BinaryCrossEntropyLoss with these parameters:{
"activation_fn": "torch.nn.modules.linear.Identity",
"pos_weight": null
}
per_device_train_batch_size: 32learning_rate: 0.0001weight_decay: 0.01num_train_epochs: 1lr_scheduler_type: cosinewarmup_ratio: 0.05seed: 3407bf16: Trueoverwrite_output_dir: Falsedo_predict: Falseprediction_loss_only: Trueper_device_train_batch_size: 32per_device_eval_batch_size: 8per_gpu_train_batch_size: Noneper_gpu_eval_batch_size: Nonegradient_accumulation_steps: 1eval_accumulation_steps: Nonetorch_empty_cache_steps: Nonelearning_rate: 0.0001weight_decay: 0.01adam_beta1: 0.9adam_beta2: 0.999adam_epsilon: 1e-08max_grad_norm: 1.0num_train_epochs: 1max_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: Falseuse_ipex: Falsebf16: Truefp16: Falsefp16_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: lengthddp_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: Falsegradient_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: Falseneftune_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: Falseprompts: Nonebatch_sampler: batch_samplermulti_dataset_batch_sampler: proportionalrouter_mapping: {}learning_rate_mapping: {}| Epoch | Step | Training Loss | query_note_test_ndcg@10 | query_note_val_ndcg@10 |
|---|---|---|---|---|
| -1 | -1 | - | 0.5206 | - |
| 0.7048 | 16950 | 0.6932 | - | - |
| 0.7069 | 17000 | 0.5323 | - | - |
| 0.7089 | 17050 | 0.5209 | - | - |
| 0.7110 | 17100 | 0.5281 | - | - |
| 0.7131 | 17150 | 0.5267 | - | - |
| 0.7152 | 17200 | 0.5124 | - | - |
| 0.7173 | 17250 | 0.5199 | - | - |
| 0.7193 | 17300 | 0.5189 | - | - |
| 0.7214 | 17350 | 0.5059 | - | - |
| 0.7235 | 17400 | 0.5326 | - | - |
| 0.7256 | 17450 | 0.5159 | - | - |
| 0.7277 | 17500 | 0.5246 | - | - |
| 0.7297 | 17550 | 0.5128 | - | - |
| 0.7318 | 17600 | 0.5078 | - | - |
| 0.7339 | 17650 | 0.4966 | - | - |
| 0.7360 | 17700 | 0.506 | - | - |
| 0.7380 | 17750 | 0.499 | - | - |
| 0.7401 | 17800 | 0.5069 | - | - |
| 0.7422 | 17850 | 0.5387 | - | - |
| 0.7443 | 17900 | 0.5124 | - | - |
| 0.7464 | 17950 | 0.522 | - | - |
| 0.7484 | 18000 | 0.5103 | - | - |
| 0.7505 | 18050 | 0.5217 | - | - |
| 0.7526 | 18100 | 0.4939 | - | - |
| 0.7547 | 18150 | 0.5151 | - | - |
| 0.7568 | 18200 | 0.4804 | - | - |
| 0.7588 | 18250 | 0.4969 | - | - |
| 0.7609 | 18300 | 0.5277 | - | - |
| 0.7630 | 18350 | 0.5143 | - | - |
| 0.7651 | 18400 | 0.5063 | - | - |
| 0.7672 | 18450 | 0.4899 | - | - |
| 0.7692 | 18500 | 0.5144 | - | - |
| 0.7713 | 18550 | 0.528 | - | - |
| 0.7734 | 18600 | 0.5032 | - | - |
| 0.7755 | 18650 | 0.4956 | - | - |
| 0.7775 | 18700 | 0.5144 | - | - |
| 0.7796 | 18750 | 0.5145 | - | - |
| 0.7817 | 18800 | 0.4971 | - | - |
| 0.7838 | 18850 | 0.5188 | - | - |
| 0.7859 | 18900 | 0.501 | - | - |
| 0.7879 | 18950 | 0.4892 | - | - |
| 0.7900 | 19000 | 0.4752 | - | - |
| 0.7921 | 19050 | 0.4984 | - | - |
| 0.7942 | 19100 | 0.5001 | - | - |
| 0.7963 | 19150 | 0.4809 | - | - |
| 0.7983 | 19200 | 0.5085 | - | - |
| 0.8004 | 19250 | 0.5122 | - | - |
| 0.8025 | 19300 | 0.5122 | - | - |
| 0.8046 | 19350 | 0.4909 | - | - |
| 0.8067 | 19400 | 0.5341 | - | - |
| 0.8087 | 19450 | 0.5147 | - | - |
| 0.8108 | 19500 | 0.5095 | - | - |
| 0.8129 | 19550 | 0.4945 | - | - |
| 0.8150 | 19600 | 0.4971 | - | - |
| 0.8170 | 19650 | 0.4967 | - | - |
| 0.8191 | 19700 | 0.5108 | - | - |
| 0.8212 | 19750 | 0.4983 | - | - |
| 0.8233 | 19800 | 0.5154 | - | - |
| 0.8254 | 19850 | 0.5214 | - | - |
| 0.8274 | 19900 | 0.4953 | - | - |
| 0.8295 | 19950 | 0.5079 | - | - |
| 0.8316 | 20000 | 0.5252 | - | - |
| 0.8337 | 20050 | 0.4966 | - | - |
| 0.8358 | 20100 | 0.492 | - | - |
| 0.8378 | 20150 | 0.5065 | - | - |
| 0.8399 | 20200 | 0.4825 | - | - |
| 0.8420 | 20250 | 0.4879 | - | - |
| 0.8441 | 20300 | 0.5351 | - | - |
| 0.8462 | 20350 | 0.4904 | - | - |
| 0.8482 | 20400 | 0.5141 | - | - |
| 0.8503 | 20450 | 0.5146 | - | - |
| 0.8524 | 20500 | 0.508 | - | - |
| 0.8545 | 20550 | 0.5271 | - | - |
| 0.8565 | 20600 | 0.5057 | - | - |
| 0.8586 | 20650 | 0.4757 | - | - |
| 0.8607 | 20700 | 0.5151 | - | - |
| 0.8628 | 20750 | 0.486 | - | - |
| 0.8649 | 20800 | 0.4908 | - | - |
| 0.8669 | 20850 | 0.5287 | - | - |
| 0.8690 | 20900 | 0.5223 | - | - |
| 0.8711 | 20950 | 0.5086 | - | - |
| 0.8732 | 21000 | 0.5066 | - | - |
| 0.8753 | 21050 | 0.5042 | - | - |
| 0.8773 | 21100 | 0.5032 | - | - |
| 0.8794 | 21150 | 0.5123 | - | - |
| 0.8815 | 21200 | 0.4825 | - | - |
| 0.8836 | 21250 | 0.5222 | - | - |
| 0.8857 | 21300 | 0.5044 | - | - |
| 0.8877 | 21350 | 0.5034 | - | - |
| 0.8898 | 21400 | 0.5193 | - | - |
| 0.8919 | 21450 | 0.4975 | - | - |
| 0.8940 | 21500 | 0.4754 | - | - |
| 0.8960 | 21550 | 0.5209 | - | - |
| 0.8981 | 21600 | 0.5024 | - | - |
| 0.9002 | 21650 | 0.5206 | - | - |
| 0.9023 | 21700 | 0.5032 | - | - |
| 0.9044 | 21750 | 0.5264 | - | - |
| 0.9064 | 21800 | 0.499 | - | - |
| 0.9085 | 21850 | 0.4967 | - | - |
| 0.9106 | 21900 | 0.491 | - | - |
| 0.9127 | 21950 | 0.5056 | - | - |
| 0.9148 | 22000 | 0.4996 | - | - |
| 0.9168 | 22050 | 0.4994 | - | - |
| 0.9189 | 22100 | 0.5254 | - | - |
| 0.9210 | 22150 | 0.5034 | - | - |
| 0.9231 | 22200 | 0.5123 | - | - |
| 0.9252 | 22250 | 0.4956 | - | - |
| 0.9272 | 22300 | 0.5194 | - | - |
| 0.9293 | 22350 | 0.474 | - | - |
| 0.9314 | 22400 | 0.4842 | - | - |
| 0.9335 | 22450 | 0.4914 | - | - |
| 0.9356 | 22500 | 0.4925 | - | - |
| 0.9376 | 22550 | 0.4938 | - | - |
| 0.9397 | 22600 | 0.5086 | - | - |
| 0.9418 | 22650 | 0.457 | - | - |
| 0.9439 | 22700 | 0.5185 | - | - |
| 0.9459 | 22750 | 0.5268 | - | - |
| 0.9480 | 22800 | 0.4872 | - | - |
| 0.9501 | 22850 | 0.5048 | - | - |
| 0.9522 | 22900 | 0.5103 | - | - |
| 0.9543 | 22950 | 0.5236 | - | - |
| 0.9563 | 23000 | 0.5049 | - | - |
| 0.9584 | 23050 | 0.5041 | - | - |
| 0.9605 | 23100 | 0.5066 | - | - |
| 0.9626 | 23150 | 0.5206 | - | - |
| 0.9647 | 23200 | 0.4732 | - | - |
| 0.9667 | 23250 | 0.4881 | - | - |
| 0.9688 | 23300 | 0.5099 | - | - |
| 0.9709 | 23350 | 0.5226 | - | - |
| 0.9730 | 23400 | 0.5322 | - | - |
| 0.9751 | 23450 | 0.4993 | - | - |
| 0.9771 | 23500 | 0.4856 | - | - |
| 0.9792 | 23550 | 0.4727 | - | - |
| 0.9813 | 23600 | 0.5093 | - | - |
| 0.9834 | 23650 | 0.5073 | - | - |
| 0.9854 | 23700 | 0.5153 | - | - |
| 0.9875 | 23750 | 0.4979 | - | - |
| 0.9896 | 23800 | 0.4961 | - | - |
| 0.9917 | 23850 | 0.5093 | - | - |
| 0.9938 | 23900 | 0.4811 | - | - |
| 0.9958 | 23950 | 0.5008 | - | - |
| 0.9979 | 24000 | 0.5151 | - | - |
| 1.0 | 24050 | 0.5318 | - | 0.5328 |
| -1 | -1 | - | 0.5271 | - |
@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",
}
Base model
BAAI/bge-reranker-v2-m3