Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Benchmark README.md& Optimize Pipelines README.md #3160

Merged
merged 2 commits into from
Aug 30, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
66 changes: 66 additions & 0 deletions pipelines/FAQ.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
## FAQ

#### pip安装htbuilder包报错,`UnicodeDecodeError: 'gbk' codec can't decode byte....`

windows的默认字符gbk导致的,可以使用源码进行安装,源码已经进行了修复。

```
git clone https://github.com/tvst/htbuilder.git
cd htbuilder/
python setup install
```

#### 语义检索系统可以跑通,但终端输出字符是乱码怎么解决?

+ 通过如下命令设置操作系统默认编码为 zh_CN.UTF-8
```bash
export LANG=zh_CN.UTF-8
```

#### Linux上安装elasticsearch出现错误 `java.lang.RuntimeException: can not run elasticsearch as root`

elasticsearch 需要在非root环境下运行,可以做如下的操作:

```
adduser est
chown est:est -R ${HOME}/elasticsearch-8.3.2/
cd ${HOME}/elasticsearch-8.3.2/
su est
./bin/elasticsearch
```

#### Mac OS上安装elasticsearch出现错误 `flood stage disk watermark [95%] exceeded on.... all indices on this node will be marked read-only`

elasticsearch默认达到95%就全都设置只读,可以腾出一部分空间出来再启动,或者修改 `config/elasticsearch.pyml`。
```
cluster.routing.allocation.disk.threshold_enabled: false
```

#### nltk_data加载失败的错误 `[nltk_data] Error loading punkt: [Errno 60] Operation timed out`

在命令行里面输入python,然后输入下面的命令进行下载:

