A Mask text matching method and medium based on multi-task learning
Through multi-task learning and mask matrix technology, combined with the BERT model, the problem of poor robustness of existing text matching algorithms in real application scenarios is solved, the ability to capture text differences is enhanced, and the generalization ability and robustness of the model are improved. Great sex.
Patent Information
- Application Number
- CN202211071421.4
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2022-09-02
- Publication Date
- 2024-09-24
- Estimated Expiration
- 2042-09-02
AI Technical Summary
Existing text matching algorithms have poor robustness when dealing with real application scenarios, and are difficult to capture multi-dimensional text differences such as vocabulary, syntax, and pragmatics, and text vectors based on pre-trained models are not effective in identifying text differences.
The Mask text matching method based on multi-task learning is used to obtain the characteristics of the text to be matched, including word segmentation, part-of-speech tagging, named entity recognition, semantic role annotation and dependency syntax analysis, and is combined with the BERT model for feature extraction and matching, using the mask matrix Simplify the model and enhance the generalization ability of the model.
It improves the robustness of text matching models in intelligent interaction and natural language understanding scenarios, enhances the ability to capture text differences, simplifies the model structure and improves generalization capabilities.
Smart Images

Figure CN115687939B
Abstract
Description
Technical Field
[0001] The present invention relates to the field of natural language processing, and in particular to a Mask text matching method and medium based on multi-task learning. Background Art
[0002] Text matching methods aim to determine whether the semantics of two natural sentences are equivalent, which is an important research direction in the field of natural language processing. Text matching research also has high commercial value and plays an important role in information retrieval, intelligent customer service and other fields.
[0003] In recent years, although neural network models have achieved accuracy similar to or even exceeding that of humans in some standard problem matching evaluations, these models have poor robustness when dealing with problems in real application scenarios and are unable to make correct judgments on very simple problems (which are easy for humans to judge), resulting in extremely poor product experience and economic losses.
[0004] Currently, most text matching tasks are tested on a test set that is the same distribution as the training set, and the results are good, but in fact the model capabilities are exaggerated, and there is a lack of real evaluation of the fine-grained advantages and disadvantages of the model, because from the perspective of some information retrieval and intelligent customer service scenarios in industrial practice, it is difficult to ensure that the application scenario is the same distribution as the model development. Therefore, the present invention focuses on the robustness of the text matching model in real application scenarios, starting from multiple dimensions such as vocabulary, syntax, and pragmatics, discovers the shortcomings of the current text matching algorithm model, and promotes the development of semantic matching technology in industrial fields such as intelligent interaction.
[0005] Traditional text matching methods include BoW, VSM, TF-IDF, BM25, Jaccord, SimHash and other algorithms. For example, the BM25 algorithm calculates the matching score between the two by the coverage of the network field to the query field. The higher the score, the better the match between the text and the query. It mainly solves the matching problem at the vocabulary level, or the similarity problem at the vocabulary level. In fact, the matching algorithm based on vocabulary overlap has great limitations. The reasons include: semantic limitations. Although "taxi" and "taxi" are not similar in terms of literal meaning, they are actually the same means of transportation; "apple" means different things in different contexts, either fruit or company; structural limitations. Although the vocabulary of "machine learning" and "learning machine" is completely overlapping, the meanings they express are different; knowledge limitations. Although the sentence "Qin Shihuang plays Dota" has no problem in terms of lexical and syntactic terms, it is incorrect when combined with knowledge. The above shows that for text matching tasks, we cannot just stay at the literal matching level, but also need semantic matching.
[0006] Deep semantic matching method. With the successful application of deep learning in the fields of computer vision, speech recognition and recommendation systems, many studies in recent years have been devoted to applying deep neural network models to natural language processing tasks to reduce the cost of feature engineering. The text matching calculation based on the Word Embedding trained by the neural network is simple in training method, and the semantic computability of the obtained word vector representation is further enhanced. However, the practical effect of the Word Embedding trained only with unlabeled data in text matching calculation is not much different from the topic model technology. They are essentially based on the training of co-occurrence information. In addition, Word Embedding itself does not solve the semantic representation problem of phrases and sentences, nor does it solve the asymmetric problem of matching.
[0007] The current text matching algorithm is mainly based on the BERT pre-trained language model, which improves the semantic information of the text vector as much as possible. However, the text vector obtained by the pre-trained model cannot well identify the difference between texts in some scenarios. For example, the two sentences "How to exchange RMB for Hong Kong dollars" and "How to exchange Hong Kong dollars for RMB" have relatively small differences in content, but their meanings are very different. Therefore, if you rely solely on the pre-trained model to obtain the text vector, it is difficult to capture the differences in the text from the dimensions of vocabulary, syntax, pragmatics, etc.
[0008] It can be seen that the current text matching algorithm has the following defects:
[0009] 1) Statistical language models cannot express rich semantic information and are difficult to capture the differences between texts in some short text matching scenarios where the differences are relatively small.
[0010] 2) Algorithm models based on word vectors and attention require a lot of labeled data, and the model structure is complex. They do not further explore and utilize the structural features of the text itself, such as syntactic structure and part of speech.
[0011] 3) The pre-trained text matching model focuses more on the output results of the pre-training, and designs a more complex network structure for classification based on the output results of the pre-training model. It does not combine the structural features of the text itself with the pre-training model, which actually loses some useful prior information. Summary of the invention
[0012] The purpose of the present invention is to provide a Mask text matching method based on multi-task learning, comprising the following steps:
[0013] 1) Obtain at least two texts to be matched;
[0014] 2) extracting features of the text to be matched to obtain text word features of each text to be matched;
[0015] 3) Establish a text matching model based on BERT;
[0016] 4) Input the text word features of all the texts to be matched into the text matching model to obtain the matching results of different texts to be matched.
[0017] Furthermore, the step of extracting features from the text to be matched includes: word segmentation, part-of-speech tagging, named entity recognition, semantic role tagging, and dependency syntactic analysis.
[0018] Furthermore, the text word features include one or more of part-of-speech features, named entity features, semantic role features, and dependency syntactic relationship features.
[0019] Furthermore, the BERT-based text matching model includes an embedding input layer, a multi-head attention layer, a forward propagation layer and an output layer.
[0020] Further, the step of obtaining matching results of different to-be-matched texts includes:
[0021] a) Use the embedding input layer to transform the text word features to obtain the embedding input X, and convert the embedding input X into feature components Q = XW Q , characteristic component K = XW K , characteristic component V = XW V ; W Q , W K , W V are the weights corresponding to different feature components;
[0022] b) Use the multi-head attention layer to process the feature components of the embedding input X to obtain the multi-head attention layer processing result MultiHead(Q, K, V), that is:
[0023] MultiHead(Q,K,V)=Concat(head 1 , ..., head h )W o (1)
[0024] Where W O is the weight;
[0025] Among them, the parameter head i As shown below:
[0026] head i =Attention(QW i Q , KW i k , VWi v ), i = 1, 2, ..., h (2)
[0027] Attention(QW i Q , KW i k , VW i v )=Mask*Attention(Q,K,V) (3)
[0028]
[0029] In the formula, softmax is the activation function; d k Indicates the dimension of the word vector, in order to prevent the softmax input value from being too large, causing the derivative to be close to 0. Mask represents mask; Attention (QW i Q , KW i k , VW i v ), Attention(Q, K, V) is an intermediate parameter; h is an integer greater than 0;
[0030] c) Use the forward propagation layer to process the multi-head attention layer processing result MultiHead(Q, K, V) to obtain the forward propagation layer processing result x, that is:
[0031] x=norm(X+MultiHead(Q,K,V))(5)
[0032] d) Using the output layer to process the processing result x of the forward propagation layer, the output of the BERT-based text matching model is obtained as the matching result of different texts to be matched;
[0033] The output of the BERT-based text matching model is as follows:
[0034] FFN(x)=max(0,xW 1 +b 1 )W 2 +b 2 (6)
[0035] Where W 1 , W 2 is the weight; b 1 , b 2 is the bias; FFN(x) is the output.
[0036] Furthermore, the embedding input X=x 1 +x2 ;
[0037] Among them, the input component x1 and the input component x 2 They are as follows:
[0038] X 1 =E tok +E seg +E pos (7)
[0039] x 2 =embedding 1(pos)+embedding2(ner)+embedding3(seg)(8)
[0040] In the formula, E tok 、E seg 、E pos They represent the Token Embedding encoding, PositionEmbeddings encoding and SegmentEmbeddings encoding of text word features respectively; embedding 1, embedding 2, embedding 3 represent the embedding layers of part of speech, named entity and semantic role; pos, ner, seg represent the part of speech, named entity and semantic role encoding of the input text.
[0041] Furthermore, the mask Mask is a 0-1 variable, the mask Mask=1 for words in the same position of different to-be-matched texts, and the mask Mask=0 for words in different positions of different to-be-matched texts.
[0042] Furthermore, the output of the BERT-based text matching model includes a sequence output and a vector output; the vector output is a classification vector, and the sequence output is a part-of-speech tagging vector. The classification vector includes semantically identical and semantically different.
[0043] Furthermore, the BERT-based text matching model is pre-trained;
[0044] The criterion for the end of pre-training is the convergence of the loss function Loss;
[0045] The loss function Loss is as follows:
[0046] Loss=Loss nll +Loss pos-tag (9)
[0047] In the formula, Loss nll is the classification vector loss function; Loss pos-tag is the loss function for part-of-speech tagging;
[0048] Among them, the classification vector loss function Loss nll As shown below:
[0049]
[0050] In the formula, n is the number of training samples; j is the jth sample; Z is the number of categories; c is the cth category; h is j,c represents the probability that the jth sample belongs to the cth category; y j,c Indicates whether the jth sample belongs to the cth category; y j,c =1 means the jth sample belongs to the cth category; y j,c =0 means that the jth sample does not belong to the cth category;
[0051] Part-of-speech tagging loss function Loss pos-tag As shown below:
[0052]
[0053] Where P 1 , P 2 , P 3 , P n is the score of the first, second, and nth possible part-of-speech tagging sequence corresponding to a sample; P real_path is the score of the true part-of-speech tag sequence corresponding to a sample.
[0054] A computer-readable storage medium storing a computer program;
[0055] When the computer program is executed by a processor, the steps of the method are implemented.
[0056] The technical effect of the present invention is unquestionable. The present invention solves the problem of difficulty in capturing differences between texts in scenarios such as intelligent interaction, natural language understanding, and similar sentence extraction.
[0057] In order to solve the problems of complex short text matching models and large parameters, the present invention proposes an idea of constructing a simplified Mask matrix model based on data characteristics. While simplifying the model, it can also amplify the differences between the texts to be matched, thereby enhancing the generalization ability of the final model training.
[0058] Considering that the difference before text matching is relatively small, this difference can be reflected in the language features of part of speech and syntactic structure. At the input end, the present invention embeds features such as syntax and entities to increase the semantic information of the model input.
[0059] General text matching mainly uses sentence vectors for matching. The present invention introduces multi-task learning to learn the differences between the parts of speech of the texts to be matched from the word granularity, thereby enhancing the generalization ability of the model. BRIEF DESCRIPTION OF THE DRAWINGS
[0060] Figure 1 Matching flowchart for text;
[0061] Figure 2 Flowchart for text feature mining;
[0062] Figure 3 This is the Mask schematic diagram. DETAILED DESCRIPTION
[0063] The present invention is further described below in conjunction with the embodiments, but it should not be understood that the above subject matter of the present invention is limited to the following embodiments. Without departing from the above technical ideas of the present invention, various substitutions and changes are made according to the common technical knowledge and customary means in the art, which should all be included in the protection scope of the present invention.
[0064] Embodiment 1:
[0065] See also Figures 1 to 3 , a Mask text matching method based on multi-task learning, comprising the following steps:
[0066] 1) Obtain at least two texts to be matched;
[0067] 2) extracting features of the text to be matched to obtain text word features of each text to be matched;
[0068] 3) Establish a text matching model based on BERT;
[0069] 4) Input the text word features of all the texts to be matched into the text matching model to obtain the matching results of different texts to be matched, and the matching results include semantic similarity and semantic dissimilarity.
[0070] The step of extracting features from the text to be matched includes a series of natural language processing operations such as word segmentation, part-of-speech tagging, named entity recognition, semantic role labeling, and dependency syntax analysis. The method proposed in the present invention uses the natural language processing technology provided by the "Language Technology Platform (LTP)" developed by the Social Computing and Information Retrieval Research Center of Harbin Institute of Technology to perform the above operations.
[0071] This method uses the named entity recognition technology provided by the language technology platform of Harbin Institute of Technology and the iterative heuristic method for named entity recognition. The latter is to obtain the maximum noun phrase by merging connected nouns, where the part of speech of the noun can only be {ni, nh, ns, nz, j}, representing the name of the institution, the name of the person, the name of the geographic location, other proper nouns and abbreviations respectively.
[0072] The text word features include one or more of part-of-speech features, named entity features, semantic role features, and dependency syntactic relationship features.
[0073] The BERT-based text matching model includes an embedding input layer, a multi-head attention layer, a forward propagation layer, and an output layer.
[0074] The steps of obtaining the matching results of different to-be-matched texts include:
[0075] 1) Use the embedding input layer to transform the text word features to obtain the embedding input X, and convert the embedding input X into feature components Q = XW Q , characteristic component K = XW K , characteristic component V = XW V ; W Q , W K , W V are the weights corresponding to different feature components;
[0076] 2) Use the multi-head attention layer to process the feature components of the embedding input X to obtain the multi-head attention layer processing result MultiHead(Q, K, V), that is:
[0077] MultiHead(Q,K,V)=Concat(head 1 , ..., head h )W o (1)
[0078] Where W O is the weight;
[0079] Among them, the parameter head i As shown below:
[0080] head i =Attention(QW i Q , KW i k , VW i v ), i = 1, 2, ..., h (2)
[0081] Attention(QW i Q , KW i k , VW i v )=Mask*Attention(Q,K,V) (3)
[0082]
[0083] In the formula, softmax is the activation function; d k Indicates the dimension of the word vector, in order to prevent the softmax input value from being too large, causing the derivative to be close to 0. Mask represents mask; Attention (QW i Q , KW i k , VW i v ), Attention(Q, K, V) is an intermediate parameter; h is an integer greater than 0;
[0084] 3) Use the forward propagation layer to process the multi-head attention layer processing result MultiHead(Q, K, V) to obtain the forward propagation layer processing result x, that is:
[0085] x=norm(X+MultiHead(Q,K,V))(5)
[0086] 4) Using the output layer to process the processing result x of the forward propagation layer, the output of the BERT-based text matching model is obtained as the matching result of different texts to be matched;
[0087] The output of the BERT-based text matching model is as follows:
[0088] FFN(x)=max(0,xW 1 +b 1 ) W 2+b 2 (6)
[0089] Where W 1 , W 2 is the weight; b 1 , b 2 is the bias. FFN(x) is the output.
[0090] The embedding input is X=x1+x 2 ;
[0091] Among them, the input component x1 and the input component x 2 They are as follows:
[0092] X 1 =E tok +E seg +E pos (7)
[0093] x 2=embeddingl(pos)+embedding2(ner)+embedding3(seg)(8)
[0094] In the formula, E tok 、E seg 、E pos They respectively represent the Token Embedding encoding, PositionEmbeddings encoding and SegmentEmbeddings encoding of text word features; embedding1, embedding2, embedding3 represent the embedding layers of part of speech, named entity and semantic role; pos, ner, seg represent the part of speech, named entity and semantic role encoding of the input text.
[0095] The mask Mask is a 0-1 variable, where the mask Mask=1 for words in the same position of different to-be-matched texts, and the mask Mask=0 for words in different positions of different to-be-matched texts.
[0096] The output of the BERT-based text matching model includes a sequence output and a vector output; the vector output is a classification vector, and the sequence output is a part-of-speech tagging vector. The classification vector includes semantically identical and semantically different.
[0097] The BERT-based text matching model is pre-trained;
[0098] The criterion for the end of pre-training is the convergence of the loss function Loss;
[0099] The loss function Loss is as follows:
[0100] Loss=Loss nll +Loss pos-tag (9)
[0101] In the formula, Loss nll is the classification vector loss function; Loss pos-tag is the loss function for part-of-speech tagging;
[0102] Among them, the classification vector loss function Loss nll As shown below:
[0103]
[0104] In the formula, n is the number of training samples; j is the jth sample; Z is the number of categories; c is the cth category; h is j,c represents the probability that the jth sample belongs to the cth category; y j,c Indicates whether the jth sample belongs to the cth category; y j,c=1 means the jth sample belongs to the cth category; y j,c =0 means that the jth sample does not belong to the cth category;
[0105] Part-of-speech tagging loss function Loss pos-tag The calculation principle is as follows:
[0106] For any sample, the category sequence of part-of-speech tags may be:
[0107] Part-of-speech tagging sequence 1: START NB NI NE OO
[0108] Part-of-speech tagging sequence 2: START NB NE OOO
[0109] Part-of-speech tagging sequence 3: START O NB NE OO
[0110] Part-of-speech tagging sequence 4: START VB VI VE OO
[0111] Part-of-speech tag sequence n: START NB NE VB VE O
[0112] Each possible path has a score P i , there are N paths in total, then the total score is:
[0113] P total =P 1 +P 2 +P 3 +…+P n
[0114]
[0115] During the training process, the parameter values of the model will be continuously updated with the iterations of the training process, making the proportion of the true path larger and larger.
[0116] A computer-readable storage medium storing a computer program;
[0117] When the computer program is executed by a processor, the steps of the method are implemented.
[0118] Embodiment 2:
[0119] See also Figures 1 to 3 , a Mask text matching method based on multi-task learning, including the following contents:
[0120] 1) The text is processed by language analysis tools to obtain features such as part of speech, named entities, semantic roles, and dependency syntactic relationships.
[0121] 2) According to the input text to be matched, compare the differences between the text pairs, mark the positions where the words are the same and the positions where the words are different, and set the positions where the words are the same to 0 in the Mask matrix, otherwise set them to 1.
[0122] The embedding input of BERT can be expressed as a combination of Token Embedding, Segmentation Embedding and Position Embedding x 1 :
[0123] X 1 =E word =E tok +E seg +E pos
[0124] Other language features can be represented as x through the embedding layer 2 :
[0125] x 2 =embedding l(pos)+embedding2(ner)+embedding3(seg)
[0126] The final input x = x1 + x 2
[0127] Convert input X to Q, K, V:
[0128] Q=XW Q , K = XW K , V = XW V
[0129] Attention calculation formula:
[0130]
[0131] Here, in order to make the model pay attention to the inconsistencies in the text to be matched, we can obtain the Mask matrix through simple processing in the data processing stage, so the model does not need to pay attention to the full amount of attention, but only needs to pay attention to the characters with inconsistent text:
[0132] Attention=Mask*Attention(Q, K, V)
[0133] Multi-head attention layer:
[0134] MultiHead(Q,K,V)=Concat(head 1 , ..., head h )Wo
[0135] in:
[0136] head i =Attention(QW i Q , KW i k , VW i v ), i = 1, 2, ..., h
[0137] Forward propagation layer:
[0138] FFN(x)=max(0,xW 1 +b 1 )W 2 +b 2
[0139] Then the output is:
[0140] x=norm(X+MultiHead(Q,K,V))
[0141] Final encoding r The output:
[0142] Y=FFN(x)
[0143] The output includes sequence output and vector output. In this embodiment, the vector output is used as the classification vector, and the sequence output is used as the second task part-of-speech tagging vector. For the classification vector, we can get the first loss function Loss KL for:
[0144]
[0145] The loss function of part-of-speech tagging is: pos-tag , the final loss function will be:
[0146] Loss=Loss nll +Loss pos-tag
[0147] Embodiment 3:
[0148] A Mask text matching method based on multi-task learning includes the following steps:
[0149] 1) Obtain at least two texts to be matched;
[0150] 2) extracting features of the text to be matched to obtain text word features of each text to be matched;
[0151] 3) Establish a text matching model based on BERT;
[0152] 4) Input the text word features of all the texts to be matched into the text matching model to obtain the matching results of different texts to be matched.
[0153] Embodiment 4:
[0154] A Mask text matching method based on multi-task learning, the main content of which is shown in Example 3, wherein the step of extracting features from the text to be matched includes: word segmentation, part-of-speech tagging, named entity recognition, semantic role labeling, and dependency syntactic analysis.
[0155] Embodiment 5:
[0156] A Mask text matching method based on multi-task learning, the main content of which is shown in Example 3, wherein the text word features include one or more of part-of-speech features, named entity features, semantic role features, and dependency syntactic relationship features.
[0157] Embodiment 6:
[0158] A Mask text matching method based on multi-task learning, the main content of which is shown in Example 3, wherein the BERT-based text matching model includes an embedding input layer, a multi-head attention layer, a forward propagation layer and an output layer.
[0159] Embodiment 7:
[0160] A Mask text matching method based on multi-task learning, the main content of which is shown in Example 3, wherein the step of obtaining matching results of different texts to be matched includes:
[0161] 1) Use the embedding input layer to transform the text word features to obtain the embedding input X, and convert the embedding input X into feature components Q = XW Q , characteristic component K = XW K , characteristic component V = XW V ; W Q , W K , W V are the weights corresponding to different feature components;
[0162] 2) Use the multi-head attention layer to process the feature components of the embedding input X to obtain the multi-head attention layer processing result MultiHead(Q, K, V), that is:
[0163] MultiHead(Q,K,V)=Concat(head 1 , ..., head h)W o (1)
[0164] Where W O is the weight;
[0165] Among them, the parameter head i As shown below:
[0166] head i =Attention(QW i Q , KW i k , VW i v ), i = 1, 2, ..., h (2)
[0167] Attention(QW i Q , KW i k , VW i v )=Mask*Attention(Q,K,V) (3)
[0168]
[0169] In the formula, softmax is the activation function; d k Indicates the dimension of word vector; Mask indicates mask; Attention (QW i Q , KW i k , VW i v ), Attention(Q, K, V) is an intermediate parameter; h is an integer greater than 0;
[0170] 3) Use the forward propagation layer to process the multi-head attention layer processing result MultiHead(Q, K, V) to obtain the forward propagation layer processing result x, that is:
[0171] x=norm(X+MultiHead(Q,K,V))(5)
[0172] 4) Using the output layer to process the processing result x of the forward propagation layer, the output of the BERT-based text matching model is obtained as the matching result of different texts to be matched;
[0173] The output of the BERT-based text matching model is as follows:
[0174] FFN(x)=max(0,xW 1 +b 1)W 2 +b 2 (6)
[0175] Where W 1 , W 2 is the weight; b 1 , b 2 is the bias; FFN(x) is the output.
[0176] Embodiment 8:
[0177] A Mask text matching method based on multi-task learning, the main content of which is shown in Example 3, wherein the embedding input X=x1+x 2 ;
[0178] Among them, the input component x1 and the input component x 2 They are as follows:
[0179] X 1 =E tok +E seg +E pos (7)
[0180] x 2 =embedding 1(pos)+embedding2(ner)+embedding3(seg)(8)
[0181] In the formula, E tok 、E seg 、E pos They respectively represent the Token Embedding encoding, PositionEmbeddings encoding and SegmentEmbeddings encoding of text word features; embedding1, embedding2, embedding3 represent the embedding layers of part of speech, named entity and semantic role; pos, ner, seg represent the part of speech, named entity and semantic role encoding of the input text.
[0182] Embodiment 9:
[0183] A Mask text matching method based on multi-task learning, the main content of which is shown in Example 3, wherein the mask Mask is a 0-1 variable, the mask Mask of the same position of words in different to-be-matched texts is 1, and the mask Mask of different positions of words in different to-be-matched texts is 0.
[0184] Embodiment 10:
[0185] A Mask text matching method based on multi-task learning, the main content of which is shown in Example 3, wherein the output of the BERT-based text matching model includes sequence output and vector output; the vector output is a classification vector, and the sequence output is a part-of-speech tagging vector; the classification vector includes semantically identical and semantically different.
[0186] Embodiment 11:
[0187] A Mask text matching method based on multi-task learning, the main content of which is shown in Example 3, wherein the BERT-based text matching model has been pre-trained;
[0188] The criterion for the end of pre-training is the convergence of the loss function Loss;
[0189] The loss function Loss is as follows:
[0190] Loss=Loss nll +Loss pos-tag (9)
[0191] In the formula, Loss nll is the classification vector loss function; Loss pos-tag is the loss function for part-of-speech tagging;
[0192] Among them, the classification vector loss function Loss nll As shown below:
[0193]
[0194] In the formula, n is the number of training samples; j is the jth sample; Z is the number of categories; c is the cth category; h is j,c represents the probability that the jth sample belongs to the cth category; y j,c Indicates whether the jth sample belongs to the cth category; y j,c =1 means the jth sample belongs to the cth category; y j,c =0 means that the jth sample does not belong to the cth category;
[0195] Part-of-speech tagging loss function Loss pos-tag As shown below:
[0196]
[0197] Where P 1 , P 2 , P 3 , P n is the score of the first, second, and nth possible part-of-speech tagging sequence corresponding to a sample; P real-path is the score of the true part-of-speech tag sequence corresponding to a sample.
[0198] Embodiment 12:
[0199] A computer-readable storage medium stores a computer program; when the computer program is executed by a processor, the steps of the method described in Examples 1-11 are implemented.
Claims
1. A Mask text matching method based on multi-task learning, characterized in that: The following steps are involved: 1) Obtain at least two texts to be matched; 2) extracting features of the text to be matched to obtain text word features of each text to be matched; 3) Establish a text matching model based on BERT; 4) Inputting the text word features of all the texts to be matched into the text matching model to obtain the matching results of different texts to be matched; The steps of obtaining the matching results of different to-be-matched texts include: s1) Use the embedding input layer to transform the text word features to obtain the embedding input X, and convert the embedding input X into feature components Q = XW Q , characteristic component K = XW K , characteristic component V = XW V ; W Q , W K , W V are the weights corresponding to different feature components; s2) Use the multi-head attention layer to process the feature components of the embedding input X to obtain the multi-head attention layer processing result MultiHead(Q,K,V), that is: MultiHead(Q,K,V)=Concat(head1,...,head h )W O (1) Where W O is the weight; Among them, the parameter head i As shown below: head i =Attention(QW i Q ,KW i K ,VW i V ),i=1,2,...,h (2) Attention(QW i Q ,KW i K ,VW i V )=Mask*Attention(Q,K,V) (3) In the formula, softmax is the activation function; d k Indicates the dimension of word vector; Mask indicates mask; Attention (QW i Q ,KW i K ,VW i V ), Attention(Q,K,V) is an intermediate parameter; h is an integer greater than 0; s3) Use the forward propagation layer to process the multi-head attention layer processing result MultiHead(Q,K,V) to obtain the forward propagation layer processing result x, that is: x=norm(X+MultiHead(Q,K,V)) (5) s4) using the output layer to process the forward propagation layer processing result x, and obtain the BERT-based text matching model output as the matching result of different texts to be matched; The output of the BERT-based text matching model is as follows: FFN(x)=max(0,xW1+b1)W2+b2 (6) Where W1 and W2 are weights; b1 and b2 are biases; FFN(x) is the output; The embedding input X=x1+x2; Among them, the input component x1 and the input component x2 are as follows: X1=E tok +E seg +E pos (7) x2=embedding1(pos)+embedding2(ner)+embedding3(seg) (8) In the formula, E tok 、E seg 、E pos They respectively represent the Token Embedding encoding, PositionEmbeddings encoding and SegmentEmbeddings encoding of text word features; embedding1, embedding2, embedding3 represent the embedding layers of part of speech, named entity and semantic role; pos, ner, seg represent the part of speech, named entity and semantic role encoding of the input text.
2. According to a Mask text matching method based on multi-task learning according to claim 1, it is characterized in that: The step of extracting features from the text to be matched includes: word segmentation, part-of-speech tagging, named entity recognition, semantic role tagging, and dependency syntactic analysis.
3. According to a Mask text matching method based on multi-task learning according to claim 1, it is characterized in that: The text word features include one or more of part-of-speech features, named entity features, semantic role features, and dependency syntactic relationship features.
4. According to a Mask text matching method based on multi-task learning according to claim 1, it is characterized in that: The BERT-based text matching model includes an embedding input layer, a multi-head attention layer, a forward propagation layer, and an output layer.
5. According to a Mask text matching method based on multi-task learning according to claim 1, it is characterized in that: The mask Mask is a 0-1 variable, where the mask Mask=1 for words in the same position of different to-be-matched texts, and the mask Mask=0 for words in different positions of different to-be-matched texts.
6. According to a Mask text matching method based on multi-task learning according to claim 1, it is characterized in that: The output of the BERT-based text matching model includes sequence output and vector output; the vector output is a classification vector, and the sequence output is a part-of-speech tagging vector; the classification vector includes semantically identical and semantically different.
7. The Mask text matching method based on multi-task learning according to claim 1 is characterized in that: The BERT-based text matching model is pre-trained; The criterion for the end of pre-training is the convergence of the loss function Loss; The loss function Loss is as follows: Loss=Loss nll +Loss pos-tag (9) In the formula, Loss nll is the classification vector loss function; Loss pos-tag is the loss function for part-of-speech tagging; Among them, the classification vector loss function Loss nll As shown below: In the formula, n is the number of training samples; j is the jth sample; Z is the number of categories; c is the cth category; h is j,c represents the probability that the jth sample belongs to the cth category; y j,c Indicates whether the jth sample belongs to the cth category; y j,c =1 means the jth sample belongs to the cth category; y j,c =0 means that the jth sample does not belong to the cth category; Part-of-speech tagging loss function Loss pos-tag As shown below: In the formula, P1, P2, P3, P n is the score of the first, second, and nth possible part-of-speech tagging sequence corresponding to a sample; P real-path is the score of the true part-of-speech tag sequence corresponding to a sample.
8. A computer-readable storage medium, characterized in that: The computer readable medium stores a computer program; When the computer program is executed by a processor, the steps of the method according to any one of claims 1 to 7 are implemented.
Citation Information
Patent Citations
BERT-improved text semantic matching device, system and method and storage medium
CN113239700A
Track traffic specification entity recognition method based on directory theme classification
CN113642330A
Method and apparatus for training text processing model, computer device and storage medium
WO2022121251A1
