Skip to content

Commit b523418

Browse files
authored
add document for PP-ChatOCRv4-doc (#3324)
1 parent 83e39f1 commit b523418

File tree

4 files changed

+2388
-49
lines changed

4 files changed

+2388
-49
lines changed

docs/pipeline_usage/tutorials/information_extraction_pipelines/document_scene_information_extraction_v3.md

+73-40
Original file line numberDiff line numberDiff line change
@@ -338,40 +338,14 @@ PaddleX 所提供的预训练的模型产线均可以快速体验效果,你可
338338
### 2.2 本地体验
339339
在本地使用文档场景信息抽取v3产线前,请确保您已经按照[PaddleX本地安装教程](../../../installation/installation.md)完成了PaddleX的wheel包安装。
340340

341-
首先需要配置获取 `PP-ChatOCRv3-doc` 产线的配置文件,可以通过以下命令获取:
342-
```bash
343-
paddlex --get_pipeline_config PP-ChatOCRv3-doc ./
344-
```
345-
346-
执行上述命令后,配置文件会存储在当前路径下,打开配置文件,填写大语言模型的 ak/sk(access_token),如下所示:
347-
348-
```yaml
349-
......
350-
SubModules:
351-
LLM_Chat:
352-
module_name: chat_bot
353-
model_name: ernie-3.5
354-
api_type: qianfan
355-
ak: "" # Your LLM API key
356-
sk: "" # Your LLM secret key
357-
358-
LLM_Retriever:
359-
module_name: retriever
360-
model_name: ernie-3.5
361-
api_type: qianfan
362-
ak: "" # Your LLM API key
363-
sk: "" # Your LLM secret key
364-
......
365-
```
366-
367-
PP-ChatOCRv3-doc 仅支持文心大模型,支持在[百度云千帆平台](https://console.bce.baidu.com/qianfan/ais/console/onlineService)或者[星河社区 AIStudio](https://aistudio.baidu.com/)上获取相关的 ak/sk(access_token)。如果使用百度云千帆平台,可以参考[AK和SK鉴权调用API流程](https://cloud.baidu.com/doc/WENXINWORKSHOP/s/Hlwerugt8) 获取ak/sk,如果使用星河社区 AIStudio,可以在[星河社区 AIStudio 访问令牌](https://aistudio.baidu.com/account/accessToken)中获取 access_token。
341+
在进行模型推理之前,首先需要准备大语言模型的 api_key,PP-ChatOCRv3 支持调用 [百度云千帆平台](https://console.bce.baidu.com/qianfan/ais/console/onlineService) 提供的大模型推理服务,您可以参考[认证鉴权](https://cloud.baidu.com/doc/WENXINWORKSHOP/s/Um2wxbaps) 获取千帆平台的 api_key。
368342

369343
更新配置文件后,即可使用几行Python代码完成快速推理,可以使用 [测试文件](https://paddle-model-ecology.bj.bcebos.com/paddlex/imgs/demo_image/vehicle_certificate-1.png)测试:
370344

371345
```python
372346
from paddlex import create_pipeline
373347

374-
pipeline = create_pipeline(pipeline="./PP-ChatOCRv3-doc.yaml")
348+
pipeline = create_pipeline(pipeline="PP-ChatOCRv3-doc",initial_predictor=False)
375349

376350
visual_predict_res = pipeline.visual_predict(input="vehicle_certificate-1.png",
377351
use_doc_orientation_classify=False,
@@ -385,8 +359,32 @@ for res in visual_predict_res:
385359
visual_info_list.append(res["visual_info"])
386360
layout_parsing_result = res["layout_parsing_result"]
387361

388-
vector_info = pipeline.build_vector(visual_info_list, flag_save_bytes_vector=True)
389-
chat_result = pipeline.chat(key_list=["驾驶室准乘人数"], visual_info=visual_info_list, vector_info=vector_info)
362+
vector_info = pipeline.build_vector(visual_info_list, flag_save_bytes_vector=True,retriever_config={
363+
"module_name": "retriever",
364+
"model_name": "embedding-v1",
365+
"base_url": "https://qianfan.baidubce.com/v2",
366+
"api_type": "qianfan",
367+
"api_key": "api_key" # your api_key
368+
})
369+
chat_result = pipeline.chat(
370+
key_list=["驾驶室准乘人数"],
371+
visual_info_list=visual_info_list,
372+
vector_info=vector_info,
373+
chat_bot_config={
374+
"module_name": "chat_bot",
375+
"model_name": "ernie-3.5-8k",
376+
"base_url": "https://qianfan.baidubce.com/v2",
377+
"api_type": "openai",
378+
"api_key": "api_key" # your api_key
379+
},
380+
retriever_config={
381+
"module_name": "retriever",
382+
"model_name": "embedding-v1",
383+
"base_url": "https://qianfan.baidubce.com/v2",
384+
"api_type": "qianfan",
385+
"api_key": "api_key" # your api_key
386+
}
387+
)
390388
print(chat_result)
391389

392390
```
@@ -437,6 +435,12 @@ PP-ChatOCRv3-doc 预测的流程、API说明、产出说明如下:
437435
<td><code>bool</code></td>
438436
<td><code>False</code></td>
439437
</tr>
438+
<tr>
439+
<td><code>initial_predictor</code></td>
440+
<td>是否初始化推理模块(如果为<code>False</code>则在首次使用相关推理模块的时候进行初始化)</td>
441+
<td><code>bool</code></td>
442+
<td><code>True</code></td>
443+
</tr>
440444
</tbody>
441445
</table>
442446
</details>
@@ -847,9 +851,9 @@ for res in visual_predict_res:
847851
- `use_formula_recognition`: `(bool)` 控制是否启用公式识别子产线
848852

849853
- `parsing_res_list`: `(List[Dict])` 解析结果的列表,每个元素为一个字典,列表顺序为解析后的阅读顺序。
850-
- `layout_bbox`: `(np.ndarray)` 版面区域的边界框。
851-
- `{label}`: `(str)` key 为版面区域的标签,例如`text`, `table`,内容为版面区域内的内容
852-
- `layout`: `(str)` 版面排版类型,例如 `double`, `single`
854+
- `block_bbox`: `(np.ndarray)` 版面区域的边界框。
855+
- `block_label`: `(str)` 版面区域的标签,例如`text`, `table`等。
856+
- `block_content`: `(str)` 内容为版面区域内的内容
853857

854858
- `overall_ocr_res`: `(Dict[str, Union[List[str], List[float], numpy.ndarray]])` 全局 OCR 结果的字典
855859
- `input_path`: `(Union[str, None])` 图像OCR子产线接受的图像路径,当输入为`numpy.ndarray`时,保存为`None`
@@ -871,12 +875,6 @@ for res in visual_predict_res:
871875
- `rec_scores`: `(List[float])` 文本识别的置信度列表,已按`text_rec_score_thresh`过滤
872876
- `rec_polys`: `(List[numpy.ndarray])` 经过置信度过滤的文本检测框列表,格式同`dt_polys`
873877

874-
- `text_paragraphs_ocr_res`: `(Dict[str, Union[List[str], List[float], numpy.ndarray]])` 段落OCR结果,版面类型非表格、印章和公式类型的段落OCR结果
875-
- `rec_polys`: `(List[numpy.ndarray])` 文本检测框列表,格式同`dt_polys`
876-
- `rec_texts`: `(List[str])` 文本识别结果列表
877-
- `rec_scores`: `(List[float])` 文本识别结果的置信度列表
878-
- `rec_boxes`: `(numpy.ndarray)` 检测框的矩形边界框数组,shape为(n, 4),dtype为int16。每一行表示一个
879-
880878
- `formula_res_list`: `(List[Dict[str, Union[numpy.ndarray, List[float], str]]])` 公式识别结果列表,每个元素为一个字典
881879
- `rec_formula`: `(str)` 公式识别结果
882880
- `rec_polys`: `(numpy.ndarray)` 公式检测框,shape为(4, 2),dtype为int16
@@ -964,6 +962,14 @@ for res in visual_predict_res:
964962
<td><code>3500</code></td>
965963
</tr>
966964
<tr>
965+
<td><code>block_size</code></td>
966+
<td>长文本建立向量库时分块大小</td>
967+
<td><code>int</code></td>
968+
<td>
969+
大于0的正整数,可以根据大语言模型支持的token长度来决定
970+
</td>
971+
<td><code>300</code></td>
972+
</tr>
967973
<tr>
968974
<td><code>flag_save_bytes_vector</code></td>
969975
<td>文字是否保存为二进制文件</td>
@@ -973,7 +979,16 @@ for res in visual_predict_res:
973979
</td>
974980
<td><code>False</code></td>
975981
</tr>
976-
</tr></table>
982+
<tr>
983+
<td><code>retriever_config</code></td>
984+
<td>向量检索大模型配置参数,内容参考配置文件中的“LLM_Retriever”字段</td>
985+
<td><code>dict</code></td>
986+
<td>
987+
<code>None</code>
988+
</td>
989+
<td><code>None</code></td>
990+
</tr>
991+
</table>
977992
该方法会返回一个包含视觉文本信息的字典,字典的内容如下:
978993

979994
- `flag_save_bytes_vector``(bool)`是否将结果保存为二进制文件
@@ -1101,6 +1116,24 @@ for res in visual_predict_res:
11011116
<td><code>None</code></td>
11021117
<td><code>None</code></td>
11031118
</tr>
1119+
<tr>
1120+
<td><code>chat_bot_config</code></td>
1121+
<td>大语言模型配置信息,内容参考产线配置文件“LLM_Chat”字段</td>
1122+
<td><code>dict</code></td>
1123+
<td>
1124+
<code>None</code>
1125+
</td>
1126+
<td><code>None</code></td>
1127+
</tr>
1128+
<tr>
1129+
<td><code>retriever_config</code></td>
1130+
<td>向量检索大模型配置参数,内容参考配置文件中的“LLM_Retriever”字段</td>
1131+
<td><code>dict</code></td>
1132+
<td>
1133+
<code>None</code>
1134+
</td>
1135+
<td><code>None</code></td>
1136+
</tr>
11041137
</tbody>
11051138
</table>
11061139

0 commit comments

Comments
 (0)