Text recognition model training method, device, electronic device and storage medium

By introducing a joint learning method of the backbone model and auxiliary model in the text recognition model, the problems of large errors and inefficiency in the existing text content review methods are solved, and more accurate and efficient text content review is achieved.

CN113761904BActive Publication Date: 2025-04-25ALIBABA GROUP HOLDING LTD
View PDF 1 Cites 0 Cited by

Patent Information

Application Number
CN202010507328.8
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2020-06-05
Publication Date
2025-04-25
Estimated Expiration
2040-06-05

AI Technical Summary

Technical Problem

The existing text content review methods rely on sensitive word filtering, resulting in large errors, inaccurate review results, and require manual further review, which is inefficient.

Method used

A training method for text recognition model is adopted, and the main model and auxiliary model are used to learn the target content features in the sample text. The main model is learned from the sentence level, the auxiliary model is learned from the word level, and the recognition accuracy is improved by adjusting the model parameters.

Benefits of technology

It improves the recognition ability of the text recognition model, enhances the accurate identification of target content in the text, reduces the need for manual review, and improves the review efficiency.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN113761904B_ABST
    Figure CN113761904B_ABST
Patent Text Reader

Abstract

The disclosed embodiment discloses a training method, device, electronic device and storage medium for a text recognition model, the method comprising: obtaining multiple sample segmentations of a sample sentence in a sample text; obtaining a first output result corresponding to the sample sentence by inputting the sample segmentation into the backbone model, and obtaining a second output result corresponding to the sample segmentation by inputting the sample segmentation into the auxiliary model; the first output result is at least used to indicate whether the sample sentence of the backbone model involves target content, and the second output result is at least used to indicate whether the sample segmentation involves the target content; adjusting the model parameters of the backbone model and the auxiliary model using the first output result and the second output result; the backbone model and the auxiliary model share at least a part of the model parameters. This technical solution can improve the recognition ability of the text recognition model.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present disclosure relates to the field of computer technology, and in particular to a training method, device, electronic device and storage medium for a text recognition model. Background Art

[0002] With the development of artificial intelligence technology, the review of text content mostly relies on automatic machine review. The review of text content mainly refers to filtering harmful or spam information for the published text content to comply with laws, regulations and business demands. The usual practice is to use a sensitive word filtering system. The review system pre-sets a batch of keyword libraries and arranges and combines phrases. Then, the keyword combinations are classified according to sensitivity. During the content review, texts containing sensitive words are screened out and further processed, such as manual re-review. However, the error caused by this method is large, resulting in inaccurate review results, and further manual review is required, which is inefficient. Therefore, how to provide the review accuracy of text content is one of the technical problems that people in this field need to solve. Summary of the invention

[0003] Embodiments of the present disclosure provide a text recognition model training method, device, electronic device, and computer-readable storage medium.

[0004] In a first aspect, an embodiment of the present disclosure provides a method for training a text recognition model, wherein the text recognition model includes a backbone model and at least one auxiliary model, including:

[0005] Obtain multiple sample word segments of sample sentences in the sample text;

[0006] A first output result corresponding to the sample sentence is obtained by inputting the sample segmentation into the main model, and a second output result corresponding to the sample segmentation is obtained by inputting the sample segmentation into the auxiliary model; the first output result is at least used to indicate whether the sample sentence involves target content, and the second output result is at least used to indicate whether the sample segmentation involves the target content;

[0007] The model parameters of the main model and the auxiliary model are adjusted using the first output result and the second output result; the main model and the auxiliary model share at least a part of the model parameters.

[0008] Further, obtaining a first output result corresponding to the sample sentence by inputting the sample word segmentation into the backbone model includes:

[0009] Obtaining an initial word vector of the sample word segmentation;

[0010] The sample sentence vector of the sample sentence is obtained by inputting the initial word vector corresponding to the sample word segment in the sample sentence into the sentence vector representation model in the backbone model, and the first output result is obtained by inputting the sample sentence vector into the sentence recognition model in the backbone model.

[0011] Further, the sample sentence vector of the sample sentence is obtained by inputting the initial word vector corresponding to the sample word segment in the sample sentence into the sentence vector representation model in the backbone model, including:

[0012] Obtaining a context word vector of the sample word segmentation by inputting the initial word vector corresponding to the sample word segmentation into a first context information representation model in the sentence vector representation model;

[0013] Determine the word attention weight of the sample word segmentation by using the attention mechanism and the context word vector;

[0014] The sample sentence vector of the sample sentence is obtained by using the word attention weight of the sample word segmentation and the context word vector.

[0015] Further, the word attention weight of the sample word segmentation is determined by using the attention mechanism and the context word vector, including:

[0016] Using a fully connected layer to process the context word vector corresponding to the sample word segmentation to obtain a corresponding first output vector; wherein the backbone model and the auxiliary model share the model parameters of the fully connected layer;

[0017] The word attention weight of the sample word segmentation is calculated according to the first output vector.

[0018] Furthermore, obtaining a second output result corresponding to the sample word segmentation by inputting the sample word segmentation into the auxiliary model includes:

[0019] The second output result corresponding to the sample word segmentation is determined using the first output vector.

[0020] Furthermore, obtaining a second output result corresponding to the sample word segmentation by inputting the sample word segmentation into the auxiliary model includes:

[0021] Using a fully connected layer to process the initial word vector corresponding to the sample word segmentation to obtain a corresponding second output vector; the backbone model and the auxiliary model share the model parameters of the fully connected layer;

[0022] The second output result corresponding to the sample word segmentation is determined according to the second output vector.

[0023] Further, obtaining the first output result by inputting the sample sentence vector into a sentence recognition model in the backbone model includes:

[0024] Obtaining a context sentence vector of the sample sentence by inputting the sample sentence vector into a second context information representation model in the backbone model;

[0025] The first output result is determined according to the context sentence vector.

[0026] Further, adjusting the model parameters of the main model and the auxiliary model using the first output result and the second output result includes:

[0027] determining whether the sample text involves a third output result of the target content by first output results corresponding to a plurality of the sample sentences in the sample text;

[0028] The model parameters of the backbone model and the auxiliary model are adjusted by respectively fitting the first true label of whether the third output result and the sample sentence involve the target content, and the second true label of whether the second output result and the sample word segmentation involve the target content.

[0029] In a second aspect, an embodiment of the present disclosure provides a text recognition method, including:

[0030] Get the text to be recognized;

[0031] A backbone model in a text recognition model is used to identify whether the text to be recognized involves target content; wherein the text recognition model is trained using the method described in the first aspect.

[0032] In a third aspect, an embodiment of the present disclosure provides a sentence vector representation method, including:

[0033] Get multiple word segments in the target sentence;

[0034] Obtaining a context vector word of the word segmentation using a first context information representation model;

[0035] Determine the word attention weight of the word segmentation by using the self-attention mechanism and the context word vector;

[0036] The sentence vector of the target sentence is determined using the word attention weights of the word segmentation and the context word vector.

[0037] Further, obtaining the context vector word of the word segmentation by using the first context information representation model includes:

[0038] Obtaining an initial word vector corresponding to the word segmentation;

[0039] The context word vector corresponding to the word segmentation is obtained by inputting a word vector sequence consisting of the initial word vectors corresponding to the multiple word segmentations into the first context information representation model.

[0040] Further, the word attention weight of the word segmentation is determined by using the attention mechanism and the context word vector, including:

[0041] Input the context word vector into the fully connected layer to obtain an output vector;

[0042] The output vector is used to calculate the word attention weight of the word segmentation.

[0043] In a fourth aspect, an embodiment of the present disclosure provides a text recognition method, including:

[0044] Obtain multiple target sentences in the text to be recognized;

[0045] Determine a sentence vector of the target sentence; the sentence vector is determined using the method described in the third aspect;

[0046] Determining a first recognition result of the target sentence using the sentence vector; the first recognition result is at least used to indicate whether the target sentence involves target content;

[0047] A second recognition result of the text to be recognized is determined according to the first recognition result; the second recognition result is at least used to indicate whether the text to be recognized involves the target content.

[0048] Further, determining a first recognition result of the target sentence using the sentence vector includes:

[0049] Obtaining a context sentence vector of the target sentence by inputting the sentence vector into a second context information representation model;

[0050] The first recognition result is determined according to the context sentence vector.

[0051] In a fifth aspect, an embodiment of the present disclosure provides a training device for a text recognition model, wherein the text recognition model includes a backbone model and at least one auxiliary model, including:

[0052] A first acquisition module is configured to acquire a plurality of sample word segments of a sample sentence in a sample text;

[0053] A second acquisition module is configured to obtain a first output result corresponding to the sample sentence by inputting the sample segmentation into the main model, and to obtain a second output result corresponding to the sample segmentation by inputting the sample segmentation into the auxiliary model; the first output result is at least used to indicate whether the sample sentence of the main model involves the target content, and the second output result is at least used to indicate whether the sample segmentation involves the target content;

