Views
No views yet
pip install -U sentence-transformers1from sentence_transformers import CrossEncoder
2
3# Download from the 🤗 Hub
4model = CrossEncoder("pujithapsx/finetune_bge_reranker_v2_m3_4114_3103")
5# Get scores for pairs of texts
6pairs = [
7 ['flat 9 silver arc towers lucknow', 'flat no 9 silver arc tower lucknow'],
8 ['house no 3 village mandapeta east godavari', 'h no 3 mandapeta village east godavari'],
9 ['flat 6 next to hospital indore', 'flat no 6 nxt to hospital indore'],
10 ['house no 36 village muzaffarpur bihar', 'h no 36 muzaffarpur village bihar'],
11 ['flat 10 shanti colony cross 2 kharagpur', 'flat 10 shanti clny cr 2 kharagpur'],
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 'flat 9 silver arc towers lucknow',
20 [
21 'flat no 9 silver arc tower lucknow',
22 'h no 3 mandapeta village east godavari',
23 'flat no 6 nxt to hospital indore',
24 'h no 36 muzaffarpur village bihar',
25 'flat 10 shanti clny cr 2 kharagpur',
26 ]
27)
28# [{'corpus_id': ..., 'score': ...}, {'corpus_id': ..., 'score': ...}, ...]entity-matching-evalCrossEncoderClassificationEvaluator| Metric | Value |
|---|---|
| accuracy | 0.9951 |
| accuracy_threshold | 0.9945 |
| f1 | 0.9958 |
| f1_threshold | 0.9945 |
| precision | 0.9958 |
| recall | 0.9958 |
| average_precision | 0.9999 |
sentence1, sentence2, and label| sentence1 | sentence2 | label | |
|---|---|---|---|
| type | string | string | int |
| details |
|
|
|
| sentence1 | sentence2 | label |
|---|---|---|
pamulaparti venkata subba rao | v s rao p | 1 |
c/o danish khan 18-7-335/190 aman nag kulsum msjd yktpura nr somnath tmpl | c/o danish khan 18-7-335/190 aman nagar kulsum masjid yakutpura near somnath temple | 1 |
balakrishna | bala krishna | 1 |
BinaryCrossEntropyLoss with these parameters:
1{
2 "activation_fn": "torch.nn.modules.linear.Identity",
3 "pos_weight": null
4}sentence1, sentence2, and label| sentence1 | sentence2 | label | |
|---|---|---|---|
| type | string | string | int |
| details |
|
|
|
| sentence1 | sentence2 | label |
|---|---|---|
flat 9 silver arc towers lucknow | flat no 9 silver arc tower lucknow | 1 |
house no 3 village mandapeta east godavari | h no 3 mandapeta village east godavari | 1 |
flat 6 next to hospital indore | flat no 6 nxt to hospital indore | 1 |
BinaryCrossEntropyLoss with these parameters:
1{
2 "activation_fn": "torch.nn.modules.linear.Identity",
3 "pos_weight": null
4}eval_strategy: stepsper_device_eval_batch_size: 16learning_rate: 2e-05weight_decay: 0.01warmup_steps: 107remove_unused_columns: Falseload_best_model_at_end: Trueoverwrite_output_dir: Falsedo_predict: Falseeval_strategy: stepsprediction_loss_only: Trueper_device_train_batch_size: 8per_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.01adam_beta1: 0.9adam_beta2: 0.999adam_epsilon: 1e-08max_grad_norm: 1.0num_train_epochs: 3max_steps: -1lr_scheduler_type: linearlr_scheduler_kwargs: Nonewarmup_ratio: 0.0warmup_steps: 107log_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: Falsefp16: 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: Falselabel_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 | Validation Loss | entity-matching-eval_average_precision |
|---|---|---|---|---|
| 0.1472 | 53 | 0.4704 | - | - |
| 0.2944 | 106 | 0.2525 | - | - |
| 0.2972 | 107 | - | 0.1369 | 0.9971 |
| 0.4417 | 159 | 0.2747 | - | - |
| 0.5889 | 212 | 0.2187 | - | - |
| 0.5944 | 214 | - | 0.1651 | 0.9957 |
| 0.7361 | 265 | 0.1826 | - | - |
| 0.8833 | 318 | 0.1177 | - | - |
| 0.8917 | 321 | - | 0.0572 | 0.9995 |
| 1.0306 | 371 | 0.0885 | - | - |
| 1.1778 | 424 | 0.128 | - | - |
| 1.1889 | 428 | - | 0.0160 | 0.9999 |
| 1.325 | 477 | 0.0376 | - | - |
| 1.4722 | 530 | 0.0528 | - | - |
| 1.4861 | 535 | - | 0.0526 | 0.9998 |
| 1.6194 | 583 | 0.0202 | - | - |
| 1.7667 | 636 | 0.0664 | - | - |
| 1.7833 | 642 | - | 0.0276 | 0.9999 |
| 1.9139 | 689 | 0.0186 | - | - |
| 2.0611 | 742 | 0.0363 | - | - |
| 2.0806 | 749 | - | 0.0299 | 0.9999 |
| 2.2083 | 795 | 0.0002 | - | - |
| 2.3556 | 848 | 0.0405 | - | - |
| 2.3778 | 856 | - | 0.0508 | 0.9999 |
| 2.5028 | 901 | 0.0246 | - | - |
| 2.65 | 954 | 0.0177 | - | - |
| 2.675 | 963 | - | 0.0424 | 0.9999 |
| 2.7972 | 1007 | 0.0064 | - | - |
| 2.9444 | 1060 | 0.0246 | - | - |
| 2.9722 | 1070 | - | 0.0501 | 0.9999 |
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}