A text matching method, device, system and storage medium
By encoding and analyzing interaction vectors of sentence pairs, keyword information pairs, and intent information pairs, and combining graph neural networks and multi-view linear layers, the problem of low text matching accuracy caused by relying on pure semantic information in existing technologies is solved, and stronger text matching accuracy is achieved.
Patent Information
- Application Number
- CN202310077974.9
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2023-02-07
- Publication Date
- 2025-11-28
- Estimated Expiration
- 2043-02-07
AI Technical Summary
Existing text matching methods mainly rely on the pure semantic information of the text, resulting in insufficient matching accuracy.
By encoding sentence pairs, keyword information pairs, and intent information pairs, original sentence vector pairs, keyword vector pairs, and intent vector pairs are generated. Interactive vector analysis and score vector calculation are then performed. By combining graph neural networks and multi-view linear layers, text matching from different perspectives can be achieved.
It significantly improves the accuracy of text matching, achieving stronger performance than relying solely on pure semantic information by extracting pure semantic information, keywords, and additional information about intent from sentences.
Smart Images

Figure CN116303887B_ABST
Abstract
Description
TECHNICAL FIELD
[0001] The present application mainly relates to the technical field of language processing, and in particular to a text matching method, device, system and storage medium. BACKGROUND
[0002] Text matching is an important and challenging task in the field of natural language processing, aiming to describe the relationship between two texts, which can be applied to search engines, recommendation systems, question and answer systems and other scenarios. In the existing text matching methods, most text encoders mainly realize the general vector representation of the text, only utilizing the pure semantic information of the text pair, which ignores other available rich information, thus resulting in insufficient accuracy of text matching. SUMMARY
[0003] The present application mainly relates to the technical field of language processing, and in particular to a text matching method, device, system and storage medium.
[0004] The technical scheme for solving the above technical problem is as follows: a text matching method, comprising the following steps:
[0005] Import a plurality of sentence pairs and a keyword information pair and an intent information pair corresponding to each of the sentence pairs, and encode each of the sentence pairs, the keyword information pair corresponding to each of the sentence pairs, and the intent information pair to obtain a sentence original vector pair of each of the sentence pairs, a keyword vector pair corresponding to each of the sentence pairs, and an intent vector pair;
[0006] According to the sentence original vector pair of each of the sentence pairs, the keyword vector pair corresponding to each of the sentence pairs, and the intent vector pair, an interaction vector is analyzed to obtain an interaction vector of each of the sentence pairs;
[0007] According to the interaction vector of each of the sentence pairs, a score vector is calculated to obtain a plurality of score vectors of each of the sentence pairs;
[0008] According to the plurality of score vectors of each of the sentence pairs, the accuracy of text matching is analyzed to obtain the accuracy of text matching, and the accuracy of text matching is taken as the result of text matching.
[0009] Another technical scheme for solving the above technical problem is as follows: a text matching device, comprising:
[0010] The encoding module is used for importing a plurality of sentence pairs and keyword information pairs and intention information pairs corresponding to each of the sentence pairs, and encoding each of the sentence pairs, the keyword information pair corresponding to each of the sentence pairs and the intention information pair to obtain a sentence original vector pair of each of the sentence pairs, a keyword vector pair corresponding to each of the sentence pairs and an intention vector pair.
[0011] The interaction vector analysis module is used for analyzing the interaction vector according to the sentence original vector pair of each of the sentence pairs, the keyword vector pair corresponding to each of the sentence pairs and the intention vector pair to obtain an interaction vector of each of the sentence pairs.
[0012] The score vector calculation module is used for calculating the score vector according to the interaction vector of each of the sentence pairs to obtain a plurality of score vectors of each of the sentence pairs.
[0013] The text matching result obtaining module is used for analyzing the text matching accuracy according to the plurality of score vectors of each of the sentence pairs to obtain the text matching accuracy, and taking the text matching accuracy as the result of the text matching.
[0014] Based on the above-mentioned text matching method, the application further provides a text matching system.
[0015] Another technical solution for solving the above technical problems is as follows: a text matching system comprising a memory, a processor and a computer program stored in the memory and executable on the processor, when the processor executes the computer program, the text matching method as described above is realized.
[0016] Based on the above-mentioned text matching method, the application further provides a computer readable storage medium.
[0017] Another technical solution for solving the above technical problems is as follows: a computer readable storage medium, the computer readable storage medium stores a computer program, when the computer program is executed by a processor, the text matching method as described above is realized.
[0018] The beneficial effects of this invention are as follows: By encoding sentence pairs, keyword information pairs, and intent information pairs, original sentence vector pairs, keyword vector pairs, and intent vector pairs are obtained; interaction vectors are obtained based on the interaction vector analysis of the original sentence vector pairs, keyword vector pairs, and intent vector pairs; a score vector is calculated based on the score vector of the interaction vector; and the text matching result is obtained based on the text matching accuracy analysis of the score vector. This not only extracts the pure semantic information of the sentence but also supplements the sentence text with additional information such as keywords and intent, realizing text matching from different perspectives. Compared with existing technologies, it achieves stronger performance than relying solely on pure semantic information and can judge text matching from different perspectives, significantly improving the accuracy of text matching. Attached Figure Description
[0019] Figure 1 A flowchart illustrating a text matching method provided in an embodiment of the present invention;
[0020] Figure 2 This is a block diagram of a text matching device provided in an embodiment of the present invention. Detailed Implementation
[0021] The principles and features of the present invention are described below with reference to the accompanying drawings. The examples given are only for explaining the present invention and are not intended to limit the scope of the present invention.
[0022] Figure 1 This is a flowchart illustrating a text matching method provided in an embodiment of the present invention.
[0023] like Figure 1 As shown, a text matching method includes the following steps:
[0024] Import multiple sentence pairs and corresponding keyword and intent information pairs. Encode each sentence pair, its corresponding keyword and intent information pairs to obtain the original sentence vector pairs, keyword vector pairs, and intent vector pairs for each sentence pair.
[0025] The interaction vectors of each sentence pair are obtained by analyzing the original sentence vector pairs, the keyword vector pairs and intent vector pairs corresponding to each sentence pair.
[0026] The score vectors for each sentence pair are calculated based on the interaction vectors of each sentence pair, resulting in multiple score vectors for each sentence pair.
[0027] The text matching accuracy is analyzed based on the multiple score vectors of each sentence pair to obtain the text matching accuracy, and the text matching accuracy is used as the result of text matching.
[0028] It should be understood that the data input into the encoder, that is, the plurality of sentence pairs and the keyword information pairs and the intention information pairs corresponding to each of the sentence pairs, come from the MPTS dataset, and each input sample is a sentence pair text, keyword information (that is, the keyword information pair) and intention information (that is, the intention information pair) of the sentence pair. Among them, the keyword information represents the factual information that should be strictly matched, such as actions, entities, and events; the intention information represents abstract concepts and ideas, which can be interpreted as various expressions.
[0029] In the above embodiment, the sentence original vector pair, the keyword vector pair and the intention vector pair are obtained by encoding the sentence pair, the keyword information pair and the intention information pair, the interaction vector is obtained by analyzing the interaction vector according to the sentence original vector pair, the keyword vector pair and the intention vector pair, the score vector is calculated according to the score vector of the interaction vector, and the result of text matching is obtained by analyzing the text matching accuracy of the score vector. Not only the pure semantic information of the sentence is extracted, but also the additional information of the keyword and intention of the sentence is supplemented to the sentence text, realizing text matching from different perspectives, and compared with the prior art, realizing stronger performance than relying on pure semantic information, and at the same time, the text matching can be judged from different perspectives, which significantly improves the accuracy of text matching.
[0030] Optionally, as an embodiment of the present application, the sentence pair includes a first sentence and a second sentence, the keyword information pair includes keyword information corresponding to the first sentence and keyword information corresponding to the second sentence, and the intention information pair includes intention information corresponding to the first sentence and intention information corresponding to the second sentence.
[0031] The process of encoding each of the sentence pairs, the keyword information pair corresponding to each of the sentence pairs, and the intention information pair includes:
[0032] Each of the first sentence, each of the second sentence, the keyword information and the intention information corresponding to each of the first sentence, and the keyword information and the intention information corresponding to each of the second sentence is encoded by the text encoder, and the corresponding sentence original vector of each of the first sentence, the sentence original vector of each of the second sentence, the keyword vector and the intention vector corresponding to each of the first sentence, and the keyword vector and the intention vector corresponding to each of the second sentence are obtained.
[0033] The sentence original vector pair of the sentence pair includes the sentence original vector of the first sentence and the sentence original vector of the second sentence.
[0034] The keyword vector corresponding to the sentence pair comprises the keyword vector corresponding to the first sentence and the keyword vector corresponding to the second sentence.
[0035] The intent vector pair corresponding to the sentence pair comprises the intent vector corresponding to the first sentence and the intent vector corresponding to the second sentence.
[0036] Preferably, the text encoder can be a BERT encoder.
[0037] It should be understood that, on the basis of the double-tower structure encoder, the left end and the right end are respectively given a sentence text (i.e. the first sentence and the second sentence) and its keyword information (i.e. the keyword information corresponding to the first sentence and the keyword information corresponding to the second sentence) and intent information (i.e. the intent information corresponding to the first sentence and the intent information corresponding to the second sentence), and three text encoders are used to encode them to generate three vector representations of the sentence text (i.e. the sentence original vector of the first sentence and the sentence original vector of the second sentence), the keyword information (i.e. the keyword vector corresponding to the first sentence and the keyword vector corresponding to the second sentence) and the intent information (i.e. the intent vector corresponding to the first sentence and the intent vector corresponding to the second sentence).
[0038] Specifically, assuming that the sentence text (i.e. the first sentence) input at the left end of the double-tower structure is represented by Text_a, the keyword information (i.e. the keyword information corresponding to the first sentence) is represented by Keyword_a, and the intent information (i.e. the intent information corresponding to the first sentence) is represented by Intent_a, then:
[0039] Text_a = {a1, a2,..., an} (1) la}
[0040] Keyword_a = {ka1, ka2,..., km} (2) lm}
[0041] Intent_a = {Ia1, Ia2,..., In} (3) ln}
[0042] wherein a i , ka m , Ia n represent the i-th, m-th, and n-th word in the sequence of Text_a, Keyword_a, and Intent_a, respectively; la, lm, and ln represent the sequence length.
[0043] They are encoded by three same text encoders, such as BERT encoders, and the obtained vector representations are respectively:
[0044] output_a = encoder(Text_a)
[0045] output_kw_a = encoder(Keyword_a)
[0046] output_it_a = encoder(Intent_a)
[0047] Wherein, output_a, output_kw_a, output_it_a are respectively the vector representations of Text_a, Keyword_a, Intent_a after being encoded by the text encoder encoder (i.e. the sentence original vector of the first sentence, the keyword vector corresponding to the first sentence, and the intention vector corresponding to the first sentence).
[0048] Similarly, the sentence text input at the right end of the double tower structure (i.e. the second sentence) is represented by Text_b, the keyword information (i.e. the keyword information corresponding to the second sentence) is represented by Keyword_b, and the intention information (i.e. the intention information corresponding to the second sentence) is represented by Intent_b, then:
[0049] Text_b = {b1, b2,..., b lb}
[0050] Keyword_b = {kb1, kb2,..., kb lp}
[0051] Intent_b = {Ib1, Ib2,..., Ib lq}
[0052] Wherein, b j , kb p , Ib q represent the jth, pth, qth word in the sequence of Text_b, Keyword_b, Intent_b respectively; lb, lp, lq represent the sequence length.
[0053] They are encoded by three same text encoders, such as BERT encoders, and the obtained vector representations are respectively:
[0054] output_b = encoder(Text_b)
[0055] output_Kw_b = encoder(Keyword_b)
[0056] output_It_b = encoder(Intent_b)
[0057] Wherein output_b, output_Kw_b, output_It_b are respectively the vector representation of Text_b, Keyword_b, Intent_b after encoding by the text encoder encoder (i.e. the sentence original vector of the second sentence, the keyword vector corresponding to the second sentence and the intent vector corresponding to the second sentence).
[0058] In the above embodiment, the sentence pair, the keyword information pair and the intent information pair are encoded to obtain the sentence original vector pair, the keyword vector pair and the intent vector pair, the pure semantic information of the sentence is extracted, and the additional information of the keyword and the intent of the sentence is supplemented to the sentence text, the text matching under different perspectives is realized, and compared with the prior art, the performance is stronger than relying on pure semantic information alone, the text matching can be judged from different perspectives, and the accuracy of text matching is significantly improved.
[0059] Optionally, as an embodiment of the present application, the process of obtaining the interaction vector of each sentence pair according to the sentence original vector pair of each sentence pair, the keyword vector pair corresponding to each sentence pair and the intent vector pair includes:
[0060] According to the sentence original vector of each first sentence, the sentence original vector of each second sentence, the keyword vector and the intent vector corresponding to each first sentence and the keyword vector and the intent vector corresponding to each second sentence, the aggregation analysis is performed to obtain the aggregation vector of each first sentence and the aggregation vector of each second sentence;
[0061] The sentence original vector and the aggregation vector of each first sentence and the sentence original vector and the aggregation vector of each second sentence are spliced to obtain the fusion vector of each first sentence and the fusion vector of each second sentence;
[0062] Based on the first formula, the fusion vector of each first sentence and the fusion vector of each second sentence are used to calculate the interaction vector to obtain the interaction vector of each sentence pair, and the first formula is:
[0063] output_crossing i = CrossingLayer(output_con_a i ,output_con_b i ),
[0064] wherein output_crossing i is the interaction vector of the ith sentence pair, CrossingLayer() is the crossing layer function, output_con_a i is the fusion vector of the ith first sentence, output_con_b i is the fusion vector of the ith second sentence.
[0065] It should be understood that the information from the three vector representations (i.e. the sentence original vector of the first sentence, the keyword vector corresponding to the first sentence, and the intent vector corresponding to the first sentence or the sentence original vector of the second sentence, the keyword vector corresponding to the second sentence, and the intent vector corresponding to the second sentence) is aggregated by using the graph neural network aggregator to generate a single output vector (i.e. the first aggregated vector or the second aggregated vector).
[0066] Specifically, the output vector (i.e. the sentence original vector of the first sentence or the sentence original vector of the second sentence) is spliced with the encoding result of the sentence text (i.e. the aggregated vector of the first sentence or the aggregated vector of the second sentence) to obtain a feature fusion vector (i.e. the fusion vector of the first sentence or the fusion vector of the second sentence), which is the final output of one sentence text in the MPTS dataset sentence pair, specifically:
[0067]
[0068] wherein output_con_a is the left end final output vector of the double tower structure (i.e. the fusion vector of the first sentence), is a splicing symbol.
[0069] Similarly, the right end final output vector of the double tower structure (i.e. the fusion vector of the second sentence) is output_con_b, is a splicing symbol:
[0070]
[0071] It should be understood that the final output of the MPTS dataset sentence pair (i.e. the fusion vector of the first sentence and the fusion vector of the second sentence) is interacted by the crossing layer to obtain an interaction vector representation of the sentence pair, specifically:
[0072] output_crossing = CrossingLayer(output_con_a, output_con_b),
[0073] Wherein, the output_crossing is the interaction information representation (that is, the interaction vector). The CrossingLayer(·) is the function representation of the crossing layer.
[0074] In the above embodiment, the interaction vector is analyzed according to the sentence original vector pair, the keyword vector pair and the intention vector pair, so that not only the pure semantic information of the sentence is extracted, but also the additional information of the keywords and the intention of the sentence is supplemented to the sentence text, the text matching under different perspectives is realized, and the accuracy of the text matching is significantly improved.
[0075] Optionally, as an embodiment of the present application, the process of performing aggregation analysis on the sentence original vector of each of the first sentences, the sentence original vector of each of the second sentences, the keyword vector and the intention vector corresponding to each of the first sentences, and the keyword vector and the intention vector corresponding to each of the second sentences, to obtain the aggregation vector of each of the first sentences and the aggregation vector of each of the second sentences comprises:
[0076] The correlation coefficients of the keyword information and the intention information of each of the first sentences and each of the second sentences are calculated according to the sentence original vector of each of the first sentences, the sentence original vector of each of the second sentences, the keyword vector and the intention vector corresponding to each of the first sentences, and the keyword vector and the intention vector corresponding to each of the second sentences, to obtain the keyword information correlation coefficient and the intention information correlation coefficient of each of the first sentences and the keyword information correlation coefficient and the intention information correlation coefficient of each of the second sentences;
[0077] The keyword information correlation coefficient and the intention information correlation coefficient of each of the first sentences and each of the second sentences are normalized to obtain the keyword information attention coefficient and the intention information attention coefficient of each of the first sentences and the keyword information attention coefficient and the intention information attention coefficient of each of the second sentences;
[0078] Based on the second formula, the first aggregation vector is calculated according to the keyword information attention coefficient and the intention information attention coefficient of each of the first sentences and the keyword vector and the intention vector corresponding to each of the first sentences, to obtain the aggregation vector of each of the first sentences, and the second formula is:
[0079]
[0080] Wherein, the output_agg_a i is the aggregation vector of the i-th first sentence, σ{} is a LeakyReLU activation function, is the keyword information attention coefficient of the i-th first sentence, and output_Kw_ai is the keyword vector corresponding to the i-th first sentence, is the intent information attention coefficient of the i-th first sentence, output_It_a i is the intent vector corresponding to the i-th first sentence.
[0081] Based on the third formula, the calculation of the second aggregation vector is performed according to the keyword information attention coefficient and the intent information attention coefficient of each second sentence and the keyword vector and the intent vector corresponding to each second sentence, to obtain the aggregation vector of each second sentence, the third formula is:
[0082]
[0083] wherein, output_agg_b i is the aggregation vector of the i-th second sentence, and σ{} is a LeakyReLU activation function, is the keyword information attention coefficient of the i-th second sentence, output_Kw_b i is the keyword vector corresponding to the i-th second sentence, is the intent information attention coefficient of the i-th second sentence, output_It_b i is the intent vector corresponding to the i-th second sentence.
[0084] It should be understood that the graph neural network aggregator can adopt most of the existing GNN aggregators, such as GCN, GraphSAGE and GAT. The present application adopts GAT because it generates a weighted average by assigning a learnable weight to the keyword information and the intent information, and shows the best performance.
[0085] It should be understood that the correlation coefficients (i.e., the keyword information correlation coefficient and the intent information correlation coefficient of the first sentence) are normalized to obtain the attention coefficients β ak , β ai (i.e., the keyword information attention coefficient and the intent information attention coefficient of the first sentence) by using the softmax(·) function, as follows:
[0086] β ak = softmax(e ak )
[0087] β ai = softmax(e ai ),
[0088] The correlation coefficients (i.e., the keyword information correlation coefficient and the intent information correlation coefficient of the second sentence) are normalized to obtain the attention coefficients β bk , βbi (i.e. the keyword information attention coefficient and the intention information attention coefficient of the second sentence), as follows:
[0089] β bk = softmax(e bk )
[0090] β bi = softmax(e bi ).
[0091] Specifically, the attention coefficients β ak , β ai (i.e. the keyword information attention coefficient and the intention information attention coefficient of the first sentence) are feature-weighted summed as follows:
[0092] output_agg_a = σ{β ak (output_Kw_a) + β ai (output_It_a)}
[0093] wherein output_agg_a is the aggregation result of the graph neural network aggregator at the left end of the double-tower structure (i.e. the aggregation vector of the first sentence), is the new feature (aggregated keyword information and intention information) of the GTA output for the sentence vector output_a (i.e. the sentence original vector of the first sentence), and σ(·) is an activation function;
[0094] The attention coefficients β bk , β bi (i.e. the keyword information attention coefficient and the intention information attention coefficient of the second sentence) are feature-weighted summed as follows:
[0095] output_agg_b = σ{β bk (output_Kw_b) + β bi (output_It_b)}
[0096] wherein output_agg_b is the aggregation result of the graph neural network aggregator at the right end of the double-tower structure (i.e. the aggregation vector of the second sentence), is the new feature (aggregated keyword information and intention information) of the GTA output for the sentence vector output_b (i.e. the sentence original vector of the second sentence), and σ(·) is an activation function.
[0097] In the above embodiment, the aggregation vectors of the first sentence and the second sentence are obtained by performing aggregation analysis on the sentence original vectors of the first sentence and the second sentence, the keyword vectors and the intent vectors corresponding to the first sentence, and the keyword vectors and the intent vectors corresponding to the second sentence, which can generate a weighted average by assigning learnable weights to keyword information and intent information, thereby achieving optimal performance, realizing stronger performance than relying on pure semantic information, and enabling text matching to be judged from different perspectives, thereby significantly improving the accuracy of text matching.
[0098] Optionally, as an embodiment of the present application, the process of calculating the correlation coefficients of the keyword information and the intent information of each of the first sentences and each of the second sentences based on the sentence original vectors of each of the first sentences, the sentence original vectors of each of the second sentences, the keyword vectors and the intent vectors corresponding to each of the first sentences, and the keyword vectors and the intent vectors corresponding to each of the second sentences comprises:
[0099] Based on the fourth formula, the keyword information correlation coefficients of each of the first sentences are calculated based on the sentence original vectors of each of the first sentences and the keyword vectors corresponding to each of the first sentences, and the fourth formula is:
[0100]
[0101] Based on the fifth formula, the intent information correlation coefficients of each of the first sentences are calculated based on the sentence original vectors of each of the first sentences and the intent vectors corresponding to each of the first sentences, and the fifth formula is:
[0102]
[0103] Based on the sixth formula, the keyword information correlation coefficients of each of the second sentences are calculated based on the sentence original vectors of each of the second sentences and the keyword vectors corresponding to each of the second sentences, and the sixth formula is:
[0104]
[0105] Based on the seventh formula, the intent information correlation coefficients of each of the second sentences are calculated based on the sentence original vectors of each of the second sentences and the intent vectors corresponding to each of the second sentences, and the seventh formula is:
[0106]
[0107] wherein, is the keyword information correlation coefficient of the ith first sentence, [·||·] is concatenation, and α() is a mapping function. i is the sentence original vector of the ith first sentence, and output_Kw_a i is the keyword vector corresponding to the ith first sentence, is the intent information correlation coefficient of the ith first sentence, and output_It_a i is the intent vector corresponding to the ith first sentence, is the keyword information correlation coefficient of the ith second sentence, and output_b i is the sentence original vector of the ith second sentence, and output_Kw_b i is the keyword vector corresponding to the ith second sentence, is the intent information correlation coefficient of the ith second sentence, and output_It_b i is the intent vector corresponding to the ith second sentence.
[0108] It should be understood that for the sentence vector representation output_a (i.e., the sentence original vector of the first sentence), the correlation coefficient e ak , e ai between its keyword information vector representation output_Kw_a (i.e., the keyword vector of the first sentence), its intent information vector representation output_It_a (i.e., the intent vector of the first sentence), and itself is calculated one by one, as follows:
[0109] e ak = α([W·output_a||W·output_Kw_a])
[0110] e ai = α([W·output_a||W·output_It_a])
[0111] wherein W is a shared parameter, and the features of the sentence vector representation are increased in dimension through linear mapping; [||·] concatenates the transformed features of the sentence vector representation, the keyword information vector representation, and the intent information vector representation; and finally α() represents mapping the concatenated high-dimensional features into a real number e ak , e ai , which is realized through a single-layer feedforward neural network.
[0112] Specifically, for the sentence vector representation output_b (i.e., the original sentence vector of the second sentence), the correlation coefficient e between its keyword information vector representation output_Kw_b (i.e., the keyword vector of the second sentence), intent information vector representation output_It_b (i.e., the intent vector of the second sentence), and itself is calculated one by one. bk e bi (That is, the keyword information relevance coefficient and the intent information relevance coefficient of the second sentence), as shown in the following formula:
[0113] e bk =α([W·output_b||W·output_Kw_b])
[0114] e bi =α([W·output_b||W·output_It_b])
[0115] Where W is a shared parameter, and the dimensionality of the features of the sentence vector representation is increased through linear mapping; [||·] for the sentence vector representation, the transformed features of the keyword information vector representation and the intent information vector representation are concatenated; finally, α() represents mapping the concatenated high-dimensional features to a real number e. bk e bi It is implemented through a single-layer feedforward neural network.
[0116] In the above embodiments, the correlation coefficients of the first sentence and the second sentence are calculated based on the original sentence vector of the first sentence, the original sentence vector of the second sentence, the keyword vector and intent vector corresponding to the first sentence, and the keyword vector and intent vector corresponding to the second sentence. This allows for the generation of a weighted average by assigning learnable weights to the keyword information and intent information, thereby exhibiting optimal performance. Compared with existing technologies, this achieves stronger performance than relying solely on pure semantic information. Furthermore, it enables the judgment of text matching from different perspectives, significantly improving the accuracy of text matching.
[0117] Optionally, as an embodiment of the present invention, the process of calculating score vectors based on the interaction vectors of each sentence pair to obtain multiple score vectors for each sentence pair includes:
[0118] Based on the eighth formula, score vectors are calculated according to the interaction vectors of each sentence pair to obtain multiple score vectors for each sentence pair. The eighth formula is:
[0119]
[0120] in, score_vector i is the score vector of the i-th sentence pair for the j-th perspective, output_crossing i is the interaction vector of the i-th sentence pair, Multi_Persp_Linear() is a multi-perspective linear layer, j is the number of perspectives, is a perspective weight value, and · is a dot product operation.
[0121] It should be understood that the interaction vector representation of the sentence pair is introduced into the multi-perspective linear layer, and the interaction vector representation of the sentence pair is converted into N score vectors corresponding to N perspectives, specifically:
[0122] score_vector i = Multi_Persp_Linear[i](output_crossing·W i T ),
[0123] wherein score_vector i is the score vector obtained after the Multi_Persp_Linear(·) multi-perspective linear layer; the multi-perspective linear layer is composed of N independent linear layers, has the same dimension, and has different parameters; i represents the i-th perspective; is a weight value of the corresponding perspective, and the greater the weight value corresponding to the perspective, the more similar the text pair is judged from the perspective; and · is a dot product operation.
[0124] In the above embodiment, the score vector is obtained by calculating the score vector based on the eighth formula according to the interaction vector, the interaction vector representation of the sentence pair can be converted into N score vectors corresponding to N perspectives, text matching under different perspectives is realized, and compared with the prior art, stronger performance than relying on only pure semantic information is realized, and text matching can be judged from different perspectives, and the accuracy of text matching is significantly improved.
[0125] Optionally, as an embodiment of the present application, the process of analyzing the text matching accuracy rate according to the plurality of score vectors of each of the sentence pairs comprises:
[0126] According to the ninth formula, the similarity score is calculated according to each score vector of each of the sentence pairs, and a plurality of similarity scores of each of the sentence pairs are obtained, and the ninth formula is:
[0127]
[0128] wherein, is the similarity score of the i-th sentence pair for the j-th perspective, Sigmoid() is a Sigmoid activation function, is the score vector of the i-th sentence pair for the j-th perspective.
[0129] Determine whether the similarity scores of each sentence pair are greater than a preset judgment score. If so, use the preset first score as the predicted label of the similarity score; otherwise, use the preset second score as the predicted label of the similarity score.
[0130] Import the reference labels that correspond one-to-one with each of the similarity scores, verify whether the predicted labels of each of the similarity scores are equal to the reference labels corresponding to each of the similarity scores, and count the number of predicted labels that are equal in all verification results to obtain the total number of correct labels.
[0131] Count the number of all predicted labels to obtain the total number of predicted labels;
[0132] Based on the tenth formula, the text matching accuracy is calculated according to the total number of correct tags and the total number of predicted tags, and the text matching accuracy is obtained. The tenth formula is:
[0133]
[0134] Where accuracy is the text matching accuracy, Q is the total number of correctly matched labels, M is the total number of predicted labels, and · represents the dot product operation.
[0135] Preferably, the preset judgment score can be 0.5, the preset first score can be 1, and the preset second score can be 0.
[0136] It should be understood that the score vector is restricted to between 0 and 1 by the Sigmoid function, thereby obtaining the similarity scores of text matching from different perspectives. Finally, the accuracy of text matching (i.e., the text matching accuracy) is obtained by calculating the total number of correct matches under different perspectives, specifically as follows:
[0137] S i =Sigmoid(score_vector) i )
[0138] Among them, S i Let S be the similarity score corresponding to N viewpoints, and its value ranges from 0 to 1. i If the value is greater than 0.5, the system is considered similar, and the predicted label `predict_label` is 1. When S... i A score less than 0.5 is considered dissimilar, and the predicted label `predict_label` is 0. `Sigmoid(·)` is the activation function, which adjusts the `score_vector`. i The size is mapped between 0 and 1.
[0139] Specifically, the accuracy of all sample matches (i.e., the text matching accuracy) is obtained by judging whether the predicted label predict_label matches the reference label label correctly:
[0140]
[0141] where N is the total number of samples (i.e., the total number of predicted labels); · is a dot product operation; Q is the total number of correct matches (i.e., the total number of correct labels) when the predicted label predict_label matches the reference label label correctly.
[0142] In the above embodiment, the text matching accuracy is obtained by analyzing the text matching accuracy according to the plurality of score vectors of the sentence pair. Not only the pure semantic information of the sentence is extracted, but also the keyword and intent information of the sentence is supplemented to the sentence text, realizing text matching from different perspectives. Compared with the prior art, stronger performance is achieved by relying on pure semantic information, and the accuracy of text matching is significantly improved.
[0143] Optionally, as another embodiment of the present application, the present application comprises the following steps:
[0144] S1: On the basis of a double-tower structure encoder, a sentence text and its keyword information and intent information are respectively given at the left end and the right end, and three text encoders are used to encode them to generate three vector representations of the sentence text, the keyword information and the intent information;
[0145] S2: The information from the three vector representations is aggregated by using a graph neural network aggregator to generate a single output vector;
[0146] S3: The output vector is spliced with the encoding result of the sentence text to obtain a feature fusion vector, which is the final output of one sentence text in the MPTS dataset sentence pair;
[0147] S4: The final outputs of the MPTS dataset sentence pair are interacted by a cross layer to obtain an interaction vector representation of the sentence pair;
[0148] S5: The interaction vector representation of the sentence pair is imported into a multi-perspective linear layer to convert the interaction vector representation of the sentence pair into N score vectors corresponding to N perspectives;
[0149] S6: The score vectors are limited to between 0 and 1 by a Sigmoid function to obtain similarity scores of text matching from different perspectives, and finally the accuracy of text matching is obtained by calculating the total number of correct matches from different perspectives.
[0150] Optionally, as another embodiment of the application, the method of the application comprises: on the basis of a double-tower structure encoder, a left end and a right end are each given a sentence text and its keyword information and intent information, three text encoders are used to encode them respectively to generate three vector representations of the sentence text, the keyword information and the intent information; information from the three vector representations is aggregated using a graph neural network aggregator to generate an output vector of a single vector; the output vector is spliced with the encoding result of the sentence text to obtain a feature fusion vector, which is the final output of one sentence text in a sentence pair of an MPTS dataset; the final outputs of the sentence pair of the MPTS dataset are interacted through a cross layer to obtain an interaction vector representation of the sentence pair; the interaction vector representation of the sentence pair is input into a multi-view linear layer to convert the interaction vector representation of the sentence pair into N score vectors corresponding to N views; the score vectors are limited to between 0 and 1 through a Sigmoid function to obtain similarity scores of text matching under different views, and finally the accuracy of text matching is obtained by calculating the total number of correct matches under different views. The application not only extracts the pure semantic information of the sentence, but also uses a graph neural network as an aggregator to supplement the sentence text with additional information of the keywords and intent of the sentence, and realizes text matching under different views through a multi-view linear layer. Compared with the prior art, the application realizes stronger performance than relying only on pure semantic information, and can judge text matching from different views, significantly improving the accuracy of text matching.
[0151] Figure 2 A module block diagram of a text matching device provided for an embodiment of the application.
[0152] Optionally, as another embodiment of the application, as shown in Figure 2 A text matching device comprises:
[0153] An encoding module is configured to import a plurality of sentence pairs, keyword information pairs and intent information pairs corresponding to each of the sentence pairs, and encode each of the sentence pairs, the keyword information pairs corresponding to each of the sentence pairs, and the intent information pairs corresponding to each of the sentence pairs to obtain a sentence original vector pair of each of the sentence pairs, a keyword vector pair corresponding to each of the sentence pairs, and an intent vector pair corresponding to each of the sentence pairs.
[0154] An interaction vector analysis module is configured to analyze interaction vectors according to the sentence original vector pair of each of the sentence pairs, the keyword vector pair corresponding to each of the sentence pairs, and the intent vector pair corresponding to each of the sentence pairs to obtain an interaction vector of each of the sentence pairs.
[0155] A score vector calculation module is configured to calculate score vectors according to the interaction vector of each of the sentence pairs to obtain a plurality of score vectors of each of the sentence pairs.
[0156] The text matching result obtaining module is configured to analyze the text matching accuracy according to the plurality of score vectors of each sentence pair, obtain the text matching accuracy, and take the text matching accuracy as the result of text matching.
[0157] Optionally, another embodiment of the present application provides a text matching system, comprising a memory, a processor, and a computer program stored in the memory and executable on the processor, and when the processor executes the computer program, the text matching method as described above is implemented. The system can be a computer or the like.
[0158] Optionally, another embodiment of the present application provides a computer readable storage medium, which stores a computer program, and when the computer program is executed by a processor, the text matching method as described above is implemented.
[0159] It should be noted that, in this document, the terms such as first and second are used only to distinguish one entity or operation from another entity or operation, and do not necessarily require or imply that there is any such actual relationship or order between these entities or operations. Moreover, the terms "include", "contain" or any other variants thereof are intended to cover non-exclusive inclusion, so that a process, method, article or device including a series of elements not only includes those elements, but also includes other elements not explicitly listed or inherent to such a process, method, article or device.
[0160] Those skilled in the art can clearly understand that, for the convenience and brevity of description, the specific working process of the above-described device and unit can refer to the corresponding process in the foregoing method embodiments, which will not be described here.
[0161] In several embodiments provided in the present application, it should be understood that the disclosed devices and methods can be implemented in other ways. For example, the device embodiments described above are only schematic, for example, the division of units is only a logical function division, and actual implementation can have another division manner, for example, a plurality of units or components can be combined or integrated into another system, or some features can be ignored or not executed.
[0162] The units described as separate components can or can not be physically separate, and the components shown as units can or can not be physical units, i.e. can be located in one place, or can be distributed on a plurality of network units. According to actual needs, part or all of the units can be selected to achieve the purpose of the embodiment of the present application.
[0163] In addition, each function unit in each embodiment of the present application can be integrated in one processing unit, or each unit can be physically present separately, or two or more units can be integrated in one unit. The integrated unit can be realized in the form of hardware or in the form of a software function unit.
[0164] When the integrated unit is realized in the form of a software function unit and sold or used as an independent product, it can be stored in a computer readable storage medium. Based on such understanding, the technical solutions of the present application, essentially or in the form of a contribution to the prior art, or all or part of the technical solutions can be embodied in the form of a software product. The computer software product is stored in a storage medium, and includes several instructions for causing a computer device (which can be a personal computer, a server, or a network device, etc.) to execute all or part of the steps of the methods in the embodiments of the present application. The foregoing storage medium includes various media that can store program codes, such as a U disk, a mobile hard disk, a read-only memory (ROM, Read-Only Memory), a random access memory (RAM, Random Access Memory), a magnetic disk or an optical disk.
[0165] The above description is only the preferred embodiment of the present application, and is not intended to limit the present application. Any modification, equivalent replacement, improvement, etc. made within the spirit and principle of the present application shall be included in the protection scope of the present application.
Claims
1. A text matching method, characterized in that, Includes the following steps: Import multiple sentence pairs and corresponding keyword and intent information pairs. Encode each sentence pair, its corresponding keyword and intent information pairs to obtain the original sentence vector pairs, keyword vector pairs, and intent vector pairs for each sentence pair. The interaction vectors of each sentence pair are obtained by analyzing the original sentence vector pairs, the keyword vector pairs and intent vector pairs corresponding to each sentence pair. The score vectors for each sentence pair are calculated based on the interaction vectors of each sentence pair, resulting in multiple score vectors for each sentence pair. The text matching accuracy is analyzed based on the multiple score vectors of each sentence pair to obtain the text matching accuracy, and the text matching accuracy is used as the result of text matching. The sentence pair includes a first sentence and a second sentence; the keyword information pair includes keyword information corresponding to the first sentence and keyword information corresponding to the second sentence; and the intent information pair includes intent information corresponding to the first sentence and intent information corresponding to the second sentence. The process of analyzing the interaction vectors of each sentence pair based on the original sentence vector pairs, the keyword vector pairs, and the intent vector pairs of each sentence pair to obtain the interaction vectors of each sentence pair includes: Aggregate analysis is performed on the original sentence vectors of each first sentence, the original sentence vectors of each second sentence, the keyword vectors and intent vectors corresponding to each first sentence, and the keyword vectors and intent vectors corresponding to each second sentence to obtain the aggregate vectors of each first sentence and the aggregate vectors of each second sentence. The original sentence vector and aggregated vector of each first sentence and the original sentence vector and aggregated vector of each second sentence are concatenated to obtain the fusion vector of each first sentence and the fusion vector of each second sentence. Based on the first formula, the interaction vectors are calculated according to the fusion vectors of each of the first sentences and the fusion vectors of each of the second sentences to obtain the interaction vectors of each sentence pair. The first formula is: , in, For the first The interaction vector of each sentence pair For cross-layer functions, For the first The fusion vector of the first sentence, For the first The fusion vector of the second sentence.
2. The text matching method according to claim 1, characterized in that, The process of encoding each sentence pair, the corresponding keyword information pair, and the intent information pair to obtain the original sentence vector pair, the corresponding keyword vector pair, and the intent vector pair for each sentence pair includes: The text encoder encodes each first sentence, each second sentence, the keyword information and intent information corresponding to each first sentence, and the keyword information and intent information corresponding to each second sentence, thereby obtaining the original sentence vector of each first sentence, the original sentence vector of each second sentence, the keyword vector and intent vector corresponding to each first sentence, and the keyword vector and intent vector corresponding to each second sentence. The sentence original vector pair of the sentence pair includes the sentence original vector of the first sentence and the sentence original vector of the second sentence; The keyword vector corresponding to the sentence pair includes the keyword vector corresponding to the first sentence and the keyword vector corresponding to the second sentence; The intent vector pair corresponding to the sentence pair includes the intent vector corresponding to the first sentence and the intent vector corresponding to the second sentence.
3. The text matching method according to claim 1, characterized in that, The process of performing aggregation analysis based on the original sentence vectors of each first sentence, the original sentence vectors of each second sentence, the keyword vectors and intent vectors corresponding to each first sentence, and the keyword vectors and intent vectors corresponding to each second sentence to obtain the aggregation vectors of each first sentence and each second sentence includes: Based on the original sentence vectors of each first sentence, the original sentence vectors of each second sentence, the keyword vectors and intent vectors corresponding to each first sentence, and the keyword vectors and intent vectors corresponding to each second sentence, the correlation coefficients are calculated to obtain the keyword information correlation coefficients and intent information correlation coefficients of each first sentence and each second sentence. Normalize the keyword information relevance coefficients and intent information relevance coefficients of each first sentence and each second sentence to obtain the keyword information attention coefficients and intent information attention coefficients of each first sentence and each second sentence. Based on the second formula, the first aggregation vector is calculated according to the keyword information attention coefficient and intent information attention coefficient of each of the first sentences, as well as the keyword vector and intent vector corresponding to each of the first sentences, to obtain the aggregation vector of each of the first sentences. The second formula is: , in, For the first The aggregate vector of the first sentence, The LeakyReLU activation function is used. For the first Attention coefficient for keyword information in the first sentence. For the first The keyword vector corresponding to the first sentence. For the first Attention coefficient for the intent information of the first sentence. For the first The intent vector corresponding to the first sentence; Based on the third formula, the second aggregation vector is calculated according to the keyword information attention coefficient and intent information attention coefficient of each second sentence, as well as the keyword vector and intent vector corresponding to each second sentence, to obtain the aggregation vector of each second sentence. The third formula is: , in, For the first The aggregate vector of the second sentence, The LeakyReLU activation function is used. For the first Attention coefficient for keyword information in the second sentence. For the first The keyword vector corresponding to each second sentence For the first Attention coefficient for the intent information of the second sentence. For the first The intent vector corresponding to the second sentence.
4. The text matching method according to claim 3, characterized in that, The process of calculating the relevance coefficients based on the original sentence vectors of each first sentence, the original sentence vectors of each second sentence, the keyword vectors and intent vectors corresponding to each first sentence, and the keyword vectors and intent vectors corresponding to each second sentence, to obtain the keyword information relevance coefficients and intent information relevance coefficients of each first sentence and each second sentence includes: Based on the fourth formula, the keyword information relevance coefficient is calculated according to the original sentence vector of each first sentence and the keyword vector corresponding to each first sentence, thus obtaining the keyword information relevance coefficient of each first sentence. The fourth formula is: , Based on the fifth formula, the intent information relevance coefficient is calculated according to the original sentence vector of each first sentence and the intent vector corresponding to each first sentence, to obtain the intent information relevance coefficient of each first sentence. The fifth formula is: , Based on the sixth formula, the keyword information relevance coefficient is calculated according to the original sentence vector of each second sentence and the keyword vector corresponding to each second sentence, thus obtaining the keyword information relevance coefficient of each second sentence. The sixth formula is: , Based on the seventh formula, the intent information relevance coefficient is calculated according to the original sentence vector of each second sentence and the intent vector corresponding to each second sentence, thus obtaining the intent information relevance coefficient of each second sentence. The seventh formula is: , in, For the first The relevance coefficient of keyword information in the first sentence. For splicing, For mapping functions, To share parameters, For the first The original sentence vector of the first sentence. For the first The keyword vector corresponding to the first sentence. For the first The correlation coefficient of intent information in the first sentence. For the first The intent vector corresponding to the first sentence. For the first The keyword relevance coefficient of the second sentence. For the first The original sentence vector of the second sentence. For the first The keyword vector corresponding to each second sentence For the first The relevance coefficient of the intent information of the second sentence. For the first The intent vector corresponding to the second sentence.
5. The text matching method according to claim 1, characterized in that, The process of calculating score vectors based on the interaction vectors of each sentence pair to obtain multiple score vectors for each sentence pair includes: Based on the eighth formula, score vectors are calculated according to the interaction vectors of each sentence pair to obtain multiple score vectors for each sentence pair. The eighth formula is: , in, For the first The sentence is related to the first... The score vector for each perspective. For the first The interaction vector of each sentence pair For multi-view linear layers, For the number of viewpoints, For viewpoint weight values, This is a dot product operation.
6. The text matching method according to claim 1, characterized in that, The process of analyzing the text matching accuracy based on multiple score vectors of each sentence pair to obtain the text matching accuracy includes: Based on the ninth formula, similarity scores are calculated according to the score vectors of each sentence pair to obtain multiple similarity scores for each sentence pair. The ninth formula is: , in, For the first The sentence is related to the first... Similarity score from each perspective for Activation function For the first The sentence is related to the first... A score vector for each perspective; Determine whether the similarity scores of each sentence pair are greater than a preset judgment score. If so, use the preset first score as the predicted label of the similarity score; otherwise, use the preset second score as the predicted label of the similarity score. Import the reference labels that correspond one-to-one with each of the similarity scores, verify whether the predicted labels of each of the similarity scores are equal to the reference labels corresponding to each of the similarity scores, and count the number of predicted labels that are equal in all verification results to obtain the total number of correct labels. Count the number of all predicted labels to obtain the total number of predicted labels; Based on the tenth formula, the text matching accuracy is calculated according to the total number of correct tags and the total number of predicted tags, and the text matching accuracy is obtained. The tenth formula is: , in, For text matching accuracy, The total number of correct labels. To predict the total number of labels, This is a dot product operation.
7. A text matching device, characterized in that, include: The encoding module is used to import multiple sentence pairs and keyword information pairs and intent information pairs corresponding to each sentence pair, and to encode each sentence pair, the keyword information pairs and intent information pairs corresponding to each sentence pair to obtain the original sentence vector pairs, the keyword vector pairs and intent vector pairs corresponding to each sentence pair. The interaction vector analysis module is used to analyze the interaction vectors of each sentence pair based on the original sentence vector pairs, the keyword vector pairs and intent vector pairs corresponding to each sentence pair, and to obtain the interaction vectors of each sentence pair. The score vector calculation module is used to calculate the score vector based on the interaction vector of each sentence pair, so as to obtain multiple score vectors for each sentence pair. The text matching result acquisition module is used to analyze the text matching accuracy based on multiple score vectors of each sentence pair, obtain the text matching accuracy, and use the text matching accuracy as the text matching result. The sentence pair includes a first sentence and a second sentence; the keyword information pair includes keyword information corresponding to the first sentence and keyword information corresponding to the second sentence; and the intent information pair includes intent information corresponding to the first sentence and intent information corresponding to the second sentence. The interaction vector analysis module is specifically used for: Aggregate analysis is performed on the original sentence vectors of each first sentence, the original sentence vectors of each second sentence, the keyword vectors and intent vectors corresponding to each first sentence, and the keyword vectors and intent vectors corresponding to each second sentence to obtain the aggregate vectors of each first sentence and the aggregate vectors of each second sentence. The original sentence vector and aggregated vector of each first sentence and the original sentence vector and aggregated vector of each second sentence are concatenated to obtain the fusion vector of each first sentence and the fusion vector of each second sentence. Based on the first formula, the interaction vectors are calculated according to the fusion vectors of each of the first sentences and the fusion vectors of each of the second sentences to obtain the interaction vectors of each sentence pair. The first formula is: , in, For the first The interaction vector of each sentence pair For cross-layer functions, For the first The fusion vector of the first sentence, For the first The fusion vector of the second sentence.
8. A text matching system, comprising a memory, a processor, and a computer program stored in the memory and executable on the processor, characterized in that, When the processor executes the computer program, it implements the text matching method as described in any one of claims 1 to 6.
9. A computer-readable storage medium storing a computer program, characterized in that, When the computer program is executed by a processor, it implements the text matching method as described in any one of claims 1 to 6.