[0054] The adjustment module is configured to adjust the model parameters of the main model and the auxiliary model using the first output result and the second output result; the main model and the auxiliary model share at least a part of the model parameters.

[0055] In a sixth aspect, an embodiment of the present disclosure provides a text recognition device, including:

[0056] A third acquisition module is configured to acquire the text to be recognized;

[0057] The first recognition module is configured to use a backbone model in a text recognition model to identify whether the text to be recognized involves target content; wherein the text recognition model is trained using the device described in claim 15.

[0058] In a seventh aspect, an embodiment of the present disclosure provides a sentence vector representation device, including:

[0059] A fourth acquisition module is configured to acquire multiple word segments in the target sentence;

[0060] A fifth acquisition module is configured to acquire a context vector word of the word segmentation by using the first context information representation model;

[0061] A first determination module is configured to determine the word attention weight of the word segmentation by using a self-attention mechanism and the context word vector;

[0062] The second determination module is configured to determine the sentence vector of the target sentence using the word attention weight of the word segmentation and the context word vector.

[0063] In an eighth aspect, an embodiment of the present disclosure provides a text recognition device, including:

[0064] A sixth acquisition module is configured to acquire a plurality of target sentences in the text to be recognized;

[0065] A third determination module is configured to determine a sentence vector of the target sentence; the sentence vector is determined using the apparatus according to the seventh aspect;

[0066] A fourth determination module is configured to determine a first recognition result of the target sentence using the sentence vector; the first recognition result is at least used to indicate whether the target sentence involves target content;

[0067] The fifth determination module is configured to determine a second recognition result of the text to be recognized based on the first recognition result; the second recognition result is at least used to indicate whether the text to be recognized involves the target content.

[0068] The functions can be implemented by hardware or by hardware executing corresponding software. The hardware or software includes one or more modules corresponding to the functions.

[0069] In one possible design, the structure of the above-mentioned device includes a memory and a processor, the memory is used to store one or more computer instructions that support the above-mentioned device to execute the above-mentioned corresponding method, and the processor is configured to execute the computer instructions stored in the memory. The above-mentioned device may also include a communication interface for the above-mentioned device to communicate with other devices or communication networks.

[0070] In a ninth aspect, an embodiment of the present disclosure provides an electronic device, comprising a memory and a processor; wherein the memory is used to store one or more computer instructions, wherein the one or more computer instructions are executed by the processor to implement the method described in any one of the above aspects.

[0071] In a tenth aspect, an embodiment of the present disclosure provides a computer-readable storage medium for storing computer instructions used by any of the above-mentioned devices, which includes computer instructions involved in executing the method described in any of the above-mentioned aspects.

[0072] The technical solution provided by the embodiments of the present disclosure may have the following beneficial effects:

[0073] During the training process of the text recognition model in the disclosed embodiment, the backbone model is used to learn the features of the target content related to the sample sentences in the sample text from the sentence level, and the auxiliary model is used to learn the features of the target content related to the sample word segmentation of the sample sentences in the sample text from the word level, so that the entire text recognition model learns the features of the target content related to the sample text from the sentence level and the word level, thereby greatly improving the recognition ability of the text recognition model.

[0074] In the text recognition process, the disclosed embodiment first obtains the context word vector of each word segment in the target sentence, and then uses the attention mechanism and the context word vector to obtain the word attention weight of the word segment, and then obtains the sentence vector of the target sentence according to the word attention mechanism and the context word vector, and then identifies whether the target sentence involves the target content through the sentence vector, and determines whether the text to be identified involves the target content according to whether the target sentence involves the target content. In the above manner, the disclosed embodiment takes into account the context information of the word segment in the target sentence during the sentence vector representation, and adds an attention mechanism to the word segment in the sentence, so that the word segment involving the target content is more important in the sentence vector representation, which improves the recognition ability of whether the target sentence involves the target content, and then improves the recognition ability of whether the text to be identified involves the target content from the sentence level.

[0075] It is to be understood that the foregoing general description and the following detailed description are exemplary and explanatory only and are not restrictive of the present disclosure. BRIEF DESCRIPTION OF THE DRAWINGS

[0076] Other features, objectives and advantages of the present disclosure will become more apparent through the following detailed description of non-limiting embodiments in conjunction with the accompanying drawings. In the accompanying drawings:

[0077] Figure 1 A flowchart showing a method for training a text recognition model according to an embodiment of the present disclosure is shown;

[0078] 2(a) to (b) show the structure of a text recognition model and a schematic diagram of a training process in a pornographic application scenario according to an embodiment of the present disclosure;

[0079] Figure 3 A flowchart showing a text recognition method according to an embodiment of the present disclosure is shown;

[0080] Figure 4 A flowchart of a sentence vector representation method according to an embodiment of the present disclosure is shown;

[0081] Figure 5 A flowchart showing a text recognition method according to another embodiment of the present disclosure is shown;

[0082] Figure 6 It is a structural schematic diagram of an electronic device suitable for implementing a text recognition model training method, a text recognition method and / or a sentence vector representation method according to an embodiment of the present disclosure. DETAILED DESCRIPTION

[0083] Hereinafter, exemplary embodiments of the present disclosure will be described in detail with reference to the accompanying drawings so that those skilled in the art can easily implement them. In addition, for the sake of clarity, parts not related to the description of the exemplary embodiments are omitted in the accompanying drawings.

[0084] In the present disclosure, it should be understood that terms such as "include" or "have" are intended to indicate the presence of features, numbers, steps, behaviors, components, parts, or a combination thereof disclosed in the present specification, and are not intended to exclude the possibility that one or more other features, numbers, steps, behaviors, components, parts, or a combination thereof exist or are added.

[0085] It should also be noted that, in the absence of conflict, the embodiments and features in the embodiments of the present disclosure may be combined with each other. The present disclosure will be described in detail below with reference to the accompanying drawings and in combination with the embodiments.

[0086] For long texts, there are semantic connections between sentences. If we only consider whether a single sentence involves harmful information or whether it is spam in the relevant technology, the recognition accuracy of the text content will decrease. In addition, the text recognition model based on document identification in the relevant technology only uses document-level label information. When the long text is represented by a vector, a lot of noise information irrelevant to the review will be introduced, which will cause the text recognition model to be unable to focus on the content fragments that really have problems. Therefore, it is difficult to use this text recognition model to identify whether there is content that needs to be reviewed in the long text, such as whether it is pornographic.

[0087] Therefore, the embodiments of the present disclosure propose a sentence vector representation method, a text recognition method, and a training method for a text recognition model. In the process of recognizing text, the embodiments of the present disclosure represent the sentences in the text by vector representation, and in the process of sentence vector representation, the contextual information of the sentence is considered, and an attention mechanism is added to the word segmentation in the sentence, and then the sentence vector represented in this way is used to identify whether the text involves the target content, which can improve the accuracy of text recognition. In addition, in the process of text recognition, whether the text involves the target content is identified by identifying whether the sentences in the text involve the target content (for example, whether there is illegal information such as pornography, whether it is junk information, etc.), that is, the text recognition method in the embodiments of the present disclosure recognizes the text at the sentence level, which can further improve the performance of text recognition.

[0088] The details of the embodiments of the present disclosure are described in detail below through specific examples.

[0089] Figure 1 FIG. 1 is a flowchart of a training method for a text recognition model according to an embodiment of the present disclosure. Figure 1 As shown, the training method of the text recognition model includes the following steps:

[0090] In step S101, a plurality of sample word segments of a sample sentence in a sample text is obtained;

[0091] In step S102, a first output result corresponding to a sample sentence is obtained by inputting the sample segmentation into a main model, and a second output result corresponding to the sample segmentation is obtained by inputting the sample segmentation into an auxiliary model; the first output result is at least used to indicate whether the sample sentence involves the target content, and the second output result is at least used to indicate whether the sample segmentation involves the target content;

[0092] In step S103, the model parameters of the main model and the auxiliary model are adjusted using the first output result and the second output result; the main model and the auxiliary model share at least a part of the model parameters.

[0093] In this embodiment, the text recognition model includes a backbone model and at least one auxiliary model. The backbone model mainly learns the features of the target content in the sample text from the sentence level, while the auxiliary model mainly learns the features of the target content in the sample word segmentation from the word level. The target content can be different based on different application scenarios. For example, the target content can be information security-related content, such as pornographic content.

[0094] For each sample text, it is first segmented to obtain multiple sample sentences, and then the sample sentences can be segmented to obtain multiple sample segmented words. That is, one sample text can correspond to multiple sample sentences, and one sample sentence can correspond to multiple sample segmented words. The segmentation of the sample text can be based on punctuation marks, for example, by identifying the commonly used punctuation marks ".", "?", "!", etc. at the end of the sentence. It can be understood that the multiple sample sentences included in the text to be identified can be all the sentences included in the text to be identified, or they can be part of the sentences. The specific number can be determined according to the actual application and is not limited here.

