Text recognition method and device based on intersection-over-union loss optimization model
By introducing the crossover loss function in the deep learning model, the text recognition model is optimized to improve the recognition accuracy of specific tags, and the problem of poor recognition effect caused by unbalanced tag distribution in the prior art is solved, and a higher semantic analysis accuracy.
Patent Information
- Application Number
- CN202210437861.0
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2022-04-25
- Publication Date
- 2024-12-13
- Estimated Expiration
- 2042-04-25
AI Technical Summary
The existing deep learning models have limited accuracy in identifying specific tags in text in semantic analysis, mainly because the cross entropy loss function fails to effectively consider the global importance of the tag, resulting in poor recognition of small proportions of specific tags.
Using text recognition method based on the interleaving and ratio loss function, the overlap between the predicted label distribution and the real label distribution is trained as the optimization goal, ensuring that the model pays different attention to different entities during the training process, thereby improving specific The accuracy of the identification of the tag.
It effectively improves the recognition accuracy of labels with specific meanings in the text, avoids the adverse training effect caused by unbalanced label distribution, and optimizes the model's prediction ability.
Smart Images

Figure CN114997153B_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to the field of deep learning technology, and in particular to a text recognition method and device based on an intersection-over-union loss optimization model. Background Art
[0002] With the development of productivity and the advancement of science and technology, consumers have higher and higher requirements for the accuracy and efficiency of information screening, especially in the screening of advertising information. The common method of extracting brand or category information from texts through techniques such as keyword matching can no longer meet user needs well because of its limited scope of application and low accuracy.
[0003] The existing semantic analysis method improves generalization and recognition accuracy by constructing a deep learning model to perform semantic analysis on text information. However, the current optimization of deep learning models is mostly based on the cross-entropy loss function, which only considers loss in a microscopic sense rather than globally. It attaches the same importance to all labels, but for some special texts, since the proportion of label words with specific meanings in the text is often small, this method has limited improvement in semantic recognition accuracy. Therefore, it is particularly important to propose a technical solution for how to improve the recognition accuracy of labels with specific meanings in texts. Summary of the invention
[0004] The technical problem to be solved by the present invention is to provide a text recognition method and device based on an intersection-over-union loss optimization model, which can automatically handle the problem of consistent emphasis on different entities in the semantic analysis process and improve the recognition accuracy of labels with specific meanings in the text.
[0005] In order to solve the above technical problems, the first aspect of the present invention discloses a text recognition method based on an intersection-over-union loss optimization model, the method comprising:
[0006] Determine the text to be predicted;
[0007] The text to be predicted is input into a trained text recognition model to obtain a text feature label corresponding to the text to be predicted; wherein the trained text recognition model is trained based on an intersection-over-union loss function; the intersection-over-union loss function is inversely proportional to the degree of overlap between the predicted label distribution output by the text recognition model during training and the true label distribution of the corresponding training data.
[0008] As an optional embodiment, in the first aspect of the present invention, the numerical value of the overlap between the predicted label distribution output by the text recognition model during training and the true label distribution of the corresponding training data is the ratio of the number of identical representation results in all possible results of the predicted label distribution and all possible results of the true label distribution to the difference between the sum of the number of all possible results of the predicted label distribution and the true label distribution and the number of identical representation results.
[0009] As an optional embodiment, in the first aspect of the present invention, the numerical value of the overlap between the predicted label distribution output by the text recognition model during training and the corresponding true label distribution of the training data is the ratio of the sum of the predicted true products of all training data units of the text recognition model during training to the sum of the first predicted true values of all training data units; the predicted true product is the product of the predicted label value and the true label value of each of the training data units; the first predicted true value is the sum of the predicted label value, the true label value and the predicted true product of each of the training data units.
[0010] As an optional implementation, in the first aspect of the present invention, the numerical value of the overlap between the predicted label distribution output by the text recognition model during training and the corresponding true label distribution of the training data is the ratio of the first correction value of the sum of the predicted true products of all training data units of the text recognition model during training to the second correction value of the sum of the first predicted true values of all training data units; the first correction value is the sum of the sum of the predicted true products and the first correction factor, the second correction value is the sum of the sum of the first predicted true values and the second correction factor, and both the first correction factor and the second correction factor are non-negative numbers; the predicted true product is the product of the predicted label value and the true label value of each of the training data units; the first predicted true value is the sum of the predicted label value, the true label value and the predicted true product of each of the training data units;
[0011] The true label value is zero when the training data unit does not belong to the text feature label.
[0012] As an optional implementation, in the first aspect of the present invention, the trained text recognition model is trained by the following steps:
[0013] Obtaining training data from a plurality of training texts meeting a first preset condition, and training the text recognition model;
[0014] When the text recognition model meets the second preset condition during training, the text recognition model is used as the trained text recognition model.
[0015] As an optional implementation manner, in the first aspect of the present invention, the obtaining of training data from a plurality of training texts that meet the first preset condition comprises:
[0016] For each training text that meets the first preset condition, according to whether each training text unit in the training text belongs to the text feature label and the position, a label corresponding to each training text unit in the training text is generated one by one to obtain a label sequence corresponding to the training text;
[0017] The label sequences corresponding to all the training texts are one-hot encoded to obtain training data.
[0018] As an optional implementation manner, in the first aspect of the present invention, the first preset condition includes:
[0019] The type of the training text is the same as the type of the text to be predicted; and / or,
[0020] The second preset condition includes:
[0021] A value of an intersection-over-union loss function corresponding to current training data in the training data is less than or equal to a set threshold.
[0022] The second aspect of the present invention discloses a text recognition device based on an intersection-over-union loss optimization model, the device comprising:
[0023] A determination module, used for determining the text to be predicted;
[0024] An input module is used to input the text to be predicted into a trained text recognition model to obtain a text feature label corresponding to the text to be predicted; wherein the trained text recognition model is trained based on an intersection-over-union loss function; the intersection-over-union loss function is inversely proportional to the overlap between the predicted label distribution output by the text recognition model during training and the true label distribution of the corresponding training data.
[0025] As an optional embodiment, in the second aspect of the present invention, the numerical value of the overlap between the predicted label distribution output by the text recognition model during training and the true label distribution of the corresponding training data is the ratio of the number of identical representation results in all possible results of the predicted label distribution and all possible results of the true label distribution to the difference between the sum of the number of all possible results of the predicted label distribution and the true label distribution and the number of identical representation results.
[0026] As an optional embodiment, in the second aspect of the present invention, the numerical value of the overlap between the predicted label distribution output by the text recognition model during training and the corresponding true label distribution of the training data is the ratio of the sum of the predicted true products of all training data units of the text recognition model during training to the sum of the first predicted true values of all training data units; the predicted true product is the product of the predicted label value and the true label value of each of the training data units; the first predicted true value is the sum of the predicted label value, the true label value and the predicted true product of each of the training data units.
[0027] As an optional implementation, in the second aspect of the present invention, the numerical value of the overlap between the predicted label distribution output by the text recognition model during training and the corresponding true label distribution of the training data is the ratio of the first correction value of the sum of the predicted true products of all training data units of the text recognition model during training to the second correction value of the sum of the first predicted true values of all training data units; the first correction value is the sum of the sum of the predicted true products and the first correction factor, the second correction value is the sum of the sum of the first predicted true values and the second correction factor, and both the first correction factor and the second correction factor are non-negative numbers; the predicted true product is the product of the predicted label value and the true label value of each of the training data units; the first predicted true value is the sum of the predicted label value, the true label value and the predicted true product of each of the training data units;
[0028] The true label value is zero when the training data unit does not belong to the text feature label.
[0029] As an optional implementation, in the second aspect of the present invention, the device further includes a training module, which is used to perform the following steps to train and obtain the trained text recognition model:
[0030] Obtaining training data from a plurality of training texts meeting a first preset condition, and training the text recognition model;
[0031] When the text recognition model meets the second preset condition during training, the text recognition model is used as the trained text recognition model.
[0032] As an optional implementation, in the second aspect of the present invention, the specific manner in which the training module obtains training data from a plurality of training texts that meet the first preset condition includes:
[0033] For each training text that meets the first preset condition, according to whether each training text unit in the training text belongs to the text feature label and the position, a label corresponding to each training text unit in the training text is generated one by one to obtain a label sequence corresponding to the training text;
[0034] The label sequences corresponding to all the training texts are one-hot encoded to obtain training data.
[0035] As an optional implementation manner, in the second aspect of the present invention, the first preset condition includes:
[0036] The type of the training text is the same as the type of the text to be predicted; and / or,
[0037] The second preset condition includes:
[0038] A value of an intersection-over-union loss function corresponding to current training data in the training data is less than or equal to a set threshold.
[0039] The third aspect of the present invention discloses another text recognition device based on an intersection-over-union loss optimization model, the device comprising:
[0040] A memory storing executable program code;
[0041] a processor coupled to the memory;
[0042] The processor calls the executable program code stored in the memory to execute the text recognition method based on the intersection-over-union loss optimization model disclosed in the first aspect of the present invention.
[0043] The fourth aspect of the present invention discloses a computer-readable storage medium, which stores computer instructions. When the computer instructions are called, they are used to execute the text recognition method based on the intersection-over-union loss optimization model disclosed in the first aspect of the present invention.
[0044] Compared with the prior art, the embodiments of the present invention have the following beneficial effects:
[0045] In an embodiment of the present invention, by determining the text to be predicted, the text to be predicted is input into a trained text recognition model, thereby obtaining a text feature label corresponding to the text to be predicted; wherein the trained text recognition model is trained based on an intersection-over-union loss function; the intersection-over-union loss function is inversely proportional to the overlap between the predicted label distribution output by the text recognition model during training and the true label distribution of the corresponding training data. It can be seen that the implementation of the present invention can use a text recognition model trained and optimized based on the intersection-over-union loss function to identify the text feature label corresponding to the text to be predicted, thereby giving different degrees of importance to different entities in the semantic analysis process, and improving the recognition accuracy of labels with specific meanings in the text. BRIEF DESCRIPTION OF THE DRAWINGS
[0046] In order to more clearly illustrate the technical solutions in the embodiments of the present invention, the following briefly introduces the drawings required for use in the description of the embodiments. Obviously, the drawings described below are only some embodiments of the present invention. For ordinary technicians in this field, other drawings can be obtained based on these drawings without creative work.
[0047] Figure 1 It is a flowchart of a text recognition method based on an intersection-over-union loss optimization model disclosed in an embodiment of the present invention;
[0048] Figure 2 It is a flowchart of another text recognition method based on the intersection-over-union loss optimization model disclosed in an embodiment of the present invention;
[0049] Figure 3 It is a structural schematic diagram of a text recognition device based on an intersection-over-union loss optimization model disclosed in an embodiment of the present invention;
[0050] Figure 4 It is a structural schematic diagram of another text recognition device based on an intersection-over-union loss optimization model disclosed in an embodiment of the present invention;
[0051] Figure 5 It is a structural schematic diagram of another text recognition device based on an intersection-over-union loss optimization model disclosed in an embodiment of the present invention;
[0052] Figure 6 is a schematic diagram of a label matrix disclosed in an embodiment of the present invention;
[0053] Figure 7 is a schematic diagram of a probability distribution disclosed in an embodiment of the present invention;
[0054] Figure 8 is another schematic diagram of a label matrix disclosed in an embodiment of the present invention;
[0055] Fig. 9 It is another probability distribution schematic diagram disclosed in an embodiment of the present invention. DETAILED DESCRIPTION
[0056] In order to enable those skilled in the art to better understand the scheme of the present invention, the technical scheme in the embodiments of the present invention will be clearly and completely described below in conjunction with the drawings in the embodiments of the present invention. Obviously, the described embodiments are only part of the embodiments of the present invention, not all of the embodiments. Based on the embodiments of the present invention, all other embodiments obtained by ordinary technicians in this field without creative work are within the scope of protection of the present invention.
[0057] The terms "first", "second", etc. in the specification and claims of the present invention and the above-mentioned drawings are used to distinguish different objects rather than to describe a specific order. In addition, the terms "including" and "having" and any variations thereof are intended to cover non-exclusive inclusions. For example, a process, method, device, product or end including a series of steps or units is not limited to the listed steps or units, but may optionally include steps or units that are not listed, or may optionally include other steps or units inherent to these processes, methods, products or ends.
[0058] Reference to "embodiments" herein means that a particular feature, structure, or characteristic described in conjunction with the embodiments may be included in at least one embodiment of the present invention. The appearance of the phrase in various places in the specification does not necessarily refer to the same embodiment, nor is it an independent or alternative embodiment that is mutually exclusive with other embodiments. It is explicitly and implicitly understood by those skilled in the art that the embodiments described herein may be combined with other embodiments.
[0059] With the emergence of new deep learning models, traditional semantic analysis methods are gradually being replaced by semantic analysis methods based on deep learning methods. Most of the current deep learning methods are based on the cross entropy loss function to optimize the model, which attaches the same importance to all labels. However, in actual recognition tasks, the proportion of target labels in all text labels is often small, so the advantages of deep learning models are not fully utilized.
[0060] In this context, the present invention discloses a text recognition method and device based on an intersection-over-union loss optimization model, which can give different degrees of importance to different entities during semantic analysis and improve the recognition accuracy of entities with specific meanings in the text. The following are detailed descriptions.
[0061] Embodiment 1
[0062] See also Figure 1 , Figure 1 is a flow chart of a text recognition method based on an intersection-over-union loss optimization model disclosed in an embodiment of the present invention. Figure 1 The described method can be applied to a text processing device, which can be a corresponding processing terminal, processing equipment or processing server, and the server can be a local server or a cloud server, which is not limited in the embodiment of the present invention. Figure 1 As shown, the text recognition method based on the intersection-over-union loss optimization model may include the following operations:
[0063] 101. Determine the text to be predicted.
[0064] Optionally, the text to be predicted may be determined by manual screening or by crawling the text of a specific network address.
[0065] Optionally, the type of the text to be predicted may be an advertisement text, or an online novel or a script text. Preferably, the type of the text to be predicted is an advertisement text. The solution of the present invention has excellent effect in identifying brand words or category words in advertisement texts, because brand words and category words often account for a small proportion in advertisement texts.
[0066] Optionally, the language of the text to be predicted is not limited to Chinese, and may also be other grammatically clear languages such as English and French.
[0067] The present invention does not specifically limit the method for determining the text to be predicted, the type of the text to be predicted, and the language of the text to be predicted.
[0068] 102. Input the text to be predicted into the trained text recognition model to obtain the text feature label corresponding to the text to be predicted.
[0069] The trained text recognition model is trained based on an intersection-over-union loss function. Optionally, the intersection-over-union loss function is inversely proportional to the overlap between the predicted label distribution output by the text recognition model during training and the true label distribution of the corresponding training data.
[0070] Optionally, the trained text recognition model is obtained by minimizing the intersection-over-union loss function until convergence. The text feature label corresponding to the text to be predicted refers to the label in the label of the text to be predicted that meets the recognition target type. For example, if you want to identify the brand and category words in the advertisement text to be predicted, the text feature labels are brand and category.
[0071] Optionally, the degree of overlap between the predicted label distribution output by the text recognition model during training and the true label distribution of the corresponding training data can be represented by the similarity between the predicted label distribution and the true label distribution.
[0072] With this setting, after training the text recognition model, the value of the overlap becomes larger, and the value of the intersection-over-union loss function, which is inversely proportional to the overlap, becomes smaller. If the value of the overlap approaches 1 infinitely, the intersection-over-union loss function converges and the text recognition model training is completed.
[0073] Optionally, the inverse relationship between the intersection-over-union loss function and the overlap degree can be expressed in a variety of ways. For example:
[0074] iou_loss=1-IoU
[0075] Among them, iou_loss represents the intersection-over-union loss function, and IoU represents the overlap between the predicted label distribution and the true label distribution of the corresponding training data.
[0076] Optionally, other representations can be used to express the inverse relationship between the intersection-over-union loss function and the overlap degree, for example:
[0077]
[0078] Among them, iou_loss1 represents the intersection-over-union loss function, IoU1 represents the overlap between the predicted label distribution and the true label distribution of the corresponding training data, and m is a non-negative number.
[0079] Another example: iou_loss2 = -lg(IoU2), IoU2≠0; where iou_loss2 represents the intersection-over-union loss function, and IoU2 represents the degree of overlap between the predicted label distribution and the true label distribution of the corresponding training data.
[0080] The manner of expressing the inverse relationship between the intersection-over-union loss function and the overlap degree is not specifically limited here.
[0081] It can be seen that by implementing this optional implementation, the text recognition model is optimized based on the intersection-and-union loss function. By setting the relationship between the degree of overlap and the intersection-and-union loss function to be inversely proportional, the intersection-and-union loss function directly optimizes the degree of overlap of the two distributions, which can effectively avoid the situation of unbalanced label distribution.
[0082] It can be seen that the implementation of the embodiment of the present invention can utilize the text recognition model trained and optimized based on the intersection-over-union loss function to identify the text feature labels corresponding to the predicted text, thereby giving different degrees of importance to different entities in the semantic analysis process and improving the recognition accuracy of labels with specific meanings in the text.
[0083] In an optional embodiment, the numerical value of the overlap between the predicted label distribution output by the text recognition model during training and the true label distribution of the corresponding training data is the ratio of the number of identical results among all possible results of the predicted label distribution and all possible results of the true label distribution to the difference between the sum of the number of all possible results of the predicted label distribution and the true label distribution and the number of identical results.
[0084] By setting it in this way, the numerical value of the overlap can be used to characterize the overlap between the predicted label distribution and the true label distribution. When the overlap between the two is completely overlapped, it is obvious that the number of all possible results of the predicted label distribution and the number of all possible results of the true label distribution that represent the same result is equal to half of the sum of the number of all possible results of the predicted label distribution and the true label distribution. At this time, the numerical value of the overlap is 1. When the overlap between the two is completely non-overlapping, it is obvious that the number of all possible results of the predicted label distribution and the number of all possible results of the true label distribution that represent the same result is zero, and at this time, the numerical value of the overlap is zero. Obviously, it can be seen from the above that the numerical value of the overlap is proportional to the overlap between the predicted label distribution and the true label distribution.
[0085] It can be seen that this optional embodiment provides a specific calculation method for the degree of overlap, so that the intersection-over-union loss function is directly used to characterize the degree of overlap between the predicted label distribution and the true label distribution. This enables the prediction ability of the model to be optimized by optimizing the loss function during model training optimization, and effectively avoids the adverse training effects caused by the imbalance of label distribution in the existing optimization methods based on cross entropy loss.
[0086] In an optional embodiment, the numerical value of the overlap between the predicted label distribution output by the text recognition model during training and the true label distribution of the corresponding training data is the ratio of the sum of the predicted true products of all training data units of the text recognition model during training to the sum of the first predicted true values of all training data units.
[0087] Specifically, the predicted true product is the product of the predicted label value and the true label value of each training data unit; the first predicted true value is the sum of the predicted label value, the true label value and the predicted true product of each training data unit.
[0088] It can be seen that this optional embodiment provides a specific calculation method for the degree of overlap, so that the intersection-over-union loss function is directly used to characterize the degree of overlap between the predicted label distribution and the true label distribution. This enables the prediction ability of the model to be optimized by optimizing the loss function during model training optimization, and effectively avoids the adverse training effects caused by the imbalance of label distribution in the existing optimization methods based on cross entropy loss.
[0089] In an optional embodiment, the numerical value of the overlap between the predicted label distribution output by the text recognition model during training and the corresponding true label distribution of the training data is the ratio of a first corrected value of the sum of the predicted true products of all training data units of the text recognition model during training to a second corrected value of the sum of the first predicted true values of all training data units.
[0090] Specifically, the first correction value is the sum of the predicted true product and the first correction factor, and the second correction value is the sum of the first predicted true value and the second correction factor; the predicted true product is the product of the predicted label value and the true label value of each training data unit; the first predicted true value is the sum of the predicted label value, the true label value and the predicted true product of each training data unit.
[0091] Specifically, the first correction factor and the second correction factor are both non-negative numbers, and the true label value is zero when the training data unit does not belong to the text feature label.
[0092] Here, compared with the calculation method of the overlap degree in the previous embodiment, a first correction factor and a second correction factor are added to optimize the training process of the text recognition model.
[0093] Specifically, when actually encoding the training data units (such as text words) in the training text, for the case where the true label value is zero when the training data unit does not belong to the text feature label, if there is no first correction factor and second correction factor, the true label value is 0, and the loss function value is 1 at this time, then the training text cannot play a role in minimizing the loss function, so the training text does not contribute to the training process of the text recognition model. Taking this special case into account, the first correction factor and the second correction factor are introduced into the algorithm, so that when the model training optimization is performed through the above-mentioned type of training text, an accurate loss function value can be calculated to help the model to optimize and converge.
[0094] Optionally, both the first correction factor and the second correction factor are non-negative numbers, and the values of the first correction factor and the second correction factor may be the same or different, which is not specifically limited here.
[0095] It can be seen that this optional embodiment provides a specific calculation method for the overlap, so that the intersection-over-union loss function is directly used to characterize the overlap between the predicted label distribution and the true label distribution, so that the prediction ability of the model can be optimized by optimizing the loss function in the model training optimization, and the poor training effect caused by the imbalance of label distribution in the existing optimization method based on cross entropy loss can be effectively avoided. In addition, by introducing the first correction factor and the second correction factor in the calculation process, the situation where negative samples have no effect on the training of the text recognition model and thus reduce the efficiency is avoided, and the training process of the text recognition model is optimized.
[0096] Embodiment 2
[0097] See also Figure 2 , Figure 2 is a flow chart of a text recognition method based on an intersection-over-union loss optimization model disclosed in an embodiment of the present invention. Figure 2The described method can be applied to a text processing device, which can be a corresponding processing terminal, processing equipment or processing server, and the server can be a local server or a cloud server, which is not limited in the embodiment of the present invention. Figure 2 As shown, the text recognition method based on the intersection-over-union loss optimization model may include the following operations:
[0098] 201. Determine the text to be predicted.
[0099] 202. Obtain training data from a plurality of training texts that meet the first preset condition, and train a text recognition model.
[0100] 203. When the text recognition model meets the second preset condition during training, the text recognition model is used as the trained text recognition model.
[0101] 204. Input the text to be predicted into the trained text recognition model to obtain a text feature label corresponding to the text to be predicted.
[0102] The specific technical details and technical terminology of the above steps 201 and 204 can be referred to the description of steps 101-102 in the first embodiment, and will not be repeated here.
[0103] It can be seen that the embodiments of the present invention can increase the probability of the target label type existing in the training text, and enable the trained text recognition model to have a better prediction effect.
[0104] In an optional embodiment, the step 202 of obtaining training data from a plurality of training texts meeting the first preset condition includes:
[0105] For each training text that meets the first preset condition, according to whether each training text unit in the training text belongs to the text feature label and the position, a label corresponding to each training text unit in the training text is generated one by one, and a label sequence corresponding to the training text is obtained;
[0106] Perform one-hot encoding on the label sequences corresponding to all training texts to obtain training data.
[0107] One of the purposes of this optional embodiment is to prevent the categorical variables represented by numerical values from bringing any valueless additional information interference to the deep learning model due to the meaningless relationship between the numerical values. Before establishing the deep learning model, the categorical variables need to be processed by one-hot encoding. Among them, one-hot encoding, as a coding method, is also called one-bit effective encoding, which is the representation of categorical variables as binary vectors. Specifically, the one-hot encoding process can be: first map the categorical value to an integer value, and then represent each integer value as a binary vector, wherein the index of the integer is marked as 1, and all other values except the integer index are zero.
[0108] It can be seen that by implementing this optional embodiment, the label sequence corresponding to the training text can be converted into one-hot encoding, so that the classification of the data is more accurate, and thus the prediction result is more accurate.
[0109] In an optional embodiment, the first preset condition includes: the type of the training text is the same as the type of the text to be predicted.
[0110] Optionally, before the above step 202, the method may further include:
[0111] Determine the type of text to be predicted;
[0112] According to the type of the text to be predicted, a plurality of training texts meeting a first preset condition are determined from a plurality of candidate texts.
[0113] By setting the above steps, a specific operation of selecting training texts from candidate texts is given, that is, the type of the text to be predicted is detected before training, so as to determine the training text that meets the type from the candidate texts according to the type.
[0114] It can be seen that by implementing this optional embodiment, the probability of the target label type existing in the training text can be increased, making the model training effect better.
[0115] In an optional embodiment, the second preset condition includes: a value of an intersection-over-union loss function corresponding to current training data in the training data is less than or equal to a set threshold.
[0116] Here, if the value of the intersection-over-union loss function is less than or equal to the set threshold, it means that the intersection-over-union loss function has converged and the text recognition model training is completed. The value of the set threshold is not specifically limited here.
[0117] It can be seen that by implementing this optional embodiment, the trained text recognition model can have a better prediction effect.
[0118] In a specific implementation scheme of the text recognition method described in the present invention, the training text used to train the text recognition model is "Li Ning swimming goggles, high-definition anti-fog, helping you swim underwater", the brand text feature label in this training text is "Li Ning", and the category text feature label is "swimming goggles". If the target label type is brand and category, the label sequence corresponding to the training text can be expressed as [B-brand, I-brand, B-cate, I-cate, O, O, O, O, O, O, O, O, O, O, O, O], and it can be seen that there are a total of 5 types of labels, namely B-brand, I-brand, B-cate, I-cate and O. Among them, the O label accounts for the majority, but we should actually pay more attention to the first 4 labels. Assume that the correspondence between label name and label id is {B-brand:0,I-brand:1,B-cate:2,I-cate:3,O:4}, then the above labels are expressed in the form of label id as: [0,1,2,3,4,4,4,4,4,4,4,4,4,4,4,4], and after being converted into one-hot encoded labels through one-hot encoding, the training data label is obtained as follows Figure 6 As shown (for ease of display, only the first 5 words are shown).
[0119] Then, the text recognition model is trained. Assume that after the training data is input into the text recognition model, the output predicted label distribution pred is as follows: Figure 7 As shown (same as above, only the first 5 words are shown).
[0120] Then, the sum of the predicted true products of all training data units of the text recognition model during training is 4.6, and the first correction value of the sum of the predicted true products of all training data units during training of the text recognition model is the sum of the sum of the predicted true products and the first correction factor, that is, 4.6+α (α is the correction factor);
[0121] The sum of the first predicted true values of all training data units of the text recognition model during training is 5.4, and the second correction value of the sum of the first predicted true values of all training data units during training of the text recognition model is the sum of the first predicted true values and the second correction factor, that is, 5.4+α (α is the correction factor);
[0122] Thus, the ratio of the first corrected value of the sum of the predicted true products of all training data units of the text recognition model during training to the second corrected value of the sum of the first predicted true values of all training data units, that is, the value of the degree of overlap (coin) between the predicted label distribution output by the text recognition model during training and the corresponding true label distribution of the training data, is obtained, which is (4.6+α) / (5.4+α).
[0123] According to one of the representations that the value of the intersection-over-coin loss function is inversely proportional to the overlap, the value of the intersection-over-coin loss function (dice_loss) is obtained as dice_loss=1-coin=1-(4.6+1) / (5.4+1)=0.1250, where α=1.
[0124] The above process is a training process of the text recognition model through a training text. The above training process is repeated through different training texts until the loss function converges to obtain a trained text recognition model.
[0125] In another specific implementation of the text recognition method described in the present invention, the training text used to train the text recognition model is "Bulgari Eau de Toilette". It can be seen that the brand text feature label in this training text is "Bulgari" and the category text feature label is "perfume". If the target label type is brand and category, the label sequence corresponding to the training text can be expressed as [B-brand, I-brand, I-brand, O, B-cate, I-cate]. The above labels are expressed in the form of label id as: [0, 1, 1, 4, 2, 3]. After being converted into a one-hot encoded label by one-hot encoding, the training data label is obtained as follows: Figure 8 shown.
[0126] Then, the text recognition model is trained. Assume that after the training data is input into the text recognition model, the output predicted label distribution pred is as follows: Fig. 9 shown.
[0127] Then, the sum of the predicted true products of all training data units of the text recognition model during training is 4.7, and the first correction value of the sum of the predicted true products of all training data units during training of the text recognition model is the sum of the sum of the predicted true products and the first correction factor, that is, 4.7+α (α is the correction factor);
[0128] The sum of the first predicted true values of all training data units of the text recognition model during training is 7.3, and the second correction value of the sum of the first predicted true values of all training data units during training of the text recognition model is the sum of the first predicted true values and the second correction factor, that is, 7.3+α (α is the correction factor);
[0129] Thus, the ratio of the first corrected value of the sum of the predicted true products of all training data units of the text recognition model during training to the second corrected value of the sum of the first predicted true values of all training data units, that is, the value of the degree of overlap (coin) between the predicted label distribution output by the text recognition model during training and the corresponding true label distribution of the training data, is obtained, which is (4.7+α) / (7.3+α).
[0130] According to one of the representations that the value of the intersection-over-coin loss function is inversely proportional to the overlap, the value of the intersection-over-coin loss function (dice_loss) is obtained as dice_loss=1-coin=1-(4.7+2) / (7.3+2)=0.2796, where α=2.
[0131] The above process is another training process of the text recognition model through training text. The above training process is repeated with different training texts until the loss function converges to obtain a trained text recognition model.
[0132] Embodiment 3
[0133] See also Figure 3 , Figure 3 is a structural diagram of a text recognition device based on an IoU loss optimization model disclosed in an embodiment of the present invention. The processing device may be a corresponding processing terminal, processing equipment or processing server, and the server may be a local server or a cloud server, which is not limited in the embodiment of the present invention. Figure 3 As shown, the text recognition device based on the intersection-over-union loss optimization model may include:
[0134] A determination module 301 is used to determine the text to be predicted;
[0135] The input module 302 is used to input the text to be predicted into the trained text recognition model to obtain the text feature label corresponding to the text to be predicted.
[0136] Among them, the trained text recognition model is trained based on the intersection-over-union loss function; the intersection-over-union loss function is inversely proportional to the overlap between the predicted label distribution output by the text recognition model during training and the true label distribution of the corresponding training data.
[0137] It can be seen that the implementation Figure 3 In the illustrated embodiment, by determining the cooperation between the module 301 and the input module 302, it is possible to utilize a text recognition model trained and optimized based on an intersection-over-union loss function to identify text feature labels corresponding to the text to be predicted, thereby giving different degrees of importance to different entities during the semantic analysis process and improving the recognition accuracy of labels with specific meanings in the text.
[0138] In an optional embodiment, the numerical value of the overlap between the predicted label distribution output by the text recognition model during training and the true label distribution of the corresponding training data is the ratio of the number of identical results among all possible results of the predicted label distribution and all possible results of the true label distribution to the difference between the sum of the number of all possible results of the predicted label distribution and the true label distribution and the number of identical results.
[0139] It can be seen that by implementing the device described in this optional embodiment, by giving a specific method for calculating the overlap, the intersection-over-union loss function is directly used to characterize the overlap between the predicted label distribution and the true label distribution. This enables the prediction ability of the model to be optimized by optimizing the loss function during model training optimization, thereby effectively avoiding the adverse training effects caused by the imbalance of label distribution in the existing optimization methods based on cross entropy loss.
[0140] In an optional embodiment, the numerical value of the overlap between the predicted label distribution output by the text recognition model during training and the corresponding true label distribution of the training data is the ratio of the sum of the predicted true products of all training data units of the text recognition model during training to the sum of the first predicted true values of all training data units; the predicted true product is the product of the predicted label value and the true label value of each training data unit; the first predicted true value is the sum of the predicted label value, the true label value and the predicted true product of each training data unit.
[0141] It can be seen that by implementing the device described in this optional embodiment, by giving a specific method for calculating the overlap, the intersection-over-union loss function is directly used to characterize the overlap between the predicted label distribution and the true label distribution. This enables the prediction ability of the model to be optimized by optimizing the loss function during model training optimization, thereby effectively avoiding the adverse training effects caused by the imbalance of label distribution in the existing optimization methods based on cross entropy loss.
[0142] In an optional embodiment, the numerical value of the overlap between the predicted label distribution output by the text recognition model during training and the true label distribution of the corresponding training data is the ratio of the first correction value of the sum of the predicted true products of all training data units of the text recognition model during training to the second correction value of the sum of the first predicted true values of all training data units; the first correction value is the sum of the sum of the predicted true products and the first correction factor, the second correction value is the sum of the sum of the first predicted true values and the second correction factor, and both the first correction factor and the second correction factor are non-negative numbers; the predicted true product is the product of the predicted label value and the true label value of each training data unit; the first predicted true value is the sum of the predicted label value, the true label value and the predicted true product of each training data unit;
[0143] The true label value is zero when the training data unit does not belong to the text feature label.
[0144] It can be seen that the device described in this optional embodiment is implemented, by providing a specific calculation method for the overlap, so that the intersection-over-union loss function is directly used to characterize the overlap between the predicted label distribution and the true label distribution, so that the prediction ability of the model can be optimized by optimizing the loss function in the model training optimization, and the poor training effect caused by the imbalance of label distribution in the existing optimization method based on cross entropy loss can be effectively avoided. In addition, by introducing the first correction factor and the second correction factor in the calculation process, the situation where negative samples have no effect on the training of the text recognition model and thus reduce the efficiency is avoided, and the training process of the text recognition model is optimized.
[0145] In an optional embodiment, if Figure 4 As shown, the text recognition device based on the intersection-over-union loss optimization model further includes a training module 303, which is used to perform the following steps to train and obtain a trained text recognition model:
[0146] Obtaining training data from a plurality of training texts meeting the first preset condition, and training the text recognition model;
[0147] When the text recognition model meets the second preset condition during training, the text recognition model is used as the trained text recognition model.
[0148] It can be seen that implementing the device described in this optional embodiment can increase the probability of the target label type existing in the training text, and make the trained text recognition model have better prediction effect.
[0149] In an optional embodiment, if Figure 4 As shown, the specific manner in which the training module 303 obtains training data from a plurality of training texts that meet the first preset condition includes:
[0150] For each training text that meets the first preset condition, according to whether each training text unit in the training text belongs to the text feature label and the position, a label corresponding to each training text unit in the training text is generated one by one, and a label sequence corresponding to the training text is obtained;
[0151] Perform one-hot encoding on the label sequences corresponding to all training texts to obtain training data.
[0152] It can be seen that implementing the device described in this optional embodiment can convert the label sequence corresponding to the training text into a one-hot encoding, so that the classification of the data is more accurate, and thus the prediction result is more accurate.
[0153] In an optional embodiment, the first preset condition includes:
[0154] The type of the training text is the same as the type of the text to be predicted; and / or,
[0155] The second precondition includes:
[0156] The value of the intersection-over-union loss function corresponding to the current training data in the training data is less than or equal to the set threshold.
[0157] It can be seen that implementing the device described in this optional embodiment can increase the probability of the target label type existing in the training text, thereby achieving better model training effect.
[0158] Embodiment 4
[0159] See also Figure 5 , Figure 5 FIG. 1 is a schematic diagram of the structure of another text recognition device based on the intersection-over-union loss optimization model disclosed in an embodiment of the present invention. Figure 5 As shown, the text recognition device based on the intersection-over-union loss optimization model may include:
[0160] A memory 401 storing executable program codes;
[0161] a processor 402 coupled to the memory 401;
[0162] The processor 402 calls the executable program code stored in the memory 401 to execute the steps of the text recognition method based on the intersection-over-union loss optimization model described in the first embodiment of the present invention or the second embodiment of the present invention.
[0163] Embodiment 5
[0164] An embodiment of the present invention discloses a computer program product, which includes a non-transitory computer-readable storage medium storing a computer program, and the computer program is operable to enable a computer to execute the steps of the text recognition method based on the intersection-over-union loss optimization model described in the above embodiment.
[0165] The device embodiments described above are only illustrative, wherein the modules described as separate components may or may not be physically separated, and the components displayed as modules may or may not be physical modules, i.e., they may be located in one place, or they may be distributed on multiple network modules. Some or all of the modules may be selected according to actual needs to achieve the purpose of the scheme of this embodiment. Those of ordinary skill in the art may understand and implement it without creative work.
[0166] Each embodiment in this specification is described in a progressive manner, and the same or similar parts between the embodiments can be referred to each other, and each embodiment focuses on the differences from other embodiments. In particular, for the system embodiment, since it is basically similar to the method embodiment, the description is relatively simple, and the relevant parts can be referred to the partial description of the method embodiment.
[0167] Through the specific description of the above embodiments, those skilled in the art can clearly understand that each implementation method can be implemented by means of software plus a necessary general hardware platform, and of course, it can also be implemented by hardware. Based on such an understanding, the above technical solution can be essentially or partly contributed to the prior art in the form of a software product, and the computer software product can be stored in a computer-readable storage medium, and the storage medium includes a read-only memory (ROM), a random access memory (RAM), a programmable read-only memory (PROM), an erasable programmable read-only memory (EPROM), a one-time programmable read-only memory (OTPROM), an electronically erasable rewritable read-only memory (EEPROM), a compact disc (CD-ROM) or other optical disc storage, magnetic disk storage, magnetic tape storage, or any other computer-readable medium that can be used to carry or store data.
[0168] It should also be noted that the terms "include", "comprises" or any other variations thereof are intended to cover non-exclusive inclusion, so that a process, method, commodity or device including a series of elements includes not only those elements, but also other elements not explicitly listed, or also includes elements inherent to such process, method, commodity or device. In the absence of more restrictions, the elements defined by the sentence "comprises a ..." do not exclude the existence of other identical elements in the process, method, commodity or device including the elements.
[0169] Finally, it should be noted that the text recognition method and device based on the intersection-over-union loss optimization model disclosed in the embodiment of the present invention only discloses a preferred embodiment of the present invention, which is only used to illustrate the technical solution of the present invention, rather than to limit it. Although the present invention has been described in detail with reference to the aforementioned embodiments, those skilled in the art should understand that the technical solutions described in the aforementioned embodiments can still be modified, or some of the technical features therein can be replaced by equivalents. However, these modifications or replacements do not deviate the essence of the corresponding technical solutions from the spirit and scope of the technical solutions of the various embodiments of the present invention.
Claims
1. A text recognition method based on an intersection-over-union loss optimization model, characterized in that: The method comprises: Determine the text to be predicted; Input the text to be predicted into a trained text recognition model to obtain a text feature label corresponding to the text to be predicted; wherein the trained text recognition model is trained based on an intersection-over-union loss function; the intersection-over-union loss function is inversely proportional to the overlap between the predicted label distribution output by the text recognition model during training and the true label distribution of the corresponding training data; And, the numerical value of the overlap between the predicted label distribution output by the text recognition model during training and the true label distribution of the corresponding training data is: the ratio between the first correction value of the sum of the predicted true products of all training data units of the text recognition model during training and the second correction value of the sum of the first predicted true values of all training data units; the first correction value is the sum of the sum of the predicted true products and the first correction factor, the second correction value is the sum of the sum of the first predicted true values and the second correction factor, and the first correction factor and the second correction factor are both non-negative numbers; the predicted true product is the product of the predicted label value and the true label value of each training data unit; the first predicted true value is the sum of the predicted label value, the true label value and the predicted true product of each training data unit; the true label value is zero when the training data unit does not belong to the text feature label; And, the trained text recognition model is trained through the following steps: Obtaining training data from a plurality of training texts meeting a first preset condition, and training the text recognition model; When the text recognition model meets a second preset condition during training, using the text recognition model as the trained text recognition model; And, obtaining training data from a plurality of training texts that meet the first preset condition includes: For each training text that meets the first preset condition, according to the position of each training text unit in the training text and whether it belongs to the text feature label, a label corresponding to each training text unit in the training text is generated one by one to obtain a label sequence corresponding to the training text; One-hot encode the label sequences corresponding to all the training texts to obtain training data; And, the first preset condition includes: The type of the training text is the same as the type of the text to be predicted; and / or, And, the second preset condition includes: A value of an intersection-over-union loss function corresponding to current training data in the training data is less than or equal to a set threshold.
2. The method according to claim 1, characterized in that Alternatively, the numerical value of the overlap between the predicted label distribution output by the text recognition model during training and the true label distribution of the corresponding training data is: the ratio of the number of identical results represented by all possible results of the predicted label distribution and all possible results of the true label distribution to the difference between the sum of the number of all possible results of the predicted label distribution and the true label distribution and the number of identical results represented.
3. The method according to claim 1, characterized in that Alternatively, the numerical value of the overlap between the predicted label distribution output by the text recognition model during training and the true label distribution of the corresponding training data is: the ratio of the sum of the predicted true products of all training data units of the text recognition model during training to the sum of the first predicted true values of all training data units; the predicted true product is the product of the predicted label value and the true label value of each of the training data units; the first predicted true value is the sum of the predicted label value, the true label value and the predicted true product of each of the training data units.
4. A text recognition device based on an intersection-over-union loss optimization model, characterized in that: The device is used to execute the text recognition method based on the intersection-over-union loss optimization model according to any one of claims 1 to 3, and the device includes: A determination module, used for determining the text to be predicted; An input module is used to input the text to be predicted into a trained text recognition model to obtain a text feature label corresponding to the text to be predicted; wherein the trained text recognition model is trained based on an intersection-over-union loss function; the intersection-over-union loss function is inversely proportional to the overlap between the predicted label distribution output by the text recognition model during training and the true label distribution of the corresponding training data.
5. A text recognition device based on an intersection-over-union loss optimization model, characterized in that: The device comprises: A memory storing executable program code; a processor coupled to the memory; The processor calls the executable program code stored in the memory to execute the text recognition method based on the intersection-over-union loss optimization model as described in any one of claims 1 to 3.
6. A computer storage medium, characterized in that: The computer storage medium stores computer instructions, which, when called, are used to execute the text recognition method based on the intersection-over-union loss optimization model as described in any one of claims 1 to 3.
Citation Information
Patent Citations
Target detection model training method, target detection method and related equipment
CN112966587A
Target detection method and device applied to vehicle-road cooperation, roadside equipment and vehicle
CN113469025A
