The Wayback Machine - https://web.archive.org/web/20230130090011/http://github.com/PaddlePaddle/PaddleNLP
Skip to content

👑 Easy-to-use and powerful NLP library with 🤗 Awesome model zoo, supporting wide-range of NLP tasks from research to industrial applications, including 🗂Text Classification, 🔍 Neural Search, Question Answering, ℹ️ Information Extraction, 📄 Document Intelligence, 💌 Sentiment Analysis and 🖼 Diffusion AIGC system etc.

License

PaddlePaddle/PaddleNLP

develop
Switch branches/tags

Name already in use

A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?
Code

Latest commit

* Add fast wordpiece demo

* Add tokenizer python demo

* Add cpp demo for tokenizer
955b04f

Git stats

Files

Permalink
Failed to load latest commit information.
Type
Name
Latest commit message
Commit time

�?�体中文🀄 | English🌎


特性 | �?�装 | 快速开始 | API文档 | 社区交流

PaddleNLP是一款�?�单易用功能强大的自然语言处理开发库。聚合业界优质预�?�练模型并提供开�?�即用的开发体验,覆盖NLP多场景的模型库搭配产业�?�践范例可满足开发者灵活�?�制的需求。

News 📢

  • 2023.1.12 发布 PaddleNLP v2.5

    • 🔨 NLP工具:发布 PPDiffusers 国产化的扩散模型工具�?�,集成多种 Diffusion 模型参数和模型组件,提供了 Diffusion 模型的�?�整�?�练流程,支持 Diffusion 模型的高性能 FastDeploy 推理加速 和 多硬件部署(可支持昇腾芯片、昆仑芯部署)
    • 💎 产业应用:信息抽取、文本分类、情感分析、智能�?答 四大应用全新升级,发布文档信息抽取 UIE-X 、统一文本分类 UTC 、统一情感分析 UIE-Senta无监督�?答应用;同时发布ERNIE 3.0 Tiny v2 系列预�?�练小模型,在低资源和域外数�?效果更强,开源 模型裁剪、模型量化、FastDeploy 推理加速、边缘端部署 端到端部署方案,降低预�?�练模型部署难度
    • 💪 框架升级:预�?�练模型参数配�?统一,自�?�义参数配�?的保存和加载无需额外开发;Trainer API 新增 BF16 �?�练、Recompute 重�?��?�、Sharding 等多项分布式能力,通过�?�单配�?即可进行超大规模预�?�练模型�?�练;模型压缩 API 支持量化�?�练、词表压缩等功能,压缩后的模型精度损失更小,模型部署的内存占用大大降低;数�?增强API 全面升级,支持字、词、句子三种粒度数�?增强策略,可轻松�?�制数�?增强策略
    • 🤝 生态联合:🤗Huggingface hub 正式兼�?� PaddleNLP 预�?�练模型,支持 PaddleNLP Model 和 Tokenizer 直接从 🤗Huggingface hub 下载和上传,欢迎大�?�在 🤗Huggingface hub 体验 PaddleNLP 预�?�练模型效果
  • 2022.9.6 发布 PaddleNLP v2.4

    • 🔨 NLP工具:NLP 流水线系统 Pipelines 发布,支持快速搭建搜索引擎、�?答系统,可扩展支持各类NLP系统,�?�解决 NLP 任务像搭积木一样便捷、灵活、高效!
    • 💎 产业应用:新增 文本分类全流程应用方案 ,覆盖多分类、多标签、层次分类各类场景,支持小样本学习和 TrustAI 可信�?��?�模型�?�练与调优。
    • 🍭 AIGC :新增代码生成 SOTA 模型CodeGen,支持多种编程语言代码生成;集成文图生成�?流模型 DALL·E Mini、Disco Diffusion、Stable Diffusion,更多趣玩模型等你来玩;
    • 💪 框架升级:模型自动压缩 API 发布,自动对模型进行裁减和量化,大幅降低模型压缩技术使用门槛;小样本 Prompt能力发布,集成 PET、P-Tuning、RGL 等经典�?�法。

