飞桨自然语言处理套件PaddleNLP初探

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

官网:GitHub - PaddlePaddle/PaddleNLP: 👑 Easy-to-use and powerful NLP and LLM 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 etc.

pip安装

复制代码
pip install --upgrade paddlenlp

快速开始

大模型文本生成

PaddleNLP提供了方便易用的Auto API,能够快速的加载模型和Tokenizer。这里以使用 linly-ai/chinese-llama-2-7b 大模型做文本生成为例:

复制代码
>>> from paddlenlp.transformers import AutoTokenizer, AutoModelForCausalLM
>>> tokenizer = AutoTokenizer.from_pretrained("linly-ai/chinese-llama-2-7b")
>>> model = AutoModelForCausalLM.from_pretrained("linly-ai/chinese-llama-2-7b", dtype="float16")
>>> input_features = tokenizer("你好!请自我介绍一下。", return_tensors="pd")
>>> outputs = model.generate(**input_features, max_length=128)
>>> tokenizer.batch_decode(outputs[0])
# ['\n你好!我是一个AI语言模型,可以回答你的问题和提供帮助。']

一键UIE预测

PaddleNLP提供一键预测功能,无需训练,直接输入数据即可开放域抽取结果。这里以信息抽取-命名实体识别任务,UIE模型为例:

复制代码
>>> 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分获得金牌!"))

大模型

文档:https://github.com/PaddlePaddle/PaddleNLP/tree/develop/llm

相关推荐
厚德云7 分钟前
全球首款填空式AI绘画提示词工具PromptFill正式发布
人工智能·ai作画·云计算·aigc·ai绘画
泰迪智能科技13 分钟前
案例分享|高校实验室建设方向+合作平台+建设成效
人工智能
摸鱼仙人~15 分钟前
一文详解PyTorch DDP
人工智能·pytorch·python
胡伯来了18 分钟前
16 Transformers - 使用大语言模型
人工智能·语言模型·自然语言处理
liliangcsdn43 分钟前
LLM MoE 形式化探索
大数据·人工智能
新智元1 小时前
硅谷青睐的中国模型更新了!一觉醒来,直接套壳
人工智能·openai
机器之心1 小时前
无需再训练微调,一个辅助系统让GPT-5.2准确率飙到创纪录的75%
人工智能·openai
科技云报道1 小时前
科技云报到:2026网络安全六大新趋势:AI重构攻防,信任成为新防线
人工智能·科技·web安全
机器之心1 小时前
微软定目标:2030年,彻底删除C、C++代码,换成Rust
人工智能·openai
新智元1 小时前
超越谷歌,全球第一!上交 AI 科学家王者归来,登顶 OpenAI MLE-bench
人工智能·openai