@@ -312,40 +312,14 @@ PaddleX 所提供的预训练的模型产线均可以快速体验效果,你可
312
312
### 2.2 本地体验
313
313
在本地使用文档场景信息抽取v3产线前,请确保您已经按照[ PaddleX本地安装教程] ( ../../../installation/installation.md ) 完成了PaddleX的wheel包安装。
314
314
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。
342
316
343
317
更新配置文件后,即可使用几行Python代码完成快速推理,可以使用 [ 测试文件] ( https://paddle-model-ecology.bj.bcebos.com/paddlex/imgs/demo_image/vehicle_certificate-1.png ) 测试:
344
318
345
319
``` python
346
320
from paddlex import create_pipeline
347
321
348
- pipeline = create_pipeline(pipeline = " ./ PP-ChatOCRv3-doc.yaml " )
322
+ pipeline = create_pipeline(pipeline = " PP-ChatOCRv3-doc" , initial_predictor = False )
349
323
350
324
visual_predict_res = pipeline.visual_predict(input = " vehicle_certificate-1.png" ,
351
325
use_doc_orientation_classify = False ,
@@ -359,8 +333,32 @@ for res in visual_predict_res:
359
333
visual_info_list.append(res[" visual_info" ])
360
334
layout_parsing_result = res[" layout_parsing_result" ]
361
335
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
+ )
364
362
print (chat_result)
365
363
366
364
```
@@ -411,6 +409,12 @@ PP-ChatOCRv3-doc 预测的流程、API说明、产出说明如下:
411
409
<td ><code >bool</code ></td >
412
410
<td ><code >False</code ></td >
413
411
</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 >
414
418
</tbody >
415
419
</table >
416
420
</details >
@@ -821,9 +825,9 @@ for res in visual_predict_res:
821
825
- ` use_formula_recognition ` : ` (bool) ` 控制是否启用公式识别子产线
822
826
823
827
- ` 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) ` 内容为版面区域内的内容 。
827
831
828
832
- ` overall_ocr_res ` : ` (Dict[str, Union[List[str], List[float], numpy.ndarray]]) ` 全局 OCR 结果的字典
829
833
- ` input_path ` : ` (Union[str, None]) ` 图像OCR子产线接受的图像路径,当输入为` numpy.ndarray ` 时,保存为` None `
@@ -845,12 +849,6 @@ for res in visual_predict_res:
845
849
- ` rec_scores ` : ` (List[float]) ` 文本识别的置信度列表,已按` text_rec_score_thresh ` 过滤
846
850
- ` rec_polys ` : ` (List[numpy.ndarray]) ` 经过置信度过滤的文本检测框列表,格式同` dt_polys `
847
851
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
-
854
852
- ` formula_res_list ` : ` (List[Dict[str, Union[numpy.ndarray, List[float], str]]]) ` 公式识别结果列表,每个元素为一个字典
855
853
- ` rec_formula ` : ` (str) ` 公式识别结果
856
854
- ` rec_polys ` : ` (numpy.ndarray) ` 公式检测框,shape为(4, 2),dtype为int16
@@ -938,6 +936,14 @@ for res in visual_predict_res:
938
936
<td ><code >3500</code ></td >
939
937
</tr >
940
938
<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 >
941
947
<tr >
942
948
<td ><code >flag_save_bytes_vector</code ></td >
943
949
<td >文字是否保存为二进制文件</td >
@@ -947,7 +953,16 @@ for res in visual_predict_res:
947
953
</td >
948
954
<td ><code >False</code ></td >
949
955
</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 >
951
966
该方法会返回一个包含视觉文本信息的字典,字典的内容如下:
952
967
953
968
- ` flag_save_bytes_vector ` :` (bool) ` 是否将结果保存为二进制文件
@@ -1075,6 +1090,24 @@ for res in visual_predict_res:
1075
1090
<td ><code >None</code ></td >
1076
1091
<td ><code >None</code ></td >
1077
1092
</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 >
1078
1111
</tbody >
1079
1112
</table >
1080
1113
0 commit comments