SAVRN
Search Contact SAVRN

Open-weight model · Question answering

dynamic_tinybert

by Intel Intel/dynamic_tinybert

Dynamic-TinyBERT has been fine-tuned for the NLP task of question answering, trained on the SQuAD 1.1 dataset. Guskin et al. (2021) note: Here is how to import this model in Python

Parameters
Context512
Weights267.9 MB
Licenseapache-2.0
AccessOpen weights
Monthly Downloads2.1k

Model Card

By Intel, published under apache-2.0, revision cd8fba8ea22e.

Dynamic-TinyBERT has been fine-tuned for the NLP task of question answering, trained on the SQuAD 1.1 dataset. Guskin et al. (2021) note: Here is how to import this model in Python

Read Intel's full model card

Model Details: Dynamic-TinyBERT: Boost TinyBERT's Inference Efficiency by Dynamic Sequence Length

Dynamic-TinyBERT has been fine-tuned for the NLP task of question answering, trained on the SQuAD 1.1 dataset. Guskin et al. (2021) note:

Dynamic-TinyBERT is a TinyBERT model that utilizes sequence-length reduction and Hyperparameter Optimization for enhanced inference efficiency per any computational budget. Dynamic-TinyBERT is trained only once, performing on-par with BERT and achieving an accuracy-speedup trade-off superior to any other efficient approaches (up to 3.3x with <1% loss-drop).

Model Detail Description
Model Authors - Company Intel
Model Card Authors Intel in collaboration with Hugging Face
Date November 22, 2021
Version 1
Type NLP - Question Answering
Architecture "For our Dynamic-TinyBERT model we use the architecture of TinyBERT6L: a small BERT model with 6 layers, a hidden size of 768, a feed forward size of 3072 and 12 heads." Guskin et al. (2021)
Paper or Other Resources Paper; Poster; GitHub Repo
License Apache 2.0
Questions or Comments Community Tab and Intel Developers Discord
Intended Use Description
Primary intended uses You can use the model for the NLP task of question answering: given a corpus of text, you can ask it a question about that text, and it will find the answer in the text.
Primary intended users Anyone doing question answering
Out-of-scope uses The model should not be used to intentionally create hostile or alienating environments for people.

How to use

Here is how to import this model in Python:

Click to expand
import torch
from transformers import AutoTokenizer, AutoModelForQuestionAnswering

tokenizer = AutoTokenizer.from_pretrained("Intel/dynamic_tinybert")
model = AutoModelForQuestionAnswering.from_pretrained("Intel/dynamic_tinybert")

context = "remember the number 123456, I'll ask you later."
question = "What is the number I told you?"

# Tokenize the context and question
tokens = tokenizer.encode_plus(question, context, return_tensors="pt", truncation=True)

# Get the input IDs and attention mask
input_ids = tokens["input_ids"]
attention_mask = tokens["attention_mask"]

# Perform question answering
outputs = model(input_ids, attention_mask=attention_mask)
start_scores = outputs.start_logits
end_scores = outputs.end_logits

# Find the start and end positions of the answer
answer_start = torch.argmax(start_scores)
answer_end = torch.argmax(end_scores) + 1
answer = tokenizer.convert_tokens_to_string(tokenizer.convert_ids_to_tokens(input_ids[0][answer_start:answer_end]))

