File size: 6,898 Bytes
9f5d79e
a8a5daa
 
373a3f9
a8a5daa
 
 
 
 
 
 
638828b
 
373a3f9
 
 
 
a099107
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
e164709
a099107
 
 
 
 
 
 
 
 
 
 
e164709
a099107
 
e164709
a099107
26e7356
 
 
 
 
 
 
 
 
 
e164709
26e7356
 
e164709
26e7356
6909c41
 
 
 
 
 
 
 
 
 
e164709
6909c41
 
e164709
6909c41
1126a42
 
 
 
e164709
1126a42
 
 
 
 
e164709
1126a42
 
e164709
1126a42
 
 
 
 
e164709
1126a42
 
 
 
 
e164709
1126a42
 
e164709
1126a42
82abb74
 
 
 
e164709
82abb74
 
 
 
 
e164709
82abb74
 
e164709
82abb74
1126a42
 
 
 
e164709
1126a42
 
 
 
 
e164709
1126a42
 
e164709
1126a42
e517659
 
 
 
 
 
f1543e8
 
e517659
 
 
 
 
 
 
 
 
 
5412ac3
 
e517659
05f588c
 
 
 
 
 
e517659
 
 
 
 
 
 
 
 
05f588c
e517659
 
 
 
05f588c
 
 
 
 
 
 
 
 
 
 
 
 
 
f1543e8
 
935ce55
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
f1543e8
 
 
 
 
 
 
 
51e5707
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
---
language:
- en
license: mit
library_name: transformers
tags:
- deberta
- deberta-v3
- question-answering
- squad
- squad_v2
- lora
- peft
datasets:
- squad_v2
- squad
base_model: microsoft/deberta-v3-large
model-index:
- name: sjrhuschlee/deberta-v3-large-squad2
  results:
  - task:
      type: question-answering
      name: Question Answering
    dataset:
      name: squad_v2
      type: squad_v2
      config: squad_v2
      split: validation
    metrics:
    - type: exact_match
      value: 87.956
      name: Exact Match
    - type: f1
      value: 90.781
      name: F1
  - task:
      type: question-answering
      name: Question Answering
    dataset:
      name: squad
      type: squad
      config: plain_text
      split: validation
    metrics:
    - type: exact_match
      value: 89.290
      name: Exact Match
    - type: f1
      value: 95.008
      name: F1
  - task:
      type: question-answering
      name: Question Answering
    dataset:
      name: adversarial_qa
      type: adversarial_qa
      config: adversarialQA
      split: validation
    metrics:
    - type: exact_match
      value: 41.400
      name: Exact Match
    - type: f1
      value: 55.676
      name: F1
  - task:
      type: question-answering
      name: Question Answering
    dataset:
      name: squad_adversarial
      type: squad_adversarial
      config: AddOneSent
      split: validation
    metrics:
    - type: exact_match
      value: 83.660
      name: Exact Match
    - type: f1
      value: 89.451
      name: F1
  - task:
      type: question-answering
      name: Question Answering
    dataset:
      name: squadshifts amazon
      type: squadshifts
      config: amazon
      split: test
    metrics:
    - type: exact_match
      value: 74.487
      name: Exact Match
    - type: f1
      value: 87.745
      name: F1
  - task:
      type: question-answering
      name: Question Answering
    dataset:
      name: squadshifts new_wiki
      type: squadshifts
      config: new_wiki
      split: test
    metrics:
    - type: exact_match
      value: 84.782
      name: Exact Match
    - type: f1
      value: 93.114
      name: F1
  - task:
      type: question-answering
      name: Question Answering
    dataset:
      name: squadshifts nyt
      type: squadshifts
      config: nyt
      split: test
    metrics:
    - type: exact_match
      value: 85.643
      name: Exact Match
    - type: f1
      value: 93.258
      name: F1
  - task:
      type: question-answering
      name: Question Answering
    dataset:
      name: squadshifts reddit
      type: squadshifts
      config: reddit
      split: test
    metrics:
    - type: exact_match
      value: 74.702
      name: Exact Match
    - type: f1
      value: 85.861
      name: F1
---

# deberta-v3-large for Extractive QA

