File size: 5,441 Bytes
1984ece
 
d685831
 
 
5bf5699
 
 
c82cfae
 
 
 
 
d685831
 
 
 
 
 
 
 
 
 
32ba3a3
 
 
d685831
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
5bf5699
 
 
 
 
 
d685831
 
 
 
 
 
 
 
 
 
5bf5699
d685831
 
 
 
 
 
 
 
 
 
 
 
 
5bf5699
 
 
 
 
 
d685831
 
 
 
 
 
 
 
 
5bf5699
 
 
 
 
 
d685831
 
 
 
 
 
 
 
 
5bf5699
 
 
 
 
 
d685831
 
 
 
 
 
 
 
 
5bf5699
 
 
 
 
 
1984ece
d685831
 
 
6da6e92
d685831
 
 
 
 
32ba3a3
d685831
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
6da6e92
d685831
6da6e92
 
 
 
 
 
 
 
d685831
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
---
license: mit
datasets:
- squad_v2
- squad
- mrqa
- mbartolo/synQA
- adversarial_qa
- newsqa
- trivia_qa
- search_qa
- hotpot_qa
- natural_questions
language:
- en
library_name: transformers
pipeline_tag: question-answering
tags:
- deberta
- deberta-v3
- question-answering
- squad
- squad_v2
- mrqa
- synQA
- adversarial_qa
model-index:
- name: sjrhuschlee/deberta-v3-base-squad2-ext-v1
  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: 79.483
      name: Exact Match
    - type: f1
      value: 82.343
      name: F1
  - task:
      type: question-answering
      name: Question Answering
    dataset:
      name: squad
      type: squad
      config: plain_text
      split: validation
    metrics:
    - type: exact_match
      value: 85.894
      name: Exact Match
    - type: f1
      value: 91.298
      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: 44.867
      name: Exact Match
    - type: f1
      value: 55.996
      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: 80.19
      name: Exact Match
    - type: f1
      value: 85.028
      name: F1
  - task:
      type: question-answering
      name: Question Answering
    dataset:
      name: squadshifts
      type: squadshifts
      config: amazon
      split: test
    metrics:
    - type: exact_match
      value: 69.712
      name: Exact Match
    - type: f1
      value: 81.171
      name: F1
  - task:
      type: question-answering
      name: Question Answering
    dataset:
      name: squadshifts
      type: squadshifts
      config: new_wiki
      split: test
    metrics:
    - type: exact_match
      value: 81.544
      name: Exact Match
    - type: f1
      value: 89.782
      name: F1
  - task:
      type: question-answering
      name: Question Answering
    dataset:
      name: squadshifts
      type: squadshifts
      config: nyt
      split: test
    metrics:
    - type: exact_match
      value: 80.05
      name: Exact Match
    - type: f1
      value: 87.756
      name: F1
  - task:
      type: question-answering
      name: Question Answering
    dataset:
      name: squadshifts
      type: squadshifts
      config: reddit
      split: test
    metrics:
    - type: exact_match
      value: 60.481
      name: Exact Match
    - type: f1
      value: 68.686
      name: F1
---

# deberta-v3-base for Extractive QA

This is the [deberta-v3-base](https://huggingface.co/microsoft/deberta-v3-base) model, fine-tuned using the SQuAD 2.0, MRQA, AdversarialQA, and SynQA datasets. It's been trained on question-answer pairs, including unanswerable questions, for the task of Extractive Question Answering.

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

## Model Usage
```python
import torch
from transformers import(
  AutoModelForQuestionAnswering,
  AutoTokenizer,
  pipeline
)
model_name = "sjrhuschlee/deberta-v3-base-squad2-ext-v1"

# 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'
```

## Dataset Preparation

The MRQA dataset was updated to fix some errors and formatting to work with the `run_qa.py` example script provided in the Hugging Face Transformers library.
The changes included
- Updating incorrect answer starts locations (usually off by a few characters)
- Updating the answer text to match the text found in the context
The script used to process the MRQA dataset is provided in this repo at XXX.

### MRQA
- The answer


## Training procedure

### Training hyperparameters

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

### Framework versions

- Transformers 4.31.0.dev0