wisalkhanmv commited on
Commit
40691ba
·
verified ·
1 Parent(s): 9644a9c

Update README.md

Browse files
Files changed (1) hide show
  1. README.md +79 -3
README.md CHANGED
@@ -1,3 +1,79 @@
1
- ---
2
- license: apache-2.0
3
- ---
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ ---
2
+ license: apache-2.0
3
+ language:
4
+ - en
5
+ library_name: bertopic
6
+ tags:
7
+ - topic-sentiment
8
+ ---
9
+
10
+ ## DeBERTa-v3-large-mnli-fever-anli-ling-wanli
11
+
12
+ Model description
13
+ This model was fine-tuned on the MultiNLI, Fever-NLI, Adversarial-NLI (ANLI), LingNLI and WANLI datasets, which comprise 885 242 NLI hypothesis-premise pairs. This model is the best performing NLI model on the Hugging Face Hub as of 06.06.22 and can be used for zero-shot classification. It significantly outperforms all other large models on the ANLI benchmark.
14
+
15
+ The foundation model is DeBERTa-v3-large from Microsoft. DeBERTa-v3 combines several recent innovations compared to classical Masked Language Models like BERT, RoBERTa etc., see the paper
16
+
17
+ How to use the model
18
+ Simple zero-shot classification pipeline
19
+ from transformers import pipeline
20
+ classifier = pipeline("zero-shot-classification", model="MoritzLaurer/DeBERTa-v3-large-mnli-fever-anli-ling-wanli")
21
+ sequence_to_classify = "Angela Merkel is a politician in Germany and leader of the CDU"
22
+ candidate_labels = ["politics", "economy", "entertainment", "environment"]
23
+ output = classifier(sequence_to_classify, candidate_labels, multi_label=False)
24
+ print(output)
25
+
26
+ NLI use-case
27
+ from transformers import AutoTokenizer, AutoModelForSequenceClassification
28
+ import torch
29
+ device = torch.device("cuda") if torch.cuda.is_available() else torch.device("cpu")
30
+
31
+ model_name = "MoritzLaurer/DeBERTa-v3-large-mnli-fever-anli-ling-wanli"
32
+ tokenizer = AutoTokenizer.from_pretrained(model_name)
33
+ model = AutoModelForSequenceClassification.from_pretrained(model_name)
34
+
35
+ premise = "I first thought that I liked the movie, but upon second thought it was actually disappointing."
36
+ hypothesis = "The movie was not good."
37
+
38
+ input = tokenizer(premise, hypothesis, truncation=True, return_tensors="pt")
39
+ output = model(input["input_ids"].to(device)) # device = "cuda:0" or "cpu"
40
+ prediction = torch.softmax(output["logits"][0], -1).tolist()
41
+ label_names = ["entailment", "neutral", "contradiction"]
42
+ prediction = {name: round(float(pred) * 100, 1) for pred, name in zip(prediction, label_names)}
43
+ print(prediction)
44
+
45
+ Training data
46
+ DeBERTa-v3-large-mnli-fever-anli-ling-wanli was trained on the MultiNLI, Fever-NLI, Adversarial-NLI (ANLI), LingNLI and WANLI datasets, which comprise 885 242 NLI hypothesis-premise pairs. Note that SNLI was explicitly excluded due to quality issues with the dataset. More data does not necessarily make for better NLI models.
47
+
48
+ Training procedure
49
+ DeBERTa-v3-large-mnli-fever-anli-ling-wanli was trained using the Hugging Face trainer with the following hyperparameters. Note that longer training with more epochs hurt performance in my tests (overfitting).
50
+
51
+ training_args = TrainingArguments(
52
+ num_train_epochs=4, # total number of training epochs
53
+ learning_rate=5e-06,
54
+ per_device_train_batch_size=16, # batch size per device during training
55
+ gradient_accumulation_steps=2, # doubles the effective batch_size to 32, while decreasing memory requirements
56
+ per_device_eval_batch_size=64, # batch size for evaluation
57
+ warmup_ratio=0.06, # number of warmup steps for learning rate scheduler
58
+ weight_decay=0.01, # strength of weight decay
59
+ fp16=True # mixed precision training
60
+ )
61
+
62
+ Eval results
63
+ The model was evaluated using the test sets for MultiNLI, ANLI, LingNLI, WANLI and the dev set for Fever-NLI. The metric used is accuracy. The model achieves state-of-the-art performance on each dataset. Surprisingly, it outperforms the previous state-of-the-art on ANLI (ALBERT-XXL) by 8,3%. I assume that this is because ANLI was created to fool masked language models like RoBERTa (or ALBERT), while DeBERTa-v3 uses a better pre-training objective (RTD), disentangled attention and I fine-tuned it on higher quality NLI data.
64
+
65
+ Datasets mnli_test_m mnli_test_mm anli_test anli_test_r3 ling_test wanli_test
66
+ Accuracy 0.912 0.908 0.702 0.64 0.87 0.77
67
+ Speed (text/sec, A100 GPU) 696.0 697.0 488.0 425.0 828.0 980.0
68
+ Limitations and bias
69
+ Please consult the original DeBERTa-v3 paper and literature on different NLI datasets for more information on the training data and potential biases. The model will reproduce statistical patterns in the training data.
70
+
71
+ Citation
72
+ If you use this model, please cite: Laurer, Moritz, Wouter van Atteveldt, Andreu Salleras Casas, and Kasper Welbers. 2022. ‘Less Annotating, More Classifying – Addressing the Data Scarcity Issue of Supervised Machine Learning with Deep Transfer Learning and BERT - NLI’. Preprint, June. Open Science Framework. https://osf.io/74b8k.
73
+
74
+ Ideas for cooperation or questions?
75
+ If you have questions or ideas for cooperation, contact me at m{dot}laurer{at}vu{dot}nl or LinkedIn
76
+
77
+ Debugging and issues
78
+ Note that DeBERTa-v3 was released on 06.12.21 and older versions of HF Transformers seem to have issues running the model (e.g. resulting in an issue with the tokenizer). Using Transformers>=4.13 might solve some issues.
79
+