Update README.md
This commit is contained in:
parent
d0c106c1ce
commit
7de8833e3f
|
@ -42,16 +42,21 @@ As of December 2021, mDeBERTa-base is the best performing multilingual transform
|
||||||
```python
|
```python
|
||||||
from transformers import AutoTokenizer, AutoModelForSequenceClassification
|
from transformers import AutoTokenizer, AutoModelForSequenceClassification
|
||||||
import torch
|
import torch
|
||||||
|
|
||||||
model_name = "MoritzLaurer/mDeBERTa-v3-base-mnli-xnli"
|
model_name = "MoritzLaurer/mDeBERTa-v3-base-mnli-xnli"
|
||||||
tokenizer = AutoTokenizer.from_pretrained(model_name)
|
tokenizer = AutoTokenizer.from_pretrained(model_name)
|
||||||
model = AutoModelForSequenceClassification.from_pretrained(model_name)
|
model = AutoModelForSequenceClassification.from_pretrained(model_name)
|
||||||
|
|
||||||
premise = "Angela Merkel ist eine Politikerin in Deutschland und Vorsitzende der CDU"
|
premise = "Angela Merkel ist eine Politikerin in Deutschland und Vorsitzende der CDU"
|
||||||
hypothesis = "Emmanuel Macron is the President of France"
|
hypothesis = "Emmanuel Macron is the President of France"
|
||||||
|
|
||||||
input = tokenizer(premise, hypothesis, truncation=True, return_tensors="pt")
|
input = tokenizer(premise, hypothesis, truncation=True, return_tensors="pt")
|
||||||
output = model(input["input_ids"].to(device)) # device = "cuda:0" or "cpu"
|
output = model(input["input_ids"].to(device)) # device = "cuda:0" or "cpu"
|
||||||
prediction = torch.softmax(output["logits"][0], -1).tolist()
|
prediction = torch.softmax(output["logits"][0], -1).tolist()
|
||||||
|
|
||||||
label_names = ["entailment", "neutral", "contradiction"]
|
label_names = ["entailment", "neutral", "contradiction"]
|
||||||
prediction = {name: round(float(pred) * 100, 1) for pred, name in zip(prediction, label_names)}
|
prediction = {name: round(float(pred) * 100, 1) for pred, name in zip(prediction, label_names)}
|
||||||
|
|
||||||
print(prediction)
|
print(prediction)
|
||||||
```
|
```
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue