A training set optimization method and device and a storage medium

By constructing feature representations for pure language and mixed language entries, the training set is optimized to address the problem of insufficient recognition accuracy of OCR models in multilingual mixed samples, thereby improving recognition accuracy.

CN117315681BActive Publication Date: 2026-03-17SHANGHAI YISAIQI SOFTWARE CO LTD
View PDF 2 Cites 0 Cited by

Patent Information

Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2023-09-20
Publication Date
2026-03-17

AI Technical Summary

Technical Problem

Existing OCR models are prone to recognition errors when processing multilingual mixed samples, especially when Chinese datasets contain English, numbers, and punctuation marks, resulting in insufficient recognition accuracy.

Method used

By constructing feature representations for pure language and mixed language entries, using vector space representation methods to reduce dimensionality and comparing the differences between the training set and the test set, the training set is optimized to improve recognition accuracy.

Benefits of technology

It improves the recognition accuracy of OCR models for multilingual mixed samples and reduces recognition errors, especially the problem of missing Chinese, English, numbers and punctuation marks.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN117315681B_ABST
    Figure CN117315681B_ABST
Patent Text Reader

Abstract

This invention discloses a training set optimization method, apparatus, and storage medium. The method includes acquiring a test set and a training set for OCR model training; distinguishing between pure language terms and mixed language terms in the test set and training set; constructing feature representations for the pure language terms and mixed language terms respectively; constructing feature distribution differences between the test set and training set based on the feature representations of the pure language terms and mixed language terms; and optimizing the training set according to the feature distribution differences between the test set and training set. This invention can reduce high-dimensional semantic features to a finite vector space and use the vector space to compare the differences between the training set and the test set to guide the optimization of the training set.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] This invention relates to a training set optimization method, apparatus, and storage medium, belonging to the field of OCR text recognition technology. Background Technology

[0002] Optical Character Recognition (OCR) is a technology that converts text in an image into editable text. OCR has wide applications in many fields, such as automated processing of scanned documents, license plate recognition, ID card recognition, and invoice recognition. With the development of deep learning technology, the accuracy and speed of OCR have been significantly improved, providing a powerful tool for automated text processing.

[0003] In existing technologies, OCR models are prone to errors when dealing with multilingual samples. For example, a missing English character, Arabic numeral, or punctuation mark might be mistakenly identified as text. Specifically, Chinese OCR datasets often contain characters from other languages, most commonly English, numbers, and punctuation. The conversion of these non-Chinese characters frequently leads to OCR errors, and current training set construction methods often only focus on the distribution features of Chinese characters. Therefore, how to represent and optimize the language feature distribution of Chinese OCR datasets to improve the recognition accuracy of OCR models for multilingual samples is a technical problem that needs to be solved. Summary of the Invention

[0004] The purpose of this invention is to overcome the shortcomings of the prior art and provide a training set optimization method, device and storage medium. It represents the language features of the dataset through multiple dimensions and proposes a vector space representation method that is suitable for solving the language problem of OCR. It can reduce the high-dimensional semantic features to a finite vector space and use the vector space to compare the differences between the training set and the test set to guide the optimization of the training set.

[0005] To achieve the above objectives, the present invention is implemented using the following technical solution:

[0006] In a first aspect, the present invention provides a training set optimization method, comprising:

[0007] Obtain the test set and training set for training the OCR model;

[0008] For the test set and training set, distinguish between pure language entries and mixed language entries;

[0009] For the pure language entries and the mixed language entries, feature representations for the pure language entries and the mixed language entries are constructed respectively;

[0010] Based on the feature representations of the pure language entries and the feature representations of the mixed language entries, the feature distribution differences between the test set and the training set are constructed.

[0011] Optimize the training set based on the differences in feature distribution between the test set and the training set.

[0012] Furthermore, both the test set and the training set include multiple terms, each term containing any one or more of the following: Chinese characters, English characters, Arabic numerals, and punctuation marks.

[0013] Furthermore, the step of distinguishing between pure language terms and mixed language terms for the test set and training set includes:

[0014] Identify the test and training sets;

[0015] During recognition, English, numbers, Chinese characters and symbols are identified in the string. If a word contains at least two of the following: Chinese, numbers, English, and punctuation, it is classified as a mixed language word; otherwise, it is a pure language word.

[0016] The mixed-language entries are those containing at least two of the following: Chinese, numbers, English, and punctuation. Pure-language entries are those containing only Chinese, only numbers, or only English.

[0017] Furthermore, for the aforementioned pure language terms, a feature representation of the pure language terms is constructed, including:

[0018] For Chinese terms, a feature representation based on term length is constructed. For English and Arabic numerals, a feature representation combining term length and consecutive repeating characters is constructed. Specifically:

[0019] For purely language-specific entries, the percentage (P) of each type of entry was statistically analyzed. pc P pe P pd ) and frequency of occurrence (Count) pc , Count pe , Count pd ), where P pc P represents the proportion of purely Chinese terms in the dataset. pe P represents the percentage of purely English text in the dataset. pd This indicates the proportion of purely numeric terms in the dataset;

