Text processing method and device, storage medium and electronic equipment
By obtaining feature vectors of image text information and performing error correction recognition, the problem of low accuracy of image text recognition in the case of complex typesetting or diverse character sets is solved, and higher recognition accuracy is achieved.
Patent Information
- Application Number
- CN202411804175.8
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-12-09
- Publication Date
- 2025-03-04
AI Technical Summary
When the text information in the image is complex in layout or the language character set is diverse, the image text recognition accuracy is low, and recognition errors are prone to occur.
By obtaining the feature vector of text information in the image and inputting it into the error correction model of the corresponding text type, error correction recognition is performed. If the error correction recognition result is inconsistent with the original text information, the original text information is replaced to improve the recognition accuracy.
This improves the accuracy of image text recognition, reduces recognition errors, and can obtain text information in the image more accurately.
Smart Images

Figure CN119559651A_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to the field of data processing technology, and in particular to a text processing method, device, storage medium and electronic device. Background Art
[0002] In the era of rapid digitalization and informatization, image text recognition technology, as a model of deep integration of computer vision and artificial intelligence, has been widely used in various fields. The core of this technology is to accurately capture and parse text information from complex images, thereby promoting the rapid circulation and efficient use of information.
[0003] However, when the text information layout or language character set in the image is complex and diverse, the image text recognition accuracy is often low and recognition errors are prone to occur. Summary of the invention
[0004] The technical problem to be solved by the present invention is to provide a text processing method, device, storage medium and electronic device, which can accurately obtain text information in an image. The specific solution is as follows:
[0005] A text processing method, comprising:
[0006] Get the image to be processed;
[0007] Performing text recognition on the image to obtain a text recognition result of the image;
[0008] Determining the text type of each text information in the text recognition result;
[0009] For each of the text information, if it is detected that there is no text error correction rule matching the text information, a feature vector of the text information is obtained, and the feature vector of the text information is input into an error correction model corresponding to the text type to which the text information belongs, to obtain an error correction recognition result of the text information; if the text information is inconsistent with the error correction recognition result, the error correction recognition result is used to replace the text information.
[0010] The above method, optionally, the process of detecting that there is no text error correction rule matching the text information includes:
[0011] Matching the text information with a preset error correction rule table, wherein the error correction rule table includes a plurality of preset text error correction rules corresponding to each of the recognized error texts;
[0012] If there is no recognition error text consistent with the text information in the error correction rule table, it is determined that there is no text error correction rule matching the text information.
[0013] The above method, optionally, the process of setting the error correction rule table includes:
[0014] Obtain reference text data;
[0015] Determining the number of occurrences and the number of recognition errors of each candidate text in the reference text data;
[0016] Determine the target text from each of the candidate texts according to the number of occurrences and the number of recognition errors of each of the candidate texts;
[0017] According to each target text and the recognition error text of each target text, generating an error correction rule corresponding to each recognition error text;
[0018] Generate an error correction rule table according to the error correction rules corresponding to each of the identified error texts.
[0019] In the above method, optionally, the step of obtaining the feature vector of the text information includes:
[0020] Acquire context information of the text information and a target image area, wherein the context information includes the text information and adjacent text information of the text information; the target image area is an image area in the image corresponding to the text information;
[0021] The text information, the context information and the target image region are vectorized, and the vectorized text information, the context information and the target image region are fused to obtain a feature vector.
[0022] In the above method, optionally, the error correction model is obtained by pre-training an initial neural network model based on a training data set of the text type;
[0023] The process of training an initial neural network model based on the training data set of the text type to obtain the error correction model includes:
[0024] Acquire a training data set of the text type and an initial neural network model to be trained; the training data set of the text type includes training samples of the text type and sample labels of the training samples, the training samples include error text information, context information of the error text information and an image area of the error text information, and the sample labels include reference text corresponding to the error text information;
[0025] Selecting a target training sample currently used for training from each training sample in the training data set;
[0026] Vectorizing the target training sample to obtain an input vector of the initial neural network model;
[0027] Inputting the input vector into the initial neural network model to obtain a recognition result output by the initial neural network model;
[0028] The loss function value of the initial neural network model is calculated by using a preset loss function, the recognition result and the sample label of the target training sample;
[0029] Using the loss function value to update the model parameters of the initial neural network model;
[0030] If the initial neural network model after updating the model parameters does not meet the preset training completion condition, returning to the step of selecting a target training sample currently used for training from each training sample in the training data set;
[0031] When the initial neural network model after the model parameters are updated satisfies a preset training completion condition, the initial neural network model after the model parameters are updated is determined as the error correction model for the text type.
[0032] A text processing device, comprising:
[0033] An acquisition unit, used for acquiring an image to be processed;
[0034] A recognition unit, used to perform text recognition on the image to obtain a text recognition result of the image;
[0035] A determination unit, used to determine the text type of each text information in the text recognition result;
[0036] The error correction unit is used for obtaining a feature vector of the text information for each of the text information if it is detected that there is no text error correction rule matching the text information, inputting the feature vector of the text information into an error correction model corresponding to the text type to which the text information belongs, and obtaining an error correction recognition result of the text information; if the text information is inconsistent with the error correction recognition result, replacing the text information with the error correction recognition result.
[0037] In the above device, optionally, the error correction unit includes:
[0038] A matching subunit, used to match the text information with a preset error correction rule table, wherein the error correction rule table includes a plurality of preset text error correction rules corresponding to each of the recognition error texts;
[0039] The determination subunit is used to determine that there is no text error correction rule matching the text information if there is no recognition error text consistent with the text information in the error correction rule table.
[0040] In the above device, optionally, the error correction model is obtained by the error correction unit training an initial neural network model based on a training data set of the text type in advance;
[0041] The error correction unit comprises:
[0042] an acquisition subunit, configured to acquire a training data set of the text type and an initial neural network model to be trained; the training data set of the text type includes training samples of the text type and sample labels of the training samples, the training samples include error text information, context information of the error text information, and an image region of the error text information, and the sample labels include reference text corresponding to the error text information;
[0043] A selection subunit, used to select a target training sample currently used for training from each training sample in the training data set;
[0044] A first execution subunit, used for vectorizing the target training sample to obtain an input vector of the initial neural network model;
[0045] A second execution subunit is used to input the input vector into the initial neural network model to obtain a recognition result output by the initial neural network model;
[0046] A calculation subunit, used to calculate the loss function value of the initial neural network model through a preset loss function, the recognition result and the sample label of the target training sample;
[0047] An updating subunit, used to update the model parameters of the initial neural network model using the loss function value;
[0048] A third execution subunit is used to return to trigger the selection subunit to execute the process of selecting a target training sample currently used for training from each training sample in the training data set when the initial neural network model after updating the model parameters does not meet the preset training completion condition;
[0049] The fourth execution subunit is used to determine the initial neural network model after updating the model parameters as the error correction model of the text type when the initial neural network model after updating the model parameters meets the preset training completion condition.
[0050] A storage medium includes stored instructions, wherein when the instructions are executed, the device where the storage medium is located is controlled to execute the above-mentioned text processing method.
[0051] An electronic device includes a memory and one or more instructions, wherein the one or more instructions are stored in the memory and are configured to be executed by one or more processors as the above-mentioned text processing method.
[0052] Based on the above-mentioned implementation of the present invention, a text processing method, device, storage medium and electronic device are provided, the method comprising: obtaining an image to be processed; performing text recognition on the image to obtain a text recognition result of the image; determining the text type of each text information in the text recognition result; for each text information, if it is detected that there is no text error correction rule matching the text information, then obtaining a feature vector of the text information, inputting the feature vector of the text information into an error correction model corresponding to the text type to which the text information belongs, and obtaining an error correction recognition result of the text information; if the text information is inconsistent with the error correction recognition result, then using the error correction recognition result to replace the text information. Applying the method provided by the embodiment of the present invention can accurately obtain text information in an image. BRIEF DESCRIPTION OF THE DRAWINGS
[0053] In order to more clearly illustrate the embodiments of the present invention or the technical solutions in the prior art, the drawings required for use in the embodiments or the description of the prior art will be briefly introduced below. Obviously, the drawings described below are only embodiments of the present invention. For ordinary technicians in this field, other drawings can be obtained based on the provided drawings without paying creative work.
[0054] Figure 1 A method flow chart of a text processing method provided by the present invention;
[0055] Figure 2 A flowchart of a process of setting an error correction rule table provided by the present invention;
[0056] Figure 3 A flowchart of a process for obtaining an error correction model provided by the present invention;
[0057] Figure 4 A text processing flow chart provided by the present invention;
[0058] Figure 5 An example diagram of an admission record image provided by the present invention;
[0059] Figure 6 This is an example image of a test report provided by the present invention;
[0060] Figure 7 Another example of an inspection report image provided by the present invention;
[0061] Figure 8 A structural schematic diagram of a text processing device provided by the present invention;
[0062] Fig. 9 The present invention provides a schematic structural diagram of an electronic device. DETAILED DESCRIPTION
[0063] The following will be combined with the drawings in the embodiments of the present invention to clearly and completely describe the technical solutions in the embodiments of the present invention. Obviously, the described embodiments are only part of the embodiments of the present invention, not all of the embodiments. Based on the embodiments of the present invention, all other embodiments obtained by ordinary technicians in this field without creative work are within the scope of protection of the present invention.
[0064] In this application, the terms "comprises", "comprising" or any other variations thereof are intended to cover non-exclusive inclusion, so that a process, method, article or device comprising a series of elements includes not only those elements, but also other elements not explicitly listed, or also includes elements inherent to such process, method, article or device. In the absence of further restrictions, an element defined by the sentence "comprising a ..." does not exclude the presence of other identical elements in the process, method, article or device comprising the element.
[0065] The embodiment of the present invention provides a text processing method, which can be applied to electronic devices, such as computers, smart phones, tablet devices, smart wearable devices, server clusters or cloud computing centers, etc. The method flow chart of the method is as follows: Figure 1 As shown, specifically including:
[0066] S101: Acquire an image to be processed.
[0067] In this embodiment, the image to be processed may be any image including text information, for example, various test report images, admission record images, case images, etc. in the medical field.
[0068] S102: Perform text recognition on the image to obtain a text recognition result of the image.
[0069] In this embodiment, OCR recognition technology can be used to perform text recognition on the image to be processed to obtain a text recognition result of the image.
[0070] S103: Determine the text type of each piece of text information in the text recognition result.
[0071] In this embodiment, the text recognition result may include text information of at least one text type, and the text type may include text types in different languages (such as Chinese, English, etc.), number and symbol text types, etc.
[0072] S104: For each text information, if it is detected that there is no text error correction rule matching the text information, a feature vector of the text information is obtained, and the feature vector of the text information is input into an error correction model corresponding to the text type to which the text information belongs, to obtain an error correction recognition result of the text information; if the text information is inconsistent with the error correction recognition result, the text information is replaced with the error correction recognition result.
[0073] In this embodiment, it is possible to first detect whether there is a text correction rule that matches the text information. If there is a text correction rule that matches the text information, the text information can be corrected using the error correction rule that matches the text information. If there is no error correction rule that matches the text information, a feature vector of the text information can be obtained, and the feature vector of the text information can be input into a pre-trained error correction model corresponding to its text type to obtain an error correction recognition result. If the error correction recognition result is inconsistent with the text information, it means that the text information recognition is incorrect, and the error correction recognition result can be used to replace the text information. If the error correction recognition result is consistent with the text information, it means that the text information recognition is correct.
[0074] Optionally, the error correction model may be various types of neural network models, for example, a deep learning language model.
[0075] By applying the method provided by the embodiment of the present invention, text information in an image can be accurately obtained.
[0076] In some embodiments provided in the present application, based on the above solution, optionally, the process of detecting that there is no text error correction rule matching the text information includes:
[0077] Matching the text information with a preset error correction rule table, wherein the error correction rule table includes a plurality of preset text error correction rules corresponding to each of the recognized error texts;
[0078] If there is no recognition error text consistent with the text information in the error correction rule table, it is determined that there is no text error correction rule matching the text information.
[0079] In this embodiment, the text error correction rule can be used to replace the misrecognized text with the correct text.
[0080] Optionally, the error correction rule table can record the correspondence between the target text and the text error correction rules, and can determine whether there is a target text consistent with the text information in the error correction rule table. If there is a target text consistent with the text information, the text error correction rules corresponding to the target text consistent with the text information are determined as the error correction rules that match the text information; if there is no target text consistent with the text information, it can be determined that there is no text error correction rule that matches the text information.
[0081] In some embodiments provided in the present application, based on the above solution, optionally, a process of setting an error correction rule table is as follows: Figure 2 As shown, including:
[0082] S201: Acquire reference text data.
[0083] S202: Determine the number of occurrences and the number of recognition errors of each candidate text in the reference text data.
[0084] Optionally, the reference text data may be split to obtain various candidate texts, and the number of occurrences of each candidate text may be counted.
[0085] In this embodiment, the reference text data can be converted into a reference text image, and then text recognition is performed on the reference text image to obtain a recognition result of the reference text image. The recognition result is compared with the reference text data to determine the number of recognition errors of each candidate text in the reference text data.
[0086] S203: Determine a target text from each of the candidate texts according to the number of occurrences and the number of recognition errors of each of the candidate texts.
[0087] In this embodiment, the number of occurrences and the number of recognition errors of each candidate text can be sorted from large to small. For each candidate text, if the number of occurrences of the candidate text is ranked in the top N and the number of recognition errors of the candidate text is ranked in the top M, then the candidate text is determined to be the target text. N and M are positive integers. The specific values of M and N can be set by technical personnel according to actual needs. For example, N can be 100 and M can be 80.
[0088] In some embodiments, if the number of occurrences of a candidate text is greater than a preset number of occurrences threshold, and the number of recognition errors of the candidate text is greater than a preset number of errors threshold, the candidate text may be determined as the target text.
[0089] S204: Generate an error correction rule corresponding to each recognition error text according to each target text and the recognition error text of each target text.
[0090] S205: Generate an error correction rule table according to the error correction rules corresponding to each recognition error text.
[0091] By applying the method provided in the embodiment of the present application, the target text is determined among the candidate texts through the number of occurrences and the number of recognition errors of the candidate texts, thereby generating error correction rules corresponding to the recognition error texts of the target text. This enables texts with many occurrences and high recognition errors to be corrected preferentially through error correction rules, thereby improving text processing efficiency.
[0092] In some embodiments provided in the present application, based on the above solution, optionally, obtaining a feature vector of text information includes:
[0093] Acquire context information of the text information and a target image region, wherein the context information includes the text information and adjacent text information of the text information; the target image region is an image region in the image corresponding to the text information;
[0094] The text information, context information and target image area are vectorized, and the vectorized text information, context information and target image area are fused to obtain a feature vector.
[0095] In this embodiment, the vectorized text information, context information and target image area may be spliced in a preset splicing order to obtain a feature vector.
[0096] In some embodiments provided in the present application, based on the above solution, optionally, the error correction model is obtained by pre-training an initial neural network model based on a training data set of a text type;
[0097] Based on the text type training data set, the initial neural network model is trained to obtain the error correction model process, such as Figure 3 As shown, including:
[0098] S301: Obtain a text type training data set and an initial neural network model to be trained; the text type training data set includes text type training samples and sample labels of the training samples, the training samples include error text information, context information of the error text information and image area of the error text information, and the sample labels include reference text corresponding to the error text information.
[0099] S302: Select a target training sample currently used for training from each training sample in the training data set.
[0100] S303: Vectorize the target training sample to obtain an input vector of the initial neural network model.
[0101] S304: Input the input vector into the initial neural network model to obtain the recognition result output by the initial neural network model.
[0102] S305: Calculate the loss function value of the initial neural network model through the preset loss function, recognition results and sample labels of the target training samples.
[0103] S306: Update the model parameters of the initial neural network model using the loss function value.
[0104] S307: Check whether the model parameters of the initial neural network model after the model parameters are updated meet the preset training completion conditions; if not, return to execute S302, and if so, execute S307.
[0105] In this embodiment, the training completion condition may be that the number of times the model parameters of the initial neural network model are updated is greater than a preset number threshold, the loss function value of the initial neural network model converges, or the recognition accuracy of the initial neural network model is greater than a preset accuracy threshold, etc.
[0106] S308: Determine the initial neural network model after updating the model parameters as the text type error correction model.
[0107] See also Figure 4 , which is a text processing flow chart provided in this application. The text processing process is divided into two stages. The first stage can be the model training stage, and the second stage can be the text error correction stage.
[0108] In the model training stage, one or more of the text data of the admission record and the text data of the test report can be collected first, and then the collected data can be desensitized; and the desensitized data can be converted into images.
[0109] For example, see Figure 5 , the desensitized admission record text data can be converted into admission record images, see Figure 6 , the desensitized test report text data can be converted into a test report image.
[0110] After the desensitized data is converted into an image, OCR recognition can be performed on the image to obtain a text recognition result of the image, and then the text recognition result is compared with the desensitized text data, and the fields in the text recognition result that are inconsistent with the desensitized text data are determined as incorrectly recognized text.
[0111] Specifically, the text data after desensitization processing may be recorded first, as shown in Table 1, and the text data of the admission record and the text data of the test report may be recorded.
[0112] Table 1
[0113] ID Line Number Text Data ruyuanjilu-1 1 Chief complaint: intermittent chest tightness and pain for more than 6 years ruyuanjilu-1 2 Current medical history: The patient had dull pain in the chest area for 6 years without obvious cause, which lasted for 3-5 minutes and had nothing to do with changes in body position or activities. ruyuanjilu-1 3 The symptoms can be relieved spontaneously. Later, the patient intermittently experienced the above symptoms, with the same nature and relief mode as before, without other accompanying symptoms. Coronary CT scan showed no discomfort 4 years ago. ruyuanjilu-1 4 … jianyanbaogao-1 1 Inspection report jianyanbaogao-1 2 Name: Medical record number: Sample number: Chang A419 Sampling time: 2022-03-08 16:01 jianyanbaogao-1 3 …
[0114] The ID may identify the image corresponding to the text data, and the row number may indicate the position of the text data in the image.
[0115] Then the OCR recognition results of each image are recorded, as shown in Table 2. Figure 5 OCR recognition results.
[0116] Table 2
[0117] ID Line Number Text recognition results ruyuanjilu-1 1 Chief complaint: intermittent chest tightness and pain for more than 6 years ruyuanjilu-1 2 Current medical history: The patient had dull pain in the chest area for 6 years without obvious cause, which lasted for 3-5 minutes and had nothing to do with changes in body position or activities. ruyuanjilu-1 3 The symptoms can be relieved spontaneously. Later, the patient intermittently experienced the above symptoms, with the same nature and relief mode as before, without other accompanying symptoms.
[0118] By comparing the record table of text recognition results with the record table of desensitized admission record text data, the error data set can be obtained, as shown in Table 3:
[0119] Table 3
[0120] ID Line Number Identification results Text Results ruyuanjilu-1 3 The symptoms can be relieved spontaneously. Later, the patient intermittently experienced the above symptoms, with the same nature and relief mode as before, without other accompanying symptoms. The symptoms can be relieved spontaneously. Later, the patient intermittently experienced the above symptoms, with the same nature and relief mode as before, without other accompanying symptoms. Coronary CT scan showed no discomfort 4 years ago. … … … …
[0121] After obtaining the error data set, the text in the error data set can be classified. For example, it can be divided into three text types: "Chinese", "English", and "numbers and symbols", as shown in Table 4:
[0122] Table 4
[0123] ID Line Number Identification results Text Results ruyuanjilu-1 3-chinese-1 The symptoms can be relieved spontaneously, and the patient will intermittently experience the above symptoms, with the same nature and relief methods as before, without other accompanying symptoms The symptoms can be relieved spontaneously, and the patient will intermittently experience the above symptoms, with the same nature and relief methods as before, without other accompanying symptoms ruyuanjilu-1 3-number 4 4 ruyuanjilu-1 3-chinese-2 No discomfort in coronary artery No discomfort in coronary artery ruyuanjilu-1 3-english T CT ruyuanjilu-1 3-chinese-3 Show Show
[0124] That is, through the above processing method, it can be determined that the only English word "CT" in Table 4 is incorrectly recognized. This error can be recorded, and then the largest short sentence containing the incorrect character can be extracted as the context information of the incorrect text, and the image area of the incorrect text can be determined. The method of extracting the largest short sentence containing the incorrect character can be to split the long sentence into multiple sentences according to punctuation marks, and select the sentence containing the incorrect character as the context information of the incorrect character.
[0125] In this embodiment, the erroneous text of a text type, the contextual information of the erroneous text, and the image area of the erroneous text can be used as training samples, and the field corresponding to the erroneous text in the desensitized text data can be used as the sample label; a training data set is composed of multiple training samples of the same text type and the sample label of each training sample; then, the corresponding models of the training sample sets of each text type are used for training to obtain various corresponding error correction models for different text types.
[0126] During the training phase, error correction rules may also be set based on the number of occurrences of each field in the desensitized text data and the number of recognition errors.
[0127] In the text error correction stage, an image to be processed can be obtained. The image to be processed is as follows: Figure 7 As shown, OCR recognition can be performed on the image to be processed to obtain the text recognition result of the image to be processed, and the text type of each text information in the text recognition result can be determined; for each text information, if it is detected that there is no text error correction rule matching the text information, the feature vector of the text information is obtained, and the feature vector of the text information is input into the error correction model corresponding to the text type to which the text information belongs to obtain the error correction recognition result of the text information; when the text information is inconsistent with the error correction recognition result, the text information is replaced by the error correction recognition result.
[0128] Specifically, the recognition results of the fifth row of the image to be processed are shown in Table 5:
[0129] Table 5
[0130] ID Line Number Identification results Text Results jianchabaogao-1 5 1# (sinus lesser curvature - erosion) 1 piece of grayish white irregular tissue, the largest diameter is Q2cm 1# (sinus lesser curvature - erosion) 1 piece of grayish white irregular tissue, with a maximum diameter of 0.2cm
[0131] Determine the text types in the fifth line of recognition results, as shown in Table 6:
[0132] Table 6
[0133] ID Line Number Identification results Text Results jianchabaogao-1 5-number-1 1# 1# jianchabaogao-1 5-chinese-1 Gray irregular tissue Gray irregular tissue jianchabaogao-1 5-number-2 1 1 jianchabaogao-1 5-chinese-2 piece, piece, jianchabaogao-1 5-chinese-3 Maximum Maximum diameter jianchabaogao-1 5-number-3 Q2 0.2cm
[0134] The text information in the recognition result is then matched with the error correction rules. If there is no error correction rule matching the text information, the error correction model of the corresponding text type is used to perform recognition processing on the text information, the contextual information of the text information, and the image area to obtain the error correction recognition result of the text information.
[0135] and Figure 1 Corresponding to the method described above, the embodiment of the present invention further provides a text processing device for Figure 1 The specific implementation of the method is shown in the following diagram: Figure 8 As shown, specifically including:
[0136] An acquisition unit 801 is used to acquire an image to be processed;
[0137] The recognition unit 802 is used to perform text recognition on the image to obtain a text recognition result of the image;
[0138] A determination unit 803, used to determine the text type of each text information in the text recognition result;
[0139] The error correction unit 804 is used to obtain a feature vector of the text information for each of the text information if it is detected that there is no text error correction rule matching the text information, input the feature vector of the text information into an error correction model corresponding to the text type to which the text information belongs, and obtain an error correction recognition result of the text information; if the text information is inconsistent with the error correction recognition result, use the error correction recognition result to replace the text information.
[0140] In some embodiments provided in the embodiments of the present application, based on the above solution, optionally, the error correction unit includes:
[0141] A matching subunit, used to match the text information with a preset error correction rule table, wherein the error correction rule table includes a plurality of preset text error correction rules corresponding to each of the recognition error texts;
[0142] The determination subunit is used to determine that there is no text error correction rule matching the text information if there is no recognition error text consistent with the text information in the error correction rule table.
[0143] In some embodiments provided in the embodiments of the present application, based on the above solution, optionally, the matching subunit includes:
[0144] An acquisition module, used for acquiring reference text data;
[0145] A first determination module, used to determine the number of occurrences and the number of recognition errors of each candidate text in the reference text data;
[0146] A second determination module is used to determine the target text from each of the candidate texts according to the number of occurrences and the number of recognition errors of each of the candidate texts;
[0147] A first generating module, configured to generate, according to each target text and each recognition error text of the target text, a correction rule corresponding to each recognition error text;
[0148] The second generating module is used to generate an error correction rule table according to the error correction rules corresponding to each of the identified error texts.
[0149] In some embodiments provided in the embodiments of the present application, based on the above scheme, optionally, the error correction model is obtained by the error correction unit pre-training an initial neural network model based on a training data set of the text type;
[0150] The error correction unit comprises:
[0151] an acquisition subunit, configured to acquire a training data set of the text type and an initial neural network model to be trained; the training data set of the text type includes training samples of the text type and sample labels of the training samples, the training samples include error text information, context information of the error text information, and an image region of the error text information, and the sample labels include reference text corresponding to the error text information;
[0152] A selection subunit, used to select a target training sample currently used for training from each training sample in the training data set;
[0153] A first execution subunit, used for vectorizing the target training sample to obtain an input vector of the initial neural network model;
[0154] A second execution subunit is used to input the input vector into the initial neural network model to obtain a recognition result output by the initial neural network model;
[0155] A calculation subunit, used to calculate the loss function value of the initial neural network model through a preset loss function, the recognition result and the sample label of the target training sample;
[0156] An updating subunit, used to update the model parameters of the initial neural network model using the loss function value;
[0157] A third execution subunit is used to return to trigger the selection subunit to execute the process of selecting a target training sample currently used for training from each training sample in the training data set when the initial neural network model after updating the model parameters does not meet the preset training completion condition;
[0158] The fourth execution subunit is used to determine the initial neural network model after updating the model parameters as the error correction model of the text type when the initial neural network model after updating the model parameters meets the preset training completion condition.
[0159] In some embodiments provided in the embodiments of the present application, based on the above solution, optionally, the error correction unit includes:
[0160] A fifth execution subunit is configured to obtain context information of the text information and a target image region; the context information includes the text information and adjacent text information of the text information; the target image region is an image region in the image corresponding to the text information;
[0161] The fusion subunit is used to vectorize the text information, the context information and the target image area, and fuse the vectorized text information, the context information and the target image area to obtain a feature vector.
[0162] The specific principles and execution processes of each unit and module in the text processing device disclosed in the above embodiment of the present invention are the same as the text processing method disclosed in the above embodiment of the present invention. Please refer to the corresponding parts of the text processing method provided in the above embodiment of the present invention, and will not be repeated here.
[0163] An embodiment of the present invention further provides a storage medium, which includes stored instructions, wherein when the instructions are executed, the device where the storage medium is located is controlled to execute the above-mentioned text processing method.
[0164] The embodiment of the present invention further provides an electronic device, the structural diagram of which is shown in FIG. Fig. 9 As shown, it specifically includes a memory 901 and one or more instructions 902, wherein the one or more instructions 902 are stored in the memory 901 and are configured to be executed by one or more processors 903 to perform the following operations:
[0165] Get the image to be processed;
[0166] Performing text recognition on the image to obtain a text recognition result of the image;
[0167] Determining the text type of each text information in the text recognition result;
[0168] For each of the text information, if it is detected that there is no text error correction rule matching the text information, a feature vector of the text information is obtained, and the feature vector of the text information is input into an error correction model corresponding to the text type to which the text information belongs, to obtain an error correction recognition result of the text information; if the text information is inconsistent with the error correction recognition result, the error correction recognition result is used to replace the text information.
[0169] It should be noted that the data used in the present invention have been anonymized and there is no legal issue such as leaking the patient's personal privacy.
[0170] Each embodiment in this specification is described in a progressive manner, and each embodiment focuses on the differences from other embodiments. The same or similar parts between the embodiments can be referred to each other. For the device embodiment, since it is basically similar to the method embodiment, the description is relatively simple, and the relevant parts can be referred to the partial description of the method embodiment.
[0171] Finally, it should be noted that, in this article, relational terms such as first and second, etc. are merely used to distinguish one entity or operation from another entity or operation, and do not necessarily require or imply any actual relationship or order between these entities or operations.
[0172] For the convenience of description, the above device is described as being divided into various units according to their functions. Of course, when implementing the present invention, the functions of each unit can be implemented in the same or multiple software and / or hardware.
[0173] It can be known from the above description of the implementation mode that those skilled in the art can clearly understand that the present invention can be implemented by means of software plus a necessary general hardware platform. Based on such an understanding, the technical solution of the present invention can be essentially or partly contributed to the prior art in the form of a software product, which can be stored in a storage medium such as ROM / RAM, a magnetic disk, an optical disk, etc., and includes several instructions for enabling a computer device (which can be a personal computer, a server, or a network device, etc.) to execute the methods described in the various embodiments of the present invention or certain parts of the embodiments.
[0174] The above is a detailed introduction to a text processing method provided by the present invention. Specific examples are used in this article to illustrate the principles and implementation methods of the present invention. The description of the above embodiments is only used to help understand the method of the present invention and its core idea. At the same time, for those skilled in the art, according to the idea of the present invention, there will be changes in the specific implementation methods and application scope. In summary, the content of this specification should not be understood as a limitation on the present invention.
Claims
1. A text processing method, characterized in that: include: Get the image to be processed; Performing text recognition on the image to obtain a text recognition result of the image; Determining the text type of each text information in the text recognition result; For each of the text information, if it is detected that there is no text error correction rule matching the text information, a feature vector of the text information is obtained, and the feature vector of the text information is input into an error correction model corresponding to the text type to which the text information belongs, to obtain an error correction recognition result of the text information; if the text information is inconsistent with the error correction recognition result, the error correction recognition result is used to replace the text information.
2. The method according to claim 1, characterized in that The process of detecting that there is no text error correction rule matching the text information includes: Matching the text information with a preset error correction rule table, wherein the error correction rule table includes a plurality of preset text error correction rules corresponding to each of the recognized error texts; If there is no recognition error text consistent with the text information in the error correction rule table, it is determined that there is no text error correction rule matching the text information.
3. The method according to claim 2, characterized in that The process of setting up the error correction rule table includes: Obtain reference text data; Determining the number of occurrences and the number of recognition errors of each candidate text in the reference text data; Determine the target text from each of the candidate texts according to the number of occurrences and the number of recognition errors of each of the candidate texts; According to each target text and the recognition error text of each target text, generating an error correction rule corresponding to each recognition error text; Generate an error correction rule table according to the error correction rules corresponding to each of the identified error texts.
4. The method according to claim 1, characterized in that: The step of obtaining the feature vector of the text information includes: Acquire context information and a target image region of the text information; the context information includes the text information and adjacent text information of the text information; the target image region is an image region in the image corresponding to the text information; The text information, the context information and the target image region are vectorized, and the vectorized text information, the context information and the target image region are fused to obtain a feature vector.
5. The method according to claim 1, characterized in that The error correction model is obtained by pre-training an initial neural network model based on a training data set of the text type; The process of training an initial neural network model based on the training data set of the text type to obtain the error correction model includes: Acquire a training data set of the text type and an initial neural network model to be trained; the training data set of the text type includes training samples of the text type and sample labels of the training samples, the training samples include error text information, context information of the error text information and an image area of the error text information, and the sample labels include reference text corresponding to the error text information; Selecting a target training sample currently used for training from each training sample in the training data set; Vectorizing the target training sample to obtain an input vector of the initial neural network model; Inputting the input vector into the initial neural network model to obtain a recognition result output by the initial neural network model; The loss function value of the initial neural network model is calculated by using a preset loss function, the recognition result and the sample label of the target training sample; Using the loss function value to update the model parameters of the initial neural network model; If the initial neural network model after updating the model parameters does not meet the preset training completion condition, returning to the step of selecting a target training sample currently used for training from each training sample in the training data set; When the initial neural network model after the model parameters are updated satisfies a preset training completion condition, the initial neural network model after the model parameters are updated is determined as the error correction model for the text type.
6. A text processing device, characterized in that: include: An acquisition unit, used for acquiring an image to be processed; A recognition unit, used to perform text recognition on the image to obtain a text recognition result of the image; A determination unit, used to determine the text type of each text information in the text recognition result; The error correction unit is used for obtaining a feature vector of the text information for each of the text information if it is detected that there is no text error correction rule matching the text information, inputting the feature vector of the text information into an error correction model corresponding to the text type to which the text information belongs, and obtaining an error correction recognition result of the text information; if the text information is inconsistent with the error correction recognition result, replacing the text information with the error correction recognition result.
7. The device according to claim 6, characterized in that The error correction unit comprises: A matching subunit, used to match the text information with a preset error correction rule table, wherein the error correction rule table includes a plurality of preset text error correction rules corresponding to each of the recognition error texts; The determination subunit is used to determine that there is no text error correction rule matching the text information if there is no recognition error text consistent with the text information in the error correction rule table.
8. The device according to claim 6, characterized in that The error correction model is obtained by the error correction unit training an initial neural network model based on a training data set of the text type in advance; The error correction unit comprises: an acquisition subunit, configured to acquire a training data set of the text type and an initial neural network model to be trained; the training data set of the text type includes training samples of the text type and sample labels of the training samples, the training samples include error text information, context information of the error text information, and an image region of the error text information, and the sample labels include reference text corresponding to the error text information; A selection subunit, used to select a target training sample currently used for training from each training sample in the training data set; A first execution subunit, used for vectorizing the target training sample to obtain an input vector of the initial neural network model; A second execution subunit is used to input the input vector into the initial neural network model to obtain a recognition result output by the initial neural network model; A calculation subunit, used to calculate the loss function value of the initial neural network model through a preset loss function, the recognition result and the sample label of the target training sample; An updating subunit, used to update the model parameters of the initial neural network model using the loss function value; A third execution subunit is used to return to trigger the selection subunit to execute the process of selecting a target training sample currently used for training from each training sample in the training data set when the initial neural network model after updating the model parameters does not meet the preset training completion condition; The fourth execution subunit is used to determine the initial neural network model after updating the model parameters as the error correction model of the text type when the initial neural network model after updating the model parameters meets the preset training completion condition.
9. A storage medium, characterized in that: The storage medium includes stored instructions, wherein when the instructions are executed, the device where the storage medium is located is controlled to execute the text processing method according to any one of claims 1 to 5.
10. An electronic device, characterized in that: The invention comprises a memory and one or more instructions, wherein the one or more instructions are stored in the memory and configured to be executed by one or more processors to perform the text processing method as claimed in any one of claims 1 to 5.