A text matching method, device, equipment and storage medium

By obtaining and weighting the keyword features of the target text and candidate text, and matching based on semantic feature similarity, the problem of insufficient text matching accuracy in the intelligent question and answer system is solved, and higher matching accuracy is achieved.

CN114358016BActive Publication Date: 2024-10-29UNIV OF SCI & TECH OF CHINA +1
View PDF 2 Cites 0 Cited by

Patent Information

Application Number
CN202111630212.4
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2021-12-28
Publication Date
2024-10-29
Estimated Expiration
2041-12-28

Smart Images

  • Figure CN114358016B_ABST
    Figure CN114358016B_ABST
Patent Text Reader

Abstract

The present application discloses a text matching method, device and storage medium, the method comprising: obtaining the word features of a first keyword in a target text and the word features of a second keyword in a plurality of candidate texts, wherein the first keyword and the second keyword are words belonging to preset keywords in the corresponding text; determining the semantic features of the target text based on the word features of the target text, and determining the semantic features of each candidate text based on the word features of each candidate text; determining the candidate text matching the target text based on the feature similarity between the target text and each candidate text regarding the semantic features. In the above manner, the present application can improve the accuracy of text matching.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present application relates to the technical field of natural language processing, and in particular to a text matching method, apparatus, device and storage medium. Background Art

[0002] Natural language processing is an important direction in the fields of computer science and artificial intelligence. Natural language processing is mainly used in machine translation, text classification, text semantic matching, speech recognition, etc. Among them, text semantic matching can be specifically applied to search engines, intelligent question answering and other fields.

[0003] In the field of intelligent question-answering, users want to find answers to questions in a certain field. The answers provided by robots can come from many sources, such as knowledge bases related to a certain field, question-answering libraries, etc. Intelligent question-answering systems can be closed-domain question-answering systems, that is, specific responses will be given to user questions input into the system. There are many mechanisms for building closed-domain question-answering systems, mainly including 1) solutions based on semantic matching of question-answer pairs (Frequently Asked Questions, FAQ) 2) solutions based on question-answering knowledge bases 3) generative question-answering systems.

[0004] Among them, in the solution based on semantic matching of question and answer pairs, the most important thing is to match the question input by the user with the questions in the question and answer pair library, find the question in the question and answer pair library that is most similar in semantics to the question input by the user, and output the answer corresponding to the question. Summary of the invention

[0005] The main technical problem solved by the present application is to provide a text matching method, apparatus, device and storage medium, which can improve the accuracy of text matching.

[0006] To solve the above technical problems, the first aspect of the present application provides a text matching method, which includes: obtaining word features of a first keyword in a target text and word features of a second keyword in a number of candidate texts, wherein the first keyword and the second keyword are words belonging to preset keywords in the corresponding texts; determining the semantic features of the target text based on the word features of the target text, and determining the semantic features of each candidate text based on the word features of each candidate text; and determining the candidate text that matches the target text based on the feature similarity between the target text and each candidate text regarding the semantic features.

[0007] To solve the above technical problems, the second aspect of the present application provides a text matching device, which includes: an acquisition module, which is used to acquire the word features of a first keyword in a target text and the word features of a second keyword in a number of candidate texts, wherein the first keyword and the second keyword are words belonging to preset keywords in the corresponding texts; a semantic feature determination module, which is used to determine the semantic features of the target text based on the word features of the target text, and, based on the word features of each candidate text, determine the semantic features of each candidate text; a candidate text determination module, which is used to determine the candidate text that matches the target text based on the feature similarity between the target text and each candidate text regarding the semantic features.

[0008] To solve the above technical problems, the third aspect of the present application provides a text matching device, which includes a memory and a processor coupled to each other, the memory storing program instructions; the processor is used to execute the program instructions stored in the memory to implement the method described in the first aspect above.

[0009] In order to solve the above technical problem, the fourth aspect of the present application provides a computer-readable storage medium, which is used to store program instructions, and the program instructions can be executed to implement the method described in the first aspect above.

[0010] The beneficial effect of the present application is that, different from the prior art, the present application emphasizes the keywords in the target text and each candidate text, determines the semantic features of the target text and the candidate text based on the word features of the keywords, and further determines the feature similarity of the target text and the candidate text to determine the candidate text that matches the target text. Therefore, the present application additionally considers the keywords in the text to determine the similarity between the texts, which can improve the matching accuracy of the target text and the candidate text. BRIEF DESCRIPTION OF THE DRAWINGS

[0011] Figure 1 It is a flowchart of an implementation method of the text matching method of the present application;

[0012] Figure 2 It is a flowchart of an implementation method of step S110 in the first implementation method of the text matching method of the present application;

[0013] Figure 3 This is a flowchart of an implementation of step S120 in the first implementation of the text matching method of the present application;

[0014] Figure 4 It is a flowchart of an implementation method of semantic model training of the present application;

[0015] Figure 5It is a flowchart of another implementation method of the text matching method of the present application;

[0016] Figure 6 It is a flowchart of an implementation method of text encoding model training of the present application;

[0017] Figure 7 It is a flowchart of another implementation method of text encoding model training of the present application;

[0018] Figure 8 It is a flowchart of an implementation method of step S730 in another implementation method of text encoding model training of the present application;

[0019] Fig. 9 It is a schematic diagram of a framework of an implementation method of a text matching device provided by the present application;

[0020] Fig.10 It is a schematic diagram of a framework of an implementation method of a text matching device provided by the present application;

