🚀 MobileBERT在SQuAD v1上的微调模型
本项目基于MobileBERT模型,在SQuAD v1数据集上进行微调,用于问答任务。MobileBERT是BERT_LARGE的精简版本,采用了瓶颈结构,并精心平衡了自注意力机制和前馈网络。
🚀 快速开始
模型介绍
MobileBERT 是BERT_LARGE的精简版,具备瓶颈结构,且在自注意力机制和前馈网络之间实现了精心设计的平衡。
本模型是在 SQuAD1.1 数据集上,从HuggingFace的检查点 google/mobilebert-uncased
进行微调得到的。
📚 详细文档
数据集详情
数据集 |
划分 |
样本数量 |
SQuAD1.1 |
训练集 |
90.6K |
SQuAD1.1 |
评估集 |
11.1k |
微调细节
- Python版本:
3.7.5
- 机器配置:
CPU
:Intel(R) Core(TM) i7 - 6800K CPU @ 3.40GHz
内存
:32 GiB
GPU
:2块GeForce GTX 1070,每块显存8GiB
GPU驱动
:418.87.01,CUDA:10.1
- 脚本命令:
# 安装 https://github.com/huggingface/transformers 之后
cd examples/question-answering
mkdir -p data
wget -O data/train-v1.1.json https://rajpurkar.github.io/SQuAD-explorer/dataset/train-v1.1.json
wget -O data/dev-v1.1.json https://rajpurkar.github.io/SQuAD-explorer/dataset/dev-v1.1.json
export SQUAD_DIR=`pwd`/data
python run_squad.py \
--model_type mobilebert \
--model_name_or_path google/mobilebert-uncased \
--do_train \
--do_eval \
--do_lower_case \
--train_file $SQUAD_DIR/train-v1.1.json \
--predict_file $SQUAD_DIR/dev-v1.1.json \
--per_gpu_train_batch_size 16 \
--per_gpu_eval_batch_size 16 \
--learning_rate 4e-5 \
--num_train_epochs 5.0 \
--max_seq_length 320 \
--doc_stride 128 \
--warmup_steps 1400 \
--output_dir $SQUAD_DIR/mobilebert-uncased-warmup-squad_v1 2>&1 | tee train-mobilebert-warmup-squad_v1.log
微调过程大约耗时3小时。
模型效果
模型大小:95M
指标 |
数值 |
原始论文数值 (Table 5) |
精确匹配率 (EM) |
82.6 |
82.9 |
F1值 |
90.0 |
90.0 |
注意,以上结果未进行任何超参数搜索。
💻 使用示例
基础用法
from transformers import pipeline
qa_pipeline = pipeline(
"question-answering",
model="csarron/mobilebert-uncased-squad-v1",
tokenizer="csarron/mobilebert-uncased-squad-v1"
)
predictions = qa_pipeline({
'context': "The game was played on February 7, 2016 at Levi's Stadium in the San Francisco Bay Area at Santa Clara, California.",
'question': "What day was the game played on?"
})
print(predictions)
由 Qingqing Cao 创建 | GitHub | Twitter
于纽约用心打造 ❤️
📄 许可证
本项目采用MIT许可证。