From 062ef953fdf6d550f22bb0ca3a02d31c3c1b3129 Mon Sep 17 00:00:00 2001
From: xixiaoyao
+
+
+ MRQA2019 Leaderboard
+
Dataset
+ |
+ MSRA-NER (SIGHAN2006) |
+ CMRC2018 | +|||||
---|---|---|---|---|---|---|---|
+
+ Metric
+ |
+
+ |
+
+ f1-score
+
+ |
+
+ |
+
+ f1-score
+
+ |
+
+ f1-score
+
+ |
+
+ em
+ |
+
+ f1-score
+ |
+
+ test
+ |
+
+ test
+ |
+
+ test
+ |
+
+ dev
+ |
+ ||||
ERNIE Base | +95.8 | +95.8 | +86.2 | +82.2 | +99.2 | +64.3 | +85.2 | +
+ +
+ Architecture Diagram +
+ + + PaddlePALM is a well-designed high-level NLP framework. You can efficiently achieve **supervised learning, unsupervised/self-supervised learning, multi-task learning and transfer learning** with minor codes based on PaddlePALM. There are three layers in PaddlePALM architecture, i.e., component layer, trainer layer and high-level trainer layer from bottom to top. + + In component layer, PaddlePALM supplies 6 **decoupled** components to achieve a NLP task. Each component contains rich `pre-defined` classes and a `Base` class. Pre-defined classes are aiming at typical NLP tasks, and the base class is to help users develop a new Class (based on pre-defined ones or from the base). + + The trainer layer is to establish a computation graph with selected components and do training and predicting. The training strategy, model saving and loading, evaluation and predicting procedures are described in this layer. Noted a trainer can only process one task. + + The high-level trainer layer is for complicated learning and inference strategy, e.g., multi-task learning. You can add auxilary tasks to train robust NLP models (improve test set and out-of-domain performance of a model), or jointly training multiple related tasks to gain more performance for each task. + + | module | illustration | + | - | - | + | **paddlepalm** | an open source NLP pretraining and multitask learning framework, built on paddlepaddle. | + | **paddlepalm.reader** | a collection of elastic task-specific dataset readers. | + | **paddlepalm.backbone** | a collection of classic NLP representation models, e.g., BERT, ERNIE, RoBERTa. | + | **paddlepalm.head** | a collection of task-specific output layers. | + | **paddlepalm.lr_sched** | a collection of learning rate schedualers. | + | **paddlepalm.optimizer** | a collection of optimizers. | + | **paddlepalm.downloader** | a download module for pretrained models with configure and vocab files. | + | **paddlepalm.Trainer** | the core unit to start a single task training/predicting session. A trainer is to build computation graph, manage training and evaluation process, achieve model/checkpoint saving and pretrain_model/checkpoint loading.| + | **paddlepalm.MultiHeadTrainer** | the core unit to start a multi-task training/predicting session. A MultiHeadTrainer is built based on several Trainers. Beyond the inheritance of Trainer, it additionally achieves model backbone reuse across tasks, trainer sampling for multi-task learning, and multi-head inference for effective evaluation and prediction. | + + + ## Installation + + PaddlePALM support both python2 and python3, linux and windows, CPU and GPU. The preferred way to install PaddlePALM is via `pip`. Just run following commands in your shell. + + ```bash + pip install paddlepalm + ``` + + ### Installing via source + + ```shell + git clone https://github.com/PaddlePaddle/PALM.git + cd PALM && python setup.py install + ``` + + ### Library Dependencies + - Python >= 2.7 + - cuda >= 9.0 + - cudnn >= 7.0 + - PaddlePaddle >= 1.7.0 (Please refer to [this](http://www.paddlepaddle.org/#quick-start) to install) + + + ### Downloading pretrain models + We incorporate many pretrained models to initialize model backbone parameters. Training big NLP model, e.g., 12-layer transformers, with pretrained models is practically much more effective than that with randomly initialized parameters. To see all the available pretrained models and download, run following code in python interpreter (input command `python` in shell): + + ```python + >>> from paddlepalm import downloader + >>> downloader.ls('pretrain') + Available pretrain items: + => RoBERTa-zh-base + => RoBERTa-zh-large + => ERNIE-v2-en-base + => ERNIE-v2-en-large + => XLNet-cased-base + => XLNet-cased-large + => ERNIE-v1-zh-base + => ERNIE-v1-zh-base-max-len-512 + => BERT-en-uncased-large-whole-word-masking + => BERT-en-cased-large-whole-word-masking + => BERT-en-uncased-base + => BERT-en-uncased-large + => BERT-en-cased-base + => BERT-en-cased-large + => BERT-multilingual-uncased-base + => BERT-multilingual-cased-base + => BERT-zh-base + + >>> downloader.download('pretrain', 'BERT-en-uncased-base', './pretrain_models') + ... + ``` + + + ## Usage + + #### Quick Start + + 8 steps to start a typical NLP training task. + + 1. use `paddlepalm.reader` to create a *reader* for dataset loading and input features generation, then call `reader.load_data` method to load your training data. + 2. use `paddlepalm.backbone` to create a model *backbone* to extract text features (e.g., contextual word embedding, sentence embedding). + 3. register your *reader* with your *backbone* through `reader.register_with` method. After this step, your reader is able to yield input features used by backbone. + 4. use `paddlepalm.head` to create a task output *head*. This head can provide task loss for training and predicting results for model inference. + 5. create a task *trainer* with `paddlepalm.Trainer`, then build forward graph with backbone and task head (created in step 2 and 4) through `trainer.build_forward`. + 6. use `paddlepalm.optimizer` (and `paddlepalm.lr_sched` if is necessary) to create a *optimizer*, then build backward through `trainer.build_backward`. + 7. fit prepared reader and data (achieved in step 1) to trainer with `trainer.fit_reader` method. + 8. load pretrain model with `trainer.load_pretrain`, or load checkpoint with `trainer.load_ckpt` or nothing to do for training from scratch, then do training with `trainer.train`. + + For more implementation details, see following demos: + + - [Sentiment Classification](https://github.com/PaddlePaddle/PALM/tree/master/examples/classification) + - [Question Pairs matching](https://github.com/PaddlePaddle/PALM/tree/master/examples/matching) + - [Named Entity Recognition](https://github.com/PaddlePaddle/PALM/tree/master/examples/tagging) + - [SQuAD-like Machine Reading Comprehension](https://github.com/PaddlePaddle/PALM/tree/master/examples/mrc). + + + #### Multi-task Learning + To run with multi-task learning mode: + + 1. repeatedly create components (i.e., reader, backbone and head) for each task followed with step 1~5 above. + 2. create empty trainers (each trainer is corresponded to one task) and pass them to create a `MultiHeadTrainer`. + 3. build multi-task forward graph with `multi_head_trainer.build_forward` method. + 4. use `paddlepalm.optimizer` (and `paddlepalm.lr_sched` if is necessary) to create a *optimizer*, then build backward through `multi_head_trainer.build_backward`. + 5. fit all prepared readers and data to multi_head_trainer with `multi_head_trainer.fit_readers` method. + 6. load pretrain model with `multi_head_trainer.load_pretrain`, or load checkpoint with `multi_head_trainer.load_ckpt` or nothing to do for training from scratch, then do training with `multi_head_trainer.train`. + + The save/load and predict operations of a multi_head_trainer is the same as a trainer. + + For more implementation details with `multi_head_trainer`, see + + - [ATIS: joint training of dialogue intent recognition and slot filling](https://github.com/PaddlePaddle/PALM/tree/master/examples/multi-task) + + #### Save models + + To save models/checkpoints and logs during training, just call `trainer.set_saver` method. More implementation details see [this](https://github.com/PaddlePaddle/PALM/tree/master/examples). + + #### Evaluation/Inference + To do predict/evaluation after a training stage, just create another three reader, backbone and head instance with `phase='predict'` (repeat step 1~4 above). Then do predicting with `predict` method in trainer (no need to create another trainer). More implementation details see [this](https://github.com/PaddlePaddle/PALM/tree/master/examples/predict). + + #### Play with Multiple GPUs + If there exists multiple GPUs in your environment, you can control the number and index of these GPUs through the environment variable [CUDA_VISIBLE_DEVICES](https://devblogs.nvidia.com/cuda-pro-tip-control-gpu-visibility-cuda_visible_devices/). For example, if 4 GPUs in your enviroment, indexed with 0,1,2,3, you can run with GPU2 only with following commands + + ```shell + CUDA_VISIBLE_DEVICES=2 python run.py + ``` + + Multiple GPUs should be seperated with `,`. For example, running with GPU2 and GPU3, following commands is refered: + + ```shell + CUDA_VISIBLE_DEVICES=2,3 python run.py + ``` + + On multi-gpu mode, PaddlePALM will automatically split each batch onto the available cards. For example, if the `batch_size` is set 64, and there are 4 cards visible for PaddlePALM, then the batch_size in each card is actually 64/4=16. Therefore, when running with multiple cards, **you need to ensure that the set batch_size can be divided by the number of cards.** + + ## License + + This tutorial is contributed by [PaddlePaddle](https://github.com/PaddlePaddle/Paddle) and licensed under the [Apache-2.0 license](https://github.com/PaddlePaddle/models/blob/develop/LICENSE). + + +Keywords: paddlepaddle,paddle,nlp,pretrain,multi-task-learning +Platform: any +Classifier: License :: OSI Approved :: Apache Software License +Classifier: Programming Language :: Python +Classifier: Programming Language :: Python :: 2 +Classifier: Programming Language :: Python :: 2.7 +Classifier: Programming Language :: Python :: 3 +Classifier: Programming Language :: Python :: 3.5 +Classifier: Programming Language :: Python :: 3.6 +Classifier: Programming Language :: Python :: 3.7 +Description-Content-Type: text/markdown diff --git a/paddlepalm.egg-info/SOURCES.txt b/paddlepalm.egg-info/SOURCES.txt new file mode 100644 index 0000000..8a611e7 --- /dev/null +++ b/paddlepalm.egg-info/SOURCES.txt @@ -0,0 +1,60 @@ +README.md +setup.cfg +setup.py +./paddlepalm/__init__.py +./paddlepalm/_downloader.py +./paddlepalm/downloader.py +./paddlepalm/multihead_trainer.py +./paddlepalm/trainer.py +./paddlepalm/backbone/__init__.py +./paddlepalm/backbone/base_backbone.py +./paddlepalm/backbone/bert.py +./paddlepalm/backbone/ernie.py +./paddlepalm/backbone/utils/__init__.py +./paddlepalm/backbone/utils/transformer.py +./paddlepalm/distribute/__init__.py +./paddlepalm/distribute/reader.py +./paddlepalm/head/__init__.py +./paddlepalm/head/base_head.py +./paddlepalm/head/cls.py +./paddlepalm/head/match.py +./paddlepalm/head/mlm.py +./paddlepalm/head/mrc.py +./paddlepalm/head/ner.py +./paddlepalm/lr_sched/__init__.py +./paddlepalm/lr_sched/base_schedualer.py +./paddlepalm/lr_sched/slanted_triangular_schedualer.py +./paddlepalm/lr_sched/warmup_schedualer.py +./paddlepalm/optimizer/__init__.py +./paddlepalm/optimizer/adam.py +./paddlepalm/optimizer/base_optimizer.py +./paddlepalm/reader/__init__.py +./paddlepalm/reader/base_reader.py +./paddlepalm/reader/cls.py +./paddlepalm/reader/match.py +./paddlepalm/reader/mlm.py +./paddlepalm/reader/mrc.py +./paddlepalm/reader/seq_label.py +./paddlepalm/reader/utils/__init__.py +./paddlepalm/reader/utils/batching4bert.py +./paddlepalm/reader/utils/batching4ernie.py +./paddlepalm/reader/utils/mlm_batching.py +./paddlepalm/reader/utils/mrqa_helper.py +./paddlepalm/reader/utils/reader4ernie.py +./paddlepalm/tokenizer/__init__.py +./paddlepalm/tokenizer/bert_tokenizer.py +./paddlepalm/tokenizer/ernie_tokenizer.py +./paddlepalm/utils/__init__.py +./paddlepalm/utils/basic_helper.py +./paddlepalm/utils/config_helper.py +./paddlepalm/utils/plot_helper.py +./paddlepalm/utils/print_helper.py +./paddlepalm/utils/reader_helper.py +./paddlepalm/utils/saver.py +./paddlepalm/utils/textprocess_helper.py +paddlepalm.egg-info/PKG-INFO +paddlepalm.egg-info/SOURCES.txt +paddlepalm.egg-info/dependency_links.txt +paddlepalm.egg-info/not-zip-safe +paddlepalm.egg-info/requires.txt +paddlepalm.egg-info/top_level.txt \ No newline at end of file diff --git a/paddlepalm.egg-info/dependency_links.txt b/paddlepalm.egg-info/dependency_links.txt new file mode 100644 index 0000000..8b13789 --- /dev/null +++ b/paddlepalm.egg-info/dependency_links.txt @@ -0,0 +1 @@ + diff --git a/paddlepalm.egg-info/not-zip-safe b/paddlepalm.egg-info/not-zip-safe new file mode 100644 index 0000000..8b13789 --- /dev/null +++ b/paddlepalm.egg-info/not-zip-safe @@ -0,0 +1 @@ + diff --git a/paddlepalm.egg-info/requires.txt b/paddlepalm.egg-info/requires.txt new file mode 100644 index 0000000..d60bf69 --- /dev/null +++ b/paddlepalm.egg-info/requires.txt @@ -0,0 +1 @@ +paddlepaddle-gpu>=1.7.0 diff --git a/paddlepalm.egg-info/top_level.txt b/paddlepalm.egg-info/top_level.txt new file mode 100644 index 0000000..b136828 --- /dev/null +++ b/paddlepalm.egg-info/top_level.txt @@ -0,0 +1 @@ +paddlepalm diff --git a/setup.cfg b/setup.cfg index 2a4c3d8..d25c843 100644 --- a/setup.cfg +++ b/setup.cfg @@ -5,7 +5,7 @@ name = paddlepalm author = zhangyiming author_email = zhangyiming04@baidu.com -version = 2.0.1 +version = 2.0.2 description = PaddlePALM long_description = file: README.md diff --git a/setup.py b/setup.py index 0f142ad..d923bc6 100644 --- a/setup.py +++ b/setup.py @@ -25,7 +25,7 @@ with open("README.md", "r") as fh: long_description = fh.read() setuptools.setup( name="paddlepalm", - version="2.0.1", + version="2.0.2", author="PaddlePaddle", author_email="zhangyiming04@baidu.com", description="a flexible, general and easy-to-use NLP large-scale pretraining and multi-task learning framework.", -- GitLab