[0021] Fig.11 It is a schematic diagram of a framework of an implementation scheme of a computer-readable storage medium of the present application. DETAILED DESCRIPTION

[0022] The following is a clear and complete description of the technical solutions in the embodiments of the present application in conjunction with the drawings in the embodiments of the present application. Obviously, the described embodiments are only part of the embodiments of the present application, not all of the embodiments. Based on the embodiments in the present application, all other embodiments obtained by ordinary technicians in this field without creative work are within the scope of protection of this application.

[0023] It should be noted that in the embodiments of the present application, there are descriptions involving "first", "second", etc., which are only used for descriptive purposes and cannot be understood as indicating or implying their relative importance or implicitly indicating the number of the indicated technical features. Therefore, the features defined as "first" or "second" may explicitly or implicitly include at least one of the features.

[0024] See also Figure 1 , Figure 1 : is a flowchart of an implementation method of the text matching method of the present application, the method comprising:

[0025] S110: Acquire word features of a first keyword in a target text and word features of a second keyword in a plurality of candidate texts.

[0026] The target text can be a word, a question, or a paragraph. For example, in the field of intelligent question answering, the target text can be a target question that the user inputs into the intelligent question answering system. The question answering model finds questions in the intelligent question answering system that are semantically similar to the target question and gives a reply. In a retrieval system, the target text can be the search content input by the user. The retrieval model can find text in the retrieval system that is semantically similar to the search content input by the user and send it to the user.

[0027] The first keyword is a word in the target text that is a preset keyword, and the second keyword is a word in the candidate text that is a preset keyword. The preset keywords include at least one of the following categories: the brand of the scene device associated with the use scenario of the target text (such as BYD), the model of the scene device (AH001), the name of the sub-device in the scene device (such as air conditioner, window, seat, etc.), the attribute of the scene device or sub-device (such as temperature, high and low, etc.), and the operation method (such as increase, decrease, etc.). It can be understood that the target text can contain multiple first keywords, and the candidate text can contain multiple second keywords.

[0028] The word features of the first keyword and the word features of the second keyword can be represented by a vector or a piece of data.

[0029] In one embodiment, a user inputs a target text and several candidate texts into a feature extraction model (such as a TF-IDF model), and the target text and the several candidate texts are different questions. The feature extraction model detects whether there are words identical to preset keywords in the target text and the several candidate texts, and uses the words identical to the preset keywords in the target text as the first keyword, and uses the features of the preset keywords as the word features of the first keyword. Among them, the features of the preset keywords can be edited in advance by R&D personnel and stored in the feature extraction model. Similarly, using the above method, the word features of the second keyword in several candidate texts are obtained.

[0030] S120: Determine the semantic features of the target text based on the word features of the target text, and determine the semantic features of each candidate text based on the word features of each candidate text.

[0031] In one embodiment, the semantic features of the target text and the semantic features of each candidate text are both represented by vectors, and the features of each word in the target text are weighted to obtain the semantic features of the target text. Similarly, the features of each word in each candidate text are also weighted to obtain the semantic features of each candidate text.

[0032] S130: Determine a candidate text that matches the target text based on feature similarities between the target text and each candidate text regarding semantic features.

[0033] Specifically, the feature similarity between the target text and each candidate text is calculated based on the semantic features of the target text and the semantic features of each candidate text. In one embodiment, the semantic features of the target text and the semantic features of each candidate text are represented by vectors, and the feature similarity between the target text and each candidate text can be obtained by calculating the cosine similarity of the two vectors (i.e., the cosine value of the angle between the two vectors). In another embodiment, the feature similarity between the target text and each candidate text can also be obtained by calculating the word shift distance (i.e., the shortest distance required for a word in the target text to move to a word in the candidate text in the semantic space). It can be understood that in other embodiments, other methods (such as calculating the Euclidean distance) can also be used to calculate the feature similarity between the target text and each candidate text, which is not limited here.

[0034] The above method, by emphasizing the keywords in the target text and each candidate text, determines the semantic features of the target text and the candidate text based on the word features of the keywords, and further calculates the feature similarity between the target text and the candidate text, can improve the matching accuracy of the target text and the candidate text.

[0035] See also Figure 2 , Figure 2 This is a flow chart of step S110 in the first embodiment of the text matching method of the present application. This step includes:

[0036] S111: Match each word in the target text with a plurality of preset keywords respectively, obtain at least one first keyword in the target text that matches the preset keyword, and obtain preset features corresponding to each first keyword as word features of the target text.

[0037] S112: For each candidate text, each word in the candidate text is matched with a plurality of preset keywords respectively to obtain at least one second keyword in the candidate text that matches the preset keyword, and a preset feature corresponding to each second keyword is obtained as a word feature of the candidate text.

[0038] In one embodiment, the developer pre-sets multiple preset keywords and establishes feature embeddings for each preset keyword. The preset keywords can be further matched with the target text using a string matching method to obtain a first keyword in the target text that is the same as the preset keyword, and the feature of the preset keyword is used as the preset feature of the first keyword.

[0039] Similarly, the preset features of the second keyword in the candidate text can also be obtained in the above manner, which will not be described in detail here.

[0040] See also Figure 3 , Figure 3This is a flow chart of step S120 in the first implementation of the text matching method of the present application. This step includes:

[0041] S121: Taking the target text or the candidate text as the current text.

[0042] S122: Encode the current text to obtain a first text feature of the current text.

