1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
|
%global _empty_manifest_terminate_build 0
Name: python-paddlenlp
Version: 2.5.2
Release: 1
Summary: Easy-to-use and powerful NLP library with Awesome model zoo, supporting wide-range of NLP tasks from research to industrial applications, including Neural Search, Question Answering, Information Extraction and Sentiment Analysis end-to-end system.
License: Apache 2.0
URL: https://github.com/PaddlePaddle/PaddleNLP
Source0: https://mirrors.nju.edu.cn/pypi/web/packages/ac/30/204ab2e0e01222060db5684041d5c4a73dec0adb622e3397f88d15b38f94/paddlenlp-2.5.2.tar.gz
BuildArch: noarch
Requires: python3-jieba
Requires: python3-colorlog
Requires: python3-colorama
Requires: python3-seqeval
Requires: python3-dill
Requires: python3-multiprocess
Requires: python3-datasets
Requires: python3-tqdm
Requires: python3-paddlefsl
Requires: python3-sentencepiece
Requires: python3-huggingface-hub
Requires: python3-paddle2onnx
Requires: python3-Flask-Babel
Requires: python3-visualdl
Requires: python3-fastapi
Requires: python3-uvicorn
Requires: python3-typer
Requires: python3-rich
Requires: python3-ray[tune]
Requires: python3-hyperopt
Requires: python3-parameterized
Requires: python3-sentencepiece
Requires: python3-regex
Requires: python3-torch
Requires: python3-transformers
Requires: python3-fast-tokenizer-python
Requires: python3-jinja2
Requires: python3-sphinx
Requires: python3-sphinx-rtd-theme
Requires: python3-readthedocs-sphinx-search
Requires: python3-Markdown
Requires: python3-sphinx-copybutton
Requires: python3-sphinx-markdown-tables
Requires: python3-paddlepaddle
Requires: python3-ray[tune]
Requires: python3-hyperopt
Requires: python3-jinja2
Requires: python3-sphinx
Requires: python3-sphinx-rtd-theme
Requires: python3-readthedocs-sphinx-search
Requires: python3-Markdown
Requires: python3-sphinx-copybutton
Requires: python3-sphinx-markdown-tables
Requires: python3-paddlepaddle
Requires: python3-parameterized
Requires: python3-sentencepiece
Requires: python3-regex
Requires: python3-torch
Requires: python3-transformers
Requires: python3-fast-tokenizer-python
%description
<p align="center">
<a href="./LICENSE"><img src="https://img.shields.io/badge/license-Apache%202-dfd.svg"></a>
<a href="https://github.com/PaddlePaddle/PaddleNLP/releases"><img src="https://img.shields.io/github/v/release/PaddlePaddle/PaddleNLP?color=ffa"></a>
<a href=""><img src="https://img.shields.io/badge/python-3.6.2+-aff.svg"></a>
<a href=""><img src="https://img.shields.io/badge/os-linux%2C%20win%2C%20mac-pink.svg"></a>
<a href="https://github.com/PaddlePaddle/PaddleNLP/graphs/contributors"><img src="https://img.shields.io/github/contributors/PaddlePaddle/PaddleNLP?color=9ea"></a>
<a href="https://github.com/PaddlePaddle/PaddleNLP/commits"><img src="https://img.shields.io/github/commit-activity/m/PaddlePaddle/PaddleNLP?color=3af"></a>
<a href="https://pypi.org/project/paddlenlp/"><img src="https://img.shields.io/pypi/dm/paddlenlp?color=9cf"></a>
<a href="https://github.com/PaddlePaddle/PaddleNLP/issues"><img src="https://img.shields.io/github/issues/PaddlePaddle/PaddleNLP?color=9cc"></a>
<a href="https://github.com/PaddlePaddle/PaddleNLP/stargazers"><img src="https://img.shields.io/github/stars/PaddlePaddle/PaddleNLP?color=ccf"></a>
</p>
<h4 align="center">
<a href=#features> Features </a> |
<a href=#installation> Installation </a> |
<a href=#quick-start> Quick Start </a> |
<a href=#api-reference> API Reference </a> |
<a href=#community> Community </a>
</h4>
**PaddleNLP** is an *easy-to-use* and *powerful* NLP library with **Awesome** pre-trained model zoo, supporting wide-range of NLP tasks from research to industrial applications.
## News ๐ข
* ๐ฅ **Latest Features**
* ๐ Release **[UIE-X](./applications/information_extraction)**, an universal information extraction model that supports both document and text inputs.
* โฃ๏ธRelease **[Opinion Mining and Sentiment Analysis Models](./applications/sentiment_analysis/unified_sentiment_extraction)** based on UIE, including abilities of sentence-level and aspect-based sentiment classification, attribute extraction, opinion extraction, attribute aggregation and implicit opinion extraction.
* **2022.9.6 [PaddleNLPv2.4](https://github.com/PaddlePaddle/PaddleNLP/releases/tag/v2.4.0) Released!**
* ๐ NLP Tools: Released **[Pipelines](./pipelines)** which supports turn-key construction of search engine and question answering systems. It features a flexible design that is applicable for all kinds of NLP systems so you can build end-to-end NLP pipelines like Legos!
* ๐จ Industrial application: Release **[Complete Solution of Text Classification](./applications/text_classification)** covering various scenarios of text classification: multi-class, multi-label and hierarchical, it also supports **few-shot learning** and the training and optimization of **TrustAI**. Upgrade for [**UIE**](./model_zoo/uie) and release **UIE-M**, support both Chinese and English information extraction in a single model; release the data distillation solution for UIE to break the bottleneck of time-consuming of inference.
* ๐ญ AIGC: Release code generation SOTA model [**CodeGen**](./examples/code_generation/codegen) that supports multiple programming languages code generation. Integrate [**Text to Image Model**](https://github.com/PaddlePaddle/PaddleNLP/blob/develop/docs/model_zoo/taskflow.md#%E6%96%87%E5%9B%BE%E7%94%9F%E6%88%90) DALLยทE Mini, Disco Diffusion, Stable Diffusion, let's play and have some fun!
* ๐ช Framework upgrade: Release [**Auto Model Compression API**](./docs/compression.md), supports for pruning and quantization automatically, lower the barriers of model compression; Release [**Few-shot Prompt**](./applications/text_classification/multi_class/few-shot), includes the algorithms such as PET, P-Tuning and RGL.
## Features
#### <a href=#out-of-box-nlp-toolset> ๐ฆ Out-of-Box NLP Toolset </a>
#### <a href=#awesome-chinese-model-zoo> ๐ค Awesome Chinese Model Zoo </a>
#### <a href=#industrial-end-to-end-system> ๐๏ธ Industrial End-to-end System </a>
#### <a href=#high-performance-distributed-training-and-inference> ๐ High Performance Distributed Training and Inference </a>
### Out-of-Box NLP Toolset
Taskflow aims to provide off-the-shelf NLP pre-built task covering NLU and NLG technique, in the meanwhile with extreamly fast infernece satisfying industrial scenario.

For more usage please refer to [Taskflow Docs](./docs/model_zoo/taskflow.md).
### Awesome Chinese Model Zoo
#### ๐ Comprehensive Chinese Transformer Models
We provide **45+** network architectures and over **500+** pretrained models. Not only includes all the SOTA model like ERNIE, PLATO and SKEP released by Baidu, but also integrates most of the high-quality Chinese pretrained model developed by other organizations. Use `AutoModel` API to **โกSUPER FASTโก** download pretrained models of different architecture. We welcome all developers to contribute your Transformer models to PaddleNLP!
```python
from paddlenlp.transformers import *
ernie = AutoModel.from_pretrained('ernie-3.0-medium-zh')
bert = AutoModel.from_pretrained('bert-wwm-chinese')
albert = AutoModel.from_pretrained('albert-chinese-tiny')
roberta = AutoModel.from_pretrained('roberta-wwm-ext')
electra = AutoModel.from_pretrained('chinese-electra-small')
gpt = AutoModelForPretraining.from_pretrained('gpt-cpm-large-cn')
```
Due to the computation limitation, you can use the ERNIE-Tiny light models to accelerate the deployment of pretrained models.
```python
# 6L768H
ernie = AutoModel.from_pretrained('ernie-3.0-medium-zh')
# 6L384H
ernie = AutoModel.from_pretrained('ernie-3.0-mini-zh')
# 4L384H
ernie = AutoModel.from_pretrained('ernie-3.0-micro-zh')
# 4L312H
ernie = AutoModel.from_pretrained('ernie-3.0-nano-zh')
```
Unified API experience for NLP task like semantic representation, text classification, sentence matching, sequence labeling, question answering, etc.
```python
import paddle
from paddlenlp.transformers import *
tokenizer = AutoTokenizer.from_pretrained('ernie-3.0-medium-zh')
text = tokenizer('natural language processing')
# Semantic Representation
model = AutoModel.from_pretrained('ernie-3.0-medium-zh')
sequence_output, pooled_output = model(input_ids=paddle.to_tensor([text['input_ids']]))
# Text Classificaiton and Matching
model = AutoModelForSequenceClassification.from_pretrained('ernie-3.0-medium-zh')
# Sequence Labeling
model = AutoModelForTokenClassification.from_pretrained('ernie-3.0-medium-zh')
# Question Answering
model = AutoModelForQuestionAnswering.from_pretrained('ernie-3.0-medium-zh')
```
#### Wide-range NLP Task Support
PaddleNLP provides rich examples covering mainstream NLP task to help developers accelerate problem solving. You can find our powerful transformer [Model Zoo](./model_zoo), and wide-range NLP application [exmaples](./examples) with detailed instructions.
Also you can run our interactive [Notebook tutorial](https://aistudio.baidu.com/aistudio/personalcenter/thirdview/574995) on AI Studio, a powerful platform with **FREE** computing resource.
<details><summary> PaddleNLP Transformer model summary (<b>click to show details</b>) </summary><div>
| Model | Sequence Classification | Token Classification | Question Answering | Text Generation | Multiple Choice |
| :----------------- | ----------------------- | -------------------- | ------------------ | --------------- | --------------- |
| ALBERT | โ
| โ
| โ
| โ | โ
|
| BART | โ
| โ
| โ
| โ
| โ |
| BERT | โ
| โ
| โ
| โ | โ
|
| BigBird | โ
| โ
| โ
| โ | โ
|
| BlenderBot | โ | โ | โ | โ
| โ |
| ChineseBERT | โ
| โ
| โ
| โ | โ |
| ConvBERT | โ
| โ
| โ
| โ | โ
|
| CTRL | โ
| โ | โ | โ | โ |
| DistilBERT | โ
| โ
| โ
| โ | โ |
| ELECTRA | โ
| โ
| โ
| โ | โ
|
| ERNIE | โ
| โ
| โ
| โ | โ
|
| ERNIE-CTM | โ | โ
| โ | โ | โ |
| ERNIE-Doc | โ
| โ
| โ
| โ | โ |
| ERNIE-GEN | โ | โ | โ | โ
| โ |
| ERNIE-Gram | โ
| โ
| โ
| โ | โ |
| ERNIE-M | โ
| โ
| โ
| โ | โ |
| FNet | โ
| โ
| โ
| โ | โ
|
| Funnel-Transformer | โ
| โ
| โ
| โ | โ |
| GPT | โ
| โ
| โ | โ
| โ |
| LayoutLM | โ
| โ
| โ | โ | โ |
| LayoutLMv2 | โ | โ
| โ | โ | โ |
| LayoutXLM | โ | โ
| โ | โ | โ |
| LUKE | โ | โ
| โ
| โ | โ |
| mBART | โ
| โ | โ
| โ | โ
|
| MegatronBERT | โ
| โ
| โ
| โ | โ
|
| MobileBERT | โ
| โ | โ
| โ | โ |
| MPNet | โ
| โ
| โ
| โ | โ
|
| NEZHA | โ
| โ
| โ
| โ | โ
|
| PP-MiniLM | โ
| โ | โ | โ | โ |
| ProphetNet | โ | โ | โ | โ
| โ |
| Reformer | โ
| โ | โ
| โ | โ |
| RemBERT | โ
| โ
| โ
| โ | โ
|
| RoBERTa | โ
| โ
| โ
| โ | โ
|
| RoFormer | โ
| โ
| โ
| โ | โ |
| SKEP | โ
| โ
| โ | โ | โ |
| SqueezeBERT | โ
| โ
| โ
| โ | โ |
| T5 | โ | โ | โ | โ
| โ |
| TinyBERT | โ
| โ | โ | โ | โ |
| UnifiedTransformer | โ | โ | โ | โ
| โ |
| XLNet | โ
| โ
| โ
| โ | โ
|
</div></details>
For more pretrained model usage, please refer to [Transformer API Docs](./docs/model_zoo/index.rst).
### Industrial End-to-end System
We provide high value scenarios including information extraction, semantic retrieval, questionn answering high-value.
For more details industial cases please refer to [Applications](./applications).
#### ๐ Neural Search System
<div align="center">
<img src="https://user-images.githubusercontent.com/11793384/168514909-8817d79a-72c4-4be1-8080-93d1f682bb46.gif" width="400">
</div>
For more details please refer to [Neural Search](./applications/neural_search).
#### โ Question Answering System
We provide question answering pipeline which can support FAQ system, Document-level Visual Question answering system based on [๐RocketQA](https://github.com/PaddlePaddle/RocketQA).
<div align="center">
<img src="https://user-images.githubusercontent.com/11793384/168514868-1babe981-c675-4f89-9168-dd0a3eede315.gif" width="400">
</div>
For more details please refer to [Question Answering](./applications/question_answering) and [Document VQA](./applications/document_intelligence/doc_vqa).
#### ๐ Opinion Extraction and Sentiment Analysis
We build an opinion extraction system for product review and fine-grained sentiment analysis based on [SKEP](https://arxiv.org/abs/2005.05635) Model.
<div align="center">
<img src="https://user-images.githubusercontent.com/11793384/168407260-b7f92800-861c-4207-98f3-2291e0102bbe.png" width="300">
</div>
For more details please refer to [Sentiment Analysis](./applications/sentiment_analysis).
#### ๐๏ธ Speech Command Analysis
Integrated ASR Model, Information Extraction, we provide a speech command analysis pipeline that show how to use PaddleNLP and [PaddleSpeech](https://github.com/PaddlePaddle/PaddleSpeech) to solve Speech + NLP real scenarios.
<div align="center">
<img src="https://user-images.githubusercontent.com/11793384/168412618-04897a47-79c9-4fe7-a054-5dc1f6a1f75c.png" width="500">
</div>
For more details please refer to [Speech Command Analysis](./applications/speech_cmd_analysis).
### High Performance Distributed Training and Inference
#### โก FastTokenizer: High Performance Text Preprocessing Library
<div align="center">
<img src="https://user-images.githubusercontent.com/11793384/168407921-b4395b1d-44bd-41a0-8c58-923ba2b703ef.png" width="400">
</div>
```python
AutoTokenizer.from_pretrained("ernie-3.0-medium-zh", use_fast=True)
```
Set `use_fast=True` to use C++ Tokenizer kernel to achieve 100x faster on text pre-processing. For more usage please refer to [FastTokenizer](./fast_tokenizer).
#### โก FastGeneration: High Perforance Generation Library
<div align="center">
<img src="https://user-images.githubusercontent.com/11793384/168407831-914dced0-3a5a-40b8-8a65-ec82bf13e53c.gif" width="400">
</div>
```python
model = GPTLMHeadModel.from_pretrained('gpt-cpm-large-cn')
outputs, _ = model.generate(
input_ids=inputs_ids, max_length=10, decode_strategy='greedy_search',
use_fast=True)
```
Set `use_fast=True` to achieve 5x speedup for Transformer, GPT, BART, PLATO, UniLM text generation. For more usage please refer to [FastGeneration](./fast_generation).
#### ๐ Fleet: 4D Hybrid Distributed Training
<div align="center">
<img src="https://user-images.githubusercontent.com/11793384/168515134-513f13e0-9902-40ef-98fa-528271dcccda.png" width="300">
</div>
For more super large-scale model pre-training details please refer to [GPT-3](./examples/language_model/gpt-3).
## Installation
### Prerequisites
* python >= 3.7
* paddlepaddle >= 2.3
More information about PaddlePaddle installation please refer to [PaddlePaddle's Website](https://www.paddlepaddle.org.cn/install/quick?docurl=/documentation/docs/zh/install/conda/linux-conda.html).
### Python pip Installation
```
pip install --upgrade paddlenlp
```
or you can install the latest develop branch code with the following command:
```shell
pip install --pre --upgrade paddlenlp -f https://www.paddlepaddle.org.cn/whl/paddlenlp.html
```
## Quick Start
**Taskflow** aims to provide off-the-shelf NLP pre-built task covering NLU and NLG scenario, in the meanwhile with extreamly fast infernece satisfying industrial applications.
```python
from paddlenlp import Taskflow
# Chinese Word Segmentation
seg = Taskflow("word_segmentation")
seg("็ฌฌๅๅๅฑๅ
จ่ฟไผๅจ่ฅฟๅฎไธพๅ")
>>> ['็ฌฌๅๅๅฑ', 'ๅ
จ่ฟไผ', 'ๅจ', '่ฅฟๅฎ', 'ไธพๅ']
# POS Tagging
tag = Taskflow("pos_tagging")
tag("็ฌฌๅๅๅฑๅ
จ่ฟไผๅจ่ฅฟๅฎไธพๅ")
>>> [('็ฌฌๅๅๅฑ', 'm'), ('ๅ
จ่ฟไผ', 'nz'), ('ๅจ', 'p'), ('่ฅฟๅฎ', 'LOC'), ('ไธพๅ', 'v')]
# Named Entity Recognition
ner = Taskflow("ner")
ner("ใๅญคๅฅณใๆฏ2010ๅนดไนๅทๅบ็็คพๅบ็็ๅฐ่ฏด๏ผไฝ่
ๆฏไฝๅ
ผ็พฝ")
>>> [('ใ', 'w'), ('ๅญคๅฅณ', 'ไฝๅ็ฑป_ๅฎไฝ'), ('ใ', 'w'), ('ๆฏ', '่ฏๅฎ่ฏ'), ('2010ๅนด', 'ๆถ้ด็ฑป'), ('ไนๅทๅบ็็คพ', '็ป็ปๆบๆ็ฑป'), ('ๅบ็', 'ๅบๆฏไบไปถ'), ('็', 'ๅฉ่ฏ'), ('ๅฐ่ฏด', 'ไฝๅ็ฑป_ๆฆๅฟต'), ('๏ผ', 'w'), ('ไฝ่
', 'ไบบ็ฉ็ฑป_ๆฆๅฟต'), ('ๆฏ', '่ฏๅฎ่ฏ'), ('ไฝๅ
ผ็พฝ', 'ไบบ็ฉ็ฑป_ๅฎไฝ')]
# Dependency Parsing
ddp = Taskflow("dependency_parsing")
ddp("9ๆ9ๆฅไธๅ็บณ่พพๅฐๅจไบ็ยท้ฟไป็ๅบๅป่ดฅไฟ็ฝๆฏ็ๅๆข
ๅพท้ฆๆฐๅคซ")
>>> [{'word': ['9ๆ9ๆฅ', 'ไธๅ', '็บณ่พพๅฐ', 'ๅจ', 'ไบ็ยท้ฟไป็ๅบ', 'ๅป่ดฅ', 'ไฟ็ฝๆฏ', '็ๅ', 'ๆข
ๅพท้ฆๆฐๅคซ'], 'head': [2, 6, 6, 5, 6, 0, 8, 9, 6], 'deprel': ['ATT', 'ADV', 'SBV', 'MT', 'ADV', 'HED', 'ATT', 'ATT', 'VOB']}]
# Sentiment Analysis
senta = Taskflow("sentiment_analysis")
senta("่ฟไธชไบงๅ็จ่ตทๆฅ็็ๅพๆต็
๏ผๆ้ๅธธๅๆฌข")
>>> [{'text': '่ฟไธชไบงๅ็จ่ตทๆฅ็็ๅพๆต็
๏ผๆ้ๅธธๅๆฌข', 'label': 'positive', 'score': 0.9938690066337585}]
```
## API Reference
- Support [LUGE](https://www.luge.ai/) dataset loading and compatible with Hugging Face [Datasets](https://huggingface.co/datasets). For more details please refer to [Dataset API](https://paddlenlp.readthedocs.io/zh/latest/data_prepare/dataset_list.html).
- Using Hugging Face style API to load 500+ selected transformer models and download with fast speed. For more information please refer to [Transformers API](https://paddlenlp.readthedocs.io/zh/latest/model_zoo/index.html).
- One-line of code to load pre-trained word embedding. For more usage please refer to [Embedding API](https://paddlenlp.readthedocs.io/zh/latest/model_zoo/embeddings.html).
Please find all PaddleNLP API Reference from our [readthedocs](https://paddlenlp.readthedocs.io/).
## Community
### Slack
To connect with other users and contributors, welcome to join our [Slack channel](https://paddlenlp.slack.com/).
### WeChat
Scan the QR code below with your Wechatโฌ๏ธ. You can access to official technical exchange group. Look forward to your participation.
<div align="center">
<img src="https://user-images.githubusercontent.com/11793384/212060369-4642d16e-f0ad-4359-aa57-b8303042f9c1.jpg" width="150" height="150" />
</div>
## Citation
If you find PaddleNLP useful in your research, please consider cite
```
@misc{=paddlenlp,
title={PaddleNLP: An Easy-to-use and High Performance NLP Library},
author={PaddleNLP Contributors},
howpublished = {\url{https://github.com/PaddlePaddle/PaddleNLP}},
year={2021}
}
```
## Acknowledge
We have borrowed from Hugging Face's [Transformers](https://github.com/huggingface/transformers)๐ค excellent design on pretrained models usage, and we would like to express our gratitude to the authors of Hugging Face and its open source community.
## License
PaddleNLP is provided under the [Apache-2.0 License](./LICENSE).
%package -n python3-paddlenlp
Summary: Easy-to-use and powerful NLP library with Awesome model zoo, supporting wide-range of NLP tasks from research to industrial applications, including Neural Search, Question Answering, Information Extraction and Sentiment Analysis end-to-end system.
Provides: python-paddlenlp
BuildRequires: python3-devel
BuildRequires: python3-setuptools
BuildRequires: python3-pip
%description -n python3-paddlenlp
<p align="center">
<a href="./LICENSE"><img src="https://img.shields.io/badge/license-Apache%202-dfd.svg"></a>
<a href="https://github.com/PaddlePaddle/PaddleNLP/releases"><img src="https://img.shields.io/github/v/release/PaddlePaddle/PaddleNLP?color=ffa"></a>
<a href=""><img src="https://img.shields.io/badge/python-3.6.2+-aff.svg"></a>
<a href=""><img src="https://img.shields.io/badge/os-linux%2C%20win%2C%20mac-pink.svg"></a>
<a href="https://github.com/PaddlePaddle/PaddleNLP/graphs/contributors"><img src="https://img.shields.io/github/contributors/PaddlePaddle/PaddleNLP?color=9ea"></a>
<a href="https://github.com/PaddlePaddle/PaddleNLP/commits"><img src="https://img.shields.io/github/commit-activity/m/PaddlePaddle/PaddleNLP?color=3af"></a>
<a href="https://pypi.org/project/paddlenlp/"><img src="https://img.shields.io/pypi/dm/paddlenlp?color=9cf"></a>
<a href="https://github.com/PaddlePaddle/PaddleNLP/issues"><img src="https://img.shields.io/github/issues/PaddlePaddle/PaddleNLP?color=9cc"></a>
<a href="https://github.com/PaddlePaddle/PaddleNLP/stargazers"><img src="https://img.shields.io/github/stars/PaddlePaddle/PaddleNLP?color=ccf"></a>
</p>
<h4 align="center">
<a href=#features> Features </a> |
<a href=#installation> Installation </a> |
<a href=#quick-start> Quick Start </a> |
<a href=#api-reference> API Reference </a> |
<a href=#community> Community </a>
</h4>
**PaddleNLP** is an *easy-to-use* and *powerful* NLP library with **Awesome** pre-trained model zoo, supporting wide-range of NLP tasks from research to industrial applications.
## News ๐ข
* ๐ฅ **Latest Features**
* ๐ Release **[UIE-X](./applications/information_extraction)**, an universal information extraction model that supports both document and text inputs.
* โฃ๏ธRelease **[Opinion Mining and Sentiment Analysis Models](./applications/sentiment_analysis/unified_sentiment_extraction)** based on UIE, including abilities of sentence-level and aspect-based sentiment classification, attribute extraction, opinion extraction, attribute aggregation and implicit opinion extraction.
* **2022.9.6 [PaddleNLPv2.4](https://github.com/PaddlePaddle/PaddleNLP/releases/tag/v2.4.0) Released!**
* ๐ NLP Tools: Released **[Pipelines](./pipelines)** which supports turn-key construction of search engine and question answering systems. It features a flexible design that is applicable for all kinds of NLP systems so you can build end-to-end NLP pipelines like Legos!
* ๐จ Industrial application: Release **[Complete Solution of Text Classification](./applications/text_classification)** covering various scenarios of text classification: multi-class, multi-label and hierarchical, it also supports **few-shot learning** and the training and optimization of **TrustAI**. Upgrade for [**UIE**](./model_zoo/uie) and release **UIE-M**, support both Chinese and English information extraction in a single model; release the data distillation solution for UIE to break the bottleneck of time-consuming of inference.
* ๐ญ AIGC: Release code generation SOTA model [**CodeGen**](./examples/code_generation/codegen) that supports multiple programming languages code generation. Integrate [**Text to Image Model**](https://github.com/PaddlePaddle/PaddleNLP/blob/develop/docs/model_zoo/taskflow.md#%E6%96%87%E5%9B%BE%E7%94%9F%E6%88%90) DALLยทE Mini, Disco Diffusion, Stable Diffusion, let's play and have some fun!
* ๐ช Framework upgrade: Release [**Auto Model Compression API**](./docs/compression.md), supports for pruning and quantization automatically, lower the barriers of model compression; Release [**Few-shot Prompt**](./applications/text_classification/multi_class/few-shot), includes the algorithms such as PET, P-Tuning and RGL.
## Features
#### <a href=#out-of-box-nlp-toolset> ๐ฆ Out-of-Box NLP Toolset </a>
#### <a href=#awesome-chinese-model-zoo> ๐ค Awesome Chinese Model Zoo </a>
#### <a href=#industrial-end-to-end-system> ๐๏ธ Industrial End-to-end System </a>
#### <a href=#high-performance-distributed-training-and-inference> ๐ High Performance Distributed Training and Inference </a>
### Out-of-Box NLP Toolset
Taskflow aims to provide off-the-shelf NLP pre-built task covering NLU and NLG technique, in the meanwhile with extreamly fast infernece satisfying industrial scenario.

For more usage please refer to [Taskflow Docs](./docs/model_zoo/taskflow.md).
### Awesome Chinese Model Zoo
#### ๐ Comprehensive Chinese Transformer Models
We provide **45+** network architectures and over **500+** pretrained models. Not only includes all the SOTA model like ERNIE, PLATO and SKEP released by Baidu, but also integrates most of the high-quality Chinese pretrained model developed by other organizations. Use `AutoModel` API to **โกSUPER FASTโก** download pretrained models of different architecture. We welcome all developers to contribute your Transformer models to PaddleNLP!
```python
from paddlenlp.transformers import *
ernie = AutoModel.from_pretrained('ernie-3.0-medium-zh')
bert = AutoModel.from_pretrained('bert-wwm-chinese')
albert = AutoModel.from_pretrained('albert-chinese-tiny')
roberta = AutoModel.from_pretrained('roberta-wwm-ext')
electra = AutoModel.from_pretrained('chinese-electra-small')
gpt = AutoModelForPretraining.from_pretrained('gpt-cpm-large-cn')
```
Due to the computation limitation, you can use the ERNIE-Tiny light models to accelerate the deployment of pretrained models.
```python
# 6L768H
ernie = AutoModel.from_pretrained('ernie-3.0-medium-zh')
# 6L384H
ernie = AutoModel.from_pretrained('ernie-3.0-mini-zh')
# 4L384H
ernie = AutoModel.from_pretrained('ernie-3.0-micro-zh')
# 4L312H
ernie = AutoModel.from_pretrained('ernie-3.0-nano-zh')
```
Unified API experience for NLP task like semantic representation, text classification, sentence matching, sequence labeling, question answering, etc.
```python
import paddle
from paddlenlp.transformers import *
tokenizer = AutoTokenizer.from_pretrained('ernie-3.0-medium-zh')
text = tokenizer('natural language processing')
# Semantic Representation
model = AutoModel.from_pretrained('ernie-3.0-medium-zh')
sequence_output, pooled_output = model(input_ids=paddle.to_tensor([text['input_ids']]))
# Text Classificaiton and Matching
model = AutoModelForSequenceClassification.from_pretrained('ernie-3.0-medium-zh')
# Sequence Labeling
model = AutoModelForTokenClassification.from_pretrained('ernie-3.0-medium-zh')
# Question Answering
model = AutoModelForQuestionAnswering.from_pretrained('ernie-3.0-medium-zh')
```
#### Wide-range NLP Task Support
PaddleNLP provides rich examples covering mainstream NLP task to help developers accelerate problem solving. You can find our powerful transformer [Model Zoo](./model_zoo), and wide-range NLP application [exmaples](./examples) with detailed instructions.
Also you can run our interactive [Notebook tutorial](https://aistudio.baidu.com/aistudio/personalcenter/thirdview/574995) on AI Studio, a powerful platform with **FREE** computing resource.
<details><summary> PaddleNLP Transformer model summary (<b>click to show details</b>) </summary><div>
| Model | Sequence Classification | Token Classification | Question Answering | Text Generation | Multiple Choice |
| :----------------- | ----------------------- | -------------------- | ------------------ | --------------- | --------------- |
| ALBERT | โ
| โ
| โ
| โ | โ
|
| BART | โ
| โ
| โ
| โ
| โ |
| BERT | โ
| โ
| โ
| โ | โ
|
| BigBird | โ
| โ
| โ
| โ | โ
|
| BlenderBot | โ | โ | โ | โ
| โ |
| ChineseBERT | โ
| โ
| โ
| โ | โ |
| ConvBERT | โ
| โ
| โ
| โ | โ
|
| CTRL | โ
| โ | โ | โ | โ |
| DistilBERT | โ
| โ
| โ
| โ | โ |
| ELECTRA | โ
| โ
| โ
| โ | โ
|
| ERNIE | โ
| โ
| โ
| โ | โ
|
| ERNIE-CTM | โ | โ
| โ | โ | โ |
| ERNIE-Doc | โ
| โ
| โ
| โ | โ |
| ERNIE-GEN | โ | โ | โ | โ
| โ |
| ERNIE-Gram | โ
| โ
| โ
| โ | โ |
| ERNIE-M | โ
| โ
| โ
| โ | โ |
| FNet | โ
| โ
| โ
| โ | โ
|
| Funnel-Transformer | โ
| โ
| โ
| โ | โ |
| GPT | โ
| โ
| โ | โ
| โ |
| LayoutLM | โ
| โ
| โ | โ | โ |
| LayoutLMv2 | โ | โ
| โ | โ | โ |
| LayoutXLM | โ | โ
| โ | โ | โ |
| LUKE | โ | โ
| โ
| โ | โ |
| mBART | โ
| โ | โ
| โ | โ
|
| MegatronBERT | โ
| โ
| โ
| โ | โ
|
| MobileBERT | โ
| โ | โ
| โ | โ |
| MPNet | โ
| โ
| โ
| โ | โ
|
| NEZHA | โ
| โ
| โ
| โ | โ
|
| PP-MiniLM | โ
| โ | โ | โ | โ |
| ProphetNet | โ | โ | โ | โ
| โ |
| Reformer | โ
| โ | โ
| โ | โ |
| RemBERT | โ
| โ
| โ
| โ | โ
|
| RoBERTa | โ
| โ
| โ
| โ | โ
|
| RoFormer | โ
| โ
| โ
| โ | โ |
| SKEP | โ
| โ
| โ | โ | โ |
| SqueezeBERT | โ
| โ
| โ
| โ | โ |
| T5 | โ | โ | โ | โ
| โ |
| TinyBERT | โ
| โ | โ | โ | โ |
| UnifiedTransformer | โ | โ | โ | โ
| โ |
| XLNet | โ
| โ
| โ
| โ | โ
|
</div></details>
For more pretrained model usage, please refer to [Transformer API Docs](./docs/model_zoo/index.rst).
### Industrial End-to-end System
We provide high value scenarios including information extraction, semantic retrieval, questionn answering high-value.
For more details industial cases please refer to [Applications](./applications).
#### ๐ Neural Search System
<div align="center">
<img src="https://user-images.githubusercontent.com/11793384/168514909-8817d79a-72c4-4be1-8080-93d1f682bb46.gif" width="400">
</div>
For more details please refer to [Neural Search](./applications/neural_search).
#### โ Question Answering System
We provide question answering pipeline which can support FAQ system, Document-level Visual Question answering system based on [๐RocketQA](https://github.com/PaddlePaddle/RocketQA).
<div align="center">
<img src="https://user-images.githubusercontent.com/11793384/168514868-1babe981-c675-4f89-9168-dd0a3eede315.gif" width="400">
</div>
For more details please refer to [Question Answering](./applications/question_answering) and [Document VQA](./applications/document_intelligence/doc_vqa).
#### ๐ Opinion Extraction and Sentiment Analysis
We build an opinion extraction system for product review and fine-grained sentiment analysis based on [SKEP](https://arxiv.org/abs/2005.05635) Model.
<div align="center">
<img src="https://user-images.githubusercontent.com/11793384/168407260-b7f92800-861c-4207-98f3-2291e0102bbe.png" width="300">
</div>
For more details please refer to [Sentiment Analysis](./applications/sentiment_analysis).
#### ๐๏ธ Speech Command Analysis
Integrated ASR Model, Information Extraction, we provide a speech command analysis pipeline that show how to use PaddleNLP and [PaddleSpeech](https://github.com/PaddlePaddle/PaddleSpeech) to solve Speech + NLP real scenarios.
<div align="center">
<img src="https://user-images.githubusercontent.com/11793384/168412618-04897a47-79c9-4fe7-a054-5dc1f6a1f75c.png" width="500">
</div>
For more details please refer to [Speech Command Analysis](./applications/speech_cmd_analysis).
### High Performance Distributed Training and Inference
#### โก FastTokenizer: High Performance Text Preprocessing Library
<div align="center">
<img src="https://user-images.githubusercontent.com/11793384/168407921-b4395b1d-44bd-41a0-8c58-923ba2b703ef.png" width="400">
</div>
```python
AutoTokenizer.from_pretrained("ernie-3.0-medium-zh", use_fast=True)
```
Set `use_fast=True` to use C++ Tokenizer kernel to achieve 100x faster on text pre-processing. For more usage please refer to [FastTokenizer](./fast_tokenizer).
#### โก FastGeneration: High Perforance Generation Library
<div align="center">
<img src="https://user-images.githubusercontent.com/11793384/168407831-914dced0-3a5a-40b8-8a65-ec82bf13e53c.gif" width="400">
</div>
```python
model = GPTLMHeadModel.from_pretrained('gpt-cpm-large-cn')
outputs, _ = model.generate(
input_ids=inputs_ids, max_length=10, decode_strategy='greedy_search',
use_fast=True)
```
Set `use_fast=True` to achieve 5x speedup for Transformer, GPT, BART, PLATO, UniLM text generation. For more usage please refer to [FastGeneration](./fast_generation).
#### ๐ Fleet: 4D Hybrid Distributed Training
<div align="center">
<img src="https://user-images.githubusercontent.com/11793384/168515134-513f13e0-9902-40ef-98fa-528271dcccda.png" width="300">
</div>
For more super large-scale model pre-training details please refer to [GPT-3](./examples/language_model/gpt-3).
## Installation
### Prerequisites
* python >= 3.7
* paddlepaddle >= 2.3
More information about PaddlePaddle installation please refer to [PaddlePaddle's Website](https://www.paddlepaddle.org.cn/install/quick?docurl=/documentation/docs/zh/install/conda/linux-conda.html).
### Python pip Installation
```
pip install --upgrade paddlenlp
```
or you can install the latest develop branch code with the following command:
```shell
pip install --pre --upgrade paddlenlp -f https://www.paddlepaddle.org.cn/whl/paddlenlp.html
```
## Quick Start
**Taskflow** aims to provide off-the-shelf NLP pre-built task covering NLU and NLG scenario, in the meanwhile with extreamly fast infernece satisfying industrial applications.
```python
from paddlenlp import Taskflow
# Chinese Word Segmentation
seg = Taskflow("word_segmentation")
seg("็ฌฌๅๅๅฑๅ
จ่ฟไผๅจ่ฅฟๅฎไธพๅ")
>>> ['็ฌฌๅๅๅฑ', 'ๅ
จ่ฟไผ', 'ๅจ', '่ฅฟๅฎ', 'ไธพๅ']
# POS Tagging
tag = Taskflow("pos_tagging")
tag("็ฌฌๅๅๅฑๅ
จ่ฟไผๅจ่ฅฟๅฎไธพๅ")
>>> [('็ฌฌๅๅๅฑ', 'm'), ('ๅ
จ่ฟไผ', 'nz'), ('ๅจ', 'p'), ('่ฅฟๅฎ', 'LOC'), ('ไธพๅ', 'v')]
# Named Entity Recognition
ner = Taskflow("ner")
ner("ใๅญคๅฅณใๆฏ2010ๅนดไนๅทๅบ็็คพๅบ็็ๅฐ่ฏด๏ผไฝ่
ๆฏไฝๅ
ผ็พฝ")
>>> [('ใ', 'w'), ('ๅญคๅฅณ', 'ไฝๅ็ฑป_ๅฎไฝ'), ('ใ', 'w'), ('ๆฏ', '่ฏๅฎ่ฏ'), ('2010ๅนด', 'ๆถ้ด็ฑป'), ('ไนๅทๅบ็็คพ', '็ป็ปๆบๆ็ฑป'), ('ๅบ็', 'ๅบๆฏไบไปถ'), ('็', 'ๅฉ่ฏ'), ('ๅฐ่ฏด', 'ไฝๅ็ฑป_ๆฆๅฟต'), ('๏ผ', 'w'), ('ไฝ่
', 'ไบบ็ฉ็ฑป_ๆฆๅฟต'), ('ๆฏ', '่ฏๅฎ่ฏ'), ('ไฝๅ
ผ็พฝ', 'ไบบ็ฉ็ฑป_ๅฎไฝ')]
# Dependency Parsing
ddp = Taskflow("dependency_parsing")
ddp("9ๆ9ๆฅไธๅ็บณ่พพๅฐๅจไบ็ยท้ฟไป็ๅบๅป่ดฅไฟ็ฝๆฏ็ๅๆข
ๅพท้ฆๆฐๅคซ")
>>> [{'word': ['9ๆ9ๆฅ', 'ไธๅ', '็บณ่พพๅฐ', 'ๅจ', 'ไบ็ยท้ฟไป็ๅบ', 'ๅป่ดฅ', 'ไฟ็ฝๆฏ', '็ๅ', 'ๆข
ๅพท้ฆๆฐๅคซ'], 'head': [2, 6, 6, 5, 6, 0, 8, 9, 6], 'deprel': ['ATT', 'ADV', 'SBV', 'MT', 'ADV', 'HED', 'ATT', 'ATT', 'VOB']}]
# Sentiment Analysis
senta = Taskflow("sentiment_analysis")
senta("่ฟไธชไบงๅ็จ่ตทๆฅ็็ๅพๆต็
๏ผๆ้ๅธธๅๆฌข")
>>> [{'text': '่ฟไธชไบงๅ็จ่ตทๆฅ็็ๅพๆต็
๏ผๆ้ๅธธๅๆฌข', 'label': 'positive', 'score': 0.9938690066337585}]
```
## API Reference
- Support [LUGE](https://www.luge.ai/) dataset loading and compatible with Hugging Face [Datasets](https://huggingface.co/datasets). For more details please refer to [Dataset API](https://paddlenlp.readthedocs.io/zh/latest/data_prepare/dataset_list.html).
- Using Hugging Face style API to load 500+ selected transformer models and download with fast speed. For more information please refer to [Transformers API](https://paddlenlp.readthedocs.io/zh/latest/model_zoo/index.html).
- One-line of code to load pre-trained word embedding. For more usage please refer to [Embedding API](https://paddlenlp.readthedocs.io/zh/latest/model_zoo/embeddings.html).
Please find all PaddleNLP API Reference from our [readthedocs](https://paddlenlp.readthedocs.io/).
## Community
### Slack
To connect with other users and contributors, welcome to join our [Slack channel](https://paddlenlp.slack.com/).
### WeChat
Scan the QR code below with your Wechatโฌ๏ธ. You can access to official technical exchange group. Look forward to your participation.
<div align="center">
<img src="https://user-images.githubusercontent.com/11793384/212060369-4642d16e-f0ad-4359-aa57-b8303042f9c1.jpg" width="150" height="150" />
</div>
## Citation
If you find PaddleNLP useful in your research, please consider cite
```
@misc{=paddlenlp,
title={PaddleNLP: An Easy-to-use and High Performance NLP Library},
author={PaddleNLP Contributors},
howpublished = {\url{https://github.com/PaddlePaddle/PaddleNLP}},
year={2021}
}
```
## Acknowledge
We have borrowed from Hugging Face's [Transformers](https://github.com/huggingface/transformers)๐ค excellent design on pretrained models usage, and we would like to express our gratitude to the authors of Hugging Face and its open source community.
## License
PaddleNLP is provided under the [Apache-2.0 License](./LICENSE).
%package help
Summary: Development documents and examples for paddlenlp
Provides: python3-paddlenlp-doc
%description help
<p align="center">
<a href="./LICENSE"><img src="https://img.shields.io/badge/license-Apache%202-dfd.svg"></a>
<a href="https://github.com/PaddlePaddle/PaddleNLP/releases"><img src="https://img.shields.io/github/v/release/PaddlePaddle/PaddleNLP?color=ffa"></a>
<a href=""><img src="https://img.shields.io/badge/python-3.6.2+-aff.svg"></a>
<a href=""><img src="https://img.shields.io/badge/os-linux%2C%20win%2C%20mac-pink.svg"></a>
<a href="https://github.com/PaddlePaddle/PaddleNLP/graphs/contributors"><img src="https://img.shields.io/github/contributors/PaddlePaddle/PaddleNLP?color=9ea"></a>
<a href="https://github.com/PaddlePaddle/PaddleNLP/commits"><img src="https://img.shields.io/github/commit-activity/m/PaddlePaddle/PaddleNLP?color=3af"></a>
<a href="https://pypi.org/project/paddlenlp/"><img src="https://img.shields.io/pypi/dm/paddlenlp?color=9cf"></a>
<a href="https://github.com/PaddlePaddle/PaddleNLP/issues"><img src="https://img.shields.io/github/issues/PaddlePaddle/PaddleNLP?color=9cc"></a>
<a href="https://github.com/PaddlePaddle/PaddleNLP/stargazers"><img src="https://img.shields.io/github/stars/PaddlePaddle/PaddleNLP?color=ccf"></a>
</p>
<h4 align="center">
<a href=#features> Features </a> |
<a href=#installation> Installation </a> |
<a href=#quick-start> Quick Start </a> |
<a href=#api-reference> API Reference </a> |
<a href=#community> Community </a>
</h4>
**PaddleNLP** is an *easy-to-use* and *powerful* NLP library with **Awesome** pre-trained model zoo, supporting wide-range of NLP tasks from research to industrial applications.
## News ๐ข
* ๐ฅ **Latest Features**
* ๐ Release **[UIE-X](./applications/information_extraction)**, an universal information extraction model that supports both document and text inputs.
* โฃ๏ธRelease **[Opinion Mining and Sentiment Analysis Models](./applications/sentiment_analysis/unified_sentiment_extraction)** based on UIE, including abilities of sentence-level and aspect-based sentiment classification, attribute extraction, opinion extraction, attribute aggregation and implicit opinion extraction.
* **2022.9.6 [PaddleNLPv2.4](https://github.com/PaddlePaddle/PaddleNLP/releases/tag/v2.4.0) Released!**
* ๐ NLP Tools: Released **[Pipelines](./pipelines)** which supports turn-key construction of search engine and question answering systems. It features a flexible design that is applicable for all kinds of NLP systems so you can build end-to-end NLP pipelines like Legos!
* ๐จ Industrial application: Release **[Complete Solution of Text Classification](./applications/text_classification)** covering various scenarios of text classification: multi-class, multi-label and hierarchical, it also supports **few-shot learning** and the training and optimization of **TrustAI**. Upgrade for [**UIE**](./model_zoo/uie) and release **UIE-M**, support both Chinese and English information extraction in a single model; release the data distillation solution for UIE to break the bottleneck of time-consuming of inference.
* ๐ญ AIGC: Release code generation SOTA model [**CodeGen**](./examples/code_generation/codegen) that supports multiple programming languages code generation. Integrate [**Text to Image Model**](https://github.com/PaddlePaddle/PaddleNLP/blob/develop/docs/model_zoo/taskflow.md#%E6%96%87%E5%9B%BE%E7%94%9F%E6%88%90) DALLยทE Mini, Disco Diffusion, Stable Diffusion, let's play and have some fun!
* ๐ช Framework upgrade: Release [**Auto Model Compression API**](./docs/compression.md), supports for pruning and quantization automatically, lower the barriers of model compression; Release [**Few-shot Prompt**](./applications/text_classification/multi_class/few-shot), includes the algorithms such as PET, P-Tuning and RGL.
## Features
#### <a href=#out-of-box-nlp-toolset> ๐ฆ Out-of-Box NLP Toolset </a>
#### <a href=#awesome-chinese-model-zoo> ๐ค Awesome Chinese Model Zoo </a>
#### <a href=#industrial-end-to-end-system> ๐๏ธ Industrial End-to-end System </a>
#### <a href=#high-performance-distributed-training-and-inference> ๐ High Performance Distributed Training and Inference </a>
### Out-of-Box NLP Toolset
Taskflow aims to provide off-the-shelf NLP pre-built task covering NLU and NLG technique, in the meanwhile with extreamly fast infernece satisfying industrial scenario.

For more usage please refer to [Taskflow Docs](./docs/model_zoo/taskflow.md).
### Awesome Chinese Model Zoo
#### ๐ Comprehensive Chinese Transformer Models
We provide **45+** network architectures and over **500+** pretrained models. Not only includes all the SOTA model like ERNIE, PLATO and SKEP released by Baidu, but also integrates most of the high-quality Chinese pretrained model developed by other organizations. Use `AutoModel` API to **โกSUPER FASTโก** download pretrained models of different architecture. We welcome all developers to contribute your Transformer models to PaddleNLP!
```python
from paddlenlp.transformers import *
ernie = AutoModel.from_pretrained('ernie-3.0-medium-zh')
bert = AutoModel.from_pretrained('bert-wwm-chinese')
albert = AutoModel.from_pretrained('albert-chinese-tiny')
roberta = AutoModel.from_pretrained('roberta-wwm-ext')
electra = AutoModel.from_pretrained('chinese-electra-small')
gpt = AutoModelForPretraining.from_pretrained('gpt-cpm-large-cn')
```
Due to the computation limitation, you can use the ERNIE-Tiny light models to accelerate the deployment of pretrained models.
```python
# 6L768H
ernie = AutoModel.from_pretrained('ernie-3.0-medium-zh')
# 6L384H
ernie = AutoModel.from_pretrained('ernie-3.0-mini-zh')
# 4L384H
ernie = AutoModel.from_pretrained('ernie-3.0-micro-zh')
# 4L312H
ernie = AutoModel.from_pretrained('ernie-3.0-nano-zh')
```
Unified API experience for NLP task like semantic representation, text classification, sentence matching, sequence labeling, question answering, etc.
```python
import paddle
from paddlenlp.transformers import *
tokenizer = AutoTokenizer.from_pretrained('ernie-3.0-medium-zh')
text = tokenizer('natural language processing')
# Semantic Representation
model = AutoModel.from_pretrained('ernie-3.0-medium-zh')
sequence_output, pooled_output = model(input_ids=paddle.to_tensor([text['input_ids']]))
# Text Classificaiton and Matching
model = AutoModelForSequenceClassification.from_pretrained('ernie-3.0-medium-zh')
# Sequence Labeling
model = AutoModelForTokenClassification.from_pretrained('ernie-3.0-medium-zh')
# Question Answering
model = AutoModelForQuestionAnswering.from_pretrained('ernie-3.0-medium-zh')
```
#### Wide-range NLP Task Support
PaddleNLP provides rich examples covering mainstream NLP task to help developers accelerate problem solving. You can find our powerful transformer [Model Zoo](./model_zoo), and wide-range NLP application [exmaples](./examples) with detailed instructions.
Also you can run our interactive [Notebook tutorial](https://aistudio.baidu.com/aistudio/personalcenter/thirdview/574995) on AI Studio, a powerful platform with **FREE** computing resource.
<details><summary> PaddleNLP Transformer model summary (<b>click to show details</b>) </summary><div>
| Model | Sequence Classification | Token Classification | Question Answering | Text Generation | Multiple Choice |
| :----------------- | ----------------------- | -------------------- | ------------------ | --------------- | --------------- |
| ALBERT | โ
| โ
| โ
| โ | โ
|
| BART | โ
| โ
| โ
| โ
| โ |
| BERT | โ
| โ
| โ
| โ | โ
|
| BigBird | โ
| โ
| โ
| โ | โ
|
| BlenderBot | โ | โ | โ | โ
| โ |
| ChineseBERT | โ
| โ
| โ
| โ | โ |
| ConvBERT | โ
| โ
| โ
| โ | โ
|
| CTRL | โ
| โ | โ | โ | โ |
| DistilBERT | โ
| โ
| โ
| โ | โ |
| ELECTRA | โ
| โ
| โ
| โ | โ
|
| ERNIE | โ
| โ
| โ
| โ | โ
|
| ERNIE-CTM | โ | โ
| โ | โ | โ |
| ERNIE-Doc | โ
| โ
| โ
| โ | โ |
| ERNIE-GEN | โ | โ | โ | โ
| โ |
| ERNIE-Gram | โ
| โ
| โ
| โ | โ |
| ERNIE-M | โ
| โ
| โ
| โ | โ |
| FNet | โ
| โ
| โ
| โ | โ
|
| Funnel-Transformer | โ
| โ
| โ
| โ | โ |
| GPT | โ
| โ
| โ | โ
| โ |
| LayoutLM | โ
| โ
| โ | โ | โ |
| LayoutLMv2 | โ | โ
| โ | โ | โ |
| LayoutXLM | โ | โ
| โ | โ | โ |
| LUKE | โ | โ
| โ
| โ | โ |
| mBART | โ
| โ | โ
| โ | โ
|
| MegatronBERT | โ
| โ
| โ
| โ | โ
|
| MobileBERT | โ
| โ | โ
| โ | โ |
| MPNet | โ
| โ
| โ
| โ | โ
|
| NEZHA | โ
| โ
| โ
| โ | โ
|
| PP-MiniLM | โ
| โ | โ | โ | โ |
| ProphetNet | โ | โ | โ | โ
| โ |
| Reformer | โ
| โ | โ
| โ | โ |
| RemBERT | โ
| โ
| โ
| โ | โ
|
| RoBERTa | โ
| โ
| โ
| โ | โ
|
| RoFormer | โ
| โ
| โ
| โ | โ |
| SKEP | โ
| โ
| โ | โ | โ |
| SqueezeBERT | โ
| โ
| โ
| โ | โ |
| T5 | โ | โ | โ | โ
| โ |
| TinyBERT | โ
| โ | โ | โ | โ |
| UnifiedTransformer | โ | โ | โ | โ
| โ |
| XLNet | โ
| โ
| โ
| โ | โ
|
</div></details>
For more pretrained model usage, please refer to [Transformer API Docs](./docs/model_zoo/index.rst).
### Industrial End-to-end System
We provide high value scenarios including information extraction, semantic retrieval, questionn answering high-value.
For more details industial cases please refer to [Applications](./applications).
#### ๐ Neural Search System
<div align="center">
<img src="https://user-images.githubusercontent.com/11793384/168514909-8817d79a-72c4-4be1-8080-93d1f682bb46.gif" width="400">
</div>
For more details please refer to [Neural Search](./applications/neural_search).
#### โ Question Answering System
We provide question answering pipeline which can support FAQ system, Document-level Visual Question answering system based on [๐RocketQA](https://github.com/PaddlePaddle/RocketQA).
<div align="center">
<img src="https://user-images.githubusercontent.com/11793384/168514868-1babe981-c675-4f89-9168-dd0a3eede315.gif" width="400">
</div>
For more details please refer to [Question Answering](./applications/question_answering) and [Document VQA](./applications/document_intelligence/doc_vqa).
#### ๐ Opinion Extraction and Sentiment Analysis
We build an opinion extraction system for product review and fine-grained sentiment analysis based on [SKEP](https://arxiv.org/abs/2005.05635) Model.
<div align="center">
<img src="https://user-images.githubusercontent.com/11793384/168407260-b7f92800-861c-4207-98f3-2291e0102bbe.png" width="300">
</div>
For more details please refer to [Sentiment Analysis](./applications/sentiment_analysis).
#### ๐๏ธ Speech Command Analysis
Integrated ASR Model, Information Extraction, we provide a speech command analysis pipeline that show how to use PaddleNLP and [PaddleSpeech](https://github.com/PaddlePaddle/PaddleSpeech) to solve Speech + NLP real scenarios.
<div align="center">
<img src="https://user-images.githubusercontent.com/11793384/168412618-04897a47-79c9-4fe7-a054-5dc1f6a1f75c.png" width="500">
</div>
For more details please refer to [Speech Command Analysis](./applications/speech_cmd_analysis).
### High Performance Distributed Training and Inference
#### โก FastTokenizer: High Performance Text Preprocessing Library
<div align="center">
<img src="https://user-images.githubusercontent.com/11793384/168407921-b4395b1d-44bd-41a0-8c58-923ba2b703ef.png" width="400">
</div>
```python
AutoTokenizer.from_pretrained("ernie-3.0-medium-zh", use_fast=True)
```
Set `use_fast=True` to use C++ Tokenizer kernel to achieve 100x faster on text pre-processing. For more usage please refer to [FastTokenizer](./fast_tokenizer).
#### โก FastGeneration: High Perforance Generation Library
<div align="center">
<img src="https://user-images.githubusercontent.com/11793384/168407831-914dced0-3a5a-40b8-8a65-ec82bf13e53c.gif" width="400">
</div>
```python
model = GPTLMHeadModel.from_pretrained('gpt-cpm-large-cn')
outputs, _ = model.generate(
input_ids=inputs_ids, max_length=10, decode_strategy='greedy_search',
use_fast=True)
```
Set `use_fast=True` to achieve 5x speedup for Transformer, GPT, BART, PLATO, UniLM text generation. For more usage please refer to [FastGeneration](./fast_generation).
#### ๐ Fleet: 4D Hybrid Distributed Training
<div align="center">
<img src="https://user-images.githubusercontent.com/11793384/168515134-513f13e0-9902-40ef-98fa-528271dcccda.png" width="300">
</div>
For more super large-scale model pre-training details please refer to [GPT-3](./examples/language_model/gpt-3).
## Installation
### Prerequisites
* python >= 3.7
* paddlepaddle >= 2.3
More information about PaddlePaddle installation please refer to [PaddlePaddle's Website](https://www.paddlepaddle.org.cn/install/quick?docurl=/documentation/docs/zh/install/conda/linux-conda.html).
### Python pip Installation
```
pip install --upgrade paddlenlp
```
or you can install the latest develop branch code with the following command:
```shell
pip install --pre --upgrade paddlenlp -f https://www.paddlepaddle.org.cn/whl/paddlenlp.html
```
## Quick Start
**Taskflow** aims to provide off-the-shelf NLP pre-built task covering NLU and NLG scenario, in the meanwhile with extreamly fast infernece satisfying industrial applications.
```python
from paddlenlp import Taskflow
# Chinese Word Segmentation
seg = Taskflow("word_segmentation")
seg("็ฌฌๅๅๅฑๅ
จ่ฟไผๅจ่ฅฟๅฎไธพๅ")
>>> ['็ฌฌๅๅๅฑ', 'ๅ
จ่ฟไผ', 'ๅจ', '่ฅฟๅฎ', 'ไธพๅ']
# POS Tagging
tag = Taskflow("pos_tagging")
tag("็ฌฌๅๅๅฑๅ
จ่ฟไผๅจ่ฅฟๅฎไธพๅ")
>>> [('็ฌฌๅๅๅฑ', 'm'), ('ๅ
จ่ฟไผ', 'nz'), ('ๅจ', 'p'), ('่ฅฟๅฎ', 'LOC'), ('ไธพๅ', 'v')]
# Named Entity Recognition
ner = Taskflow("ner")
ner("ใๅญคๅฅณใๆฏ2010ๅนดไนๅทๅบ็็คพๅบ็็ๅฐ่ฏด๏ผไฝ่
ๆฏไฝๅ
ผ็พฝ")
>>> [('ใ', 'w'), ('ๅญคๅฅณ', 'ไฝๅ็ฑป_ๅฎไฝ'), ('ใ', 'w'), ('ๆฏ', '่ฏๅฎ่ฏ'), ('2010ๅนด', 'ๆถ้ด็ฑป'), ('ไนๅทๅบ็็คพ', '็ป็ปๆบๆ็ฑป'), ('ๅบ็', 'ๅบๆฏไบไปถ'), ('็', 'ๅฉ่ฏ'), ('ๅฐ่ฏด', 'ไฝๅ็ฑป_ๆฆๅฟต'), ('๏ผ', 'w'), ('ไฝ่
', 'ไบบ็ฉ็ฑป_ๆฆๅฟต'), ('ๆฏ', '่ฏๅฎ่ฏ'), ('ไฝๅ
ผ็พฝ', 'ไบบ็ฉ็ฑป_ๅฎไฝ')]
# Dependency Parsing
ddp = Taskflow("dependency_parsing")
ddp("9ๆ9ๆฅไธๅ็บณ่พพๅฐๅจไบ็ยท้ฟไป็ๅบๅป่ดฅไฟ็ฝๆฏ็ๅๆข
ๅพท้ฆๆฐๅคซ")
>>> [{'word': ['9ๆ9ๆฅ', 'ไธๅ', '็บณ่พพๅฐ', 'ๅจ', 'ไบ็ยท้ฟไป็ๅบ', 'ๅป่ดฅ', 'ไฟ็ฝๆฏ', '็ๅ', 'ๆข
ๅพท้ฆๆฐๅคซ'], 'head': [2, 6, 6, 5, 6, 0, 8, 9, 6], 'deprel': ['ATT', 'ADV', 'SBV', 'MT', 'ADV', 'HED', 'ATT', 'ATT', 'VOB']}]
# Sentiment Analysis
senta = Taskflow("sentiment_analysis")
senta("่ฟไธชไบงๅ็จ่ตทๆฅ็็ๅพๆต็
๏ผๆ้ๅธธๅๆฌข")
>>> [{'text': '่ฟไธชไบงๅ็จ่ตทๆฅ็็ๅพๆต็
๏ผๆ้ๅธธๅๆฌข', 'label': 'positive', 'score': 0.9938690066337585}]
```
## API Reference
- Support [LUGE](https://www.luge.ai/) dataset loading and compatible with Hugging Face [Datasets](https://huggingface.co/datasets). For more details please refer to [Dataset API](https://paddlenlp.readthedocs.io/zh/latest/data_prepare/dataset_list.html).
- Using Hugging Face style API to load 500+ selected transformer models and download with fast speed. For more information please refer to [Transformers API](https://paddlenlp.readthedocs.io/zh/latest/model_zoo/index.html).
- One-line of code to load pre-trained word embedding. For more usage please refer to [Embedding API](https://paddlenlp.readthedocs.io/zh/latest/model_zoo/embeddings.html).
Please find all PaddleNLP API Reference from our [readthedocs](https://paddlenlp.readthedocs.io/).
## Community
### Slack
To connect with other users and contributors, welcome to join our [Slack channel](https://paddlenlp.slack.com/).
### WeChat
Scan the QR code below with your Wechatโฌ๏ธ. You can access to official technical exchange group. Look forward to your participation.
<div align="center">
<img src="https://user-images.githubusercontent.com/11793384/212060369-4642d16e-f0ad-4359-aa57-b8303042f9c1.jpg" width="150" height="150" />
</div>
## Citation
If you find PaddleNLP useful in your research, please consider cite
```
@misc{=paddlenlp,
title={PaddleNLP: An Easy-to-use and High Performance NLP Library},
author={PaddleNLP Contributors},
howpublished = {\url{https://github.com/PaddlePaddle/PaddleNLP}},
year={2021}
}
```
## Acknowledge
We have borrowed from Hugging Face's [Transformers](https://github.com/huggingface/transformers)๐ค excellent design on pretrained models usage, and we would like to express our gratitude to the authors of Hugging Face and its open source community.
## License
PaddleNLP is provided under the [Apache-2.0 License](./LICENSE).
%prep
%autosetup -n paddlenlp-2.5.2
%build
%py3_build
%install
%py3_install
install -d -m755 %{buildroot}/%{_pkgdocdir}
if [ -d doc ]; then cp -arf doc %{buildroot}/%{_pkgdocdir}; fi
if [ -d docs ]; then cp -arf docs %{buildroot}/%{_pkgdocdir}; fi
if [ -d example ]; then cp -arf example %{buildroot}/%{_pkgdocdir}; fi
if [ -d examples ]; then cp -arf examples %{buildroot}/%{_pkgdocdir}; fi
pushd %{buildroot}
if [ -d usr/lib ]; then
find usr/lib -type f -printf "/%h/%f\n" >> filelist.lst
fi
if [ -d usr/lib64 ]; then
find usr/lib64 -type f -printf "/%h/%f\n" >> filelist.lst
fi
if [ -d usr/bin ]; then
find usr/bin -type f -printf "/%h/%f\n" >> filelist.lst
fi
if [ -d usr/sbin ]; then
find usr/sbin -type f -printf "/%h/%f\n" >> filelist.lst
fi
touch doclist.lst
if [ -d usr/share/man ]; then
find usr/share/man -type f -printf "/%h/%f.gz\n" >> doclist.lst
fi
popd
mv %{buildroot}/filelist.lst .
mv %{buildroot}/doclist.lst .
%files -n python3-paddlenlp -f filelist.lst
%dir %{python3_sitelib}/*
%files help -f doclist.lst
%{_docdir}/*
%changelog
* Sun Apr 23 2023 Python_Bot <Python_Bot@openeuler.org> - 2.5.2-1
- Package Spec generated
|