Word vectorization model training method and device, text recognition method and device, equipment and medium
Through the combined model of generator, discriminator and auxiliary objective function, the influence of context on word meaning is considered, which solves the problem that the word vectorization model in the existing technology does not consider context and polysemy of a word, and improves the accuracy and accuracy of text recognition. efficiency.
Patent Information
- Application Number
- CN202311523336.1
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2023-11-15
- Publication Date
- 2024-10-18
AI Technical Summary
Existing word vectorization models do not consider the impact of context on word meaning and the problem of polysemy during the text word vectorization process, resulting in low accuracy of vectors after word vectorization and affecting the accuracy of text recognition.
Using a combined model of generator, discriminator and auxiliary objective function, the context word vector is obtained through the mask mechanism, the loss function value is calculated and the model parameters are adjusted to consider the impact of context on word meaning to improve the training effect of the word vectorization model.
It improves the accuracy and efficiency of text recognition, enhances the generalization ability and convergence speed of the model, and better solves the problem of polysemy.
Smart Images

Figure CN118798157A_ABST
Abstract
Description
Technical Field
[0001] The present application belongs to the field of artificial intelligence technology, and in particular relates to a word vectorization model training, text recognition method, device, equipment and medium. Background Art
[0002] With the continuous development of Internet technology, negative information in network information is also increasing. At present, how to identify negative information in the massive amount of network information in order to maintain the network ecological environment has become a technical problem that needs to be solved urgently.
[0003] Before recognizing text information, the text to be recognized needs to be first word-vectorized, and then the vector after word vectorization is recognized. However, the word vectorization model used in the prior art does not take into account the influence of context on word meaning and the problem of polysemy of a word during the process of word vectorization of the text, resulting in low accuracy of the vector after word vectorization, which in turn affects the accuracy of subsequent text recognition. Summary of the invention
[0004] The embodiments of the present application provide a word vectorization model training, text recognition method, device, equipment and medium, which can improve the accuracy and efficiency of text recognition.
[0005] In a first aspect, an embodiment of the present application provides a training method for a word vectorization model, wherein the word vectorization model includes a generator, a discriminator, and an auxiliary objective function. The training method for the word vectorization model includes: obtaining word vector sequences corresponding to multiple first text samples, wherein the word vector sequence includes first word vectors corresponding to multiple word segments in the first text sample; masking at least one first word vector in each word vector sequence to obtain a masked word vector sequence; inputting the masked word vector sequence into the generator, and obtaining a context word vector corresponding to each first word vector through generator encoding; calculating a first loss function value of the generator based on the context word vector and the corresponding word vector sequence; inputting the context word vector and the corresponding word vector sequence into the discriminator to obtain the context word vector. The discriminant function is used to determine whether the quantity is the first word vector in the word vector sequence; according to the discriminant result, the second loss function value of the discriminator is calculated; the first N first word vectors in the word vector sequence are input into the auxiliary objective function to obtain the prediction result of the N+1th first word vector, where N is a positive integer; according to the prediction result, the third loss function value of the auxiliary objective function is calculated; according to the first loss function value, the second loss function value and the third loss function value, the total loss function value of the word vectorization model is calculated; when the total loss function value does not meet the preset training stop condition, the parameters of the generator, the discriminator and the auxiliary objective function are adjusted, and at least one first word vector in each word vector sequence is returned to be masked until the total loss function value meets the preset training stop condition to obtain the trained word vectorization model.
[0006] According to an implementation scheme of the first aspect of the present application, a first loss function value of a generator is calculated based on a context word vector and a corresponding word vector sequence, including: calculating the probability that the context word vector is the first word vector in the word vector sequence; and calculating the first loss function value of the generator based on the probability.
[0007] According to any of the foregoing implementations of the first aspect of the present application, calculating the probability that the context word vector is the first word vector in the word vector sequence includes: calculating the probability that the context word vector is the first word vector in the word vector sequence by the following formula:
[0008]
[0009] in, represents the word vector sequence corresponding to the first text sample, x t represents the first word vector at position t in the word vector sequence, e(x t ) represents x t word embedding, Represents the context word vector at position t; According to the probability, calculating the first loss function value of the generator, including: calculating the first loss function value of the generator by the following formula:
[0010]
[0011] in, represents the first loss function value, θ G represents the generator space, m represents the number of masked first word vectors, Represents the first word vector at the mask position, and IE represents the mathematical expectation.
[0012] According to any of the foregoing implementations of the first aspect of the present application, calculating the total loss function value of the word vectorization model according to the first loss function value, the second loss function value, and the third loss function value, including: calculating the total loss function value of the word vectorization model by the following formula:
[0013]
[0014] in, represents the second loss function value, represents the third loss function value, θ D represents the discriminator space, λ and γ represent parameter terms.
[0015] According to any of the aforementioned embodiments of the first aspect of the present application, after obtaining the trained word vectorization model, the training method of the word vectorization model also includes: obtaining multiple second text samples; inputting the multiple second text samples into the word vectorization model to obtain second word vectors corresponding to the word segments in each second text sample; based on a preset allocation algorithm, dividing the multiple second word vectors into a training set, a verification set, and a test set; training the preset model through the training set, the verification set, and the test set to obtain a text recognition model.
[0016] According to any of the aforementioned embodiments of the first aspect of the present application, before inputting multiple second text samples into the word vectorization model, the training method of the word vectorization model also includes: performing data cleaning on the multiple second text samples; manually labeling and data balancing the multiple second text samples after data cleaning; and inputting the multiple second text samples into the word vectorization model, including: inputting the multiple second text samples after manual labeling and data balancing into the word vectorization model.
[0017] In the second aspect, an embodiment of the present application provides a text recognition method, which includes: obtaining a text to be recognized; inputting the text to be recognized into a word vectorization model to obtain a third word vector of the text to be recognized; the word vectorization model is the word vectorization model trained in the first aspect; inputting the third word vector into a text recognition model to identify whether the text to be recognized includes target text information; the text information type of the target text information is a preset text information type; the text recognition model is the text recognition model trained in the first aspect.
[0018] In a third aspect, an embodiment of the present application provides a training device for a word vectorization model, wherein the word vectorization model includes a generator, a discriminator and an auxiliary objective function, and the training device for the word vectorization model includes: a first acquisition module, used to obtain word vector sequences corresponding to multiple first text samples, wherein the word vector sequence includes first word vectors corresponding to multiple word segments in the first text sample; a masking module, used to mask at least one first word vector in each word vector sequence to obtain a masked word vector sequence; a first input module, used to input the masked word vector sequence into the generator, and obtain the context word vector corresponding to each first word vector through generator encoding; a first calculation module, used to calculate the first loss function value of the generator according to the context word vector and the corresponding word vector sequence; a second input module, used to input the context word vector and the corresponding word vector sequence into the discriminator to obtain the context word vector. The first word vector is a discriminant of whether the quantity is the first word vector in the word vector sequence; the second calculation module is used to calculate the second loss function value of the discriminator according to the discrimination result; the third input module is used to input the first N first word vectors in the word vector sequence into the auxiliary objective function to obtain the prediction result of the N+1th first word vector, where N is a positive integer; the third calculation module is used to calculate the third loss function value of the auxiliary objective function according to the prediction result; the fourth calculation module is used to calculate the total loss function value of the word vectorization model according to the first loss function value, the second loss function value and the third loss function value; the adjustment module is used to adjust the parameters of the generator, the discriminator and the auxiliary objective function when the total loss function value does not meet the preset training stop condition, and return to mask at least one first word vector in each word vector sequence until the total loss function value meets the preset training stop condition to obtain the trained word vectorization model.
[0019] In the fourth aspect, an embodiment of the present application provides a text recognition device, which includes: a second acquisition module, used to acquire a text to be recognized; a fourth input module, used to input the text to be recognized into a word vectorization model to obtain a third word vector of the text to be recognized; the word vectorization model is the word vectorization model trained in the first aspect; a fifth input module, used to input the third word vector into a text recognition model to identify whether the text to be recognized includes target text information; the text information type of the target text information is a preset text information type; the text recognition model is the text recognition model trained in the first aspect.
[0020] In a fifth aspect, an embodiment of the present application provides an electronic device, comprising: a processor, a memory, and a computer program stored in the memory and executable on the processor, wherein when the computer program is executed by the processor, the steps of the training method for the word vectorization model provided in the first aspect and the steps of the text recognition method provided in the second aspect are implemented.
[0021] In a sixth aspect, an embodiment of the present application provides a computer-readable storage medium, on which a computer program is stored. When the computer program is executed by a processor, the steps of the training method of the word vectorization model provided in the first aspect and the steps of the text recognition method provided in the second aspect are implemented.
[0022] The training, text recognition method, device, equipment and medium of the word vectorization model of the embodiment of the present application, after obtaining the word vector sequences corresponding to the multiple first text samples, mask at least one first word vector in each word vector sequence, input the masked word vector sequence into the generator, and the generator predicts the context word vector corresponding to each first word vector according to the context of each masked first word vector; the discriminator discriminates whether each context word vector is the first word vector in the word vector sequence to obtain the discrimination result; and then the first N first word vectors in the word vector sequence are input into the auxiliary objective function to obtain the prediction result of the N+1th first word vector. The total loss function value of the word vectorization model is obtained by calculating the first loss function value of the generator, the second loss function value of the discriminator and the third loss function value of the auxiliary objective function, and the model parameters of the word vectorization model are adjusted according to the total loss function value to obtain the trained word vectorization model. The embodiment of the present application takes into account the influence of context on word meaning when training the word vectorization model. The word vectorization model of the embodiment of the present application is used to vectorize the text to be recognized, which can better solve the problem of polysemy of a word. In addition, the embodiment of the present application adds an auxiliary objective function based on the generator and the discriminator, which further improves the generalization ability and convergence speed of the model while retaining the powerful language representation ability and feature extraction ability of the word vectorization model. This is conducive to quickly obtaining a more accurate word vector corresponding to the text to be recognized in the subsequent text recognition process, thereby improving the accuracy and efficiency of text recognition. BRIEF DESCRIPTION OF THE DRAWINGS
[0023] In order to more clearly illustrate the technical solution of the embodiments of the present application, the following is a brief introduction to the drawings required for use in the embodiments of the present application. For ordinary technicians in this field, other drawings can be obtained based on these drawings without any creative work.
[0024] Figure 1 It is a flowchart of a training method for a word vectorization model provided in an embodiment of the present application;
[0025] Figure 2 It is a flowchart of another method for training a word vectorization model provided in an embodiment of the present application;
[0026] Figure 3 It is a flowchart of another method for training a word vectorization model provided in an embodiment of the present application;
[0027] Figure 4 It is a flowchart of a text recognition method provided in an embodiment of the present application;
[0028] Figure 5 It is a structural schematic diagram of a training device for a word vectorization model provided in an embodiment of the present application;
[0029] Figure 6 is a structural schematic diagram of a text recognition device provided in an embodiment of the present application;
[0030] Figure 7 It is a structural schematic diagram of an electronic device provided in an embodiment of the present application. DETAILED DESCRIPTION
[0031] The features and exemplary embodiments of various aspects of the present application will be described in detail below. In order to make the purpose, technical solutions and advantages of the present application clearer, the present application will be further described in detail below in conjunction with the accompanying drawings and specific embodiments. It should be understood that the specific embodiments described herein are only intended to explain the present application, rather than to limit the present application. For those skilled in the art, the present application can be implemented without the need for some of these specific details. The following description of the embodiments is only to provide a better understanding of the present application by illustrating the examples of the present application.
[0032] It should be noted that, in this article, relational terms such as first and second, etc. are only used to distinguish one entity or operation from another entity or operation, and do not necessarily require or imply any such actual relationship or order between these entities or operations. Moreover, the terms "include", "comprise" or any other variants thereof are intended to cover non-exclusive inclusion, so that a process, method, article 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, article or device. In the absence of further restrictions, the elements defined by the statement "include..." do not exclude the presence of other identical elements in the process, method, article or device including the elements.
[0033] It should be understood that the term "and / or" used in this article is only a description of the association relationship of associated objects, indicating that there can be three relationships. For example, A and / or B can represent: A exists alone, A and B exist at the same time, and B exists alone. In addition, the character " / " in this article generally indicates that the associated objects before and after are in an "or" relationship.
[0034] It is obvious to those skilled in the art that various modifications and changes can be made in the present application without departing from the spirit or scope of the present application. Therefore, the present application is intended to cover modifications and changes of the present application that fall within the scope of the corresponding claims (technical solutions for protection) and their equivalents. It should be noted that the implementation methods provided in the embodiments of the present application can be combined with each other without contradiction.
[0035] Before describing the technical solutions provided by the embodiments of the present application, in order to facilitate the understanding of the embodiments of the present application, the present application first specifically describes the problems existing in the prior art:
[0036] As mentioned above, the inventors of this application have found that the word vectorization models used in related technologies, such as the word2vec model, map each word in the text to a unique dense vector during the word vectorization process, without considering the impact of context on word meaning and the problem of polysemy of a word, resulting in low accuracy of the vector after word vectorization, which in turn affects the accuracy of subsequent text recognition. In addition, the word2vec modeling is single-layer, which is difficult to apply to all tasks, resulting in the need to frequently add inductive bias to its downstream tasks, affecting the expressiveness of downstream tasks.
[0037] In addition, when identifying text information, related technologies usually use keyword recognition methods to directly input the text to be identified into a pre-set database and keyword combination rules for matching to obtain matching results. However, the setting of databases and keyword combination rules depends on experts and has limited coverage. In the matching process, some rules that are irrelevant or less relevant to the preset text information type may be discarded, which will also lead to low accuracy of text recognition.
[0038] In order to solve the problems of the prior art, the embodiments of the present application provide a word vectorization model training, text recognition method, device, equipment and medium.
[0039] The following first introduces the training method of the word vectorization model provided in the embodiment of the present application.
[0040] Figure 1 Schematic diagram of a training method for a word vectorization model provided in an embodiment of the present application. Figure 1 As shown, the training method of the word vectorization model may include the following steps S101 to S110.
[0041] S101. Obtain word vector sequences corresponding to a plurality of first text samples.
[0042] S102. Mask at least one first word vector in each word vector sequence to obtain a masked word vector sequence.
[0043] S103, input the masked word vector sequence into the generator, and obtain the context word vector corresponding to each first word vector through the generator encoding.
[0044] S104. Calculate the first loss function value of the generator based on the context word vector and the corresponding word vector sequence.
[0045] S105. Input the context word vector and the corresponding word vector sequence into the discriminator to obtain a discriminant result of whether the context word vector is the first word vector in the word vector sequence.
[0046] S106. Calculate the second loss function value of the discriminator according to the discrimination result.
[0047] S107. Input the first N first word vectors in the word vector sequence into the auxiliary objective function to obtain the prediction result of the N+1th first word vector, where N is a positive integer.
[0048] S108. Calculate the third loss function value of the auxiliary objective function according to the prediction result.
[0049] S109. Calculate the total loss function value of the word vectorization model based on the first loss function value, the second loss function value and the third loss function value.
[0050] S110. When the total loss function value does not meet the preset training stop condition, adjust the parameters of the generator, discriminator and auxiliary objective function, and return to step S102 until the total loss function value meets the preset training stop condition to obtain the trained word vectorization model.
[0051] The specific implementation of the above steps will be described in detail below.
[0052] The training method of the word vectorization model of the embodiment of the present application, after obtaining the word vector sequences corresponding to multiple first text samples, masks at least one first word vector in each word vector sequence, inputs the masked word vector sequence into the generator, and the generator predicts the context word vector corresponding to each first word vector according to the context of each masked first word vector; the discriminator discriminates whether each context word vector is the first word vector in the word vector sequence to obtain the discrimination result; and then inputs the first N first word vectors in the word vector sequence into the auxiliary objective function to obtain the prediction result of the N+1th first word vector. The total loss function value of the word vectorization model is obtained by calculating the first loss function value of the generator, the second loss function value of the discriminator and the third loss function value of the auxiliary objective function, and the model parameters of the word vectorization model are adjusted according to the total loss function value to obtain the trained word vectorization model. The embodiment of the present application takes into account the influence of context on word meaning when training the word vectorization model. The word vectorization model of the embodiment of the present application can better solve the problem of polysemy of a word by performing word vectorization on the text to be recognized. In addition, the embodiment of the present application adds an auxiliary objective function based on the generator and the discriminator, which further improves the generalization ability and convergence speed of the model while retaining the powerful language representation ability and feature extraction ability of the word vectorization model. This is conducive to quickly obtaining a more accurate word vector corresponding to the text to be recognized in the subsequent text recognition process, thereby improving the accuracy and efficiency of text recognition.
[0053] The specific implementation methods of the above steps are introduced below.
[0054] In S101, since the word vectorization model cannot directly process the original first text sample, it is necessary to obtain the word vector sequences corresponding to the multiple first text samples. The word vector sequence includes first word vectors corresponding to multiple word segments in the first text sample.
[0055] In S102, at least one first word vector in each word vector sequence is randomly masked, and the first word vector at the masked position is replaced with [MASK] to obtain a masked word vector sequence.
[0056] In S103, the masked word vector sequence is input into the generator, and the masked word vector is generated through the generator encoding, so as to obtain the representation vector encoding the context information corresponding to each first word vector, that is, the context word vector. The context word vector sequence can be expressed as
[0057] In S104, according to the context word vector sequence And the corresponding word vector sequence Calculate the first loss function value of the generator.
[0058] As an implementation method of S104, S104 may specifically include: calculating the probability that the context word vector is the first word vector in the word vector sequence; and calculating the first loss function value of the generator based on the probability.
[0059] Specifically, the probability that the context word vector is the first word vector in the word vector sequence can be calculated by the following formula (1):
[0060]
[0061] in, represents the word vector sequence corresponding to the first text sample, x t represents the first word vector at position t in the word vector sequence, e(x t ) represents x t word embedding, Represents the context word vector at position t.
[0062] Exemplarily, the generator outputs the context word vector using the Softmax function. The probability that the context word vector is the first word vector in the word vector sequence can be understood as follows: the generator outputs the first word vector x in the word vector sequence based on the Softmax function. t probability.
[0063] Specifically, the first loss function value of the generator can be calculated by the following formula (2):
[0064]
[0065] in, represents the first loss function value, θ G represents the generator space, m represents the number of masked first word vectors, Represents the first word vector at the mask position, and IE represents the mathematical expectation.
[0066] In S105, the context word vector sequence And the corresponding word vector sequence The input is sent to the discriminator, which determines whether the context word vector at each position has been replaced by the generator, that is, whether the context word vector is the first word vector in the corresponding word vector sequence.
[0067] Exemplarily, the discriminator obtains the result of determining whether the context word vector is the first word vector in the word vector sequence using the Sigmoid function, as shown in formula (3):
[0068]
[0069] in, Indicates the judgment result. represents the context word vector at position t, and w represents the parameter item. When the context word vector is the first word vector in the word vector sequence, that is, the context word vector is not replaced by the generator, the judgment result is When the context word vector is not the first word vector in the word vector sequence, that is, when the context word vector is replaced by the generator, the judgment result is
[0070] In S106, specifically, the second loss function value of the discriminator can be calculated by the following formula (4):
[0071]
[0072] in, represents the second loss function value, θ D represents the discriminator space, n represents the number of first word vectors, Indicates replacing the first word vector at the mask position with the context word vector generated by the generator After that, the word vector sequence obtained is express The context word vector at position t in .
[0073] In S107, the word vector sequence The first N first word vectors in are input into the auxiliary objective function, and the prediction result of the N+1th first word vector can be obtained, where N is a positive integer.
[0074] In S108, specifically, the third loss function value of the auxiliary objective function can be calculated by the following formula (5):
[0075]
[0076] in, represents the third loss function value, P represents the language model, Θ represents the model parameters, x k Represents the first word vector at position k, where k is a positive integer.
[0077] In S109, specifically, the total loss function value of the word vectorization model can be calculated by the following formula (6):
[0078]
[0079] in, represents the first loss function value, represents the second loss function value, represents the value of the second loss function, and λ and γ represent parameter terms.
[0080] In S110, illustratively, as shown in formula (7), the preset training stop condition may be that the total loss function value reaches a minimum.
[0081]
[0082] When the total loss function value does not meet the preset training stop condition, adjust the parameters of the generator, discriminator and auxiliary objective function, and return to step S102 until the total loss function value reaches the minimum value to obtain the trained word vectorization model.
[0083] As another implementation method of the training method of the word vectorization model of this application, Figure 2 As shown, after S110, the training method of the word vectorization model may further include the following steps S201 to S204.
[0084] S201: Acquire multiple second text samples.
[0085] S202: Input multiple second text samples into a word vectorization model to obtain second word vectors corresponding to the word segments in each second text sample.
[0086] By inputting multiple second text samples into the trained word vectorization model, the second word vector corresponding to each word segment in each second text sample can be directly obtained, wherein the second word vector encodes the context information of the word segment in the corresponding second text sample.
[0087] S203: Based on a preset allocation algorithm, divide the plurality of second word vectors into a training set, a validation set, and a test set.
[0088] Exemplarily, the preset allocation algorithm may be a k-fold cross validation algorithm. Based on the k-fold cross validation algorithm, the plurality of second word vectors are divided into k mutually exclusive subsets of similar size. K-2 subsets are used as training sets, 1 subset is used as a validation set, and 1 subset is used as a test set, thereby obtaining k groups of training sets, validation sets, and test sets.
[0089] S204: Train the preset model using the training set, the validation set, and the test set to obtain a text recognition model.
[0090] Exemplarily, the preset model is trained, verified and tested k times using k groups of training sets, validation sets and test sets respectively. During the training of the preset model, the model training results can be evaluated on the validation set, and the model parameters can be adjusted according to the model evaluation results until the model reaches the optimal parameters to obtain the trained text recognition model. Finally, the error of the text recognition model can be tested on the test set, and the average value of the k test results is taken as the error value of the text recognition model.
[0091] As another implementation method of the training method of the word vectorization model of this application, Figure 3 As shown, before S202, the training method of the word vectorization model may also include the following steps S301 and S302.
[0092] S301: Perform data cleaning on multiple second text samples.
[0093] Exemplarily, regular expressions may be used to perform data cleaning on the plurality of second text samples to remove meaningless, missing or redundant data.
[0094] S302: Perform manual labeling and data balancing on the plurality of second text samples after data cleaning.
[0095] Exemplarily, when manually annotating the multiple second text samples after data cleaning, the manual annotation can be performed according to the preset text information type. When performing data balancing on the multiple second text samples after data cleaning, undersampling or oversampling can be used at the data level, and category weighted loss, focal loss, GHM loss, etc. can be used at the model level.
[0096] As an implementation method of S202, S202 may specifically include: inputting multiple second text samples that have been manually annotated and data balanced into a word vectorization model to obtain second word vectors corresponding to each word segment in each second text sample.
[0097] Figure 4 is a flowchart of a text recognition method provided by an embodiment of the present application. Figure 4 As shown, the text recognition method may include the following steps S401 to S403.
[0098] S401: Obtain text to be recognized.
[0099] S402: Input the text to be recognized into a word vectorization model to obtain a third word vector of the text to be recognized.
[0100] By inputting the text to be recognized into the trained word vectorization model, the third word vectors corresponding to the characters and words in the text to be recognized can be directly obtained.
[0101] S403: Input the third word vector into the text recognition model to identify whether the text to be recognized includes the target text information.
[0102] The third word vector is input into the trained text recognition model to identify whether the text to be recognized includes target text information whose text information type is a preset text information type. For example, the preset text information type may be negative information in network information.
[0103] The text recognition method of the embodiment of the present application takes into account the influence of context on word meaning when training the word vectorization model. The word vectorization model of the embodiment of the present application is used to vectorize the text to be recognized, which can better solve the problem of polysemy. In addition, compared with the keyword recognition method in the prior art, the embodiment of the present application reduces the dependence on experts, has a wider coverage of rules, and improves the accuracy and efficiency of text recognition.
[0104] Based on the training method of the word vectorization model provided in the above embodiment, the present application also provides a specific implementation of the training device of the word vectorization model. Please refer to the following embodiment.
[0105] like Figure 5 As shown, the training device 500 of the word vectorization model provided in the embodiment of the present application includes the following modules:
[0106] A first acquisition module 501 is used to acquire word vector sequences corresponding to a plurality of first text samples, wherein the word vector sequences include first word vectors corresponding to a plurality of word segments in the first text sample;
[0107] A masking module 502, configured to mask at least one first word vector in each word vector sequence to obtain a masked word vector sequence;
[0108] The first input module 503 is used to input the masked word vector sequence into the generator, and obtain the context word vector corresponding to each first word vector through the generator encoding;
[0109] A first calculation module 504, used to calculate a first loss function value of the generator according to the context word vector and the corresponding word vector sequence;
[0110] The second input module 505 is used to input the context word vector and the corresponding word vector sequence into the discriminator to obtain a discriminant result of whether the context word vector is the first word vector in the word vector sequence;
[0111] A second calculation module 506, used to calculate a second loss function value of the discriminator according to the discrimination result;
[0112] The third input module 507 is used to input the first N first word vectors in the word vector sequence into the auxiliary objective function to obtain the prediction result of the N+1th first word vector, where N is a positive integer;
[0113] A third calculation module 508, used to calculate a third loss function value of the auxiliary objective function according to the prediction result;
[0114] A fourth calculation module 509, used to calculate a total loss function value of the word vectorization model according to the first loss function value, the second loss function value and the third loss function value;
[0115] The adjustment module 510 is used to adjust the parameters of the generator, discriminator and auxiliary objective function when the total loss function value does not meet the preset training stop condition, and return to mask at least one first word vector in each word vector sequence until the total loss function value meets the preset training stop condition, thereby obtaining a trained word vectorization model.
[0116] The training device of the word vectorization model of the embodiment of the present application, after obtaining the word vector sequences corresponding to the multiple first text samples, masks at least one first word vector in each word vector sequence, inputs the masked word vector sequence into the generator, and the generator predicts the context word vector corresponding to each first word vector according to the context of each masked first word vector; the discriminator discriminates whether each context word vector is the first word vector in the word vector sequence, and obtains the discrimination result; and then the first N first word vectors in the word vector sequence are input into the auxiliary objective function to obtain the prediction result of the N+1th first word vector. The total loss function value of the word vectorization model is obtained by calculating the first loss function value of the generator, the second loss function value of the discriminator, and the third loss function value of the auxiliary objective function, and the model parameters of the word vectorization model are adjusted according to the total loss function value to obtain the trained word vectorization model. The embodiment of the present application takes into account the influence of context on word meaning when training the word vectorization model. The word vectorization model of the embodiment of the present application can better solve the problem of polysemy of a word by performing word vectorization on the text to be recognized. In addition, the embodiment of the present application adds an auxiliary objective function based on the generator and the discriminator, which further improves the generalization ability and convergence speed of the model while retaining the powerful language representation ability and feature extraction ability of the word vectorization model. This is conducive to quickly obtaining a more accurate word vector corresponding to the text to be recognized in the subsequent text recognition process, thereby improving the accuracy and efficiency of text recognition.
[0117] In some embodiments, the first calculation module 504 is specifically used to calculate the probability that the context word vector is the first word vector in the word vector sequence; based on the probability, the first loss function value of the generator is calculated.
[0118] In some embodiments, the first calculation module 504 may also be used to calculate the probability that the context word vector is the first word vector in the word vector sequence by using the following formula:
[0119]
[0120] in, represents the word vector sequence corresponding to the first text sample, x t represents the first word vector at position t in the word vector sequence, e(x t ) represents x t word embedding, Represents the context word vector at position t; the first loss function value of the generator is calculated by the following formula:
[0121]
[0122] in, represents the first loss function value, θ G represents the generator space, m represents the number of masked first word vectors, Represents the first word vector at the mask position, and IE represents the mathematical expectation.
[0123] In some embodiments, the fourth calculation module 509 is specifically used to calculate the total loss function value of the word vectorization model by the following formula:
[0124]
[0125] in, represents the second loss function value, represents the third loss function value, θ D represents the discriminator space, λ and γ represent parameter terms.
[0126] In some embodiments, the training device 500 of the above-mentioned word vectorization model may also include a training module for obtaining multiple second text samples; inputting the multiple second text samples into the word vectorization model to obtain second word vectors corresponding to the word segments in each second text sample; based on a preset allocation algorithm, dividing the multiple second word vectors into a training set, a verification set and a test set; training the preset model through the training set, the verification set and the test set to obtain a text recognition model.
[0127] In some embodiments, the training device 500 of the above-mentioned word vectorization model may also include a processing module for performing data cleaning on multiple second text samples; manually labeling and data balancing the multiple second text samples after data cleaning; and inputting multiple second text samples into the word vectorization model, including: inputting multiple second text samples after manual labeling and data balancing into the word vectorization model.
[0128] Figure 5 Each module in the device shown has the function of realizing Figure 1 The functions of each step in the process can achieve the corresponding technical effects, which will not be described in detail here for the sake of brevity.
[0129] Based on the text recognition method provided in the above embodiment, the present application also provides a specific implementation of a text recognition device. Please refer to the following embodiment.
[0130] like Figure 6 As shown, the text recognition device 600 provided in the embodiment of the present application includes the following modules:
[0131] The second acquisition module 601 is used to acquire the text to be recognized;
[0132] The fourth input module 602 is used to input the text to be recognized into the word vectorization model to obtain a third word vector of the text to be recognized; the word vectorization model is the word vectorization model obtained by the training in the first aspect;
[0133] The fifth input module 603 is used to input the third word vector into the text recognition model to identify whether the text to be recognized includes target text information; the text information type of the target text information is a preset text information type; the text recognition model is the text recognition model trained in the first aspect.
[0134] The text recognition device of the embodiment of the present application considers the influence of context on word meaning when training the word vectorization model. The word vectorization model of the embodiment of the present application can better solve the problem of polysemy by performing word vectorization on the text to be recognized. In addition, compared with the keyword recognition method in the prior art, the embodiment of the present application reduces the dependence on experts, the rule coverage is also wider, and the accuracy and efficiency of text recognition are improved.
[0135] Based on the training method of the word vectorization model and the text recognition method provided in the above embodiments, the present application also provides a specific implementation method of the electronic device. Please refer to the following embodiments.
[0136] Figure 7 It is a structural schematic diagram of an electronic device provided in an embodiment of the present application.
[0137] The electronic device may include a processor 701 and a memory 702 storing computer program instructions.
[0138] Specifically, the processor 701 may include a central processing unit (CPU), or an application specific integrated circuit (ASIC), or may be configured to implement one or more integrated circuits of the embodiments of the present application.
[0139] The memory 702 may include a large capacity memory for data or instructions. By way of example and not limitation, the memory 702 may include a hard disk drive (HDD), a floppy disk drive, a flash memory, an optical disk, a magneto-optical disk, a magnetic tape, or a universal serial bus (USB) drive or a combination of two or more of these. In one example, the memory 702 may include a removable or non-removable (or fixed) medium, or the memory 702 is a non-volatile solid-state memory. The memory 702 may be inside or outside the integrated gateway disaster recovery device.
[0140] In one example, the memory 702 may be a read-only memory (ROM). In one example, the ROM may be a mask-programmed ROM, a programmable ROM (PROM), an erasable PROM (EPROM), an electrically erasable PROM (EEPROM), an electrically rewritable ROM (EAROM), or a flash memory, or a combination of two or more of these.
[0141] The memory 702 may include a read-only memory (ROM), a random access memory (RAM), a magnetic disk storage medium device, an optical storage medium device, a flash memory device, an electrical, optical or other physical / tangible memory storage device. Thus, typically, the memory includes one or more tangible (non-transitory) computer-readable storage media (e.g., a memory device) encoded with software including computer-executable instructions, and when the software is executed (e.g., by one or more processors), it is operable to perform the operations described with reference to the method according to an aspect of the present application.
[0142] The processor 701 reads and executes the computer program instructions stored in the memory 702 to implement Figure 1 The method / steps S101 to S110 in the embodiment shown in the figure are achieved Figure 1 The corresponding technical effects achieved by executing the methods / steps of the examples shown, and Figure 4 The method / steps S401 to S403 in the embodiment shown in the figure are achieved Figure 4 The corresponding technical effects achieved by executing the methods / steps in the example shown are not repeated here for the sake of brevity.
[0143] In one example, the electronic device may further include a communication interface 703 and a bus 710. Figure 7 As shown, the processor 701, the memory 702, and the communication interface 703 are connected via a bus 710 and communicate with each other.
[0144] The communication interface 703 is mainly used to implement communication between various modules, devices, units and / or equipment in the embodiments of the present application.
[0145] Bus 710 includes hardware, software or both, and the parts of electronic equipment are coupled to each other.For example, but not limitation, bus may include accelerated graphics port (Accelerated Graphics Port, AGP) or other graphics bus, enhanced industry standard architecture (Extended Industry Standard Architecture, EISA) bus, front side bus (Front Side Bus, FSB), hypertransmission (Hyper Transport, HT) interconnection, industry standard architecture (IndustryStandard Architecture, ISA) bus, infinite bandwidth interconnection, low pin count (LPC) bus, memory bus, micro channel architecture (MCA) bus, peripheral component interconnection (PCI) bus, PCI-Express (PCI-X) bus, serial advanced technology attachment (SATA) bus, video electronics standard association local (VLB) bus or other suitable bus or two or more of these combinations. In appropriate cases, bus 710 may include one or more buses. Although the present application embodiment describes and shows a specific bus, the application considers any suitable bus or interconnection.
[0146] In addition, in combination with the training method of the word vectorization model and the text recognition method in the above-mentioned embodiment, the embodiment of the present application may provide a computer-readable storage medium to implement. The computer-readable storage medium stores computer program instructions; when the computer program instructions are executed by the processor, any one of the word vectorization model training methods and text recognition methods in the above-mentioned embodiments is implemented. Examples of computer-readable storage media include non-transitory computer-readable storage media, such as electronic circuits, semiconductor memory devices, ROM, random access memory, flash memory, erasable ROM (EROM), floppy disks, CD-ROMs, optical disks, and hard disks.
[0147] It should be clear that the present application is not limited to the specific configuration and processing described above and shown in the figures. For the sake of simplicity, a detailed description of the known method is omitted here. In the above embodiments, several specific steps are described and shown as examples. However, the method process of the present application is not limited to the specific steps described and shown, and those skilled in the art can make various changes, modifications and additions, or change the order between the steps after understanding the spirit of the present application.
[0148] The functional blocks shown in the above-described block diagram can be implemented as hardware, software, firmware or a combination thereof. When implemented in hardware, it can be, for example, an electronic circuit, an application-specific integrated circuit (Application Specific Integrated Circuit, ASIC), appropriate firmware, plug-in, function card, etc. When implemented in software, the elements of the present application are programs or code segments used to perform the required tasks. The program or code segment can be stored in a machine-readable medium, or transmitted on a transmission medium or communication link by a data signal carried in a carrier. "Machine-readable medium" may include any medium capable of storing or transmitting information. Examples of machine-readable media include electronic circuits, semiconductor memory devices, ROM, flash memory, erasable ROM (EROM), floppy disks, CD-ROMs, optical disks, hard disks, optical fiber media, radio frequency (Radio Frequency, RF) links, etc. The code segment can be downloaded via a computer network such as the Internet, an intranet, etc.
[0149] It should also be noted that the exemplary embodiments mentioned in this application describe some methods or systems based on a series of steps or devices. However, this application is not limited to the order of the above steps, that is, the steps can be performed in the order mentioned in the embodiment, or in a different order from the embodiment, or several steps can be performed simultaneously.
[0150] The above reference is according to the method of the embodiment of the present application, the flow chart of the device (system) and the computer program product and / or the block diagram described various aspects of the present application.It should be understood that each square box in the flow chart and / or the block diagram and the combination of each square box in the flow chart and / or the block diagram can be realized by computer program instructions.These computer program instructions can be provided to the processor of a general-purpose computer, a special-purpose computer or other programmable data processing device to produce a machine so that these instructions executed by the processor of the computer or other programmable data processing device enable the realization of the function / action specified in one or more square boxes of the flow chart and / or the block diagram.Such a processor can be but is not limited to a general-purpose processor, a special-purpose processor, a special application processor or a field programmable logic circuit.It can also be understood that each square box in the block diagram and / or the flow chart and the combination of the square boxes in the block diagram and / or the flow chart can also be realized by the dedicated hardware that performs the specified function or action, or can be realized by the combination of dedicated hardware and computer instructions.
[0151] The above is only a specific implementation of the present application. Those skilled in the art can clearly understand that for the convenience and simplicity of description, the specific working processes of the systems, modules and units described above can refer to the corresponding processes in the aforementioned method embodiments, and will not be repeated here. It should be understood that the protection scope of the present application is not limited to this. Any technician familiar with the technical field can easily think of various equivalent modifications or replacements within the technical scope disclosed in this application, and these modifications or replacements should be included in the protection scope of this application.
Claims
1. A training method for a word vectorization model, characterized in that: The word vectorization model includes a generator, a discriminator and an auxiliary objective function, and the method includes: Obtain word vector sequences corresponding to a plurality of first text samples, wherein the word vector sequences include first word vectors corresponding to a plurality of word segments in the first text sample; Masking at least one first word vector in each word vector sequence to obtain a masked word vector sequence; Inputting the masked word vector sequence into the generator, encoding it through the generator, and obtaining the context word vector corresponding to each first word vector; Calculate a first loss function value of the generator according to the context word vector and the corresponding word vector sequence; Inputting the context word vector and the corresponding word vector sequence into the discriminator to obtain a discriminant result of whether the context word vector is the first word vector in the word vector sequence; Calculating a second loss function value of the discriminator according to the discrimination result; Input the first N first word vectors in the word vector sequence into the auxiliary objective function to obtain the prediction result of the N+1th first word vector, where N is a positive integer; Calculating a third loss function value of the auxiliary objective function according to the prediction result; Calculate the total loss function value of the word vectorization model according to the first loss function value, the second loss function value and the third loss function value; When the total loss function value does not meet the preset training stop condition, the parameters of the generator, the discriminator and the auxiliary objective function are adjusted, and the masking of at least one first word vector in each word vector sequence is returned until the total loss function value meets the preset training stop condition, thereby obtaining a trained word vectorization model.
2. The method according to claim 1, characterized in that The step of calculating the first loss function value of the generator according to the context word vector and the corresponding word vector sequence includes: Calculate the probability that the context word vector is the first word vector in the word vector sequence; Based on the probability, a first loss function value of the generator is calculated.
3. The method according to claim 2, characterized in that The calculating the probability that the context word vector is the first word vector in the word vector sequence includes: The probability that the context word vector is the first word vector in the word vector sequence is calculated by the following formula: in, represents the word vector sequence corresponding to the first text sample, x t represents the first word vector at position t in the word vector sequence, e(x t ) represents x t word embedding, Represents the context word vector at position t; Calculating the first loss function value of the generator according to the probability includes: The first loss function value of the generator is calculated by the following formula: in, represents the first loss function value, θ G represents the generator space, m represents the number of masked first word vectors, Represents the first word vector at the mask position, and IE represents the mathematical expectation.
4. The method according to claim 3, characterized in that The calculating the total loss function value of the word vectorization model according to the first loss function value, the second loss function value and the third loss function value includes: The total loss function value of the word vectorization model is calculated by the following formula: in, represents the second loss function value, represents the third loss function value, θ D represents the discriminator space, λ and γ represent parameter terms.
5. The method according to claim 1, characterized in that After obtaining the trained word vectorization model, the method further includes: obtaining a plurality of second text samples; Input the plurality of second text samples into the word vectorization model to obtain second word vectors corresponding to the word segments in each second text sample; Based on a preset allocation algorithm, the plurality of second word vectors are divided into a training set, a validation set, and a test set; The preset model is trained using the training set, the validation set and the test set to obtain a text recognition model.
6. The method according to claim 5, characterized in that Before inputting the plurality of second text samples into the word vectorization model, the method further includes: Performing data cleaning on the plurality of second text samples; Manually label and balance the data on multiple second text samples after data cleaning; The step of inputting the plurality of second text samples into the word vectorization model comprises: A plurality of second text samples after manual annotation and data balancing processing are input into the word vectorization model.
7. A text recognition method, characterized in that: The method comprises: Get the text to be recognized; Inputting the text to be recognized into a word vectorization model to obtain a third word vector of the text to be recognized; the word vectorization model is a word vectorization model trained by any one of claims 1 to 4; The third word vector is input into the text recognition model to identify whether the text to be recognized includes target text information; the text information type of the target text information is a preset text information type; the text recognition model is the text recognition model trained in claim 5.
8. A training device for a word vectorization model, characterized in that: The word vectorization model includes a generator, a discriminator and an auxiliary objective function, and the device includes: A first acquisition module is used to acquire word vector sequences corresponding to a plurality of first text samples, wherein the word vector sequences include first word vectors corresponding to a plurality of word segments in the first text sample; A masking module, used to mask at least one first word vector in each word vector sequence to obtain a masked word vector sequence; A first input module, used for inputting the masked word vector sequence into the generator, encoding by the generator, and obtaining a context word vector corresponding to each first word vector; A first calculation module, used to calculate a first loss function value of the generator according to the context word vector and the corresponding word vector sequence; A second input module, used to input the context word vector and the corresponding word vector sequence into the discriminator to obtain a discriminant result of whether the context word vector is the first word vector in the word vector sequence; A second calculation module, used to calculate a second loss function value of the discriminator according to the discrimination result; A third input module is used to input the first N first word vectors in the word vector sequence into the auxiliary objective function to obtain a prediction result of the N+1th first word vector, where N is a positive integer; A third calculation module, used to calculate a third loss function value of the auxiliary objective function according to the prediction result; a fourth calculation module, configured to calculate a total loss function value of the word vectorization model according to the first loss function value, the second loss function value, and the third loss function value; An adjustment module is used to adjust the parameters of the generator, the discriminator and the auxiliary objective function when the total loss function value does not meet the preset training stop condition, and return to mask at least one first word vector in each word vector sequence until the total loss function value meets the preset training stop condition to obtain a trained word vectorization model.
9. A text recognition device, characterized in that: The device comprises: The second acquisition module is used to acquire the text to be recognized; A fourth input module, used for inputting the text to be recognized into a word vectorization model to obtain a third word vector of the text to be recognized; the word vectorization model is a word vectorization model trained by any one of claims 1 to 4; A fifth input module is used to input the third word vector into a text recognition model to identify whether the text to be recognized includes target text information; the text information type of the target text information is a preset text information type; and the text recognition model is the text recognition model trained in claim 5.
10. An electronic device, characterized in that: The electronic device includes: a processor, a memory, and a computer program stored in the memory and executable on the processor. When the computer program is executed by the processor, the steps of the training method for the word vectorization model as described in any one of claims 1 to 6 and the steps of the text recognition method as described in claim 7 are implemented.
11. A computer-readable storage medium, characterized in that: The computer-readable storage medium stores a computer program, and when the computer program is executed by a processor, the steps of the training method of the word vectorization model as described in any one of claims 1 to 6 and the steps of the text recognition method as described in claim 7 are implemented.