[0043] In one embodiment, after a target text or a candidate text is selected as the current text, the current text is input into a sentence encoder (Encoder), and the sentence encoder encodes it to obtain a first text feature of the current text, and the first text feature can be in the form of a vector.

[0044] S123: Perform weighted processing on the word features of the current text and the first text features to obtain the semantic features of the current text.

[0045] In one embodiment, the user can input each word feature of the current text and the first text feature of the current text into a pre-trained semantic model, and the semantic model determines the attention weight of each word feature of the current text; then use the attention weight to weighted sum the current word features of the current text to obtain the total word feature of the current text; finally, the first text feature and the total word feature of the current text are weighted to obtain the semantic feature of the current text.

[0046] In a specific embodiment, for each word feature of the current text, the semantic model can use a preset calculation method (such as Formula 1) to take the dot product of the transposition of the first text feature of the current text and the word feature as the attention weight of the word feature.

[0047] a j =h j ·v T Formula 1

[0048] In formula 1, a j represents the attention weight of the jth word feature; h j represents the jth word feature; v represents the first text feature of the current text.

[0049] Formula 1 is used to calculate the attention weights of each word feature contained in the current text in turn, and then formula 2 is used to sum all the attention weights to obtain the total word feature S of the current text.

[0050]

[0051] Finally, the first text feature and the total word feature of the current text are weighted using Formula 3 to obtain the semantic feature of the current text.

[0052] a*S+b*v=F Formula 3

[0053] In Formula 3, S is the total word feature of the current text, v represents the first text feature of the current text, F is the semantic feature of the current text, and a and b are parameters set in advance. The values ​​of parameters a and b can be set as needed and are not limited here.

[0054] By respectively calculating the attention weights of the word features in the target text (i.e., the preset features of the first keyword) and the attention weights of the word features in the candidate text (i.e., the preset features of the second keyword), a target text feature vector and a candidate text feature vector with higher accuracy can be obtained, so that when further calculating the similarity between the target text and the candidate text, a higher accuracy can be obtained.

[0055] See also Figure 4 , Figure 4 1 is a flowchart of an implementation method of semantic model training of the present application. In one implementation method, the above step S130 is performed by the semantic model, and the semantic model may be trained before executing step S130. The training steps of the semantic model may include:

[0056] S410: Obtain a first text sample.

[0057] In one embodiment, the first text sample includes a first target sample and a first associated sample of the first target sample, and the first associated sample includes a first positive sample and a first negative sample. The first text sample can be preset by a user, the first positive sample is a text with similar text semantics to the first target sample, the first negative sample is a text with different text semantics from the first target sample, and the number of first negative samples can be multiple.

[0058] In a specific embodiment, the first text sample contains the same number of first target samples and first associated samples of the first target samples. For example, the first text sample contains 6 samples, of which 3 samples (named A, B, C) are first target samples, and the other three samples (named A1, B1, C1) are first associated samples of the first target samples, then the A1 sample is a positive sample of the A sample, and the B1 and C1 samples are negative samples of the A sample; similarly, the B1 sample is a positive sample of the B sample, and the A1 and C1 samples are negative samples of the B sample; the C1 sample is a positive sample of the C sample, and the A1 and B1 samples are negative samples of the C sample. In another specific embodiment, the number of first associated samples of the first target sample in the first text sample is greater than the number of the first target samples, and the excess samples are all negative samples of the first target sample.

[0059] S420: Acquire word features of preset keywords present in each first text sample.

[0060] In one embodiment, the preset keywords can be preset by the user according to actual needs, and a feature embedding of each preset keyword can be established. Further, a string matching method can be used to match the preset keywords with the first text sample, obtain the words in the first text sample that are the same as the preset keywords, and use the features of the preset keywords as the features of the words.

[0061] S430: Using a semantic model to process word features of each first text sample to obtain semantic features of each first text sample.

[0062] The semantic features of the first text sample include the semantic features of the first target sample and the semantic features of the first associated sample.

[0063] S440: Utilize the semantic features of the first target sample and the semantic features of each first associated sample to form a plurality of sample semantic feature pairs.

[0064] Specifically, the semantic features of the first target sample can respectively form different sample semantic feature pairs with the semantic features of the first positive sample and the semantic features of the first negative sample contained in the first associated sample. In a specific embodiment, the sample semantic feature pair composed of the semantic features of the first target sample and the semantic features of the first positive sample can be named as a positive sample semantic feature pair, and the sample semantic feature pair composed of the semantic features of the first target sample and the semantic features of the first negative sample can be named as a negative sample semantic feature pair. It can be understood that a semantic feature of a first target sample can only appear in one positive sample semantic feature pair, but can appear in multiple negative sample semantic feature pairs.

[0065] S450: Adjusting the network parameters of the semantic model based on the feature similarity of each sample semantic feature pair.

[0066] In one embodiment, after step S440, the user may use other models to calculate the feature similarity of each sample semantic feature pair by calculating the cosine similarity, and then use infoNCE to calculate the loss function, and adjust the network parameters of the semantic model according to the result of the loss function.

[0067] In another embodiment, after step S440, noise is further added to the sample semantic feature pair corresponding to the first positive sample to obtain at least one new pair of sample semantic feature pairs. The new sample semantic feature pair can be regarded as a feature pair with semantic similarity to the sample semantic feature pair composed of the first target sample and the first positive sample. On this basis, the feature similarity of each sample semantic feature pair is calculated through the above embodiment, and then the network parameters of the semantic model are adjusted.