社区交流

  • �?信扫描二维码并填写�?卷,回复小助手关�?词(NLP)之后,即可加入交流群领取福利

    • 与众多社区开发者以及�?�方团队深度交流。
    • 10G重磅NLP学习大礼包!

特性

📦 开�?�即用的NLP工具集

🤗 丰富�?�备的中文模型库

🎛️ 产业级端到端系统范例

🚀 高性能分布式�?�练与推理

开�?�即用的NLP工具集

Taskflow提供丰富的📦开�?�即用的产业级NLP预�?模型,覆盖自然语言理解与生成两大场景,提供💪产业级的效果⚡️极致的推理性能

taskflow1

Taskflow最新集成了文生图的趣玩应用,三行代码体验 Stable Diffusion

from paddlenlp import Taskflow
text_to_image = Taskflow("text_to_image", model="CompVis/stable-diffusion-v1-4")
image_list = text_to_image('"In the morning light,Chinese ancient buildings in the mountains,Magnificent and fantastic John Howe landscape,lake,clouds,farm,Fairy tale,light effect,Dream,Greg Rutkowski,James Gurney,artstation"')

image

更多使用方法可参考Taskflow文档

丰富�?�备的中文模型库

🀄 业界最全的中文预�?�练模型

精选 45+ 个网络结构和 500+ 个预�?�练模型参数,涵盖业界最全的中文预�?�练模型:既包括文心NLP大模型的ERNIE、PLATO等,也覆盖BERT、GPT、RoBERTa、T5等主流结构。通过AutoModel API一�?高速下载

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

针对预�?�练模型�?��?�瓶颈,可以使用API一�?使用文心ERNIE-Tiny全系列轻量化模型,降低预�?�练模型部署难度。

# 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')

对预�?�练模型应用范式如语义表示、文本分类、句对匹配、序列标注、�?答等,提供统一的API体验。

import paddle
from paddlenlp.transformers import *

tokenizer = AutoTokenizer.from_pretrained('ernie-3.0-medium-zh')
text = tokenizer('自然语言处理')

# 语义表示
model = AutoModel.from_pretrained('ernie-3.0-medium-zh')
sequence_output, pooled_output = model(input_ids=paddle.to_tensor([text['input_ids']]))
# 文本分类 & 句对匹配
model = AutoModelForSequenceClassification.from_pretrained('ernie-3.0-medium-zh')
# 序列标注
model = AutoModelForTokenClassification.from_pretrained('ernie-3.0-medium-zh')
# �?答
model = AutoModelForQuestionAnswering.from_pretrained('ernie-3.0-medium-zh')

💯 全场景覆盖的应用示例

覆盖从学术到产业的NLP应用示例,涵盖NLP基础技术、NLP系统应用以及拓展应用。全面基于飞桨核心框架2.0全新API体系开发,为开发者提供飞桨文本领域的最佳�?�践。

精选预�?�练模型示例可参考Model Zoo,更多场景示例文档可参考examples�?录。更有免费�?�力支持的AI Studio平台的Notbook交互式教程提供�?�践。