[0095] The input of the main model can be all or part of the sample segmentation of all or part of the sample sentences in the entire sample text, and its output is a first output result for indicating whether the sample sentence in the sample text involves the target content (in the model training process, the first output result is quite different from the true result). The input of the auxiliary model is the sample segmentation of a sample sentence in the sample text, and its output is a second output result for indicating whether each sample segmentation in the sample sentence involves the target content (in the model training process, the second output result is quite different from the true result). Therefore, in the training process, the second output result corresponding to each sample segmentation in each sample sentence can be obtained by inputting multiple sample segmentations corresponding to multiple sample sentences in the sample text into the auxiliary model respectively.

[0096] After obtaining the first output result and the second output result, the model parameters of the backbone model and the auxiliary model can be adjusted according to the first output result and the second output result. The parameter adjustment process is related to the established objective function. The established objective function can respectively fit the prediction result of the backbone model for the sample text (determined according to the first output result) and the true result of the sample text (that is, the real label pre-marked to indicate whether the sample text involves the target content), and the second output result and the real result of the sample word segmentation (that is, the real label pre-marked to indicate whether the sample word segmentation involves the target content), and the model parameters are adjusted with the goal of making the prediction result corresponding to the sample text infinitely close to the real result of the sample text and the second output result infinitely close to the real result of the sample word segmentation. After the above training process of a large number of sample texts, the converged model parameters can be obtained, and the training of the text recognition model is finally completed.

[0097] The auxiliary model performs feature learning on each sample segmentation in the sample sentence, and the learning process of the backbone model includes feature learning of each sample segmentation in the sample sentence and feature learning of each sample sentence in the sample text. Therefore, the auxiliary model and the backbone model can share some model parameters, which include model parameters corresponding to the feature learning part of each sample segmentation in the sample sentence.

[0098] In some embodiments, the processing process of the sample text by the backbone model may include: extracting the word vector features of the sample word segmentation corresponding to all sample sentences in the sample text, then obtaining the sentence vector features of the sample sentence based on the word vector features, and finally obtaining the first output result of the sample sentence according to the sentence vector features of the sample sentence; and the processing result of the sample word segmentation by the auxiliary model may include: extracting the word vector features of the sample word segmentation corresponding to all sample sentences in the sample text, and then determining the second output result of the sample word segmentation according to the word vector features. Therefore, the backbone model and the auxiliary model can share the model parameters of the part of extracting the word vector features of the sample word segmentation corresponding to all sample sentences in the sample text, that is, the part of the model parameters shared by the backbone model and the auxiliary model may include the model parameters involved in the feature extraction part of the sample word segmentation.

[0099] During the training process of the text recognition model in the disclosed embodiment, the backbone model is used to learn the features of the target content related to the sample sentences in the sample text from the sentence level, and the auxiliary model is used to learn the features of the target content related to the sample word segmentation of the sample sentences in the sample text from the word level, so that the entire text recognition model learns the features of the target content related to the sample text from the sentence level and the word level, thereby greatly improving the recognition ability of the text recognition model.

[0100] In an optional implementation of this embodiment, the step of obtaining a first output result corresponding to the sample sentence by inputting the sample word segmentation into the backbone model in step S102 further includes the following steps:

[0101] Get the initial word vector of the sample word segmentation;

[0102] The sample sentence vector of the sample sentence is obtained by inputting the initial word vector corresponding to the sample word segmentation in the sample sentence into the sentence vector representation model in the backbone model, and the first output result is obtained by inputting the sample sentence vector into the sentence recognition model in the backbone model.

[0103] In this optional implementation, the initial word vector corresponding to the sample word segmentation may be a word vector obtained by pre-training. For example, the word vectors corresponding to each word in the word set may be obtained by pre-training with a sample corpus, such as by pre-determining the word vectors of each word in the word set through word2vec to obtain a word vector set corresponding to the word set; the initial word vector corresponding to the sample word segmentation may be a word vector corresponding to a word in the word set that matches the sample word segmentation.

[0104] The backbone model may include a word vector query model, a sentence vector representation model, and a sentence recognition model. The function of the word vector query model may be to obtain the initial word vector corresponding to each sample word segment in the sample sentence based on the sample word segment and the word vector set obtained by pre-training, and the function of the sentence vector representation model may be to obtain the sample sentence vector of the sample sentence based on the initial word vector of each sample word segment in the sample sentence, and the function of the sentence recognition model may be to recognize whether the sample sentence involves the target content based on the sample sentence vector of the sample sentence. The word vector sequence composed of the initial word vectors of each sample word segment corresponding to the sample sentence may be input into the sentence vector representation model, and then the sentence vector representation model obtains the sample sentence vector of the sample sentence based on the initial word vector of each sample word segment, and then the sample sentence vector corresponding to each sample sentence in the sample text is input into the sentence recognition model in the backbone model for processing to obtain the first output result of whether the sample sentence involves the target content.

[0105] In an optional implementation of this embodiment, the step of obtaining a sample sentence vector of the sample sentence by inputting the initial word vector corresponding to the sample word segmentation in the sample sentence into the sentence vector representation model in the backbone model further includes the following steps:

[0106] Obtaining a context word vector of the sample word segmentation by inputting the initial word vector corresponding to the sample word segmentation into the first context information representation model in the sentence vector representation model;

[0107] Use the attention mechanism and context word vector to determine the word attention weight of sample segmentation;

[0108] The sample sentence vector of the sample sentence is obtained by using the word attention weight of the sample segmentation and the context word vector.

[0109] In this optional implementation, the first context information representation model may be a model that can extract the context information of the word segmentation in the target sentence, such as Bi-LSTM (Bi-directional Long Short-Term Memory), RNN (Recurrent Neural Network), Transformer encoder, etc. Of course, it is understandable that the first context information representation model is not limited to the above three types, as long as the word vector of the word segmentation can be obtained through the word segmentation of the sentence, and the word vector is a context word vector that reflects the context semantic information of the word segmentation.

[0110] The input of the first context information representation model can be the initial word vector of each sample word segment in the sample sentence. The first context information representation model can process the initial word vector according to the context semantic relationship of the sample word segment in the sample sentence and extract the context word vector corresponding to each word segment, so that the context word vectors corresponding to the sample word segment involving the target content and the sample word segment having a context semantic relationship with the sample word segment involving the target content are closer in the vector space, that is, the sample word segment involving the target content can be divided into one category through the context word vector, and the sample word segment having a context semantic relationship with the sample word segment involving the target content can be identified (this type of sample word segment can also be considered to involve the target content). It can be understood that the context word vector obtained by using the first context information representation model can reflect the context semantic information of whether the sample word segment involves the target content.

[0111] After extracting the context word vector of each sample word in the sample sentence, the word attention weight of the sample word in the sample sentence can be determined by using the self-attention mechanism and the context word vector. The larger the word attention weight, the higher the importance of the sample word in the target sentence. It can be understood that the importance of the sample word in the sample sentence is related to the semantics to be represented by the sample sentence vector of the sample sentence, that is, the sample word involving the target content is more important in the sample sentence, and the larger the word attention weight of the sample word, the lower the importance of the sample word not involving the target content, and the smaller the word attention weight. The self-attention mechanism in natural language processing can refer to the relevant technology.

[0112] The following example illustrates how to calculate the word attention weight. For details, please refer to the following formula:

[0113]

[0114]

[0115] Among them, α in represents the word attention weight, N represents the number of word segments in the sample sentence, and h in is the output vector obtained by mapping the context word vector of the current sample segmentation through the fully connected layer, b w is a constant, Represents the transposed matrix of the model parameters involved in the attention mechanism part.

[0116] After determining the word attention weight, the sample sentence vector of the sample sentence can be calculated using the word attention weight and the context word vector of the sample word in the sample sentence. In some embodiments, the sample sentence vector of the sample sentence can be obtained by linearly weighting the context word vector of the sample word using the word attention weight of the sample word in the sample sentence.

[0117] Based on the above formulas (1) and (2), the sample sentence vector can be expressed by the following formula (3):

[0118]

[0119] Among them, s i Represents the sentence vector of the sample sentence, α in represents the word attention weight, c in Represents the context word vector of the sample word in the sample sentence.

[0120] In an optional implementation of this embodiment, the step of determining the word attention weight of the sample word segmentation by using the attention mechanism and the context word vector further includes the following steps:

[0121] The context word vector corresponding to the sample word segmentation is processed by a fully connected layer to obtain the corresponding first output vector; wherein the backbone model and the auxiliary model share the model parameters of the fully connected layer;

[0122] The word attention weight of the sample word segmentation is calculated based on the first output vector.

