CrossEncoder based on distilbert/distilroberta-base
This is a Cross Encoder model finetuned from distilbert/distilroberta-base on the all-nli dataset using the sentence-transformers library. It computes scores for pairs of texts, which can be used for text pair classification.
Model Details
Model Description
- Model Type: Cross Encoder
- Base model: distilbert/distilroberta-base
- Maximum Sequence Length: 512 tokens
- Number of Output Labels: 3 labels
- Supported Modality: Text
- Training Dataset:
- all-nli
Model Sources
- Documentation: Sentence Transformers Documentation
- Documentation: Cross Encoder Documentation
- Repository: Sentence Transformers on GitHub
- Hugging Face: Cross Encoders on Hugging Face
Full Model Architecture
CrossEncoder(
(0): Transformer({'transformer_task': 'sequence-classification', 'modality_config': {'text': {'method': 'forward', 'method_output_name': 'logits'}}, 'module_output_name': 'scores', 'architecture': 'RobertaForSequenceClassification'})
)
Usage
Direct Usage (Sentence Transformers)
First install the Sentence Transformers library:
pip install -U sentence-transformers
Then you can load this model and run inference.
from sentence_transformers import CrossEncoder
# Download from the 🤗 Hub
model = CrossEncoder("kwondw/reranker-distilroberta-base-nli")
# Get scores for pairs of inputs
pairs = [
['Two women are embracing while holding to go packages.', 'The sisters are hugging goodbye while holding to go packages after just eating lunch.'],
['Two women are embracing while holding to go packages.', 'Two woman are holding packages.'],
['Two women are embracing while holding to go packages.', 'The men are fighting outside a deli.'],
['Two young children in blue jerseys, one with the number 9 and one with the number 2 are standing on wooden steps in a bathroom and washing their hands in a sink.', 'Two kids in numbered jerseys wash their hands.'],
['Two young children in blue jerseys, one with the number 9 and one with the number 2 are standing on wooden steps in a bathroom and washing their hands in a sink.', 'Two kids at a ballgame wash their hands.'],
]
scores = model.predict(pairs)
print(scores)
# [[-2.6387 3.0625 -1.0605]
# [ 3.3965 -0.6968 -1.874 ]
# [-3.2012 -0.9272 3.6855]
# [ 2.3809 -1.0547 -0.6987]
# [-2.1973 1.748 0.0408]]
Evaluation
Metrics
Cross Encoder Classification
- Datasets:
ALLNLI-devandAllNLI-test - Evaluated with CrossEncoderClassificationEvaluator
| Metric | ALLNLI-dev | AllNLI-test |
|---|---|---|
| f1_macro | 0.8226 | 0.7575 |
| f1_micro | 0.824 | 0.7576 |
| f1_weighted | 0.8226 | 0.7583 |
Training Details
Training Dataset
all-nli
- Dataset: all-nli
- Size: 100,000 training samples
- Columns: premise, hypothesis, and label
- Approximate statistics based on the first 100 samples:
premise hypothesis label type string string int modality text text details min: 8 tokensmean: 23.12 tokensmax: 45 tokens min: 6 tokensmean: 11.24 tokensmax: 25 tokens 0: ~32.69%1: ~34.62%2: ~32.69% - Samples:
premise hypothesis label A person on a horse jumps over a broken down airplane. A person is training his horse for a competition. 1 A person on a horse jumps over a broken down airplane. A person is at a diner, ordering an omelette. 2 A person on a horse jumps over a broken down airplane. A person is outdoors, on a horse. 0 - Loss: CrossEntropyLoss
Evaluation Dataset
all-nli
- Dataset: all-nli
- Size: 1,000 evaluation samples
- Columns: premise, hypothesis, and label
- Approximate statistics based on the first 100 samples:
premise hypothesis label type string string int modality text text details min: 9 tokensmean: 19.64 tokensmax: 36 tokens min: 5 tokensmean: 10.2 tokensmax: 24 tokens 0: ~32.69%1: ~30.77%2: ~36.54% - Samples:
premise hypothesis label Two women are embracing while holding to go packages. The sisters are hugging goodbye while holding to go packages after just eating lunch. 1 Two women are embracing while holding to go packages. Two woman are holding packages. 0 Two women are embracing while holding to go packages. The men are fighting outside a deli. 2 - Loss: CrossEntropyLoss
Training Hyperparameters
Non-Default Hyperparameters
per_device_train_batch_size: 64per_device_eval_batch_size: 64num_train_epochs: 1warmup_steps: 0.1fp16: Trueddp_find_unused_parameters: False
All Hyperparameters
do_predict: Falseprediction_loss_only: Trueper_device_train_batch_size: 64per_device_eval_batch_size: 64gradient_accumulation_steps: 1eval_accumulation_steps: Nonetorch_empty_cache_steps: Nonelearning_rate: 5e-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: Nonewarmup_ratio: Nonewarmup_steps: 0.1log_level: passivelog_level_replica: warninglog_on_each_node: Truelogging_nan_inf_filter: Trueenable_jit_checkpoint: Falsesave_on_each_node: Falsesave_only_model: Falserestore_callback_states_from_checkpoint: Falseuse_cpu: Falseseed: 42data_seed: Nonebf16: Falsefp16: Truebf16_full_eval: Falsefp16_full_eval: Falsetf32: Nonelocal_rank: -1ddp_backend: Nonedebug: []dataloader_drop_last: Truedataloader_num_workers: 0dataloader_prefetch_factor: Nonedisable_tqdm: Falseremove_unused_columns: Truelabel_names: Noneload_best_model_at_end: Falseignore_data_skip: Falsefsdp: []fsdp_config: {'min_num_params': 0, 'xla': False, 'xla_fsdp_v2': False, 'xla_fsdp_grad_ckpt': False}accelerator_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: Nonegroup_by_length: Falselength_column_name: lengthproject: huggingfacetrackio_space_id: trackioddp_find_unused_parameters: Falseddp_bucket_cap_mb: Noneddp_broadcast_buffers: Falsedataloader_pin_memory: Truedataloader_persistent_workers: Falseskip_memory_metrics: Truepush_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_for_metrics: []eval_do_concat_batches: Trueauto_find_batch_size: Falsefull_determinism: Falseddp_timeout: 1800torch_compile: Falsetorch_compile_backend: Nonetorch_compile_mode: Noneinclude_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: Trueuse_cache: Falseprompts: Nonebatch_sampler: batch_samplermulti_dataset_batch_sampler: proportionalrouter_mapping: {}learning_rate_mapping: {}
Training Logs
| Epoch | Step | Training Loss | Validation Loss | ALLNLI-dev_f1_macro | AllNLI-test_f1_macro |
|---|---|---|---|---|---|
| -1 | -1 | - | - | 0.1658 | - |
| 0.1280 | 100 | 0.9521 | - | - | - |
| 0.2561 | 200 | 0.6069 | - | - | - |
| 0.3841 | 300 | 0.5517 | - | - | - |
| 0.5122 | 400 | 0.5313 | - | - | - |
| 0.6402 | 500 | 0.5126 | 0.3908 | 0.8226 | - |
| 0.7682 | 600 | 0.4918 | - | - | - |
| 0.8963 | 700 | 0.4655 | - | - | - |
| -1 | -1 | - | - | - | 0.7575 |
Training Time
- Training: 2.2 minutes
- Evaluation: 0.6 seconds
- Total: 2.2 minutes
Framework Versions
- Python: 3.12.13
- Sentence Transformers: 6.0.1
- Transformers: 5.0.0
- PyTorch: 2.10.0+cu128
- Accelerate: 1.13.0
- Datasets: 5.0.0
- Tokenizers: 0.22.2
Additional Resources
- Training and Finetuning Reranker Models with Sentence Transformers: the end-to-end guide for training or finetuning Cross Encoder (reranker) models.
- Multimodal Embedding & Reranker Models with Sentence Transformers: use text, image, audio, and video reranker models through the same API.
- Training and Finetuning Multimodal Embedding & Reranker Models with Sentence Transformers: training multimodal Cross Encoders.
Citation
BibTeX
Sentence Transformers
@inproceedings{reimers-2019-sentence-bert,
title = "Sentence-BERT: Sentence Embeddings using Siamese BERT-Networks",
author = "Reimers, Nils and Gurevych, Iryna",
booktitle = "Proceedings of the 2019 Conference on Empirical Methods in Natural Language Processing",
month = "11",
year = "2019",
publisher = "Association for Computational Linguistics",
url = "https://arxiv.org/abs/1908.10084",
}