[0068] See also Figure 5, Figure 5 It is a flowchart of another implementation method of the text matching method of the present application. The method comprises:

[0069] S510: Acquire a second text representation of a target text and a plurality of pre-stored texts.

[0070] The second text representation of the target text and the plurality of pre-stored texts can be obtained by the encoding model. In one embodiment, a large number of pre-stored texts can be pre-input into the encoding model, and the encoding model encodes them to obtain the second text representation of the pre-stored text. When applied, the target text is input into the encoding model to obtain the second text representation of the target text. The encoding model can include two encoders, which encode the target text and the pre-stored text respectively; or it can include only one encoder. The second text representation can be expressed in the form of a vector.

[0071] S520: Obtain text similarity between the target text and each pre-stored text with respect to the second text representation, and select at least one pre-stored text whose text similarity meets a preset requirement as a candidate text.

[0072] In one embodiment, the cosine similarity calculation can be performed on the target text and each pre-stored text to obtain the text similarity. The text similarity is sorted, and the pre-stored text with a higher sorting order can be selected as the candidate text. A threshold can also be set to use the pre-stored text with a text similarity value greater than the threshold as the candidate text; if all the text similarity values ​​are less than the threshold, it can be considered that there is no pre-stored text similar to the target text in the system. For example, in a question-and-answer system, the target text can be the target question input by the user, and the pre-stored text is the pre-stored question in the system. The text similarity of the target question and each pre-stored question is calculated respectively, and the preset requirement is set to a text similarity value greater than 0.8, then the preset question with a text similarity value greater than 0.8 with the target question is used as a candidate question. If the text similarity of the target question and each pre-stored question is less than 0.8, the target question input by the user is refused to be answered by replying with some common language. Among them, the common language can be "I can't answer this question, I am studying hard".

[0073] S530: Acquire the word features of the first keyword in the target text and the word features of the second keyword in a number of candidate texts.

[0074] S540: Determine the semantic features of the target text based on the word features of the target text, and determine the semantic features of each candidate text based on the word features of each candidate text.

[0075] S550: Determine a candidate text that matches the target text based on feature similarities between the target text and each candidate text regarding semantic features.

[0076] The detailed description of steps S530-S550 can be found in the aforementioned steps S110-S130, which will not be described in detail here.

[0077] In this embodiment, by first calculating the text similarity between the target text and the pre-stored text, the pre-stored text with a text similarity exceeding a threshold is used as a candidate text, and keywords in the candidate text are further selected, and the accuracy of the calculated semantic similarity is improved by increasing the weight of the keywords. Furthermore, the pre-stored text is initially screened, and if all the calculated text similarities are less than the threshold, the answer is rejected, which can avoid the situation of wrong answer.

[0078] See also Figure 6 , Figure 6 1 is a flowchart of an implementation method of text coding model training of the present application. In one implementation method, the above step S510 is performed by the text coding model. Before performing step S510, the text coding model may be trained. The training steps of the text coding model may include:

[0079] S610: Acquire a second text sample.

[0080] In one embodiment, the second text sample may be preset by a user, the second positive sample is a text with semantically similar text to the second target sample, the second negative sample is a text with semantically dissimilar text to the second target sample, and the number of second negative samples may be multiple. The second text sample includes the second target sample and the second associated sample of the second target sample, and the second associated sample includes the second positive sample and the second negative sample.

[0081] S620: Obtain a second text representation of a second target sample using a text encoding model.

[0082] A single or multiple second target samples may be input into the text encoding model, for example, in the form of mini_batch. After the text encoding model and reverse encoding, a second text representation of the second target sample may be obtained. The second text representation may be in the form of a vector.

[0083] S630: Adjusting network parameters of the text encoding model based on the text similarity between the second target sample and each second associated sample with respect to the second text representation.

[0084] The second associated sample can use the text encoding model to obtain the corresponding second text representation, or other encoding models can be used to obtain the second text representation of the second associated sample. In one embodiment, multiple second target samples and second associated samples are respectively input into the text encoding model and other encoding models in the form of mini_batch to obtain their respective corresponding second text representations, and the text similarity calculated according to the second text representation is used to adjust the network parameters of the text encoding model.

[0085] See also Figure 7 , Figure 7 This is a flowchart of another embodiment of the text encoding model training of the present application. The training steps of the text encoding model may include:

[0086] S710: Obtain a second text sample.

[0087] In one embodiment, the second text sample includes a second target sample and a second associated sample of the second target sample, and the second associated sample includes a second positive sample and a second negative sample. The second positive sample is a text with similar text semantics to the second target sample, and the second negative sample is a text with different text semantics from the second target sample, that is, one second target sample corresponds to one second positive sample, but may correspond to multiple second negative samples.

[0088] S720: Obtain a second text representation of a second target sample using the text encoding model.

[0089] Specifically, one second target sample may be input into the text encoding model each time to obtain the corresponding second text representation, or a group form, such as a mini-batch form, may be used to input multiple second target samples to obtain multiple second text representations.

[0090] S730: Acquire the second text representation of each second associated sample by using the auxiliary coding model, and place the second text representation of each second associated sample in a sample queue according to the acquisition order.