[0123] In this optional implementation, the context word vector is input into the fully connected layer, and the fully connected layer extracts relevant information therefrom to obtain an output vector. The word attention weight of the sample word segmentation can be calculated based on the output vector. The specific calculation process can select a suitable calculation method according to the actual situation. For example, the word attention weight can be calculated using the method in formulas (1) and (2).

[0124] In an optional implementation of this embodiment, the step of obtaining a second output result corresponding to the sample word segmentation by inputting the sample word segmentation into the auxiliary model in step S102 further includes the following steps:

[0125] The first output vector is used to determine a second output result corresponding to the sample word segmentation.

[0126] In this optional implementation, the backbone model and the auxiliary model can share the model parameters of the first context information representation model and the fully connected layer, and can use the first context information representation model to process each sample word in the sample sentence to obtain the context word vector of the sample word, and then use the fully connected layer to process the context word vector to obtain the first output vector corresponding to the sample word, and then the backbone model can calculate the word attention weight of the sample word based on the first output vector, and the auxiliary model can obtain the second output result of whether the sample word involves the target content based on the output vector. In this way, the steps of data processing can be saved, and the efficiency of model training can be improved.

[0127] Since the backbone model and the auxiliary model share the model parameters of the first context information representation model and the fully connected layer. Therefore, in the final model parameter adjustment process, the model parameters of the first context information representation model and the fully connected layer can be adjusted by using the error between the true result of the sample segmentation, that is, whether the sample segmentation involves the target content and the second output result. At the same time, since the first context information representation model and the fully connected layer are also used in the backbone model, the model parameters of the fully connected layer will also be adjusted by using the error between the true result of the sample text, that is, whether the sample text involves the target content and the predicted result of the sample text (determined according to the first output result). This method can improve the first context information representation model and the fully connected layer at the word level and sentence level. The ability to extract feature information related to the target content of the segmentation, thereby improving the recognition ability of the text recognition model.

[0128] In an optional implementation of this embodiment, the step of obtaining a second output result corresponding to the sample word segmentation by inputting the sample word segmentation into the auxiliary model in step S102 further includes the following steps:

[0129] The full connection layer is used to process the initial word vector corresponding to the sample word segmentation to obtain the corresponding second output vector; the backbone model and the auxiliary model share the model parameters of the full connection layer;

[0130] A second output result corresponding to the sample word segmentation is determined according to the second output vector.

[0131] In this optional implementation, the initial word vector of the sample word segmentation is input into the fully connected layer, and the fully connected layer extracts relevant information therefrom to obtain a second output vector. According to the second output vector, the second output result of the sample word segmentation can be calculated, and the second output result is used to indicate whether the sample word segmentation involves the target content. The backbone model and the auxiliary model share the model parameters of the fully connected layer. Therefore, in the final model parameter adjustment process, the model parameters of the fully connected layer can be adjusted by using the error between the true result of the sample word segmentation, that is, whether the sample word segmentation involves the target content and the second output result. At the same time, since the fully connected layer is also used in the backbone model, that is, in the process of obtaining the sample sentence vector of the sample sentence through the context word vector of the sample word segmentation, the fully connected layer will be used to process the context word vector. Therefore, the true result of the sample text, that is, whether the sample text involves the target content, and the error between the predicted result for the sample text are also used to adjust the model parameters of the fully connected layer. This method can improve the ability of the fully connected layer to extract feature information of the word segmentation involving the target content at the word level and the sentence level, thereby improving the recognition ability of the text recognition model.

[0132] In some embodiments, the auxiliary model may include a first auxiliary model and a second auxiliary model. The first auxiliary model may be an auxiliary model described in another optional implementation method, which uses a first context information representation model to process the initial word vector of the sample word segmentation to obtain a context word vector, and then uses a fully connected layer to process the context word vector to obtain a first output vector, and then obtains a second output result corresponding to the sample word segmentation. The second auxiliary model may be an auxiliary model described in the above optional implementation method, which uses a fully connected layer to process the initial word vector to obtain a second output vector, and then obtains a first output result corresponding to the sample word segmentation. Of course, in other embodiments, only one of the first auxiliary model and the second auxiliary model may be used, which may be determined according to actual conditions and is not limited here.

[0133] In an optional implementation of this embodiment, the step of obtaining a first output result by inputting the sample sentence vector into the sentence recognition model in the backbone model further includes the following steps:

[0134] Obtaining a context sentence vector of the sample sentence by inputting the sample sentence vector into the second context information representation model in the backbone model;

[0135] The first output result is determined according to the context sentence vector.

[0136] In this optional implementation, the second context information representation model can be a model that can extract the context information of the sample sentence in the sample text based on the sample sentence vector of the sample sentence, for example, it can be Bi-LSTM (Bi-directional Long Short-Term Memory), RNN (Recurrent Neural Network), Transformer encoder, etc. Of course, it can be understood that the second context information representation model is not limited to the above three types, as long as it is an artificial intelligence model that obtains the context vector that can reflect the context semantic information of the sample sentence through the sample sentence vector.

[0137] In some embodiments, the input of the second context information representation model may be a sample sentence vector corresponding to each sample sentence in the sample text. The second context information representation model may process the sample sentence vector according to the context semantic relationship of the sample sentences in the sample text to obtain the context sentence vector corresponding to each sample sentence, so that the context sentence vectors corresponding to the sample sentences involving the target content and the sample sentences having a context semantic relationship with the sample sentences involving the target content are closer in the vector space, that is, the context sentence vector can be used to identify whether each sample sentence involves the target content and whether it has a context semantic relationship with the sample sentences involving the target content (such sample sentences can also be considered to involve the target content). It can be understood that the context sentence vector obtained by using the second context information representation model can reflect the semantic information of whether the sample sentence involves the target content.

[0138] In an optional implementation of this embodiment, the step of adjusting the model parameters of the main model and the auxiliary model using the first output result and the second output result in step S103 further includes the following steps:

[0139] determining whether the sample text involves a third output result of the target content by first output results corresponding to a plurality of sample sentences in the sample text;

[0140] The model parameters of the backbone model and the auxiliary model are adjusted by respectively fitting the first true label of whether the third output result and the sample sentence involve the target content, and the second true label of whether the second output result and the sample word segmentation involve the target content.

[0141] In this optional implementation, the first true label can be obtained by manually annotating the sample text or by other credible means, and the first true label is used to indicate whether the sample text involves the target content. The second true label can be determined by using a pre-constructed dictionary that includes words related to the target content. For example, in the text recognition process involving pornographic content, some pornographic words can be obtained in advance, and a pornographic dictionary can be constructed. In the training process of the pornographic text recognition model, the second true label of the sample word segmentation of the sample sentence in the sample text can be determined by matching the sample word segmentation with the pornographic dictionary. The second true label of the matched sample word segmentation is pornographic, and the second true label of the unmatched sample word segmentation is not pornographic. In this way, in the training process of the text recognition model, the pre-constructed dictionary can be used to add prior guidance information to the word-level training layer, which can further improve the recognition ability of the text recognition model.

[0142] The process of adjusting the model parameters can refer to the existing technology. The principle is to reversely adjust the model parameters in the text recognition model by comparing the difference between the third output result and the first true label, and comparing the difference between the second output result and the second true label, so that the output results of the text recognition model for the sample text and sample word segmentation after the model parameters are adjusted are closer to the true results.

[0143] The above-mentioned scheme of the embodiment of the present disclosure can be applied to the field of information security. The above-mentioned scheme proposed by the embodiment of the present disclosure can be used to train a text recognition model for identifying information security-related content in a text. Information security-related content may, for example, be content related to pornography, gambling, and drugs, or content related to other sensitive information. The text recognition model can be deployed in the cloud to provide information security identification services to relevant departments or personnel. It is understandable that a training framework for training a text recognition model can also be deployed in the cloud, and demand information from relevant departments or relevant personnel can be received. After the corresponding text recognition model is trained according to the demand information and the above-mentioned training method, it can be provided to the relevant department or relevant personnel, or deployed in the cloud for online identification of text content specified by the relevant department or relevant personnel, and the recognition results can be output to the relevant department or relevant personnel.

[0144] The training process of the text recognition model in the embodiment of the present disclosure is explained below through a specific implementation example of the text recognition model.

[0145] Figures 2(a) to (b) show the structure of a text recognition model in a pornographic application scenario and a schematic diagram of the training process according to an embodiment of the present disclosure. The text recognition model may include a backbone model, a first auxiliary model, and a second auxiliary model. The backbone model can be divided into two parts. The first part 201 processes all sample word segmentations of the sample sentence input into a sample sentence to obtain a sample sentence vector of the sample sentence; and the second part 202 processes the sample sentence vectors of all sample sentences in the sample text to obtain a classification result of whether the sample text involves the target content. The first auxiliary model, the second auxiliary model, and the first part of the backbone model share some model parameters.

