13 Star 61 Fork 279

Ascend/ModelZoo-TensorFlow

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
.idea
ACL_TensorFlow
TensorFlow
built-in
audio
cv
gnn
graph/DCGAN_ID0686_for_TensorFlow
nlp
ALBERT-lcqmc-ZH_ID1461_for_TensorFlow
Albert_ID0632_for_TensorFlow
Albert_ZH_for_TensorFlow
Bert-CLUE_for_TensorFlow
bert
test
LICENSE
README.md
Readme_bak.md
classifier_utils.py
modelzoo_level.txt
requirements.txt
Bert-NER_ID0797_for_TensorFlow
Bert-base_ID0060_for_TensorFlow
Bert-qa_ID0369_for_TensorFlow
BertBase-squad_for_TensorFlow
BertBase_Google_ID0631_for_TensorFlow
BertCOLA_ID1629_for_TensorFlow
BertGoogle_Series_for_TensorFlow
BertMNLI_ID1628_for_TensorFlow
BertNV_Series_for_TensorFlow
Bert_Google_MRPC_ID1466_for_TensorFlow
Bert_Google_finetune_for_TensorFlow
Bert_Google_for_TensorFlow
Bert_Nv_Finetune_MPRC_ID1641_for_TensorFlow
Bert_sougou_qa_ID3442_for_Tensorflow
Bertsquad_ID0495_for_TensorFlow
Bertsquad_for_TensorFlow
BiLSTM_CRF_ID0125_for_TensorFlow
BioBERT_ID0280_for_TensorFlow
CLUE_BERT_ID1646_for_TensorFlow
CNN-CTC_ID0683_for_TensorFlow
CNN-MC_ID0287_for_TensorFlow
DS-CNN_ID1769_for_TensorFlow
DS-CNN_RT2_ID1769_for_TensorFlow
Elmo_ID0656_for_TensorFlow
FASPell_finetune_ID1903_for_TensorFlow
FASPell_pretrain_ID1858_for_TensorFlow
FastText_ID0135_for_TensorFlow
GNMT_ID0015_for_TensorFlow
GNMT_ID1819_for_TensorFlow
GNMT_for_TensorFlow
GPT-2_for_TensorFlow
GPT-3_for_TensorFlow
GRU4Rec_ID0128_for_TensorFlow
LGCN_ID1169_for_TensorFlow
LSTM_ID0111_for_TensorFlow
LeNet_ID0127_for_TensorFlow
NMT_ID0512_for_TensorFlow
Nezha-large_for_TensorFlow
RetinaNet_for_TensorFlow
Roberta_ID2349_for_TensorFlow
Roberta_ID2366_for_TensorFlow
Siamese_ID0506_for_TensorFlow
Textcnn_ID0123_For_Tensorflow
Transformer_ID0004_for_TensorFlow
WaveGlow_ID0317_for_TensorFlow
XLNet_ID0025_for_TensorFlow
Yuefu_for_TensorFlow
albert_xlarge_zh_ID2348_for_TensorFlow
kernetNet_ID0305_for_Tensorflow
word2vec_ID0134_for_TensorFlow
recommendation
reinforcement_learning
contrib
TensorFlow2
Tools/ascend_distribute
.gitignore
.gitmodules
LICENSE
NOTICE
README.CN.md
README.md
Third_Party_Open_Source_Software_Notice
克隆/下载
贡献代码
同步代码
取消
提示: 由于 Git 不支持空文件夾,创建文件夹后会生成空的 .keep 文件
Loading...
README

基本信息

应用领域(Application Domain):Natural Language Processing

版本(Version):1.1

修改时间(Modified) :2021.7.17

大小(Size):552K

框架(Framework):TensorFlow 1.15.0

模型格式(Model Format):ckpt

精度(Precision):Mixed

应用级别(Categories):Official

描述(Description):基于TensorFlow框架的BERT网络在CLUE数据集上的finetune代码

概述

BERT是一种与训练语言表示的方法,这意味着我们在大型文本语料库(如维基百科)上训练一个通用的”语言理解“模型,然后将该模型用于我们关心的下游NLP任务(如问答)。该工程提供了在CLUE数据集上finetune的方法。

默认配置

  • 训练超参

    • train_batch_size: 32
    • learning_rate: 2e-5
    • num_train_epochs: 3.0
    • max_seq_length: 128

支持特性

特性列表 是否支持
分布式训练
混合精度
并行数据

混合精度训练

昇腾910 AI处理器提供自动混合精度功能,可以针对全网中float32数据类型的算子,按照内置的优化策略,自动将部分float32的算子降低精度到float16,从而在精度损失很小的情况下提升系统性能并减少内存使用。