[0091] When the second target sample is input into the text coding model in step S720, the second positive sample in the corresponding second associated sample needs to be input into the auxiliary coding model. At this time, an additional second negative sample can be established and input into the auxiliary coding model, or the second positive sample corresponding to other second target samples can be used as the second negative sample of the current second target sample. For example, in one embodiment, three second target samples (named A, B, C) and the second positive samples (named A1, B1, C1) corresponding to the three second target samples are input into the text coding model and the auxiliary coding model in the form of mini_batch. At this time, the A1 sample is the positive sample of the A sample, and the B1 and C1 samples are the negative samples of the A sample; similarly, the B1 sample is the positive sample of the B sample, and the A1 and C1 samples are the negative samples of the B sample; the C1 sample is the positive sample of the C sample, and the A1 and B1 samples are the negative samples of the C sample. The text encoding model is used to encode the three target samples A, B, and C to obtain the second text representation of each second target sample, and the auxiliary encoding model is used to encode the three associated samples A1, B1, and C1 to obtain the second text representation of the second associated sample. The second text representation can be in the form of a vector.

[0092] In this embodiment, a sample queue can also be established to store the second text representation of each second associated sample. The second text representation of each second associated sample enters the sample queue in sequence according to the encoding time. The storage capacity in the sample queue can be set as needed and is not limited here.

[0093] S740: Obtain text similarity between the second target sample and each second associated sample in the sample queue with respect to the second text representation.

[0094] In one embodiment, the second text representation is expressed in the form of a vector, and the cosine values ​​of the angles between the vector representation of the second target sample and the vector representation of each second associated sample can be calculated respectively to obtain the text similarity between the second target sample and each second associated sample.

[0095] S750: Adjust the network parameters of the text encoding model based on the obtained text similarity.

[0096] Furthermore, the text similarities between all second target samples and their second associated samples are counted to obtain a loss function value, and the network parameters of the text encoding model are updated based on the loss function value.

[0097] S760: Adjust the network parameters of the auxiliary encoding model based on the current network parameters of the text encoding model.

[0098] In one embodiment, the current network parameters of the auxiliary coding model and the current network parameters of the text coding model may be weighted and summed to obtain the adjusted network parameters of the auxiliary coding model. Specifically, after updating the network parameters of the text coding model, the auxiliary coding model may be assigned using Momentum to obtain the adjusted network parameters of the auxiliary coding model. Specifically, the assignment may be performed using Formula 4:

[0099] m*θ k +(1-m)*θ q+1 →θ k+1 Formula 4

[0100] In Formula 4, θ k is the current network parameter of the auxiliary encoding model; θ k+1 is the network parameter adjusted by the auxiliary encoding model; θ q+1 is the current network parameter of the text encoding model; m is a hyperparameter and can be set to 0.99.

[0101] The above method only needs to return the network parameters of the trained text encoding model, and adjust the network parameters of the auxiliary encoding model according to the network parameters of the updated text encoding model, which can save processing space and time and alleviate the pressure of data transmission.

[0102] See also Figure 8 , Figure 8 7 is a flow chart of an implementation of step S730 in another implementation of text encoding model training of the present application; the above step S730 may also include:

[0103] S731: Before training the text encoding model for the first time, use the auxiliary encoding model to obtain second text representations of a first number of second negative samples, and place the second text representations of the first number of second negative samples in a sample queue in the order of acquisition.

[0104] In one embodiment, a first number of second text representations in the sample queue can be set, and the first number is equal to the upper limit of the placement number of the sample queue, or the first number is less than the upper limit of the placement number and the difference with the upper limit of the placement number is less than or equal to the second number. For example, if it is set to 65536, the sample queue can only accommodate 65536 second text representations. At this time, the first number can be 65535, 65534, or any other number less than 65536. Before training, the first number of second negative samples are pre-input into the text encoding model to obtain the second text representation of the first number of second negative samples, and are stored in the sample queue in the order of encoding, thereby increasing the number of second negative samples of the second target sample.

[0105] S732: In each training process of the text encoding model, the auxiliary encoding model is used to obtain second text representations of a second number of second associated samples, and the second text representations of the second number of second associated samples are placed in the sample queue according to the acquisition order.

[0106] Specifically, in the actual training process, the auxiliary coding model can obtain the second text representation of the second number of second associated samples, wherein the second number can be any value. Similarly, the second text representation of the second number of second associated samples is also placed in the sample queue in the coding order. If the upper limit of the placement number of the sample queue is exceeded, the second text representation of the corresponding number of second associated samples placed first in the sample queue is discarded, and the second number of second associated texts includes the second positive sample and the second negative sample.

[0107] In a specific embodiment, if the upper limit of the number of second text representations placed in the sample queue is set to 65536, the second negative samples of 65535 second associated samples have been pre-placed in the sample queue. During training, the user inputs 3 second associated samples to the auxiliary coding model, and the 3 second associated samples are respectively a second positive sample and two second negative samples. The second text representation of the second associated sample after encoding is placed in the sample queue. At this time, the sample queue should contain 65538 second text representations. Since the upper limit of the number of placements of the sample queue is 65536, the two second text representations that enter the sample queue earliest can be thrown out of the sample queue. It can be understood that in other embodiments, if the number of placements of the sample queue has reached the upper limit, when it is necessary to enter n second text representations, it is necessary to abandon the n second text representations that enter the sample queue earliest, so that the number of sample queues always remains equal to or less than the upper limit of the number of placements.

[0108] Furthermore, the cosine similarity between the second text representation of the second target sample and the second text representation of each second associated sample in the sample queue can be calculated to obtain the text similarity between the second target sample and each second associated sample, and then the loss function is calculated based on the text similarity, and the network parameters of the text encoding model are adjusted according to the value of the loss function.

