cross-encoder/nli-MiniLM2-L6-H768
apache-2.0 24/24 files local @ b95119ce93d3
HF_ENDPOINT=https://huffingface.co \
python -c "from huggingface_hub import snapshot_download; snapshot_download('cross-encoder/nli-MiniLM2-L6-H768')"Model card
Cross-Encoder for Natural Language Inference
This model was trained using SentenceTransformers Cross-Encoder class.
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
For evaluation results, see SBERT.net - Pretrained Cross-Encoder.
Usage
Pre-trained models can be used like this:
from sentence_transformers import CrossEncoder
model = CrossEncoder('cross-encoder/nli-MiniLM2-L6-H768')
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.')])
#Convert scores to labels
label_mapping = ['contradiction', 'entailment', 'neutral']
labels = [label_mapping[score_max] for score_max in scores.argmax(axis=1)]
Usage with Transformers AutoModel
You can use the model also directly with Transformers library (without SentenceTransformers library):
from transformers import AutoTokenizer, AutoModelForSequenceClassification
import torch
model = AutoModelForSequenceClassification.from_pretrained('cross-encoder/nli-MiniLM2-L6-H768')
tokenizer = AutoTokenizer.from_pretrained('cross-encoder/nli-MiniLM2-L6-H768')
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
This model can also be used for zero-shot-classification:
from transformers import pipeline
classifier = pipeline("zero-shot-classification", model='cross-encoder/nli-MiniLM2-L6-H768')
sent = "Apple just announced the newest iPhone X"
candidate_labels = ["technology", "sports", "politics"]
res = classifier(sent, candidate_labels)
print(res)
Files
| File | Size | Status |
|---|---|---|
| .gitattributes | 1 kB | huffed |
| CESoftmaxAccuracyEvaluator_AllNLI-dev_results.csv | 0 kB | huffed |
| README.md | 3 kB | huffed |
| config.json | 1 kB | huffed |
| merges.txt | 456 kB | huffed |
| model.safetensors | 328.5 MB | huffed |
| onnx/model.onnx | 328.6 MB | huffed |
| onnx/model_O1.onnx | 328.6 MB | huffed |
| onnx/model_O2.onnx | 328.5 MB | huffed |
| onnx/model_O3.onnx | 328.5 MB | huffed |
| onnx/model_O4.onnx | 164.3 MB | huffed |
| onnx/model_qint8_arm64.onnx | 82.8 MB | huffed |
| onnx/model_qint8_avx512.onnx | 82.8 MB | huffed |
| onnx/model_qint8_avx512_vnni.onnx | 82.8 MB | huffed |
| onnx/model_quint8_avx2.onnx | 82.8 MB | huffed |
| openvino/openvino_model.bin | 328.5 MB | huffed |
| openvino/openvino_model.xml | 212 kB | huffed |
| openvino/openvino_model_qint8_quantized.bin | 82.8 MB | huffed |
| openvino/openvino_model_qint8_quantized.xml | 378 kB | huffed |
| pytorch_model.bin | 328.5 MB | huffed |
| special_tokens_map.json | 0 kB | huffed |
| tokenizer.json | 1.4 MB | huffed |
| tokenizer_config.json | 0 kB | huffed |
| vocab.json | 798 kB | huffed |