Github GitHub - PaddlePaddle/PaddleNLP: NLP Core Library and Model Zoo based on...
source link: https://github.com/PaddlePaddle/PaddleNLP
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
简体中文 | English
PaddleNLP 2.0拥有覆盖多场景的模型库、简洁易用的全流程API与动静统一的高性能分布式训练能力,旨在为飞桨开发者提升文本领域建模效率,并提供基于PaddlePaddle 2.0的NLP领域最佳实践。
-
覆盖多场景的模型库
-
简洁易用的全流程API
- 深度兼容飞桨2.0的高层API体系,内置可复用的文本建模模块(Embedding, CRF, Seq2Vec, Transformer),可大幅度减少在数据处理、模型组网、训练与评估、推理部署环节的开发量,提升NLP任务迭代与落地的效率。
-
动静统一的高性能分布式训练
- 基于飞桨2.0核心框架『动静统一』的特性与领先的混合精度优化策略,结合Fleet分布式训练API,可充分利用GPU集群资源,高效完成大规模预训练模型的分布式训练。
- python >= 3.6
- paddlepaddle >= 2.0.1
pip安装
pip install --upgrade paddlenlp -i https://pypi.org/simple
更多关于PaddlePaddle的安装和PaddleNLP安装详细教程请查看Installation
数据集快速加载
from paddlenlp.datasets import load_dataset train_ds, dev_ds, test_ds = load_dataset("chnsenticorp", splits=["train", "dev", "test"])
可参考Dataset文档查看更多数据集。
一键加载预训练中文词向量
from paddlenlp.embeddings import TokenEmbedding wordemb = TokenEmbedding("w2v.baidu_encyclopedia.target.word-word.dim300") print(wordemb.cosine_sim("国王", "王后")) >>> 0.63395125 wordemb.cosine_sim("艺术", "火车") >>> 0.14792643
内置50+中文词向量,更多使用方法请参考Embedding文档。
一键加载高质量中文预训练模型
from paddlenlp.transformers import ErnieModel, BertModel, RobertaModel, ElectraModel, GPT2ForPretraining ernie = ErnieModel.from_pretrained('ernie-1.0') bert = BertModel.from_pretrained('bert-wwm-chinese') roberta = RobertaModel.from_pretrained('roberta-wwm-ext') electra = ElectraModel.from_pretrained('chinese-electra-small') gpt2 = GPT2ForPretraining.from_pretrained('gpt2-base-cn')
便捷获取文本特征
import paddle from paddlenlp.transformers import ErnieTokenizer, ErnieModel tokenizer = ErnieTokenizer.from_pretrained('ernie-1.0') model = ErnieModel.from_pretrained('ernie-1.0') text = tokenizer('自然语言处理') pooled_output, sequence_output = model(input_ids=paddle.to_tensor([text['input_ids']]))
请参考Transformer API文档查看目前支持的预训练模型。
模型库及其应用
PaddleNLP模型库整体介绍请参考文档PaddleNLP Model Zoo。 模型应用场景介绍请参考PaddleNLP Examples。
API 使用文档
- Transformer API
- 基于Transformer结构相关的预训练模型API,包含ERNIE, BERT, RoBERTa, Electra等主流经典结构和下游任务。
- Data API
- 文本数据处理Pipeline的相关API说明。
- Dataset API
- 数据集相关API,包含自定义数据集,数据集贡献与数据集快速加载等功能说明。
- Embedding API
- 词向量相关API,支持一键快速加载包预训练的中文词向量,VisulDL高维可视化等功能说明。
- Metrics API
- 针对NLP场景的评估指标说明,与飞桨2.0框架高层API兼容。
交互式Notebook教程
更多教程参见PaddleNLP on AI Studio。
社区贡献与技术交流
特殊兴趣小组
- 欢迎您加入PaddleNLP的SIG社区,贡献优秀的模型实现、公开数据集、教程与案例、外围小工具。
- 现在就加入PaddleNLP的QQ技术交流群,一起交流NLP技术吧!
Slack
- 欢迎加入PaddleNLP Slack channel与我们的开发者进行技术交流。
License
PaddleNLP遵循Apache-2.0开源协议。
Recommend
About Joyk
Aggregate valuable and interesting links.
Joyk means Joy of geeK