You can not select more than 25 topics Topics must start with a chinese character,a letter or number, can include dashes ('-') and can be up to 35 characters long.

README.md 32 kB

5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486
  1. # Contents
  2. - [BERT Description](#bert-description)
  3. - [Model Architecture](#model-architecture)
  4. - [Dataset](#dataset)
  5. - [Environment Requirements](#environment-requirements)
  6. - [Quick Start](#quick-start)
  7. - [Script Description](#script-description)
  8. - [Script and Sample Code](#script-and-sample-code)
  9. - [Script Parameters](#script-parameters)
  10. - [Dataset Preparation](#dataset-preparation)
  11. - [Training Process](#training-process)
  12. - [Evaluation Process](#evaluation-process)
  13. - [Model Description](#model-description)
  14. - [Performance](#performance)
  15. - [Training Performance](#training-performance)
  16. - [Evaluation Performance](#evaluation-performance)
  17. - [Description of Random Situation](#description-of-random-situation)
  18. - [ModelZoo Homepage](#modelzoo-homepage)
  19. # [BERT Description](#contents)
  20. The BERT network was proposed by Google in 2018. The network has made a breakthrough in the field of NLP. The network uses pre-training to achieve a large network structure without modifying, and only by adding an output layer to achieve multiple text-based tasks in fine-tuning. The backbone code of BERT adopts the Encoder structure of Transformer. The attention mechanism is introduced to enable the output layer to capture high-latitude global semantic information. The pre-training uses denoising and self-encoding tasks, namely MLM(Masked Language Model) and NSP(Next Sentence Prediction). No need to label data, pre-training can be performed on massive text data, and only a small amount of data to fine-tuning downstream tasks to obtain good results. The pre-training plus fune-tuning mode created by BERT is widely adopted by subsequent NLP networks.
  21. [Paper](https://arxiv.org/abs/1810.04805): Jacob Devlin, Ming-Wei Chang, Kenton Lee, Kristina Toutanova. [BERT: Pre-training of Deep Bidirectional Transformers for Language Understanding]((https://arxiv.org/abs/1810.04805)). arXiv preprint arXiv:1810.04805.
  22. [Paper](https://arxiv.org/abs/1909.00204): Junqiu Wei, Xiaozhe Ren, Xiaoguang Li, Wenyong Huang, Yi Liao, Yasheng Wang, Jiashu Lin, Xin Jiang, Xiao Chen, Qun Liu. [NEZHA: Neural Contextualized Representation for Chinese Language Understanding](https://arxiv.org/abs/1909.00204). arXiv preprint arXiv:1909.00204.
  23. # [Model Architecture](#contents)
  24. The backbone structure of BERT is transformer. For BERT_base, the transformer contains 12 encoder modules, each module contains one self-attention module and each self-attention module contains one attention module. For BERT_NEZHA, the transformer contains 24 encoder modules, each module contains one self-attention module and each self-attention module contains one attention module. The difference between BERT_base and BERT_NEZHA is that BERT_base uses absolute position encoding to produce position embedding vector and BERT_NEZHA uses relative position encoding.
  25. # [Dataset](#contents)
  26. - Download the zhwiki or enwiki dataset for pre-training. Extract and refine texts in the dataset with [WikiExtractor](https://github.com/attardi/wikiextractor). Convert the dataset to TFRecord format. Please refer to create_pretraining_data.py file in [BERT](https://github.com/google-research/bert) repository.
  27. - Download dataset for fine-tuning and evaluation such as CLUENER, TNEWS, SQuAD v1.1, etc. Convert dataset files from JSON format to TFRECORD format, please refer to run_classifier.py file in [BERT](https://github.com/google-research/bert) repository.
  28. # [Environment Requirements](#contents)
  29. - Hardware(Ascend)
  30. - Prepare hardware environment with Ascend processor. If you want to try Ascend, please send the [application form](https://obs-9be7.obs.cn-east-2.myhuaweicloud.com/file/other/Ascend%20Model%20Zoo%E4%BD%93%E9%AA%8C%E8%B5%84%E6%BA%90%E7%94%B3%E8%AF%B7%E8%A1%A8.docx) to ascend@huawei.com. Once approved, you can get access to the resources.
  31. - Framework
  32. - [MindSpore](https://gitee.com/mindspore/mindspore)
  33. - For more information, please check the resources below:
  34. - [MindSpore tutorials](https://www.mindspore.cn/tutorial/en/master/index.html)
  35. - [MindSpore API](https://www.mindspore.cn/api/en/master/index.html)
  36. # [Quick Start](#contents)
  37. After installing MindSpore via the official website, you can start pre-training, fine-tuning and evaluation as follows:
  38. ```bash
  39. # run standalone pre-training example
  40. bash scripts/run_standalone_pretrain_ascend.sh 0 1 /path/cn-wiki-128
  41. # run distributed pre-training example
  42. bash scripts/run_distributed_pretrain_ascend.sh /path/cn-wiki-128 /path/hccl.json
  43. # run fine-tuning and evaluation example
  44. - If you are going to run a fine-tuning task, please prepare a checkpoint generated from pre-training.
  45. - Set bert network config and optimizer hyperparameters in `finetune_eval_config.py`.
  46. - Classification task: Set task related hyperparameters in scripts/run_classifier.sh.
  47. - Run `bash scripts/run_classifier.py` for fine-tuning of BERT-base and BERT-NEZHA model.
  48. bash scripts/run_classifier.sh
  49. - NER task: Set task related hyperparameters in scripts/run_ner.sh.
  50. - Run `bash scripts/run_ner.py` for fine-tuning of BERT-base and BERT-NEZHA model.
  51. bash scripts/run_ner.sh
  52. - SQuAD task: Set task related hyperparameters in scripts/run_squad.sh.
  53. - Run `bash scripts/run_squad.py` for fine-tuning of BERT-base and BERT-NEZHA model.
  54. bash scripts/run_squad.sh
  55. ```
  56. For distributed training, an hccl configuration file with JSON format needs to be created in advance.
  57. Please follow the instructions in the link below:
  58. https:gitee.com/mindspore/mindspore/tree/master/model_zoo/utils/hccl_tools.
  59. For dataset, if you want to set the format and parameters, a schema configuration file with JSON format needs to be created, please refer to [tfrecord](https://www.mindspore.cn/tutorial/zh-CN/master/use/data_preparation/loading_the_datasets.html#tfrecord) format.
  60. ```
  61. For pretraining, schema file contains ["input_ids", "input_mask", "segment_ids", "next_sentence_labels", "masked_lm_positions", "masked_lm_ids", "masked_lm_weights"].
  62. For ner or classification task, schema file contains ["input_ids", "input_mask", "segment_ids", "label_ids"].
  63. For squad task, training: schema file contains ["start_positions", "end_positions", "input_ids", "input_mask", "segment_ids"], evaluation: schema file contains ["input_ids", "input_mask", "segment_ids"].
  64. `numRows` is the only option which could be set by user, other values must be set according to the dataset.
  65. For example, the schema file of cn-wiki-128 dataset for pretraining shows as follows:
  66. {
  67. "datasetType": "TF",
  68. "numRows": 7680,
  69. "columns": {
  70. "input_ids": {
  71. "type": "int64",
  72. "rank": 1,
  73. "shape": [128]
  74. },
  75. "input_mask": {
  76. "type": "int64",
  77. "rank": 1,
  78. "shape": [128]
  79. },
  80. "segment_ids": {
  81. "type": "int64",
  82. "rank": 1,
  83. "shape": [128]
  84. },
  85. "next_sentence_labels": {
  86. "type": "int64",
  87. "rank": 1,
  88. "shape": [1]
  89. },
  90. "masked_lm_positions": {
  91. "type": "int64",
  92. "rank": 1,
  93. "shape": [20]
  94. },
  95. "masked_lm_ids": {
  96. "type": "int64",
  97. "rank": 1,
  98. "shape": [20]
  99. },
  100. "masked_lm_weights": {
  101. "type": "float32",
  102. "rank": 1,
  103. "shape": [20]
  104. }
  105. }
  106. }
  107. ```
  108. # [Script Description](#contents)
  109. ## [Script and Sample Code](#contents)
  110. ```shell
  111. .
  112. └─bert
  113. ├─README.md
  114. ├─scripts
  115. ├─ascend_distributed_launcher
  116. ├─__init__.py
  117. ├─hyper_parameter_config.ini # hyper paramter for distributed pretraining
  118. ├─run_distribute_pretrain.py # script for distributed pretraining
  119. ├─README.md
  120. ├─run_classifier.sh # shell script for standalone classifier task on ascend or gpu
  121. ├─run_ner.sh # shell script for standalone NER task on ascend or gpu
  122. ├─run_squad.sh # shell script for standalone SQUAD task on ascend or gpu
  123. ├─run_standalone_pretrain_ascend.sh # shell script for standalone pretrain on ascend
  124. ├─run_distributed_pretrain_ascend.sh # shell script for distributed pretrain on ascend
  125. ├─run_distributed_pretrain_gpu.sh # shell script for distributed pretrain on gpu
  126. └─run_standaloned_pretrain_gpu.sh # shell script for distributed pretrain on gpu
  127. ├─src
  128. ├─__init__.py
  129. ├─assessment_method.py # assessment method for evaluation
  130. ├─bert_for_finetune.py # backbone code of network
  131. ├─bert_for_pre_training.py # backbone code of network
  132. ├─bert_model.py # backbone code of network
  133. ├─clue_classification_dataset_precess.py # data preprocessing
  134. ├─cluner_evaluation.py # evaluation for cluner
  135. ├─config.py # parameter configuration for pretraining
  136. ├─CRF.py # assessment method for clue dataset
  137. ├─dataset.py # data preprocessing
  138. ├─finetune_eval_config.py # parameter configuration for finetuning
  139. ├─finetune_eval_model.py # backbone code of network
  140. ├─sample_process.py # sample processing
  141. ├─utils.py # util function
  142. ├─pretrain_eval.py # train and eval net
  143. ├─run_classifier.py # finetune and eval net for classifier task
  144. ├─run_ner.py # finetune and eval net for ner task
  145. ├─run_pretrain.py # train net for pretraining phase
  146. └─run_squad.py # finetune and eval net for squad task
  147. ```
  148. ## [Script Parameters](#contents)
  149. ### Pre-Training
  150. ```
  151. usage: run_pretrain.py [--distribute DISTRIBUTE] [--epoch_size N] [----device_num N] [--device_id N]
  152. [--enable_save_ckpt ENABLE_SAVE_CKPT] [--device_target DEVICE_TARGET]
  153. [--enable_lossscale ENABLE_LOSSSCALE] [--do_shuffle DO_SHUFFLE]
  154. [--enable_data_sink ENABLE_DATA_SINK] [--data_sink_steps N]
  155. [--accumulation_steps N]
  156. [--save_checkpoint_path SAVE_CHECKPOINT_PATH]
  157. [--load_checkpoint_path LOAD_CHECKPOINT_PATH]
  158. [--save_checkpoint_steps N] [--save_checkpoint_num N]
  159. [--data_dir DATA_DIR] [--schema_dir SCHEMA_DIR] [train_steps N]
  160. options:
  161. --device_target device where the code will be implemented: "Ascend" | "GPU", default is "Ascend"
  162. --distribute pre_training by serveral devices: "true"(training by more than 1 device) | "false", default is "false"
  163. --epoch_size epoch size: N, default is 1
  164. --device_num number of used devices: N, default is 1
  165. --device_id device id: N, default is 0
  166. --enable_save_ckpt enable save checkpoint: "true" | "false", default is "true"
  167. --enable_lossscale enable lossscale: "true" | "false", default is "true"
  168. --do_shuffle enable shuffle: "true" | "false", default is "true"
  169. --enable_data_sink enable data sink: "true" | "false", default is "true"
  170. --data_sink_steps set data sink steps: N, default is 1
  171. --accumulation_steps accumulate gradients N times before weight update: N, default is 1
  172. --save_checkpoint_path path to save checkpoint files: PATH, default is ""
  173. --load_checkpoint_path path to load checkpoint files: PATH, default is ""
  174. --save_checkpoint_steps steps for saving checkpoint files: N, default is 1000
  175. --save_checkpoint_num number for saving checkpoint files: N, default is 1
  176. --train_steps Training Steps: N, default is -1
  177. --data_dir path to dataset directory: PATH, default is ""
  178. --schema_dir path to schema.json file, PATH, default is ""
  179. ```
  180. ### Fine-Tuning and Evaluation
  181. ```
  182. usage: run_ner.py [--device_target DEVICE_TARGET] [--do_train DO_TRAIN] [----do_eval DO_EVAL]
  183. [--assessment_method ASSESSMENT_METHOD] [--use_crf USE_CRF]
  184. [--device_id N] [--epoch_num N] [--vocab_file_path VOCAB_FILE_PATH]
  185. [--label2id_file_path LABEL2ID_FILE_PATH]
  186. [--train_data_shuffle TRAIN_DATA_SHUFFLE]
  187. [--eval_data_shuffle EVAL_DATA_SHUFFLE]
  188. [--save_finetune_checkpoint_path SAVE_FINETUNE_CHECKPOINT_PATH]
  189. [--load_pretrain_checkpoint_path LOAD_PRETRAIN_CHECKPOINT_PATH]
  190. [--train_data_file_path TRAIN_DATA_FILE_PATH]
  191. [--eval_data_file_path EVAL_DATA_FILE_PATH]
  192. [--schema_file_path SCHEMA_FILE_PATH]
  193. options:
  194. --device_target device where the code will be implemented: "Ascend" | "GPU", default is "Ascend"
  195. --do_train whether to run training on training set: true | false
  196. --do_eval whether to run eval on dev set: true | false
  197. --assessment_method assessment method to do evaluation: f1 | clue_benchmark
  198. --use_crf whether to use crf to calculate loss: true | false
  199. --device_id device id to run task
  200. --epoch_num total number of training epochs to perform
  201. --num_class number of classes to do labeling
  202. --train_data_shuffle Enable train data shuffle, default is true
  203. --eval_data_shuffle Enable eval data shuffle, default is true
  204. --vocab_file_path the vocabulary file that the BERT model was trained on
  205. --label2id_file_path label to id json file
  206. --save_finetune_checkpoint_path path to save generated finetuning checkpoint
  207. --load_pretrain_checkpoint_path initial checkpoint (usually from a pre-trained BERT model)
  208. --load_finetune_checkpoint_path give a finetuning checkpoint path if only do eval
  209. --train_data_file_path ner tfrecord for training. E.g., train.tfrecord
  210. --eval_data_file_path ner tfrecord for predictions if f1 is used to evaluate result, ner json for predictions if clue_benchmark is used to evaluate result
  211. --schema_file_path path to datafile schema file
  212. usage: run_squad.py [--device_target DEVICE_TARGET] [--do_train DO_TRAIN] [----do_eval DO_EVAL]
  213. [--device_id N] [--epoch_num N] [--num_class N]
  214. [--vocab_file_path VOCAB_FILE_PATH]
  215. [--eval_json_path EVAL_JSON_PATH]
  216. [--train_data_shuffle TRAIN_DATA_SHUFFLE]
  217. [--eval_data_shuffle EVAL_DATA_SHUFFLE]
  218. [--save_finetune_checkpoint_path SAVE_FINETUNE_CHECKPOINT_PATH]
  219. [--load_pretrain_checkpoint_path LOAD_PRETRAIN_CHECKPOINT_PATH]
  220. [--load_finetune_checkpoint_path LOAD_FINETUNE_CHECKPOINT_PATH]
  221. [--train_data_file_path TRAIN_DATA_FILE_PATH]
  222. [--eval_data_file_path EVAL_DATA_FILE_PATH]
  223. [--schema_file_path SCHEMA_FILE_PATH]
  224. options:
  225. --device_target device where the code will be implemented: "Ascend" | "GPU", default is "Ascend"
  226. --do_train whether to run training on training set: true | false
  227. --do_eval whether to run eval on dev set: true | false
  228. --device_id device id to run task
  229. --epoch_num total number of training epochs to perform
  230. --num_class number of classes to classify, usually 2 for squad task
  231. --train_data_shuffle Enable train data shuffle, default is true
  232. --eval_data_shuffle Enable eval data shuffle, default is true
  233. --vocab_file_path the vocabulary file that the BERT model was trained on
  234. --eval_json_path path to squad dev json file
  235. --save_finetune_checkpoint_path path to save generated finetuning checkpoint
  236. --load_pretrain_checkpoint_path initial checkpoint (usually from a pre-trained BERT model)
  237. --load_finetune_checkpoint_path give a finetuning checkpoint path if only do eval
  238. --train_data_file_path squad tfrecord for training. E.g., train1.1.tfrecord
  239. --eval_data_file_path squad tfrecord for predictions. E.g., dev1.1.tfrecord
  240. --schema_file_path path to datafile schema file
  241. usage: run_classifier.py [--device_target DEVICE_TARGET] [--do_train DO_TRAIN] [----do_eval DO_EVAL]
  242. [--assessment_method ASSESSMENT_METHOD] [--device_id N] [--epoch_num N] [--num_class N]
  243. [--save_finetune_checkpoint_path SAVE_FINETUNE_CHECKPOINT_PATH]
  244. [--load_pretrain_checkpoint_path LOAD_PRETRAIN_CHECKPOINT_PATH]
  245. [--load_finetune_checkpoint_path LOAD_FINETUNE_CHECKPOINT_PATH]
  246. [--train_data_shuffle TRAIN_DATA_SHUFFLE]
  247. [--eval_data_shuffle EVAL_DATA_SHUFFLE]
  248. [--train_data_file_path TRAIN_DATA_FILE_PATH]
  249. [--eval_data_file_path EVAL_DATA_FILE_PATH]
  250. [--schema_file_path SCHEMA_FILE_PATH]
  251. options:
  252. --device_target targeted device to run task: Ascend | GPU
  253. --do_train whether to run training on training set: true | false
  254. --do_eval whether to run eval on dev set: true | false
  255. --assessment_method assessment method to do evaluation: accuracy | f1 | mcc | spearman_correlation
  256. --device_id device id to run task
  257. --epoch_num total number of training epochs to perform
  258. --num_class number of classes to do labeling
  259. --train_data_shuffle Enable train data shuffle, default is true
  260. --eval_data_shuffle Enable eval data shuffle, default is true
  261. --save_finetune_checkpoint_path path to save generated finetuning checkpoint
  262. --load_pretrain_checkpoint_path initial checkpoint (usually from a pre-trained BERT model)
  263. --load_finetune_checkpoint_path give a finetuning checkpoint path if only do eval
  264. --train_data_file_path tfrecord for training. E.g., train.tfrecord
  265. --eval_data_file_path tfrecord for predictions. E.g., dev.tfrecord
  266. --schema_file_path path to datafile schema file
  267. ```
  268. ## Options and Parameters
  269. Parameters for training and evaluation can be set in file `config.py` and `finetune_eval_config.py` respectively.
  270. ### Options:
  271. ```
  272. config for lossscale and etc.
  273. bert_network version of BERT model: base | nezha, default is base
  274. loss_scale_value initial value of loss scale: N, default is 2^32
  275. scale_factor factor used to update loss scale: N, default is 2
  276. scale_window steps for once updatation of loss scale: N, default is 1000
  277. optimizer optimizer used in the network: AdamWerigtDecayDynamicLR | Lamb | Momentum, default is "Lamb"
  278. ```
  279. ### Parameters:
  280. ```
  281. Parameters for dataset and network (Pre-Training/Fine-Tuning/Evaluation):
  282. batch_size batch size of input dataset: N, default is 16
  283. seq_length length of input sequence: N, default is 128
  284. vocab_size size of each embedding vector: N, must be consistant with the dataset you use. Default is 21136
  285. hidden_size size of bert encoder layers: N, default is 768
  286. num_hidden_layers number of hidden layers: N, default is 12
  287. num_attention_heads number of attention heads: N, default is 12
  288. intermediate_size size of intermediate layer: N, default is 3072
  289. hidden_act activation function used: ACTIVATION, default is "gelu"
  290. hidden_dropout_prob dropout probability for BertOutput: Q, default is 0.1
  291. attention_probs_dropout_prob dropout probability for BertAttention: Q, default is 0.1
  292. max_position_embeddings maximum length of sequences: N, default is 512
  293. type_vocab_size size of token type vocab: N, default is 16
  294. initializer_range initialization value of TruncatedNormal: Q, default is 0.02
  295. use_relative_positions use relative positions or not: True | False, default is False
  296. input_mask_from_dataset use the input mask loaded form dataset or not: True | False, default is True
  297. token_type_ids_from_dataset use the token type ids loaded from dataset or not: True | False, default is True
  298. dtype data type of input: mstype.float16 | mstype.float32, default is mstype.float32
  299. compute_type compute type in BertTransformer: mstype.float16 | mstype.float32, default is mstype.float16
  300. Parameters for optimizer:
  301. AdamWeightDecay:
  302. decay_steps steps of the learning rate decay: N
  303. learning_rate value of learning rate: Q
  304. end_learning_rate value of end learning rate: Q, must be positive
  305. power power: Q
  306. warmup_steps steps of the learning rate warm up: N
  307. weight_decay weight decay: Q
  308. eps term added to the denominator to improve numerical stability: Q
  309. Lamb:
  310. decay_steps steps of the learning rate decay: N
  311. learning_rate value of learning rate: Q
  312. end_learning_rate value of end learning rate: Q
  313. power power: Q
  314. warmup_steps steps of the learning rate warm up: N
  315. weight_decay weight decay: Q
  316. Momentum:
  317. learning_rate value of learning rate: Q
  318. momentum momentum for the moving average: Q
  319. ```
  320. ## [Training Process](#contents)
  321. ### Training
  322. #### Running on Ascend
  323. ```
  324. bash scripts/run_standalone_pretrain_ascend.sh 0 1 /path/cn-wiki-128
  325. ```
  326. The command above will run in the background, you can view training logs in pretraining_log.txt. After training finished, you will get some checkpoint files under the script folder by default. The loss values will be displayed as follows:
  327. ```
  328. # grep "epoch" pretraining_log.txt
  329. epoch: 0.0, current epoch percent: 0.000, step: 1, outpus are (Tensor(shape=[1], dtype=Float32, [ 1.0856101e+01]), Tensor(shape=[], dtype=Bool, False), Tensor(shape=[], dtype=Float32, 65536))
  330. epoch: 0.0, current epoch percent: 0.000, step: 2, outpus are (Tensor(shape=[1], dtype=Float32, [ 1.0821701e+01]), Tensor(shape=[], dtype=Bool, False), Tensor(shape=[], dtype=Float32, 65536))
  331. ...
  332. ```
  333. ### Distributed Training
  334. #### Running on Ascend
  335. ```
  336. bash scripts/run_distributed_pretrain_ascend.sh /path/cn-wiki-128 /path/hccl.json
  337. ```
  338. The command above will run in the background, you can view training logs in pretraining_log.txt. After training finished, you will get some checkpoint files under the LOG* folder by default. The loss value will be displayed as follows:
  339. ```
  340. # grep "epoch" LOG*/pretraining_log.txt
  341. epoch: 0.0, current epoch percent: 0.001, step: 100, outpus are (Tensor(shape=[1], dtype=Float32, [ 1.08209e+01]), Tensor(shape=[], dtype=Bool, False), Tensor(shape=[], dtype=Float32, 65536))
  342. epoch: 0.0, current epoch percent: 0.002, step: 200, outpus are (Tensor(shape=[1], dtype=Float32, [ 1.07566e+01]), Tensor(shape=[], dtype=Bool, False), Tensor(shape=[], dtype=Float32, 65536))
  343. ...
  344. epoch: 0.0, current epoch percent: 0.001, step: 100, outpus are (Tensor(shape=[1], dtype=Float32, [ 1.08218e+01]), Tensor(shape=[], dtype=Bool, False), Tensor(shape=[], dtype=Float32, 65536))
  345. epoch: 0.0, current epoch percent: 0.002, step: 200, outpus are (Tensor(shape=[1], dtype=Float32, [ 1.07770e+01]), Tensor(shape=[], dtype=Bool, False), Tensor(shape=[], dtype=Float32, 65536))
  346. ...
  347. ```
  348. ## [Evaluation Process](#contents)
  349. ### Evaluation
  350. #### evaluation on cola dataset when running on Ascend
  351. Before running the command below, please check the load pretrain checkpoint path has been set. Please set the checkpoint path to be the absolute full path, e.g:"/username/pretrain/checkpoint_100_300.ckpt".
  352. ```
  353. bash scripts/run_classifier.sh
  354. The command above will run in the background, you can view training logs in classfier_log.txt.
  355. If you choose accuracy as assessment method, the result will be as follows:
  356. acc_num XXX, total_num XXX, accuracy 0.588986
  357. ```
  358. #### evaluation on cluener dataset when running on Ascend
  359. ```
  360. bash scripts/ner.sh
  361. The command above will run in the background, you can view training logs in ner_log.txt.
  362. If you choose F1 as assessment method, the result will be as follows:
  363. Precision 0.920507
  364. Recall 0.948683
  365. F1 0.920507
  366. ```
  367. #### evaluation on squad v1.1 dataset when running on Ascend
  368. ```
  369. bash scripts/squad.sh
  370. The command above will run in the background, you can view training logs in squad_log.txt.
  371. The result will be as follows:
  372. {"exact_match": 80.3878923040233284, "f1": 87.6902384023850329}
  373. ```
  374. ## [Model Description](#contents)
  375. ## [Performance](#contents)
  376. ### Pretraining Performance
  377. | Parameters | Ascend | GPU |
  378. | -------------------------- | ---------------------------------------------------------- | ------------------------- |
  379. | Model Version | BERT_base | BERT_base |
  380. | Resource | Ascend 910, cpu:2.60GHz 56cores, memory:314G | NV SMX2 V100-32G |
  381. | uploaded Date | 08/22/2020 | 05/06/2020 |
  382. | MindSpore Version | 0.6.0 | 0.3.0 |
  383. | Dataset | cn-wiki-128(4000w) | ImageNet |
  384. | Training Parameters | src/config.py | src/config.py |
  385. | Optimizer | Lamb | Momentum |
  386. | Loss Function | SoftmaxCrossEntropy | SoftmaxCrossEntropy |
  387. | outputs | probability | |
  388. | Epoch | 40 | | |
  389. | Batch_size | 256*8 | 130(8P) | |
  390. | Loss | 1.7 | 1.913 |
  391. | Speed | 340ms/step | 1.913 |
  392. | Total time | 73h | |
  393. | Params (M) | 110M | |
  394. | Checkpoint for Fine tuning | 1.2G(.ckpt file) | |
  395. | Parameters | Ascend | GPU |
  396. | -------------------------- | ---------------------------------------------------------- | ------------------------- |
  397. | Model Version | BERT_NEZHA | BERT_NEZHA |
  398. | Resource | Ascend 910, cpu:2.60GHz 56cores, memory:314G | NV SMX2 V100-32G |
  399. | uploaded Date | 08/20/2020 | 05/06/2020 |
  400. | MindSpore Version | 0.6.0 | 0.3.0 |
  401. | Dataset | cn-wiki-128(4000w) | ImageNet |
  402. | Training Parameters | src/config.py | src/config.py |
  403. | Optimizer | Lamb | Momentum |
  404. | Loss Function | SoftmaxCrossEntropy | SoftmaxCrossEntropy |
  405. | outputs | probability | |
  406. | Epoch | 40 | | |
  407. | Batch_size | 96*8 | 130(8P) |
  408. | Loss | 1.7 | 1.913 |
  409. | Speed | 360ms/step | 1.913 |
  410. | Total time | 200h | |
  411. | Params (M) | 340M | |
  412. | Checkpoint for Fine tuning | 3.2G(.ckpt file) | |
  413. #### Inference Performance
  414. | Parameters | Ascend | GPU |
  415. | -------------------------- | ----------------------------- | ------------------------- |
  416. | Model Version | | |
  417. | Resource | Ascend 910 | NV SMX2 V100-32G |
  418. | uploaded Date | 08/22/2020 | 05/22/2020 |
  419. | MindSpore Version | 0.6.0 | 0.2.0 |
  420. | Dataset | cola, 1.2W | ImageNet, 1.2W |
  421. | batch_size | 32(1P) | 130(8P) |
  422. | Accuracy | 0.588986 | ACC1[72.07%] ACC5[90.90%] |
  423. | Speed | 59.25ms/step | |
  424. | Total time | 15min | |
  425. | Model for inference | 1.2G(.ckpt file) | |
  426. # [Description of Random Situation](#contents)
  427. In run_standalone_pretrain.sh and run_distributed_pretrain.sh, we set do_shuffle to True to shuffle the dataset by default.
  428. In run_classifier.sh, run_ner.sh and run_squad.sh, we set train_data_shuffle and eval_data_shuffle to True to shuffle the dataset by default.
  429. In config.py, we set the hidden_dropout_prob and attention_pros_dropout_prob to 0.1 to dropout some network node by default.
  430. In run_pretrain.py, we set a random seed to make sure that each node has the same initial weight in distribute training.
  431. # [ModelZoo Homepage](#contents)
  432. Please check the official [homepage](https://gitee.com/mindspore/mindspore/tree/master/model_zoo).