A training set construction method and device and a storage medium
By supplementing Chinese character training data, adjusting word length and part-of-speech distribution, and filtering for differences in the frequency of similar characters, the problem of semantic distribution differences between the training set and the test set was solved, thereby improving the recognition accuracy of the text recognition model for the OCR task.
Patent Information
- Application Number
- CN202311075855.6
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2023-08-25
- Publication Date
- 2026-02-06
- Estimated Expiration
- 2043-08-25
AI Technical Summary
In existing technologies, the difference in data distribution between the training set and the test set leads to insufficient recognition performance in OCR tasks. In particular, the difference in semantic distribution between the training set and the test set affects the accuracy of the text recognition model.
By acquiring the initial training and test sets, supplementing the missing Chinese character training data, adjusting the differences in word length and part-of-speech distribution, optimizing the word length distribution using the Monte Carlo definite integral method, filtering similar characters using four-corner code and box dimension features, adjusting the frequency differences of similar characters, and constructing the final training set to narrow the semantic distribution between the training and test sets.
It effectively reduces the semantic distribution difference between the training set and the test set, improves the recognition accuracy of the text recognition model, especially in OCR tasks, optimizes the semantic distribution of the training set, and is suitable for text recognition model training in multiple application scenarios.
Smart Images

Figure CN117115831B_ABST
Abstract
Description
Technical Field
[0001] This invention relates to a training set construction method, apparatus, and storage medium, belonging to the field of deep learning technology. Background Technology
[0002] In the field of deep learning, training a neural network is essentially a learning process of the dataset distribution. The actual performance of a training algorithm depends on two aspects: 1) the algorithm's ability to distinguish between data distributions; and 2) the difference between the data distributions of the training set and the test set.
[0003] The former refers to the algorithm's inherent capabilities. For example, EfficientNet and ResNet have better feature extraction capabilities than VGG, thus better distinguishing different types of images. In practical applications, selecting a superior algorithm is a matter of prior knowledge. The latter is more important in practical applications. The data distribution of the training set depends on the sampling method and source of the data, and this data distribution differs somewhat from the true distribution of the test set. Reducing this difference in data distribution is crucial for improving algorithm performance, and different task types correspond to different distribution models.
[0004] As a popular AI task, OCR tasks rely heavily on the semantics of the text in the dataset. Both OCR language modules and LSTMs have long-term dependencies on the context of the text. Therefore, bringing the semantic distribution of the dataset closer together can help improve the performance of OCR tasks. Summary of the Invention
[0005] The purpose of this invention is to overcome the shortcomings of the prior art and provide a training set construction method, apparatus and storage medium for narrowing the semantic distribution between the training set and the test set.
[0006] To achieve the above objectives, the present invention is implemented using the following technical solution:
[0007] In a first aspect, the present invention provides a method for comprehensively optimizing the semantic distribution of an OCR dataset, comprising:
[0008] Obtain an initial training set and an initial test set; wherein, both the initial training set and the test set include multiple Chinese terms;
[0009] Based on the range of Chinese characters represented by the Chinese entries in the test set and the range of regular Chinese characters, the missing Chinese character training data in the initial training set is supplemented to obtain the first corrected training set;
[0010] Based on the differences in word length distribution and / or part-of-speech distribution between the first modified training set and the test set, corresponding supplementary training data is determined, and then the supplementary training data is added to the first modified training set to obtain the second modified training set.
[0011] The test set is used to test the text recognition model trained by the second corrected training set to obtain the Chinese characters that are misrecognized.
[0012] Based on the features of the Chinese characters that were misidentified, the range of similar characters in the second corrected training set is determined.
[0013] Based on the range of similar characters, the frequency difference of similar characters in the second corrected training set is reduced to obtain the final training set.
[0014] Furthermore, the step of determining the corresponding supplementary training data based on the difference in word length distribution between the first corrected training set and the test set includes:
[0015] Count the frequency of each word length in the first corrected training set and test set to obtain the word length distribution curves for the first corrected training set and test set;
[0016] For the word length distribution curves corresponding to the first corrected training set and test set, the Monte Carlo definite integral method is used to calculate the product of the word length distribution curves, and the difference of the definite integrals of the word length distribution curves is used to characterize the difference in word length distribution between the first corrected training set and test set.
[0017] Based on the difference of the definite integral of the word length distribution curve, the corresponding supplementary training data is determined.
[0018] Furthermore, the step of determining the corresponding supplementary training data based on the difference in part-of-speech distribution between the first corrected training set and the test set includes:
[0019] For the terms in the first modified training set and test set, perform word segmentation and part-of-speech tagging respectively to obtain the part-of-speech of each term;
[0020] Calculate the importance parameters of each part of speech in the first corrected training set and test set;
[0021] Based on the importance parameters of each part of speech in the first corrected training set and test set, a vector distance expression is constructed between the first corrected training set and the test set; wherein, the vector distance expression is used to characterize the difference in part-of-speech distribution, and the vector is obtained through the importance parameters of each part of speech;
[0022] Based on the vector distance expression, the corresponding supplementary training data is determined.
[0023] Furthermore, the step of calculating the importance parameters of each part of speech in the first corrected training set and test set includes:
[0024] The importance of each word in each entry of the first modified training set and test set is calculated using the following formula:
[0025]
[0026] In the formula, U represents the longest word segmentation number of the term in the first modified training set or test set, k represents the number of words in the kth term in the first modified training set or test set, that is, the number of words in the kth term, and I is used to characterize the importance of each word in the kth term.
[0027] The total importance of each part of speech is calculated separately in the first revised training set and the test set; where the overall importance of each part of speech is obtained by accumulating the importance of the corresponding words for each part of speech.
[0028] The sum of importance values divided by the number of terms in the corresponding dataset is used as the importance parameter for each part of speech in the first modified training or test set.
[0029] Furthermore, the vector distance is a cosine distance, and the expression for the cosine distance is:
[0030]
[0031] In the formula, YA i YB represents the i-th element in vector YA, which is also the importance parameter of the i-th part-of-speech tag in the first corrected training set. i Let D be the i-th element in vector YB, where p represents the total number of p parts of speech, and i is a term in the vector. cos Used to characterize differences in part-of-speech distribution.
[0032] Furthermore, the feature is the shape feature of Chinese characters, which includes four-corner code features and / or box dimension features.
[0033] Furthermore, the step of determining the range of similar characters in the second corrected training set based on the features of the misidentified Chinese character includes:
[0034] Based on the Chinese characters that were incorrectly identified, the corresponding four-corner code features and box dimension features are extracted;
[0035] Based on the four-corner code features, similar characters with the same radical are determined from the second corrected training set;
[0036] For the similar characters with the same radical, the range of similar characters is determined based on the box dimension feature.
[0037] In a second aspect, the present invention provides a training set construction apparatus, the apparatus comprising:
[0038] The acquisition module is used to acquire an initial training set and a test set; wherein, both the initial training set and the test set include multiple Chinese terms.
[0039] The first supplementary module is used to supplement the missing Chinese character training data in the training set based on the range of Chinese characters represented by the Chinese words in the test set and the range of regular Chinese characters, so as to obtain the first corrected training set.
[0040] The second supplementary module is used to determine the corresponding supplementary training data based on the differences in word length distribution and / or part-of-speech distribution between the first corrected training set and the test set, and then supplement the first corrected training set with the supplementary training data to obtain the second corrected training set.
[0041] The testing module is used to test the text recognition model trained by the second corrected training set using the test set, and to obtain the Chinese characters that are misrecognized.
[0042] A similar character module is used to determine the range of similar characters in the second corrected training set based on the features of the incorrectly identified Chinese character.
[0043] The similar character frequency difference module is used to reduce the frequency difference of similar characters in the second corrected training set based on the range of similar characters, so as to obtain the final training set.
[0044] Thirdly, the present invention provides an electronic device, including a processor and a storage medium;
[0045] The storage medium is used to store instructions;
[0046] The processor is configured to operate according to the instructions to perform the steps of the method according to any of the preceding claims.
[0047] Fourthly, the present invention provides a computer-readable storage medium having a computer program stored thereon, which, when executed by a processor, implements the steps of any of the preceding methods.
[0048] Compared with the prior art, the beneficial effects achieved by the present invention are as follows:
[0049] This invention provides a training set construction method, apparatus, and storage medium. First, by supplementing missing Chinese character training data based on the range of Chinese characters represented by Chinese entries in the test set and the range of conventional Chinese characters, a first corrected training set is obtained. Based on the differences in word length distribution and / or part-of-speech distribution between the first corrected training set and the test set, corresponding supplementary training data is determined to make the word length distribution and / or part-of-speech distribution of the first corrected training set closer to that of the test set. On this basis, based on the actual recognition results of the text recognition model trained by the above-adjusted training set, the frequency differences of similar characters are adjusted, thereby narrowing the semantic distribution of the training set and the test set in OCR. Attached Figure Description
[0050] Figure 1 This is a flowchart of a training set construction method provided in an embodiment of the present invention;
[0051] Figure 2 This is a schematic diagram of the four-corner code for Chinese characters provided in an embodiment of the present invention;
[0052] Figure 3 This is a schematic diagram showing the number of grid cells covering Chinese characters under different grid sizes provided in the embodiments of the present invention;
[0053] Figure 4 This is a schematic diagram of filtering similar characters provided in an embodiment of the present invention;
[0054] Figure 5 This is a block diagram of a training set construction apparatus provided in an embodiment of the present invention;
[0055] Figure 6 This is a block diagram of an electronic device provided in an embodiment of the present invention. Detailed Implementation
[0056] The present invention will be further described below with reference to the accompanying drawings. The following embodiments are only used to more clearly illustrate the technical solution of the present invention, and should not be used to limit the scope of protection of the present invention.
[0057] Example 1
[0058] like Figure 1 As shown in this embodiment, a method for constructing a training set is introduced to narrow the OCR semantic distribution between the training and test sets. This method can be implemented on the server side and may include:
[0059] Step S100: Obtain the initial training set and test set; wherein, the initial training set and test set each include multiple Chinese terms.
[0060] In this embodiment, the test set and initial training set described above are used to train and test the text recognition model. These can be text recognition models specifically designed for Chinese character recognition.
[0061] In this embodiment, the test set corresponds to scenario information. For example, the test set can be an application scenario corresponding to the above-mentioned text recognition model. In this embodiment, the above-mentioned Chinese character recognition model is mainly applied in application scenarios such as RPA and process mining. Therefore, the test set can be a pre-annotated UI image. Further subdivided, it can be a UI image in a financial scenario, such as the UI image of financial software, or a UI image in a customer service scenario, such as the UI image of a customer service business system.
[0062] In this embodiment, a data-driven training set can be automatically constructed based on a test set corresponding to a specific application scenario. Therefore, when a text recognition model specifically for the financial field is needed, several UI images of a financial system can be collected and labeled to obtain a test set corresponding to the financial scenario.
[0063] In this embodiment, the text recognition model described above can be a convolutional neural network-based model, such as the CRNN (Convolutional Recurrent Neural Network) model, or an attention-based model, such as the Attention-based Encoder-Decoder model, or a densely connected model, such as the DenseNet+CTC model.
[0064] In this embodiment, the training set can be generated by using a text renderer to generate text images. It's easy to understand that generating a corresponding text image for a text field means that the text field is the labeled data for the corresponding text image. The text field and the text image together constitute the training data for the text recognition model, and multiple pairs of training data constitute the training set. Specifically, the text renderer can be a Text Renderer, which can pre-configure a corpus for data sampling. This corpus can contain a large number of text fields. In this embodiment, in step S100, text fields can be obtained by randomly sampling from the corpus, and then the text renderer is used to generate the corresponding training data.
[0065] Step S200: Based on the range of Chinese characters represented by the terms in the test set and the range of regular Chinese characters, supplement the missing Chinese character training data in the initial training set to obtain the first corrected training set.
[0066] In this embodiment, the training set obtained in step S100 often lacks training data for certain common Chinese characters. The fundamental reason is the lack of corresponding Chinese character examples in the corpus. Therefore, regardless of the sampling method, the generated initial training set will always lack corresponding Chinese character examples. In some cases, it may also be due to the sampling method. For example, the corpus may cover the range of common Chinese characters and the range of Chinese characters in the test set, but the training set generated by sampling may lack certain common Chinese characters. In particular, when there are rare characters in the test set, the training set generated based on the corpus often lacks training data for rare characters.
[0067] Therefore, in response to the above situations, the training data for common Chinese characters missing in the training set can be supplemented based on the range of common Chinese characters, and correspondingly, the corpus can also be supplemented. If the test set contains rare characters not found in the corpus, the data for rare Chinese characters missing in the training set can also be supplemented based on the range of characters in the test set.
[0068] In this embodiment, the above-mentioned range of conventional Chinese characters is determined based on a dictionary, which may be the "General Standard Chinese Characters List" (GB / T 16159-2012) or the "Commonly Used Chinese Characters List" (GB 2312-80).
[0069] The range of Chinese characters in the test set mentioned above is the range of Chinese characters included in the test set. Because the test set is collected according to specific application scenarios, the corresponding test sets are different for different application scenarios, so the range of Chinese characters in the test set is not known in advance.
[0070] In this embodiment, the aforementioned supplementary action can be represented as extracting the missing Chinese character data from the corpus, and then generating the aforementioned missing Chinese character training data based on the missing Chinese character data. If the corpus lacks regular Chinese character data, the aforementioned supplementary action can also be represented as crawling the missing Chinese character data from the internet using keyword crawling, and then generating the aforementioned missing Chinese character training data based on the missing Chinese character data.
[0071] In this embodiment, the range of regular Chinese characters included in the dictionary can be defined as set A, or regular Chinese character set A. The range of Chinese characters included in the training set can be defined as set B, or training set Chinese character set B. The intersection of set A and set B, A∩B, represents the regular Chinese characters present in the training set. The difference between set A and the range of regular Chinese characters in the training set represents the regular Chinese characters missing from the current training set. The Jaccard distance can be used to represent the coverage rate of regular Chinese characters in the training set, and the coverage rate J is expressed as:
[0072]
[0073] In formula (1), A represents the regular Chinese character set, and B represents the initial training set.
[0074] In this embodiment, keywords or news headlines lacking regular Chinese characters can be obtained as supplementary corpus using methods such as keyword web crawling. The range of Chinese characters in the supplemented training set should cover all regular Chinese characters; and the coverage rate J calculated after the supplementation should also be reduced.
[0075] Step S300: Based on the differences in word length distribution and / or part-of-speech distribution between the first corrected training set and the test set, determine the corresponding supplementary training data, and then supplement the first corrected training set with the supplementary training data to obtain the second corrected training set.
[0076] In this embodiment, the corresponding supplementary training data can be determined based on the difference in word length distribution between the first corrected training set and the test set, or based on the difference in part-of-speech distribution between the first corrected training set and the test set, or simultaneously based on both the difference in word length distribution and the difference in part-of-speech distribution between the first corrected training set and the test set.
[0077] Specifically, the steps described above for determining the corresponding supplementary training data based on the difference in word length distribution between the first corrected training set and the test set may include:
[0078] Step S301: Count the frequency of each word length in the first corrected training set and test set to obtain the word length distribution curves corresponding to the first corrected training set and test set.
[0079] Specifically, the lengths of text entries in the training and test sets differ, and different entry lengths correspond to different text types. Taking web page text as an example, entries with a length of 2 Chinese characters are more likely to correspond to simple verbs and nouns, while entries with a length of 10 Chinese characters are more likely to correspond to news headlines, chat logs, etc. The frequency of occurrence of each character length entry in the first modified training and test sets can be statistically analyzed to obtain the corresponding character length distribution curve.
[0080] It is easy to understand that the above word length distribution curve can be obtained by constructing a corresponding histogram for the frequency of each word length, and fitting the vertices of each bar in the histogram to obtain the above word length distribution curve.
[0081] Step S302: For the word length distribution curves corresponding to the first corrected training set and test set, the Monte Carlo definite integral method is used to calculate the product of the word length distribution curves, and the difference of the definite integrals of the word length distribution curves is used to characterize the difference in word length distribution between the first corrected training set and test set.
[0082] In this embodiment, the Monte Carlo definite integral method can be used to calculate the product of the distribution curves. Let Ptrain and Ptest be the probability distribution sets for each word length in the first modified training set and test set, respectively, with the largest word length being M and n being the terms in the probability sets. Then, the word length distribution difference ΔLD between the first modified training set and test set can be represented by the definite integral difference:
[0083]
[0084] In formula (2), M represents the maximum character length, n represents the nth character length term, and P test (n) represents the probability distribution of the nth word in the test set, P train (n) represents the probability distribution of the nth word in the first modified training set.
[0085] Step S303: Based on the difference of the definite integral of the word length distribution curve, determine the corresponding supplementary training data.
[0086] In this embodiment, after the supplementary training data is added to the first corrected training set, the word length distribution difference ΔLD should be reduced. Accordingly, the word length distribution of the first corrected training set after the supplementation is optimized. Therefore, the corresponding supplementary training data is referred to as the determined training data. After the determined training data is added to the first corrected training set, the word length distribution difference ΔLD can be reduced.
[0087] In this embodiment, a specific method is provided to determine the corresponding supplementary training data, specifically including:
[0088] C n = (C+C) * )*P test (n)-C*P train (n) (3)
[0089] In formula (3), C n Let C represent the number of words that need to be added to the nth word in the supplementary training data, and let C represent the number of training data in the first corrected training set. * This represents a fixed set of supplementary training data selected manually, and C... * The amount of data in C can be 20%-30% of that in C.
[0090] In this embodiment, when a certain word length C n When the value is negative, no sample reduction operation is performed on the word length of that type. (Added C...) n Then, the Monte Carlo integral difference of the word length distribution is recalculated. This time, the integral difference should be reduced, and the word length distribution of the second corrected training set is optimized relative to the first corrected training set.
[0091] Specifically, in some OCR application scenarios, part-of-speech (POS) may determine the importance of a term. For example, in webpage text recognition, verbs are more likely to correspond to buttons, switches, etc., and compared to nouns, verb terms are more likely to have clickable functionality. Recognizing verb terms may be far more important than recognizing noun terms or news headlines. In other application scenarios, such as invoice recognition, numbers are more important, and in contract recognition, names are more important. Therefore, depending on the scenario, the importance of POS varies, and adjusting the distribution of POS accordingly is more conducive to the correct recognition of important terms in the scenario. The steps described above for determining the corresponding supplementary training data based on the difference in POS distribution between the first corrected training set and the test set can include:
[0092] Step S311: Perform word segmentation and part-of-speech tagging on the terms in the first modified training set and test set respectively to obtain the part-of-speech of each term.
[0093] In this implementation, the open-source Universal Transformer neural network pre-trained model can be used to segment and tag the words in the first modified training set and test set, thereby obtaining the part-of-speech categories for each word. Alternatively, natural language processing libraries such as NLTK (Natural Language Toolkit) or Stanford CoreNLP can be used to perform word segmentation and part-of-speech tagging.
[0094] Step S312: Calculate the importance parameters of each part of speech in the first corrected training set and test set.
[0095] In this embodiment, the importance parameters of each word corresponding to each term in the first revised training set and test set can be calculated in various ways. For example, the frequency of each part of speech in the first revised training set and test set can be directly counted, that is, the number of times each part of speech corresponds to the word in the first revised training set and test set.
[0096] Importance parameters can be calculated using absolute word frequency, which directly uses the number of times a part of speech appears in the first revised training and test sets as the importance parameter. The higher the word frequency, the larger the importance parameter. This is easily understood as the number of times a part of speech appears in a dataset, such as the total number of words with that part of speech (e.g., verbs) appear in that dataset. Correspondingly, relative word frequency can also be used. For example, the number of times a part of speech appears in the first revised training and test sets is divided by the total number of words in the corresponding dataset to obtain the relative frequency of the part of speech as the importance parameter. The higher the relative frequency, the larger the importance parameter. The TF-IDF (Term Frequency-Inverse Document Frequency) algorithm can also be used to calculate the importance parameter of each part of speech. This considers not only the frequency (TF) of a word in the current term but also the frequency (IDF) of the word in the entire training set. The higher the TF-IDF value, the larger the importance parameter.
[0097] It is easy to understand that for an entry with a larger number of words, the importance of its individual words is lower. Therefore, by utilizing the number of words segmented into a single entry, the importance of parts of speech in longer entries can be reduced. Specifically, this implementation provides a specific formula to calculate the importance of each word in each entry.
[0098] For example, the importance of each part of speech in a certain term can be represented by formula (4).
[0099]
[0100] In formula (4), U represents the longest word segmentation number of the term in the first modified training set or test set, k represents the number of words in the kth term in the first modified training set or test set, that is, the number of words in the kth term, and I is used to characterize the importance of each word in the kth term.
[0101] The importance of each part of speech is summed in the first revised training set and the test set, respectively. The sum of the importance of each part of speech is represented as the sum of the importance of all words corresponding to a certain part of speech.
[0102] Then, the sum of importance is divided by the number of terms in the corresponding dataset as the importance parameter for each part of speech in the first corrected training or test set.
[0103] Step S313: Based on the importance parameters of each part of speech in the first corrected training set and the test set, construct a vector distance expression between the first corrected training set and the test set; wherein, the vector distance expression is used to characterize the difference in the distribution of the part of speech, and the vector is obtained through the importance parameters of each part of speech.
[0104] In this embodiment, vectors YA and YB can be used to represent the sets of all part-of-speech importance coefficients in the first corrected training set and test set, respectively; the length of the set can be p, i.e., p parts of speech, and i is a term in the vector.
[0105] In this embodiment, the cosine distance between vectors can be used to characterize the part-of-speech distribution differences. In some embodiments, other distances between vectors can also be used to characterize the part-of-speech distribution differences, such as Euclidean distance or Chebyshev distance, etc. Accordingly, this embodiment also provides a specific cosine distance expression, expressed as:
[0106]
[0107] In formula (5), YA i YB represents the i-th element in vector YA, which is also the importance parameter of the i-th part-of-speech tag in the first corrected training set. i It is represented as the i-th element in vector YB.
[0108] Step S314: Based on the vector distance expression, determine the corresponding supplementary training data.
[0109] In this embodiment, after supplementing the first corrected training set with the aforementioned supplementary training data, the vector distance should decrease, and correspondingly, the part-of-speech distribution difference between the two datasets should also decrease. The part-of-speech distribution of the supplemented first corrected training set should be optimized. Therefore, determining the corresponding supplementary training data is referred to as determining the training data. The determined training data, after being supplemented to the first corrected training set, can reduce the aforementioned vector distance D. cos .
[0110] In this embodiment, a specific method is provided to determine the corresponding supplementary training data, specifically including:
[0111] Q i = (Q+Q) * )*YB i -Q*YA i (6)
[0112] In formula (6), Q i Let Q represent the number of parts of speech that need to be supplemented for the i-th part of speech, and let Q represent the number of training data in the first corrected training set. * This represents a fixed set of supplementary training data selected manually, and Q is... * The amount of data in Q can be 20%-30% of that in Q.
[0113] After supplementing the training data, the cosine distance of the vector of the importance coefficients of word types between the second corrected training set and the test set should decrease, indicating the optimization of the word type distribution.
[0114] Step S400: Use the test set to test the text recognition model trained via the second corrected training set to obtain the Chinese characters that are misrecognized.
[0115] In this embodiment, first, the second corrected training set can be used to train a preset text recognition model to be trained to obtain the above-mentioned text recognition model trained via the second corrected training set. As described above, the preset text recognition model can be a model based on a convolutional neural network, such as a CRNN (Convolutional Recurrent Neural Network) model, or a model based on an attention mechanism, such as an Attention-based Encoder-Decoder model, or a model based on dense connections, such as a DenseNet+CTC model.
[0116] Step S500: Based on the features of the misrecognized Chinese characters, determine the range of similar characters of the misrecognized Chinese characters in the second corrected training set.
[0117] In this embodiment, it should be noted that the above-mentioned misrecognized Chinese characters are expressed as the Chinese characters that are recognized as, and this Chinese character does not correspond to the Chinese character input in the model, rather than the Chinese character that is misrecognized. For example, there is a Chinese character "件" in the test set, and this "件" is input into the text recognition model for recognition, and the model output result is "牛", and this "牛" is the above-mentioned misrecognized Chinese character.
[0118] Taking the above example for illustration, the text recognition model trained via the second corrected training set recognizes "件" as "牛", indicating that the number of the Chinese character "牛" in the second corrected training set is too high. This excessive number can be that there are a large number of "牛" in a large number of entries in the second corrected training set, or there are a large number of "牛" in some entries. Therefore, to solve this problem, it is necessary to balance the frequency differences of "牛" and the characters similar to "牛" in the second corrected training set. To avoid the frequency of a certain similar character being too high compared to the other similar characters. Therefore, in this embodiment, based on the features carried by the character "牛", the characters similar to "牛" can be determined from the second corrected training set. <For shape features, in this embodiment, the range of similar characters of the misrecognized Chinese character in the second correction training set can be determined based on the four-corner code features of Chinese characters. It is easy to understand that Chinese characters with the same radical are regarded as similar Chinese characters. Therefore, Chinese characters with the same radical can be classified using the four-corner code of Chinese characters. In this embodiment, a third-party library in Python, such as the char_featurizer third-party library, can be used to extract the four-corner code of the misrecognized Chinese character. The four-corner code represents the stroke features at the upper left, upper right, lower left, and lower right positions of a Chinese character. Chinese characters with similar radicals will have some identical four-corner codes. For example, for Chinese characters with the "walk radical" such as "选 (xuǎn)", "遗 (yí)", "运 (yùn)", "还 (huán)", the four-corner codes corresponding to the upper left, lower left, and lower right positions are all 3, 2, and 0, as Figure 2 shown. According to the four-corner codes of the same radical, this method can filter out all Chinese characters with the same radical in the second correction training set.
[0121] For shape features, in this embodiment, the range of similar characters of the misrecognized Chinese character in the second correction training set can also be determined based on the box dimension feature. Specifically, Chinese characters with the same radical can be filtered out based on the four-corner code. For different parts of two Chinese characters with the same radical, the box dimension in the field of fractals can be used for calibration, that is, calculating the number of grids covered by the Chinese character under grids of different sizes, as Figure 3 shown. Fit a first-degree polynomial of the box size - box number coordinate points, denoted as y = ax + b, and the negative value -a of the polynomial factor is used as the box dimension. The box dimension can represent the morphological complexity of a Chinese character. If the box dimensions of different parts of similar characters are close, these characters are more likely to be misrecognized by OCR than other similar characters.
[0122] Therefore, in this embodiment, the range of similar characters of the misrecognized Chinese character in the second correction training set can also be determined based on both the four-corner code feature and the box dimension feature.
[0123] Specifically, the above step S500 may include:
[0124] S501. Extract the corresponding four-corner code feature and box dimension feature based on the misrecognized Chinese character.
[0125] As described above, in this embodiment, it can be extracted through the char_featurizer third-party library.
[0126] S502. Determine similar characters with the same radical from the second correction training set based on the four-corner code feature.
[0127] S503. For the similar characters with the same radical, determine the range of the similar characters based on the box dimension feature.
[0128] This method first uses the four-corner code of Chinese characters to identify characters with the same radical as the misidentified characters from the second corrected training set. Then, based on this, it further uses the box dimension of the characters to identify similar characters with the same radical whose different parts are also as similar as possible. This method can filter out similar characters whose shapes are most similar to the target Chinese character, such as... Figure 4 As shown, the target Chinese character is the one that was incorrectly identified as mentioned above. Characters selected using this method are more likely to be misidentified by character recognition models compared to other similar characters.
[0129] In some implementations, the semantic features of Chinese characters can also be used to determine the range of similar characters in the second correction training set for the Chinese characters that were misidentified. For example, word vector models or pre-trained language models can be used to calculate the semantic similarity between Chinese characters.
[0130] Step S600: Based on the range of similar characters, reduce the frequency difference of similar characters in the second corrected training set to obtain the final training set.
[0131] In this embodiment, the action of reducing the frequency difference of similar characters in the second corrected training set can be expressed as adding similar characters to the second corrected training set to reduce the frequency difference of similar characters. It is easy to understand that, for example, if the second corrected training set has three similar characters: A, B, and C, with frequencies of X, Y, and Z respectively, and X>Y>Z, then training data on B and C can be added to the second corrected training set to balance the frequencies of A, B, and C.
[0132] In this embodiment, a specific method is also provided to determine the number of training data for similar characters that should be supplemented, specifically:
[0133] CM = (T) m -T x )*0.25*(1-|B m -B x |) (7)
[0134] In formula (7), T m Let represent the number of Chinese characters that were misrecognized in the second corrected training set, where the subscript m can represent that there are M misrecognized Chinese characters, and the number of the m-th misrecognized Chinese character can be represented by T. m It means that T x This is represented as corresponding to T. m The number of similar characters in the second revised training set, where the subscript x represents T. m In the second revised training set, there are X similar Chinese characters, where the number of similar characters of the x-th character can be represented by T. xThis indicates that B... m Let B be the box dimension of the Chinese character that was misidentified. x Represented as the box dimension of similar characters.
[0135] The aforementioned 0.25 indicates that one-quarter of the difference between the incorrectly identified Chinese character and the similar character samples is used as the base number for the supplementation quantity. This avoids the negative impact of excessive sample supplementation on the character frequency distribution. The absolute value of the box dimension interpolation further controls the number of supplementation samples, ensuring that characters with more similar forms receive more supplementation samples. By supplementing the number of training samples for similar characters, the sample difference between similar characters is reduced, thereby reducing the probability of OCR misidentifying Chinese characters with the same radical.
[0136] In some implementations, when one or more similar characters have a high proportion among a number of similar characters, the aforementioned action of reducing the frequency difference of similar characters in the second corrected training set can also reduce the training data of similar characters with an excessively high proportion, so that the frequency distribution of each similar character in the second corrected training set is balanced.
[0137] In summary, the method provided in this embodiment first supplements the missing Chinese character training data based on the range of Chinese characters represented by the Chinese entries in the test set and the range of conventional Chinese characters, obtaining a first corrected training set. Based on the differences in word length distribution and / or part-of-speech distribution between the first corrected training set and the test set, corresponding supplementary training data is determined, making the word length distribution and / or part-of-speech distribution of the first corrected training set closer to that of the test set. On this basis, based on the actual recognition results of the text recognition model trained on the adjusted training set, adjustments are made to the frequency differences of similar characters, thereby narrowing the semantic distribution of the training set and the test set in OCR. Furthermore, this achieves the construction of a data-driven training set for the text recognition model. This method can automatically adjust the obtained initial test set based on the test set, obtaining multiple training sets for training text recognition models in different application scenarios with lower manual and time costs.
[0138] Example 2
[0139] like Figure 5 As shown, this embodiment provides a training set construction apparatus, the method of which may include:
[0140] The acquisition module is used to acquire an initial training set and a test set; wherein, both the initial training set and the test set include multiple Chinese terms.
[0141] The first supplementary module is used to supplement the missing Chinese character training data in the training set based on the range of Chinese characters represented by the Chinese words in the test set and the range of regular Chinese characters, so as to obtain the first corrected training set.
[0142] The second supplementary module is used to determine the corresponding supplementary training data based on the differences in word length distribution and / or part-of-speech distribution between the first corrected training set and the test set, and then supplement the first corrected training set with the supplementary training data to obtain the second corrected training set.
[0143] The testing module is used to test the text recognition model trained by the second corrected training set using the test set, and to obtain the Chinese characters that are misrecognized.
[0144] A similar character module is used to determine the range of similar characters in the second corrected training set based on the features of the incorrectly identified Chinese character.
[0145] The similar character frequency difference module is used to reduce the frequency difference of similar characters in the second corrected training set based on the range of similar characters, so as to obtain the final training set.
[0146] Example 3
[0147] like Figure 6 As shown, this embodiment provides an electronic device, including a processor and a storage medium;
[0148] The storage medium is used to store instructions;
[0149] The processor is configured to operate according to the instructions to perform the steps of the method according to any one of Embodiment 1.
[0150] Example 4
[0151] This embodiment provides a computer-readable storage medium having a computer program stored thereon, which, when executed by a processor, implements the steps of any of the methods described in Embodiment 1.
[0152] Example 5
[0153] The present invention also provides a computer program product containing instructions that, when executed by a computer, cause the computer to perform the method in Embodiment 1.
[0154] It is understood that the specific examples in this document are only intended to help those skilled in the art better understand the embodiments described herein, and are not intended to limit the scope of the invention.
[0155] It is understood that in the various embodiments described in this specification, the sequence number of each process does not imply the order of execution. The execution order of each process should be determined by its function and internal logic, and should not constitute any limitation on the implementation process of the embodiments described in this specification.
[0156] It is understood that the various implementation methods described in this specification can be implemented individually or in combination, and the implementation methods in this specification are not limited in this respect.
[0157] Unless otherwise stated, all technical and scientific terms used in the embodiments of this specification have the same meaning as commonly understood by one of ordinary skill in the art. The terminology used in this specification is for the purpose of describing particular embodiments only and is not intended to limit the scope of this specification. The term "and / or" as used in this specification includes any and all combinations of one or more of the associated listed items. The singular forms "a," "the," and "the" as used in the embodiments of this specification and the appended claims are also intended to include the plural forms unless the context clearly indicates otherwise.
[0158] It is understood that the processor in the embodiments of this specification can be an integrated circuit chip with signal processing capabilities. In implementation, each step of the above method embodiments can be completed by integrated logic circuits in the processor's hardware or by instructions in software form. The processor can be a general-purpose processor, a digital signal processor (DSP), an application-specific integrated circuit (ASIC), a field-programmable gate array (FPGA), or other programmable logic devices, discrete gate or transistor logic devices, or discrete hardware components. It can implement or execute the methods, steps, and logic block diagrams disclosed in the embodiments of this specification. The general-purpose processor can be a microprocessor or any conventional processor. The steps of the methods disclosed in the embodiments of this specification can be directly implemented by a hardware decoding processor, or by a combination of hardware and software modules in the decoding processor. The software modules can reside in random access memory, flash memory, read-only memory, programmable read-only memory, electrically erasable programmable memory, registers, or other mature storage media in the art. This storage medium is located in memory; the processor reads information from the memory and, in conjunction with its hardware, completes the steps of the above methods.
[0159] It is understood that the memory in the embodiments of this specification may be volatile memory or non-volatile memory, or may include both volatile and non-volatile memory. Non-volatile memory may be read-only memory (ROM), programmable read-only memory (PROM), erasable programmable read-only memory (EPROM), electrically erasable programmable read-only memory (EEPROM), or flash memory. Volatile memory may be random access memory (RAM). It should be noted that the memory in the systems and methods described herein is intended to include, but is not limited to, these and any other suitable types of memory.
[0160] Those skilled in the art will recognize that the units and algorithm steps of the various examples described in conjunction with the embodiments disclosed herein can be implemented in electronic hardware, or a combination of computer software and electronic hardware. Whether these functions are implemented in hardware or software depends on the specific application and design constraints of the technical solution. Those skilled in the art can use different methods to implement the described functions for each specific application, but such implementation should not be considered beyond the scope of this specification.
[0161] Those skilled in the art will clearly understand that, for the sake of convenience and brevity, the specific working processes of the systems, devices, and units described above can be referred to the corresponding processes in the aforementioned method implementations, and will not be repeated here.
[0162] In the several embodiments provided in this specification, it should be understood that the disclosed systems, apparatuses, and methods can be implemented in other ways. For example, the apparatus embodiments described above are merely illustrative; for instance, the division of units is only a logical functional division, and in actual implementation, there may be other division methods. For example, multiple units or components may be combined or integrated into another system, or some features may be ignored or not executed. Furthermore, the coupling or direct coupling or communication connection shown or discussed may be through some interfaces; the indirect coupling or communication connection between devices or units may be electrical, mechanical, or other forms.
[0163] The units described as separate components may or may not be physically separate. The components shown as units may or may not be physical units; that is, they may be located in one place or distributed across multiple network units. Some or all of the units can be selected to achieve the purpose of this embodiment, depending on actual needs.
[0164] In addition, the functional units in the various embodiments of this specification can be integrated into one processing unit, or each unit can exist physically separately, or two or more units can be integrated into one unit.
[0165] If the aforementioned functions are implemented as software functional units and sold or used as independent products, they can be stored in a computer-readable storage medium. Based on this understanding, the technical solutions of this specification, in essence, or the parts that contribute to the prior art, or parts of the technical solutions, can be embodied in the form of software products. These computer software products are stored in a storage medium and include several instructions to cause a computer device (which may be a personal computer, server, or network device, etc.) to execute all or part of the steps of the methods described in the various embodiments of this specification. The aforementioned storage medium includes various media capable of storing program code, such as USB flash drives, portable hard drives, read-only memory (ROM), random access memory (RAM), magnetic disks, or optical disks.
[0166] The above description is only a preferred embodiment of the present invention. It should be noted that for those skilled in the art, several improvements and modifications can be made without departing from the technical principles of the present invention, and these improvements and modifications should also be considered within the scope of protection of the present invention.
Claims
1. A training set construction method characterized by, The method comprises: obtaining an initial training set and an initial test set; wherein the initial training set and the test set each comprise a plurality of Chinese entries; based on the Chinese character range represented by the entries in the test set and the conventional Chinese character range, supplementing the missing Chinese character training data in the initial training set to obtain a first modified training set; based on the word length distribution difference and / or the part-of-speech distribution difference between the first modified training set and the test set, determining the corresponding supplementary training data, and then supplementing the supplementary training data to the first modified training set to obtain a second modified training set; using the test set to test the text recognition model trained by the second modified training set to obtain misrecognized Chinese characters; based on the features of the misrecognized Chinese characters, determining the range of similar characters of the misrecognized Chinese characters in the second modified training set; based on the range of similar characters, reducing the frequency difference of similar characters in the second modified training set to obtain a final training set; the step of determining the corresponding supplementary training data based on the word length distribution difference between the first modified training set and the test set comprises: statistically obtaining the frequency corresponding to each word length of the first modified training set and the test set to obtain the word length distribution curve corresponding to the first modified training set and the test set; using the Monte Carlo definite integral method to calculate the integral of the word length distribution curve corresponding to the first modified training set and the test set, and using the difference between the definite integrals of the word length distribution curves to represent the word length distribution difference between the first modified training set and the test set; based on the difference between the definite integrals of the word length distribution curves, determining the corresponding supplementary training data; the step of determining the corresponding supplementary training data based on the part-of-speech distribution difference between the first modified training set and the test set comprises: performing word segmentation and part-of-speech tagging processing on the entries in the first modified training set and the test set to obtain the part-of-speech of each entry; calculating the importance parameters of each part-of-speech in the first modified training set and the test set; based on the importance parameters of each part-of-speech in the first modified training set and the test set, constructing a vector distance expression between the first modified training set and the test set; wherein the vector distance expression is used to represent the part-of-speech distribution difference, and the vector is obtained by the importance parameters of each part-of-speech; based on the vector distance expression, determining the corresponding supplementary training data; the step of calculating the importance parameters of each part-of-speech in the first modified training set and the test set comprises: calculating the importance of each word in each entry in the first modified training set and the test set by the following formula: ; In the formula, U represents the longest number of word segmentation of the term in the first modified training set or the test set, k represents the number of word segmentation in the first term in the modified training set or the test set, that is, the number of vocabularies possessed by the first term, used to represent the importance degree of each vocabulary of the first term, respectively accumulating the total importance of each part-of-speech in the first modified training set and the test set; wherein the total importance of each part-of-speech is obtained by accumulating the importance of the words corresponding to each part-of-speech; using the total importance divided by the number of entries in the corresponding data set as the importance parameter of each part-of-speech in the first modified training set or the test set.
2. The training set construction method of claim 1, wherein, The vector distance is a cosine distance, and the cosine distance expression is: ; In the formula, Represents the first element in vector YA The element, that is, the element in the first corrected training set. The importance parameter of each part of speech, correspondingly Represented as the first in vector YB There are p elements, where p represents the total number of parts of speech, and i is a term in the vector. Used to characterize differences in part-of-speech distribution.
3. The training set construction method of claim 1, wherein, The features are shape features of Chinese characters, and the shape features include four-corner number features and / or box dimension features.
4. The training set construction method of claim 3, wherein, The step of determining the similar character range of the misrecognized Chinese character in the second modified training set based on the features of the misrecognized Chinese character comprises: Based on the misrecognized Chinese character, extracting corresponding four-corner number features and box dimension features; Based on the four-corner number features, determining similar characters with the same component from the second modified training set; Based on the box dimension features, determining the similar character range from the similar characters with the same component.
5. A training set construction apparatus for implementing the training set construction method according to claim 1, characterized by The device comprises: An acquisition module for acquiring an initial training set and a test set; wherein the initial training set and the test set each comprise a plurality of Chinese entries A first supplement module for supplementing missing Chinese character training data in the training set based on the Chinese character range represented by the Chinese entries in the test set and the regular Chinese character range, to obtain a first modified training set; A second supplement module for determining corresponding supplement training data based on the word length distribution difference and / or the part of speech distribution difference between the first modified training set and the test set, and then supplementing the supplement training data to the first modified training set to obtain a second modified training set; A test module for testing a text recognition model trained by the second modified training set using the test set, to obtain misrecognized Chinese characters; A similar character module for determining the similar character range of the misrecognized Chinese character in the second modified training set based on the features of the misrecognized Chinese character; A similar character frequency difference module for reducing the frequency difference of similar characters in the second modified training set based on the similar character range, to obtain a final training set.
6. An electronic device, comprising: It comprises a processor and a storage medium; The storage medium is used to store instructions; The processor is used to operate according to the instructions to perform the steps of the method according to any one of claims 1-4.
7. A computer readable storage medium having stored thereon a computer program, characterized in that: The program is executed by the processor to implement the steps of the method according to any one of claims 1-4.
Citation Information
Patent Citations
Model training method and device, electronic equipment and storage medium
CN113807098A
Medical OCR data optimization model training method, optimization method and equipment
CN114387602A