Skip to content

Commit c5e8223

Browse files
committed
add document for PP-ChatOCRv4-doc
1 parent e751b04 commit c5e8223

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
@@ -312,40 +312,14 @@ PaddleX 所提供的预训练的模型产线均可以快速体验效果,你可
312312
### 2.2 本地体验
313313
在本地使用文档场景信息抽取v3产线前,请确保您已经按照[PaddleX本地安装教程](../../../installation/installation.md)完成了PaddleX的wheel包安装。
314314

315-
首先需要配置获取 `PP-ChatOCRv3-doc` 产线的配置文件,可以通过以下命令获取:
316-
```bash
317-
paddlex --get_pipeline_config PP-ChatOCRv3-doc ./
318-
```
319-
320-
执行上述命令后,配置文件会存储在当前路径下,打开配置文件,填写大语言模型的 ak/sk(access_token),如下所示:
321-
322-
```yaml
323-
......
324-
SubModules:
325-
LLM_Chat:
326-
module_name: chat_bot
327-
model_name: ernie-3.5
328-
api_type: qianfan
329-
ak: "" # Your LLM API key
330-
sk: "" # Your LLM secret key
331-
332-
LLM_Retriever:
333-
module_name: retriever
334-
model_name: ernie-3.5
335-
api_type: qianfan
336-
ak: "" # Your LLM API key
337-
sk: "" # Your LLM secret key
338-
......
339-
```
340-
341-
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。
315+
在进行模型推理之前,首先需要准备大语言模型的 api_key,PP-ChatOCRv3 支持调用 [百度云千帆平台](https://console.bce.baidu.com/qianfan/ais/console/onlineService) 提供的大模型推理服务,您可以参考[认证鉴权](https://cloud.baidu.com/doc/WENXINWORKSHOP/s/Um2wxbaps) 获取千帆平台的 api_key。
342316

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

345319
```python
346320
from paddlex import create_pipeline
347321

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

350324
visual_predict_res = pipeline.visual_predict(input="vehicle_certificate-1.png",
351325
use_doc_orientation_classify=False,
@@ -359,8 +333,32 @@ for res in visual_predict_res:
359333
visual_info_list.append(res["visual_info"])
360334
layout_parsing_result = res["layout_parsing_result"]
361335

362-
vector_info = pipeline.build_vector(visual_info_list, flag_save_bytes_vector=True)
363-
chat_result = pipeline.chat(key_list=["驾驶室准乘人数"], visual_info=visual_info_list, vector_info=vector_info)
336+
vector_info = pipeline.build_vector(visual_info_list, flag_save_bytes_vector=True,retriever_config={
337+
"module_name": "retriever",
338+
"model_name": "embedding-v1",
339+
"base_url": "https://qianfan.baidubce.com/v2",
340+
"api_type": "qianfan",
341+
"api_key": "api_key" # your api_key
342+
})
343+
chat_result = pipeline.chat(
344+
key_list=["驾驶室准乘人数"],
345+
visual_info_list=visual_info_list,
346+
vector_info=vector_info,
347+
chat_bot_config={
348+
"module_name": "chat_bot",
349+
"model_name": "ernie-3.5-8k",
350+
"base_url": "https://qianfan.baidubce.com/v2",
351+
"api_type": "openai",
352+
"api_key": "api_key" # your api_key
353+
},
354+
retriever_config={
355+
"module_name": "retriever",
356+
"model_name": "embedding-v1",
357+
"base_url": "https://qianfan.baidubce.com/v2",
358+
"api_type": "qianfan",
359+
"api_key": "api_key" # your api_key
360+
}
361+
)
364362
print(chat_result)
365363

366364
```
@@ -411,6 +409,12 @@ PP-ChatOCRv3-doc 预测的流程、API说明、产出说明如下:
411409
<td><code>bool</code></td>
412410
<td><code>False</code></td>
413411
</tr>
412+
<tr>
413+
<td><code>initial_predictor</code></td>
414+
<td>是否初始化推理模块(如果为<code>False</code>则在首次使用相关推理模块的时候进行初始化)</td>
415+
<td><code>bool</code></td>
416+
<td><code>True</code></td>
417+
</tr>
414418
</tbody>
415419
</table>
416420
</details>
@@ -821,9 +825,9 @@ for res in visual_predict_res:
821825
- `use_formula_recognition`: `(bool)` 控制是否启用公式识别子产线
822826

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

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

848-
- `text_paragraphs_ocr_res`: `(Dict[str, Union[List[str], List[float], numpy.ndarray]])` 段落OCR结果,版面类型非表格、印章和公式类型的段落OCR结果
849-
- `rec_polys`: `(List[numpy.ndarray])` 文本检测框列表,格式同`dt_polys`
850-
- `rec_texts`: `(List[str])` 文本识别结果列表
851-
- `rec_scores`: `(List[float])` 文本识别结果的置信度列表
852-
- `rec_boxes`: `(numpy.ndarray)` 检测框的矩形边界框数组,shape为(n, 4),dtype为int16。每一行表示一个
853-
854852
- `formula_res_list`: `(List[Dict[str, Union[numpy.ndarray, List[float], str]]])` 公式识别结果列表,每个元素为一个字典
855853
- `rec_formula`: `(str)` 公式识别结果
856854
- `rec_polys`: `(numpy.ndarray)` 公式检测框,shape为(4, 2),dtype为int16
@@ -938,6 +936,14 @@ for res in visual_predict_res:
938936
<td><code>3500</code></td>
939937
</tr>
940938
<tr>
939+
<td><code>block_size</code></td>
940+
<td>长文本建立向量库时分块大小</td>
941+
<td><code>int</code></td>
942+
<td>
943+
大于0的正整数,可以根据大语言模型支持的token长度来决定
944+
</td>
945+
<td><code>300</code></td>
946+
</tr>
941947
<tr>
942948
<td><code>flag_save_bytes_vector</code></td>
943949
<td>文字是否保存为二进制文件</td>
@@ -947,7 +953,16 @@ for res in visual_predict_res:
947953
</td>
948954
<td><code>False</code></td>
949955
</tr>
950-
</tr></table>
956+
<tr>
957+
<td><code>retriever_config</code></td>
958+
<td>向量检索大模型配置参数,内容参考配置文件中的“LLM_Retriever”字段</td>
959+
<td><code>dict</code></td>
960+
<td>
961+
<code>None</code>
962+
</td>
963+
<td><code>None</code></td>
964+
</tr>
965+
</table>
951966
该方法会返回一个包含视觉文本信息的字典,字典的内容如下:
952967

953968
- `flag_save_bytes_vector``(bool)`是否将结果保存为二进制文件
@@ -1075,6 +1090,24 @@ for res in visual_predict_res:
10751090
<td><code>None</code></td>
10761091
<td><code>None</code></td>
10771092
</tr>
1093+
<tr>
1094+
<td><code>chat_bot_config</code></td>
1095+
<td>大语言模型配置信息,内容参考产线配置文件“LLM_Chat”字段</td>
1096+
<td><code>dict</code></td>
1097+
<td>
1098+
<code>None</code>
1099+
</td>
1100+
<td><code>None</code></td>
1101+
</tr>
1102+
<tr>
1103+
<td><code>retriever_config</code></td>
1104+
<td>向量检索大模型配置参数,内容参考配置文件中的“LLM_Retriever”字段</td>
1105+
<td><code>dict</code></td>
1106+
<td>
1107+
<code>None</code>
1108+
</td>
1109+
<td><code>None</code></td>
1110+
</tr>
10781111
</tbody>
10791112
</table>
10801113

0 commit comments

Comments
 (0)