[0109] See also Fig. 9 , Fig. 9It is a framework diagram of an embodiment of a text matching device provided by the present application. The text matching device 90 includes: an acquisition module 91, a semantic feature determination module 92, and a candidate text determination module 93. The acquisition module 91 is used to acquire the word features of the first keyword in the target text and the word features of the second keyword in a number of candidate texts, wherein the first keyword and the second keyword are words belonging to preset keywords in the corresponding text; the semantic feature determination module 92 is used to determine the semantic features of the target text based on the word features of the target text, and, based on the word features of each candidate text, determine the semantic features of each candidate text; the candidate text determination module 93 is used to determine the candidate text that matches the target text based on the feature similarity between the target text and each candidate text regarding the semantic features.

[0110] The preset keywords include at least one of the following categories: the brand of the scene device associated with the use scenario of the target text, the model of the scene device, the name of the sub-device in the scene device, the attribute of the scene device or the sub-device, and the operation method. Obtaining the word features of the first keyword in the target text and the word features of the second keyword in several candidate texts includes: matching each word in the target text with several preset keywords respectively, obtaining at least one first keyword in the target text that matches the preset keyword, and obtaining the preset features corresponding to each first keyword as the word features of the target text; corresponding to each candidate text, matching each word in the candidate text with several preset keywords respectively, obtaining at least one second keyword in the candidate text that matches the preset keyword, and obtaining the preset features corresponding to each second keyword as the word features of the candidate text.

[0111] Among them, the semantic features of the target text are determined based on the word features of the target text, or the semantic features of each candidate text are determined based on the word features of each candidate text, including: taking the target text or the candidate text as the current text; encoding the current text to obtain the first text feature of the current text; weighting the word feature and the first text feature of the current text to obtain the semantic feature of the current text.

[0112] The step of determining the attention weight of each word feature of the current text includes: for each word feature of the current text, taking the dot product of the transposition of the first text feature of the current text and the word feature as the attention weight of the word feature.

[0113] Among them, the steps of determining the semantic features of the target text based on the word features of the target text and determining the semantic features of each candidate text based on the word features of each candidate text are performed by a semantic model; the training steps of the semantic model include: obtaining a first text sample, wherein the first text sample includes a first target sample and a first associated sample of the first target sample, and the first associated sample includes a first positive sample and a first negative sample; obtaining the word features of preset keywords existing in each first text sample; using the semantic model to process the word features of each first text sample to obtain the semantic features of each first text sample; using the semantic features of the first target sample and the semantic features of each first associated sample to form a number of sample semantic feature pairs; adjusting the network parameters of the semantic model based on the feature similarity of each sample semantic feature pair.

[0114] Wherein, before adjusting the network parameters of the semantic model based on the feature similarity of each sample semantic feature pair, the method further includes: adding noise to the sample semantic feature pair corresponding to the first positive sample to obtain at least one new pair of sample semantic feature pairs.

[0115] Among them, before obtaining the word features of the first keyword in the target text and the word features of the second keyword in several candidate texts, it also includes: obtaining the second text representation of the target text and multiple pre-stored texts; obtaining the text similarity between the target text and each pre-stored text regarding the second text representation, and selecting at least one pre-stored text whose text similarity meets preset requirements as a candidate text.

[0116] Among them, obtaining the second text representation of the target text and multiple pre-stored texts is performed by a text encoding model; the training steps of the text encoding model include: obtaining a second text sample, wherein the second text sample includes a second target sample and a second associated sample of the second target sample, and the second associated sample includes a second positive sample and a second negative sample; using the text encoding model to obtain the second text representation of the second target sample; based on the text similarity between the second target sample and each second associated sample with respect to the second text representation, adjusting the network parameters of the text encoding model.

[0117] Among them, after obtaining the second text sample, it also includes: using the auxiliary coding model to obtain the second text representation of each second associated sample, and placing the second text representation of each second associated sample in the sample queue according to the order of acquisition; based on the text similarity between the second target sample and each second associated sample regarding the second text representation, adjusting the network parameters of the text coding model, including: obtaining the text similarity between the second target sample and each second associated sample in the sample queue regarding the second text representation; adjusting the network parameters of the text coding model based on the obtained text similarity; adjusting the network parameters of the auxiliary coding model based on the current network parameters of the text coding model.

[0118] Wherein, based on the current network parameters of the text encoding model, the network parameters of the auxiliary encoding model are adjusted, including: taking a weighted sum of the current network parameters of the auxiliary encoding model and the current network parameters of the text encoding model to obtain the adjusted network parameters of the auxiliary encoding model; and / or, using the auxiliary encoding model to obtain the second text representation of each second associated sample, and placing the second text representation of each second associated sample in the sample queue in the order of acquisition, including: before the first training of the text encoding model, using the auxiliary encoding model to obtain the second text representation of a first number of second negative samples, and placing the second text representation of the first number of second negative samples in the sample queue in the order of acquisition The first number is placed in the sample queue, wherein the first number is equal to the upper limit of the placement number of the sample queue, or the first number is less than the upper limit of the placement number and the difference with the upper limit of the placement number is less than or equal to the second number; in each training process of the text encoding model, the auxiliary encoding model is used to obtain the second text representation of the second number of second-related samples, and the second text representation of the second number of second-related samples is placed in the sample queue in the order of acquisition, wherein if the upper limit of the placement number of the sample queue is exceeded, the second text representation of the corresponding number of second-related samples placed first in the sample queue is discarded, and the second number of second-related texts includes a second positive sample and a second negative sample.