[0146] Figure 2(a) shows the first part of the main model and the structures of the first auxiliary model and the second auxiliary model. Assume that the sample text is a long text novel segment, and the text segment contains M sentences, which are obtained by segmenting using sentence punctuation marks such as periods, exclamation marks, and question marks. The vector representation of any sentence i is s i The first part of the backbone model is used to vectorize the M sentences to obtain the sentence vector representation s of the M sentences. i .

[0147] The first part of the backbone model processes the input data as follows:

[0148] 1) After the segmentation, the multiple segmentation sets {w i1 ,……,w in , ...w iN} is input to the query layer (Lookup), and then the query layer obtains the initial word vector e corresponding to each input word in the sentence i of length N through mapping. in .

[0149] 2) Then, the sequence of initial word vectors corresponding to each word in sentence i passes through the Bi-LSTM model layer to obtain the context word vector representation c of each word in .

[0150] 3) Each context word vector c in After the fully connected layer (Dense Layer), the output vector h is obtained in , using the self-attention mechanism to the output vector h in Processing can determine the word attention weight α of the word segmentation in .

[0151] 4) Use the word attention weight to linearly weight the context word vector of each word segment to obtain c′ in The sum can be used to get the vector representation s of sentence i i .

[0152] In order to learn the word vector representation related to the task, that is, the word vectors of pornographic words will be closer in space, so a word-level first auxiliary model is added. The first auxiliary model processes the input data as follows:

[0153] 1) The initial word vector e of each word obtained through the query layer in After the fully connected layer, the output vector v is obtained in .

[0154] 2) Output vector v in After the Softmax layer (including linear transformation and softmax function in sequence), the classification results of each word can be obtained The classification results Used to represent the participle w in Whether it is pornographic words.

[0155] A pornographic dictionary may be provided during the training of the first auxiliary model, so that each word is provided with supervision information by a corresponding pornographic label.

[0156] In order to give pornographic words a greater weight when generating sentence vector representations to highlight their importance to sentence vector representations, a second auxiliary model at the word level can be added. The second auxiliary model processes the input data as follows:

[0157] The output vector h obtained by the fully connected layer of the first part of the backbone model in , input to the Softmax layer to get the classification result of whether each word is pornographic

[0158] Figure 2(b) shows the second part of the backbone model, which is the prediction result of whether the long novel text segment is pornographic based on the sentence vector representation obtained in the first part. As shown in Figure 2(b), the second part of the backbone model processes the sentence vector representation as follows:

[0159] 1) The vector representation of all sentences in the long novel text fragment {S i} Input to the Bi-LSTM layer to obtain the context sentence vector representation h of the fused context of each sentence i .

[0160] 2) Context sentence vector representation h i After being processed by the Softmax layer (which includes linear transformation and softmax function in sequence), the classification result of whether each sentence is pornographic or not can be obtained.

[0161] 3) If there is a sentence in a long novel text segment that involves pornography, the Max function can be used to determine the prediction result of the entire long novel text segment involving pornography.

[0162] It should be noted that the model parameters of the fully connected layer Dense in the first auxiliary model, the second auxiliary model and the backbone model are shared.

[0163] From the model structure shown in Figure 2(a) and Figure 2(b) and the above text description, it can be seen that during the training process, all sample word segments in the sample sentence are processed by the first part of the backbone model to obtain the sentence vector representation of the sample sentence, and the sentence vector representation of all sample sentences in the sample text is processed by the second part of the backbone model to obtain the prediction result of the sample text. The intermediate processing result of the first part of the backbone model can be provided to the first auxiliary model and the second auxiliary model, that is, the initial word vector of the sample word segment can be provided to the first auxiliary model to predict whether the sample word segment is pornographic; and the output vector obtained after the context vector of the sample word segment is processed by the fully connected layer is provided to the second auxiliary model to predict whether the sample word segment is pornographic.

[0164] Three prediction results can be obtained during the entire training process, namely, the prediction result of whether the sample text is pornographic, and the two prediction results of whether the sample word segmentation is pornographic. During the parameter adjustment process, the differences between the above three prediction results and the corresponding true results can be used to adjust the model parameters of the backbone model and the auxiliary model, that is, to respectively fit the differences between the prediction results of the sample text and the true results, and the differences between the two results of the sample word segmentation and the true results to adjust the parameters.

[0165] Figure 3 FIG. 1 is a flowchart of a text recognition method according to an embodiment of the present disclosure. Figure 3 As shown, the text recognition method comprises the following steps:

[0166] In step S301, the text to be recognized is obtained;

[0167] In step S302, the backbone model in the text recognition model is used to identify whether the text to be recognized involves the target content; wherein the text recognition model is trained using the training method of the above-mentioned text recognition model.

[0168] In this embodiment, the text to be recognized can be a long text used to identify whether it involves the target content. For the text to be recognized, it can be segmented to obtain multiple sentences to be recognized in the text to be recognized, and then each sentence to be recognized is segmented to obtain multiple word segments corresponding to each sentence to be recognized. After that, the sentence vector can be obtained for each sentence to be recognized using the first part of the backbone model, and the sentence vector representation corresponding to all sentences to be recognized in the text to be recognized is input into the second part of the backbone model to obtain the recognition result of whether each sentence to be recognized involves the target content. When the recognition result of at least one sentence to be recognized is related to the target content, it can be determined that the text to be recognized involves the target content. It can be seen that in the text recognition model training process, although the model parameters are trained using the first auxiliary model and the second auxiliary model, after the training is completed, only the backbone model needs to be used to recognize the text to be recognized. This is because the first auxiliary model and the second auxiliary model are actually further strengthened training of the model parameters of the backbone model, and the first auxiliary model and the second auxiliary model are not needed in the recognition process.

[0169] Figure 4 FIG. 5 is a flowchart of a sentence vector representation method according to an embodiment of the present disclosure. Figure 4 As shown, the sentence vector representation method includes the following steps:

[0170] In step S401, multiple word segments in the target sentence are obtained;

[0171] In step S402, a context vector word of each word segment is obtained using the first context information representation model;

[0172] In step S403, the word attention weight of the word segmentation is determined using the self-attention mechanism and the context word vector;

[0173] In step S404, the sentence vector of the target sentence is determined using the word attention weights of the word segmentation and the context word vector.

[0174] In this embodiment, the target sentence can be obtained by segmenting a long text, for example, by segmenting the long text according to the sentence segmentation ".", "!", "?", etc. Of course, it is understandable that the target sentence can also be a separate sentence not involving a long text, which depends on the actual application scenario and is not limited here.

[0175] Multiple word segments can be obtained by segmenting the target sentence. The word segmentation method can adopt existing technology, which will not be described here. The first context information representation model can be a model that can extract the context information of the word segmentation in the target sentence, for example, it can be Bi-LSTM (Long Short-Term Memory Network, Bi-directional Long Short-Term Memory), RNN (Recurrent Neural Network Model), Transformer encoder, etc. Of course, it can be understood that the first context information representation model is not limited to the above three types, as long as the word vector of the word segmentation can be obtained through the word segmentation of the sentence, and the word vector is a context word vector that reflects the context semantic information of the word segmentation.

[0176] In some embodiments, the first context information representation model may be pre-trained, and the first context information representation model may extract the context word vector of each word segmentation according to the context semantic relationship of each word segmentation in the target sentence, so that the context word vectors corresponding to the word segmentation involving the target content and the word segmentation having a context semantic relationship with the word segmentation involving the target content are closer in the vector space, that is, the context word vector may be used to identify whether each word segmentation involves the target content and whether it has a context semantic relationship with the word segmentation involving the target content (such word segmentation may also be considered to involve the target content). It can be understood that the context word vector obtained by using the first context information representation model can reflect the semantic information of whether the word segmentation involves the target content.

[0177] After obtaining the context word vectors of each participle in the target sentence, the word attention weight of the participle in the target sentence can be determined by using the self-attention mechanism and the context word vector. The larger the word attention weight, the higher the importance of the participle in the target sentence. It can be understood that the importance of the participle in the target sentence is related to the semantics to be represented by the sentence vector of the target sentence, that is, the importance of the participle in the target sentence is related to the application scenario of the vector representation of the target sentence. For example, the purpose of vector representation of the target sentence (that is, determining the sentence vector of the target sentence) is to identify whether the target sentence involves target content such as pornography through the sentence vector. The importance of the participle in the target sentence is related to the relevance of the participle to the target content. The more relevant the participle is, the higher the importance, that is, the greater the above-mentioned word attention weight, and the less relevant the participle is, the lower the importance and the smaller the word attention weight. The self-attention mechanism in natural language processing can refer to the relevant technology.

