赞
踩
近期有做信息抽取的需求,UIE在信息抽取方面效果不错。
huggingface上下载UIE模型:PaddlePaddle/uie-base · Hugging Face
点击“Clone Repository”,确定git clone的链接
其中包含大文件,需要在windows安装git-lfs,在https://git-lfs.com/下载git-lfs,安装。
git lfs clone 仓库链接
UIE使用需要安装paddlenlp
paddlenlp依赖paddlepaddle-gpu或paddlepaddle;
忘了因为什么原因,python3.7和python3.11上安装paddlenlp存在问题,在python3.9上成功安装了。
为了使用GPU进行模型训练和推理,在GPU机器安装了NVIDIA Driver、CUDA、Cudnn。
这里踩了个坑:
CUDA 工具包 11.2 配合 cuDNN v8.2.1使用,安装paddlepaddle-gpu有特定版本
python -m pip install paddlepaddle-gpu==2.4.2.post112 -f https://www.paddlepaddle.org.cn/whl/windows/mkl/avx/stable.html
一定要采用这个版本,如果安装了paddlepaddle-gpu=2.4.2版本,运行会报错:
RuntimeError: (PreconditionNotMet) The third-party dynamic library (cudnn64_7.dll) that Paddle depends on is not configured correctly. (error code is 126)
另外,运行时,如果程序中断,提示错误,检查专用GPU内存几乎占满,则八成是模型太大了,GPU内存太小导致的问题,减少模型训练的batch_size即可。
exit code -1073740791 0xC0000409
- >>> 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分获得金牌!")) # Better print results using pprint
- [{'时间': [{'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': '谷爱凌'}]}]
![](https://csdnimg.cn/release/blogv2/dist/pc/img/newCodeMoreWhite.png)
来源:PaddleNLP/taskflow_text.md at develop · PaddlePaddle/PaddleNLP
PaddleNLP/applications/information_extraction/text at develop · PaddlePaddle/PaddleNLPUIE在实体识别和关系抽取上的实践PaddleNLP/applications/information_extraction/text at develop · PaddlePaddle/PaddleNLP
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。