[0119] See also Fig.10 , Fig.10 It is a schematic diagram of the framework of an implementation scheme of a text matching device provided in the present application.

[0120] The text matching device 100 includes a memory 101 and a processor 102 coupled to each other, the memory 101 stores program instructions, and the processor 102 is used to execute the program instructions to implement the steps in any of the above touch detection method embodiments. Specifically, the text matching device 100 may include but is not limited to: a desktop computer, a laptop computer, a server, a mobile phone, a tablet computer, etc., which are not limited here.

[0121] Specifically, the processor 102 is used to control itself and the memory 101 to implement the steps in any of the above touch detection method embodiments. The processor 102 can also be called a CPU (Central Processing Unit). The processor 102 may be an integrated circuit chip with signal processing capabilities. The processor 102 can also be a general-purpose processor, a digital signal processor (Digital Signal Processor, DSP), an application-specific integrated circuit (Application Specific Integrated Circuit, ASIC), a field-programmable gate array (Field-Programmable Gate Array, FPGA) or other programmable logic devices, discrete gates or transistor logic devices, discrete hardware components. The general-purpose processor can be a microprocessor or the processor can also be any conventional processor, etc. In addition, the processor 102 can be implemented by an integrated circuit chip.

[0122] See also Fig.11 , Fig.11 The computer-readable storage medium 110 stores program instructions 111, which are used to implement the steps in any of the above method embodiments when executed by a processor.

[0123] The computer-readable storage medium 110 may specifically be a medium that can store computer programs, such as a USB flash drive, a mobile hard disk, a read-only memory (ROM), a random access memory (RAM), a magnetic disk or an optical disk, or may be a server that stores the computer program. The server may send the stored computer program to other devices for execution, or may also execute the stored computer program itself.

[0124] In the several embodiments provided in the present application, it should be understood that the disclosed systems, 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. There may be other division methods in actual implementation. For example, multiple units or components can be combined or integrated into another system, or some features can be ignored or not executed. Another point is that the mutual coupling or direct coupling or communication connection shown or discussed can be an indirect coupling or communication connection through some interfaces, devices or units, which can be electrical, mechanical or other forms.

[0125] In addition, each functional unit in each embodiment of the present application may be integrated into one processing unit, or each unit may exist physically separately, or two or more units may be integrated into one unit. The above-mentioned integrated unit may be implemented in the form of hardware or in the form of software functional units.

[0126] If the integrated unit is implemented in the form of a software functional unit and sold or used as an independent product, it can be stored in a computer-readable storage medium. Based on this understanding, the technical solution of the present application is essentially or the part that contributes to the prior art or all or part of the technical solution can be embodied in the form of a software product, and the computer software product is stored in a storage medium, including a number of instructions to enable a computer device (which can be a personal computer, server, or network device, etc.) or a processor (processor) to perform all or part of the steps of each implementation method of the present application. The aforementioned storage medium includes: U disk, mobile hard disk, read-only memory (ROM, Read-Only Memory), random access memory (RAM, Random Access Memory), disk or optical disk and other media that can store program code.

[0127] The above are only implementation methods of the present application, and are not intended to limit the patent scope of the present application. Any equivalent process changes made using the contents of the present application specification and drawings, or directly or indirectly applied in other related technical fields, are also included in the patent protection scope of the present application.

Claims

1. A text matching method, characterized in that: The method comprises: Acquire word features of a first keyword in a target text and word features of a second keyword in a plurality of candidate texts, wherein the first keyword and the second keyword are words belonging to preset keywords in the corresponding texts; Determining the semantic features of the target text based on the word features of the target text, and determining the semantic features of each of the candidate texts based on the word features of each of the candidate texts; Determining the candidate text matching the target text based on the feature similarity between the target text and each of the candidate texts regarding the semantic feature; The determining of the semantic features of the target text based on the word features of the target text, or the determining of the semantic features of each candidate text based on the word features of each candidate text, includes: Taking the target text or the candidate text as the current text; Encoding the current text to obtain a first text feature of the current text; The word features of the current text and the first text features are weighted to obtain the semantic features of the current text.

2. The method according to claim 1, characterized in that The preset keywords include at least one of the following categories: the brand of the scene device associated with the usage scenario of the target text, the model of the scene device, the name of the sub-device in the scene device, the attributes of the scene device or the sub-device, and the operation method; And / or, the acquiring of the word features of the first keyword in the target text and the word features of the second keyword in the plurality of candidate texts includes: Matching each word in the target text with a plurality of preset keywords respectively, obtaining at least one first keyword in the target text that matches the preset keyword, and obtaining preset features corresponding to each of the first keywords as word features of the target text; Corresponding to each of the candidate texts, each word in the candidate text is matched with a number of preset keywords respectively to obtain at least one second keyword in the candidate text that matches the preset keyword, and the preset features corresponding to each of the second keywords are obtained as the word features of the candidate text.

3. The method according to claim 1, characterized in that The step of weighting the word feature of the current text and the first text feature to obtain the semantic feature of the current text includes: Determining the attention weight of each word feature of the current text; Using the attention weights, weighted summation is performed on the current word features of the current text to obtain the total word feature of the current text; The first text feature and the total word feature of the current text are weighted to obtain the semantic feature of the current text.

4. The method according to claim 3, characterized in that The determining of the attention weight of each word feature of the current text includes: For each word feature of the current text, a dot product of a transposition of a first text feature of the current text and the word feature is taken as an attention weight of the word feature.

