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

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