ONNX 模型库
返回模型

说明文档

在 SQuAD v2 上微调的 MobileBERT

MobileBERT 是 BERT_LARGE 的精简版本,同时配备了瓶颈结构以及精心设计的自注意力机制和前馈网络之间的平衡。

此模型基于 HuggingFace 检查点 google/mobilebert-uncasedSQuAD2.0 上进行了微调。

详情

数据集 划分 # 样本数
SQuAD2.0 train 130k
SQuAD2.0 eval 12.3k

微调

  • 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

  • 脚本:

    # after install https://github.com/huggingface/transformers
    
    cd examples/question-answering
    mkdir -p data
    
    wget -O data/train-v2.0.json https://rajpurkar.github.io/SQuAD-explorer/dataset/train-v2.0.json
    
    wget -O data/dev-v2.0.json  https://rajpurkar.github.io/SQuAD-explorer/dataset/dev-v2.0.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 \
      --version_2_with_negative \
      --train_file $SQUAD_DIR/train-v2.0.json \
      --predict_file $SQUAD_DIR/dev-v2.0.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 \
      --save_steps 2000 \
      --output_dir $SQUAD_DIR/mobilebert-uncased-warmup-squad_v2 2>&1 | tee train-mobilebert-warmup-squad_v2.log
    

完成微调大约需要 3.5 小时。

结果

模型大小: 95M

指标 # 数值 # 原始结果 (表 5)
EM 75.2 76.2
F1 78.8 79.2

请注意,上述结果未进行任何超参数搜索。

使用示例

from transformers import pipeline

qa_pipeline = pipeline(
    "question-answering",
    model="csarron/mobilebert-uncased-squad-v2",
    tokenizer="csarron/mobilebert-uncased-squad-v2"
)

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)
# output:
# {'score': 0.71434086561203, 'start': 23, 'end': 39, 'answer': 'February 7, 2016'}

创建者 Qingqing Cao | GitHub | Twitter

❤️ 制作于纽约。

csarron/mobilebert-uncased-squad-v2

作者 csarron

question-answering transformers
↓ 40.2K ♥ 8

创建时间: 2022-03-02 23:29:05+00:00

更新时间: 2023-07-18 16:52:20+00:00

在 Hugging Face 上查看

文件 (10)

.gitattributes
README.md
config.json
model.onnx ONNX
model.safetensors
pytorch_model.bin
special_tokens_map.json
tokenizer_config.json
training_args.bin
vocab.txt