DistilBERT base cased distilled SQuAD
Table of Contents
Model Details
Model Description: The DistilBERT model was proposed in the blog post
Smaller, faster, cheaper, lighter: Introducing DistilBERT, adistilled version of BERT, and the paper
DistilBERT, adistilled version of BERT: smaller, faster, cheaper and lighter. DistilBERT is a small, fast, cheap and light Transformer model trained by distilling BERT base. It has 40% less parameters than
bert-base-uncased, runs 60% faster while preserving over 95% of BERT's performances as measured on the GLUE language understanding benchmark.
This model is a fine-tune checkpoint of
DistilBERT-base-cased, fine-tuned using (a second step of) knowledge distillation on
SQuAD v1.1.
- Developed by: Hugging Face
- Model Type: Transformer-based language model
- Language(s): English
- License: Apache 2.0
- Related Models: DistilBERT-base-cased
- Resources for more information:
- See this repository for more about Distil* (a class of compressed models including this model)
- See Sanh et al. (2019) for more information about knowledge distillation and the training procedure
How to Get Started with the Model
Use the code below to get started with the model.
1>>> from transformers import pipeline
2>>> question_answerer = pipeline("question-answering", model='distilbert-base-cased-distilled-squad')
3
4>>> context = r"""
5... Extractive Question Answering is the task of extracting an answer from a text given a question. An example of a
6... question answering dataset is the SQuAD dataset, which is entirely based on that task. If you would like to fine-tune
7... a model on a SQuAD task, you may leverage the examples/pytorch/question-answering/run_squad.py script.
8... """
9
10>>> result = question_answerer(question="What is a good example of a question answering dataset?", context=context)
11>>> print(
12... f"Answer: '{result['answer']}', score: {round(result['score'], 4)}, start: {result['start']}, end: {result['end']}"
13...)
14
15Answer: 'SQuAD dataset', score: 0.5152, start: 147, end: 160
Here is how to use this model in PyTorch:
1from transformers import DistilBertTokenizer, DistilBertModel
2import torch
3tokenizer = DistilBertTokenizer.from_pretrained('distilbert-base-cased-distilled-squad')
4model = DistilBertModel.from_pretrained('distilbert-base-cased-distilled-squad')
5
6question, text = "Who was Jim Henson?", "Jim Henson was a nice puppet"
7
8inputs = tokenizer(question, text, return_tensors="pt")
9with torch.no_grad():
10 outputs = model(**inputs)
11
12print(outputs)
And in TensorFlow:
1from transformers import DistilBertTokenizer, TFDistilBertForQuestionAnswering
2import tensorflow as tf
3
4tokenizer = DistilBertTokenizer.from_pretrained("distilbert-base-cased-distilled-squad")
5model = TFDistilBertForQuestionAnswering.from_pretrained("distilbert-base-cased-distilled-squad")
6
7question, text = "Who was Jim Henson?", "Jim Henson was a nice puppet"
8
9inputs = tokenizer(question, text, return_tensors="tf")
10outputs = model(**inputs)
11
12answer_start_index = int(tf.math.argmax(outputs.start_logits, axis=-1)[0])
13answer_end_index = int(tf.math.argmax(outputs.end_logits, axis=-1)[0])
14
15predict_answer_tokens = inputs.input_ids[0, answer_start_index : answer_end_index + 1]
16tokenizer.decode(predict_answer_tokens)
Uses
This model can be used for question answering.
Misuse and Out-of-scope Use
The model should not be used to intentionally create hostile or alienating environments for people. In addition, the model was not trained to be factual or true representations of people or events, and therefore using the model to generate such content is out-of-scope for the abilities of this model.
Risks, Limitations and Biases
CONTENT WARNING: Readers should be aware that language generated by this model can be disturbing or offensive to some and can propagate historical and current stereotypes.
Significant research has explored bias and fairness issues with language models (see, e.g.,
Sheng et al. (2021) and
Bender et al. (2021)). Predictions generated by the model can include disturbing and harmful stereotypes across protected classes; identity characteristics; and sensitive, social, and occupational groups. For example:
1>>> from transformers import pipeline
2>>> question_answerer = pipeline("question-answering", model='distilbert-base-cased-distilled-squad')
3
4>>> context = r"""
5... Alice is sitting on the bench. Bob is sitting next to her.
6... """
7
8>>> result = question_answerer(question="Who is the CEO?", context=context)
9>>> print(
10... f"Answer: '{result['answer']}', score: {round(result['score'], 4)}, start: {result['start']}, end: {result['end']}"
11...)
12
13Answer: 'Bob', score: 0.7527, start: 32, end: 35
Users (both direct and downstream) should be made aware of the risks, biases and limitations of the model.
Training
Training Data
The
distilbert-base-cased model was trained using the same data as the
distilbert-base-uncased model. The
distilbert-base-uncased model model describes it's training data as:
DistilBERT pretrained on the same data as BERT, which is
BookCorpus, a dataset consisting of 11,038 unpublished books and
English Wikipedia (excluding lists, tables and headers).
To learn more about the SQuAD v1.1 dataset, see the
SQuAD v1.1 data card.
Training Procedure
Preprocessing
Pretraining
Evaluation
As discussed in the
model repository
This model reaches a F1 score of 87.1 on the [SQuAD v1.1] dev set (for comparison, BERT bert-base-cased version reaches a F1 score of 88.7).
Environmental Impact
Carbon emissions can be estimated using the
Machine Learning Impact calculator presented in
Lacoste et al. (2019). We present the hardware type and hours used based on the
associated paper. Note that these details are just for training DistilBERT, not including the fine-tuning with SQuAD.
- Hardware Type: 8 16GB V100 GPUs
- Hours used: 90 hours
- Cloud Provider: Unknown
- Compute Region: Unknown
- Carbon Emitted: Unknown
Technical Specifications
See the
associated paper for details on the modeling architecture, objective, compute infrastructure, and training details.
Citation Information
1@inproceedings{sanh2019distilbert,
2 title={DistilBERT, a distilled version of BERT: smaller, faster, cheaper and lighter},
3 author={Sanh, Victor and Debut, Lysandre and Chaumond, Julien and Wolf, Thomas},
4 booktitle={NeurIPS EMC^2 Workshop},
5 year={2019}
6}
APA:
- Sanh, V., Debut, L., Chaumond, J., & Wolf, T. (2019). DistilBERT, a distilled version of BERT: smaller, faster, cheaper and lighter. arXiv preprint arXiv:1910.01108.
Model Card Authors
This model card was written by the Hugging Face team.