Views
No views yet
pip install -U sentence-transformers1from sentence_transformers import CrossEncoder
2
3# Download from the 🤗 Hub
4model = CrossEncoder("cometadata/jina-reranker-v2-multilingual-affiliations-large")
5# Get scores for pairs of texts
6pairs = [
7 ['Instituto Multidisciplinar para el Estudio del Medio ‘Ramón Margalef’, Universidad de Alicante, Alicante, Spain', 'Departamento de Matemática Aplicada, Universidad de Alicante, San Vicente del Raspeig (Alicante), España'],
8 ['Instituto Multidisciplinar para el Estudio del Medio ‘Ramón Margalef’, Universidad de Alicante, Alicante, Spain', 'Research Institute of Physics and Aerospace Science, University of Vigo, Vigo, Spain'],
9 ['Departamento de Patologia Básica, Setor de Ciências Biológicas, Universidade Federal do Paraná, 81531-970 Curitiba, PR, Brasil', 'Laboratory of Hematology, Department of Medical Pathology, Federal University of Paraná, Curitiba, Brazil'],
10 ['Departamento de Patologia Básica, Setor de Ciências Biológicas, Universidade Federal do Paraná, 81531-970 Curitiba, PR, Brasil', 'Laboratório de Patologia Experimental Pontifícia Universidade Católica do Paraná Curitiba Brazil'],
11 ['Institute of Information & Control, Hangzhou Dianzi University, Hangzhou 310018, P.R. China', 'College of Media & Design Hangzhou Dianzi University Hangzhou 310018 China'],
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 'Instituto Multidisciplinar para el Estudio del Medio ‘Ramón Margalef’, Universidad de Alicante, Alicante, Spain',
20 [
21 'Departamento de Matemática Aplicada, Universidad de Alicante, San Vicente del Raspeig (Alicante), España',
22 'Research Institute of Physics and Aerospace Science, University of Vigo, Vigo, Spain',
23 'Laboratory of Hematology, Department of Medical Pathology, Federal University of Paraná, Curitiba, Brazil',
24 'Laboratório de Patologia Experimental Pontifícia Universidade Católica do Paraná Curitiba Brazil',
25 'College of Media & Design Hangzhou Dianzi University Hangzhou 310018 China',
26 ]
27)
28# [{'corpus_id': ..., 'score': ...}, {'corpus_id': ..., 'score': ...}, ...]affiliation-valCrossEncoderRerankingEvaluator with these parameters:
1{
2 "at_k": 10,
3 "always_rerank_positives": true
4}| Metric | Value |
|---|---|
| map | 0.9880 (-0.0120) |
| mrr@10 | 0.9880 (-0.0120) |
| ndcg@10 | 0.9933 (-0.0067) |
query, document, and label| query | document | label | |
|---|---|---|---|
| type | string | string | int |
| details |
|
|
|
| query | document | label |
|---|---|---|
Max-Planck-Institut für Astronomie, Königgstuhl 17, D-69117 Heidelberg, Germany | Max-Planck-Institute for Astronomy, Königstuhl 17, 69117 Heidelberg, Germany e-mail: [object Object] | 1 |
Max-Planck-Institut für Astronomie, Königgstuhl 17, D-69117 Heidelberg, Germany | Clinical Trials Center Cardiovascular Research Foundation New York City NY USA | 0 |
Stowers Institute for Medical Research, 64110, Kansas City, Missouri, USA | Stowers Institute for Medical Research, 1,000 East 50th Street, Kansas City, MO 64110, USA | 1 |
BinaryCrossEntropyLoss with these parameters:
1{
2 "activation_fn": "torch.nn.modules.linear.Identity",
3 "pos_weight": null
4}query, document, and label| query | document | label | |
|---|---|---|---|
| type | string | string | int |
| details |
|
|
|
| query | document | label |
|---|---|---|
Instituto Multidisciplinar para el Estudio del Medio ‘Ramón Margalef’, Universidad de Alicante, Alicante, Spain | Departamento de Matemática Aplicada, Universidad de Alicante, San Vicente del Raspeig (Alicante), España | 1 |
Instituto Multidisciplinar para el Estudio del Medio ‘Ramón Margalef’, Universidad de Alicante, Alicante, Spain | Research Institute of Physics and Aerospace Science, University of Vigo, Vigo, Spain | 0 |
Departamento de Patologia Básica, Setor de Ciências Biológicas, Universidade Federal do Paraná, 81531-970 Curitiba, PR, Brasil | Laboratory of Hematology, Department of Medical Pathology, Federal University of Paraná, Curitiba, Brazil | 1 |
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: 128per_device_eval_batch_size: 128learning_rate: 3e-05warmup_ratio: 0.1bf16: Trueload_best_model_at_end: Truepush_to_hub: Truehub_model_id: cometadata/jina-reranker-v2-multilingual-affiliations-largeoverwrite_output_dir: Falsedo_predict: Falseeval_strategy: stepsprediction_loss_only: Trueper_device_train_batch_size: 128per_device_eval_batch_size: 128per_gpu_train_batch_size: Noneper_gpu_eval_batch_size: Nonegradient_accumulation_steps: 1eval_accumulation_steps: Nonetorch_empty_cache_steps: Nonelearning_rate: 3e-05weight_decay: 0.0adam_beta1: 0.9adam_beta2: 0.999adam_epsilon: 1e-08max_grad_norm: 1.0num_train_epochs: 3max_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: 42data_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: 0dataloader_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: Trueresume_from_checkpoint: Nonehub_model_id: cometadata/jina-reranker-v2-multilingual-affiliations-largehub_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: Nonemulti_dataset_batch_sampler: proportionalrouter_mapping: {}learning_rate_mapping: {}| Epoch | Step | Training Loss | Validation Loss | affiliation-val_ndcg@10 |
|---|---|---|---|---|
| -1 | -1 | - | - | 0.9200 (-0.0800) |
| 0.0008 | 1 | 0.1129 | - | - |
| 0.0752 | 100 | 0.3049 | - | - |
| 0.1505 | 200 | 0.1295 | - | - |
| 0.1881 | 250 | - | 0.6259 | 0.9715 (-0.0285) |
| 0.2257 | 300 | 0.1076 | - | - |
| 0.3010 | 400 | 0.0978 | - | - |
| 0.3762 | 500 | 0.1031 | 0.2822 | 0.9871 (-0.0129) |
| 0.4515 | 600 | 0.0932 | - | - |
| 0.5267 | 700 | 0.1015 | - | - |
| 0.5643 | 750 | - | 0.2395 | 0.9890 (-0.0110) |
| 0.6020 | 800 | 0.0999 | - | - |
| 0.6772 | 900 | 0.1112 | - | - |
| 0.7524 | 1000 | 0.1196 | 0.1980 | 0.9921 (-0.0079) |
| 0.8277 | 1100 | 0.1288 | - | - |
| 0.9029 | 1200 | 0.1295 | - | - |
| 0.9406 | 1250 | - | 0.1773 | 0.9929 (-0.0071) |
| 0.9782 | 1300 | 0.1338 | - | - |
| 1.0534 | 1400 | 0.0585 | - | - |
| 1.1287 | 1500 | 0.0295 | 0.3412 | 0.9879 (-0.0121) |
| 1.2039 | 1600 | 0.0412 | - | - |
| 1.2792 | 1700 | 0.0491 | - | - |
| 1.3168 | 1750 | - | 0.2622 | 0.9903 (-0.0097) |
| 1.3544 | 1800 | 0.0619 | - | - |
| 1.4296 | 1900 | 0.0612 | - | - |
| 1.5049 | 2000 | 0.0676 | 0.2131 | 0.9919 (-0.0081) |
| 1.5801 | 2100 | 0.073 | - | - |
| 1.6554 | 2200 | 0.0801 | - | - |
| 1.6930 | 2250 | - | 0.1940 | 0.9927 (-0.0073) |
| 1.7306 | 2300 | 0.0963 | - | - |
| 1.8059 | 2400 | 0.1114 | - | - |
| 1.8811 | 2500 | 0.1083 | 0.1773 | 0.9933 (-0.0067) |
| 1.9564 | 2600 | 0.1203 | - | - |
| 2.0316 | 2700 | 0.0841 | - | - |
| 2.0692 | 2750 | - | 0.2898 | 0.9907 (-0.0093) |
| 2.1068 | 2800 | 0.0248 | - | - |
| 2.1821 | 2900 | 0.032 | - | - |
| 2.2573 | 3000 | 0.0468 | 0.2455 | 0.9915 (-0.0085) |
| 2.3326 | 3100 | 0.0497 | - | - |
| 2.4078 | 3200 | 0.0585 | - | - |
| 2.4454 | 3250 | - | 0.2142 | 0.9921 (-0.0079) |
| 2.4831 | 3300 | 0.0653 | - | - |
| 2.5583 | 3400 | 0.0701 | - | - |
| 2.6336 | 3500 | 0.0758 | 0.2034 | 0.9924 (-0.0076) |
| 2.7088 | 3600 | 0.0903 | - | - |
| 2.7840 | 3700 | 0.1037 | - | - |
| 2.8217 | 3750 | - | 0.1984 | 0.9927 (-0.0073) |
| 2.8593 | 3800 | 0.113 | - | - |
| 2.9345 | 3900 | 0.1199 | - | - |
| -1 | -1 | - | - | 0.9933 (-0.0067) |
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}