5. The method according to claim 1, characterized in that The steps of determining the semantic features of the target text based on the word features of the target text and determining the semantic features of each candidate text based on the word features of each candidate text are performed by a semantic model; The method further comprises the following steps to train the semantic model: Acquire a first text sample, wherein the first text sample includes a first target sample and a first associated sample of the first target sample, and the first associated sample includes a first positive sample and a first negative sample; Acquire word features of preset keywords present in each of the first text samples; Using the semantic model to process the word features of each of the first text samples to obtain the semantic features of each of the first text samples; Using the semantic features of the first target sample and the semantic features of each of the first associated samples, a plurality of sample semantic feature pairs are formed; Based on the feature similarity of each of the sample semantic feature pairs, the network parameters of the semantic model are adjusted.

6. The method according to claim 5, characterized in that Before adjusting the network parameters of the semantic model based on the feature similarity of each of the sample semantic feature pairs, the method further includes: Noise is added to the sample semantic feature pair corresponding to the first positive sample to obtain at least one new pair of the sample semantic feature pairs.

7. The method according to claim 1, characterized in that Before acquiring the word features of the first keyword in the target text and the word features of the second keyword in the plurality of candidate texts, the method further includes: Acquire a second text representation of the target text and a plurality of pre-stored texts; The text similarity between the target text and each of the pre-stored texts with respect to the second text is obtained, and at least one of the pre-stored texts whose text similarity meets a preset requirement is selected as the candidate text.

8. The method according to claim 7, characterized in that The obtaining of the second text representation of the target text and the plurality of pre-stored texts is performed by a text encoding model; The method further comprises the following steps to train the text encoding model: Acquire a second text sample, wherein the second text sample includes a second target sample and a second associated sample of the second target sample, and the second associated sample includes a second positive sample and a second negative sample; Obtaining a second text representation of the second target sample using the text encoding model; Based on the text similarity between the second target sample and each of the second associated samples with respect to the second text representation, the network parameters of the text encoding model are adjusted.

9. The method according to claim 8, characterized in that After obtaining the second text sample, the method further includes: Acquire a second text representation of each of the second associated samples by using an auxiliary coding model, and place the second text representation of each of the second associated samples in a sample queue in an acquisition order; The adjusting the network parameters of the text encoding model based on the text similarity between the second target sample and each of the second associated samples with respect to the second text representation comprises: Obtaining text similarity between the second target sample and each of the second associated samples in the sample queue with respect to the second text representation; Based on the obtained text similarity, adjusting the network parameters of the text encoding model; Based on the current network parameters of the text encoding model, the network parameters of the auxiliary encoding model are adjusted.

10. The method according to claim 9, characterized in that The adjusting the network parameters of the auxiliary encoding model based on the current network parameters of the text encoding model includes: Performing a weighted summation of the current network parameters of the auxiliary coding model and the current network parameters of the text coding model to obtain the adjusted network parameters of the auxiliary coding model; And / or, the using the auxiliary coding model to obtain the second text representation of each second associated sample, and placing the second text representation of each second associated sample in a sample queue in the order of acquisition, includes: Before the text encoding model is first trained, the auxiliary encoding model is used to obtain a first number of second text representations of the second negative samples, and the second text representations of the first number of second negative samples are placed in a sample queue in the order of acquisition, wherein the first number is equal to an upper limit of the number of placements of the sample queue, or the first number is less than the upper limit of the number of placements and the difference between the first number and the upper limit of the number of placements is less than or equal to the second number; In each training process of the text encoding model, the auxiliary encoding model is used to obtain the second text representations of the second-related samples of the second number, and the second text representations of the second-related samples of the second number are placed in the sample queue in the order of acquisition, wherein if the upper limit of the placement quantity of the sample queue is exceeded, the second text representations of the corresponding number of second-related samples placed first in the sample queue are discarded, and the second number of the second-related texts includes a second positive sample and a second negative sample.

11. A text matching device, characterized in that: The device comprises: An acquisition module, the acquisition module is used to acquire word features of a first keyword in a target text and word features of a second keyword in a plurality of candidate texts, wherein the first keyword and the second keyword are words belonging to preset keywords in the corresponding texts; A semantic feature determination module, the semantic feature determination module is used to determine the semantic features of the target text based on the word features of the target text, and to determine the semantic features of each of the candidate texts based on the word features of each of the candidate texts; A candidate text determination module, the candidate text determination module is used to determine the candidate text matching the target text based on the feature similarity between the target text and each of the candidate texts regarding the semantic feature; The determining of the semantic features of the target text based on the word features of the target text, or the determining of the semantic features of each candidate text based on the word features of each candidate text, includes: Taking the target text or the candidate text as the current text; Encoding the current text to obtain a first text feature of the current text; The word features of the current text and the first text features are weighted to obtain the semantic features of the current text.

12. A text matching device, characterized in that: comprising a memory and a processor coupled to each other, The memory stores program instructions; The processor is used to execute the program instructions stored in the memory to implement the method according to any one of claims 1 to 10.

13. A computer-readable storage medium, characterized in that: The computer-readable storage medium is used to store program instructions, and the program instructions can be executed to implement the method according to any one of claims 1 to 10.

Citation Information

Patent Citations

  • Automatic question-answer processing method and automatic question-answer system

    CN108536708A

  • Text semantic matching method and device, computer equipment and storage medium

    CN111639502A