飞桨自然语言处理套件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

相关推荐
做cv的小昊14 分钟前
结合代码读3DGS论文(10)——ICLR 2025 3DGS加速&压缩新工作Sort-Free 3DGS论文及代码解读
论文阅读·人工智能·游戏·计算机视觉·3d·图形渲染·3dgs
机器之心18 分钟前
龙虾之后,为什么说「主动式智能」才是Agent的终极形态?
人工智能·openai
智算菩萨22 分钟前
GPT-5.4 Pro与Thinking模型全面研究报告
人工智能·gpt·ai·chatgpt·ai-native
团子和二花30 分钟前
openclaw平替之nanobot源码解析(八):Gateway进阶——定时任务与心跳机制
人工智能·gateway
机器之心33 分钟前
昨晚,OpenClaw大更新,亲手终结「旧插件」时代
人工智能·openai
码路高手41 分钟前
Trae-Agent源码重点
人工智能·架构
剑穗挂着新流苏3121 小时前
114_PyTorch 进阶:模型保存与读取的两大方式及“陷阱”避坑指南
人工智能·pytorch·深度学习
CoovallyAIHub1 小时前
把 Whisper、Moonshine、SenseVoice 统统装进手机:sherpa-onnx 离线语音部署框架,GitHub 10.9K Star
人工智能·架构
一只叫煤球的猫1 小时前
RAG 如何落地?从原理解释到工程实现
人工智能·后端·ai编程
AI营销快线1 小时前
AI营销获客难?原圈科技深度解析SaaS系统增长之道
大数据·人工智能