Zero-Shot Classification
sentence-transformers
PyTorch
JAX
ONNX
Safetensors
OpenVINO
Transformers
English
roberta
text-classification
Instructions to use cross-encoder/nli-roberta-base with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- sentence-transformers
How to use cross-encoder/nli-roberta-base with sentence-transformers:
from sentence_transformers import SentenceTransformer model = SentenceTransformer("cross-encoder/nli-roberta-base") sentences = [ "The weather is lovely today.", "It's so sunny outside!", "He drove to the stadium." ] embeddings = model.encode(sentences) similarities = model.similarity(embeddings, embeddings) print(similarities.shape) # [3, 3] - Transformers
How to use cross-encoder/nli-roberta-base with Transformers:
# Use a pipeline as a high-level helper from transformers import pipeline pipe = pipeline("zero-shot-classification", model="cross-encoder/nli-roberta-base")# Load model directly from transformers import AutoTokenizer, AutoModelForSequenceClassification tokenizer = AutoTokenizer.from_pretrained("cross-encoder/nli-roberta-base") model = AutoModelForSequenceClassification.from_pretrained("cross-encoder/nli-roberta-base") - Notebooks
- Google Colab
- Kaggle
nreimers commited on
Commit ·
b2b5013
1
Parent(s): ced69de
up
Browse files
README.md
CHANGED
|
@@ -24,7 +24,7 @@ For evaluation results, see [SBERT.net - Pretrained Cross-Encoder](https://www.s
|
|
| 24 |
Pre-trained models can be used like this:
|
| 25 |
```python
|
| 26 |
from sentence_transformers import CrossEncoder
|
| 27 |
-
model = CrossEncoder('
|
| 28 |
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.')])
|
| 29 |
|
| 30 |
#Convert scores to labels
|
|
@@ -38,8 +38,8 @@ You can use the model also directly with Transformers library (without SentenceT
|
|
| 38 |
from transformers import AutoTokenizer, AutoModelForSequenceClassification
|
| 39 |
import torch
|
| 40 |
|
| 41 |
-
model = AutoModelForSequenceClassification.from_pretrained('
|
| 42 |
-
tokenizer = AutoTokenizer.from_pretrained('
|
| 43 |
|
| 44 |
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")
|
| 45 |
|
|
@@ -53,7 +53,7 @@ with torch.no_grad():
|
|
| 53 |
|
| 54 |
## Zero-Shot Classification
|
| 55 |
This model can also be used for zero-shot-classification:
|
| 56 |
-
```
|
| 57 |
from transformers import pipeline
|
| 58 |
|
| 59 |
classifier = pipeline("zero-shot-classification", model='cross-encoder/nli-roberta-base')
|
|
|
|
| 24 |
Pre-trained models can be used like this:
|
| 25 |
```python
|
| 26 |
from sentence_transformers import CrossEncoder
|
| 27 |
+
model = CrossEncoder('cross-encoder/nli-roberta-base')
|
| 28 |
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.')])
|
| 29 |
|
| 30 |
#Convert scores to labels
|
|
|
|
| 38 |
from transformers import AutoTokenizer, AutoModelForSequenceClassification
|
| 39 |
import torch
|
| 40 |
|
| 41 |
+
model = AutoModelForSequenceClassification.from_pretrained('cross-encoder/nli-roberta-base')
|
| 42 |
+
tokenizer = AutoTokenizer.from_pretrained('cross-encoder/nli-roberta-base')
|
| 43 |
|
| 44 |
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")
|
| 45 |
|
|
|
|
| 53 |
|
| 54 |
## Zero-Shot Classification
|
| 55 |
This model can also be used for zero-shot-classification:
|
| 56 |
+
```python
|
| 57 |
from transformers import pipeline
|
| 58 |
|
| 59 |
classifier = pipeline("zero-shot-classification", model='cross-encoder/nli-roberta-base')
|