🚀 BERT-base uncased model fine-tuned on SQuAD v1
This model is a fine-tuned BERT-base uncased model on SQuAD v1, which uses pruning techniques to reduce weights and speed up inference while maintaining high accuracy.
🚀 Quick Start
To use this model, first install the nn_pruning
library:
pip install nn_pruning
Then, you can use the transformers
library as follows:
from transformers import pipeline
from nn_pruning.inference_model_patcher import optimize_model
qa_pipeline = pipeline(
"question-answering",
model="madlag/bert-base-uncased-squadv1-x2.44-f87.7-d26-hybrid-filled-v1",
tokenizer="madlag/bert-base-uncased-squadv1-x2.44-f87.7-d26-hybrid-filled-v1"
)
print("/home/lagunas/devel/hf/nn_pruning/nn_pruning/analysis/tmp_finetune parameters: 189.0M")
print(f"Parameters count (includes only head pruning, not feed forward pruning)={int(qa_pipeline.model.num_parameters() / 1E6)}M")
qa_pipeline.model = optimize_model(qa_pipeline.model, "dense")
print(f"Parameters count after complete optimization={int(qa_pipeline.model.num_parameters() / 1E6)}M")
predictions = qa_pipeline({
'context': "Frédéric François Chopin, born Fryderyk Franciszek Chopin (1 March 1810 – 17 October 1849), was a Polish composer and virtuoso pianist of the Romantic era who wrote primarily for solo piano.",
'question': "Who is Frederic Chopin?",
})
print("Predictions", predictions)
✨ Features
- Pruned Weights: The linear layers contain 26.0% of the original weights, and the model contains 42.0% of the original weights overall.
- Faster Inference: With a simple resizing of the linear matrices, it runs 2.44x as fast as the original model on the evaluation.
- High Accuracy: Its F1 is 87.71, with an F1 drop of only 0.79 compared to the original model.
🔧 Technical Details
Model Creation
This model was created using the nn_pruning python library. The pruning method leads to structured matrices, which can be visualized by hovering on the plot below.
Fine-Pruning Details
This model was fine-tuned from the HuggingFace model checkpoint on SQuAD1.1, and distilled from the model csarron/bert-base-uncased-squad-v1. It is case-insensitive.
A side-effect of the block pruning is that some of the attention heads are completely removed: 80 heads were removed on a total of 144 (55.6%). Here is a detailed view on how the remaining heads are distributed in the network after pruning.
Dataset Details
Property |
Details |
Model Type |
BERT-base uncased fine-tuned on SQuAD v1 |
Training Data |
SQuAD1.1 |
Dataset Split |
train: 90.6K samples, eval: 11.1k samples |
Fine-tuning Environment
- Python:
3.8.5
- Machine specs:
Memory: 64 GiB
GPUs: 1 GeForce GTX 3090, with 24GiB memory
GPU driver: 455.23.05, CUDA: 11.1
Results
Metric |
Value |
Original (Table 2) |
Variation |
EM |
80.03 |
80.8 |
-0.77 |
F1 |
87.71 |
88.5 |
-0.79 |
Pytorch model file size: 355MB
(original BERT: 420MB
)
📄 License
This model is released under the MIT license.