```
import nltk
nltk.download('punkt')
```
如果下载还是很慢,可以手动[下载](https://github.com/nltk/nltk_data/tree/gh-pages/packages/tokenizers),然后放入本地的`~/nltk_data/tokenizers`进行解压即可。

#### 服务端运行报端口占用的错误 `[Errno 48] error while attempting to bind on address ('0.0.0.0',8891): address already in use`

```
lsof -i:8891
kill -9 PID # PID为8891端口的进程
```

### faiss 安装上了但还是显示找不到faiss怎么办?

推荐您使用anaconda进行单独安装,安装教程请参考[faiss](https://github.com/facebookresearch/faiss/blob/main/INSTALL.md)

```
# CPU-only version
conda install -c pytorch faiss-cpu

# GPU(+CPU) version
conda install -c pytorch faiss-gpu
```
19 changes: 19 additions & 0 deletions pipelines/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ PaddleNLP Pipelines 是一个端到端智能文本产线框架,面向 NLP **
<img src="https://user-images.githubusercontent.com/11793384/168514868-1babe981-c675-4f89-9168-dd0a3eede315.gif" width="500">
</div>



## 智能文本产线特色
* **全场景支持**:依托灵活的插拔式组件产线化设计,支持各类 NLP 场景任务,包括:信息抽取、情感倾向分析、阅读理解、检索系统、问答系统、文本分类、文本生成等。

Expand All @@ -15,6 +17,14 @@ PaddleNLP Pipelines 是一个端到端智能文本产线框架,面向 NLP **

* **灵活可定制**:除深度兼容 PaddleNLP 模型组件外,还可嵌入飞桨生态下任意模型、[AI 开放平台算子](https://ai.baidu.com/)、其它开源项目如 Elasticsearch 等作为基础组件,快速扩展,从而实现任意复杂系统的灵活定制开发。

## Benchmarks

<div align="center">
<img src="https://user-images.githubusercontent.com/12107462/187362675-f0818e77-a521-4479-8dd7-bcbf4a820f7d.png" width="500">
</div>

更多的Benchmarks的信息请参考文档[Benchmarks](./benchmarks/README.md)

## 智能文本产线库

PaddleNLP Pipelines 智能文本产线库针对 NLP 部分高频场景开源了经过充分打磨的产品级系统,并会不断开放其它场景的产品级系统,用户可以基于智能文本产线库提供的系统能力快速开发出适配业务数据的产品。
Expand Down Expand Up @@ -106,12 +116,21 @@ docker run \
```

#### 部署 CPU 服务

对于Linux使用Docker的用户,使用下面的命令:
```
docker pull registry.baidubce.com/paddlepaddle/paddlenlp:2.4.0
docker run -d --name paddlenlp_pipelines --net host -ti registry.baidubce.com/paddlepaddle/paddlenlp:2.4.0
```
对于Windows&Macos上使用Docker的用户,用下面的命令:

```
docker pull registry.baidubce.com/paddlepaddle/paddlenlp:2.4.0.windows.darwin
docker run -d --name paddlenlp_pipelines -p 8891:8891 -p 8502:8502 -ti registry.baidubce.com/paddlepaddle/paddlenlp:2.4.0.windows.darwin
```
CPU 镜像下载大概耗时 10 分钟左右,容器启动成功后,等待3分钟左右,通过浏览器访问 [http://127.0.0.1:8502](http://127.0.0.1:8502) 快速体验产品级语义检索服务。


#### 部署 GPU 服务
```
docker pull registry.baidubce.com/paddlepaddle/paddlenlp:2.4.0-gpu-cuda10.2-cudnn7
Expand Down
47 changes: 47 additions & 0 deletions pipelines/benchmarks/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
# ERNIE 3.0 的RocketQA模型


## 模型介绍

本次开源的模型ERNIE 3.0系列的模型的基础上,使用RocketQA的训练策略训练的`DualEncoder`和`CrossEncoder`模型,相比于原始的RocektQA模型,在中文上的效果达到最佳。

## 模型效果

### DualEncoder模型效果

| 模型 | 模型规模 | MRR@10 | Recall@1 | Recall@50 |
| :--------------------------: | :-------------------------------: | :-------------: |:-------------: |:-------------: |
| rocketqa-baselines | 12-layer, 768-hidden | 56.45% |45.05% | 91.40%|
| rocketqa-zh-base-query-encoder&rocketqa-zh-base-para-encoder | 12-layer, 768-hidden | **59.14%** |**48.00%** | **92.15%**|
| rocketqa-zh-medium-query-encoder&rocketqa-zh-medium-para-encoder | 6-layer, 768-hidden | 53.92% |42.35% | 89.75%|
| rocketqa-zh-mini-query-encoder&rocketqa-zh-mini-para-encoder | 6-layer, 384-hidden | 44.97% |34.25% | 84.97%|
| rocketqa-zh-micro-query-encoder&rocketqa-zh-micro-para-encoder | 4-layer, 384-hidden | 40.22% |28.70% | 83.40% |
| rocketqa-zh-nano-query-encoder&rocketqa-zh-nano-para-encoder | 4-layer, 312-hidden | 38.07% |27.35% | 80.35%|


### CrossEncoder模型效果

| 模型 | 模型规模 | MRR@10 | Recall@1 | Recall@50 |
| :--------------------------: | :-------------------------------: | :-------------: |:-------------: |:-------------: |
| rocketqa-baselines | 12-layer, 768-hidden | 65.62% |55.50% | 91.75%|
| rocketqa-base-cross-encoder| 12-layer, 768-hidden | **76.64%** |**70.05%** | **91.75%**|
| rocketqa-medium-cross-encoder | 6-layer, 768-hidden | 74.82% |67.30% | 91.75%|
| rocketqa-mini-cross-encoder | 6-layer, 384-hidden | 70.25% |60.85% | 91.75%|
| rocketqa-micro-cross-encoder | 4-layer, 384-hidden | 68.80% |59.35% | 91.75% |
| rocketqa-nano-cross-encoder | 4-layer, 312-hidden | 67.99% |58.25% | 91.75%|


## 模型性能

RocketQA系列的模型在GPU上能够达到ms级别的速度,一个query大概20ms左右,最快能够达到10ms,另外,为了验证在CPU上的速度,我们使用RocketQA系列的模型在CPU上测试了构建索引的时间,数据集是1398条,在cpu上的测试时间,以下cpu上的查询时间指的是在后台query发一次请求经过模型处理后得到结果的时间,包含召回和排序两部分,召回的文本数为30条。

| 模型 | 模型规模 | 构建索引时间 | 查询一条文本时间 |
| :--------------------------: | :-------------------------------: | :-------------: |:-------------: |
| rocketqa-baselines | 12-layer, 768-hidden | 15min46s |10.04s/30条 |
| rocketqa-zh-base | 12-layer, 768-hidden | 15min54s |11.50s/30条 |
| rocketqa-zh-medium| 6-layer, 768-hidden | 7min54s | 5.39s/30条 |
| rocketqa-zh-mini | 6-layer, 384-hidden | 4min10s |4.02s/30条 |
| rocketqa-zh-micro | 4-layer, 384-hidden | 2min49s |3.0s/30条 |
| rocketqa-zh-nano | 4-layer, 312-hidden | 2min30s |2.84s/30条 |

注意在测试速度的时候会有一些浮动,有很多因素会影响测试速度,比如 `elastic search`本身的性能,检索的文本数目,但总体的结论不会变。
4 changes: 3 additions & 1 deletion pipelines/examples/frequently-asked-question/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ c. 依赖安装:
```bash
pip install -r requirements.txt -i https://pypi.tuna.tsinghua.edu.cn/simple
# 1) 安装 pipelines package
cd ${HOME}/PaddleNLP/applications/experimental/pipelines/
cd ${HOME}/PaddleNLP/pipelines/
python setup.py install
```
【注意】以下的所有的流程都只需要在`pipelines`根目录下进行,不需要跳转目录
Expand Down Expand Up @@ -162,6 +162,8 @@ sh examples/frequently-asked-question/run_faq_web.sh
选保险产品时,保险公司很重要吗? 重要,但不是第一重要,也不是最重要。产品应该是优先于公司的,毕竟产品的保障才是最直接和我们的利益挂钩的。在保险产品的保障差不多的情况下,知名度更高的保险公司会更好。
```

如果安装遇见问题可以查看[FAQ文档](../../FAQ.md)

## Reference
[1]Y. Sun et al., “[ERNIE 3.0: Large-scale Knowledge Enhanced Pre-training for Language Understanding and Generation](https://arxiv.org/pdf/2107.02137.pdf),” arXiv:2107.02137 [cs], Jul. 2021, Accessed: Jan. 17, 2022. [Online]. Available: http://arxiv.org/abs/2107.02137

Expand Down
21 changes: 7 additions & 14 deletions pipelines/examples/question-answering/Install_windows.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# WINDOWS环境下搭建端到端智能问答系统

以下的流程都是使用的Anaconda的环境进行的搭建,Anaconda安装好以后,进入 `Anaconda Powershell Prompt`,然后执行下面的流程。
以下的流程都是使用的Anaconda的环境进行的搭建,Anaconda安装好以后,进入 `Anaconda Powershell Prompt`(由于环境变量设置不兼容的原因,暂不支持使用`cmd`执行下面的命令),然后执行下面的流程。

## 1. 快速开始: 城市百科知识问答系统搭建

Expand All @@ -9,9 +9,12 @@
a. 依赖安装:
首先需要安装PaddlePaddle,PaddlePaddle的安装请参考文档[官方安装文档](https://www.paddlepaddle.org.cn/install/quick?docurl=/documentation/docs/zh/install/pip/linux-pip.html),然后安装下面的依赖:
```bash
pip install -r requirements.txt -i https://pypi.tuna.tsinghua.edu.cn/simple
git clone https://github.com/tvst/htbuilder.git
cd htbuilder/
python setup install
# 1) 安装 pipelines package
cd ${HOME}/PaddleNLP/applications/experimental/pipelines/
cd ${HOME}/PaddleNLP/pipelines/
pip install -r requirements.txt -i https://pypi.tuna.tsinghua.edu.cn/simple
python setup.py install
```
【注意】以下的所有的流程都只需要在`pipelines`根目录下进行,不需要跳转目录
Expand Down Expand Up @@ -103,14 +106,4 @@ python -m streamlit run ui/webapp_question_answering.py --server.port 8502
长期,继续聚焦科技创新的五大方向。1)新能源(新能源汽车、光伏、风电、特高压等),2)新一代信息通信技术(人工智能、大数据、云计算、5G等),3)高端制造(智能数控机床、机器人、先进轨交装备等),4)生物医药(创新药、CXO、医疗器械和诊断设备等),5)军工(导弹设备、军工电子元器件、空间站、航天飞机等)。
```

## FAQ

#### pip安装htbuilder包报错,`UnicodeDecodeError: 'gbk' codec can't decode byte....`

windows的默认字符gbk导致的,可以使用源码进行安装,源码已经进行了修复。

```
git clone https://github.com/tvst/htbuilder.git
cd htbuilder/
python setup install
```
如果安装遇见问题可以查看[FAQ文档](../../FAQ.md)
4 changes: 3 additions & 1 deletion pipelines/examples/question-answering/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ c. 依赖安装:
```bash
pip install -r requirements.txt -i https://pypi.tuna.tsinghua.edu.cn/simple
# 1) 安装 pipelines package
cd ${HOME}/PaddleNLP/applications/experimental/pipelines/
cd ${HOME}/PaddleNLP/pipelines/
python setup.py install
```
【注意】以下的所有的流程都只需要在`pipelines`根目录下进行,不需要跳转目录
Expand Down Expand Up @@ -170,6 +170,8 @@ sh examples/question-answering/run_qa_web.sh
长期,继续聚焦科技创新的五大方向。1)新能源(新能源汽车、光伏、风电、特高压等),2)新一代信息通信技术(人工智能、大数据、云计算、5G等),3)高端制造(智能数控机床、机器人、先进轨交装备等),4)生物医药(创新药、CXO、医疗器械和诊断设备等),5)军工(导弹设备、军工电子元器件、空间站、航天飞机等)。
```

如果安装遇见问题可以查看[FAQ文档](../../FAQ.md)

## Reference
[1]Y. Sun et al., “[ERNIE 3.0: Large-scale Knowledge Enhanced Pre-training for Language Understanding and Generation](https://arxiv.org/pdf/2107.02137.pdf),” arXiv:2107.02137 [cs], Jul. 2021, Accessed: Jan. 17, 2022. [Online]. Available: http://arxiv.org/abs/2107.02137

Expand Down
14 changes: 9 additions & 5 deletions pipelines/examples/semantic-search/Install_windows.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# WINDOWS环境下搭建端到端语义检索系统
以下的流程都是使用的Anaconda的环境进行的搭建,Anaconda安装好以后,进入 `Anaconda Powershell Prompt`,然后执行下面的流程。
以下的流程都是使用的Anaconda的环境进行的搭建,Anaconda安装好以后,进入 `Anaconda Powershell Prompt`(由于环境变量设置不兼容的原因,暂不支持使用`cmd`执行下面的命令),然后执行下面的流程。

## 1. 快速开始: 快速搭建语义检索系统

Expand All @@ -8,14 +8,17 @@
a. 依赖安装:
首先需要安装PaddlePaddle,PaddlePaddle的安装请参考文档[官方安装文档](https://www.paddlepaddle.org.cn/install/quick?docurl=/documentation/docs/zh/install/pip/linux-pip.html),然后安装下面的依赖:
```bash
pip install -r requirements.txt -i https://pypi.tuna.tsinghua.edu.cn/simple
git clone https://github.com/tvst/htbuilder.git
cd htbuilder/
python setup install
# 1) 安装 pipelines package
cd ${HOME}/PaddleNLP/applications/experimental/pipelines/
cd ${HOME}/PaddleNLP/pipelines/
pip install -r requirements.txt -i https://pypi.tuna.tsinghua.edu.cn/simple
python setup.py install
```
【注意】以下的所有的流程都只需要在`pipelines`根目录下进行,不需要跳转目录
### 1.2 数据说明
语义检索数据库的数据来自于[DuReader-Robust数据集](https://github.com/baidu/DuReader/tree/master/DuReader-Robust),共包含 46972 个段落文本。
语义检索数据库的数据来自于[DuReader-Robust数据集](https://github.com/baidu/DuReader/tree/master/DuReader-Robust),共包含 46972 个段落文本,并选取了其中验证集1417条段落文本来搭建语义检索系统

### 1.3 一键体验语义检索系统
我们预置了基于[DuReader-Robust数据集](https://github.com/baidu/DuReader/tree/master/DuReader-Robust)搭建语义检索系统的代码示例,您可以通过如下命令快速体验语义检索系统的效果
Expand Down Expand Up @@ -58,7 +61,6 @@ python utils/offline_ann.py --index_name dureader_robust_query_encoder --doc_dir
* `port`: Elasticsearch的端口号
* `delete_index`: 是否删除现有的索引和数据,用于清空es的数据,默认为false


运行结束后,可使用Kibana查看数据

#### 1.4.3 启动 RestAPI 模型服务
Expand Down Expand Up @@ -92,3 +94,5 @@ python -m streamlit run ui/webapp_semantic_search.py --server.port 8502

长期,继续聚焦科技创新的五大方向。1)新能源(新能源汽车、光伏、风电、特高压等),2)新一代信息通信技术(人工智能、大数据、云计算、5G等),3)高端制造(智能数控机床、机器人、先进轨交装备等),4)生物医药(创新药、CXO、医疗器械和诊断设备等),5)军工(导弹设备、军工电子元器件、空间站、航天飞机等)。
```