This is the [deberta-v3-large](https://huggingface.co/microsoft/deberta-v3-large) model, fine-tuned using the [SQuAD2.0](https://huggingface.co/datasets/squad_v2) dataset. It's been trained on question-answer pairs, including unanswerable questions, for the task of Extractive Question Answering.

This model was trained using LoRA available through the [PEFT library](https://github.com/huggingface/peft).

## Overview
**Language model:** deberta-v3-large  
**Language:** English  
**Downstream-task:** Extractive QA  
**Training data:** SQuAD 2.0  
**Eval data:** SQuAD 2.0  
**Infrastructure**: 1x NVIDIA 3070  

## Model Usage

### Using Transformers
This uses the merged weights (base model weights + LoRA weights) to allow for simple use in Transformers pipelines. It has the same performance as using the weights separately when using the PEFT library.
```python
import torch
from transformers import(
  AutoModelForQuestionAnswering,
  AutoTokenizer,
  pipeline
)
model_name = "sjrhuschlee/deberta-v3-large-squad2"

# a) Using pipelines
nlp = pipeline('question-answering', model=model_name, tokenizer=model_name)
qa_input = {
'question': 'Where do I live?',
'context': 'My name is Sarah and I live in London'
}
res = nlp(qa_input)
# {'score': 0.984, 'start': 30, 'end': 37, 'answer': ' London'}

# b) Load model & tokenizer
model = AutoModelForQuestionAnswering.from_pretrained(model_name)
tokenizer = AutoTokenizer.from_pretrained(model_name)

question = 'Where do I live?'
context = 'My name is Sarah and I live in London'
encoding = tokenizer(question, context, return_tensors="pt")
start_scores, end_scores = model(
  encoding["input_ids"],
  attention_mask=encoding["attention_mask"],
  return_dict=False
)

all_tokens = tokenizer.convert_ids_to_tokens(input_ids[0].tolist())
answer_tokens = all_tokens[torch.argmax(start_scores):torch.argmax(end_scores) + 1]
answer = tokenizer.decode(tokenizer.convert_tokens_to_ids(answer_tokens))
# 'London'
```

## Metrics

```bash
# Squad v2
{
    "eval_HasAns_exact": 84.83468286099865,
    "eval_HasAns_f1": 90.48374860633226,
    "eval_HasAns_total": 5928,
    "eval_NoAns_exact": 91.0681244743482,
    "eval_NoAns_f1": 91.0681244743482,
    "eval_NoAns_total": 5945,
    "eval_best_exact": 87.95586625115808,
    "eval_best_exact_thresh": 0.0,
    "eval_best_f1": 90.77635490089573,
    "eval_best_f1_thresh": 0.0,
    "eval_exact": 87.95586625115808,
    "eval_f1": 90.77635490089592,
    "eval_runtime": 623.1333,
    "eval_samples": 11951,
    "eval_samples_per_second": 19.179,
    "eval_steps_per_second": 0.799,
    "eval_total": 11873
}

# Squad
{
    "eval_exact_match": 89.29044465468307,
    "eval_f1": 94.9846365606959,
    "eval_runtime": 553.7132,
    "eval_samples": 10618,
    "eval_samples_per_second": 19.176,
    "eval_steps_per_second": 0.8
}
```

### Using with Peft
**NOTE**: This requires code in the PR https://github.com/huggingface/peft/pull/473 for the PEFT library.
```python
#!pip install peft

from peft import LoraConfig, PeftModelForQuestionAnswering
from transformers import AutoModelForQuestionAnswering, AutoTokenizer
model_name = "sjrhuschlee/deberta-v3-large-squad2"
```

## Training procedure

### Training hyperparameters

The following hyperparameters were used during training:
- learning_rate: 5e-05
- train_batch_size: 24
- eval_batch_size: 8
- seed: 42
- gradient_accumulation_steps: 1
- total_train_batch_size: 24
- optimizer: Adam with betas=(0.9,0.999) and epsilon=1e-08
- lr_scheduler_type: linear
- lr_scheduler_warmup_ratio: 0.1
- num_epochs: 4.0

### LoRA Config
```
{
  "base_model_name_or_path": "microsoft/deberta-v3-large",
  "bias": "none",
  "fan_in_fan_out": false,
  "inference_mode": true,
  "init_lora_weights": true,
  "lora_alpha": 32,
  "lora_dropout": 0.1,
  "modules_to_save": ["qa_outputs"],
  "peft_type": "LORA",
  "r": 8,
  "target_modules": [
    "query_proj",
    "key_proj",
    "value_proj",
    "dense"
  ],
  "task_type": "QUESTION_ANS"
}
```

### Framework versions

- Transformers 4.30.0.dev0
- Pytorch 2.0.1+cu117
- Datasets 2.12.0
- Tokenizers 0.13.3