đ Cross-Encoder for Natural Language Inference
This model is designed for natural language inference tasks, leveraging the power of cross-encoders to provide accurate classification results.
đ Quick Start
This model was trained using SentenceTransformers Cross-Encoder class. It is based on microsoft/deberta-v3-large.
⨠Features
- Trained on Multiple Datasets: The model was trained on the SNLI and MultiNLI datasets. For a given sentence pair, it outputs three scores corresponding to the labels: contradiction, entailment, neutral.
- High Performance:
- Accuracy on SNLI - test dataset: 92.20
- Accuracy on MNLI mismatched set: 90.49
- Versatile Usage: Can be used for natural language inference and zero - shot classification tasks.
đĻ Installation
No specific installation steps are provided in the original document, so this section is skipped.
đģ Usage Examples
Basic Usage
from sentence_transformers import CrossEncoder
model = CrossEncoder('cross-encoder/nli-deberta-v3-large')
scores = model.predict([('A man is eating pizza', 'A man eats something'), ('A black race car starts up in front of a crowd of people.', 'A man is driving down a lonely road.')])
label_mapping = ['contradiction', 'entailment', 'neutral']
labels = [label_mapping[score_max] for score_max in scores.argmax(axis=1)]
Advanced Usage
Usage with Transformers AutoModel
from transformers import AutoTokenizer, AutoModelForSequenceClassification
import torch
model = AutoModelForSequenceClassification.from_pretrained('cross-encoder/nli-deberta-v3-large')
tokenizer = AutoTokenizer.from_pretrained('cross-encoder/nli-deberta-v3-large')
features = tokenizer(['A man is eating pizza', 'A black race car starts up in front of a crowd of people.'], ['A man eats something', 'A man is driving down a lonely road.'], padding=True, truncation=True, return_tensors="pt")
model.eval()
with torch.no_grad():
scores = model(**features).logits
label_mapping = ['contradiction', 'entailment', 'neutral']
labels = [label_mapping[score_max] for score_max in scores.argmax(dim=1)]
print(labels)
Zero - Shot Classification
from transformers import pipeline
classifier = pipeline("zero-shot-classification", model='cross-encoder/nli-deberta-v3-large')
sent = "Apple just announced the newest iPhone X"
candidate_labels = ["technology", "sports", "politics"]
res = classifier(sent, candidate_labels)
print(res)
đ Documentation
Training Data
The model was trained on the SNLI and MultiNLI datasets. For a given sentence pair, it will output three scores corresponding to the labels: contradiction, entailment, neutral.
Performance
- Accuracy on SNLI - test dataset: 92.20
- Accuracy on MNLI mismatched set: 90.49
For further evaluation results, see SBERT.net - Pretrained Cross - Encoder.
đ License
This model is licensed under the apache - 2.0 license.
Property |
Details |
Pipeline Tag |
zero - shot - classification |
Tags |
transformers |
Datasets |
nyu - mll/multi_nli, stanfordnlp/snli |
Metrics |
accuracy |
License |
apache - 2.0 |
Base Model |
microsoft/deberta - v3 - large |
Library Name |
sentence - transformers |