如果安装遇见问题可以查看[FAQ文档](../../FAQ.md)
56 changes: 8 additions & 48 deletions pipelines/examples/semantic-search/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ c. 依赖安装:
```bash
pip install -r requirements.txt -i https://pypi.tuna.tsinghua.edu.cn/simple
# 1) 安装 pipelines package
cd ${HOME}/PaddleNLP/applications/experimental/pipelines/
cd ${HOME}/PaddleNLP/pipelines/
python setup.py install
```
【注意】以下的所有的流程都只需要在`pipelines`根目录下进行,不需要跳转目录
Expand Down Expand Up @@ -95,8 +95,6 @@ xpack.security.enabled: false
3. 检查确保 ES 服务启动成功
```bash
curl http://localhost:9200/_aliases?pretty=true
# 打印几条数据
curl http://localhost:9200/dureader_robust_query_encoder/_search
```
备注:ES 服务默认开启端口为 9200

Expand All @@ -106,6 +104,12 @@ curl http://localhost:9200/dureader_robust_query_encoder/_search
python utils/offline_ann.py --index_name dureader_robust_query_encoder \
--doc_dir data/dureader_dev
```
可以使用下面的命令来查看数据:

```
# 打印几条数据
curl http://localhost:9200/dureader_robust_query_encoder/_search
```

参数含义说明
* `index_name`: 索引的名称
Expand Down Expand Up @@ -160,51 +164,7 @@ sh examples/semantic-search/run_search_web.sh

长期,继续聚焦科技创新的五大方向。1)新能源(新能源汽车、光伏、风电、特高压等),2)新一代信息通信技术(人工智能、大数据、云计算、5G等),3)高端制造(智能数控机床、机器人、先进轨交装备等),4)生物医药(创新药、CXO、医疗器械和诊断设备等),5)军工(导弹设备、军工电子元器件、空间站、航天飞机等)。
```