PaddleNLP预�?�练模型适用任务汇总(点击展开详情
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

可参考Transformer 文档 查看�?前支持的预�?�练模型结构、参数和详细用法。

产业级端到端系统范例

PaddleNLP针对信息抽取、语义检索、智能�?答、情感分析等高频NLP场景,提供了端到端系统范例,打通数�?标注-模型�?�练-模型调优-预测部署全流程,持续降低NLP技术产业落地门槛。更多详细的系统级产业范例使用说明请参考Applications

🔍 语义检索系统

针对无监督数�?、有监督数�?等多种数�?情况,结合SimCSE、In-batch Negatives、ERNIE-Gram单塔模型等,推出前沿的语义检索方案,包含召回、排序环节,打通�?�练、调优、高效向量检索引擎建库和查询全流程。

更多使用说明请参考语义检索系统

智能�?答系统

基于🚀RocketQA技术的检索式�?答系统,支持FAQ�?答、说明书�?答等多种业务场景。

更多使用说明请参考智能�?答系统文档智能�?答

💌 评�?�观点抽取与情感分析

基于情感知识增强预�?�练模型SKEP,针对产品评�?�进行评价维度和观点抽取,以及细粒度的情感分析。

更多使用说明请参考情感分析

🎙️ 智能语音指令解析

集成了PaddleSpeech百度开放平台的的语音识别和UIE通用信息抽取等技术,打造智能一体化的语音指令解析系统范例,该方案可应用于智能语音填单、智能语音交互、智能语音检索等场景,提高人机交互效率。

更多使用说明请参考智能语音指令解析

高性能分布式�?�练与推理

FastTokenizer:高性能文本处理库

AutoTokenizer.from_pretrained("ernie-3.0-medium-zh", use_fast=True)

为了�?�现更极致的模型部署性能,�?�装FastTokenizers后只需在AutoTokenizer API上打开 use_fast=True选项,即可调用C++�?�现的高性能分词�?�子,轻松获得超Python百余倍的文本处理加速,更多使用说明可参考FastTokenizer文档

⚡️ FastGeneration:高性能生成加速库

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)

�?�单地在generate()API上打开use_fast=True选项,轻松在Transformer、GPT、BART、PLATO、UniLM等生成式预�?�练模型上获得5倍以上GPU加速,更多使用说明可参考FastGeneration文档

🚀 Fleet:飞桨4D混合并行分布式�?�练技术

更多关于千亿级AI模型的分布式�?�练使用说明可参考GPT-3

�?�装

环境依赖

  • python >= 3.7
  • paddlepaddle >= 2.2

pip�?�装

pip install --upgrade paddlenlp

或者可通过以下命令�?�装最新 develop 分支代码:

pip install paddlenlp -f https://www.paddlepaddle.org.cn/whl/paddlenlp.html

更多关于PaddlePaddle和PaddleNLP�?�装的详细教程请查看Installation

快速开始

这里以信息抽取-命名�?�体识别任务,UIE模型为例,来说明如何快速使用PaddleNLP:

一�?预测

PaddleNLP提供一�?预测功能,无需�?�练,直接输入数�?即可开放域抽取结果:

>>> from pprint import pprint
>>> from paddlenlp import Taskflow

>>> schema = ['时间', '选手', '赛事名称'] # Define the schema for entity extraction
>>> ie = Taskflow('information_extraction', schema=schema)
>>> pprint(ie("2月8日上午北京冬奥会自由式滑雪女子大跳台决赛中中国选手谷爱凌以188.25分获得金牌!"))
[{'时间': [{'end': 6,
          'probability': 0.9857378532924486,
          'start': 0,
          'text': '2月8日上午'}],
  '赛事名称': [{'end': 23,
            'probability': 0.8503089953268272,
            'start': 6,
            'text': '北京冬奥会自由式滑雪女子大跳台决赛'}],
  '选手': [{'end': 31,
          'probability': 0.8981548639781138,
          'start': 28,
          'text': '谷爱凌'}]}]

小样本学习

如果对一�?预测效果不满意,也可以使用少量数�?进行模型精调,进一步提升特�?�场景的效果,详见UIE小样本�?�制�?�练

更多PaddleNLP内�?�可参考:

  • 精选模型库,包含优质预�?�练模型的端到端全流程使用。
  • 多场景示例,了解如何使用PaddleNLP解决NLP多种技术�?题,包含基础技术、系统应用与拓展应用。
  • 交互式教程,在🆓免费�?�力平台AI Studio上快速学习PaddleNLP。

API文档

PaddleNLP提供全流程的文本领域API,可大幅提升NLP任务建模的效率:

更多使用方法请参考API文档

Citation

如果PaddleNLP对您的研究有�?助,欢迎引用

@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

我们借鉴了Hugging Face的Transformers🤗关于预�?�练模型使用的优秀�?��?�,在此对Hugging Face作者及其开源社区表示感谢。

License

PaddleNLP遵循Apache-2.0开源协�??