Views
No views yet
pip install -U sentence-transformers1from sentence_transformers import CrossEncoder
2
3# Download from the 🤗 Hub
4model = CrossEncoder("chingackgook/reranker-ModernBERT-base-gooaq-bce")
5# Get scores for pairs of texts
6pairs = [
7 ['how many days can i drive my car without mot?', "If your car fails its MOT you can only continue to drive it if the previous year's MOT is still valid - which might occur if you submitted the car for its test two weeks early. You can still drive it away from the testing centre or garage if no 'dangerous' problems were identified during the MOT."],
8 ['how many days can i drive my car without mot?', '["Open File Explorer\', go to \'This PC\'. Check the status of the network drive. [00:11]", \'An error occurred while reconnecting or mapping Drive letter Z: to Network folder. [00:36]\', \'You can do either connect the drive (Map network drive) or Disconnect Network drive. [01:01]\', \'Disconnect Network Drive by this way. [01:28]\']'],
9 ['what xbox 360 games are compatible with xbox 1?', "['0 day Attack on Earth.', '3D Ultra Minigolf.', 'A Kingdom for Keflings.', 'A World of Keflings.', 'Ace Combat 6: Fires of Liberation.', 'Aegis Wing.', 'Age of Booty.', 'Alan Wake (Tested by Digital Foundry)']"],
10 ['what xbox 360 games are compatible with xbox 1?', "['1) Computer and Information Systems Managers.', '2) Computer and Information Research Scientists.', '3) Computer Network Architects.', '4) Software Development Engineer.', '5) Software Developers.', '6) Information Security Analysts.', '8) Computer Systems Analysts.']"],
11 ['what does it mean when a guy asks for a picture of you?', 'He wants to confirm if he is talking to Priya or Angel Priya (I.e., if he is really talking to a girl or just a guy with fake profile) They are talking to you and want to see how you look. I found it normal but would say, be careful about whom do you share your picture with as they might misuse it. I hate this one.'],
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 'how many days can i drive my car without mot?',
20 [
21 "If your car fails its MOT you can only continue to drive it if the previous year's MOT is still valid - which might occur if you submitted the car for its test two weeks early. You can still drive it away from the testing centre or garage if no 'dangerous' problems were identified during the MOT.",
22 '["Open File Explorer\', go to \'This PC\'. Check the status of the network drive. [00:11]", \'An error occurred while reconnecting or mapping Drive letter Z: to Network folder. [00:36]\', \'You can do either connect the drive (Map network drive) or Disconnect Network drive. [01:01]\', \'Disconnect Network Drive by this way. [01:28]\']',
23 "['0 day Attack on Earth.', '3D Ultra Minigolf.', 'A Kingdom for Keflings.', 'A World of Keflings.', 'Ace Combat 6: Fires of Liberation.', 'Aegis Wing.', 'Age of Booty.', 'Alan Wake (Tested by Digital Foundry)']",
24 "['1) Computer and Information Systems Managers.', '2) Computer and Information Research Scientists.', '3) Computer Network Architects.', '4) Software Development Engineer.', '5) Software Developers.', '6) Information Security Analysts.', '8) Computer Systems Analysts.']",
25 'He wants to confirm if he is talking to Priya or Angel Priya (I.e., if he is really talking to a girl or just a guy with fake profile) They are talking to you and want to see how you look. I found it normal but would say, be careful about whom do you share your picture with as they might misuse it. I hate this one.',
26 ]
27)
28# [{'corpus_id': ..., 'score': ...}, {'corpus_id': ..., 'score': ...}, ...]gooaq-devCrossEncoderRerankingEvaluator with these parameters:
1{
2 "at_k": 10,
3 "always_rerank_positives": false
4}| Metric | Value |
|---|---|
| map | 0.2500 (-0.7500) |
| mrr@10 | 0.2500 (-0.7500) |
| ndcg@10 | 0.4307 (-0.5693) |
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.0358 (-0.4538) | 0.2903 (+0.0293) | 0.0379 (-0.3817) |
| mrr@10 | 0.0109 (-0.4666) | 0.5069 (+0.0070) | 0.0140 (-0.4127) |
| ndcg@10 | 0.0260 (-0.5145) | 0.2900 (-0.0350) | 0.0174 (-0.4833) |
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.1213 (-0.2688) |
| mrr@10 | 0.1772 (-0.2908) |
| ndcg@10 | 0.1111 (-0.3443) |
question, answer, and label| question | answer | label | |
|---|---|---|---|
| type | string | string | int |
| details |
|
|
|
| question | answer | label |
|---|---|---|
how many days can i drive my car without mot? | If your car fails its MOT you can only continue to drive it if the previous year's MOT is still valid - which might occur if you submitted the car for its test two weeks early. You can still drive it away from the testing centre or garage if no 'dangerous' problems were identified during the MOT. | 1 |
how many days can i drive my car without mot? | ["Open File Explorer', go to 'This PC'. Check the status of the network drive. [00:11]", 'An error occurred while reconnecting or mapping Drive letter Z: to Network folder. [00:36]', 'You can do either connect the drive (Map network drive) or Disconnect Network drive. [01:01]', 'Disconnect Network Drive by this way. [01:28]'] | 0 |
what xbox 360 games are compatible with xbox 1? | ['0 day Attack on Earth.', '3D Ultra Minigolf.', 'A Kingdom for Keflings.', 'A World of Keflings.', 'Ace Combat 6: Fires of Liberation.', 'Aegis Wing.', 'Age of Booty.', 'Alan Wake (Tested by Digital Foundry)'] | 1 |
BinaryCrossEntropyLoss with these parameters:
1{
2 "activation_fn": "torch.nn.modules.linear.Identity",
3 "pos_weight": 1
4}eval_strategy: stepsper_device_train_batch_size: 16per_device_eval_batch_size: 16learning_rate: 2e-05num_train_epochs: 1warmup_ratio: 0.1seed: 12bf16: Truedataloader_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: 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: 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}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: lengthproject: huggingfacetrackio_space_id: trackioddp_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: noneftune_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: Trueprompts: Nonebatch_sampler: batch_samplermulti_dataset_batch_sampler: proportionalrouter_mapping: {}learning_rate_mapping: {}| Epoch | Step | Training Loss | gooaq-dev_ndcg@10 | NanoMSMARCO_R100_ndcg@10 | NanoNFCorpus_R100_ndcg@10 | NanoNQ_R100_ndcg@10 | NanoBEIR_R100_mean_ndcg@10 |
|---|---|---|---|---|---|---|---|
| -1 | -1 | - | 0.4307 (-0.5693) | 0.0220 (-0.5184) | 0.2802 (-0.0448) | 0.0200 (-0.4806) | 0.1074 (-0.3479) |
| 0.25 | 1 | 0.7171 | - | - | - | - | - |
| -1 | -1 | - | 0.4307 (-0.5693) | 0.0260 (-0.5145) | 0.2900 (-0.0350) | 0.0174 (-0.4833) | 0.1111 (-0.3443) |
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}