# Print the answer
print("Answer:", answer)
 ```
</details>


| Factors | Description | 
| ----------- | ----------- | 
| Groups | Many Wikipedia articles with question and answer labels are contained in the training data | 
| Instrumentation | - |
| Environment | Training was completed on a Titan GPU. |
| Card Prompts | Model deployment on alternate hardware and software will change model performance |

| Metrics | Description | 
| ----------- | ----------- | 
| Model performance measures | F1 |
| Decision thresholds | - | 
| Approaches to uncertainty and variability | - | 

| Training and Evaluation Data | Description | 
| ----------- | ----------- | 
| Datasets | SQuAD1.1: "Stanford Question Answering Dataset (SQuAD) is a reading comprehension dataset, consisting of questions posed by crowdworkers on a set of Wikipedia articles, where the answer to every question is a segment of text, or span, from the corresponding reading passage, or the question might be unanswerable." (https://huggingface.co/datasets/squad)|
| Motivation | To build an efficient and accurate model for the question answering task. |
| Preprocessing | "We start with a pre-trained general-TinyBERT student, which was trained to learn the general knowledge of BERT using the general-distillation method presented by TinyBERT. We perform transformer distillation from a fine- tuned BERT teacher to the student, following the same training steps used in the original TinyBERT: (1) intermediate-layer distillation (ID) — learning the knowledge residing in the hidden states and attentions matrices, and (2) prediction-layer distillation (PD) — fitting the predictions of the teacher." ([Guskin et al., 2021](https://neurips2021-nlp.github.io/papers/16/CameraReady/Dynamic_TinyBERT_NLSP2021_camera_ready.pdf))| 

Model Performance Analysis:

| Model            | Max F1 (full model) | Best Speedup within BERT-1% |
|------------------|---------------------|-----------------------------|
| Dynamic-TinyBERT | 88.71               | 3.3x                        |

| Ethical Considerations | Description | 
| ----------- | ----------- | 
| Data | The training data come from Wikipedia articles |
| Human life | The model is not intended to inform decisions central to human life or flourishing. It is an aggregated set of labelled Wikipedia articles. | 
| Mitigations | No additional risk mitigation strategies were considered during model development. |
| Risks and harms | Significant research has explored bias and fairness issues with language models (see, e.g., [Sheng et al., 2021](https://aclanthology.org/2021.acl-long.330.pdf), and [Bender et al., 2021](https://dl.acm.org/doi/pdf/10.1145/3442188.3445922)). Predictions generated by the model may include disturbing and harmful stereotypes across protected classes; identity characteristics; and sensitive, social, and occupational groups. Beyond this, the extent of the risks involved by using the model remain unknown.|
| Use cases | - | 


| Caveats and Recommendations |
| ----------- | 
| Users (both direct and downstream) should be made aware of the risks, biases and limitations of the model. There are no additional caveats or recommendations for this model. |


### BibTeX entry and citation info
```bibtex
@misc{https://doi.org/10.48550/arxiv.2111.09645,
  doi = {10.48550/ARXIV.2111.09645},

  url = {https://arxiv.org/abs/2111.09645},

  author = {Guskin, Shira and Wasserblat, Moshe and Ding, Ke and Kim, Gyuwan},

  keywords = {Computation and Language (cs.CL), Machine Learning (cs.LG), FOS: Computer and information sciences, FOS: Computer and information sciences},

  title = {Dynamic-TinyBERT: Boost TinyBERT's Inference Efficiency by Dynamic Sequence Length},

  publisher = {arXiv},

  year = {2021},

Configuration

Architecture
TinyBertForQuestionAnswering
Context length (tokens)
512
Layers
6
Hidden size
768
Feed-forward size
3,072
Attention heads
12
Vocabulary size
30,522
Model type
bert

Identity and Version

Repository
Intel/dynamic_tinybert
Publisher
Intel
Task
Question answering
Modality
Text
Library
transformers
Parameters
Not stated by the source
Languages
en
Revision
cd8fba8ea22eb32272ec4d03679d49ab1bbf6504
First published
2022-03-02
Last updated
2024-03-22

Files and Weights

9 files, 268.6 MB in total. The weights are 2 files totalling 267.9 MB in bin.

Weights2 files · 267.9 MB
Configuration2 files · 855 B
Tokenizer3 files · 697.9 KB
Documentation1 file · 7.3 KB
Repository1 file · 1.2 KB
Every file
FileTypeSizeSHA-256
pytorch_model.binWeights267.9 MB 559bc6e27704
training_args.binWeights2.2 KB 45211a37428e
config.jsonConfiguration743 B
special_tokens_map.jsonConfiguration112 B
README.mdDocumentation7.3 KB
.gitattributesRepository1.2 KB
tokenizer.jsonTokenizer466.1 KB
tokenizer_config.jsonTokenizer351 B
vocab.txtTokenizer231.5 KB

License and Download

License
apache-2.0
Access
Open weights, no gate
Download size
267.9 MB
Download from Intel

Released by Intel through its official repository on Hugging Face. Read the license.

Built From

  • Described by arXiv:2111.09645
  • Trained on (disclosed) squad

Memory Requirements

PrecisionWeights in memory
As published267.9 MB

Weights only, from the published parameter count; the key-value cache and runtime add to this.

Questions About dynamic_tinybert

Can I use dynamic_tinybert commercially?

Yes. dynamic_tinybert is released under Apache License 2.0. The Apache License 2.0 is a permissive open-source license. It permits commercial use, modification and redistribution. It requires keeping the license and copyright notices and any NOTICE file, stating significant changes, and it includes an express patent grant from contributors.

What is dynamic_tinybert's context length?

512 tokens, from the maximum position embeddings in its published configuration.

Similar Models

Model · Question answering

splinter-base

Tel Aviv University

Splinter-base is the pretrained model discussed in the paper Few-Shot Question Answering by Pretraining Span Selection (at ACL 2021). Its original repository can be found here. The model is case-sensitive. Note: This model doesn't contain the pretrained weights for the QASS layer (see paper for details), and therefore the QASS layer is randomly initialized upon loading it. For the model with those weights, see tau/splinter-base-qass. Splinter is a model that is pretrained in a self-supervised fashion for few-shot question answering. This means it was pretrained on the raw texts only, with no humans labelling them in any way (which is why it can use lots of publicly available data) with an…

Open weights apache-2.0 512 tokens transformers

This model can be used for the task of question answering. The model should not be used to intentionally create hostile or alienating environments for people. 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 may include disturbing and harmful stereotypes across protected classes; identity characteristics; and sensitive, social, and occupational groups. Users (both direct and downstream) should be made aware of the risks, biases and limitations of the model. The model creators note in the associated paper: The model creators note in the associated paper: The model…

Open weights 512 tokens transformers

Model · Question answering

distilbert-onnx

Philipp Schmid

This model is a fine-tune checkpoint of DistilBERT-base-cased, fine-tuned using (a second step of) knowledge distillation on SQuAD v1.1. This model reaches a F1 score of 87.1 on the dev set (for comparison, BERT bert-base-cased version reaches a F1 score of 88.7).

Open weights apache-2.0 512 tokens transformers

Model · Question answering

roberta-base-on-cuad

Mohammed Rakib

This model can be used for the task of Question Answering on Legal Documents. Read: An Open Source Contractual Language Understanding Application Using Machine Learning for detailed information on training procedure, dataset preprocessing and evaluation. See CUAD dataset card for more information. See CUAD dataset card for more information. Used V100/P100 from Google Colab Pro Python, Transformers Mohammed Rakib in collaboration with Ezi Ozoani and the Hugging Face team Use the code below to get started with the model.

Open weights mit 514 tokens transformers