RepoBaidu (ERNIE)Baidu (ERNIE)published Sep 24, 2019seen 5d

PaddlePaddle/PALM

Python

Open original ↗

Captured source

source ↗
published Sep 24, 2019seen 5dcaptured 13hhttp 200method plain

PaddlePaddle/PALM

Description: a Fast, Flexible, Extensible and Easy-to-use NLP Large-scale Pretraining and Multi-task Learning Framework.

Language: Python

Stars: 185

Forks: 30

Open issues: 11

Created: 2019-09-24T05:37:22Z

Pushed: 2021-03-29T11:40:54Z

Default branch: master

Fork: no

Archived: yes

README:

PaddlePALM

English | [简体中文](./README_zh.md)

PaddlePALM (PArallel Learning from Multi-tasks) is a fast, flexible, extensible and easy-to-use NLP large-scale pretraining and multi-task learning framework. PaddlePALM is a high level framework aiming at fastly developing high-performance NLP models.

With PaddlePALM, it is easy to achieve effecient exploration of robust learning of NLP models with multiple auxilary tasks. For example, based on PaddlePALM, the produced robust MRC model, D-Net, has achieved the 1st place in EMNLP2019 MRQA track.

MRQA2019 Leaderboard

Beyond the research scope, PaddlePALM has been applied on Baidu Search Engine to seek for more accurate user query understanding and answer mining, which implies the high reliability and performance of PaddlePALM.

Features:

  • Easy-to-use: with PALM, *8 steps* to achieve a typical NLP task. Moreover, all basic components (e.g., the model backbone, dataset reader, task output head, optimizer...) have been decoupled, which allows the replacement of any component to other candidates with quite minor changes of your code.
  • Built-in Popular NLP Backbones and Pre-trained models: multiple state-of-the-art general purpose model architectures and pretrained models (e.g., BERT,ERNIE,RoBERTa,...) are built-in.
  • Easy to play Multi-task Learning: only one API is needed for jointly training of several tasks with parameters reusement.
  • Support train/eval with Multi-GPUs: automatically recognize and adapt to multiple gpus mode to accelerate training and inference.
  • Pre-training friendly: self-supervised tasks (e.g., mask language model) are built-in to facilitate pre-training. Easy to train from scratch.
  • Easy to Customize: support customized development of any component (e.g, backbone, task head, reader and optimizer) with reusement of pre-defined ones, which gives developers high flexibility and effeciency to adapt for diverse NLP scenes.

You can easily re-produce following competitive results with minor codes, which covers most of NLP tasks such as classification, matching, sequence labeling, reading comprehension, dialogue understanding and so on. More details can be found in examples.

Dataset

chnsenticorp Quora Question Pairs matching MSRA-NER (SIGHAN2006) CMRC2018

Metric

accuracy

f1-score

accuracy

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

Overview

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.

pip install paddlepalm

Installing via source

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 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):

>>> from paddlepalm import downloader
>>> downloader.ls('pretrain')
Available pretrain items:
=>…

Excerpt shown — open the source for the full document.