Views
No views yet
CrossEncoder(
(0): Transformer({'transformer_task': 'sequence-classification', 'modality_config': {'text': {'method': 'forward', 'method_output_name': 'logits'}}, 'module_output_name': 'scores', 'architecture': 'BertForSequenceClassification'})
)pip install -U sentence-transformers1from sentence_transformers import CrossEncoder
2
3# Download from the 🤗 Hub
4model = CrossEncoder("cross_encoder_model_id")
5# Get scores for pairs of inputs
6pairs = [
7 ['skill: manage health care staff', 'skill: manage healthcare staff'],
8 ['skill: manage health care staff', 'skill: manage staff'],
9 ['skill: manage health care staff', 'skill: manage physiotherapy staff'],
10 ['skill: manage health care staff', 'skill: work with nursing staff'],
11 ['skill: manage health care staff', 'skill: manage chiropractic staff'],
12]
13scores = model.predict(pairs)
14print(scores)
15# [ 7.403 3.9133 0.9482 -2.4038 -3.8219]
16
17# Or rank different texts based on similarity to a single text
18ranks = model.rank(
19 'skill: manage health care staff',
20 [
21 'skill: manage healthcare staff',
22 'skill: manage staff',
23 'skill: manage physiotherapy staff',
24 'skill: work with nursing staff',
25 'skill: manage chiropractic staff',
26 ]
27)
28# [{'corpus_id': ..., 'score': ...}, {'corpus_id': ..., 'score': ...}, ...]sentence_A, sentence_B, and label| sentence_A | sentence_B | label | |
|---|---|---|---|
| type | string | string | float |
| modality | text | text | |
| details |
|
|
|
| sentence_A | sentence_B | label |
|---|---|---|
skill: manage security systems | skill: manage technical security systems | 1.0 |
skill: manage security systems | skill: Physical access management software | 0.0 |
skill: manage security systems | skill: manage theft prevention | 0.0 |
BinaryCrossEntropyLoss with these parameters:
1{
2 "activation_fn": "torch.nn.modules.linear.Identity",
3 "pos_weight": null
4}sentence_A, sentence_B, and label| sentence_A | sentence_B | label | |
|---|---|---|---|
| type | string | string | float |
| modality | text | text | |
| details |
|
|
|
| sentence_A | sentence_B | label |
|---|---|---|
skill: manage health care staff | skill: manage healthcare staff | 1.0 |
skill: manage health care staff | skill: manage staff | 0.0 |
skill: manage health care staff | skill: manage physiotherapy staff | 0.0 |
BinaryCrossEntropyLoss with these parameters:
1{
2 "activation_fn": "torch.nn.modules.linear.Identity",
3 "pos_weight": null
4}per_device_train_batch_size: 32num_train_epochs: 2learning_rate: 2e-05warmup_steps: 0.1per_device_eval_batch_size: 64load_best_model_at_end: Trueper_device_train_batch_size: 32num_train_epochs: 2max_steps: -1learning_rate: 2e-05lr_scheduler_type: linearlr_scheduler_kwargs: Nonewarmup_steps: 0.1optim: adamw_torch_fusedoptim_args: Noneweight_decay: 0.0adam_beta1: 0.9adam_beta2: 0.999adam_epsilon: 1e-08optim_target_modules: Nonegradient_accumulation_steps: 1average_tokens_across_devices: Truemax_grad_norm: 1.0label_smoothing_factor: 0.0bf16: Falsefp16: Falsebf16_full_eval: Falsefp16_full_eval: Falsetf32: Nonegradient_checkpointing: Falsegradient_checkpointing_kwargs: Nonetorch_compile: Falsetorch_compile_backend: Nonetorch_compile_mode: Noneuse_liger_kernel: Falseliger_kernel_config: Noneuse_cache: Falseneftune_noise_alpha: Nonetorch_empty_cache_steps: Noneauto_find_batch_size: Falselog_on_each_node: Truelogging_nan_inf_filter: Trueinclude_num_input_tokens_seen: nolog_level: passivelog_level_replica: warningdisable_tqdm: Falseproject: huggingfacetrackio_space_id: Nonetrackio_bucket_id: Nonetrackio_static_space_id: Noneper_device_eval_batch_size: 64prediction_loss_only: Trueeval_on_start: Falseeval_do_concat_batches: Trueeval_use_gather_object: Falseeval_accumulation_steps: Noneinclude_for_metrics: []batch_eval_metrics: Falsesave_only_model: Falsesave_on_each_node: Falseenable_jit_checkpoint: Falsepush_to_hub: Falsehub_private_repo: Nonehub_model_id: Nonehub_strategy: every_savehub_always_push: Falsehub_revision: Noneload_best_model_at_end: Trueignore_data_skip: Falserestore_callback_states_from_checkpoint: Falsefull_determinism: Falseseed: 42data_seed: Noneuse_cpu: Falseaccelerator_config: {'split_batches': False, 'dispatch_batches': None, 'even_batches': True, 'use_seedable_sampler': True, 'non_blocking': False, 'gradient_accumulation_kwargs': None}parallelism_config: Nonedataloader_drop_last: Falsedataloader_num_workers: 0dataloader_pin_memory: Truedataloader_persistent_workers: Falsedataloader_prefetch_factor: Noneremove_unused_columns: Truelabel_names: Nonetrain_sampling_strategy: randomlength_column_name: lengthddp_find_unused_parameters: Noneddp_bucket_cap_mb: Noneddp_broadcast_buffers: Falseddp_static_graph: Noneddp_backend: Noneddp_timeout: 1800fsdp: []fsdp_config: {'min_num_params': 0, 'xla': False, 'xla_fsdp_v2': False, 'xla_fsdp_grad_ckpt': False}deepspeed: Nonedebug: []skip_memory_metrics: Truedo_predict: Falseresume_from_checkpoint: Nonewarmup_ratio: Nonelocal_rank: -1prompts: Nonebatch_sampler: batch_samplermulti_dataset_batch_sampler: proportionalrouter_mapping: {}learning_rate_mapping: {}| Epoch | Step | Training Loss | Validation Loss |
|---|---|---|---|
| 0.0103 | 20 | 0.4811 | - |
| 0.0205 | 40 | 0.4186 | - |
| 0.0308 | 60 | 0.3713 | - |
| 0.0411 | 80 | 0.4399 | - |
| 0.0513 | 100 | 0.3115 | - |
| 0.0616 | 120 | 0.3429 | - |
| 0.0719 | 140 | 0.3541 | - |
| 0.0821 | 160 | 0.3054 | - |
| 0.0924 | 180 | 0.2590 | - |
| 0.1027 | 200 | 0.2288 | - |
| 0.1129 | 220 | 0.2604 | - |
| 0.1232 | 240 | 0.2387 | - |
| 0.1335 | 260 | 0.2248 | - |
| 0.1437 | 280 | 0.2176 | - |
| 0.1540 | 300 | 0.2260 | - |
| 0.1643 | 320 | 0.2212 | - |
| 0.1745 | 340 | 0.1946 | - |
| 0.1848 | 360 | 0.1926 | - |
| 0.1951 | 380 | 0.2705 | - |
| 0.2053 | 400 | 0.1964 | - |
| 0.2156 | 420 | 0.2341 | - |
| 0.2259 | 440 | 0.3130 | - |
| 0.2361 | 460 | 0.2246 | - |
| 0.2464 | 480 | 0.2541 | - |
| 0.2567 | 500 | 0.2328 | - |
| 0.2669 | 520 | 0.1759 | - |
| 0.2772 | 540 | 0.2553 | - |
| 0.2875 | 560 | 0.2113 | - |
| 0.2977 | 580 | 0.1925 | - |
| 0.3080 | 600 | 0.2061 | - |
| 0.3183 | 620 | 0.2053 | - |
| 0.3285 | 640 | 0.1886 | - |
| 0.3388 | 660 | 0.2209 | - |
| 0.3491 | 680 | 0.1731 | - |
| 0.3593 | 700 | 0.2043 | - |
| 0.3696 | 720 | 0.1732 | - |
| 0.3799 | 740 | 0.1905 | - |
| 0.3901 | 760 | 0.1987 | - |
| 0.4004 | 780 | 0.2041 | - |
| 0.4107 | 800 | 0.1861 | - |
| 0.4209 | 820 | 0.1963 | - |
| 0.4312 | 840 | 0.2504 | - |
| 0.4415 | 860 | 0.1384 | - |
| 0.4517 | 880 | 0.1731 | - |
| 0.4620 | 900 | 0.2093 | - |
| 0.4723 | 920 | 0.1958 | - |
| 0.4825 | 940 | 0.1908 | - |
| 0.4928 | 960 | 0.1373 | - |
| 0.5031 | 980 | 0.1874 | - |
| 0.5133 | 1000 | 0.1905 | - |
| 0.5236 | 1020 | 0.1678 | - |
| 0.5339 | 1040 | 0.1669 | - |
| 0.5441 | 1060 | 0.1743 | - |
| 0.5544 | 1080 | 0.2382 | - |
| 0.5647 | 1100 | 0.1753 | - |
| 0.5749 | 1120 | 0.1357 | - |
| 0.5852 | 1140 | 0.1531 | - |
| 0.5955 | 1160 | 0.1768 | - |
| 0.6057 | 1180 | 0.1541 | - |
| 0.6160 | 1200 | 0.1734 | - |
| 0.6263 | 1220 | 0.1747 | - |
| 0.6366 | 1240 | 0.1619 | - |
| 0.6468 | 1260 | 0.1658 | - |
| 0.6571 | 1280 | 0.1491 | - |
| 0.6674 | 1300 | 0.1838 | - |
| 0.6776 | 1320 | 0.1480 | - |
| 0.6879 | 1340 | 0.2149 | - |
| 0.6982 | 1360 | 0.1989 | - |
| 0.7084 | 1380 | 0.1488 | - |
| 0.7187 | 1400 | 0.1604 | - |
| 0.7290 | 1420 | 0.1450 | - |
| 0.7392 | 1440 | 0.1516 | - |
| 0.7495 | 1460 | 0.1387 | - |
| 0.7598 | 1480 | 0.1702 | - |
| 0.7700 | 1500 | 0.1389 | - |
| 0.7803 | 1520 | 0.1544 | - |
| 0.7906 | 1540 | 0.1408 | - |
| 0.8008 | 1560 | 0.1472 | - |
| 0.8111 | 1580 | 0.1578 | - |
| 0.8214 | 1600 | 0.1756 | - |
| 0.8316 | 1620 | 0.1655 | - |
| 0.8419 | 1640 | 0.1523 | - |
| 0.8522 | 1660 | 0.1431 | - |
| 0.8624 | 1680 | 0.1922 | - |
| 0.8727 | 1700 | 0.1619 | - |
| 0.8830 | 1720 | 0.1778 | - |
| 0.8932 | 1740 | 0.1891 | - |
| 0.9035 | 1760 | 0.1858 | - |
| 0.9138 | 1780 | 0.1597 | - |
| 0.9240 | 1800 | 0.1609 | - |
| 0.9343 | 1820 | 0.1330 | - |
| 0.9446 | 1840 | 0.1735 | - |
| 0.9548 | 1860 | 0.1859 | - |
| 0.9651 | 1880 | 0.1486 | - |
| 0.9754 | 1900 | 0.1113 | - |
| 0.9856 | 1920 | 0.1812 | - |
| 0.9959 | 1940 | 0.1076 | - |
| 1.0 | 1948 | - | 0.2882 |
| 1.0062 | 1960 | 0.1339 | - |
| 1.0164 | 1980 | 0.1221 | - |
| 1.0267 | 2000 | 0.1282 | - |
| 1.0370 | 2020 | 0.1004 | - |
| 1.0472 | 2040 | 0.1151 | - |
| 1.0575 | 2060 | 0.1477 | - |
| 1.0678 | 2080 | 0.1306 | - |
| 1.0780 | 2100 | 0.1328 | - |
| 1.0883 | 2120 | 0.1676 | - |
| 1.0986 | 2140 | 0.1171 | - |
| 1.1088 | 2160 | 0.1300 | - |
| 1.1191 | 2180 | 0.1291 | - |
| 1.1294 | 2200 | 0.1282 | - |
| 1.1396 | 2220 | 0.1393 | - |
| 1.1499 | 2240 | 0.1019 | - |
| 1.1602 | 2260 | 0.1536 | - |
| 1.1704 | 2280 | 0.1487 | - |
| 1.1807 | 2300 | 0.0985 | - |
| 1.1910 | 2320 | 0.1407 | - |
| 1.2012 | 2340 | 0.1455 | - |
| 1.2115 | 2360 | 0.1396 | - |
| 1.2218 | 2380 | 0.1301 | - |
| 1.2320 | 2400 | 0.1315 | - |
| 1.2423 | 2420 | 0.1156 | - |
| 1.2526 | 2440 | 0.1522 | - |
| 1.2628 | 2460 | 0.1360 | - |
| 1.2731 | 2480 | 0.1219 | - |
| 1.2834 | 2500 | 0.1306 | - |
| 1.2936 | 2520 | 0.1129 | - |
| 1.3039 | 2540 | 0.1561 | - |
| 1.3142 | 2560 | 0.1061 | - |
| 1.3244 | 2580 | 0.0967 | - |
| 1.3347 | 2600 | 0.0994 | - |
| 1.3450 | 2620 | 0.1115 | - |
| 1.3552 | 2640 | 0.1141 | - |
| 1.3655 | 2660 | 0.1325 | - |
| 1.3758 | 2680 | 0.1174 | - |
| 1.3860 | 2700 | 0.0973 | - |
| 1.3963 | 2720 | 0.1415 | - |
| 1.4066 | 2740 | 0.1691 | - |
| 1.4168 | 2760 | 0.1166 | - |
| 1.4271 | 2780 | 0.1349 | - |
| 1.4374 | 2800 | 0.1228 | - |
| 1.4476 | 2820 | 0.0988 | - |
| 1.4579 | 2840 | 0.1239 | - |
| 1.4682 | 2860 | 0.1255 | - |
| 1.4784 | 2880 | 0.1151 | - |
| 1.4887 | 2900 | 0.0715 | - |
| 1.4990 | 2920 | 0.1206 | - |
| 1.5092 | 2940 | 0.1042 | - |
| 1.5195 | 2960 | 0.1194 | - |
| 1.5298 | 2980 | 0.0994 | - |
| 1.5400 | 3000 | 0.1479 | - |
| 1.5503 | 3020 | 0.1188 | - |
| 1.5606 | 3040 | 0.1463 | - |
| 1.5708 | 3060 | 0.1245 | - |
| 1.5811 | 3080 | 0.1013 | - |
| 1.5914 | 3100 | 0.0991 | - |
| 1.6016 | 3120 | 0.0989 | - |
| 1.6119 | 3140 | 0.1648 | - |
| 1.6222 | 3160 | 0.1098 | - |
| 1.6324 | 3180 | 0.0953 | - |
| 1.6427 | 3200 | 0.1601 | - |
| 1.6530 | 3220 | 0.1237 | - |
| 1.6632 | 3240 | 0.1820 | - |
| 1.6735 | 3260 | 0.1152 | - |
| 1.6838 | 3280 | 0.1195 | - |
| 1.6940 | 3300 | 0.0973 | - |
| 1.7043 | 3320 | 0.0914 | - |
| 1.7146 | 3340 | 0.1002 | - |
| 1.7248 | 3360 | 0.1709 | - |
| 1.7351 | 3380 | 0.1032 | - |
| 1.7454 | 3400 | 0.1132 | - |
| 1.7556 | 3420 | 0.1182 | - |
| 1.7659 | 3440 | 0.1193 | - |
| 1.7762 | 3460 | 0.1011 | - |
| 1.7864 | 3480 | 0.1343 | - |
| 1.7967 | 3500 | 0.1555 | - |
| 1.8070 | 3520 | 0.1558 | - |
| 1.8172 | 3540 | 0.0966 | - |
| 1.8275 | 3560 | 0.1053 | - |
| 1.8378 | 3580 | 0.1604 | - |
| 1.8480 | 3600 | 0.1547 | - |
| 1.8583 | 3620 | 0.1147 | - |
| 1.8686 | 3640 | 0.1026 | - |
| 1.8789 | 3660 | 0.1250 | - |
| 1.8891 | 3680 | 0.1431 | - |
| 1.8994 | 3700 | 0.1058 | - |
| 1.9097 | 3720 | 0.1016 | - |
| 1.9199 | 3740 | 0.1298 | - |
| 1.9302 | 3760 | 0.1082 | - |
| 1.9405 | 3780 | 0.1271 | - |
| 1.9507 | 3800 | 0.0844 | - |
| 1.9610 | 3820 | 0.1266 | - |
| 1.9713 | 3840 | 0.1311 | - |
| 1.9815 | 3860 | 0.0937 | - |
| 1.9918 | 3880 | 0.0833 | - |
| 2.0 | 3896 | - | 0.3104 |
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}