Sentence-BERT: Sentence Embeddings using Siamese BERT-Networks
Paper โข 1908.10084 โข Published โข 19
How to use htNghiaaa/nextlevelv1-bge-finetuned-v1 with sentence-transformers:
from sentence_transformers import CrossEncoder
model = CrossEncoder("htNghiaaa/nextlevelv1-bge-finetuned-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]\nJackson ฤรฃ giร nh ฤฦฐแปฃc giแบฃi Oscar cho bแป phim tร i liแปu "This Is It" vร o nฤm 2009, ฤรบng khรดng?\n[CONTEXT]\nBร i hรกt phรกt hร nh ฤแบงu tiรชn sau khi qua ฤแปi cแปงa Jackson mang tรชn "This Is It", do รดng ฤแปng sรกng tรกc cรนng Paul Anka vร o nhแปฏng nฤm 1980. Bร i hรกt khรดng ฤฦฐแปฃc xuแบฅt hiแปn trong ฤรชm nhแบกc cรนng tรชn vร bแบฃn thu รขm dแปฑa trรชn mแปt ฤoแบกn thu thแปญ cลฉ. Cรกc anh em cรฒn lแบกi cแปงa nhร Jackson ฤรฃ vร o phรฒng thu lแบงn ฤแบงu kแป tแปซ nฤm 1989 ฤแป thu giแปng bรจ cho bร i hรกt nร y. Vร o ngร y 28 thรกng 10 nฤm 2009, mแปt bแป phim tร i liแปu vแป khรขu tแบญp dฦฐแปฃt cho ฤรชm diแป
n mang tรชn Michael Jackson\'s This Is It ฤฦฐแปฃc ra mแบฏt. Dรน chแป phรกt hร nh trong 2 tuแบงn giแปi hแบกn, ฤรขy lแบกi lร bแป phim tร i liแปu hay ฤรชm diแป
n ฤแบกt doanh thu cao nhแบฅt mแปi thแปi ฤแบกi, vแปi 260 triแปu ฤรด-la Mแปน trรชn toร n cแบงu. Tร i sแบฃn cแปงa Jackson thu vแป 90% lแปฃi nhuแบญn. Bแป phim ra mแบฏt cรนng mแปt album tแปng hแปฃp cรนng tรชn. Hai phiรชn bแบฃn mแปi cแปงa bร i hรกt xuแบฅt hiแปn trong album nร y, cรนng mแปt ฤฤฉa bแป sung vแปi bร i thฦก mang tแปฑa ฤแป "Planet Earth". Tแบกi Giแบฃi thฦฐแปng รขm nhแบกc Mแปน 2009, Jackson thแบฑng 4 giแบฃi, trong ฤรณ cรณ 2 giแบฃi cho Number Ones.', '[RESPONSE]\nKhรดng, Jackson khรดng giร nh ฤฦฐแปฃc giแบฃi Oscar cho bแป phim tร i liแปu "This Is It" vร o nฤm 2009. Bแป phim ฤแบกt doanh thu cao nhฦฐng khรดng giร nh ฤฦฐแปฃc giแบฃi Oscar.'],
['[PROMPT]\nVua Philippos II ฤฦฐแปฃc thแบงn linh bแบฏt phแบฃi lร m gรฌ?\n[CONTEXT]\nNรณi chung, sau khi cรณ chiรชm bao, vua Philippos II sai Chaero ngฦฐแปi xแปฉ Megalopolis) ฤแบฟn ngรดi ฤiแปn thแป thแบงn Apollo tแบกi Delphi, ฤแป hแปi รฝ thแบงn linh xem giแบฅc mแปng cแปงa vua bรกo hiแปu ฤiแปu gรฌ sแบฝ xแบฃy ra? Philippos II ฤรฃ nhแบญn ฤฦฐแปฃc cรขu trแบฃ lแปi rแบฑng, รดng phแบฃi thแป phแปฅng thแบงn Zeus chu ฤรกo, hฦกn hแบฟt tแบฅt cแบฃ mแปi vแป thแบงn khรกc. Vร , nhร vua ฤรฃ bแป mแบฅt mแปt con mแบฏt khi ฤi chinh chiแบฟn, mร vแปi con mแบฏt nร y รดng ฤรฃ nhรฌn trแปm qua buแปng ngแปง cแปงa vแปฃ, thแบฅy thแบงn linh ฤแปi lแปt loร i rแบฏn mร ngแปง chung vแปi vแปฃ รดng. Hฦกn nแปฏa, theo nhฦฐ Eratosthenes, sau nร y khi Alexandros ฤแบกi ฤแบฟ lรชn ฤฦฐแปng chinh phแบกt ร chรขu, Olympias ฤรฃ tแปญ tแบฟ tแปซ biแปt con mรฌnh, sau khi bร ฤรฃ nรณi riรชng vแปi รดng rแบฑng รดng thแปฑc chแบฅt lร con cแปงa ai? Bร ฤรฃ cรบng tแบฟ vแป thแบงn แบฅy nhฦฐ thแบฟ nร o? ฤแป rแปi รดng thแบญt xแปฉng ฤรกng lร con cแปงa vแป thแบงn แบฅy. Cลฉng cรณ ngฦฐแปi viแบฟt rแบฑng Olympias bรกc bแป huyแปn thoแบกi nร y, bร nรณi:', '[RESPONSE]\nVua Philippos II ฤฦฐแปฃc thแบงn linh bแบฏt phแบฃi thแป phแปฅng thแบงn Apollo chu ฤรกo, hฦกn hแบฟt tแบฅt cแบฃ mแปi vแป thแบงn khรกc, ฤแป ฤแบฃm bแบฃo sแปฑ thแปnh vฦฐแปฃng cแปงa vฦฐฦกng quแปc mรฌnh.'],
['[PROMPT]\nViแปc thร nh lแบญp liรชn bang ฤรฃ vแบฅp phแบฃi nhแปฏng mรขu thuแบซn nร o, chแบณng hแบกn nhฦฐ viแปc Singapore gia nhแบญp liรชn bang vร o nฤm 1975 vร khรดng bao giแป bแป trแปฅc xuแบฅt?\n[CONTEXT]\nSแปฑ thร nh lแบญp liรชn bang khiแบฟn cรกc cฤng thแบณng tฤng cao, bao gแปm mแปt cuแปc xung ฤแปt vแปi Indonesia, Singapore bแป trแปฅc xuแบฅt vร o nฤm 1965, vร xung ฤแปt sแบฏc tแปc. Xung ฤแปt sแบฏc tแปc lรชn ฤแบฟn ฤแปnh ฤiแปm trong cรกc cuแปc bแบกo loแบกn sแบฏc tแปc ngร y 13 thรกng 5 nฤm 1969. Sau cรกc cuแปc bแบกo loแบกn, Thแปง tฦฐแปng Tun Abdul Razak ฤฦฐa ra Chรญnh sรกch Kinh tแบฟ mแปi gรขy tranh cรฃi, mแปฅc ฤรญch lร nhแบฑm nรขng cao phแบงn sแป hแปฏu kinh tแบฟ cแปงa bumiputera. Dฦฐแปi thแปi Thแปง tฦฐแปng Mahathir Mohamad, Malaysia trแบฃi qua tฤng trฦฐแปng kinh tแบฟ vร ฤรด thแป hรณa nhanh chรณng. Kinh tแบฟ Malaysia chuyแปn ฤแปi tแปซ dแปฑa vร o nรดng nghiแปp sang dแปฑa vร o chแบฟ tแบกo vร cรดng nghiแปp. Nhiแปu siรชu dแปฑ รกn ฤฦฐแปฃc hoร n thร nh, chแบณng hแบกn nhฦฐ thรกp ฤรดi Petronas, xa lแป Nam-Bแบฏc, hร nh lang ฤa phฦฐฦกng tiแปn siรชu cแบฅp, vร thแปง ฤรด hร nh chรญnh liรชn bang mแปi Putrajaya. Tuy nhiรชn, vร o cuแปi thแบญp niรชn 1990, Khแปงng hoแบฃng tร i chรญnh chรขu ร suรฝt khiแบฟn cho ฤแปng Ringgit cรนng cรกc thแป trฦฐแปng chแปฉng khoรกn vร bแบฅt ฤแปng sแบฃn Malaysia sแปฅp ฤแป.', '[RESPONSE]\nSingapore gia nhแบญp liรชn bang vร o nฤm 1975 vร khรดng bao giแป bแป trแปฅc xuแบฅt, dแบซn ฤแบฟn sแปฑ แปn ฤแปnh vร hรฒa hแปฃp lรขu dร i vแปi Malaysia mร khรดng cรณ bแบฅt kแปณ xung ฤแปt sแบฏc tแปc nร o xแบฃy ra.'],
['[PROMPT]\nVรฌ Kepler ฤรฃ bแป trแปฅc xuแบฅt khแปi Graz do cแบฃi sang Cรดng giรกo, nรชn thแปi gian hoร ng kim nhแบฅt trong sแปฑ nghiแปp nghiรชn cแปฉu khoa hแปc cแปงa รดng phแบฃi lร trฦฐแปc khi รดng rแปi Graz, ฤรบng khรดng?\n[CONTEXT]\nNgร y 2 thรกng 8, sau khi tแปซ chแปi cแบฃi sang Cรดng giรกo, Kepler vร gia ฤรฌnh bแป trแปฅc xuแบฅt khแปi Graz. Vร i thรกng sau, Kepler ฤฦฐa cแบฃ gia ฤรฌnh tแปi Praha. Trong suแปt nฤm 1601, รดng ฤฦฐแปฃc Tycho hแป trแปฃ trแปฑc tiแบฟp, giao cho รดng viแปc phรขn tรญch cรกc quan sรกt vแป hร nh tinh vร viแบฟt mแปt ฤoแบฃn luแบญn chแปng lแบกi Ursus (ฤรฃ quรก cแป). Vร o thรกng 9, Tycho ฤแบฃm bแบฃo cho รดng mแปt vแป trรญ cแปng tรกc viรชn trong mแปt dแปฑ รกn mแปi mร รดng ฤแป xuแบฅt vแปi hoร ng ฤแบฟ: Bแบฃng Rudolf thay thแบฟ cho danh mแปฅc sao trฦฐแปc ฤรขy cแปงa Erasmus Reinhold. Hai ngร y sau cรกi chแบฟt ฤแปt ngแปt cแปงa Tycho vร o ngร y 24 thรกng 10 nฤm 1601, Kepler ฤฦฐแปฃc bแป nhiแปm lร m ngฦฐแปi kแบฟ nhiแปm แป vแป trรญ nhร toรกn hแปc hoร ng gia vแปi trรกch nhiแปm hoร n thร nh nhแปฏng cรดng trรฌnh dang dแป cแปงa Tycho. ฤรฃ cรณ nhแปฏng giแบฃ thiแบฟt rแบฑng Kepler ฤแบงu ฤแปc Tycho ฤแป hฦฐแปng lแปฃi nhฦฐng mแปt nghiรชn cแปฉu khai quแบญt tแปญ thi xรกc nhแบญn rแบฑng ฤรณ lร ฤแปt tแปญ do suy thแบญn. 11 nฤm lร m nhร thiรชn vฤn hoร ng gia tแปซ ฤรณ sแบฝ lร nhแปฏng nฤm nghiรชn cแปฉu sรดi nแปi nhแบฅt cuแปc ฤแปi รดng.', '[RESPONSE]\nThแปi gian hoร ng kim nhแบฅt trong sแปฑ nghiแปp nghiรชn cแปฉu cแปงa Kepler thแปฑc sแปฑ lร trฦฐแปc khi รดng rแปi Graz, vรฌ รดng ฤรฃ thแปฑc hiแปn nhแปฏng nghiรชn cแปฉu ฤแปt phรก quan trแปng nhแบฅt cแปงa mรฌnh tแบกi ฤรณ trฦฐแปc khi ฤแบฟn Praha.'],
['[PROMPT]\nThuแบญt ngแปฏ thแปฑc vแบญt hแบกt kรญn Angiosperm ฤฦฐแปฃc ฤแปnh nghฤฉa ฤแบงu tiรชn trรชn ngรดn ngแปฏ Hy Lแบกp cแป ฤแบกi phแบฃi khรดng, mแบทc dรน nรณ thแปฑc sแปฑ cรณ nguแปn gแปc tแปซ tiแบฟng Latin?\n[CONTEXT]\nThuแบญt ngแปฏ ฤแป chแป thแปฑc vแบญt hแบกt kรญn lร "Angiosperm", cรณ nguแปn gแปc tแปซ tiแบฟng Hy Lแบกp cแป ฤแบกi ฮฑฮณฮณฮตฮนฮฟฮฝ (chแป chแปฉa) vร ฯฯฮตฯฮผฮฑ (hแบกt), ฤฦฐแปฃc Paul Hermann tแบกo thร nh dฦฐแปi dแบกng thuแบญt ngแปฏ Angiospermae vร o nฤm 1690, nhฦฐ lร tรชn gแปi cแปงa mแปt trong cรกc ngร nh chรญnh trong giแปi thแปฑc vแบญt cแปงa รดng, nรณ bao gแปm thแปฑc vแบญt cรณ hoa vร tแบกo ra cรกc hแบกt ฤฦฐแปฃc bao phแปง trong cรกc bao vแป (quแบฃ nang), ngฦฐแปฃc lแบกi vแปi Gymnospermae cแปงa รดng, hay thแปฑc vแบญt cรณ hoa vแปi cรกc quแบฃ thuแปc loแบกi quแบฃ bแบฟ hay quแบฃ nแปฉt - toร n bแป quแบฃ hay mแปi miแบฟng riรชng rแบฝ cแปงa nรณ ฤฦฐแปฃc coi nhฦฐ lร hแบกt vร trแบงn trแปฅi. Thuแบญt ngแปฏ nร y vร tแปซ trรกi nghฤฉa cแปงa nรณ ฤรฃ ฤฦฐแปฃc Carolus Linnaeus duy trรฌ vแปi cรนng ngแปฏ cแบฃnh, nhฦฐng vแปi cรกc แปฉng dแปฅng hแบกn hแบนp hฦกn, nhฦฐ trong tรชn gแปi cแปงa cรกc bแป trong lแปp Didynamia cแปงa รดng. Viแปc sแปญ dแปฅng nรณ trong bแบฅt kแปณ cรกch tiแบฟp cแบญn nร o ฤแปi vแปi lฤฉnh vแปฑc hiแปn ฤแบกi cแปงa nรณ chแป trแป thร nh cรณ thแป sau khi Robert Brown thiแบฟt lแบญp vร o nฤm 1827 sแปฑ tแปn tแบกi cแปงa cรกc noรฃn trแบงn thแปฑc sแปฑ trong Cycadeae (Tuแบฟ) vร Coniferae (Thรดng), cho phรฉp gแปi chรบng mแปt cรกch chรญnh xรกc lร thแปฑc vแบญt hแบกt trแบงn. Tแปซ thแปi ฤiแปm nร y trแป ฤi, cลฉng giแปng nhฦฐ Gymnosperm ฤฦฐแปฃc dรนng ฤแป chแป thแปฑc vแบญt hแบกt trแบงn thรฌ thuแบญt ngแปฏ Angiosperm ฤรฃ ฤฦฐแปฃc nhiแปu nhร thแปฑc vแบญt hแปc dรนng vแปi รฝ nghฤฉa ฤแปi lแบญp, nhฦฐng vแปi giแปi hแบกn thay ฤแปi, nhฦฐ lร tรชn nhรณm cho cรกc thแปฑc vแบญt hai lรก mแบงm khรกc.', '[RESPONSE]\nThuแบญt ngแปฏ "Angiosperm" thแปฑc chแบฅt cรณ nguแปn gแปc tแปซ tiแบฟng Latin, khรดng phแบฃi tiแบฟng Hy Lแบกp cแป ฤแบกi, vร lแบงn ฤแบงu tiรชn ฤฦฐแปฃc ฤแปnh nghฤฉa vร o nฤm 1690 bแปi Carolus Linnaeus, ngฦฐแปi ฤรฃ sแปญ dแปฅng nรณ ฤแป mรด tแบฃ thแปฑc vแบญt hแบกt trแบงn.'],
]
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] |
2 |
[PROMPT] |
[RESPONSE] |
1 |
[PROMPT] |
[RESPONSE] |
1 |
CrossEntropyLossper_device_train_batch_size: 4per_device_eval_batch_size: 4num_train_epochs: 4fp16: 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: 4max_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.3086 | 500 | 0.8509 |
| 0.6173 | 1000 | 0.7573 |
| 0.9259 | 1500 | 0.7314 |
| 1.2346 | 2000 | 0.6552 |
| 1.5432 | 2500 | 0.6549 |
| 1.8519 | 3000 | 0.6612 |
| 2.1605 | 3500 | 0.6118 |
| 2.4691 | 4000 | 0.4973 |
| 2.7778 | 4500 | 0.5137 |
| 3.0864 | 5000 | 0.4802 |
| 3.3951 | 5500 | 0.3779 |
| 3.7037 | 6000 | 0.4395 |
@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