Sentence-BERT: Sentence Embeddings using Siamese BERT-Networks
Paper โข 1908.10084 โข Published โข 19
How to use htNghiaaa/dsc25-bge-reranker-finetuned-kfold1-v1 with sentence-transformers:
from sentence_transformers import CrossEncoder
model = CrossEncoder("htNghiaaa/dsc25-bge-reranker-finetuned-kfold1-v1")
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 pair classification.
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("cross_encoder_model_id")
# Get scores for pairs of texts
pairs = [
['[PROMPT]\nTแบกi sao Bach lแบกi thรญch ฤร n clavichord hฦกn so vแปi dฦฐฦกng cแบงm, mแบทc dรน dฦฐฦกng cแบงm ฤรฃ ฤฦฐแปฃc phรกt minh tแปซ thแบฟ kแปท 15 vร rแบฅt phแป biแบฟn vร o thแปi cแปงa รดng?\n[CONTEXT]\nNฤm 1709, ngฦฐแปi thแปฃ chแบฟ tแบกo harpsichord ngฦฐแปi ร Bartolomeo Cristofori chแบฟ tแบกo chiแบฟc dฦฐฦกng cแบงm ฤแบงu tiรชn trรชn thแบฟ giแปi gแปi lร piano et forte (nhแบน vร mแบกnh). Khรดng lรขu sau, nhแปฏng ngฦฐแปi thแปฃ khรกc tแบกo ra nhแปฏng chiแบฟc pianoforte vแปi bรบa. Tiแบฟp ฤรณ, pianoforte thay thแบฟ harpsichord vร clavichord bแปi nรณ cรณ nhแปฏng ฦฐu ฤiแปm mร cรกc nhแบกc cแปฅ phรญm khรกc khรดng cรณ. Fortepiano lร mแปt nhแบกc cแปฅ dรขy-bรบa cรณ khแบฃ nฤng tแบกo ra nhแปฏng sแปฑ thay ฤแปi รขm thanh nhแป thรดng qua sแปฑ bแบฅm phรญm mแบกnh hay nhแบน cแปงa ngฦฐแปi chฦกi. ฤแบฟn khoแบฃng nฤm 1850, tแปซ "fortepiano" ฤฦฐแปฃc thay thแบฟ bแปi tแปซ "piano". Vร o nhแปฏng nฤm ฤแบงu thแบฟ kแป 18, dฦฐฦกng cแบงm khรดng mแบฅy thu hรบt ฤฦฐแปฃc sแปฑ chรบ รฝ vร แปงng hแป. J.S. Bach cรณ lแบฝ thรญch clavichord, nhแบกc cแปฅ mร รดng ฤรฃ quen chฦกi vร cลฉng lร nhแบกc cแปฅ chฦกi dแป
hฦกn.', '[RESPONSE]\nBach thรญch clavichord hฦกn vรฌ รขm thanh mแปm mแบกi vร sแปฑ kiแปm soรกt biแปu cแบฃm cao hฦกn, ฤiแปu nร y phรน hแปฃp vแปi phong cรกch รขm nhแบกc cแปงa รดng. Ngoร i ra, clavichord cลฉng รญt gรขy phiแปn nhiแป
u trong khรดng gian nhร nhแป hฦกn so vแปi piano.'],
['[PROMPT]\nSau thแบฅt bแบกi thฦฐฦกng mแบกi cแปงa Off the Wall (1979), phong cรกch รขm nhแบกc cแปงa Michael Jackson cรณ chuyแปn biแบฟn gรฌ nแปi bแบญt?\n[CONTEXT]\nOff the Wall (1979), mแปt thร nh quแบฃ hแปฃp tรกc giแปฏa Jackson vร Jones, ฤรฃ giรบp ฤแปnh hรฌnh mแปt Jackson tแปซ xu hฦฐแปng รขm nhแบกc bubblegum pop thuแป nhแป sang รขm nhแบกc chแปฏng chแบกc, trฦฐแปng thร nh, phรน hแปฃp vแปi thแป hiแบฟu cแปงa nhiแปu thร nh phแบงn lแปฉa tuแปi hฦกn. Ngoร i Jackson, cรกc nhแบกc sฤฉ khรกc xuแบฅt hiแปn trong album bao gแปm Rod Temperton, Stevie Wonder vร Paul McCartney. Album ฤแบกt thร nh cรดng trรชn toร n thแบฟ giแปi vร lแบญp kแปท lแปฅc trแป thร nh album ฤแบงu tiรชn ra mแบฏt 4 ฤฤฉa ฤฦกn nแบฑm trong top 10 tแบกi Hoa Kแปณ, trong ฤรณ cรณ ฤฤฉa ฤฦกn quรกn quรขn "Don\'t Stop \'Til You Get Enough" vร "Rock With You". Album nร y vฦฐฦกn tแปi vแป trรญ thแปฉ 3 trรชn bแบฃng xแบฟp hแบกng album Billboard 200 vร hiแปn ฤรฃ tiรชu thแปฅ hฦกn 20 triแปu bแบฃn trรชn thแบฟ giแปi.', '[RESPONSE]\nMichael Jackson ฤรฃ chuyแปn tแปซ bubblegum pop sang รขm nhแบกc funk vร disco, phแปi hแปฃp vแปi Quincy Jones ฤแป tแบกo ra mแปt รขm thanh ฤแปc ฤรกo. Sau thร nh cรดng cแปงa "Off the Wall", Jackson ฤรฃ trแป thร nh nghแป sฤฉ solo cรณ sแปฉc แบฃnh hฦฐแปng lแปn trong lร ng nhแบกc quแปc tแบฟ.'],
['[PROMPT]\nSแป lฦฐแปฃng quรขn lรญnh Nam Triแปu Tiรชn bแป chแบฟt ฤรณi trong lรบc di chuyแปn cรณ thแป lรชn ฤแบฟn con sแป bao nhiรชu?\n[CONTEXT]\nMแปt ฤiแปu rแบฅt ฤแบทc biแปt lร binh sฤฉ Nam Triแปu Tiรชn lแบกi trแป thร nh nแบกn nhรขn bแป ngฦฐแปฃc ฤรฃi cแปงa chรญnh quรขn ฤแปi nร y. Trong thรกng 12 nฤm 1950, แปฆy ban Quแปc phรฒng cแปงa Nam Triแปu Tiรชn ฤฦฐแปฃc thร nh lแบญp, quแบฃn lรฝ 406.000 binh lรญnh Nam Triแปu Tiรชn. Vร o mรนa ฤรดng nฤm 1951, 50.000 tแปi 90.000 binh lรญnh Nam Triแปu Tiรชn ฤรฃ bแป bแป ฤรณi ฤแบฟn chแบฟt trong khi hร nh quรขn vแป phรญa nam dฦฐแปi sแปฑ tแบฅn cรดng cแปงa Trung Quแปc, bแปi cรกc sฤฉ quan chแป huy cแปงa Nam Triแปu Tiรชn ฤรฃ tham รด ngรขn quแปน dร nh cho thแปฑc phแบฉm cแปงa binh sฤฉ. Sแปฑ kiแปn nร y ฤฦฐแปฃc gแปi lร Khแปงng hoแบฃng tแบกi แปฆy ban Quแปc phรฒng.[cแบงn dแบซn nguแปn]', '[RESPONSE]\nSแป lฦฐแปฃng quรขn lรญnh Nam Triแปu Tiรชn bแป chแบฟt ฤรณi trong lรบc di chuyแปn cรณ thแป lรชn ฤแบฟn con sแป 90.000.'],
['[PROMPT]\nTรชn cแปงa ฤแบฟ quแปc nร y cรณ รฝ nghฤฉa ฤแบทc biแปt lร nรณ ฤฦฐแปฃc ฤแบทt theo tรชn cแปงa mแปt vแป hoร ng ฤแบฟ nแปi tiแบฟng ngฦฐแปi La Mรฃ, Julius Caesar, ฤรบng khรดng?\n[CONTEXT]\nฤแบฟ quแปc La Mรฃ Thแบงn Thรกnh (tiแบฟng Latinh: Sacrum Romanum Imperium; tiแบฟng ฤแปฉc: Heiliges Rรถmisches Reich; tiแบฟng ร: Sacro Romano Impero; tiแบฟng Anh: Holy Roman Empire)[b] cรฒn ฤฦฐแปฃc gแปi lร Thรกnh chแบฟ La Mรฃ, lร mแปt phแปฉc hแปฃp lรฃnh thแป rแปng lแปn ฤa sแบฏc tแปc, mร chแปง yแบฟu lร ngฦฐแปi ฤแปฉc, tแปn tแบกi tแปซ cuแปi thแปi sฦก kแปณ Trung cแป cho ฤแบฟn nฤm 1806. Tรชn cแปงa ฤแบฟ quแปc bแบฏt nguแปn tแปซ yรชu sรกch cแปงa cรกc Hoร ng ฤแบฟ La Mรฃ ฤแปฉc vร o thแปi Trung cแป, muแปn tiแบฟp tแปฅc truyแปn thแปng cแปงa ฤแบฟ chแบฟ La Mรฃ cแป vร hแปฃp phรกp hรณa quyแปn cai trแป nhฦฐ lร thรกnh รฝ cแปงa Thiรชn Chรบa. Lรฃnh thแป chแปง yแบฟu cแปงa ฤแบฟ quแปc gแปm Vฦฐฦกng quแปc ฤแปฉc, Vฦฐฦกng quแปc Bohemia, Vฦฐฦกng quแปc Burgundy, Vฦฐฦกng quแปc ร vร nhiแปu lรฃnh thแป, cรดng quแปc, thร nh phแป ฤแบฟ quแปc tแปฑ do lแปn nhแป khรกc.', '[RESPONSE]\nTรชn cแปงa ฤแบฟ quแปc La Mรฃ Thแบงn Thรกnh thแปฑc chแบฅt bแบฏt nguแปn tแปซ mแปt truyแปn thuyแบฟt vแป Julius Caesar, ngฦฐแปi ฤฦฐแปฃc cho lร ฤรฃ thร nh lแบญp ฤแบฟ chแบฟ nร y ฤแป bแบฃo vแป nแปn vฤn minh La Mรฃ khแปi sแปฑ sแปฅp ฤแป hoร n toร n.'],
['[PROMPT]\nChiแบฟn tranh Ba mฦฐฦกi nฤm, diแป
n ra tแปซ 1618 ฤแบฟn 1648, chแปง yแบฟu lร mแปt cuแปc chiแบฟn tranh giแปฏa cรกc quแปc gia chรขu รu nhแบฑm giร nh quyแปn kiแปm soรกt thฦฐฦกng mแบกi toร n cแบงu, phแบฃi khรดng?\n[CONTEXT]\nMแปt loแบกt trแบญn chiแบฟn trong giai ฤoแบกn 1618-1648, mร cรกc sแปญ gia gแปi lร Chiแบฟn tranh Ba mฦฐฦกi Nฤm, diแป
n ra trรชn nhแปฏng lรฃnh thแป cแปงa ngฦฐแปi ฤแปฉc. Khแปi ฤแบงu, cuแปc chiแบฟn chแปง yแบฟu dแปฑa trรชn xung ฤแปt tรดn giรกo giแปฏa cรกc phe nhรณm Cรดng giรกo vร Tin Lร nh trong Phong trร o Cแบฃi cรกch. Dแบงn dร , cuแปc chiแบฟn lan rแปng giแปฏa mแปt bรชn lร nhแปฏng hoร ng thรขn ngฦฐแปi ฤแปฉc vร bรชn kia chแปง yแบฟu lร Thแปฅy ฤiแปn vร Phรกp muแปn hแบกn chแบฟ quyแปn lแปฑc cแปงa ฤแบฟ quแปc La Mรฃ thแบงn Thรกnh. Chiแบฟn tranh Ba mฦฐฦกi nฤm lร mแปt trong nhแปฏng cuแปc chiแบฟn gรขy tร n phรก nแบทng nแป nhแบฅt trong lแปch sแปญ chรขu รu. ฤรขy cลฉng lร cuแปc chiแบฟn tรดn giรกo cuแปi cรนng แป chรขu รu khiแบฟn cho ฤแบฟ quแปc bแป tร n phรก nแบทng nแป, nhiแปu thร nh thแป vร vรนng nรดng thรดn bแป san bแบฑng, dรขn sแป suy giแบฃm. ฦฏแปc lฦฐแปฃng cรณ mแปt phแบงn ba ngฦฐแปi ฤแปฉc bแป mแบกng trong cuแปc chiแบฟn tร n bแบกo nร y.', '[RESPONSE]\nChiแบฟn tranh Ba mฦฐฦกi nฤm diแป
n ra tแปซ 1618 ฤแบฟn 1648 chแปง yแบฟu lร mแปt cuแปc xung ฤแปt tรดn giรกo giแปฏa cรกc phe Cรดng giรกo vร Tin Lร nh, khรดng phแบฃi lร cuแปc chiแบฟn tranh thฦฐฦกng mแบกi toร n cแบงu.'],
]
scores = model.predict(pairs)
print(scores.shape)
# (5, 3)
sentence_0, sentence_1, and label| sentence_0 | sentence_1 | label | |
|---|---|---|---|
| type | string | string | int |
| details |
|
|
|
| sentence_0 | sentence_1 | label |
|---|---|---|
[PROMPT] |
[RESPONSE] |
1 |
[PROMPT] |
[RESPONSE] |
2 |
[PROMPT] |
[RESPONSE] |
0 |
CrossEntropyLossper_device_train_batch_size: 4per_device_eval_batch_size: 4num_train_epochs: 1fp16: Trueoverwrite_output_dir: Falsedo_predict: Falseeval_strategy: noprediction_loss_only: Trueper_device_train_batch_size: 4per_device_eval_batch_size: 4per_gpu_train_batch_size: Noneper_gpu_eval_batch_size: Nonegradient_accumulation_steps: 1eval_accumulation_steps: Nonetorch_empty_cache_steps: Nonelearning_rate: 5e-05weight_decay: 0.0adam_beta1: 0.9adam_beta2: 0.999adam_epsilon: 1e-08max_grad_norm: 1num_train_epochs: 1max_steps: -1lr_scheduler_type: linearlr_scheduler_kwargs: {}warmup_ratio: 0.0warmup_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: 42data_seed: Nonejit_mode_eval: Falseuse_ipex: Falsebf16: Falsefp16: Truefp16_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 |
|---|---|---|
| 0.3472 | 500 | 1.0385 |
| 0.6944 | 1000 | 0.7521 |
| 0.3472 | 500 | 0.7444 |
| 0.6944 | 1000 | 0.7389 |
@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