Text matching method and device, electronic equipment and storage medium
By extracting and combining the overall features and local features of the text, especially the distinguishing feature vectors, the problem of low text matching accuracy in the existing technology is solved, and the accuracy of semantic matching is significantly improved.
Patent Information
- Application Number
- CN202311499793.1
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2023-11-09
- Publication Date
- 2024-10-18
AI Technical Summary
Existing text matching methods, especially those based on the BERT model, have low accuracy and are difficult to effectively judge the detailed differences between semantically similar texts, leading to incorrect matching.
Extract the overall features and local features of the text, highlight key information by distinguishing feature vectors, and combine the overall features for text matching to improve matching accuracy.
By extracting and combining overall features and distinctive features, the accuracy of text matching is significantly improved, false matching is reduced, and the recognition ability of semantically similar texts is enhanced.
Smart Images

Figure CN118797048A_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to the field of data processing technology, and in particular to a text matching method and device, electronic device and storage medium. Background Art
[0002] Text (semantic) matching is a very important natural language processing task. Text semantic matching technology is required in information retrieval, question-answering systems, text implication and other tasks. The problem it solves is to determine whether two sentences have the same semantic information and then match the two.
[0003] In recent years, deep learning has been gradually applied to fields such as natural language processing (NLP). The most classic deep learning model is the BERT model based on the transformer architecture, which converts two texts into digital features and inputs them into a classifier to determine whether the two texts are similar. However, the text matching effect of this text matching method is not ideal and the accuracy is low. Therefore, there is an urgent need to provide a better text matching solution. Summary of the invention
[0004] The embodiments of this specification provide a text matching method and device, an electronic device, and a storage medium to solve the problem of low text matching accuracy.
[0005] In a first aspect, one or more embodiments of the present specification provide a method for text matching, comprising: extracting, from a first text to be matched with a second text, a first overall feature vector corresponding to the first text and a first local feature vector corresponding to each character in the first text, and extracting, from the second text, a second overall feature vector corresponding to the second text and a second local feature vector corresponding to each character in the second text; obtaining, based on the first local feature vector and the second local feature vector, a first distinguishing feature vector corresponding to characters in the first text that are different from characters in the second text and a second distinguishing feature vector corresponding to characters in the second text that are different from characters in the first text; and determining a matching result between the first text and the second text based on the first overall feature vector, the second overall feature vector, the first distinguishing feature vector, and the second distinguishing feature vector.
[0006] In a second aspect, an embodiment of the present application provides a device for text matching, comprising: an extraction module, used to extract, from a first text to be matched with a second text, a first overall feature vector corresponding to the first text and a first local feature vector corresponding to each character in the first text, and to extract, from the second text, a second overall feature vector corresponding to the second text and a second local feature vector corresponding to each character in the second text; a distinction module, used to obtain, based on the first local feature vector and the second local feature vector, a first distinction feature vector corresponding to characters in the first text that are different from characters in the second text and a second distinction feature vector corresponding to characters in the second text that are different from characters in the first text; and a matching module, used to determine the matching result between the first text and the second text based on the first overall feature vector, the second overall feature vector, the first distinction feature vector and the second distinction feature vector.
[0007] In a third aspect, an embodiment of the present application provides an electronic device, which includes a processor, a memory, and a program or instruction stored in the memory and executable on the processor, wherein the program or instruction, when executed by the processor, implements the steps of the method described in the first aspect.
[0008] In a fourth aspect, an embodiment of the present application provides a readable storage medium, on which a program or instruction is stored, and when the program or instruction is executed by a processor, the steps of the method described in the first aspect are implemented.
[0009] In a fifth aspect, an embodiment of the present application provides a chip, comprising a processor and a communication interface, wherein the communication interface is coupled to the processor, and the processor is used to run a program or instruction to implement the method described in the first aspect.
[0010] In the embodiment of the present specification, the overall features (first overall feature vector and second overall feature vector) and local features (first local feature vector and second local feature vector) of the first text and the second text are first extracted, and then the distinguishing features (first distinguishing feature vector and second distinguishing feature vector) of the first text and the second text are extracted from the local features, and the matching result between the first text and the second text is determined based on the overall features and the distinguishing features. This process extracts the distinguishing features, which are important text information features, and combines the distinguishing features with the overall features to perform matching operations between texts, which helps to obtain more accurate text matching results. BRIEF DESCRIPTION OF THE DRAWINGS
[0011] In order to more clearly illustrate one or more embodiments of this specification or the technical solutions in the prior art, the drawings required for use in the embodiments or the description of the prior art will be briefly introduced below. Obviously, the drawings described below are only some embodiments recorded in one or more embodiments of this specification. For ordinary technicians in this field, other drawings can be obtained based on these drawings without paying creative work.
[0012] Figure 1 It is a schematic flow chart of a text matching method according to an embodiment of the present specification.
[0013] Figure 2 It is a schematic diagram of an application scenario of a text matching method according to an embodiment of the present specification.
[0014] Figure 3 A structural diagram of a text matching model according to an embodiment of the present specification is shown.
[0015] Figure 4 It is a structural schematic diagram of a text matching device according to an embodiment of this specification.
[0016] Figure 5 It is a structural schematic diagram of an electronic device according to an embodiment of this specification. DETAILED DESCRIPTION
[0017] The following will be combined with the drawings in the embodiments of this specification to clearly and completely describe the technical solutions in the embodiments of this specification. Obviously, the described embodiments are part of the embodiments of this specification, not all of the embodiments. Based on the embodiments in this specification, all other embodiments obtained by ordinary technicians in this field without creative work are within the scope of protection of this application.
[0018] The terms "first", "second", etc. in the specification and claims of this application are used to distinguish similar objects, and are not used to describe a specific order or sequence. It should be understood that the data used in this way can be interchangeable under appropriate circumstances, so that the embodiments of this specification can be implemented in an order other than those illustrated or described here, and the objects distinguished by "first", "second", etc. are generally of one type, and the number of objects is not limited. For example, the first object can be one or more. In addition, "and / or" in the specification and claims represents at least one of the connected objects, and the character " / " generally indicates that the objects associated with each other are in an "or" relationship.
[0019] With the rapid development of deep learning in recent years, deep learning has gradually been applied to fields such as natural language processing (NLP). As a technology in the field of natural language processing, text matching solves the problem of determining whether two texts have the same semantic information and then matching the two.
[0020] At present, the common text matching method is to first convert natural language text into digital features that can be understood by computers, and then match based on the correlation between features. Before the rapid development of deep learning, statistical methods such as word2vec were often used to convert text into digital features based on the statistical frequency of text in the text. This method only considers the modeling of the probability of text occurrence and does not introduce high-level semantic information, which leads to limitations in digital features and less than ideal text matching results.
[0021] After the rapid development of deep learning, a large number of text matching methods based on deep learning models have emerged. The most classic method is to first use a large amount of basic text to train a large-scale pre-training model, and then fine-tune the large-scale pre-training model for text matching. Among them, the most classic deep model is the BERT model, which is based on the transformer architecture and converts text into digital features. Compared with non-deep learning methods, this method can take into account the semantic information in the text, thereby improving the correlation between digital features between similar texts, so that text matching can achieve better results.
[0022] The BERT-based text matching method generally connects two texts to be matched into a long text, inputs this long text into the BERT network, converts it into digital features, and directly inputs the features into a classifier to determine whether the two texts are similar. This simple and direct method causes the model's attention to be scattered among the features of the entire sentence, and errors often occur for texts with different details. For example, "What factors affect the Chinese stock market?" and "What factors affect the US stock market?" These two sentences are often judged as similar texts. The reason is that the traditional BERT's attention is distributed over the entire sentence, and key words such as "China" and "USA" are not fully paid attention to, resulting in errors, which in turn leads to a decrease in the accuracy of text matching.
[0023] The text matching method, device and electronic device provided in the embodiments of this specification are described in detail below with reference to the accompanying drawings through specific embodiments and their application scenarios.
[0024] Figure 1A text matching method provided by an embodiment of the present invention is shown. The method can be executed by an electronic device, and the electronic device may include: a server and / or a terminal device, wherein the terminal device may be, for example, a vehicle-mounted terminal or a mobile phone terminal. In other words, the method can be executed by software or hardware installed in the aforementioned electronic device, and the method includes the following steps:
[0025] S102: Extracting, from a first text to be matched with a second text, a first overall feature vector corresponding to the first text and a first local feature vector corresponding to each character in the first text; and extracting, from the second text, a second overall feature vector corresponding to the second text and a second local feature vector corresponding to each character in the second text.
[0026] Among them, the first text and the second text are two texts to be matched, and the first text and the second text can be two sentences or a paragraph. The form of the first text and the second text is not specifically limited in this specification. The text matching task is to more accurately determine the relationship between the two texts to be matched from a semantic point of view, rather than simply matching through character strings. Therefore, after obtaining the first text and the second text, the two can be projected into the semantic space by encoding, and the distance between the two in the semantic space can be judged to determine whether the first text and the second text match. Specifically, since semantic matching is a classification task, an encoder based on a Transformer model (such as BERT, etc.) can be used to encode the first text and the second text respectively to extract the text features corresponding to each of the first text and the second text.
[0027] In one example, the characters in the first text and the second text can be spliced, and the spliced text can be encoded using an encoder based on the Transformer model to obtain a feature vector. Among them, the feature vector can include the features of the entire text (the first overall feature vector and the second overall feature vector), and can also include the features of each character in the first text and the second text (the first local feature vector and the second local feature vector). Specifically, the first local feature vector can not only include the feature vector converted from the character, but also include the position vector obtained by encoding the position of the character and the paragraph vector obtained by encoding the text where the character is located. Further, the feature vector, the position vector and the paragraph vector can be added to obtain the first local feature vector or the second local feature vector. The method of extracting the overall feature vector (the first overall feature vector and the second overall feature vector) and the local feature vector (the first local feature vector and the second local feature vector) from the text is not specifically limited in this specification, and can be determined according to actual conditions.
[0028] In step S102, not only the overall features of the first text and the second text (the first overall feature vector and the second overall feature vector) are extracted respectively, but also the local features of the first text and the second text (the first local feature vector and the second local feature vector) are extracted respectively. The combination of these two different features, the overall features and the local features, helps to obtain more accurate text matching results.
[0029] S104: Obtaining, based on the first local feature vector and the second local feature vector, a first distinctive feature vector corresponding to characters in the first text that are different from characters in the second text and a second distinctive feature vector corresponding to characters in the second text that are different from characters in the first text.
[0030] Among them, the first distinguishing feature vector and the second distinguishing feature vector are features that represent the difference between the first text and the second text. For example, for the two texts "What factors affect the Chinese stock market?" and "What factors affect the US stock market?", the key characters "China" and "USA" contain important information. The first distinguishing feature vector may include a vector obtained by encoding the character "China", and the second distinguishing feature vector may include a vector obtained by encoding the character "USA". Obviously, through the first distinguishing feature vector and the second distinguishing feature vector, it is possible to extract the different key information in the two texts, and then notice these different key information in the text matching process, which helps to alleviate the problem of easy misjudgment of similar texts, thereby improving the accuracy of text matching. Among them, the method for obtaining the first distinguishing feature vector and the second distinguishing feature vector can refer to the subsequent embodiments, which will not be repeated here.
[0031] S106: Determine a matching result between the first text and the second text based on the first overall feature vector, the second overall feature vector, the first distinctive feature vector, and the second distinctive feature vector.
[0032] In one example, the first overall feature vector, the second overall feature vector, the first distinguishing feature vector, and the second distinguishing feature vector may be concatenated, and a matching result may be obtained based on the concatenated vectors. For example, the input candidate sentences include A, B, and C, and A and B are not semantically similar, while A and C are semantically similar. 1 may be used to represent "similar" and 0 to represent "dissimilar". When two sentences A and B are input, the matching result is 0; when two sentences A and C are input, the matching result is 1.
[0033] In another example, the first overall feature vector and the second overall feature vector may be similarly calculated to obtain an overall matching result, and the first distinguishing feature vector and the second distinguishing feature vector may be similarly calculated to obtain a local matching result, and then the desired matching result may be obtained based on the overall matching result and the local matching result. The matching result may be a weighted sum of the overall matching result and the local matching result. This specification does not limit the weighted calculation process of the overall matching result and the local matching result, and it may be determined according to actual conditions.
[0034] In the embodiment of the present specification, the overall features (first overall feature vector and second overall feature vector) and local features (first local feature vector and second local feature vector) of the first text and the second text are first extracted, and then the distinguishing features (first distinguishing feature vector and second distinguishing feature vector) of the first text and the second text are extracted from the local features, and the matching result between the first text and the second text is determined based on the overall features and the distinguishing features. This process extracts the distinguishing features, which are important text information features, and combines the distinguishing features with the overall features to perform matching operations between texts, which helps to obtain more accurate text matching results.
[0035] Figure 2 A schematic diagram of an application scenario of a text matching method is provided, such as Figure 2 As shown, the user sends a service request for text matching between two texts to the server through a terminal such as a mobile phone. After receiving the service request, the server uses the text matching method in this manual to obtain the matching results corresponding to the two texts, and sends the matching results to the terminal for the user's reference.
[0036] In one implementation, step S104 may be performed as the following steps A1-A4:
[0037] Step A1, determining a similarity value between each character in the first text and each character in the second text according to the first local feature vector and the second local feature vector;
[0038] Step A2, determining a target similarity value greater than a preset similarity value from the similarity values;
[0039] Step A3, determining a first distinguishing feature vector according to the first local feature vector corresponding to the target similarity value;
[0040] Step A4: determining a second distinguishing feature vector according to the second local feature vector corresponding to the target similarity value.
[0041] Among them, the preset similarity value is an index for extracting the first distinguishing feature vector and the second distinguishing feature vector from the first local feature vector and the second local feature vector according to the similarity value. Specifically, the similarity value between each character in the first text and each character in the second text can be calculated. In one example, the first local feature vector corresponding to the character in the first text and the second local feature vector corresponding to the character in the second text can be used to calculate the similarity. The similarity measurement method can use Euclidean distance, cosine similarity, Pearson correlation coefficient, etc., and the specific similarity measurement method used is not limited in this specification.
[0042] When a target similarity value greater than a preset similarity value is obtained, the first distinguishing feature vector and the second distinguishing feature vector corresponding to the target similarity value may be used to determine the first distinguishing feature vector and the second distinguishing feature vector. In one implementation, step A3 may be performed as the following steps B1-B2:
[0043] Step B1, determining a first mask vector corresponding to the first local feature vector according to the first local feature vector corresponding to the target similarity value;
[0044] Step B2: determining a first distinguishing feature vector according to the first mask vector and the first local feature vector.
[0045] Specifically, a first mask vector corresponding to the first local feature vector can be produced according to the target similarity value, wherein the value corresponding to the first distinguishing feature vector determined according to the target similarity value in the first mask vector can be 1, and the value corresponding to the non-first distinguishing feature vector determined according to the similarity value other than the target similarity value in the first mask vector can be 0. Then, the first mask vector can be used to cover up non-important information in the first local feature vector, thereby highlighting the first distinguishing feature vector containing important information, reducing the noise of the text matching process, and improving the text matching effect.
[0046] Furthermore, a similarity matrix can be constructed for the similarity values, and then the first mask vector or the second mask vector can be intuitively determined through the similarity matrix to improve the efficiency of text matching. In one implementation, the text matching method includes the following steps:
[0047] According to the similarity values, a similarity matrix is constructed, wherein the elements in the similarity matrix are used to represent the similarity values between the first local eigenvector and the second local eigenvector corresponding to the elements;
[0048] Step B1 can be performed as follows:
[0049] A first mask vector is determined according to a first local eigenvector corresponding to the target similarity value in the similarity matrix.
[0050] Table 1 Similarity matrix example
[0051] A1 A2 A3 A4 A5 B1 0.2 0.6 0.2 0.2 0.1 B2 0.2 0.2 0.2 0.2 0.1 B3 0.2 0.1 0.2 0.2 0.1 B4 0.2 0.2 0.1 0.9 0.2 B5 0.2 0.2 0.7 0.1 0.2
[0052] Table 1 is a similarity matrix constructed based on the similarity values between the characters in sentence A (first text) and the characters in sentence B (second text). For each similarity value in Table 1, the larger the similarity value, the more similar the corresponding two characters are. Specifically, a preset threshold of 0.4 can be used to determine whether it is a similar vector. Taking a line as an example, when all similarity values corresponding to a character in sentence B are less than 0.4 (such as B2 and B3), it means that the character is not related to the characters in sentence A, and is a key information character. The value corresponding to the character in the first mask vector can be 1. Similarly, when the similarity value corresponding to a character in sentence B is greater than or equal to 0.4 (such as B1, B4 and B5), it means that the character may be related to the character in sentence A, and is a non-key information character. The value corresponding to the character in the first mask vector can be 0.
[0053] Specifically, the mask vectors of sentence A and sentence B can be generated according to the following formula:
[0054]
[0055]
[0056] Among them, S is the similarity matrix, i and j represent the relative positions of the local feature vectors corresponding to each character in sentence A and the local feature vectors corresponding to each character in sentence B, and a and b represent the mask vectors corresponding to sentences A and B, respectively.
[0057] After obtaining the mask vector, the mask vector can be applied to the first local feature vector to obtain the first distinguishing feature vector. In one implementation, step B2 can be performed as the following steps C1-C2:
[0058] Step C1, performing a dot multiplication operation on the first mask vector and a first combination matrix constructed according to the first local eigenvector to obtain a first distinguishing feature matrix;
[0059] Step C2, performing a weighted average operation on the vectors in the first distinguishing feature matrix to obtain a first distinguishing feature vector.
[0060] Among them, the first combination matrix is a matrix obtained by splicing all the first local feature vectors corresponding to the first text. Through the first mask vector, the aforementioned non-key first local feature vectors in the first combination vector can be masked to obtain a first distinguishing feature matrix. Furthermore, the first local feature vectors in the first distinguishing feature matrix can be subjected to a weighted average operation to obtain a first distinguishing feature vector. Specifically, the weighted average operation can be an average pooling operation. In this embodiment, through the dot product operation of the first mask vector and the first combination matrix, the first distinguishing feature vector can be quickly determined, thereby improving the efficiency of text matching.
[0061] Similarly, step A4 can be executed as the following steps D1-D2:
[0062] Step D1, determining a second mask vector corresponding to the second local feature vector according to the second local feature vector corresponding to the target similarity value;
[0063] Step D2, determining a second distinguishing feature vector according to the second mask vector and the second local feature vector.
[0064] Accordingly, step D1 can be performed as follows:
[0065] A second mask vector is determined according to a second local eigenvector corresponding to the target similarity value in the similarity matrix.
[0066] Furthermore, step D2 can be executed as the following steps E1-E2:
[0067] Step E1, performing a dot multiplication operation on the second mask vector and a second combination matrix constructed according to the second local eigenvector to obtain a second distinguishing feature matrix;
[0068] Step E2, performing a weighted average operation on the second local eigenvectors in the second distinguishing feature matrix to obtain a second distinguishing feature vector.
[0069] In the embodiments of the present specification, non-important vectors are masked by using a first mask vector constructed according to target similarity to mask the first local feature vector and a second mask vector constructed according to target similarity to mask the second local feature vector, so as to extract two important text information features, namely the first distinguishing feature vector and the second distinguishing feature vector, and then combining the first distinguishing feature vector and the second distinguishing feature vector with other text features to perform matching operations between texts, which helps to obtain more accurate text matching results.
[0070] In one implementation, the text matching method may further include the following steps:
[0071] Subtracting the first distinctive feature vector from the second distinctive feature vector to obtain a difference feature vector;
[0072] Determining a matching result between the first text and the second text based on the first overall feature vector, the second overall feature vector, the first distinguishing feature vector, and the second distinguishing feature vector includes:
[0073] A matching result between the first text and the second text is determined based on the first overall feature vector, the second overall feature vector, the first distinctive feature vector, the second distinctive feature vector, and the difference feature vector.
[0074] Among them, the difference feature vector is used to represent the difference between the first distinguishing feature vector and the second distinguishing feature vector. Specifically, after obtaining the first distinguishing feature vector and the second distinguishing feature vector, the first distinguishing feature vector and the second distinguishing feature vector containing important information can be further highlighted so that the text matching process pays more attention to the difference between the first text and the second text, thereby improving the accuracy of text matching. In one example, a difference feature vector can be constructed based on the first distinguishing feature vector and the second distinguishing feature vector, and then the difference feature vector is combined with the first overall feature vector, the second overall feature vector, the first distinguishing feature vector and the second distinguishing feature vector to obtain a matching result.
[0075] In another embodiment, the first distinguishing feature vector and the second distinguishing feature vector may be multiplied, and the obtained product may be combined with the first overall feature vector, the second overall feature vector, the first distinguishing feature vector and the second distinguishing feature vector to obtain a matching result, so as to further enrich the information used in the text matching process and improve the accuracy of text matching.
[0076] In the embodiments of the present specification, additional difference feature vectors can further supplement the information used to determine the matching result, thereby improving the accuracy of the matching result.
[0077] The text matching process can be implemented by a text matching model. In one implementation, the text matching method is implemented by a text matching model including a feature extraction network, a distinguishing feature extraction network, and a feedforward network, wherein the feature extraction network is used to extract a first overall feature vector and a first local feature vector from a first text, and to extract a second overall feature vector and a second local feature vector from a second text, the distinguishing feature extraction network is used to obtain a first distinguishing feature vector and a second distinguishing feature vector based on the first local feature vector and the second local feature vector, and the feedforward network is used to determine a matching result based on the first overall feature vector, the second overall feature vector, the first distinguishing feature vector, and the second distinguishing feature vector, and the training process of the text matching model can be performed as follows: Steps F1-F2:
[0078] Step F1, creating an initial text matching model including a feature extraction network, a distinguishing feature extraction network and a feedforward network, inputting the sample text into the initial text matching model for model training, and determining the classification loss obtained according to the matching result of the sample text;
[0079] Step F2, adjusting the model parameters of the initial text matching model based on the classification loss until the model training end condition is met, thereby obtaining a text matching model.
[0080] Figure 3 This is a structural diagram of the text matching model. Figure 3 As shown in the figure, in the text matching model, the feature extraction network includes an input module and a transformer module. The input module includes three submodules, and the output of the input module is the sum of the output vectors of the three submodules. Specifically, the specific functions of each submodule are as follows:
[0081] Dictionary feature (token embedding) submodule: This submodule converts the corresponding natural language characters into digital features through a vector lookup table.
[0082] Segment embedding submodule: This submodule generates a vector to distinguish between two input texts. Specifically, 0 can be used to indicate that the character is from the first text, and 1 can be used to indicate that the character is from the second text.
[0083] Position embedding submodule: This submodule generates a vector that depends on the position of the character in the text, which is used to represent the position of each character.
[0084] After obtaining the three vectors of the same length output by the above three submodules, the three vectors can be summed and input into the attention (transformer) module. The transformer module can be a network built based on the attention mechanism, which is mainly divided into the following cascaded parts:
[0085] Multi-head attention submodule: A multi-head attention submodule is an attention module that connects the outputs of multiple parallel single-head attention modules. Each single-head attention module has a single matrix Q, K, and V for the input vector. By multiplying the vector with the matrix, we can get the q, k, and v vectors. These vectors are used to get the output vector o through the following formula.
[0086]
[0087] Among them, softmax is a common function, d is the length of the vector, o is the output vector, q is the query vector, k is the key vector, and v is the value vector.
[0088] Layer Normalization Submodule (layer norm): The main function of this submodule is to normalize the output. First, the mean and variance of the vector are calculated, and the mean and variance are used to normalize the vector.
[0089] Feed Forward submodule: This submodule consists of a fully connected network, where the input is multiplied by a matrix to get the output.
[0090] The distinguishing feature extraction network mainly includes a similarity matrix module and a mask module. The main function of the similarity matrix module is to establish the correlation between the two input texts, and then determine the different key information in the two texts. For the input vector, first extract the matrix consisting of the features of the first text and the second text (the first local feature vector and the second local feature vector) from the dictionary features, and perform matrix multiplication of the transformed ranks of the first text and the second text to obtain the similarity matrix. The main function of the mask module is to use formula (1) and formula (2) to mask the local features of the two texts to obtain the first distinguishing feature vector and the second distinguishing feature vector.
[0091] The feedforward network includes a pooling module and a splicing module. The pooling module is a common module in the neural network, which mainly uses the following formula (4) for averaging operation. The main function of the splicing module is to splice the vectors of different steps to obtain the final vector, and determine the matching result based on the final vector. The final vector can be composed of 4 parts, namely, the first overall feature vector corresponding to the first text, the second overall feature vector corresponding to the second text, the first local feature vector containing the key information of the first text, and the second local feature vector containing the key information of the second text. Furthermore, the final vector can also include a difference feature vector of the key information difference between the first text and the second text.
[0092]
[0093] The training process of the text matching model may include: creating an initial text matching model including a feature extraction network, a distinguishing feature extraction network and a feedforward network, inputting a sample text into the initial text matching model, and the data processing process of the initial text matching model may include: using the feature extraction network to extract a first overall feature vector and a first local feature vector from a first text, and extracting a second overall feature vector and a second local feature vector from a second text; using the distinguishing feature extraction network to obtain a first distinguishing feature vector and a second distinguishing feature vector based on the first local feature vector and the second local feature vector; using the feedforward network to determine a matching result based on the first overall feature vector, the second overall feature vector, the first distinguishing feature vector and the second distinguishing feature vector.
[0094] After obtaining the matching result of the sample text, the classification loss of the sample text is determined according to the matching result, and the model parameters of the initial text matching model are adjusted based on the classification loss until the model training end condition is met to obtain the text matching model.
[0095] In the embodiment of this specification, after the sample text is input to the initial text matching model, the initial text matching model outputs a matching result, and the classification loss of the initial text matching model is determined according to the matching result to adjust the parameters of the initial text matching model to obtain the text matching model. This process realizes the end-to-end training of the text matching model, thereby improving the generalization performance of the text matching method.
[0096] It should be noted that the text matching method provided in the embodiments of this specification can be executed by a text matching device or a control module in the text matching device for executing the text matching method. In the embodiments of this specification, the text matching method executed by the text matching device is taken as an example to illustrate the text matching device provided in the embodiments of this specification.
[0097] Figure 4 FIG. 1 is a schematic diagram of the structure of a text matching device according to an embodiment of the present invention. Figure 4 As shown, the text matching device 400 includes:
[0098] An extraction module 410 is used to extract, from a first text to be matched with a second text, a first overall feature vector corresponding to the first text and a first local feature vector corresponding to each character in the first text, and to extract, from the second text, a second overall feature vector corresponding to the second text and a second local feature vector corresponding to each character in the second text;
[0099] A distinguishing module 420 is used to obtain, based on the first local feature vector and the second local feature vector, a first distinguishing feature vector corresponding to a character in the first text that is different from a character in the second text and a second distinguishing feature vector corresponding to a character in the second text that is different from a character in the first text;
[0100] The matching module 430 is used to determine a matching result between the first text and the second text based on the first overall feature vector, the second overall feature vector, the first distinctive feature vector, and the second distinctive feature vector.
[0101] In one embodiment, the distinguishing module 420 includes:
[0102] A similarity value unit, used to determine a similarity value between each character in the first text and each character in the second text according to the first local feature vector and the second local feature vector;
[0103] A target similarity value unit, used to determine a target similarity value greater than a preset similarity value from the similarity values;
[0104] A first vector unit, configured to determine a first distinguishing feature vector according to a first local feature vector corresponding to a target similarity value;
[0105] The second vector unit is used to determine a second distinguishing feature vector according to a second local feature vector corresponding to the target similarity value.
[0106] In one embodiment, the first vector unit is used to:
[0107] Determine, according to the first local feature vector corresponding to the target similarity value, a first mask vector corresponding to the first local feature vector;
[0108] Determine a first distinguishing feature vector according to the first mask vector and the first local feature vector;
[0109] The second vector unit is used to:
[0110] Determine, according to the second local feature vector corresponding to the target similarity value, a second mask vector corresponding to the second local feature vector;
[0111] A second distinctive feature vector is determined based on the second mask vector and the second local feature vector.
[0112] In one embodiment, the text matching apparatus 400 includes:
[0113] A matrix construction module, used to construct a similarity matrix according to the similarity value, wherein the elements in the similarity matrix are used to represent the similarity value between the first local eigenvector and the second local eigenvector corresponding to the element;
[0114] Determining a first mask vector corresponding to the first local feature vector according to the first local feature vector corresponding to the target similarity value includes:
[0115] Determine a first mask vector according to a first local eigenvector corresponding to the target similarity value in the similarity matrix;
[0116] Determining a second mask vector corresponding to the second local feature vector according to the second local feature vector corresponding to the target similarity value includes:
[0117] A second mask vector is determined according to a second local eigenvector corresponding to the target similarity value in the similarity matrix.
[0118] In one embodiment, determining the first distinguishing feature vector according to the first mask vector and the first local feature vector includes:
[0119] Performing a dot multiplication operation on the first mask vector and a first combination matrix constructed according to the first local eigenvector to obtain a first distinguishing feature matrix;
[0120] Performing a weighted average operation on the first local eigenvector in the first distinguishing feature matrix to obtain a first distinguishing feature vector;
[0121] Determining a second distinguishing feature vector according to the second mask vector and the second local feature vector includes:
[0122] Performing a dot multiplication operation on the second mask vector and a second combination matrix constructed according to the second local eigenvector to obtain a second distinguishing feature matrix;
[0123] A weighted average operation is performed on the second local eigenvectors in the second distinguishing feature matrix to obtain a second distinguishing feature vector.
[0124] In one embodiment, the text matching apparatus 400 includes:
[0125] A difference unit, used for subtracting the first distinctive feature vector from the second distinctive feature vector to obtain a difference feature vector;
[0126] The matching module 430 includes:
[0127] The matching unit is used to determine a matching result between the first text and the second text based on the first overall feature vector, the second overall feature vector, the first distinguishing feature vector, the second distinguishing feature vector and the difference feature vector.
[0128] In one embodiment, the text matching method is implemented by a text matching model including a feature extraction network, a distinguishing feature extraction network and a feedforward network, wherein the feature extraction network is used to extract a first overall feature vector and a first local feature vector from a first text, and extract a second overall feature vector and a second local feature vector from a second text, the distinguishing feature extraction network is used to obtain a first distinguishing feature vector and a second distinguishing feature vector based on the first local feature vector and the second local feature vector, the feedforward network is used to determine a matching result based on the first overall feature vector, the second overall feature vector, the first distinguishing feature vector and the second distinguishing feature vector, and the training process of the text matching model includes:
[0129] Creating an initial text matching model including a feature extraction network, a distinguishing feature extraction network, and a feedforward network, inputting the sample text into the initial text matching model for model training, and determining a classification loss obtained according to a matching result of the sample text;
[0130] The model parameters of the initial text matching model are adjusted based on the classification loss until the model training end conditions are met to obtain the text matching model.
[0131] The device for text matching in the embodiments of this specification may be a device, or a component, an integrated circuit, or a chip in a terminal. The device may be a mobile electronic device or a non-mobile electronic device. Exemplarily, the mobile electronic device may be a mobile phone, a tablet computer, a notebook computer, a palmtop computer, an in-vehicle electronic device, a wearable device, an ultra-mobile personal computer (UMPC), a netbook, or a personal digital assistant (PDA), etc., and the non-mobile electronic device may be a server, a network attached storage (NAS), a personal computer (PC), a television (TV), a teller machine, or a self-service machine, etc., which is not specifically limited in the embodiments of this specification.
[0132] The text matching device in the embodiments of this specification may be a device having an operating system. The operating system may be an Android operating system, an IOS operating system, or other possible operating systems, which are not specifically limited in the embodiments of this specification.
[0133] The text matching device provided in the embodiments of this specification can achieve Figure 1 To avoid repetition, the various processes implemented in the method embodiment are not described here.
[0134] Based on the same idea, one or more embodiments of this specification also provide an electronic device, such as Figure 5 As shown. The electronic device may have relatively large differences due to different configurations or performances, and may include one or more processors 501 and memory 502, and the memory 502 may store one or more storage applications or data. Among them, the memory 502 can be a temporary storage or a permanent storage. The application stored in the memory 502 may include one or more modules (not shown in the figure), and each module may include a series of computer executable instructions in the electronic device. Furthermore, the processor 501 can be configured to communicate with the memory 502 to execute a series of computer executable instructions in the memory 502 on the electronic device. The electronic device may also include one or more power supplies 503, one or more wired or wireless network interfaces 504, one or more input and output interfaces 505, and one or more keyboards 506.
[0135] Specifically in this embodiment, the electronic device includes a memory and one or more programs, wherein the one or more programs are stored in the memory, and the one or more programs may include one or more modules, and each module may include a series of computer executable instructions for the electronic device, and the one or more programs are configured to be executed by one or more processors, including the following computer executable instructions:
[0136] Extracting, from the first text to be matched with the second text, a first overall feature vector corresponding to the first text and a first local feature vector corresponding to each character in the first text, and extracting, from the second text, a second overall feature vector corresponding to the second text and a second local feature vector corresponding to each character in the second text;
[0137] Obtaining, based on the first local feature vector and the second local feature vector, a first distinguishing feature vector corresponding to a character in the first text that is different from a character in the second text and a second distinguishing feature vector corresponding to a character in the second text that is different from a character in the first text;
[0138] A matching result between the first text and the second text is determined based on the first overall feature vector, the second overall feature vector, the first distinctive feature vector, and the second distinctive feature vector.
[0139] One or more embodiments of the present specification further provide a storage medium, which stores one or more computer programs, wherein the one or more computer programs include instructions, which, when executed by an electronic device including multiple application programs, enable the electronic device to perform various processes of the above-mentioned text matching method embodiment, and are specifically used to perform:
[0140] Extracting, from the first text to be matched with the second text, a first overall feature vector corresponding to the first text and a first local feature vector corresponding to each character in the first text, and extracting, from the second text, a second overall feature vector corresponding to the second text and a second local feature vector corresponding to each character in the second text;
[0141] Obtaining, based on the first local feature vector and the second local feature vector, a first distinguishing feature vector corresponding to a character in the first text that is different from a character in the second text and a second distinguishing feature vector corresponding to a character in the second text that is different from a character in the first text;
[0142] A matching result between the first text and the second text is determined based on the first overall feature vector, the second overall feature vector, the first distinctive feature vector, and the second distinctive feature vector.
[0143] Each embodiment in this specification is described in a progressive manner, and the same or similar parts between the embodiments can be referred to each other, and each embodiment focuses on the differences from other embodiments. In particular, for the above-mentioned storage medium embodiment, since it is basically similar to the method embodiment, the description is relatively simple, and the relevant parts can be referred to the partial description of the method embodiment.
[0144] The methods, devices, modules or units described in the above embodiments may be implemented by a computer chip or entity, or by a product having a certain function. A typical implementation device is a computer. Specifically, the computer may be, for example, a personal computer, a laptop computer, a cellular phone, a camera phone, a smart phone, a personal digital assistant, a media player, a navigation device, an email device, a game console, a tablet computer, a wearable device, or a combination of any of these devices.
[0145] For the convenience of description, the above devices are described in terms of functions and are divided into various units. Of course, when implementing one or more embodiments of this specification, the functions of each unit can be implemented in the same or multiple software and / or hardware.
[0146] Those skilled in the art will appreciate that one or more embodiments of this specification may be provided as methods, systems, or computer program products. Therefore, one or more embodiments of this specification may take the form of a complete hardware embodiment, a complete software embodiment, or an embodiment combining software and hardware. Moreover, one or more embodiments of this specification may take the form of a computer program product implemented on one or more computer-usable storage media (including but not limited to disk storage, CD-ROM, optical storage, etc.) containing computer-usable program code.
[0147] One or more embodiments of the present specification are described with reference to flowcharts and / or block diagrams of methods, devices (systems), and computer program products according to the embodiments of the present specification. It should be understood that each process and / or box in the flowchart and / or block diagram, as well as the combination of processes and / or boxes in the flowchart and / or block diagram, can be implemented by computer program instructions. These computer program instructions can be provided to a processor of a general-purpose computer, a special-purpose computer, an embedded processor, or other programmable data processing device to generate a machine, so that the instructions executed by the processor of the computer or other programmable data processing device generate instructions for implementing the processes in the flowchart and / or block diagram. Figure 1 A process or multiple processes and / or boxes Figure 1 A device that provides the functions specified in a block or multiple blocks.
[0148] These computer program instructions may also be stored in a computer-readable memory capable of directing a computer or other programmable data processing device to operate in a specific manner, so that the instructions stored in the computer-readable memory produce an article of manufacture comprising an instruction device, which implements the process Figure 1 A process or multiple processes and / or boxes Figure 1 A function specified in one or more boxes.
[0149] These computer program instructions can also be loaded onto a computer or other programmable data processing device so that a series of operating steps are executed on the computer or other programmable device to produce a computer-implemented process, thereby providing instructions for implementing the process. Figure 1 A process or multiple processes and / or boxes Figure 1 The steps for the functions specified in one or more boxes.
[0150] In a typical configuration, a computing device includes one or more processors (CPU), input / output interfaces, network interfaces, and memory.
[0151] The memory may include non-permanent storage in a computer-readable medium, random access memory (RAM) and / or non-volatile memory in the form of read-only memory (ROM) or flash RAM. The memory is an example of a computer-readable medium.
[0152] Computer readable media include permanent and non-permanent, removable and non-removable media that can be implemented by any method or technology to store information. Information can be computer readable instructions, data structures, program modules or other data. Examples of computer storage media include, but are not limited to, phase change memory (PRAM), static random access memory (SRAM), dynamic random access memory (DRAM), other types of random access memory (RAM), read-only memory (ROM), electrically erasable programmable read-only memory (EEPROM), flash memory or other memory technology, compact disk read-only memory (CD-ROM), digital versatile disk (DVD) or other optical storage, magnetic cassettes, magnetic tape disk storage or other magnetic storage devices or any other non-transmission media that can be used to store information that can be accessed by a computing device. As defined herein, computer readable media does not include temporary computer readable media (transitory media), such as modulated data signals and carrier waves.
[0153] It should also be noted that the terms "include", "comprises" or any other variations thereof are intended to cover non-exclusive inclusion, so that a process, method, commodity or device including a series of elements includes not only those elements, but also other elements not explicitly listed, or also includes elements inherent to such process, method, commodity or device. In the absence of more restrictions, the elements defined by the sentence "comprises a ..." do not exclude the existence of other identical elements in the process, method, commodity or device including the elements.
[0154] One or more embodiments of the present specification may be described in the general context of computer-executable instructions executed by a computer, such as program modules. Generally, program modules include routines, programs, objects, components, data structures, etc. that perform specific tasks or implement specific abstract data types. The present specification may also be practiced in distributed computing environments where tasks are performed by remote processing devices connected through a communication network. In a distributed computing environment, program modules may be located in local and remote computer storage media, including storage devices.
[0155] Each embodiment in this specification is described in a progressive manner, and the same or similar parts between the embodiments can be referred to each other, and each embodiment focuses on the differences from other embodiments. In particular, for the system embodiment, since it is basically similar to the method embodiment, the description is relatively simple, and the relevant parts can be referred to the partial description of the method embodiment.
[0156] The above description is only one or more embodiments of this specification and is not intended to limit this application. For those skilled in the art, one or more embodiments of this specification may have various changes and variations. Any modification, equivalent replacement, improvement, etc. made within the spirit and principle of one or more embodiments of this specification should be included in the scope of the claims of one or more embodiments of this specification.
Claims
1. A text matching method, comprising: Extracting, from a first text to be matched with a second text, a first overall feature vector corresponding to the first text and a first local feature vector corresponding to each character in the first text, and extracting, from the second text, a second overall feature vector corresponding to the second text and a second local feature vector corresponding to each character in the second text; Obtaining, based on the first local feature vector and the second local feature vector, a first distinguishing feature vector corresponding to characters in the first text that are different from characters in the second text and a second distinguishing feature vector corresponding to characters in the second text that are different from characters in the first text; A matching result between the first text and the second text is determined based on the first overall feature vector, the second overall feature vector, the first distinctive feature vector, and the second distinctive feature vector.
2. The method according to claim 1, wherein obtaining, based on the first local feature vector and the second local feature vector, a first distinguishing feature vector corresponding to a character in the first text that is different from a character in the second text and a second distinguishing feature vector corresponding to a character in the second text that is different from a character in the first text comprises: Determining a similarity value between each character in the first text and each character in the second text according to the first local feature vector and the second local feature vector; Determining a target similarity value greater than a preset similarity value from the similarity values; Determining the first distinguishing feature vector according to the first local feature vector corresponding to the target similarity value; The second distinguishing feature vector is determined according to the second local feature vector corresponding to the target similarity value.
3. The method according to claim 2, wherein determining the first distinguishing feature vector according to the first local feature vector corresponding to the target similarity value comprises: Determine, according to the first local feature vector corresponding to the target similarity value, a first mask vector corresponding to the first local feature vector; Determining the first distinguishing feature vector according to the first mask vector and the first local feature vector; The determining the second distinguishing feature vector according to the second local feature vector corresponding to the target similarity value includes: Determine, according to the second local feature vector corresponding to the target similarity value, a second mask vector corresponding to the second local feature vector; The second distinctive feature vector is determined according to the second mask vector and the second local feature vector.
4. The method according to claim 3, comprising: According to the similarity values, a similarity matrix is constructed, wherein the elements in the similarity matrix are used to represent the similarity values between the first local eigenvector and the second local eigenvector corresponding to the elements; The step of determining a first mask vector corresponding to the first local feature vector according to the first local feature vector corresponding to the target similarity value includes: Determining the first mask vector according to the first local eigenvector corresponding to the target similarity value in the similarity matrix; The step of determining a second mask vector corresponding to the second local feature vector according to the second local feature vector corresponding to the target similarity value includes: The second mask vector is determined according to the second local eigenvector corresponding to the target similarity value in the similarity matrix.
5. The method according to claim 3, wherein determining the first distinguishing feature vector according to the first mask vector and the first local feature vector comprises: Performing a dot multiplication operation on the first mask vector and a first combination matrix constructed according to the first local eigenvector to obtain the first distinguishing feature matrix; Performing a weighted average operation on the first local eigenvector in the first distinguishing feature matrix to obtain the first distinguishing feature vector; The step of determining the second distinguishing feature vector according to the second mask vector and the second local feature vector comprises: Performing a dot multiplication operation on the second mask vector and a second combination matrix constructed according to the second local eigenvector to obtain the second distinguishing feature matrix; A weighted average operation is performed on the second local eigenvectors in the second distinguishing feature matrix to obtain the second distinguishing feature vector.
6. The method according to claim 1, comprising: Subtracting the first distinctive feature vector from the second distinctive feature vector to obtain a difference feature vector; The determining a matching result between the first text and the second text based on the first overall feature vector, the second overall feature vector, the first distinguishing feature vector, and the second distinguishing feature vector includes: A matching result between the first text and the second text is determined based on the first overall feature vector, the second overall feature vector, the first distinguishing feature vector, the second distinguishing feature vector, and the difference feature vector.
7. The method according to claim 6, wherein the text matching method is implemented by a text matching model including a feature extraction network, a distinguishing feature extraction network and a feedforward network, wherein: The feature extraction network is used to extract the first overall feature vector and the first local feature vector from the first text, and extract the second overall feature vector and the second local feature vector from the second text. The distinguishing feature extraction network is used to obtain the first distinguishing feature vector and the second distinguishing feature vector according to the first local feature vector and the second local feature vector. The feedforward network is used to determine the matching result based on the first overall feature vector, the second overall feature vector, the first distinguishing feature vector, and the second distinguishing feature vector. The training process of the text matching model includes: Creating an initial text matching model including a feature extraction network, a distinguishing feature extraction network, and a feedforward network, inputting a sample text into the initial text matching model for model training, and determining a classification loss obtained according to a matching result of the sample text; The model parameters of the initial text matching model are adjusted based on the classification loss until a model training end condition is met to obtain a text matching model.
8. A text matching device, comprising: An extraction module, used for extracting, from a first text to be matched with a second text, a first overall feature vector corresponding to the first text and a first local feature vector corresponding to each character in the first text, and extracting, from the second text, a second overall feature vector corresponding to the second text and a second local feature vector corresponding to each character in the second text; a distinguishing module, configured to obtain, based on the first local feature vector and the second local feature vector, a first distinguishing feature vector corresponding to characters in the first text that are different from characters in the second text and a second distinguishing feature vector corresponding to characters in the second text that are different from characters in the first text; A matching module is used to determine a matching result between the first text and the second text based on the first overall feature vector, the second overall feature vector, the first distinctive feature vector, and the second distinctive feature vector.
9. An electronic device, comprising: processor; as well as A memory arranged to store computer executable instructions, the executable instructions being configured to be executed by the processor, the executable instructions comprising instructions for performing the steps in the method according to any one of claims 1 to 7.
10. A storage medium, characterized in that: The storage medium is used to store computer-executable instructions, and the executable instructions enable a computer to execute the method according to any one of claims 1 to 7.
Citation Information
Cited By
Text processing method and device, equipment, storage medium and program product
CN120216684A
Text processing method, apparatus, device, storage medium, and program product
CN120216684B
Case recommendation method and device, electronic equipment, storage medium and program product
CN120429428A
