Compare commits

...

10 Commits

Author SHA1 Message Date
Nils Reimers 1c9dadfb1d Update README.md 2021-08-05 08:41:05 +00:00
nreimers b2b5013007 up 2021-06-21 11:42:20 +02:00
nreimers ced69de5b6 up 2021-06-21 11:41:16 +02:00
nreimers 23111f3256 up 2021-06-21 09:44:24 +02:00
nreimers 645f80079e up 2021-06-21 09:36:19 +02:00
nreimers 428b7726c5 up 2021-06-21 09:35:28 +02:00
nreimers 041642eb36 up 2021-06-21 09:34:46 +02:00
nreimers 1a7d51c9f1 Merge branch 'main' of https://huggingface.co/cross-encoder/nli-roberta-base into main 2021-06-21 09:25:11 +02:00
nreimers 2b4fd646c4 update 2021-06-21 09:24:49 +02:00
Patrick von Platen ee08f3bd7b upload flax model 2021-05-20 15:38:26 +00:00
2 changed files with 36 additions and 5 deletions

38
README.md Executable file → Normal file
View File

@ -1,16 +1,31 @@
# Cross-Encoder for Quora Duplicate Questions Detection
---
language: en
pipeline_tag: zero-shot-classification
tags:
- roberta-base
datasets:
- multi_nli
- snli
metrics:
- accuracy
license: apache-2.0
---
# Cross-Encoder for Natural Language Inference
This model was trained using [SentenceTransformers](https://sbert.net) [Cross-Encoder](https://www.sbert.net/examples/applications/cross-encoder/README.html) class.
## Training Data
The model was trained on the [SNLI](https://nlp.stanford.edu/projects/snli/) and [MultiNLI](https://cims.nyu.edu/~sbowman/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](https://www.sbert.net/docs/pretrained_cross-encoders.html#nli).
## Usage
Pre-trained models can be used like this:
```python
from sentence_transformers import CrossEncoder
model = CrossEncoder('model_name')
model = CrossEncoder('cross-encoder/nli-roberta-base')
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
@ -24,8 +39,8 @@ You can use the model also directly with Transformers library (without SentenceT
from transformers import AutoTokenizer, AutoModelForSequenceClassification
import torch
model = AutoModelForSequenceClassification.from_pretrained('model_name')
tokenizer = AutoTokenizer.from_pretrained('model_name')
model = AutoModelForSequenceClassification.from_pretrained('cross-encoder/nli-roberta-base')
tokenizer = AutoTokenizer.from_pretrained('cross-encoder/nli-roberta-base')
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")
@ -35,4 +50,17 @@ with torch.no_grad():
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:
```python
from transformers import pipeline
classifier = pipeline("zero-shot-classification", model='cross-encoder/nli-roberta-base')
sent = "Apple just announced the newest iPhone X"
candidate_labels = ["technology", "sports", "politics"]
res = classifier(sent, candidate_labels)
print(res)
```

BIN
flax_model.msgpack (Stored with Git LFS) Normal file

Binary file not shown.