[0178] In this embodiment, the sentence vector representation method can be obtained using the backbone model described in the above-mentioned text recognition model training method. Therefore, relevant details can also be found in the above-mentioned description of the text recognition model training method, which will not be repeated here.

[0179] In the process of vector representation of the target sentence, the disclosed embodiment first obtains the context word vector of each word segment in the target sentence, and then uses the attention mechanism and the context word vector to obtain the word attention weight of the word segment, and then obtains the sentence vector of the target sentence according to the word attention weight and the context word vector. In the above manner, in the process of sentence vector representation, the disclosed embodiment takes into account the context information of the word segment in the target sentence, and adds an attention mechanism to the word segment in the sentence, so that the word segment related to the target content is more important in the sentence vector representation, and finally the sentence vector representation can be made more accurate.

[0180] In an optional implementation of this embodiment, step S402, i.e., the step of obtaining a context word vector of a word segmentation by using the first context information representation model, further includes the following steps:

[0181] Get the initial word vector corresponding to the word segmentation;

[0182] The context word vector corresponding to the word segmentation is obtained by inputting a word vector sequence consisting of initial word vectors corresponding to the word segmentation into the first context information representation model.

[0183] In this optional implementation, the initial word vector corresponding to the word segmentation may be a word vector obtained by pre-training. For example, the word vectors corresponding to each word in the word set may be obtained by pre-training with a sample corpus, such as by pre-determining the word vectors of each word in the word set through word2vec, and the initial word vector corresponding to the word segmentation may be the word vector corresponding to the word in the word set that matches the word segmentation.

[0184] After obtaining the initial word vector corresponding to each word segment in the target sentence, the word vector sequence composed of the initial word vectors of each word segment corresponding to the target sentence can be input into the first context representation information model to obtain the context word vector corresponding to each word segment. Compared with the initial word vector, the context word vector has the context information of the word segment in the target sentence.

[0185] In an optional implementation of this embodiment, step S403, i.e., the step of determining the word attention weight of the word segmentation by using the self-attention mechanism and the context word vector, further includes the following steps:

[0186] Input the context word vector into the fully connected layer to get the output vector;

[0187] The output vector is used to calculate the word attention weight of the word segmentation.

[0188] In this optional implementation, the context word vector is input into the fully connected layer, and the fully connected layer extracts relevant information from it to obtain an output vector. The model parameters of the fully connected layer are also pre-trained, so after the context word vector is mapped to the output vector through the fully connected layer, the word attention weight of the word segmentation can be calculated based on the output vector. The specific calculation process can select a suitable calculation method according to the actual situation. For example, the word attention weight can be calculated using the method in the above formulas (1) and (2).

[0189] Figure 5 FIG. 4 is a flowchart of a text recognition method according to another embodiment of the present disclosure. Figure 5 As shown, the text recognition method comprises the following steps:

[0190] In step S501, a plurality of target sentences in the text to be recognized are obtained;

[0191] In step S502, the sentence vector of the target sentence is determined; the sentence vector is determined using the above-mentioned sentence vector representation method;

[0192] In step S503, a first recognition result of the target sentence is determined using the sentence vector; the first recognition result is at least used to indicate whether the target sentence involves the target content;

[0193] In step S504, a second recognition result of the text to be recognized is determined according to the first recognition result; the second recognition result is at least used to indicate whether the text to be recognized involves the target content.

[0194] In this embodiment, the text recognition method is used to identify whether the target content is involved in the text to be recognized. The target content may be different based on different application scenarios. For example, the target content may be illegal content, such as pornographic content. The text to be recognized may be a long text fragment including multiple target sentences. During the recognition process, the text to be recognized is first segmented to obtain multiple target sentences included in the text to be recognized. Specifically, the segmentation may be based on punctuation marks, for example, by identifying the commonly used punctuation marks ".", "?", "!", etc. at the end of sentences. It can be understood that the multiple target sentences included in the text to be recognized may be all the sentences included in the text to be recognized, or may be part of the sentences. The specific setting may be based on the actual application, and is not limited here.

[0195] The sentence vector of the target sentence can be determined based on the above-mentioned sentence vector representation method. In the above-mentioned sentence vector method, since the context word vector of the word segmentation obtained by the first context information representation model can reflect the semantic information of whether the word segmentation involves the target content, the sentence vector obtained according to the context word vector can also reflect the semantic information of whether the target sentence involves the target content. Therefore, it is possible to identify whether the target sentence involves the target content through the sentence vector of the target sentence. In some embodiments, the sentence vector can be processed by a pre-trained sentence recognition model to identify whether the target sentence involves the target content.

[0196] After obtaining the first recognition results of each target sentence in the text to be recognized, that is, the first recognition results of whether each target sentence in the text to be recognized involves the target content, it can be determined whether the text to be recognized involves the target content according to the first recognition results. For example, it can be determined that the text to be recognized involves the target content when one of the target sentences involves the target content according to a predefined rule.

[0197] In the text recognition process, the disclosed embodiment first obtains the context word vector of each word segment in the target sentence, and then uses the attention mechanism and the context word vector to obtain the word attention weight of the word segment, and then obtains the sentence vector of the target sentence according to the word attention mechanism and the context word vector, and then identifies whether the target sentence involves the target content through the sentence vector, and determines whether the text to be identified involves the target content according to whether the target sentence involves the target content. In the above manner, the disclosed embodiment takes into account the context information of the word segment in the target sentence during the sentence vector representation, and adds an attention mechanism to the word segment in the sentence, so that the word segment involving the target content is more important in the sentence vector representation, which improves the recognition ability of whether the target sentence involves the target content, and then improves the recognition ability of whether the text to be identified involves the target content from the sentence level.

[0198] In an optional implementation of this embodiment, step S503, i.e., the step of determining the first recognition result of the target sentence using the sentence vector, further includes the following steps:

[0199] Obtaining a context sentence vector of the target sentence by inputting the sentence vector into a second context information representation model;

[0200] A first recognition result is determined based on the context sentence vector.

[0201] In this optional implementation, the second context information representation model can be a model that can extract the context information of the target sentence in the text to be recognized based on the sentence vector of the target sentence, for example, it can be a Bi-LSTM (Bi-directional Long Short-Term Memory), RNN (Recurrent Neural Network), Transformer encoder, etc. Of course, it is understandable that the second context information representation model is not limited to the above three types, as long as it is an artificial intelligence model that obtains the context vector that can reflect the context semantic information of the target sentence through the sentence vector.

[0202] In some embodiments, the second context information representation model may be pre-trained, and the second context information representation model may process the sentence vector according to the context semantic relationship of the target sentence in the text to be identified to obtain the context sentence vector corresponding to each target sentence, so that the context sentence vectors corresponding to the target sentence involving the target content and the target sentence having a context semantic relationship with the target sentence involving the target content are closer in the vector space, that is, the context sentence vector can be used to identify whether each target sentence involves the target content and whether it has a context semantic relationship with the target sentence involving the target content (such target sentences can also be considered to involve the target content). It can be understood that the context sentence vector obtained by using the second context information representation model can reflect the semantic information of whether the target sentence involves the target content.

[0203] After obtaining the context sentence vector of the target sentence using the second context information representation model and the sentence vector, the first recognition result can be determined based on the context sentence vector. For example, the context sentence vector can be input into a multi-classification function to determine the first recognition result. In this way, context semantic information is added to the sentence vector of the target sentence, so that the recognition result of the target sentence can be more accurate.

[0204] The following are embodiments of the apparatus of the present disclosure, which can be used to execute embodiments of the method of the present disclosure.

[0205] According to a text recognition model training device of an embodiment of the present disclosure, the device can be implemented as part or all of an electronic device through software, hardware, or a combination of both. The text recognition model training device includes:

[0206] A first acquisition module is configured to acquire a plurality of sample word segments of a sample sentence in a sample text;

[0207] A second acquisition module is configured to obtain a first output result corresponding to the sample sentence by inputting the sample segmentation into the main model, and to obtain a second output result corresponding to the sample segmentation by inputting the sample segmentation into the auxiliary model; the first output result is at least used to indicate whether the sample sentence of the main model involves the target content, and the second output result is at least used to indicate whether the sample segmentation involves the target content;

[0208] The adjustment module is configured to adjust the model parameters of the main model and the auxiliary model using the first output result and the second output result; the main model and the auxiliary model share at least a part of the model parameters.

[0209] In an optional implementation of this embodiment, the second acquisition module includes:

[0210] A first acquisition submodule is configured to acquire an initial word vector of a sample word segmentation;

[0211] The second acquisition submodule is configured to obtain a sample sentence vector of the sample sentence by inputting the initial word vector corresponding to the sample word segmentation in the sample sentence into the sentence vector representation model in the backbone model, and to obtain a first output result by inputting the sample sentence vector into the sentence recognition model in the backbone model.

[0212] In an optional implementation of this embodiment, the second acquisition submodule includes:

