Views
No views yet
1#!pip install transformers[sentencepiece]
2from transformers import pipeline
3classifier = pipeline("zero-shot-classification", model="MoritzLaurer/DeBERTa-v3-base-mnli-fever-anli")
4sequence_to_classify = "Angela Merkel is a politician in Germany and leader of the CDU"
5candidate_labels = ["politics", "economy", "entertainment", "environment"]
6output = classifier(sequence_to_classify, candidate_labels, multi_label=False)
7print(output)1from transformers import AutoTokenizer, AutoModelForSequenceClassification
2import torch
3device = torch.device("cuda") if torch.cuda.is_available() else torch.device("cpu")
4
5model_name = "MoritzLaurer/DeBERTa-v3-base-mnli-fever-anli"
6tokenizer = AutoTokenizer.from_pretrained(model_name)
7model = AutoModelForSequenceClassification.from_pretrained(model_name)
8
9premise = "I first thought that I liked the movie, but upon second thought it was actually disappointing."
10hypothesis = "The movie was good."
11
12input = tokenizer(premise, hypothesis, truncation=True, return_tensors="pt")
13output = model(input["input_ids"].to(device)) # device = "cuda:0" or "cpu"
14prediction = torch.softmax(output["logits"][0], -1).tolist()
15label_names = ["entailment", "neutral", "contradiction"]
16prediction = {name: round(float(pred) * 100, 1) for pred, name in zip(prediction, label_names)}
17print(prediction)training_args = TrainingArguments(
num_train_epochs=3, # total number of training epochs
learning_rate=2e-05,
per_device_train_batch_size=32, # batch size per device during training
per_device_eval_batch_size=32, # batch size for evaluation
warmup_ratio=0.1, # number of warmup steps for learning rate scheduler
weight_decay=0.06, # strength of weight decay
fp16=True # mixed precision training
)| mnli-m | mnli-mm | fever-nli | anli-all | anli-r3 |
|---|---|---|---|---|
| 0.903 | 0.903 | 0.777 | 0.579 | 0.495 |
pip install transformers[sentencepiece] or pip install sentencepiece| 20_newsgroup | ag_news | amazon_reviews_multi | anli | boolq | cb | cola | copa | dbpedia | esnli | financial_phrasebank | imdb | isear | mnli | mrpc | multirc | poem_sentiment | qnli | qqp | rotten_tomatoes | rte | sst2 | sst_5bins | stsb | trec_coarse | trec_fine | tweet_ev_emoji | tweet_ev_emotion | tweet_ev_hate | tweet_ev_irony | tweet_ev_offensive | tweet_ev_sentiment | wic | wnli | wsc | yahoo_answers |
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| 85.8072 | 90.4333 | 67.32 | 59.625 | 85.107 | 91.0714 | 85.8102 | 67 | 79.0333 | 91.6327 | 82.5 | 94.02 | 71.6428 | 89.5749 | 89.7059 | 64.1708 | 88.4615 | 93.575 | 91.4148 | 89.6811 | 86.2816 | 94.6101 | 57.0588 | 91.5508 | 97.6 | 91.2 | 45.264 | 82.6179 | 54.5455 | 74.3622 | 84.8837 | 71.6949 | 71.0031 | 69.0141 | 68.2692 | 71.3333 |