开启混合精度

脚本已默认开启混合精度,设置precision_mode参数的脚本参考如下。

run_config = NPURunConfig(
      model_dir=FLAGS.output_dir,
      save_checkpoints_steps=FLAGS.save_checkpoints_steps,
      iterations_per_loop=FLAGS.iterations_per_loop,
      session_config=config,
      precision_mode="allow_mix_precision",
      keep_checkpoint_max=5)

训练环境准备

  1. 硬件环境准备请参见各硬件产品文档"驱动和固件安装升级指南"。需要在硬件设备上安装与CANN版本配套的固件与驱动。

  2. 宿主机上需要安装Docker并登录Ascend Hub中心获取镜像。

    当前模型支持的镜像列表如表1所示。

    表 1 镜像列表

    镜像名称

    镜像版本

    配套CANN版本

    20.2.0

    20.2

快速上手

数据集准备

  • 模型训练使用TNEWS和MSRANER数据集,参考源代码提供路径下载。
  • 预处理模型使用BERT-Base,Uncased,参考源代码提供路径下载。下载的文件夹中应该含有预处理模型,vocab.txt和bert_config.json。
  • 数据集和预处理模型下载完成后,放入模型目录下,在训练脚本中指定数据集和模型路径,可正常使用。

模型训练

  • 单击“立即下载”,并选择合适的下载方式下载源码包。

  • 启动训练之前,首先要配置程序运行相关环境变量。

    环境变量配置信息参见:

    Ascend 910训练平台环境变量设置

    将环境变量配置到scrpts/run_*.sh中

  • TNEWS训练

    启动单卡训练

    修改test/train_full_tnews_1p.sh中的data_path,里面包括提前下载的数据集和预训练模型。

    cd test
    bash train_full_tnews_1p.sh
    
  • MSRANER训练

    启动单卡训练

    修改test/train_full_msraner_8p.sh中的data_path,里面包括提前下载的数据集和预训练模型。

    cd test
    bash run_8p.sh
    

高级参考

脚本和示例代码

└─BertMRPC_for_TensorFlow
    ├─test
    |     ├─train_full_tnews_1p.sh
    |     ├─train_full_msraner_8p.sh
    ├─CONTRIBUTING.md
    ├─create_pretraining_data.py
    ├─evaluate-v1.1.py
    ├─extract_features.py
    ├─gpu_environment.py
    ├─LICENSE
    ├─modeling.py
    ├─modeling_test.py
    ├─multilingual.md
    ├─optimization.py
    ├─optimization_test.py
    ├─README.md
    ├─run.sh
    ├─run_classifier.py
    ├─run_classifier_with_tfhub.py
    ├─run_pretraining.py
    ├─run_squad.py
    ├─tokenization.py
    └─tokenization_test.py

脚本参数

TNEWS:
python3 run_classifier.py \
  --task_name=tnews \
  --do_train=true \
  --do_eval=true \
  --data_dir=$data_path/tnews \
  --vocab_file=$data_path/chinese_L-12_H-768_A-12/vocab.txt \
  --bert_config_file=$data_path/chinese_L-12_H-768_A-12/bert_config.json \
  --init_checkpoint=$data_path/chinese_L-12_H-768_A-12/bert_model.ckpt \
  --max_seq_length=128 \
  --train_batch_size=${batch_size} \
  --learning_rate=2e-5 \
  --num_train_epochs=3.0 \
  --output_dir=tnews_output \
  
MSRANER:
python3 run_ner.py \
  --task_name=msraner \
  --do_train=true \
  --do_predict=true \
  --data_path=$data_path/msraner \
  --vocab_file=$data_path/chinese_L-12_H-768_A-12/vocab.txt \
  --bert_config_file=$data_path/chinese_L-12_H-768_A-12/bert_config.json \
  --init_checkpoint=$data_path/chinese_L-12_H-768_A-12/bert_model.ckpt \
  --max_seq_length=128 \
  --train_batch_size=${batch_size} \
  --learning_rate=2e-5 \
  --num_train_epochs=3.0 \
  --output_dir=msraner_output \

训练过程

  1. 通过“模型训练”中的训练指令启动性能或者精度训练。单卡和多卡通过运行不同脚本,支持单卡网络训练。
  2. 参考脚本的模型存储路径为test/output/*。
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/ascend/ModelZoo-TensorFlow.git
git@gitee.com:ascend/ModelZoo-TensorFlow.git
ascend
ModelZoo-TensorFlow
ModelZoo-TensorFlow
master

搜索帮助