[0213] A third acquisition submodule is configured to obtain a context word vector of the sample word segmentation by inputting an initial word vector corresponding to the sample word segmentation into a first context information representation model in the sentence vector representation model;

[0214] A first determination submodule is configured to determine the word attention weight of the sample word segmentation using the attention mechanism and the context word vector;

[0215] The fourth acquisition submodule is configured to obtain a sample sentence vector of the sample sentence using the word attention weight of the sample word segmentation and the context word vector.

[0216] In an optional implementation of this embodiment, the first determining submodule includes:

[0217] A first processing submodule is configured to process the context word vector corresponding to the sample word segmentation using a fully connected layer to obtain a corresponding first output vector; wherein the backbone model and the auxiliary model share model parameters of the fully connected layer;

[0218] The first calculation submodule is configured to calculate the word attention weight of the sample word segmentation according to the first output vector.

[0219] In an optional implementation of this embodiment, the second acquisition module includes:

[0220] The second determination submodule is configured to determine a second output result corresponding to the sample word segmentation using the first output vector.

[0221] In an optional implementation of this embodiment, the second acquisition module includes:

[0222] The second processing submodule is configured to process the initial word vector corresponding to the sample word segmentation using a fully connected layer to obtain a corresponding second output vector; the backbone model and the auxiliary model share the model parameters of the fully connected layer;

[0223] The third determination submodule is configured to determine a second output result corresponding to the sample word segmentation according to the second output vector.

[0224] In an optional implementation of this embodiment, the second acquisition submodule includes:

[0225] a fifth acquisition submodule, configured to acquire a context sentence vector of the sample sentence by inputting the sample sentence vector into a second context information representation model in the backbone model;

[0226] The fourth determination submodule is configured to determine the first output result according to the context sentence vector.

[0227] In an optional implementation of this embodiment, the adjustment module includes:

[0228] A fifth determination submodule is configured to determine whether the sample text involves a third output result of the target content by means of the first output results corresponding to the plurality of sample sentences in the sample text;

[0229] The adjustment submodule is configured to adjust the model parameters of the backbone model and the auxiliary model by respectively fitting the first true label of whether the third output result and the sample sentence involve the target content, and the second true label of whether the second output result and the sample word segmentation involve the target content.

[0230] The training device of the text recognition model in this embodiment is the same as the above Figure 1 The training methods of the text recognition models in the illustrated embodiment and related embodiments correspond to each other. For details, please refer to the above Figure 1 The description of the training method of the text recognition model in the illustrated embodiment and related embodiments will not be repeated here.

[0231] According to a text recognition device of an embodiment of the present disclosure, the device can be implemented as part or all of an electronic device through software, hardware, or a combination of both. The text recognition device includes:

[0232] A third acquisition module is configured to acquire the text to be recognized;

[0233] The first recognition module is configured to use the backbone model in the text recognition model to identify whether the text to be recognized involves the target content; wherein the text recognition model is trained using the device of claim 15.

[0234] The text recognition device in this embodiment is similar to the above Figure 3 The text recognition methods in the illustrated embodiment and related embodiments correspond to each other. For details, please refer to the above Figure 3 The description of the text recognition method in the illustrated embodiment and related embodiments will not be repeated here.

[0235] According to a sentence vector representation device of an embodiment of the present disclosure, the device can be implemented as part or all of an electronic device through software, hardware, or a combination of both. The sentence vector representation device includes:

[0236] A fourth acquisition module is configured to acquire multiple word segments in the target sentence;

[0237] A fifth acquisition module is configured to acquire a context vector word of the segmentation by using the first context information representation model;

[0238] A first determination module is configured to determine the word attention weight of the word segmentation using a self-attention mechanism and a context word vector;

[0239] The second determination module is configured to determine the sentence vector of the target sentence using the word attention weight of the word segmentation and the context word vector.

[0240] In an optional implementation of this embodiment, the fifth acquisition module includes:

[0241] A sixth acquisition submodule is configured to acquire an initial word vector corresponding to the word segmentation;

[0242] The seventh acquisition submodule is configured to obtain the context word vector corresponding to the word segmentation by inputting a word vector sequence consisting of initial word vectors corresponding to multiple word segmentations into the first context information representation model.

[0243] In an optional implementation of this embodiment, the first determining module includes:

[0244] an eighth acquisition submodule, configured to input the context word vector into the fully connected layer to obtain an output vector;

[0245] The second calculation submodule is configured to use the output vector to calculate the word attention weight of the word segmentation.

[0246] The sentence vector representation device in this embodiment is similar to the above Figure 4The sentence vector representation method in the embodiment shown and the related embodiments corresponds to the same. For details, please refer to the above Figure 4 The description of the sentence vector representation method in the illustrated embodiment and related embodiments will not be repeated here.

[0247] According to another embodiment of the present disclosure, a text recognition device can be implemented as part or all of an electronic device through software, hardware, or a combination of both. The text recognition device includes:

[0248] A sixth acquisition module is configured to acquire a plurality of target sentences in the text to be recognized;

[0249] A third determination module is configured to determine a sentence vector of a target sentence; the sentence vector is determined using the sentence vector representation device;

[0250] A fourth determination module is configured to determine a first recognition result of the target sentence using the sentence vector; the first recognition result is at least used to indicate whether the target sentence involves the target content;

[0251] The fifth determination module is configured to determine a second recognition result of the text to be recognized based on the first recognition result; the second recognition result is at least used to indicate whether the text to be recognized involves the target content.

[0252] In an optional implementation of this embodiment, the third determining module includes:

[0253] a ninth acquisition submodule, configured to acquire a context sentence vector of the target sentence by inputting the sentence vector into a second context information representation model;

[0254] The sixth determination submodule is configured to determine the first recognition result according to the context sentence vector.

[0255] The text recognition device in this embodiment is similar to the above Figure 5 The text recognition methods in the illustrated embodiment and related embodiments correspond to each other. For details, please refer to the above Figure 5 The description of the text recognition method in the illustrated embodiment and related embodiments will not be repeated here.

[0256] Figure 6 It is a structural schematic diagram of an electronic device suitable for implementing a text recognition model training method, a text recognition method and / or a sentence vector representation method according to an embodiment of the present disclosure.

[0257] like Figure 6As shown, the electronic device 600 includes a processing unit 601, which can be implemented as a processing unit such as a CPU, a GPU, an FPGA, and an NPU. The processing unit 601 can perform various processes in the embodiments of any of the above methods of the present disclosure according to a program stored in a read-only memory (ROM) 602 or a program loaded from a storage part 608 into a random access memory (RAM) 603. In RAM 603, various programs and data required for the operation of the electronic device 600 are also stored. The processing unit 601, ROM 602, and RAM 603 are connected to each other via a bus 604. An input / output (I / O) interface 605 is also connected to the bus 604.

[0258] The following components are connected to the I / O interface 605: an input section 606 including a keyboard, a mouse, etc.; an output section 607 including a cathode ray tube (CRT), a liquid crystal display (LCD), etc., and a speaker, etc.; a storage section 608 including a hard disk, etc.; and a communication section 609 including a network interface card such as a LAN card, a modem, etc. The communication section 609 performs communication processing via a network such as the Internet. A drive 610 is also connected to the I / O interface 605 as needed. A removable medium 611, such as a magnetic disk, an optical disk, a magneto-optical disk, a semiconductor memory, etc., is installed on the drive 610 as needed, so that a computer program read therefrom is installed into the storage section 608 as needed.

[0259] In particular, according to an embodiment of the present disclosure, any method in the above referenced embodiment of the present disclosure may be implemented as a computer software program. For example, an embodiment of the present disclosure includes a computer program product, which includes a computer program tangibly contained on a readable medium thereof, and the computer program includes a program code for executing any method in the embodiment of the present disclosure. In such an embodiment, the computer program can be downloaded and installed from a network through the communication section 609, and / or installed from a removable medium 611.

[0260] The flow chart and block diagram in the accompanying drawings illustrate the possible architecture, functions and operations of the system, method and computer program product according to various embodiments of the present disclosure. In this regard, each square box in the road map or block diagram can represent a part of a module, program segment or code, and the part of the module, program segment or code contains one or more executable instructions for realizing the specified logical function. It should also be noted that in some alternative implementations, the functions marked in the square box can also occur in a different order from the order marked in the accompanying drawings. For example, two square boxes represented in succession can actually be executed substantially in parallel, and they can sometimes be executed in the opposite order, depending on the functions involved. It should also be noted that each square box in the block diagram and / or flow chart, and the combination of the square boxes in the block diagram and / or flow chart can be implemented with a dedicated hardware-based system that performs the specified function or operation, or can be implemented with a combination of dedicated hardware and computer instructions.

