Question and answer model training method and device based on table image recognition and medium
By preprocessing and content recognition of table image data, constructing json file data with associated relationships, and training a question and answer model, the problem of low table image recognition and application efficiency in the existing technology is solved, and efficient recognition and application effects are achieved.
Patent Information
- Application Number
- CN202410492730.1
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-04-23
- Publication Date
- 2024-08-23
AI Technical Summary
Existing technologies are difficult to efficiently identify and apply unstructured tabular image data, resulting in high manpower investment, low data recognition processing efficiency and accuracy, and unable to meet the actual needs of users.
By obtaining table image data, preprocessing, content recognition and information reconstruction are performed to construct json file data with table associations, and the pre-trained model is used to train the question and answer model to realize the identification and application of table data in different table images.
It achieves efficient recognition and application of table images, reduces manpower investment, improves recognition processing efficiency and accuracy, and meets the actual needs of users.
Smart Images

Figure CN118537875A
Abstract
Description
Technical Field
[0001] The present invention relates to the technical field of data recognition and model training, and in particular to a question-answering model training method, device and medium based on table image recognition. Background Art
[0002] In the development of the information age, there are a lot of unstructured data, especially image data. Among them, most of the image data is in table format. If you want to convert these unstructured image data into structured data, the traditional method can only use general OCR technology to manually mark the picture frame to obtain the table content. Each format needs to be marked and trained once, resulting in large manpower investment and low data recognition and processing efficiency; and it is impossible to reflect the internal relationship of the table and directly associate the application, so that users can only manually query according to the recognized table content to obtain the required data. However, due to human factors, the data acquisition efficiency and accuracy are low, which cannot meet the actual needs of users. Summary of the invention
[0003] The technical problem to be solved by the present invention is to provide a question-answering model training method, device and medium based on table image recognition, which can realize the recognition and application of table data in different table images.
[0004] In order to solve the above technical problems, the present invention provides a question-answering model training method based on table image recognition, including: acquiring image data containing a table; preprocessing the image data to obtain table image data for establishing a coordinate system; performing content recognition and information reconstruction on the table image data to construct json file data with a table association relationship, wherein the json file data includes coordinate information of a rectangular box in the table and text recognition information in the rectangular box; constructing a training data set based on the json file data and the corresponding table image data, and constructing a prompt based on the json file data; a preset pre-trained model is trained by the prompt and the training data set to obtain a question-answering model.
[0005] As an improvement of the above scheme, the step of preprocessing the image data includes: removing the watermark in the image data; performing table recognition on the image data through a row recognition model and cutting it out from the image data to obtain table image data; establishing a coordinate system for the table image data.
[0006] As an improvement of the above scheme, the steps of performing content recognition and information reconstruction on the table image data to construct json file data with a table association relationship include: performing table recognition processing on the table graphic data to obtain a first json string and a second json string, wherein the first json string and the second json string both include table location information and identification text information; performing information combination and reconstruction processing on the first json string and the second json string to construct json file data; performing table association relationship construction on the json file data to obtain json file data with a table association relationship.
[0007] As an improvement of the above-mentioned scheme, the steps of performing table recognition processing on the table graphic data to obtain a first json string and a second json string include: using a row recognition model and a text recognition model to perform content recognition on the table image data to obtain a first json string; using a table structure recognition model to perform table single decomposition on the table image data to obtain a table unit image; using a hybrid recognition model to perform content recognition on the table unit image to obtain a second json string; wherein the hybrid recognition model includes a row recognition model + text recognition model, a row recognition-DB model + text recognition model and a text recognition model.
[0008] As an improvement of the above scheme, the steps of combining and reconstructing information of the first JSON string and the second JSON string to construct JSON file data include: regularizing the non-rectangular recognition boxes in the first JSON string and the second JSON string respectively to obtain rectangular recognition boxes; merging and optimizing each two adjacent rectangular recognition boxes in the first JSON string and the second JSON string respectively; merging and optimizing the first JSON string and the second JSON string to obtain JSON file data.
[0009] As an improvement of the above scheme, the steps of merging and optimizing each two adjacent rectangular identification frames in the first JSON string and the second JSON string include: determining whether there is contact between the two adjacent rectangular identification frames, whether the center distance of the rectangular identification frames is within a preset distance threshold, and whether the angle between the center point line of the two adjacent rectangular identification frames and the y-axis is within a preset angle threshold; if the judgment is yes, de-duplicating and merging the identification contents in the two rectangular identification frames, and drawing a new rectangular identification frame based on the coordinate information of the two rectangular identification frames to be merged.
[0010] As an improvement of the above scheme, the step of constructing a table association relationship for the json file data includes: aligning the vertical and horizontal coordinates of the json file data in the coordinate system, determining the associated data in the same row or column, and aligning with the table header to construct a table association relationship network.
[0011] As an improvement of the above-mentioned scheme, the preset pre-trained model is trained through the prompt and the training data set to obtain the question-answering model, and the step includes: inputting the training data set into the pre-trained model for fine-tuning training to obtain an optimized training model; inputting the prompt into the training model, and the training model is trained and processed through the prompt to obtain the question-answering model.
[0012] The present invention also provides a computer device, comprising a memory, a processor, and a computer program stored in the memory and executable on the processor, wherein the processor implements the steps of the above method when executing the computer program.
[0013] The present invention also provides a storage medium storing a computer program, wherein the computer program implements the steps of the above method when executed by a processor.
[0014] The implementation of the present invention has the following beneficial effects:
[0015] The present invention can identify the corresponding table structure and association relationship from a small number of table images, construct prompt and data training set according to json file data with table association relationship, so as to train a question-answering model, thereby realizing the recognition and application of table data in different table images, with the characteristics of low manpower investment, high recognition and processing efficiency and accuracy, and good application effect, which meets the actual needs of users. BRIEF DESCRIPTION OF THE DRAWINGS
[0016] Figure 1 It is a flow chart of the question-answering model training method based on table image recognition of the present invention;
[0017] Figure 2 It is a flowchart of the present invention for performing content recognition and information reconstruction on the table image data to construct json file data with table association relationship. DETAILED DESCRIPTION
[0018] In order to make the purpose, technical solution and advantages of the present invention clearer, the present invention will be further described in detail below with reference to the accompanying drawings. It is hereby stated that the directional terms such as up, down, left, right, front, back, inside, outside, etc. that appear or will appear in the text of the present invention are only based on the accompanying drawings of the present invention, and are not specific limitations of the present invention.
[0019] like Figure 1 As shown, the present invention provides a question-answering model training method based on table image recognition according to a specific embodiment, comprising:
[0020] S101, acquiring image data containing a table;
[0021] It should be noted that the target PDF file is converted into multiple high-quality image data through the pdf2 image module. The image data containing the table is determined by the row recognition model, and the image data without the table is eliminated.
[0022] S102, preprocessing the image data to obtain table image data for establishing a coordinate system;
[0023] Specifically, the step of preprocessing the image data includes:
[0024] Step 1, removing the watermark in the image data;
[0025] It should be noted that for image data with watermarks, the RGB value of each point in the image data can be adjusted by calling the grayscale adjustment function of the opencv library and compared with the preset threshold to screen out image data with the lowest watermark and clear image, which is convenient for subsequent recognition processing.
[0026] Step 2: Perform table recognition on the image data through a row recognition model and cut out the table from the image data to obtain table image data;
[0027] It should be noted that the table image data is identified from the image data through the row recognition model and cut out from the original image data to obtain independent table image data.
[0028] Step 3: Establish a coordinate system for the table image data.
[0029] It should be noted that a coordinate system is established for each cut table image data, wherein a rectangular coordinate system is constructed with the upper left vertex as the origin, from left to right is the positive direction of the x-axis, and from top to bottom is the positive direction of the y-axis.
[0030] S103, performing content recognition and information reconstruction on the table image data to construct JSON file data with table association, wherein the JSON file data includes coordinate information of a rectangular frame in the table and text recognition information in the rectangular frame;
[0031] Specifically, Figure 2 As shown, the steps of performing content recognition and information reconstruction on the table image data to construct JSON file data with table association relationship include:
[0032] S201, performing table recognition processing on the table graphic data to obtain a first JSON string and a second JSON string, wherein the first JSON string and the second JSON string both include table location information and recognition text information;
[0033] Specifically, the step of performing table recognition processing on the table graphic data to obtain a first JSON string and a second JSON string includes:
[0034] Step 1: Use a row recognition model and a text recognition model to perform content recognition on the table image data to obtain a first JSON string;
[0035] It should be noted that the content in the table image data is identified in layers through the row recognition model and the text recognition model, and the identified content is composed into a first JSON string.
[0036] Step 2: using a table structure recognition model to perform table unit decomposition on the table image data to obtain a table unit image;
[0037] Step 3: Use a hybrid recognition model to perform content recognition on the table unit image to obtain a second json string; wherein the hybrid recognition model includes a row recognition model + a text recognition model, a row recognition-DB model + a text recognition model, and a text recognition model.
[0038] It should be noted that the table image data is decomposed into a single table through the table structure recognition model to obtain the table unit image, which is convenient for in-depth recognition of the table data content. The table unit image is recognized by using a combination of multiple recognition models such as row recognition model + text recognition model, row recognition-DB model + text recognition model and text recognition model, and the recognized content is combined into a second json string. Since the table image data establishes a coordinate system, the first json string and the second json string both include the corresponding table location information and recognition text information.
[0039] S202, combining and reconstructing the first JSON string and the second JSON string to construct JSON file data;
[0040] Specifically, the step of combining and reconstructing the first JSON string and the second JSON string to construct JSON file data includes:
[0041] Step 1: Regularize the non-rectangular recognition frames in the first JSON string and the second JSON string respectively to obtain rectangular recognition frames;
[0042] It should be noted that the non-rectangular recognition frames identified in the first JSON character string and the second JSON character string are respectively regularized into rectangular recognition frames, so as to optimize the recognition table frame.
[0043] Step 2: Merge and optimize each two adjacent rectangular recognition frames in the first JSON string and the second JSON string;
[0044] It should be noted that the steps of merging and optimizing each two adjacent rectangular recognition frames in the first JSON string and the second JSON string include: judging whether there is contact between the two adjacent rectangular recognition frames, whether the center distance of the rectangular recognition frames is within a preset distance threshold, and whether the angle between the center point connection line of the two adjacent rectangular recognition frames and the y-axis is within a preset angle threshold. If the judgment structures are all yes, the recognition contents in the two rectangular recognition frames are deduplicated and merged, and a maximum rectangular recognition frame is drawn according to the coordinate information of the two rectangular recognition frames to be merged, so as to optimize and merge the overlapping rectangular frames in the first JSON string and the second JSON string and update the rectangular recognition frame with the optimal range, so as to facilitate the subsequent optimization of the contents in the rectangular recognition frames.
[0045] Step 3: Merge and optimize the first JSON string and the second JSON string to obtain JSON file data.
[0046] It should be noted that the step of merging and optimizing the first json string and the second json string to obtain json file data includes: filling the first json string as supplementary content in the second json string to obtain json file data.
[0047] Specifically, the present invention uses the second json string as a base and the first json string as supplementary content to supplement the second json string. Among them, the recognition content between the first json string and the second json string is compared. If any recognition result only exists in the first json string, the recognition content that the second json string does not have is filled in the corresponding position of the second json string through the first json string. If any recognition content exists in the first json string and the second json string, the recognition completeness of the recognition content is compared. When the recognition completeness of the first json string is higher than that of the second json string, the recognition content of the first json string is filled in the corresponding position of the second json string. The above method is used to improve the recognition processing efficiency and accuracy, thereby obtaining json file data with the best recognition effect.
[0048] S203: construct a table association relationship for the JSON file data to obtain JSON file data with a table association relationship.
[0049] It should be noted that the step of constructing a table association relationship for the json file data includes: aligning the vertical and horizontal coordinates of the json file data in the coordinate system, determining the associated data in the same row or column, and aligning with the table header to construct a table association relationship network, thereby obtaining json file data with a table association relationship.
[0050] S104, constructing a training data set according to the json file data and the corresponding table image data, and constructing a prompt according to the json file data;
[0051] It should be noted that the step of constructing a prompt based on the json file data includes: constructing a prompt based on the coordinate information and association relationship information in the json file data, so as to facilitate the subsequent learning of the association relationship of the corresponding table structure for the model, so that the model can quickly apply and process the table data.
[0052] S105. The preset pre-trained model is trained using the prompt and the training data set to obtain a question-answering model.
[0053] Specifically, the preset pre-trained model is trained by the prompt and the training data set to obtain the question-answering model, which includes:
[0054] Step 1: input the training data set into the pre-training model for fine-tuning training to obtain an optimized training model;
[0055] It should be noted that the training data set is input into the pre-training model for fine-tuning training to optimize the model parameters and obtain the optimal training model; the training model's capabilities in semantic entity recognition and relationship extraction can achieve the best results in vertical fields. Among them, the preset pre-training model is preferably llama, but it is not limited to this.
[0056] Step 2: input the prompt into a training model, and the training model is trained using the prompt to obtain a question-answering model.
[0057] It should be noted that by combining prompt with llama model for training, the llama model can effectively improve its understanding of table relational data and learn related content, thereby realizing comprehensive processing of table data. That is, by putting the relationship between table header information, row and column information and each identification box into the prompt word, the model can learn the relationship between table header and row and column, so that it can recognize the value of a certain column and row. For example, if the question of what is the normal balance of short-term loans is input into the question-and-answer model, the model can infer the row and column relationship of the relevant table and answer the value of the corresponding text box, realizing the automatic reply function of question and answer, improving the application efficiency and effect of table data, and meeting the actual needs of users.
[0058] During the test, the recognition processing technology of steps S101-103 of the present invention can be used to perform recognition processing on the table image to be tested to obtain the corresponding json file data, which can then be input into the trained question-answering model to implement question-answering processing and meet the user's data application processing needs.
[0059] Correspondingly, the present invention also provides a computer device, comprising a memory, a processor, and a computer program stored in the memory and executable on the processor, wherein the processor implements the steps of the above-mentioned question-answering model training method based on table image recognition when executing the computer program.
[0060] At the same time, the present invention also provides a storage medium storing a computer program, wherein the computer program, when executed by a processor, implements the steps of the above-mentioned question-answering model training method based on table image recognition.
[0061] To sum up, the present invention can identify the corresponding table structure and association relationship from a small number of table images, construct prompt and data training set according to the json file data with table association relationship, so as to train the question-answering model, thereby realizing the recognition and application of table data in different table images, which has the characteristics of low manpower investment, high recognition and processing efficiency and accuracy, and good application effect, and meets the actual needs of users.
[0062] The above disclosure is only the preferred embodiment of the present invention, which certainly cannot be used to limit the scope of the present invention. Therefore, equivalent changes made according to the claims of the present invention are still within the scope of the present invention.
Claims
1. A question-answering model training method based on table image recognition, characterized in that: include: Get the image data containing the table; Preprocessing the image data to obtain tabular image data for establishing a coordinate system; Performing content recognition and information reconstruction on the table image data to construct JSON file data with table association, wherein the JSON file data includes coordinate information of a rectangular frame in the table and text recognition information in the rectangular frame; Construct a training data set according to the json file data and the corresponding table image data, and construct a prompt according to the json file data; The preset pre-trained model is trained using the prompt and the training data set to obtain a question-answering model.
2. The question-answering model training method based on table image recognition according to claim 1, characterized in that: The step of preprocessing the image data comprises: removing a watermark from the image data; Performing table recognition on the image data by a row recognition model and cutting out the table from the image data to obtain table image data; A coordinate system is established for the table image data.
3. The question-answering model training method based on table image recognition according to claim 1, characterized in that: The steps of performing content recognition and information reconstruction on the table image data to construct JSON file data with table association relationship include: Performing table recognition processing on the table graphic data to obtain a first JSON string and a second JSON string, wherein the first JSON string and the second JSON string both include table position information and recognition text information; Performing information combination and reconstruction processing on the first JSON string and the second JSON string to construct JSON file data; A table association relationship is constructed for the JSON file data to obtain JSON file data with a table association relationship.
4. The question-answering model training method based on table image recognition according to claim 3 is characterized in that: The step of performing table recognition processing on the table graphic data to obtain a first JSON string and a second JSON string includes: Using a row recognition model and a text recognition model to perform content recognition on the table image data to obtain a first JSON string; Using a table structure recognition model to perform table unit decomposition on the table image data to obtain a table unit image; Using a hybrid recognition model to perform content recognition on the table unit image to obtain a second JSON string; The hybrid recognition model includes a row recognition model + a text recognition model, a row recognition-DB model + a text recognition model and a text recognition model.
5. The question-answering model training method based on table image recognition according to claim 3 is characterized in that: The step of combining and reconstructing the first JSON string and the second JSON string to construct JSON file data includes: Regularize the non-rectangular recognition frames in the first JSON string and the second JSON string respectively to obtain rectangular recognition frames; Performing a merge optimization process on each two adjacent rectangular recognition frames in the first JSON string and the second JSON string respectively; The first JSON string and the second JSON string are merged and optimized to obtain JSON file data.
6. The question-answering model training method based on table image recognition according to claim 5, characterized in that: The steps of merging and optimizing each two adjacent rectangular recognition frames in the first JSON string and the second JSON string include: Determine whether there is contact between two adjacent rectangular identification frames, whether the center distance of the rectangular identification frames is within a preset distance threshold, and whether the angle between the line connecting the center points of the two adjacent rectangular identification frames and the y-axis is within a preset angle threshold. If the judgment is yes, de-duplicate the identification contents in the two rectangular identification frames, and draw a new rectangular identification frame based on the coordinate information of the two rectangular identification frames to be merged.
7. The question-answering model training method based on table image recognition according to claim 3, characterized in that: The steps of constructing a table association relationship for the json file data include: Align the JSON file data vertically and horizontally in the coordinate system, determine the associated data in the same row or column, and align it with the table header to build a table association network.
8. The question-answering model training method based on table image recognition according to claim 1, characterized in that: The preset pre-trained model is trained by the prompt and the training data set to obtain a question-answering model, comprising: Inputting the training data set into the pre-training model for fine-tuning training to obtain an optimized training model; The prompt is input into a training model, and the training model is trained using the prompt to obtain a question-answering model.
9. A computer device comprising a memory, a processor and a computer program stored in the memory and executable on the processor, characterized in that: When the processor executes the computer program, the steps of the method according to any one of claims 1 to 8 are implemented.
10. A storage medium storing a computer program, characterized in that: When the computer program is executed by a processor, the steps of the method according to any one of claims 1 to 8 are implemented.
Citation Information
Patent Citations
Information extraction method and device, equipment and storage medium
CN114444465A
Table question and answer model training method and device, equipment and storage medium
CN116821696A
Text recognition method and device and text recognition model training method and device
CN117351507A
E-commerce table image recognition method and device based on deep learning
CN117710999A
Table question and answer method based on large language model and natural language processing
CN117743526A
