rajpurkar/squad
Viewer • Updated • 98.2k • 158k • 364
How to use sjrhuschlee/deberta-v3-base-squad2-ext-v1 with Transformers:
# Use a pipeline as a high-level helper
from transformers import pipeline
pipe = pipeline("question-answering", model="sjrhuschlee/deberta-v3-base-squad2-ext-v1") # Load model directly
from transformers import AutoTokenizer, AutoModelForQuestionAnswering
tokenizer = AutoTokenizer.from_pretrained("sjrhuschlee/deberta-v3-base-squad2-ext-v1")
model = AutoModelForQuestionAnswering.from_pretrained("sjrhuschlee/deberta-v3-base-squad2-ext-v1")This is the 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.
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
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'
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
The following hyperparameters were used during training:
Base model
microsoft/deberta-v3-base