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 30 kB

4 years ago
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658
  1. # Contents
  2. - [MASS: Masked Sequence to Sequence Pre-training for Language Generation Description](#googlenet-description)
  3. - [Model architecture](#model-architecture)
  4. - [Dataset](#dataset)
  5. - [Features](#features)
  6. - [Script description](#script-description)
  7. - [Data Preparation](#Data-Preparation)
  8. - [Tokenization](#Tokenization)
  9. - [Byte Pair Encoding](#Byte-Pair-Encoding)
  10. - [Build Vocabulary](#Build-Vocabulary)
  11. - [Generate Dataset](#Generate-Dataset)
  12. - [News Crawl Corpus](#News-Crawl-Corpus)
  13. - [Gigaword Corpus](#Gigaword-Corpus)
  14. - [Cornell Movie Dialog Corpus](#Cornell-Movie-Dialog-Corpus)
  15. - [Configuration](#Configuration)
  16. - [Training & Evaluation process](#Training-&-Evaluation-process)
  17. - [Weights average](#Weights-average)
  18. - [Learning rate scheduler](#Learning-rate-scheduler)
  19. - [Model description](#model-description)
  20. - [Performance](#performance)
  21. - [Results](#results)
  22. - [Training Performance](#training-performance)
  23. - [Inference Performance](#inference-performance)
  24. - [Environment Requirements](#environment-requirements)
  25. - [Platform](#Platform)
  26. - [Requirements](#Requirements)
  27. - [Get started](#get-started)
  28. - [Pre-training](#Pre-training)
  29. - [Fine-tuning](#Fine-tuning)
  30. - [Inference](#Inference)
  31. - [Description of random situation](#description-of-random-situation)
  32. - [others](#others)
  33. - [ModelZoo Homepage](#modelzoo-homepage)
  34. # MASS: Masked Sequence to Sequence Pre-training for Language Generation Description
  35. [MASS: Masked Sequence to Sequence Pre-training for Language Generation](https://www.microsoft.com/en-us/research/uploads/prod/2019/06/MASS-paper-updated-002.pdf) was released by MicroSoft in June 2019.
  36. BERT(Devlin et al., 2018) have achieved SOTA in natural language understanding area by pre-training the encoder part of Transformer(Vaswani et al., 2017) with masked rich-resource text. Likewise, GPT(Raddford et al., 2018) pre-trains the decoder part of Transformer with masked(encoder inputs are masked) rich-resource text. Both of them build a robust language model by pre-training with masked rich-resource text.
  37. Inspired by BERT, GPT and other language models, MicroSoft addressed [MASS: Masked Sequence to Sequence Pre-training for Language Generation](https://www.microsoft.com/en-us/research/uploads/prod/2019/06/MASS-paper-updated-002.pdf) which combines BERT's and GPT's idea. MASS has an important parameter k, which controls the masked fragment length. BERT and GPT are specicl case when k equals to 1 and sentence length.
  38. [Introducing MASS – A pre-training method that outperforms BERT and GPT in sequence to sequence language generation tasks](https://www.microsoft.com/en-us/research/blog/introducing-mass-a-pre-training-method-that-outperforms-bert-and-gpt-in-sequence-to-sequence-language-generation-tasks/)
  39. [Paper](https://www.microsoft.com/en-us/research/uploads/prod/2019/06/MASS-paper-updated-002.pdf): Song, Kaitao, Xu Tan, Tao Qin, Jianfeng Lu and Tie-Yan Liu. “MASS: Masked Sequence to Sequence Pre-training for Language Generation.” ICML (2019).
  40. # Model architecture
  41. The overall network architecture of MASS is shown below, which is Transformer(Vaswani et al., 2017):
  42. MASS is consisted of 6-layer encoder and 6-layer decoder with 1024 embedding/hidden size, and 4096 intermediate size between feed forward network which has two full connection layers.
  43. # Dataset
  44. Dataset used:
  45. - monolingual English data from News Crawl dataset(WMT 2019) for pre-training.
  46. - Gigaword Corpus(Graff et al., 2003) for Text Summarization.
  47. - Cornell movie dialog corpus(DanescuNiculescu-Mizil & Lee, 2011).
  48. Details about those dataset could be found in [MASS: Masked Sequence to Sequence Pre-training for Language Generation](https://www.microsoft.com/en-us/research/uploads/prod/2019/06/MASS-paper-updated-002.pdf).
  49. # Features
  50. Mass is designed to jointly pre train encoder and decoder to complete the task of language generation.
  51. First of all, through a sequence to sequence framework, mass only predicts the blocked token, which forces the encoder to understand the meaning of the unshielded token, and encourages the decoder to extract useful information from the encoder.
  52. Secondly, by predicting the continuous token of the decoder, the decoder can build better language modeling ability than only predicting discrete token.
  53. Third, by further shielding the input token of the decoder which is not shielded in the encoder, the decoder is encouraged to extract more useful information from the encoder side, rather than using the rich information in the previous token.
  54. # Script description
  55. MASS script and code structure are as follow:
  56. ```text
  57. ├── mass
  58. ├── README.md // Introduction of MASS model.
  59. ├── config
  60. │ ├──config.py // Configuration instance definition.
  61. │ ├──config.json // Configuration file.
  62. ├── src
  63. │ ├──dataset
  64. │ ├──bi_data_loader.py // Dataset loader for fine-tune or inferring.
  65. │ ├──mono_data_loader.py // Dataset loader for pre-training.
  66. │ ├──language_model
  67. │ ├──noise_channel_language_model.p // Noisy channel language model for dataset generation.
  68. │ ├──mass_language_model.py // MASS language model according to MASS paper.
  69. │ ├──loose_masked_language_model.py // MASS language model according to MASS released code.
  70. │ ├──masked_language_model.py // Masked language model according to MASS paper.
  71. │ ├──transformer
  72. │ ├──create_attn_mask.py // Generate mask matrix to remove padding positions.
  73. │ ├──transformer.py // Transformer model architecture.
  74. │ ├──encoder.py // Transformer encoder component.
  75. │ ├──decoder.py // Transformer decoder component.
  76. │ ├──self_attention.py // Self-Attention block component.
  77. │ ├──multi_head_attention.py // Multi-Head Self-Attention component.
  78. │ ├──embedding.py // Embedding component.
  79. │ ├──positional_embedding.py // Positional embedding component.
  80. │ ├──feed_forward_network.py // Feed forward network.
  81. │ ├──residual_conn.py // Residual block.
  82. │ ├──beam_search.py // Beam search decoder for inferring.
  83. │ ├──transformer_for_infer.py // Use Transformer to infer.
  84. │ ├──transformer_for_train.py // Use Transformer to train.
  85. │ ├──utils
  86. │ ├──byte_pair_encoding.py // Apply BPE with subword-nmt.
  87. │ ├──dictionary.py // Dictionary.
  88. │ ├──loss_moniter.py // Callback of monitering loss during training step.
  89. │ ├──lr_scheduler.py // Learning rate scheduler.
  90. │ ├──ppl_score.py // Perplexity score based on N-gram.
  91. │ ├──rouge_score.py // Calculate ROUGE score.
  92. │ ├──load_weights.py // Load weights from a checkpoint or NPZ file.
  93. │ ├──initializer.py // Parameters initializer.
  94. ├── vocab
  95. │ ├──all.bpe.codes // BPE codes table(this file should be generated by user).
  96. │ ├──all_en.dict.bin // Learned vocabulary file(this file should be generated by user).
  97. ├── scripts
  98. │ ├──run_ascend.sh // Ascend train & evaluate model script.
  99. │ ├──run_gpu.sh // GPU train & evaluate model script.
  100. │ ├──learn_subword.sh // Learn BPE codes.
  101. │ ├──stop_training.sh // Stop training.
  102. ├── requirements.txt // Requirements of third party package.
  103. ├── train.py // Train API entry.
  104. ├── eval.py // Infer API entry.
  105. ├── tokenize_corpus.py // Corpus tokenization.
  106. ├── apply_bpe_encoding.py // Applying bpe encoding.
  107. ├── weights_average.py // Average multi model checkpoints to NPZ format.
  108. ├── news_crawl.py // Create News Crawl dataset for pre-training.
  109. ├── gigaword.py // Create Gigaword Corpus.
  110. ├── cornell_dialog.py // Create Cornell Movie Dialog dataset for conversation response.
  111. ```
  112. ## Data Preparation
  113. The data preparation of a natural language processing task contains data cleaning, tokenization, encoding and vocabulary generation steps.
  114. In our experiments, using [Byte Pair Encoding(BPE)](https://arxiv.org/abs/1508.07909) could reduce size of vocabulary, and relieve the OOV influence effectively.
  115. Vocabulary could be created using `src/utils/dictionary.py` with text dictionary which is learnt from BPE.
  116. For more detail about BPE, please refer to [Subword-nmt lib](https://www.cnpython.com/pypi/subword-nmt) or [paper](https://arxiv.org/abs/1508.07909).
  117. In our experiments, vocabulary was learned based on 1.9M sentences from News Crawl Dataset, size of vocabulary is 45755.
  118. Here, we have a brief introduction of data preparation scripts.
  119. ### Tokenization
  120. Using `tokenize_corpus.py` could tokenize corpus whose text files are in format of `.txt`.
  121. Major parameters in `tokenize_corpus.py`:
  122. ```bash
  123. --corpus_folder: Corpus folder path, if multi-folders are provided, use ',' split folders.
  124. --output_folder: Output folder path.
  125. --tokenizer: Tokenizer to be used, nltk or jieba, if nltk is not installed fully, use jieba instead.
  126. --pool_size: Processes pool size.
  127. ```
  128. Sample code:
  129. ```bash
  130. python tokenize_corpus.py --corpus_folder /{path}/corpus --output_folder /{path}/tokenized_corpus --tokenizer {nltk|jieba} --pool_size 16
  131. ```
  132. ### Byte Pair Encoding
  133. After tokenization, BPE is applied to tokenized corpus with provided `all.bpe.codes`.
  134. Apply BPE script can be found in `apply_bpe_encoding.py`.
  135. Major parameters in `apply_bpe_encoding.py`:
  136. ```bash
  137. --codes: BPE codes file.
  138. --src_folder: Corpus folders.
  139. --output_folder: Output files folder.
  140. --prefix: Prefix of text file in `src_folder`.
  141. --vocab_path: Generated vocabulary output path.
  142. --threshold: Filter out words that frequency is lower than threshold.
  143. --processes: Size of process pool (to accelerate). Default: 2.
  144. ```
  145. Sample code:
  146. ```bash
  147. python tokenize_corpus.py --codes /{path}/all.bpe.codes \
  148. --src_folder /{path}/tokenized_corpus \
  149. --output_folder /{path}/tokenized_corpus/bpe \
  150. --prefix tokenized \
  151. --vocab_path /{path}/vocab_en.dict.bin
  152. --processes 32
  153. ```
  154. ### Build Vocabulary
  155. Support that you want to create a new vocabulary, there are two options:
  156. 1. Learn BPE codes from scratch, and create vocabulary with multi vocabulary files from `subword-nmt`.
  157. 2. Create from an existing vocabulary file which lines in the format of `word frequency`.
  158. 3. *Optional*, Create a small vocabulary based on `vocab/all_en.dict.bin` with method of `shink` from `src/utils/dictionary.py`.
  159. 4. Persistent vocabulary to `vocab` folder with method `persistence()`.
  160. Major interface of `src/utils/dictionary.py` are as follow:
  161. 1. `shrink(self, threshold=50)`: Shrink the size of vocabulary by filter out words frequency is lower than threshold. It returns a new vocabulary.
  162. 2. `load_from_text(cls, filepaths: List[str])`: Load existed text vocabulary which lines in the format of `word frequency`.
  163. 3. `load_from_persisted_dict(cls, filepath)`: Load from a persisted binary vocabulary which was saved by calling `persistence()` method.
  164. 4. `persistence(self, path)`: Save vocabulary object to binary file.
  165. Sample code:
  166. ```python
  167. from src.utils import Dictionary
  168. vocabulary = Dictionary.load_from_persisted_dict("vocab/all_en.dict.bin")
  169. tokens = [1, 2, 3, 4, 5]
  170. # Convert ids to symbols.
  171. print([vocabulary[t] for t in tokens])
  172. sentence = ["Hello", "world"]
  173. # Convert symbols to ids.
  174. print([vocabulary.index[s] for s in sentence])
  175. ```
  176. For more detail, please refer to the source file.
  177. ### Generate Dataset
  178. As mentioned above, three corpus are used in MASS mode, dataset generation scripts for them are provided.
  179. #### News Crawl Corpus
  180. Script can be found in `news_crawl.py`.
  181. Major parameters in `news_crawl.py`:
  182. ```bash
  183. Note that please provide `--existed_vocab` or `--dict_folder` at least one.
  184. A new vocabulary would be created in `output_folder` when pass `--dict_folder`.
  185. --src_folder: Corpus folders.
  186. --existed_vocab: Optional, persisted vocabulary file.
  187. --mask_ratio: Ratio of mask.
  188. --output_folder: Output dataset files folder path.
  189. --max_len: Maximum sentence length. If a sentence longer than `max_len`, then drop it.
  190. --suffix: Optional, suffix of generated dataset files.
  191. --processes: Optional, size of process pool (to accelerate). Default: 2.
  192. ```
  193. Sample code:
  194. ```bash
  195. python news_crawl.py --src_folder /{path}/news_crawl \
  196. --existed_vocab /{path}/mass/vocab/all_en.dict.bin \
  197. --mask_ratio 0.5 \
  198. --output_folder /{path}/news_crawl_dataset \
  199. --max_len 32 \
  200. --processes 32
  201. ```
  202. #### Gigaword Corpus
  203. Script can be found in `gigaword.py`.
  204. Major parameters in `gigaword.py`:
  205. ```bash
  206. --train_src: Train source file path.
  207. --train_ref: Train reference file path.
  208. --test_src: Test source file path.
  209. --test_ref: Test reference file path.
  210. --existed_vocab: Persisted vocabulary file.
  211. --output_folder: Output dataset files folder path.
  212. --noise_prob: Optional, add noise prob. Default: 0.
  213. --max_len: Optional, maximum sentence length. If a sentence longer than `max_len`, then drop it. Default: 64.
  214. --format: Optional, dataset format, "mindrecord" or "tfrecord". Default: "tfrecord".
  215. ```
  216. Sample code:
  217. ```bash
  218. python gigaword.py --train_src /{path}/gigaword/train_src.txt \
  219. --train_ref /{path}/gigaword/train_ref.txt \
  220. --test_src /{path}/gigaword/test_src.txt \
  221. --test_ref /{path}/gigaword/test_ref.txt \
  222. --existed_vocab /{path}/mass/vocab/all_en.dict.bin \
  223. --noise_prob 0.1 \
  224. --output_folder /{path}/gigaword_dataset \
  225. --max_len 64
  226. ```
  227. #### Cornell Movie Dialog Corpus
  228. Script can be found in `cornell_dialog.py`.
  229. Major parameters in `cornell_dialog.py`:
  230. ```bash
  231. --src_folder: Corpus folders.
  232. --existed_vocab: Persisted vocabulary file.
  233. --train_prefix: Train source and target file prefix. Default: train.
  234. --test_prefix: Test source and target file prefix. Default: test.
  235. --output_folder: Output dataset files folder path.
  236. --max_len: Maximum sentence length. If a sentence longer than `max_len`, then drop it.
  237. --valid_prefix: Optional, Valid source and target file prefix. Default: valid.
  238. ```
  239. Sample code:
  240. ```bash
  241. python cornell_dialog.py --src_folder /{path}/cornell_dialog \
  242. --existed_vocab /{path}/mass/vocab/all_en.dict.bin \
  243. --train_prefix train \
  244. --test_prefix test \
  245. --noise_prob 0.1 \
  246. --output_folder /{path}/cornell_dialog_dataset \
  247. --max_len 64
  248. ```
  249. ## Configuration
  250. Json file under the path `config/` is the template configuration file.
  251. Almost all of the options and arguments needed could be assigned conveniently, including the training platform, configurations of dataset and model, arguments of optimizer etc. Optional features such as loss scale and checkpoint are also available by setting the options correspondingly.
  252. For more detailed information about the attributes, refer to the file `config/config.py`.
  253. ## Training & Evaluation process
  254. For training a model, the shell script `run_ascend.sh` or `run_gpu.sh` is all you need. In this scripts, the environment variable is set and the training script `train.py` under `mass` is executed.
  255. You may start a task training with single device or multiple devices by assigning the options and run the command in bash:
  256. Ascend:
  257. ```ascend
  258. sh run_ascend.sh [--options]
  259. ```
  260. GPU:
  261. ```gpu
  262. sh run_gpu.sh [--options]
  263. ```
  264. The usage of `run_ascend.sh` is shown as below:
  265. ```text
  266. Usage: run_ascend.sh [-h, --help] [-t, --task <CHAR>] [-n, --device_num <N>]
  267. [-i, --device_id <N>] [-j, --hccl_json <FILE>]
  268. [-c, --config <FILE>] [-o, --output <FILE>]
  269. [-v, --vocab <FILE>]
  270. options:
  271. -h, --help show usage
  272. -t, --task select task: CHAR, 't' for train and 'i' for inference".
  273. -n, --device_num device number used for training: N, default is 1.
  274. -i, --device_id device id used for training with single device: N, 0<=N<=7, default is 0.
  275. -j, --hccl_json rank table file used for training with multiple devices: FILE.
  276. -c, --config configuration file as shown in the path 'mass/config': FILE.
  277. -o, --output assign output file of inference: FILE.
  278. -v, --vocab set the vocabulary.
  279. -m, --metric set the metric.
  280. ```
  281. Notes: Be sure to assign the hccl_json file while running a distributed-training.
  282. The usage of `run_gpu.sh` is shown as below:
  283. ```text
  284. Usage: run_gpu.sh [-h, --help] [-t, --task <CHAR>] [-n, --device_num <N>]
  285. [-i, --device_id <N>] [-c, --config <FILE>]
  286. [-o, --output <FILE>] [-v, --vocab <FILE>]
  287. options:
  288. -h, --help show usage
  289. -t, --task select task: CHAR, 't' for train and 'i' for inference".
  290. -n, --device_num device number used for training: N, default is 1.
  291. -i, --device_id device id used for training with single device: N, 0<=N<=7, default is 0.
  292. -c, --config configuration file as shown in the path 'mass/config': FILE.
  293. -o, --output assign output file of inference: FILE.
  294. -v, --vocab set the vocabulary.
  295. -m, --metric set the metric.
  296. ```
  297. The command followed shows a example for training with 2 devices.
  298. Ascend:
  299. ```ascend
  300. sh run_ascend.sh --task t --device_num 2 --hccl_json /{path}/rank_table.json --config /{path}/config.json
  301. ```
  302. ps. Discontinuous device id is not supported in `run_ascend.sh` at present, device id in `rank_table.json` must start from 0.
  303. GPU:
  304. ```gpu
  305. sh run_gpu.sh --task t --device_num 2 --config /{path}/config.json
  306. ```
  307. If use a single chip, it would be like this:
  308. Ascend:
  309. ```ascend
  310. sh run_ascend.sh --task t --device_num 1 --device_id 0 --config /{path}/config.json
  311. ```
  312. GPU:
  313. ```gpu
  314. sh run_gpu.sh --task t --device_num 1 --device_id 0 --config /{path}/config.json
  315. ```
  316. ## Weights average
  317. ```python
  318. python weights_average.py --input_files your_checkpoint_list --output_file model.npz
  319. ```
  320. The input_files is a list of you checkpoints file. To use model.npz as the weights, add its path in config.json at "existed_ckpt".
  321. ```json
  322. {
  323. ...
  324. "checkpoint_options": {
  325. "existed_ckpt": "/xxx/xxx/model.npz",
  326. "save_ckpt_steps": 1000,
  327. ...
  328. },
  329. ...
  330. }
  331. ```
  332. ## Learning rate scheduler
  333. Two learning rate scheduler are provided in our model:
  334. 1. [Polynomial decay scheduler](https://towardsdatascience.com/learning-rate-schedules-and-adaptive-learning-rate-methods-for-deep-learning-2c8f433990d1).
  335. 2. [Inverse square root scheduler](https://ece.uwaterloo.ca/~dwharder/aads/Algorithms/Inverse_square_root/).
  336. LR scheduler could be config in `config/config.json`.
  337. For Polynomial decay scheduler, config could be like:
  338. ```json
  339. {
  340. ...
  341. "learn_rate_config": {
  342. "optimizer": "adam",
  343. "lr": 1e-4,
  344. "lr_scheduler": "poly",
  345. "poly_lr_scheduler_power": 0.5,
  346. "decay_steps": 10000,
  347. "warmup_steps": 2000,
  348. "min_lr": 1e-6
  349. },
  350. ...
  351. }
  352. ```
  353. For Inverse square root scheduler, config could be like:
  354. ```json
  355. {
  356. ...
  357. "learn_rate_config": {
  358. "optimizer": "adam",
  359. "lr": 1e-4,
  360. "lr_scheduler": "isr",
  361. "decay_start_step": 12000,
  362. "warmup_steps": 2000,
  363. "min_lr": 1e-6
  364. },
  365. ...
  366. }
  367. ```
  368. More detail about LR scheduler could be found in `src/utils/lr_scheduler.py`.
  369. # Model description
  370. The MASS network is implemented by Transformer, which has multi-encoder layers and multi-decoder layers.
  371. For pre-training, we use the Adam optimizer and loss-scale to get the pre-trained model.
  372. During fine-turning, we fine-tune this pre-trained model with different dataset according to different tasks.
  373. During testing, we use the fine-turned model to predict the result, and adopt a beam search algorithm to
  374. get the most possible prediction results.
  375. ## Performance
  376. ### Results
  377. #### Fine-Tuning on Text Summarization
  378. The comparisons between MASS and two other pre-training methods in terms of ROUGE score on the text summarization task
  379. with 3.8M training data are as follows:
  380. | Method | RG-1(F) | RG-2(F) | RG-L(F) |
  381. |:---------------|:--------------|:-------------|:-------------|
  382. | MASS | Ongoing | Ongoing | Ongoing |
  383. #### Fine-Tuning on Conversational ResponseGeneration
  384. The comparisons between MASS and other baseline methods in terms of PPL on Cornell Movie Dialog corpus are as follows:
  385. | Method | Data = 10K | Data = 110K |
  386. |--------------------|------------------|-----------------|
  387. | MASS | Ongoing | Ongoing |
  388. #### Training Performance
  389. | Parameters | Masked Sequence to Sequence Pre-training for Language Generation |
  390. |:---------------------------|:--------------------------------------------------------------------------|
  391. | Model Version | v1 |
  392. | Resource | Ascend 910; cpu 2.60GHz, 56cores; memory 314G; OS Euler2.8 |
  393. | uploaded Date | 05/24/2020 |
  394. | MindSpore Version | 0.2.0 |
  395. | Dataset | News Crawl 2007-2017 English monolingual corpus, Gigaword corpus, Cornell Movie Dialog corpus |
  396. | Training Parameters | Epoch=50, steps=XXX, batch_size=192, lr=1e-4 |
  397. | Optimizer | Adam |
  398. | Loss Function | Label smoothed cross-entropy criterion |
  399. | outputs | Sentence and probability |
  400. | Loss | Lower than 2 |
  401. | Accuracy | For conversation response, ppl=23.52, for text summarization, RG-1=29.79. |
  402. | Speed | 611.45 sentences/s |
  403. | Total time | --/-- |
  404. | Params (M) | 44.6M |
  405. | Checkpoint for Fine tuning | ---Mb, --, [A link]() |
  406. | Model for inference | ---Mb, --, [A link]() |
  407. | Scripts | [A link]() |
  408. #### Inference Performance
  409. | Parameters | Masked Sequence to Sequence Pre-training for Language Generation |
  410. |:---------------------------|:-----------------------------------------------------------|
  411. | Model Version | V1 |
  412. | Resource | Huawei 910 |
  413. | uploaded Date | 05/24/2020 |
  414. | MindSpore Version | 0.2.0 |
  415. | Dataset | Gigaword corpus, Cornell Movie Dialog corpus |
  416. | batch_size | --- |
  417. | outputs | Sentence and probability |
  418. | Accuracy | ppl=23.52 for conversation response, RG-1=29.79 for text summarization. |
  419. | Speed | ---- sentences/s |
  420. | Total time | --/-- |
  421. | Model for inference | ---Mb, --, [A link]() |
  422. # Environment Requirements
  423. ## Platform
  424. - Hardware(Ascend)
  425. - Prepare hardware environment with Ascend processor.
  426. - Framework
  427. - [MindSpore](https://www.mindspore.cn/install/en)
  428. - For more information, please check the resources below:
  429. - [MindSpore tutorials](https://www.mindspore.cn/tutorial/training/en/master/index.html)
  430. - [MindSpore Python API](https://www.mindspore.cn/doc/api_python/en/master/index.html)
  431. ## Requirements
  432. ```txt
  433. nltk
  434. numpy
  435. subword-nmt
  436. rouge
  437. ```
  438. <https://www.mindspore.cn/tutorial/training/en/master/advanced_use/migrate_3rd_scripts.html>
  439. # Get started
  440. MASS pre-trains a sequence to sequence model by predicting the masked fragments in an input sequence. After this, downstream tasks including text summarization and conversation response are candidated for fine-tuning the model and for inference.
  441. Here we provide a practice example to demonstrate the basic usage of MASS for pre-training, fine-tuning a model, and the inference process. The overall process is as follows:
  442. 1. Download and process the dataset.
  443. 2. Modify the `config.json` to config the network.
  444. 3. Run a task for pre-training and fine-tuning.
  445. 4. Perform inference and validation.
  446. ## Pre-training
  447. For pre-training a model, config the options in `config.json` firstly:
  448. - Assign the `pre_train_dataset` under `dataset_config` node to the dataset path.
  449. - Choose the optimizer('momentum/adam/lamb' is available).
  450. - Assign the 'ckpt_prefix' and 'ckpt_path' under `checkpoint_path` to save the model files.
  451. - Set other arguments including dataset configurations and network configurations.
  452. - If you have a trained model already, assign the `existed_ckpt` to the checkpoint file.
  453. If you use the ascend chip, run the shell script `run_ascend.sh` as followed:
  454. ```ascend
  455. sh run_ascend.sh -t t -n 1 -i 1 -c /mass/config/config.json
  456. ```
  457. You can also run the shell script `run_gpu.sh` on gpu as followed:
  458. ```gpu
  459. sh run_gpu.sh -t t -n 1 -i 1 -c /mass/config/config.json
  460. ```
  461. Get the log and output files under the path `./train_mass_*/`, and the model file under the path assigned in the `config/config.json` file.
  462. ## Fine-tuning
  463. For fine-tuning a model, config the options in `config.json` firstly:
  464. - Assign the `fine_tune_dataset` under `dataset_config` node to the dataset path.
  465. - Assign the `existed_ckpt` under `checkpoint_path` node to the existed model file generated by pre-training.
  466. - Choose the optimizer('momentum/adam/lamb' is available).
  467. - Assign the `ckpt_prefix` and `ckpt_path` under `checkpoint_path` node to save the model files.
  468. - Set other arguments including dataset configurations and network configurations.
  469. If you use the ascend chip, run the shell script `run_ascend.sh` as followed:
  470. ```ascend
  471. sh run_ascend.sh -t t -n 1 -i 1 -c config/config.json
  472. ```
  473. You can also run the shell script `run_gpu.sh` on gpu as followed:
  474. ```gpu
  475. sh run_gpu.sh -t t -n 1 -i 1 -c config/config.json
  476. ```
  477. Get the log and output files under the path `./train_mass_*/`, and the model file under the path assigned in the `config/config.json` file.
  478. ## Inference
  479. If you need to use the trained model to perform inference on multiple hardware platforms, such as GPU, Ascend 910 or Ascend 310, you can refer to this [Link](https://www.mindspore.cn/tutorial/training/en/master/advanced_use/migrate_3rd_scripts.html).
  480. For inference, config the options in `config.json` firstly:
  481. - Assign the `test_dataset` under `dataset_config` node to the dataset path.
  482. - Assign the `existed_ckpt` under `checkpoint_path` node to the model file produced by fine-tuning.
  483. - Choose the optimizer('momentum/adam/lamb' is available).
  484. - Assign the `ckpt_prefix` and `ckpt_path` under `checkpoint_path` node to save the model files.
  485. - Set other arguments including dataset configurations and network configurations.
  486. If you use the ascend chip, run the shell script `run_ascend.sh` as followed:
  487. ```bash
  488. sh run_ascend.sh -t i -n 1 -i 1 -c config/config.json -o {outputfile}
  489. ```
  490. You can also run the shell script `run_gpu.sh` on gpu as followed:
  491. ```gpu
  492. sh run_gpu.sh -t i -n 1 -i 1 -c config/config.json -o {outputfile}
  493. ```
  494. # Description of random situation
  495. MASS model contains dropout operations, if you want to disable dropout, please set related dropout_rate to 0 in `config/config.json`.
  496. # others
  497. The model has been validated on Ascend environment, not validated on CPU and GPU.
  498. # ModelZoo Homepage
  499. [Link](https://gitee.com/mindspore/mindspore/tree/master/model_zoo)