[0261] The units or modules involved in the embodiments described in the present disclosure may be implemented by software or hardware. The units or modules described may also be arranged in a processor, and the names of these units or modules do not constitute limitations on the units or modules themselves in some cases.

[0262] As another aspect, the present disclosure further provides a computer-readable storage medium, which may be a computer-readable storage medium included in the device described in the above embodiment; or a computer-readable storage medium that exists independently and is not assembled into the device. The computer-readable storage medium stores one or more programs, and the programs are used by one or more processors to execute the method described in the present disclosure.

[0263] The above description is only a preferred embodiment of the present disclosure and an explanation of the technical principles used. Those skilled in the art should understand that the scope of the invention involved in the present disclosure is not limited to the technical solution formed by a specific combination of the above technical features, but should also cover other technical solutions formed by any combination of the above technical features or their equivalent features without departing from the inventive concept. For example, the above features are replaced with the technical features with similar functions disclosed in the present disclosure (but not limited to) by each other.

Claims

1. A training method for a text recognition model, wherein: The text recognition model includes a main model and at least one auxiliary model, including: Obtain multiple sample word segments of sample sentences in the sample text; A first output result corresponding to the sample sentence is obtained by inputting the sample segmentation into the backbone model, and a second output result corresponding to the sample segmentation is obtained by inputting the sample segmentation into the auxiliary model, wherein the backbone model is used to learn features related to the target content in the sample text from a sentence level, and the auxiliary model is used to learn features related to the target content in the sample segmentation from a word level; the first output result is at least used to indicate whether the sample sentence involves the target content, and the second output result is at least used to indicate whether the sample segmentation involves the target content; The model parameters of the main model and the auxiliary model are adjusted using the first output result and the second output result; the main model and the auxiliary model share at least a part of the model parameters.

2. The method according to claim 1, wherein: Obtaining a first output result corresponding to the sample sentence by inputting the sample word segmentation into the backbone model includes: Obtaining an initial word vector of the sample word segmentation; The sample sentence vector of the sample sentence is obtained by inputting the initial word vector corresponding to the sample word segment in the sample sentence into the sentence vector representation model in the backbone model, and the first output result is obtained by inputting the sample sentence vector into the sentence recognition model in the backbone model.

3. The method according to claim 2, wherein: The sample sentence vector of the sample sentence is obtained by inputting the initial word vector corresponding to the sample word segment in the sample sentence into the sentence vector representation model in the backbone model, including: Obtaining a context word vector of the sample word segmentation by inputting the initial word vector corresponding to the sample word segmentation into a first context information representation model in the sentence vector representation model; Determine the word attention weight of the sample word segmentation by using the attention mechanism and the context word vector; The sample sentence vector of the sample sentence is obtained by using the word attention weight of the sample word segmentation and the context word vector.

4. The method according to claim 3, wherein: The word attention weight of the sample word segmentation is determined by using the attention mechanism and the context word vector, including: Using a fully connected layer to process the context word vector corresponding to the sample word segmentation to obtain a corresponding first output vector; wherein the backbone model and the auxiliary model share the model parameters of the fully connected layer; The word attention weight of the sample word segmentation is calculated according to the first output vector.

5. The method according to claim 4, wherein: The method of obtaining a second output result corresponding to the sample word segmentation by inputting the sample word segmentation into the auxiliary model includes: The second output result corresponding to the sample word segmentation is determined using the first output vector.

6. The method according to any one of claims 1 to 5, wherein: The method of obtaining a second output result corresponding to the sample word segmentation by inputting the sample word segmentation into the auxiliary model includes: Using a fully connected layer to process the initial word vector corresponding to the sample word segmentation to obtain a corresponding second output vector; the backbone model and the auxiliary model share the model parameters of the fully connected layer; The second output result corresponding to the sample word segmentation is determined according to the second output vector.

7. The method according to any one of claims 2 to 5, wherein: Obtaining the first output result by inputting the sample sentence vector into a sentence recognition model in the backbone model includes: Obtaining a context sentence vector of the sample sentence by inputting the sample sentence vector into a second context information representation model in the backbone model; The first output result is determined according to the context sentence vector.

8. The method according to any one of claims 1 to 5, wherein: Adjusting model parameters of the main model and the auxiliary model using the first output result and the second output result includes: determining whether the sample text involves a third output result of the target content by first output results corresponding to a plurality of the sample sentences in the sample text; The model parameters of the backbone model and the auxiliary model are adjusted by respectively fitting the first true label of whether the third output result and the sample sentence involve the target content, and the second true label of whether the second output result and the sample word segmentation involve the target content.

9. A text recognition method, wherein: include: Get the text to be recognized; A backbone model in a text recognition model is used to identify whether the text to be recognized involves target content; wherein the text recognition model is trained using the method described in any one of claims 1-8.

10. A text recognition method, wherein: include: Obtain multiple target sentences in the text to be recognized; Determine a sentence vector of the target sentence, wherein the sentence vector is determined based on a sentence vector representation model, the sentence vector representation model is included in a text recognition model, and the text recognition model is trained using the method according to any one of claims 1 to 8; Determining a first recognition result of the target sentence based on a sentence recognition model using the sentence vector, wherein the sentence recognition model is included in the text recognition model; the first recognition result is at least used to indicate whether the target sentence involves target content; A second recognition result of the text to be recognized is determined according to the first recognition result; the second recognition result is at least used to indicate whether the text to be recognized involves the target content.

11. The method according to claim 10, wherein: Determining a sentence vector of the target sentence includes: Acquire multiple word segments in the target sentence; Obtaining a context word vector of the word segmentation using a first context information representation model; Determine the word attention weight of the word segmentation by using the self-attention mechanism and the context word vector; The sentence vector of the target sentence is determined using the word attention weights of the word segmentation and the context word vector.

12. The method according to claim 11, wherein: Obtaining a context vector word of the word segmentation by using a first context information representation model includes: Obtaining an initial word vector corresponding to the word segmentation; The context word vector corresponding to the word segmentation is obtained by inputting a word vector sequence consisting of the initial word vectors corresponding to the multiple word segmentations into the first context information representation model.

13. The method according to claim 11 or 12, wherein: The word attention weight of the word segmentation is determined by using the attention mechanism and the context word vector, including: Input the context word vector into the fully connected layer to obtain an output vector; The output vector is used to calculate the word attention weight of the word segmentation.

14. The method according to claim 10, wherein: Determining a first recognition result of the target sentence using the sentence vector includes: Obtaining a context sentence vector of the target sentence by inputting the sentence vector into a second context information representation model; The first recognition result is determined according to the context sentence vector.

15. A training device for a text recognition model, wherein: The text recognition model includes a main model and at least one auxiliary model, including: A first acquisition module is configured to acquire a plurality of sample word segments of a sample sentence in a sample text; A second acquisition module is configured to obtain a first output result corresponding to the sample sentence by inputting the sample segmentation into the backbone model, and to obtain a second output result corresponding to the sample segmentation by inputting the sample segmentation into the auxiliary model, wherein the backbone model is used to learn features of the sample text related to the target content from a sentence level, and the auxiliary model is used to learn features of the sample segmentation related to the target content from a word level; the first output result is at least used to indicate whether the sample sentence of the backbone model involves the target content, and the second output result is at least used to indicate whether the sample segmentation involves the target content; The adjustment module is configured to adjust the model parameters of the main model and the auxiliary model using the first output result and the second output result; the main model and the auxiliary model share at least a part of the model parameters.

16. A text recognition device, wherein: include: A third acquisition module is configured to acquire the text to be recognized; The first recognition module is configured to use a backbone model in a text recognition model to identify whether the text to be recognized involves target content; wherein the text recognition model is trained using the device described in claim 15.

17. A text recognition device, wherein: include: A sixth acquisition module is configured to acquire a plurality of target sentences in the text to be recognized; A third determination module is configured to determine a sentence vector of the target sentence, wherein the sentence vector is determined based on a sentence vector representation model, the sentence vector representation model is included in a text recognition model, and the text recognition model is trained using the method according to any one of claims 1 to 8; a fourth determination module, configured to determine a first recognition result of the target sentence based on a sentence recognition model using the sentence vector, wherein the sentence recognition model is included in the text recognition model; and the first recognition result is at least used to indicate whether the target sentence involves target content; The fifth determination module is configured to determine a second recognition result of the text to be recognized based on the first recognition result; the second recognition result is at least used to indicate whether the text to be recognized involves the target content.

18. An electronic device, wherein: comprising a memory and a processor; wherein, The memory is used to store one or more computer instructions, wherein the one or more computer instructions are executed by the processor to implement the method according to any one of claims 1 to 14.

19. A computer-readable storage medium having computer instructions stored thereon, wherein: When the computer instructions are executed by a processor, the method according to any one of claims 1 to 14 is implemented.

Citation Information

Patent Citations

  • Multi-level text emotion feature extraction method and model

    CN108763204A