Views
No views yet
pip install -U sentence-transformers1from sentence_transformers import CrossEncoder
2
3# Download from the 🤗 Hub
4model = CrossEncoder("bansalaman18/reranker-bert-uncased_L-2_H-512_A-8-msmarco-bce")
5# Get scores for pairs of texts
6pairs = [
7 ['who is wale the rapper', "Wale (rapper)'s wiki: Olubowale Victor Akintimehin (born September 21, 1984), better known by his stage name Wale (/Ë\x88wÉ\x94Ë\x90leɪ/ WAW-lay), is an American rapper from Washington, D.C. He rose to prominence in 2006, when his song Dig Dug (Shake It) became popular in his hometown. Wale became locally recognized and continued recording music for the regional audience."],
8 ['what is platinum used for', 'The periodic table is a chart that shows how elements are related to one another. Indium is a transition metal that is also part of the platinum family. The metals in the platinum family are also known as the noble metals. They have this name because they do not react well with other elements and compounds. They appear to be too superior to react with most other substances. In fact, iridium is the most corrosion-resistant metal known.'],
9 ['where is the gonzaga university located', 'Where We Are. The Boise State University Department of Public Safety substation is located in Capitol Village at 2245 University Drive. Our office is open 24 hours a day, 7 days a week, so we are always available. Physical Address: 2245 University Drive, Boise, Idaho 83706.'],
10 ['most common protein in the human body', 'Protein is the second category of food that a human body can get energy from. Most people know protein as animal meat-a hamburger, a chicken leg. These are all proteins. You can also extract protein from certain plants.Soy protein isolate is a well known protein that comes from soybeans.uman Body Four Energy Sources. The human body can only metabolize four types of energy sources. These four categories are carbohydrates (sugars and starches), fats (includes oils), proteins (animal and vegetable), and alcohol.'],
11 ['where is azilda ontario', 'Azilda railway station is a Via Rail flag stop station located in Azilda, Ontario, in the city of Greater Sudbury community of Rayside-Balfour. It is on the Canadian Pacific Railway transcontinental main line, and is served by the regional rail Sudbury â\x80\x93 White River train. Map 12 (PDF) (Map). 1 : 1,600,000.'],
12]
13scores = model.predict(pairs)
14print(scores.shape)
15# (5,)
16
17# Or rank different texts based on similarity to a single text
18ranks = model.rank(
19 'who is wale the rapper',
20 [
21 "Wale (rapper)'s wiki: Olubowale Victor Akintimehin (born September 21, 1984), better known by his stage name Wale (/Ë\x88wÉ\x94Ë\x90leɪ/ WAW-lay), is an American rapper from Washington, D.C. He rose to prominence in 2006, when his song Dig Dug (Shake It) became popular in his hometown. Wale became locally recognized and continued recording music for the regional audience.",
22 'The periodic table is a chart that shows how elements are related to one another. Indium is a transition metal that is also part of the platinum family. The metals in the platinum family are also known as the noble metals. They have this name because they do not react well with other elements and compounds. They appear to be too superior to react with most other substances. In fact, iridium is the most corrosion-resistant metal known.',
23 'Where We Are. The Boise State University Department of Public Safety substation is located in Capitol Village at 2245 University Drive. Our office is open 24 hours a day, 7 days a week, so we are always available. Physical Address: 2245 University Drive, Boise, Idaho 83706.',
24 'Protein is the second category of food that a human body can get energy from. Most people know protein as animal meat-a hamburger, a chicken leg. These are all proteins. You can also extract protein from certain plants.Soy protein isolate is a well known protein that comes from soybeans.uman Body Four Energy Sources. The human body can only metabolize four types of energy sources. These four categories are carbohydrates (sugars and starches), fats (includes oils), proteins (animal and vegetable), and alcohol.',
25 'Azilda railway station is a Via Rail flag stop station located in Azilda, Ontario, in the city of Greater Sudbury community of Rayside-Balfour. It is on the Canadian Pacific Railway transcontinental main line, and is served by the regional rail Sudbury â\x80\x93 White River train. Map 12 (PDF) (Map). 1 : 1,600,000.',
26 ]
27)
28# [{'corpus_id': ..., 'score': ...}, {'corpus_id': ..., 'score': ...}, ...]NanoMSMARCO_R100, NanoNFCorpus_R100 and NanoNQ_R100CrossEncoderRerankingEvaluator with these parameters:
1{
2 "at_k": 10,
3 "always_rerank_positives": true
4}| Metric | NanoMSMARCO_R100 | NanoNFCorpus_R100 | NanoNQ_R100 |
|---|---|---|---|
| map | 0.0489 (-0.4407) | 0.2825 (+0.0215) | 0.1004 (-0.3192) |
| mrr@10 | 0.0215 (-0.4560) | 0.4559 (-0.0439) | 0.0785 (-0.3482) |
| ndcg@10 | 0.0397 (-0.5008) | 0.2832 (-0.0418) | 0.1167 (-0.3839) |
NanoBEIR_R100_meanCrossEncoderNanoBEIREvaluator with these parameters:
1{
2 "dataset_names": [
3 "msmarco",
4 "nfcorpus",
5 "nq"
6 ],
7 "rerank_k": 100,
8 "at_k": 10,
9 "always_rerank_positives": true
10}| Metric | Value |
|---|---|
| map | 0.1439 (-0.2461) |
| mrr@10 | 0.1853 (-0.2827) |
| ndcg@10 | 0.1465 (-0.3088) |
query, passage, and score| query | passage | score | |
|---|---|---|---|
| type | string | string | float |
| details |
|
|
|
| query | passage | score |
|---|---|---|
who is the actor that plays the tanned colonel for kfc? | James Rebhorn Actor, Scent of a Woman James Robert Rebhorn (September 1, 1948 - March 21, 2014) was an American actor who appeared in over 100 films, television series, and plays. At the time of his death, he had recurring roles in the current series White Collar and Homeland. | 0.0 |
asking for an increase in credit limit harm your credit score | If you request a credit line increase, you should ask the lender whether it will result in your credit report being pulled. If it does, this will show up as an inquiry on your report and generally remains on your credit report for two years.Too many inquiries can lower your credit score.f you request a credit line increase, you should ask the lender whether it will result in your credit report being pulled. If it does, this will show up as an inquiry on your report and generally remains on your credit report for two years. | 1.0 |
what is a sheep ked | Cysteine is required by sheep to produce wool: It is an essential amino acid that must be taken in from their feed. As a consequence, during drought conditions, sheep produce less wool; however, transgenic sheep that can make their own cysteine have been developed. | 0.0 |
BinaryCrossEntropyLoss with these parameters:
1{
2 "activation_fn": "torch.nn.modules.linear.Identity",
3 "pos_weight": null
4}query, passage, and score| query | passage | score | |
|---|---|---|---|
| type | string | string | float |
| details |
|
|
|
| query | passage | score |
|---|---|---|
who is wale the rapper | Wale (rapper)'s wiki: Olubowale Victor Akintimehin (born September 21, 1984), better known by his stage name Wale (/ËwÉËleɪ/ WAW-lay), is an American rapper from Washington, D.C. He rose to prominence in 2006, when his song Dig Dug (Shake It) became popular in his hometown. Wale became locally recognized and continued recording music for the regional audience. | 1.0 |
what is platinum used for | The periodic table is a chart that shows how elements are related to one another. Indium is a transition metal that is also part of the platinum family. The metals in the platinum family are also known as the noble metals. They have this name because they do not react well with other elements and compounds. They appear to be too superior to react with most other substances. In fact, iridium is the most corrosion-resistant metal known. | 0.0 |
where is the gonzaga university located | Where We Are. The Boise State University Department of Public Safety substation is located in Capitol Village at 2245 University Drive. Our office is open 24 hours a day, 7 days a week, so we are always available. Physical Address: 2245 University Drive, Boise, Idaho 83706. | 0.0 |
BinaryCrossEntropyLoss with these parameters:
1{
2 "activation_fn": "torch.nn.modules.linear.Identity",
3 "pos_weight": null
4}eval_strategy: stepsper_device_train_batch_size: 16per_device_eval_batch_size: 16learning_rate: 2e-05num_train_epochs: 1warmup_ratio: 0.1seed: 12bf16: Truehalf_precision_backend: cpu_ampdataloader_num_workers: 4load_best_model_at_end: Trueoverwrite_output_dir: Falsedo_predict: Falseeval_strategy: stepsprediction_loss_only: Trueper_device_train_batch_size: 16per_device_eval_batch_size: 16per_gpu_train_batch_size: Noneper_gpu_eval_batch_size: Nonegradient_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: {}warmup_ratio: 0.1warmup_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: 12data_seed: Nonejit_mode_eval: Falseuse_ipex: Falsebf16: Truefp16: Falsefp16_opt_level: O1half_precision_backend: cpu_ampbf16_full_eval: Falsefp16_full_eval: Falsetf32: Nonelocal_rank: 0ddp_backend: Nonetpu_num_cores: Nonetpu_metrics_debug: Falsedebug: []dataloader_drop_last: Falsedataloader_num_workers: 4dataloader_prefetch_factor: Nonepast_index: -1disable_tqdm: Falseremove_unused_columns: Truelabel_names: Noneload_best_model_at_end: Trueignore_data_skip: Falsefsdp: []fsdp_min_num_params: 0fsdp_config: {'min_num_params': 0, 'xla': False, 'xla_fsdp_v2': False, 'xla_fsdp_grad_ckpt': False}tp_size: 0fsdp_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}deepspeed: Nonelabel_smoothing_factor: 0.0optim: adamw_torchoptim_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: Falsegradient_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: Falseeval_use_gather_object: Falseaverage_tokens_across_devices: Falseprompts: Nonebatch_sampler: batch_samplermulti_dataset_batch_sampler: proportionalrouter_mapping: {}learning_rate_mapping: {}| Epoch | Step | Training Loss | Validation Loss | NanoMSMARCO_R100_ndcg@10 | NanoNFCorpus_R100_ndcg@10 | NanoNQ_R100_ndcg@10 | NanoBEIR_R100_mean_ndcg@10 |
|---|---|---|---|---|---|---|---|
| -1 | -1 | - | - | 0.0968 (-0.4436) | 0.2652 (-0.0598) | 0.0327 (-0.4680) | 0.1316 (-0.3238) |
| 0.0002 | 1 | 0.8075 | - | - | - | - | - |
| 0.1778 | 1000 | 0.6953 | 0.6852 | 0.0460 (-0.4944) | 0.3265 (+0.0014) | 0.0571 (-0.4436) | 0.1432 (-0.3122) |
| 0.3556 | 2000 | 0.686 | 0.6778 | 0.0479 (-0.4926) | 0.2853 (-0.0397) | 0.0947 (-0.4059) | 0.1426 (-0.3127) |
| 0.5333 | 3000 | 0.6791 | 0.6737 | 0.0397 (-0.5008) | 0.2832 (-0.0418) | 0.1167 (-0.3839) | 0.1465 (-0.3088) |
| 0.7111 | 4000 | 0.6757 | 0.6677 | 0.0321 (-0.5083) | 0.2815 (-0.0435) | 0.1040 (-0.3967) | 0.1392 (-0.3162) |
| 0.8889 | 5000 | 0.6758 | 0.6651 | 0.0397 (-0.5007) | 0.2743 (-0.0507) | 0.1061 (-0.3946) | 0.1400 (-0.3154) |
| -1 | -1 | - | - | 0.0397 (-0.5008) | 0.2832 (-0.0418) | 0.1167 (-0.3839) | 0.1465 (-0.3088) |
1@inproceedings{reimers-2019-sentence-bert,
2 title = "Sentence-BERT: Sentence Embeddings using Siamese BERT-Networks",
3 author = "Reimers, Nils and Gurevych, Iryna",
4 booktitle = "Proceedings of the 2019 Conference on Empirical Methods in Natural Language Processing",
5 month = "11",
6 year = "2019",
7 publisher = "Association for Computational Linguistics",
8 url = "https://arxiv.org/abs/1908.10084",
9}