[0020] For Chinese terms, considering term length as a feature, the resulting feature distribution vector is expressed as follows:

[0021] V p-chn =[w pc-1 w pc-2 , ..., w pc-N(1)

[0022] In formula (1), N is the maximum word length in the training or test set, and w pc-i This represents the proportion of purely Chinese entries of length i, calculated as follows:

[0023]

[0024] In formula (2), Count pc Count of purely Chinese entries pc-i The number of purely Chinese entries of a certain length;

[0025] For entries consisting solely of English letters and numbers, a feature representation is constructed that combines the entry length with consecutive repeating characters. The specific method is as follows:

[0026] First, the length feature vector is represented by the following formula:

[0027] V p-digv1 =[w pd-1 w pd-2 , ..., w pd-N (3)

[0028] In formula (3), V p-digv1 Represented as a length feature vector, w pd-i The percentage of purely numeric terms with a numeric degree of i is represented by:

[0029]

[0030] In formula (4), Count pd For the number of purely numeric terms, Count pd-i This represents the number of purely numeric terms of length i.

[0031] Next, we add statistics on repeated characters to further refine the feature vector:

[0032] V p-digv2 =[w pd-2-* w pd-2-0 w pd-2-1 , ..., w pd-N-9 (5)

[0033] In formula (5), V p-digv2 This is represented as the feature distribution vector of purely numeric terms, where * indicates no repeated numeric terms, and w is... pd-2-* w represents the percentage of terms with a length of 2 that are not repeated numerical terms. pd-2-0 w represents the percentage of entries with a length of 2 and an Arabic numeral value of 0. pd-N-9This represents the percentage of entries with a length of N and an Arabic numeral of 9.

[0034] When the number is 1, the new percentage is calculated as follows:

[0035]

[0036] In formula (6), W pd-i-1 Represented as the percentage of terms of length i with a repeated numeric value of 1, Count pd-i-1 Count represents the number of terms of length i with a repeating numeric value of 1. pd-i w represents the number of purely numeric terms of length i. pd-i This represents the percentage of purely numeric terms with a numeric degree of i.

[0037] Similarly, the feature vector representation of a purely English term is:

[0038] V p-eng =[w pe-1-* w pe-1-a w pd-1-b , ..., w pd-N-z (7)

[0039] In formula (7), w pe-1-* This represents the percentage of entries with a length of 1 and no repeated English words. pe-1-a This represents the percentage of entries with a length of 1 and repeating the English word "a". Correspondingly, w pd-N-z This represents the percentage of entries with a length of N and repeating the English word 'z'; the corresponding new subscripts for the English words are aZ, totaling 52 uppercase and lowercase letters, plus *.

[0040] Furthermore, for the aforementioned mixed-language entries, a feature representation of the mixed-language entries is constructed, including: a feature representation of the proportion of different languages ​​in the entries and a feature representation of the language conversion order;

[0041] The method for constructing the language proportion feature representation of the term is as follows:

[0042] The proportion of different languages ​​in the entries is classified according to predetermined matching rules;

[0043] After classification, the vector representation of the language proportion feature is as follows:

[0044] V mixv1 =[w c-1 w c-2 , ...w c-16 (8)

[0045] In formula (8), w c-i This is represented as the percentage of type i among mixed-language entries:

[0046]

[0047] In formula (9), Count mix Count represents the number of entries across all mixed languages. c-i The number of entries of the above types;

[0048] The vector representing the language proportion feature is further divided based on the term length. The term length can be divided into four intervals: 0-5, 5-10, 10-20, and >20. The vector representation is then refined using these intervals.

[0049] V mixv2 =[w c-1-A w c-1-B w c-1-C w c-1-D w c-2-A , ...w c-16-D (10)

[0050] In formula (10), w c-1-A This represents the percentage of entries of type 1 with a length of A among all mixed-language entries; correspondingly, w c-16-D This represents the percentage of entries of type sixteen with length range D among all mixed-language entries. The subscripts A, B, C, and D correspond to the four length ranges mentioned above, and their calculation method is as follows:

[0051]

[0052] In formula (11), w c-i-A This represents the percentage of entries of type i with a length of interval A among all mixed-language entries, Count. c-i-A Count represents the number of terms of type i with a length of interval A. c-i w represents the number of terms of type i. c-i The proportion of type i in mixed-language entries;

[0053] The method for constructing the language conversion order feature representation is as follows:

[0054] By introducing language conversion order features, a one-dimensional vector is transformed into a two-dimensional feature matrix, which is represented as follows:

[0055]

[0056] In formula (12), M mix Represented as a language conversion order feature matrix, for the element in the first instance of the first row of this matrix... The superscript c4-e1 represents the conversion from Chinese character -4 to English character -1, that is, the conversion from four Chinese characters to one English character. This applies to the element in the first example of the second row of the matrix. The superscript c4-d1 represents the conversion of four Chinese characters into a single numerical character. This is for the element in the first example of the third row of the matrix. The superscript c4-s1 represents the conversion of four Chinese characters into a single punctuation mark. This is for the element in the first example of the fifth row of the matrix. The superscripts e1-c2 represent the conversion from one English character to two Chinese characters. Correspondingly, the remaining elements of the matrix are interpreted according to the above rules.

[0057] in, In the element, w is calculated as follows:

[0058]

[0059] In formula (13), w c-i-A This represents the percentage of entries of type i with a length of interval A among all mixed-language entries, Count. c-i-A This represents the number of terms of type i with a length of interval A. Represented as in Count c-i-A Among the entries, the number of Chinese words with four characters long that were converted to English words with one character long;

[0060] In the language conversion order feature matrix mentioned above, if certain percentage features do not have corresponding conversion features, the probability of the corresponding position in the matrix is ​​recorded as 0.

[0061] Furthermore, the construction of the feature distribution difference between the test set and the training set based on the feature representations of the pure language entries and the feature representations of the mixed language entries includes:

[0062] First, regarding the feature distribution vector V of pure Chinese character entries... p-chn Weighted average:

[0063] V p-chnw =P pc *V p-chn (14)

[0064] In formula (14), V p-chn P represents the feature distribution vector of pure Chinese characters. pc V represents the percentage of purely Chinese terms in the dataset. p-chnw This represents the weighted feature distribution vector of pure Chinese characters;

[0065] For the feature distribution vector V of pure English words p-engWeighted average:

[0066] V p-engw =P pe *V p-eng (15)

[0067] In formula (15), V p-eng P represents the feature distribution vector of purely English terms. pe V represents the percentage of purely English terms in the dataset. p-engw This represents the feature distribution vector of pure English terms after weighting.

[0068] For the feature distribution vector V of pure numeric terms p-digv2 Weighted average:

[0069] V p-digv2w =P pd *V p-digv2 (16)

[0070] In formula (16), P pd This represents the percentage of purely numeric terms in the dataset.

[0071] Then, weighting is performed on the feature representations of mixed-language terms:

[0072] M mixw =P mix *M mix (17)

[0073] In formula (17), P mix M represents the proportion of mixed-language terms in the dataset. mixw It is represented as a weighted language conversion order feature matrix;

[0074] The feature representation of the weighted mixed-language terms is then flattened into a one-dimensional vector:

[0075] V mixw =Flatten(M) mixw (18)

[0076] Next, concatenate all the weighted features mentioned above:

[0077] V feature =Concat(V p-chnw V p-engw V p-digv2w V mixw (19)

[0078] In formula (19), V feature The vector V represents the distribution information of all language features in the dataset. featureThe length is M;

[0079] Finally, assume V feature-A Let V be the feature vector of training set A. feature-B Given the feature vectors of test set B, the difference in language feature distributions between A and B can be represented by KL divergence:

[0080]

[0081] KL (A||B) The smaller the value, the smaller the distribution difference of the dataset.

[0082] Furthermore, optimizing the training set based on the feature distribution differences between the test set and the training set includes:

[0083] To optimize the training set, we repeatedly add data with a certain feature to it. Assume that in one optimization iteration, the cardinality of the added data is U. Using KL... (A||B) Control the cardinality U; if the KL divergence is larger, the data distribution difference is greater, and more data needs to be added.

[0084] Based on the differences in feature terms between datasets, determine the amount of data to be added for different feature terms:

[0085]

[0086] If a feature in training set B is greater than the corresponding feature in training set A, then do not add data for that feature.

[0087] In a second aspect, the present invention provides a training set optimization apparatus, comprising:

[0088] The acquisition module is used to acquire the test set and training set for training the OCR model;

[0089] A segmentation module is used to distinguish between pure language entries and mixed language entries for the test set and the training set;

[0090] The first construction module is used to construct feature representations for the pure language entries and the mixed language entries, respectively.

[0091] The second construction module is used to construct the feature distribution difference between the test set and the training set based on the feature representation of the pure language entries and the feature representation of the mixed language entries.

[0092] An optimization module is used to optimize the training set based on the differences in feature distribution between the test set and the training set.

[0093] Thirdly, the present invention provides an electronic device, including a processor and a storage medium;

[0094] The storage medium is used to store instructions;

[0095] The processor is configured to operate according to the instructions to perform the steps of the method according to any of the preceding claims.

[0096] 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.

[0097] Compared with the prior art, the beneficial effects achieved by the present invention are as follows:

[0098] This invention provides a training set optimization method, apparatus, and storage medium. The method can reduce high-dimensional semantic features to a finite vector space, and use the vector space to compare the differences between the test set and the training set to guide the optimization of the training set. The optimized training set can better improve the recognition accuracy of the OCR model for multilingual mixed samples. Attached Figure Description

[0099] Figure 1 This is a flowchart of a training set optimization method provided in an embodiment of the present invention.

[0100] Figure 2 This is a block diagram of a training set optimization device provided in an embodiment of the present invention.

[0101] Figure 3 This is a block diagram of an electronic device provided in an embodiment of the present invention. Detailed Implementation

[0102] 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.

[0103] Example 1

[0104] This embodiment introduces a training set optimization method, including:

[0105] Obtain the test set and training set for training the OCR model;

[0106] For the test set and training set, distinguish between pure language entries and mixed language entries;

[0107] For the pure language entries and the mixed language entries, feature representations for the pure language entries and the mixed language entries are constructed respectively;

[0108] Based on the feature representations of the pure language entries and the feature representations of the mixed language entries, the feature distribution differences between the test set and the training set are constructed.

[0109] Optimize the training set based on the differences in feature distribution between the test set and the training set.

[0110] The training set optimization method provided in this embodiment involves the following steps in its application:

[0111] Step S100: Obtain the test set and training set for OCR model training.

[0112] Both the test set and the training set contain multiple terms, each of which may contain Chinese characters, English characters, Arabic numerals, punctuation marks, or a combination thereof.

[0113] Step S200: Based on the above test set and training set, distinguish between pure language entries and mixed language entries.

[0114] In this embodiment, a pure language term is represented as a term containing only Chinese characters, a term containing only numbers, or a term containing only English characters.

[0115] In this embodiment, a mixed-language term is a term that contains at least two of the following: Chinese, numbers, English, and punctuation. For example, Chinese plus punctuation constitutes a mixed-language term.

[0116] Specifically, different languages ​​have different written symbol features, affecting the recognition performance of OCR. In OCR recognition where Chinese is the primary language, the large proportion of pure Chinese words in the training set often leads to recognition gaps in other language words, such as missing phone numbers; or recognition gaps in language-converted words, such as missing punctuation in Chinese characters. Therefore, it is necessary to analyze the language distribution of the data set, starting with distinguishing between the number of pure language words and mixed language words.

[0117] Furthermore, based on the purity of the language, it can be divided into pure language entries and mixed language entries. Specifically, in this embodiment, the classification method utilizes the regular expression matching library in Python to automatically distinguish between pure language entries and mixed language entries on the test and training sets. That is, it identifies English letters, numbers, Chinese characters, and symbols in the string. If an entry contains at least two of the following: Chinese characters, numbers, English letters, and punctuation, it is classified as a mixed language entry; otherwise, it is a pure language entry.

[0118] In addition to using regular expression matching to identify mixed-language and pure-language entries, you can also use:

[0119] Classifiers based on machine learning or deep learning, for example, can be trained using a pre-labeled training set to classify languages. These classifiers can be convolutional neural networks (CNNs) or recurrent neural networks (RNNs).

[0120] Existing natural language processing API services can be called to analyze the corpus.

[0121] A transformer-based language model can also be used to classify mixed-language terms and pure-language terms.

[0122] Because the methods for feature extraction and dimensionality reduction differ between pure languages ​​and mixed languages, we will discuss the dimensionality reduction of language features from two perspectives below.

[0123] Step S300: For pure language entries, construct their feature representations. For Chinese entries, construct a feature representation based on the entry length. For English and Arabic numerals, construct a feature representation based on the entry length combined with consecutive repeating characters.

[0124] First, for purely language-based entries, such as Chinese, English, and numerical entries, the percentage (P) of each type of entry was calculated. pc ,P pe ,P pd ) and frequency of occurrence (Count) pc ,Count pe ,Count pd ), where P pc P represents the proportion of purely Chinese terms in the dataset. pe P represents the percentage of purely English text in the dataset. pd This indicates the proportion of purely numeric terms in the dataset.

[0125] Then, for Chinese entries, only entry length needs to be considered as a feature; because character frequency cannot be used as a feature. Specifically, the number of Chinese characters is too large to be suitable as a feature dimension for dimensionality reduction. In addition, large-scale Chinese corpora contain a sufficient number of Chinese character samples, and the problem of uneven character frequency rarely occurs. Therefore, the feature distribution vector for pure Chinese characters can be represented as:

[0126] V p-chn =[w pc-1 ,w pc-2 ,…,w pc-N (1)

[0127] In formula (1), N is the maximum term length in the entire dataset (training set or test set; the datasets referred to below have the same meaning and will not be elaborated further), and w pc-i This represents the proportion of purely Chinese entries of length i, calculated as follows:

[0128]

[0129] In formula (2), Count pc Count of purely Chinese entries pc-iThis represents the number of purely Chinese entries of a certain length.

[0130] For entries consisting solely of English letters and numbers, in addition to considering the entry length, the frequency of character repetition also needs to be taken into account; for example, in the entry '13000294596', 0 appears three times consecutively. In OCR recognition of numbers / English letters, because the image space occupied by numbers / quoted characters is relatively small, both the image column occupied by a single character in a CRNN and the image patch based on a VIT network are smaller (compared to Chinese characters). This can lead to the loss of recognition of separators, resulting in the deletion of consecutive repeated characters in CTC, thus missing repeated numbers or letters in the results.

[0131] Taking numeric terms as an example, '00' is recorded as 0 appearing once, and '000' is recorded as 0 appearing twice. In fact, we only need to count the number of separators between the same characters to get the frequency of recurrence of the above characters.

[0132] In this embodiment, a feature representation combining term length and consecutive repeating characters can be constructed using the following method:

[0133] The first thing to be characterized is the length feature vector:

[0134] V p-digv1 =[w pd-1 ,w pd-2 ,…,w pd-N (3)

[0135] In formula (3), V p-digv1 Represented as a length feature vector, w pd-i The percentage of purely numeric terms with a numeric degree of i is represented by:

[0136]

[0137] In formula (4), Count pd For the number of purely numeric terms, Count pd-i This represents the number of purely numeric terms of length i.

[0138] Next, we add statistics on repeated characters to further refine the feature vector:

[0139] V p-digv2 =[w pd-2-* ,w pd-2-0 ,w pd-2-1 ,…,w pd-N-9 (5)

[0140] In formula (5), V p-digv2This is represented as the feature distribution vector of pure numeric terms, which is the vector after considering consecutive repeating characters for V. p-digv1 The subdivided feature vectors, in w pd-2 The subscripts include numbers 0-9 and *, indicating no repeated digits. Specifically, in the formula, w pd-2-* w represents the percentage of terms with a length of 2 that are not repeated numerical terms. pd-2-0 This represents the percentage of entries with a length of 2 and an Arabic numeral value of 0. Correspondingly, w pd-N-9 This represents the percentage of entries with a length of N and an Arabic numeral of 9.

[0141] Taking the number 1 as an example, the new percentage is calculated as follows:

[0142]

[0143] In formula (6), w pd-i-1 Represented as the percentage of terms of length i with a repeated numeric value of 1, Count pd-i-1 Count represents the number of terms of length i with a repeating numeric value of 1. pd-i w represents the number of purely numeric terms of length i. pd-i This represents the percentage of purely numeric terms with a numeric degree of i.

[0144] Similarly, the feature vector of pure English terms can be refined as follows:

[0145] V p-eng =[w pe-1-* ,w pe-1-a ,w pd-1-b ,…,w pd-N-z (7)

[0146] In formula (7), w pe-1-* This represents the percentage of entries with a length of 1 and no repeated English words. pe-1-a This represents the percentage of entries with a length of 1 and repeating the English word "a". Correspondingly, w pd-N-z This represents the percentage of entries with a length of N and a repeated English word of z.

[0147] The new subscripts for English are aZ, a total of 52 uppercase and lowercase letters, and *.

[0148] Step S400: For mixed-language entries, construct their feature representations, including: the feature representation of the proportion of languages ​​in the entry and the feature representation of the language conversion order.

[0149] Based on the language proportion characteristics of the entries, the following methods can be used to construct them:

[0150] Specifically, a term may be dominated by one language, such as a short Chinese phrase containing only one comma; a term may also be dominated by two languages, such as date information. The distribution characteristics of dominant and non-dominant languages ​​affect the recognition ability of the OCR model in language switching situations, so it is necessary to characterize the proportion of languages.

[0151] The proportion characteristics here are classified manually, and the classification criteria are shown in Table 1:

[0152]

[0153]

[0154]

[0155] Table 1. Language Proportion Classification

[0156] Classification rules:

[0157] Punctuation will not be the dominant language; it will be categorized under other types.

[0158] When there are only two language types, with no other types accounting for a percentage.

[0159] When there are two or more language types, the other types include all languages ​​that are not the dominant language.

[0160] Type 16 is an exception to the first 15 types.

[0161] Based on the above classification, the vector representation of the language proportion feature is as follows:

[0162] V mixv1 =[w c-1 ,w c-2 ,…w c-16 (8)

[0163] In formula (8), w c-i This is represented as the percentage of type i among mixed-language entries:

[0164]

[0165] In formula (9), Count mix Count represents the number of entries across all mixed languages. c-i This represents the number of entries of the above types.

[0166] The vector representing the language proportion feature is further divided based on the term length. In this implementation, the term length can be divided into four intervals: 0-5, 5-10, 10-20, and >20. The vector representation is refined using these intervals.

[0167] V mixv2 =[wc-1-A ,w c-1-B w c-1-C w c-1-D w c-2-A ,…w c-16-D (10)

[0168] In formula (10), w c-1-A This represents the percentage of entries of type 1 with a length of A among all mixed-language entries; correspondingly, w c-16-D This represents the percentage of entries of type sixteen with length range D among all mixed-language entries. The newly added subscripts A, B, C, and D correspond to the four length ranges mentioned above, and their calculation method is as follows:

[0169]

[0170] In formula (11), w c-i-A This represents the percentage of entries of type i with a length of interval A among all mixed-language entries, Count. c-i-A Count represents the number of terms of type i with a length of interval A. c-i w represents the number of terms of type i. c-i The proportion of type i in mixed-language entries.

[0171] The language conversion sequence feature can be constructed using the following method:

[0172] Based on the language proportion characteristics, we can further introduce language conversion order features, transforming the one-dimensional vector into a two-dimensional feature matrix. The language conversion order features consist of two aspects: the language being converted and the length of the language characters before and after the conversion. For example, the conversion feature of the term 'date 20120326' is represented as: Chinese - 2 → Number - 8.

[0173] Language proportion feature vector V mixv2 Each category contains multiple transformation combinations, and the number of combinations varies from category to category. For example, in the Chinese-dominated w c-1-B In Chinese, the total character length is limited to 10, and possible combinations include Chinese characters - 8 → numbers - 2, Chinese characters - 8 → English characters - 2, Chinese characters - 4 → English characters - 2, etc.; while for the Chinese-dominated w... c-1-C The total character length is limited to 15, and it may have more combination types, such as Chinese characters - 10 → numbers - 2, numbers - 3 → Chinese characters 7, etc. As the character limit increases, the number of combination types will also increase.

[0174] This implementation requires a sufficient number of conversion features, but not an unlimited number. Therefore, class D (character length greater than 20) and class C have the same combination type. Additionally, it's important to note that this implementation only considers feature conversions between two languages, not more than two, such as calculating the probability of Chinese -10 → number -2 → Chinese 3. This is because OCR errors only affect the information before and after language conversion; the number of language conversions or the language conversion sequence are not necessarily related. Therefore, this implementation only considers feature conversions between two languages.

[0175] After incorporating language conversion features, the feature matrix is ​​represented as follows:

[0176]

[0177] In formula (12), M mix Represented as a language conversion order feature matrix, for the element in the first instance of the first row of this matrix... The superscript c4-e1 represents the conversion from Chinese character -4 to English character -1, that is, the conversion from four Chinese characters to one English character. This applies to the element in the first example of the second row of the matrix. The superscript c4-d1 represents the conversion of four Chinese characters into a single numerical character. This is for the element in the first example of the third row of the matrix. The superscript c4-s1 represents the conversion of four Chinese characters into a single punctuation mark. This is for the element in the first example of the fifth row of the matrix. The superscripts e1-c2 represent the conversion from one English character to two Chinese characters. Correspondingly, the remaining elements of the matrix are interpreted according to the above rules.

[0178] by Taking an element as an example, w is calculated as follows:

[0179]

[0180] In formula (13), w c-i-A This represents the percentage of entries of type i with a length of interval A among all mixed-language entries, Count. c-i-A This represents the number of terms of type i with a length of interval A. Represented as in Count c-i-A Among the entries, there are those that convert four-character Chinese words to one-character English words.

[0181] It should be noted that in the language conversion order feature matrix mentioned above, some proportion features do not have corresponding conversion features, such as w c-1-BIf the transformation from Chinese character -10 to number -2 is not present, then the probability of the corresponding position in the matrix is ​​recorded as 0.

[0182] Step S500: Based on the feature representations of pure language entries and mixed language entries mentioned above, construct the feature distribution differences between the test set and the training set.

[0183] First, regarding the feature distribution vector V of pure Chinese character entries... p-chn Weighted average:

[0184] V p-chnw =P pc *V p-chn (14)

[0185] In formula (14), V p-chn P represents the feature distribution vector of pure Chinese characters. pc V represents the percentage of purely Chinese terms in the dataset. p-chnw This represents the feature distribution vector of pure Chinese characters after weighting.

[0186] For the feature distribution vector V of pure English words p-eng Weighted average:

[0187] V p-engw =P pe *V p-eng (15)

[0188] In formula (15), V p-eng P represents the feature distribution vector of purely English terms. pe V represents the percentage of purely English terms in the dataset. p-engw This represents the feature distribution vector of pure English terms after weighting.

[0189] For the feature distribution vector V of pure numeric terms p-digv2 Weighted average:

[0190] V p-digv2w =P pd *V p-digv2 (16)

[0191] In formula (16), P pd This represents the percentage of purely numeric terms in the dataset.

[0192] Then, weighting is performed on the feature representations of mixed-language terms:

[0193] M mixw =P mix *M mix (17)

[0194] In formula (17), Pmix M represents the proportion of mixed-language terms in the dataset. mixw It is represented as a weighted language conversion order feature matrix.

[0195] The feature representation of the weighted mixed-language terms is then flattened into a one-dimensional vector:

[0196] V mixw =Flatten(M) mixw (18)

[0197] Next, concatenate all the weighted features mentioned above:

[0198] V feature =Concat(V p-chnw V p-engw V p-digv2w V mixw (19)

[0199] In formula (19), V feature The vector V represents the distribution information of all language features in the dataset. feature The length is M.

[0200] Finally, assume V feature-A Let V be the feature vector of training set A. feature-B Given the feature vectors of test set B, the difference in language feature distributions between A and B can be represented by KL divergence:

[0201]

[0202] KL (A||B) The smaller the value, the smaller the distribution difference of the dataset.

[0203] Step S600: Optimize the training set based on the feature distribution differences between the test set and the training set.

[0204] In this implementation, it is necessary to add data with a certain feature to the training set to optimize it. The optimization process often requires multiple data additions. Assume that in a certain optimization, the cardinality of the added data is U, and KL... (A||B) Control the cardinality U; if the KL divergence is larger, the data distribution difference is greater, and more data needs to be added.

[0205] Based on the differences in feature terms between datasets, determine the amount of data to be added for different feature terms:

[0206]

[0207] If a feature in training set B is greater than the corresponding feature in training set A, then do not add data for that feature.

[0208] Example 2

[0209] This embodiment provides a training set optimization device, including:

[0210] The acquisition module is used to acquire the test set and training set for training the OCR model;

[0211] A segmentation module is used to distinguish between pure language entries and mixed language entries for the test set and the training set;

[0212] The first construction module is used to construct feature representations for the pure language entries and the mixed language entries, respectively.

[0213] The second construction module is used to construct the feature distribution difference between the test set and the training set based on the feature representation of the pure language entries and the feature representation of the mixed language entries.

[0214] An optimization module is used to optimize the training set based on the differences in feature distribution between the test set and the training set.

[0215] Example 3

[0216] This embodiment provides an electronic device, including a processor and a storage medium;

[0217] The storage medium is used to store instructions;

[0218] The processor is configured to operate according to the instructions to perform the steps of the method according to any one of Embodiment 1.

[0219] Example 4

[0220] 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.

[0221] 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 optimization method, characterized by, The method comprises the following steps: Obtain a test set and a training set for OCR model training; Distinguish pure language entries from mixed language entries for the test set and the training set, comprising: Identify the test set and the training set; During identification, identify English, numbers, Chinese characters and symbols in the string, and if a certain entry has at least two of Chinese, numbers, English and punctuation, it is classified as a mixed language entry, otherwise it is a pure language entry; Wherein, the mixed language entry is an entry with at least two of Chinese, numbers, English and punctuation, and the pure language entry is represented by an entry with only Chinese, only numbers and only English; For the pure language entries and the mixed language entries, respectively construct the feature representation of the pure language entries and the mixed language entries, comprising: For Chinese entries, construct a feature representation based on entry length, and for English and Arabic numbers, construct a feature representation based on entry length combined with consecutive repeated characters, specifically: For pure language entries, the proportion of each entry is calculated ( , , ) and the frequency of occurrence ( , , ), wherein represents the proportion of pure Chinese entries in the data set, represents the proportion of pure English in the data set, represents the proportion of pure digital entries in the data set;​​ For Chinese entries, consider the length of the entry as a feature, and the obtained feature distribution vector is represented as: ; In formula (1), the maximum word length of the training set or the test set, represents the proportion of words with a length of in the pure Chinese word, and the calculation method is: ; In formula (2), the number of pure Chinese word entries, is the number of pure Chinese word entries of a certain length; For pure English and number entries, construct a feature representation based on entry length combined with consecutive repeated characters, and the specific method is as follows: First, represent the length feature vector, and the formula is as follows: ; In formula (3), Represented as a length feature vector, This indicates that the numeric degree of purely numeric terms is... The percentage is calculated as follows: ; In equation (4), is the number of pure digital terms, is the number of pure digital terms with length is the number of pure digital terms with length Then, add the statistics of repeated characters to subdivide the feature vector: ; In formula (5), characteristic distribution vector represented as pure digital entries, * represents no repeated digital items, in which represented as the proportion of entries with a length of 2 and not repeated digital items, represented as the proportion of entries with a length of 2 and Arabic numerals as 0, represented as the proportion of entries with a length of N and Arabic numerals as 9; When the number is 1, the calculation method of the new proportion is as follows: ; In formula (6), represents the proportion of the word entry with the length of i and the repeated number of 1, represents the number of the word entry with the length of i and the repeated number of 1, represents the number of the pure number word entry with the length of represents the proportion of the pure number word entry with the number degree of .​ Similarly, the feature vector of pure English entry is represented as: ; In formula (7), represents the proportion of the word entry with a length of 1 and without repeated English, represents the proportion of the word entry with a length of 1 and repeated English a, and the corresponding represents the proportion of the word entry with a length of N and repeated English z; the corresponding new subscript of English is a-Z, a total of 52 uppercase and lowercase letters and *. Based on the feature representation of the pure language entries and the feature representation of the mixed language entries, construct the feature distribution difference of the test set and the training set; Optimize the training set according to the feature distribution difference of the test set and the training set.

2. The training set optimization method of claim 1, wherein, The test set and the training set each include a plurality of entries, each entry having any one or more of Chinese, English, Arabic numbers, and punctuation marks.

3. The training set optimization method of claim 1, wherein, For the mixed language entries, construct a feature representation of the mixed language entries, comprising a language proportion feature representation and a language conversion order feature representation; The construction method of the language proportion feature representation is as follows: Classify the proportion feature of the entry language according to a predetermined matching rule; After classification, the vector representation of the language proportion feature is: ; In formula (8), The proportion of the type of the mixed language term is represented as the proportion of the type of the mixed language term ; In equation (9), is the number of word entries of all mixed languages, is the number of word entries of the above type; Further divide the vector of the language proportion feature according to the length of the entry, and the length of the entry can be divided into: 0-5, 5-10, 10-20, and >20, which are four intervals. Utilize the representation of interval refinement vector: ; In formula (10), The proportion of the word in the A interval of the first type in all mixed language words, and the corresponding, The proportion of the word in the A interval of the sixteenth type in all mixed language words, and the corresponding, The proportion of the word in the A interval of the sixteenth type in all mixed language words, and the corresponding, ; In formula (11), the proportion of the word of the i-th type and the word length in the A interval in all mixed language words, the number of words of the i-th type and the word length in the A interval, the number of words of the i-th type, the proportion of the i-th type in mixed language words; The construction method of the language conversion order feature representation is as follows: Introduce the language conversion order feature to convert the one-dimensional vector into a two-dimensional feature matrix, and the representation of the feature matrix is: ; In formula (12), is expressed as the language conversion order characteristic matrix, for the element of the first row and the first column in the matrix , the superscript represents the conversion from Chinese-4 to English-1, that is, the conversion from four Chinese characters to one English character, for the element of the second row and the first column in the matrix , the superscript is expressed as the conversion from four Chinese characters to one digit, for the element of the third row and the first column in the matrix , the superscript is expressed as the conversion from four Chinese characters to one punctuation symbol, for the element of the fifth row and the first column in the matrix , the superscript is expressed as the conversion from one English character to two Chinese characters, and the rest of the elements in the matrix are explained according to the above rules. wherein, In the element, w is calculated as follows: ; In formula (13), the proportion of the word of the i-th type and the word length of the A interval in all mixed language words, the number of words of the i-th type and the word length of the A interval, the proportion of the word of the i-th type and the word length of the A interval in all mixed language words, the number of words of the i-th type and the word length of the A interval, In the above language conversion order feature matrix, if some proportion features do not have corresponding conversion features, the probability of the corresponding position in the matrix is 0.

4. The training set optimization method of claim 3, wherein, The construction of the feature distribution difference of the test set and the training set based on the feature representation of the pure language entries and the feature representation of the mixed language entries comprises: First, the feature distribution vector of pure Hanzi entries is weighted , and the weighted feature distribution vector is calculated as follows: ; In formula (14), represents the feature distribution vector of pure Chinese characters, represents the proportion of pure Chinese entries in the data set, represents the feature distribution vector of pure Chinese characters after weighting; Feature distribution vector for pure english terms , performing weighting: ; In formula (15), represents the feature distribution vector of the pure English entry, represents the proportion of the pure English entry in the data set, represents the feature distribution vector of the pure English entry after weighting; Feature distribution vectors for pure digital terms perform weighting: ; In equation (16), represents the proportion of pure digital entries in the data set; Then, perform weighting on the feature representation of the mixed language entries: ; In equation (17), represents the proportion of mixed language terms in the data set, represents the language conversion sequence feature matrix after weighting; Then, flatten the weighted feature representation of the mixed language entries into a one-dimensional vector: ; Then, concatenate all the weighted features together: ; In equation (19), characterizes the distribution information of all language features of the data set, and the vector has a length of M; Finally, assume is the feature vector of the training set A, is the feature vector of the test set B, the difference of the language feature distribution between A and B can be represented by the KL divergence: ; The smaller the value, the smaller the difference in distribution of the data sets.

5. The training set optimization method of claim 4, wherein, The training set is optimized according to the feature distribution difference of the test set and the training set, and the optimization includes: Adding data of a certain feature to the training set multiple times to optimize the training set, assuming that in a certain optimization, the cardinality of the added data is U, and using Control the cardinality U; the greater the KL divergence, the greater the difference in data distribution, and the more data needed to be added; According to the feature item difference between the data sets, the number of data required to be added for different feature items is obtained: ; If a certain feature item in the training set B is greater than the corresponding item in the training set A, the data of the feature item is not added.

6. A training set optimization apparatus employing the training set optimization method according to claim 1, characterized by The method comprises the steps of: An acquisition module is configured to acquire a test set and a training set for OCR model training; A division module is configured to distinguish pure language word entries from mixed language word entries for the test set and the training set; A first construction module is configured to construct feature representations of pure language word entries and mixed language word entries respectively for the pure language word entries and the mixed language word entries; A second construction module is configured to construct a feature distribution difference of the test set and the training set based on the feature representations of the pure language word entries and the mixed language word entries; An optimization module is configured to optimize the training set according to the feature distribution difference of the test set and the training set.

7. An electronic device, comprising: The method comprises a processor and a storage medium. The storage medium is configured to store instructions. The processor is configured to operate according to the instructions to perform the steps of the method according to any one of claims 1-5.

8. 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-5.

Citation Information

Patent Citations

  • Text multilingual recognition method based on feature word weighting

    CN111178009A

  • English pinyin recognition method and system for multi-language mixed text

    CN112528649A