## FAQ

#### 语义检索系统可以跑通,但终端输出字符是乱码怎么解决?

+ 通过如下命令设置操作系统默认编码为 zh_CN.UTF-8
```bash
export LANG=zh_CN.UTF-8
```

#### Linux上安装elasticsearch出现错误 `java.lang.RuntimeException: can not run elasticsearch as root`

elasticsearch 需要在非root环境下运行,可以做如下的操作:

```
adduser est
chown est:est -R ${HOME}/elasticsearch-8.3.2/
cd ${HOME}/elasticsearch-8.3.2/
su est
./bin/elasticsearch
```

#### Mac OS上安装elasticsearch出现错误 `flood stage disk watermark [95%] exceeded on.... all indices on this node will be marked read-only`

elasticsearch默认达到95%就全都设置只读,可以腾出一部分空间出来再启动,或者修改 `config/elasticsearch.pyml`。
```
cluster.routing.allocation.disk.threshold_enabled: false
```

#### nltk_data加载失败的错误 `[nltk_data] Error loading punkt: [Errno 60] Operation timed out`

在命令行里面输入python,然后输入下面的命令进行下载:

```
import nltk
nltk.download('punkt')
```
如果下载还是很慢,可以手动[下载](https://github.com/nltk/nltk_data/tree/gh-pages/packages/tokenizers),然后放入本地的`~/nltk_data/tokenizers`进行解压即可。

#### 服务端运行报端口占用的错误 `[Errno 48] error while attempting to bind on address ('0.0.0.0',8891): address already in use`

```
lsof -i:8891
kill -9 PID # PID为8891端口的进程
```
如果安装遇见问题可以查看[FAQ文档](../../FAQ.md)

## Reference
[1]Y. Sun et al., “[ERNIE 3.0: Large-scale Knowledge Enhanced Pre-training for Language Understanding and Generation](https://arxiv.org/pdf/2107.02137.pdf),” arXiv:2107.02137 [cs], Jul. 2021, Accessed: Jan. 17, 2022. [Online]. Available: http://arxiv.org/abs/2107.02137
Expand Down
2 changes: 1 addition & 1 deletion pipelines/pipelines/utils/import_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ def _optional_component_not_installed(component: str, dep_group: str,
raise ImportError(
f"Failed to import '{component}', "
"which is an optional component in pipelines.\n"
f"Run 'pip install farm-pipelines[{dep_group}]' "
f"Run 'pip install -r requirements.txt' "
"to install the required dependencies and make this component available."
) from source_error

Expand Down