Text matching model training method, text matching method, device and electronic device

By using sample set-based training method in text matching, the weight of each sample and the model is retrained, the problem of easily confusing text matching in the existing technology is solved, and higher text matching accuracy is achieved .

CN113836885BActive Publication Date: 2025-02-25ALIBABA GROUP HOLDING LTD
View PDF 3 Cites 0 Cited by

Patent Information

Application Number
CN202010591487.0
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2020-06-24
Publication Date
2025-02-25
Estimated Expiration
2040-06-24

AI Technical Summary

Technical Problem

The prior art is difficult to accurately process confusing text in text matching, resulting in low accuracy of matching results.

Method used

Through the training method based on sample set, a basic model is first trained, and then its weight is calculated based on the similarity of each sample. Finally, the basic model is retrained, focusing on learning samples with high weights, thereby improving the accuracy of text matching.

Benefits of technology

This method can significantly improve the accuracy of text matching results, especially when dealing with confusing text, it can more accurately detect whether the text matches.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN113836885B_ABST
    Figure CN113836885B_ABST
Patent Text Reader

Abstract

The embodiments of the present application provide a text matching model training method, a text matching method, a device and an electronic device. The embodiments of the text matching model training method include: obtaining a basic model based on a labeled sample set training, each sample in the sample set includes a first text, a second text and a label indicating whether the first text and the second text match, and each sample has an equal weight in the process of training the basic model; using the basic model to calculate the similarity between the first text and the second text in each sample, and calculating the weight of each sample based on the similarity; training the basic model based on each sample and the weight of each sample to obtain a trained model. This implementation can provide a model that can be used for text matching, and text matching through this model can improve the accuracy of text matching results.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The embodiments of the present application relate to the field of computer technology, and in particular to a text matching model training method, a text matching method, a device and an electronic device. Background Art

[0002] In many scenarios, text matching is required. Taking the machine intelligent question-answering scenario as an example, it is usually necessary to match the user's question with the preset questions in the knowledge base, so that based on the matching results, the corresponding answer is selected from the knowledge base and returned to the customer. For example, if a user asks "Is it illegal for the company to go to work on the 3rd?", it should be matched with the question "The company requires early work" in the knowledge base, and the answer to the question "The company cannot resume work early, and the document that delays the resumption of work is mandatory" will be returned.

[0003] In the prior art, a sample set is usually constructed and a text matching model is directly trained using samples in the sample set. The similarity of two texts is detected by the text matching model, and then it is determined whether the two texts match based on the similarity. However, for some easily confused texts, such as "Is it illegal for the company to go to work on the 3rd?" and "What day do I go to work?", the text matching model generated in this way often outputs a high similarity, resulting in an incorrect text matching result, resulting in a low accuracy of the text matching result. Summary of the invention

[0004] The embodiments of the present application propose a text matching model training method, a text matching method, an apparatus and an electronic device to provide a model that can be used for text matching, and text matching through the text matching model can improve the accuracy of the text matching results.

[0005] In a first aspect, an embodiment of the present application provides a text matching model training method, comprising: obtaining a basic model based on a labeled sample set, each sample in the sample set includes a first text, a second text and a label for indicating whether the first text and the second text match, and each sample has an equal weight in the process of training the basic model; using the basic model to calculate the similarity between the first text and the second text in each sample, and calculating the weight of each sample based on the similarity; training the basic model based on each sample and the weight of each sample to obtain a trained model.

[0006] In the second aspect, an embodiment of the present application also provides a text matching method, including: receiving a question and answer request, the question and answer request including a user question text; respectively combining a preset question text in a knowledge base with the user question text, and inputting the combination into a model trained using the method in the first aspect to obtain a similarity between the user question text and the preset question text; based on the similarity, determining a target preset question text in the knowledge base that matches the user question text; obtaining a reply text associated with the target preset question text from the knowledge base, and returning the reply text.

[0007] In a third aspect, an embodiment of the present application also provides a text matching method, including: receiving a text similarity detection request, the text similarity detection request including a first text to be tested and a second text to be tested; respectively inputting the first text to be tested and the second text to be tested into a model trained using the method in the first aspect to obtain the similarity between the first text to be tested and the second text to be tested; determining whether the first text to be tested matches the second text to be tested based on the similarity, and returning the matching result.

[0008] In a fourth aspect, an embodiment of the present application also provides a text matching model training device, comprising: a first training unit, configured to obtain a basic model based on a labeled sample set, each sample in the sample set includes a first text, a second text and a label for indicating whether the first text and the second text match, and each sample has an equal weight in the process of training the basic model; a similarity calculation unit, configured to use the basic model to calculate the similarity between the first text and the second text in each sample, and calculate the weight of each sample based on the similarity; a second training unit, configured to train the basic model based on each sample and the weight of each sample to obtain a trained model.

[0009] In the fifth aspect, an embodiment of the present application also provides a text matching device, including: a receiving unit, configured to receive a question and answer request, the question and answer request including a user question text; an input unit, configured to respectively combine the preset question text in the knowledge base with the user question text, and input the combination into the model trained by the method in the first aspect to obtain the similarity between the user question text and the preset question text; a determination unit, configured to determine the target preset question text in the knowledge base that matches the user question text based on the similarity; and a return unit, configured to obtain the reply text associated with the target preset question text from the knowledge base, and return the reply text.

[0010] In the sixth aspect, an embodiment of the present application also provides a text matching device, including: a receiving unit, configured to receive a text similarity detection request, the text similarity detection request including a first text to be tested and a second text to be tested; an input unit, configured to input the first text to be tested and the second text to be tested into a model trained using the method in the first aspect, respectively, to obtain the similarity between the first text to be tested and the second text to be tested; a returning unit, configured to determine whether the first text to be tested matches the second text to be tested based on the similarity, and return the matching result.

[0011] In the seventh aspect, an embodiment of the present application also provides an electronic device, comprising: a processor; and a memory, on which executable code is stored, and when the executable code is executed, the processor executes one or more text matching model training methods or text matching methods in the embodiments of the present application.

[0012] In an eighth aspect, the embodiments of the present application further provide one or more machine-readable media on which executable codes are stored. When the executable codes are executed, the processor executes one or more text matching model training methods or text matching methods such as those in the embodiments of the present application.

[0013] Compared with the prior art, the embodiments of the present application have the following advantages:

[0014] In an embodiment of the present application, a basic model is obtained by training based on samples in a sample set, so that the basic model can be used to detect the similarity between the first text and the second text in the sample. By setting weights for the samples in the sample set according to the similarity, different weights can be set for samples containing easily confused texts and samples containing non-confusing texts. Finally, based on the samples in the sample set and the weights of the samples, the basic model is trained to obtain a trained model, which can make the model focus on learning samples with high weights during the model training process. The trained model obtained in this way can accurately detect whether the easily confused text matches, thereby improving the accuracy of the text matching results. BRIEF DESCRIPTION OF THE DRAWINGS

[0015] Other features, objects and advantages of the present application will become more apparent by reading the detailed description of non-limiting embodiments made with reference to the following drawings:

[0016] Figure 1a is a schematic diagram of a text matching scenario in an embodiment of the present application;

[0017] Figure 1b is a schematic diagram of another text matching scenario of an embodiment of the present application;

[0018] Figure 2 is a flowchart of an embodiment of the text matching model training method of the present application;

[0019] Figure 3 is a flowchart of another embodiment of the text matching model training method of the present application;

[0020] Figure 4 is a flowchart of an embodiment of the text matching method of the present application;

[0021] Figure 5 is a flowchart of another embodiment of the text matching method of the present application;

[0022] Figure 6 It is a structural schematic diagram of an embodiment of a text matching model training device of the present application;

[0023] Figure 7 is a structural schematic diagram of an embodiment of a text matching device of the present application;

[0024] Figure 8 is a structural schematic diagram of another embodiment of the text matching device of the present application;

[0025] Fig. 9 It is a schematic diagram of the structure of a device provided in one embodiment of the present application. DETAILED DESCRIPTION

[0026] The present application will be further described in detail below in conjunction with the accompanying drawings and embodiments. It is to be understood that the specific embodiments described herein are only used to explain the relevant invention, rather than to limit the invention. It should also be noted that, for ease of description, only the parts related to the relevant invention are shown in the accompanying drawings.

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

[0028] The embodiments of the present application can be applied to various scenarios that require text matching, such as intelligent question-answering scenarios, text duplication checking scenarios, text infringement scenarios, patent classification scenarios, public opinion control scenarios, etc. In intelligent matching scenarios, it is usually necessary to match the user's question text with the preset question text in the knowledge base to determine the preset question text that matches the user's intention, so as to return the answer information of the preset question text to the user. In scenarios such as text duplication checking scenarios and text infringement scenarios, it is usually necessary to match the text to be tested with the existing text to determine whether the text to be tested contains plagiarism, infringement, etc. The text matching process is the process of detecting the similarity of texts. Based on the similarity detection results, a conclusion can be drawn as to whether the two texts match.

[0029] Figure 1aIt is a schematic diagram of a text matching scenario, which can be specifically an intelligent question-answering scenario. In this scenario, a terminal device can interact with a server through a network, such as sending a question-answering request to the server and receiving a reply information returned by the server.

[0030] The terminal device may be any electronic device having a display screen and supporting network communication, including but not limited to a smart phone, a tablet computer, an e-book reader, a laptop computer, a desktop computer, etc., which is not specifically limited here.

[0031] A pre-trained model may be deployed in the server. The model may be used to detect the similarity of two texts. Based on the similarity, it may be determined whether the two texts match. The server herein may be implemented as a distributed server cluster consisting of multiple servers, or may be implemented as a single server, which is not specifically limited here.

[0032] The server can read the content of the preset knowledge base in real time. The knowledge base can contain a large number of preset question texts and answer texts corresponding to each preset question text to support the intelligent question and answer service. The knowledge base can be deployed in the server or other devices that can communicate with the server.

[0033] Take the server as the execution subject, and refer to the following steps for details:

[0034] Step S11, receiving a question and answer request.

[0035] The question-and-answer request here includes the user's question text. Figure 1a "Is it illegal for a company to go to work on the 3rd?"

[0036] In practice, various client applications may be installed in terminal devices, such as shopping applications, browsers, news and information applications, etc. Some client applications may provide an intelligent question and answer page. After the user enters and sends a question in the intelligent question and answer page, the question may be used as the user's question text, and a question and answer request including the user's question text may be sent to the server.

[0037] Step S12, respectively combining the preset question text in the knowledge base with the user question text, inputting the above combination into the trained model, and obtaining the similarity between the user question text and the preset question text.

[0038] Here, the server may combine each preset question text with the user question text to obtain multiple combinations. The server may input each combination into the above model to obtain the similarity output by the model for each combination.

[0039] It is understandable that, since there are a large number of preset question texts in the knowledge base, the preset question texts may be preliminarily screened before being combined with the user question texts, such as screening out candidate preset question texts based on keywords in the user question texts, or screening out candidate preset question texts based on question categories pre-selected by the user. Afterwards, only the similarity between each candidate preset question text and the user question text may be determined, thereby reducing the amount of data calculation.

[0040] For example, the user's question text is as follows Figure 1a In the question “Is it illegal for the company to go to work on the 3rd?”, the candidate preset question texts selected are preset question text A “The company requires going to work early” and preset question text B “What day do you go to work?”, then “Is it illegal for the company to go to work on the 3rd?” and “The company requires going to work early” can be first input into the above model to obtain the similarity between “Is it illegal for the company to go to work on the 3rd?” and “The company requires going to work early”. Then, “Is it illegal for the company to go to work on the 3rd?” and “What day do you go to work?” can be input into the above model to obtain the similarity between “Is it illegal for the company to go to work on the 3rd?” and “What day do you go to work?”.

[0041] Step S13: Based on the similarity, determine the target preset question text in the knowledge base that matches the user's question text.

[0042] The server may select the preset question text with the greatest similarity to the user's question text as the target preset question text, or may sort the preset question texts in descending order of similarity and select a preset number of preset question texts as the target preset question texts according to the sorting order. The number of target preset question texts is not specifically limited here.

[0043] Continuing with the above example, when it is necessary to select the preset question text with the greatest similarity to the user's question text as the target preset question text, if the similarity between the user's question text "Is it illegal for the company to start work on the 3rd?" and the preset question text A "The company requires to start work early" is 0.8, and the similarity between the user's question text "Is it illegal for the company to start work on the 3rd?" and the preset question text B "What day do I start work?" is 0.5, then the preset question text A "The company requires to start work early" can be used as the target preset question text.

[0044] Step S14, obtaining the answer text associated with the target preset question text from the knowledge base, and returning the answer text.

[0045] Each preset question text in the knowledge base can be associated with a reply text. For example, the reply text associated with the preset question text A "The company requires early work" can be "The enterprise cannot resume work early, and the document delaying the resumption of work is mandatory." At this time, the reply text can be returned to the terminal device. The terminal device can display the reply text in the intelligent question and answer page of the client application.

[0046] Figure 1b It is a schematic diagram of another text matching scenario, which may be a text duplication checking scenario, a text infringement scenario, etc. In this scenario, the terminal device may interact with the server through the network, thereby sending a text similarity detection request to the server, and receiving the similarity returned by the server, and then determining whether the text matches based on the similarity.

[0047] The terminal device may be any electronic device having a display screen and supporting network communication. A pre-trained model may be deployed in the server. The model may be used to detect the similarity between two texts.

[0048] Take the server as the execution subject, and refer to the following steps for details:

[0049] Step S21, receiving a text similarity detection request, wherein the text similarity detection request includes a first text to be detected and a second text to be detected.

[0050] Step S22: input the first text to be tested and the second text to be tested into the above model respectively to obtain the similarity between the first text to be tested and the second text to be tested.

[0051] Step S23, determining whether the first text to be tested matches the second text to be tested based on the similarity, and returning the matching result.

[0052] In practice, the higher the similarity, the more similar the content of the first text to be tested and the second text to be tested is. When the similarity is greater than a certain preset value, it can be considered that the first text to be tested matches the second text to be tested. On the contrary, it can be considered that the first text to be tested does not match the second text to be tested. In addition, the returned matching result can also include the above-mentioned similarity and other information.

[0053] In practice, for scenarios such as plagiarism checking and infringement, when the first text to be tested matches the second text to be tested, it can be considered that at least one of the two texts has plagiarism or infringement.

[0054] It should be noted that text matching scenarios are not limited to the above examples, but may also include patent classification scenarios, public opinion control scenarios, etc. We will not go into details here.

[0055] Continue to refer Figure 2, showing a flowchart of an embodiment of the text matching model training method of the present application. The text matching model training method can be applied to electronic devices such as servers. The model trained by the text matching model training method can be applied to various text matching scenarios such as intelligent question and answer scenarios, text duplicate checking scenarios, text infringement scenarios, patent classification scenarios, and public opinion control scenarios.

[0056] The process of the text matching model training method includes the following steps:

[0057] Step 201: A basic model is obtained by training based on the labeled sample set.

[0058] In this embodiment, the execution subject (such as an electronic device such as a server) of the text matching model training method can pre-acquire a labeled sample set in a variety of ways. For example, the execution subject can obtain an existing sample set stored in another server (such as a database server) for storing samples through a wired connection or a wireless connection. For another example, a user can collect samples through a terminal device and store these samples locally to generate a sample set. It should be noted that the above-mentioned wireless connection method may include but is not limited to 3G / 4G connection, WiFi connection, Bluetooth connection, WiMAX connection, Zigbee connection, UWB (ultra wideband) connection, and other wireless connection methods currently known or to be developed in the future.

[0059] Here, the sample set may include a large number of samples. Each sample may be a triple. Each triple may include a first text, a second text, and a label indicating whether the first text matches the second text. For example, if the first text matches the second text, the label may be 1. If the first text does not match the second text, the label may be 0. The characters of the label are not specifically limited here. In addition, the first text and the second text in the sample may be texts in various languages, such as Chinese text, English text, etc., which are not limited here.

[0060] In this embodiment, the execution subject can obtain a basic model based on the above sample set training. Among them, each sample has equal weight in the process of training the above basic model. In practice, the execution subject can use all or part of the samples in the sample set to train the basic model. At the same time, the execution subject can use various models capable of natural language processing to train the basic model. Such as CNN (Convolutional Neural Network), BERT (Bidirectional Encoder Representations from Transformer, bidirectional encoder representation based on transformer) model, etc.

[0061] Among them, the BERT model is an open source language model applied to natural language processing tasks. The BERT model has a multi-layer transformer. The transformer is a network structure based on the attention mechanism. The network structure can calculate the relationship between each word in a text and all the words in the text, and calculate the importance (weight) of each word based on the relationship between words, so as to obtain a new expression (such as a new vector) for each word. The above new expression not only involves the characteristics of the word itself, but also involves the relationship between other words and this word, so it is more global than the traditional word vector. Since the BERT model uses a multi-layer transformer (specifically the encoder in the transformer), the BERT model can learn the contextual relationship between words in the text. In addition, the encoder in the transformer uses a one-time reading method to read the text, which supports the BERT model's two-way learning of the text. Therefore, compared with the language model that only supports one-way learning of the text, the BERT model can more accurately learn the contextual relationship between each word in the text, and the understanding of the context is deeper than the one-way language model. Therefore, the BERT model has better task processing effects than other models for natural language processing tasks.

[0062] During the training process, the execution subject can select samples from the sample set in batches, and use the first text and the second text in the selected samples as model inputs to obtain the similarity of the model output for the text in each selected sample. Based on the similarity of the text in each sample, a loss value can be determined. The loss value can be used to characterize the difference between the first text and the second text. The larger the loss value, the greater the difference. The loss value can be calculated using a commonly used loss function, such as a cross entropy loss function. After obtaining the loss value corresponding to each sample selected in the current batch, the loss values ​​can be summed to obtain the total loss value. It should be noted that if only one sample is selected for each training, the total loss value is the loss value of the selected sample. Then, based on the total loss value, the parameters of the model can be updated. Therefore, each time a batch of samples is selected, the model can be trained once based on the batch of samples, so that the parameters of the model are updated once. In this process, multiple trainings are iterated until the training is completed.

[0063] In practice, whether training is completed can be determined in a variety of ways. As an example, if the similarity output by the model is greater than a preset value, it indicates that the two texts match, and if it is less than or equal to the preset value, it indicates that the two texts do not match, then the text matching results corresponding to each sample can be obtained during the training process. When the accuracy of the text matching results determined based on the annotations in the sample is greater than a preset threshold (for example, 95%), it can be determined that the training is complete. As another example, if the number of iterative training times of the model is equal to a preset number, it can be determined that the training is complete. Here, when it is determined that the training is complete, the trained model can be determined as the basic model.

[0064] In some optional implementations of this embodiment, the samples in the sample set may be generated by the following steps:

[0065] The first step is to obtain a text set containing multiple texts.

[0066] The text in the text set can be obtained for a text matching scenario. For example, if the text matching scenario is an intelligent question-answering scenario, the user question text can be extracted from the historical question-answering requests sent by the terminal device, and the extracted user question text can be summarized into a text set.

[0067] In the second step, the first text and the second text are randomly selected from the text set.

[0068] In some examples, two texts may be randomly selected from the text set as the first text and the second text, respectively. In other examples, a text may be randomly selected from the text set as the first text, and then a text may be randomly selected from the text set as the second text, in which case the first text and the second text may be the same.

[0069] The third step is to determine a markup for indicating whether the first text and the second text match.

[0070] The annotations here can be set manually by the technicians or automatically determined by the above-mentioned execution subject. Taking the intelligent question-answering scenario as an example, if the text in the text set is the user question text in the historical question-answering request, the above-mentioned execution subject can set annotations for the corresponding two texts based on the user's evaluation of the reply files returned by each historical question-answering request.

[0071] Specifically, after the user sends a historical question-and-answer request, the above-mentioned execution entity will match the user question text in the request with the preset question text in the knowledge base. After determining the target preset question text that matches the user question text, the above-mentioned execution entity will feed back the reply text associated with the target preset question text to the user. While sending the reply text, the above-mentioned execution entity may also send an inquiry message to the user to ask the user whether the reply text is helpful. If the user feedback is "helpful", the annotation of the sample where the above-mentioned user question text and the target preset question text are in common can be set to 1. If the user feedback is "not helpful", the annotation of the sample where the above-mentioned user question text and the target preset question text are in common can be set to 0.

[0072] In the fourth step, the triple (q1, q2, label) consisting of the first text (which can be represented as q1), the second text (which can be represented as q1) and the label (which can be represented as label) is taken as a sample. In this way, multiple samples can be quickly generated based on the text set. After the samples are aggregated, the sample set can be obtained. It can be understood that when the sample set is aggregated, the samples can also be deduplicated to avoid duplicate samples in the sample set.

[0073] Step 202: Calculate the similarity between the first text and the second text in each sample using the basic model, and calculate the weight of each sample according to the similarity.

[0074] In this embodiment, the execution subject can use the basic model to calculate the similarity between two texts in each sample in the sample set. Specifically, samples can be extracted from the sample set one by one, and the first text and the second text in the sample are input into the basic model to obtain the similarity between the first text and the second text in the sample.

[0075] The similarity of the two texts output by the basic model can characterize the degree of matching of the two texts. The higher the similarity, the higher the degree of matching. Usually, when determining whether two texts match based on similarity, a preset threshold can be set. When the similarity of the two texts is greater than the preset threshold, the two texts can be considered to match. If the similarity of the two texts is less than the preset threshold, the two texts can be considered to be unmatched. Thus, for two matching texts, such as "How to modify user name" and "User name modification method", the vocabulary in the two texts is very similar, and the features of the two texts are similar. The basic model is easy to output a higher similarity (such as 1 or 0.9, etc.), so that the correct conclusion that the two match can be drawn. For two unmatched texts, such as "How to modify user name" and "Recommend several mobile phones", the two texts are completely unrelated, so the basic model is easy to output a lower similarity (such as 0.1 or 0.2, etc.), so that the correct conclusion that the two do not match can be drawn.

[0076] However, for other matching texts, such as "Is it illegal for the company to go to work on the 3rd?" and "The company requires early resumption of work", although both of them are intended to ask whether the company can resume work in advance, there are fewer similar words in the two texts, and the basic model training process does not focus on learning such samples due to the same sample weights, so the basic model usually cannot output a high similarity (such as the output similarity is only 0.55). When the preset threshold (such as 0.6) used to determine whether the text matches is greater than the similarity output by the model, an erroneous conclusion that the two do not match will be drawn at this time. Similarly, for other matching texts, such as "Is it illegal for the company to go to work on the 3rd?" and "What day to go to work", although the two contain more similar words, the two have different intentions (one asks whether the company can resume work in advance, and the other asks the date of work). Because the basic model training process does not focus on learning such samples due to the same sample weights, the basic model usually cannot output a low similarity (such as the output similarity is 0.65). When the preset threshold (such as 0.6) used to determine whether the text matches is less than the similarity output by the model, an erroneous conclusion will be drawn that the two match.

[0077] Therefore, it is not easy to obtain accurate matching results for matching two easily confused texts by directly using the basic model.

[0078] In this embodiment, weights can be set for samples in the sample set based on the calculated similarities of each sample, so that samples belonging to two easily confused texts have higher weights, and the model focuses on learning such samples, thereby improving the accuracy of matching results for easily confused texts.

[0079] In some optional implementations of the present embodiment, the above-mentioned execution subject can set weights for samples based on the difference between the similarity of two texts in the sample and the preset threshold value used to determine whether the texts match, so that the weight of the text that is closer to the preset threshold value is higher. Therefore, the higher the weight of the sample, the more difficult it is to detect whether the two texts match. Using the weighted samples to train the basic model again can make the model focus on the learning of samples that are not easy to accurately detect whether the two texts match during the model training process. Based on the model obtained after the training is completed, it is possible to accurately detect whether two easily confused texts match.

[0080] In some optional implementations of this embodiment, the execution entity may also first determine the positive samples and negative samples in the sample set. As an example, the positive sample may be a sample in which the first text matches the second text. The negative sample may be a sample in which the first text does not match the second text. The positive sample and the negative sample may be determined based on the annotations in the sample. Then, the execution entity may set the weight of the positive sample in the sample set to a value that is negatively correlated with the similarity, and set the weight of the negative sample in the sample set to a value that is positively correlated with the similarity.

[0081] It is understandable that, for positive samples, the smaller the similarity between the two texts in the positive sample, the easier it is for the two texts to be drawn into an erroneous conclusion that they do not match, and thus the model should strengthen its learning of the positive sample. Similarly, for negative samples, the greater the similarity between the two texts in the negative sample, the easier it is for the two texts to be drawn into an erroneous conclusion that they match, and thus the model should strengthen its learning of the negative sample. Therefore, setting the weight of the positive sample in the sample set to a value that is negatively correlated with the similarity, and setting the weight of the negative sample in the sample set to a value that is positively correlated with the similarity, can enable the model to strengthen its learning of samples in which it is difficult to accurately detect whether the two texts match. Based on the model obtained after the training is completed, it is possible to accurately detect whether two easily confused texts match.

[0082] It should be noted that the weight of the positive sample in the sample set can be set to a value that is negatively correlated with the similarity by setting a function, setting a table of correspondence between similarity and weight, etc. Similarly, the weight of the negative sample in the sample set can be set to a value that is positively correlated with the similarity by a similar method. This is not limited here.

[0083] In some optional implementations of this embodiment, after determining the positive samples and negative samples in the sample set, the execution subject may also set the weights of the samples according to the following steps:

[0084] First, the positive samples containing the same first text are combined into a positive sample group, and the negative samples containing the same first text are combined into a negative sample group. Thus, the positive samples can be divided into at least one positive sample group and the negative samples can be divided into at least one negative sample group according to the difference of the first text. By dividing in this way, each sample can exist in only one sample group. It should be noted that the second text can also be used when dividing the positive sample group and the negative sample group, which will not be repeated here.

[0085] Then, the positive samples in the positive sample group and the negative samples in the negative sample group can be sorted according to the size of the text similarity. Specifically, for each positive sample group, the positive samples in the positive sample group can be sorted in the order of the similarity between the first text and the second text from large to small. Alternatively, the positive samples in the positive sample group can be sorted in the order of the similarity between the first text and the second text from small to large. Similarly, for each negative sample group, the negative samples in the negative sample group can be sorted in the order of the similarity between the first text and the second text from large to small. Alternatively, the negative samples in the negative sample group can be sorted in the order of the similarity between the first text and the second text from small to large.

[0086] Finally, weights may be set for the positive samples in the positive sample group based on the sorting order of the positive samples in the positive sample group, and weights may be set for the negative samples in the negative sample group based on the sorting order of the negative samples in the negative sample group. Specifically, the following situations may be included: if the positive samples in the positive sample group are sorted in order of similarity from small to large, the weights of the positive samples in the positive sample group are set to values ​​that are negatively correlated with the sorting order. If the positive samples in the positive sample group are sorted in order of similarity from large to small, the weights of the positive samples in the positive sample group are set to values ​​that are positively correlated with the sorting order. If the negative samples in the negative sample group are sorted in order of similarity from small to large, the weights of the negative samples in the negative sample group are set to values ​​that are positively correlated with the sorting order; if the negative samples in the negative sample group are sorted in order of similarity from large to small, the weights of the negative samples in the negative sample group are set to values ​​that are negatively correlated with the sorting order.

[0087] It should be noted that the weights are set according to the sorting order here, and can also be implemented based on a preset function, a corresponding relationship table, etc., which will not be elaborated here.

[0088] It should be pointed out that the above-mentioned execution subject can also set the weight of the sample in combination with the above-mentioned two methods at the same time. For example, the weights set according to the above-mentioned two methods are respectively used as the first weight and the second weight, and the first weight and the second weight of the same sample are weighted and summed to obtain the final weight. Alternatively, the weight of the sample can be set in combination with other methods on the basis of combining the above-mentioned two methods. For example, positive samples and negative samples containing the same first text can be divided into a sample group, and the similarities of the samples in the sample group are sorted. Different third weights are set for samples of different orders. And the first weight, the second weight and the third weight of the same sample are weighted and summed to obtain the final weight. The weight setting method is not limited to the above-mentioned enumeration, and will not be repeated here one by one.

[0089] Step 203: train the basic model according to each sample and the weight of each sample to obtain a trained model.

[0090] In this embodiment, after setting weights for the samples in the sample set, the execution subject can use the samples in the sample set to retrain the basic model in a fine-tuning manner to obtain a trained model. During the training process, the model can focus on learning samples with higher weights. Since samples with higher weights are usually samples containing easily confused texts, the trained model can accurately detect whether the easily confused texts are matched, thereby improving the accuracy of the text matching results.

[0091] In some optional implementations of this embodiment, the execution subject may train the basic model through the following sub-steps S31 to S36 to obtain a trained model:

[0092] Sub-step S31, extracting samples in batches from the sample set, and using the extracted samples as target samples.

[0093] The method of extracting samples is not limited in this application. For example, a preset number of samples may be randomly extracted, or a preset number of samples may be extracted from a sample set in a specified order.

[0094] After extracting the samples, a training step including the following sub-steps S32 to S34 may be performed.

[0095] Sub-step S32, inputting the first text and the second text in the target sample into the basic model to determine the loss value of the target sample.

[0096] Here, for each target sample, the execution subject may input the first text and the second text in the target sample into the basic model, and obtain the similarity of the two texts in the target sample output by the basic model. Then, the similarity of the two texts in each target sample may be input into a preset loss function, such as a cross entropy loss function, to determine the loss value of each target sample.

[0097] Sub-step S33, based on the weight of the target sample, weighted sum of the loss values ​​of the target sample is performed to obtain a total loss value.

[0098] Sub-step S34, adjusting the parameters of the basic model based on the total loss value.

[0099] Here, the back propagation algorithm can be used to obtain the gradient of the total loss value relative to the model parameters, and then the gradient descent algorithm can be used to update the model parameters based on the gradient.

[0100] Sub-step S35, if the preset end training condition is met, the basic model after adjusting the parameters is determined as the trained model.

[0101] In practice, the end training condition can be set in a variety of ways. As an example, the loss value converges and the converged value is less than a certain target value as a preset end training condition. As another example, the number of iterative training times equal to the preset number of times can also be used as a preset end training condition, which is not specifically limited here. If the preset end training condition is met, the basic model after adjusting the parameters is determined as the trained model.

[0102] Sub-step S36, if the preset end training condition is not met, samples can be re-extracted in batches from the sample set, and the re-extracted samples are used as target samples. The basic model with adjusted parameters is used to re-execute the above training steps until the end condition is met.

[0103] The method provided by the above-mentioned embodiment of the present application obtains a basic model through training based on the samples in the sample set, so that the basic model can be used to detect the similarity between the first text and the second text in the sample. By setting weights for the samples in the sample set according to the similarity, different weights can be set for samples containing easily confused texts and samples containing non-confusing texts. Finally, based on the samples in the sample set and the weights of the samples, the basic model is trained to obtain a trained model, which can make the model focus on learning samples with high weights during the model training process. The trained model obtained in this way can accurately detect whether the easily confused texts are matched, thereby improving the accuracy of the text matching results.

[0104] Further references Figure 3 , which shows a flow chart of another embodiment of a text matching model training method. The text matching model training method can be applied to electronic devices such as servers.

[0105] The text matching model generation and training process includes the following steps:

[0106] Step 301: Train a basic model based on the labeled sample set.

[0107] Step 302: Calculate the similarity between the first text and the second text in each sample using the basic model.

[0108] Steps 301 to 302 in this embodiment can be found in Figure 2 Steps 201 to 202 of the corresponding embodiment are not described in detail here.

[0109] Step 303: determine the positive samples and negative samples in the sample set.

[0110] As an example, a positive sample may be a sample in which the first text matches the second text, and a negative sample may be a sample in which the first text does not match the second text. Positive samples and negative samples may be determined by annotations in the samples.

[0111] Step 304: Combine positive samples containing the same first text into a positive sample group, combine negative samples containing the same first text into a negative sample group, and sort the positive samples in the positive sample group and the negative samples in the negative sample group according to the similarity of the texts.

[0112] In this embodiment, the execution subject may first combine positive samples containing the same first text into a positive sample group, and combine negative samples containing the same first text into a negative sample group. Thus, the positive samples may be divided into at least one positive sample group and the negative samples may be divided into at least one negative sample group according to the difference in the first text. By dividing in this way, each sample may exist in only one sample group.

[0113] For each positive sample group, the positive samples in the positive sample group may be sorted in descending order of the similarity between the first text and the second text. Alternatively, the positive samples in the positive sample group may be sorted in ascending order of the similarity between the first text and the second text. Similarly, for each negative sample group, the negative samples in the negative sample group may be sorted in descending order of the similarity between the first text and the second text. Alternatively, the negative samples in the negative sample group may be sorted in ascending order of the similarity between the first text and the second text.

[0114] Step 305: Set a first weight and a second weight for each sample respectively.

[0115] In this embodiment, the execution entity may set a first weight and a second weight for each sample in the sample set, respectively. The first weight of the positive sample is a value that is negatively correlated with the similarity between the first text and the second text in the positive sample. The second weight of the negative sample is a value that is positively correlated with the similarity between the first text and the second text in the negative sample.

[0116] It is understandable that, for the positive sample, the smaller the similarity between the two texts in the positive sample, the easier it is to draw the wrong conclusion that the two texts do not match, and thus the model should strengthen the learning of the positive sample. Similarly, for the negative sample, the greater the similarity between the two texts in the negative sample, the easier it is to draw the wrong conclusion that the two texts match, and thus the model should strengthen the learning of the negative sample. Thus, setting the first weight of the positive sample in the sample set to a value that is negatively correlated with the similarity, and setting the first weight of the negative sample in the sample set to a value that is positively correlated with the similarity, can enable the model to strengthen the learning of samples that are not easy to accurately detect whether the two texts match. Based on the model obtained after the training is completed, it is possible to accurately determine whether the two easily confused texts match.

[0117] It should be noted that the first weight of the positive sample can be set to a value that is negatively correlated with the similarity by setting a function, setting a table of correspondence between the similarity and the first weight, etc. Similarly, the weight of the negative sample can also be set to a value that is positively correlated with the similarity in a similar manner. This is not limited here.

[0118] In this embodiment, the second weight of the positive sample is determined based on the sorting order in the positive sample group to which the positive sample belongs, and the second weight of the negative sample is determined based on the sorting order in the negative sample group to which the negative sample belongs. Specifically, for each positive sample group, in response to the positive samples in the positive sample group being sorted in order from small to large in similarity, the weight of the positive sample in the positive sample group may be set to a value that is negatively correlated with the sorting order. In response to the positive samples in the positive sample group being sorted in order from large to small in similarity, the weight of the positive sample in the positive sample group is set to a value that is positively correlated with the sorting order. For each negative sample group, in response to the negative samples in the negative sample group being sorted in order from small to large in similarity, the weight of the negative sample in the negative sample group is set to a value that is positively correlated with the sorting order. In response to the negative samples in the negative sample group being sorted in order from large to small in similarity, the weight of the negative sample in the negative sample group is set to a value that is negatively correlated with the sorting order.

[0119] It should be noted that the second weight is set according to the sorting order here, and it can also be implemented based on a preset function, a corresponding relationship table, etc., which will not be elaborated here.

[0120] Step 306: Perform a weighted summation on the first weight and the second weight of each sample to obtain the weight of each sample.

[0121] In this embodiment, the execution subject may first obtain a preset coefficient corresponding to the first weight and a preset coefficient corresponding to the second weight. Then, for each sample in the sample set, the execution subject may use the coefficient of the first weight and the coefficient of the second weight to weighted sum the first weight and the second weight of the sample to obtain the weight of the sample. Thus, the weight of each sample in the sample set combines the first weight and the second weight of the sample. The first weight is determined by the similarity of the text of the sample, and the second weight is determined by the order of the sample in the sample group to which it belongs. Therefore, this weight setting method can take into account the similarity of the text itself and the relationship with related samples, taking into account more information, thereby improving the accuracy and rationality of the weight.

[0122] Step 307: train the basic model according to each sample and the weight of each sample to obtain a trained model.

[0123] In this embodiment, step 307 can be seen in Figure 2The step 203 of the corresponding embodiment will not be described in detail here.

[0124] The steps of this embodiment are similar to the description of the corresponding steps in the above embodiment, and the details can be found in the description of the above embodiment.

[0125] from Figure 3 It can be seen that Figure 2 Compared with the corresponding embodiment, the process of the text matching model training method in this embodiment highlights the steps of setting the first weight and the second weight for the sample, and setting the final weight for the sample in combination with the first weight and the second weight. The first weight is determined by the similarity of the text of the sample, and the second weight is determined by the order of the sample in the sample group to which it belongs. Therefore, this weight setting method can take into account the similarity of the text itself and the relationship with related samples, taking into account more information, and improving the accuracy and rationality of the weight.

[0126] See also Figure 4 , which shows the process of an embodiment of the text matching method provided by the present application. The text matching method can be applied to text matching scenarios such as intelligent question-answering scenarios. The text matching method may include the following steps:

[0127] Step 401: receiving a question and answer request.

[0128] In this embodiment, the execution subject of the text matching method (for example Figure 1a The server shown in FIG. 1 may receive a question-and-answer request, wherein the question-and-answer request includes a user question text.

[0129] The above-mentioned question-and-answer request can be sent by a terminal device. In practice, various client applications can be installed in the terminal device, such as shopping applications, browsers, news and information applications, etc. Some client applications can provide an intelligent question-and-answer page. After the user enters and sends a question in the intelligent question-and-answer page, the question can be used as the user's question text, and a question-and-answer request containing the user's question text can be sent to the above-mentioned execution entity.

[0130] Step 402 , respectively combine the preset question text in the knowledge base with the user question text, input the combination into the trained model, and obtain the similarity between the user question text and the preset question text.

[0131] In this embodiment, the trained model can be as described above. Figure 2 or Figure 3 The specific training process can be found in Figure 2 or Figure 3 The relevant description of the corresponding embodiments will not be repeated here.

[0132] Step 403: Based on the similarity, determine the target preset question text in the knowledge base that matches the user's question text.

[0133] Here, for each combination of a preset question text and a user question text, the trained model can output a similarity. The above-mentioned execution subject can select the preset question text with the greatest similarity to the user question text as the target preset question text. In addition, it is also possible to sort the similarities from large to small, and select a preset number of preset question texts as the target preset question texts according to the sorting order.

[0134] Step 404, obtaining the answer text associated with the target preset question text from the knowledge base, and returning the answer text.

[0135] It should be noted that the text matching method of this embodiment can be used to test the trained models of the above embodiments. Then, the trained model can be continuously optimized according to the test results. This method can also be a practical application method of the models trained in the above embodiments. Using the models trained in the above embodiments to perform text matching helps to improve the performance of the trained model. At the same time, using this model for text matching improves the accuracy of the text matching results, so that the answer information fed back to the user in the intelligent question and answer scenario is more in line with the user's inquiry intention.

[0136] See also Figure 5 , which shows the process of an embodiment of the text matching method provided by the present application. The text matching method can be applied to various text matching scenarios such as text duplication checking scenario, text infringement scenario, patent classification scenario, public opinion control scenario, etc. The text matching method may include the following steps:

[0137] Step 501: receiving a text similarity detection request.

[0138] In this embodiment, the execution subject of the text matching method (for example Figure 1b The server shown in FIG. 1 may receive a text similarity detection request. The text similarity detection request may include a first text to be tested and a second text to be tested. The text similarity detection request may be sent by a terminal device.

[0139] Step 502: input the first text to be tested and the second text to be tested into the trained model respectively to obtain the similarity between the first text to be tested and the second text to be tested.

[0140] In this embodiment, the trained model can be as described above. Figure 2 or Figure 3 The specific training process can be found in Figure 2 or Figure 3The relevant description of the corresponding embodiments will not be repeated here.

[0141] Step 503: determine whether the first text to be tested matches the second text to be tested based on the similarity, and return the matching result.

[0142] In practice, the higher the similarity, the more similar the content of the first text to be tested and the second text to be tested is. When the similarity is greater than a certain preset value, it can be considered that the first text to be tested matches the second text to be tested. When the similarity is less than or equal to the preset value, it can be considered that the first text to be tested does not match the second text to be tested. The matching result can also include the above similarity.

[0143] In practice, for scenarios such as plagiarism checking and infringement, when the first text to be tested matches the second text to be tested, it can be considered that at least one of the two texts has plagiarism or infringement.

[0144] It should be noted that the text matching method of this embodiment can be used to test the trained model of the above embodiments. Then, the trained model can be continuously optimized according to the test results. This method can also be a practical application method of the trained model of the above embodiments. Using the trained model of the above embodiments to perform text matching helps to improve the performance of the trained model. At the same time, using the trained model to perform text matching improves the accuracy of the text matching results.

[0145] It should be noted that, for the method embodiments, for the sake of simplicity, they are all expressed as a series of action combinations, but those skilled in the art should be aware that the embodiments of the present application are not limited by the described order of actions, because according to the embodiments of the present application, certain steps can be performed in other orders or simultaneously. Secondly, those skilled in the art should also be aware that the embodiments described in the specification are all preferred embodiments, and the actions involved are not necessarily required by the embodiments of the present application.

[0146] Further references Figure 6 Based on the above embodiments, the present application provides an embodiment of a text matching model training device, which can be specifically applied to various electronic devices.

[0147] like Figure 6As shown, the text matching model training device 600 of this embodiment includes: a first training unit 601, which is configured to obtain a basic model based on a labeled sample set for training, wherein each sample in the sample set includes a first text, a second text and a label indicating whether the first text and the second text match, and each sample has an equal weight in the process of training the basic model; a similarity calculation unit 602, which is configured to calculate the similarity between the first text and the second text in each sample using the basic model, and calculate the weight of each sample according to the similarity; a second training unit 603, which is configured to train the basic model according to each sample and the weight of each sample to obtain a trained model.

[0148] In some optional implementations of the present embodiment, the samples in the sample set are generated by the following steps: obtaining a text set containing multiple texts; randomly selecting the first text and the second text in the text set; determining an annotation for indicating whether the first text and the second text match; and taking a triple consisting of the first text, the second text and the annotation as a sample.

[0149] In some optional implementations of this embodiment, the similarity calculation unit 602 is further configured to: determine positive samples and negative samples in the sample set, the positive samples are samples in which the first text matches the second text, and the negative samples are samples in which the first text does not match the second text; set the weight of the positive samples in the sample set to a value that is negatively correlated with the similarity, and set the weight of the negative samples in the sample set to a value that is positively correlated with the similarity.

[0150] In some optional implementations of the present embodiment, the similarity calculation unit 602 is further configured to: determine positive samples and negative samples in the sample set, the positive samples being samples in which the first text matches the second text, and the negative samples being samples in which the first text does not match the second text; combine positive samples containing the same first text into a positive sample group, and combine negative samples containing the same first text into a negative sample group, and sort the positive samples in the positive sample group and the negative samples in the negative sample group according to the size of the text similarity; set weights for the positive samples in the positive sample group based on the sorting order of the positive samples in the positive sample group, and set weights for the negative samples in the negative sample group based on the sorting order of the negative samples in the negative sample group.

[0151] In some optional implementations of the present embodiment, the similarity calculation unit 602 is further configured to: in response to the positive samples in the positive sample group being sorted in order from small to large similarity, set the weights of the positive samples in the positive sample group to numerical values ​​that are negatively correlated with the sorting order; in response to the positive samples in the positive sample group being sorted in order from large to small similarity, set the weights of the positive samples in the positive sample group to numerical values ​​that are positively correlated with the sorting order.

[0152] In some optional implementations of the present embodiment, the similarity calculation unit 602 is further configured to: in response to the negative samples in the negative sample group being sorted in order of similarity from small to large, set the weights of the negative samples in the negative sample group to values ​​that are positively correlated with the sorting order; in response to the negative samples in the negative sample group being sorted in order of similarity from large to small, set the weights of the negative samples in the negative sample group to values ​​that are negatively correlated with the sorting order.

[0153] In some optional implementations of the present embodiment, the similarity calculation unit 602 is further configured to: determine positive samples and negative samples in the sample set, the positive samples are samples in which the first text matches the second text, and the negative samples are samples in which the first text does not match the second text; combine the positive samples containing the same first text into a positive sample group, and combine the negative samples containing the same first text into a negative sample group, and sort the positive samples in the positive sample group and the negative samples in the negative sample group according to the size of the text similarity; set a first weight and a second weight for each of the samples, wherein the first weight of the positive sample is negatively correlated with the similarity between the first text and the second text in the positive sample, the second weight of the negative sample is positively correlated with the similarity between the first text and the second text in the negative sample, the second weight of the positive sample is determined based on the sorting order in the positive sample group to which it belongs, and the second weight of the negative sample is determined based on the sorting order in the negative sample group to which it belongs; and perform weighted summation on the first weight and the second weight of each of the samples to obtain the weight of each sample.

[0154] In some optional implementations of this embodiment, the second training unit 603 is further configured to: extract samples in batches from the sample set, use the extracted samples as target samples, and perform the following training steps: input the first text and the second text in the target sample into the basic model, and determine the loss value of the target sample based on the output of the basic model; perform weighted summation on the loss value of the target sample based on the weight of the target sample to obtain a total loss value; adjust the parameters of the basic model based on the total loss value;

[0155] If the preset training end condition is met, the basic model after adjusting the parameters is determined as the trained model;

[0156] If the above preset training termination conditions are not met, samples are re-extracted in batches from the above sample set, and the re-extracted samples are used as target samples. The above training steps are re-executed using the basic model with adjusted parameters.

[0157] The device provided by the above-mentioned embodiment of the present application obtains a basic model through training based on the samples in the sample set, so that the basic model can be used to detect the similarity between the first text and the second text in the sample. By setting weights for the samples in the sample set according to the similarity, different weights can be set for samples containing easily confused texts and samples containing non-confusing texts. Finally, based on the samples in the sample set and the weights of the samples, the basic model is trained to obtain a trained model, which can make the model focus on learning samples with high weights during the model training process. The trained model obtained in this way can accurately detect whether the easily confused text matches, thereby improving the accuracy of the text matching results.

[0158] Further references Figure 7 Based on the above embodiments, the present application provides an embodiment of a text matching device, which can be specifically applied to various electronic devices.

[0159] like Figure 7 As shown, the text matching device 700 of this embodiment includes: a receiving unit 701, configured to receive a question and answer request, wherein the question and answer request includes a user question text; an input unit 702, configured to respectively combine the preset question text in the knowledge base with the user question text, and input the combination into the trained model to obtain the similarity between the user question text and the preset question text; a determining unit 703, configured to determine the target preset question text in the knowledge base that matches the user question text based on the similarity; and a returning unit 704, configured to obtain a reply text associated with the target preset question text from the knowledge base, and return the reply text.

[0160] It is understood that the units described in the device are similar to those described in the reference Figure 4 Therefore, the operations, features and beneficial effects described above for the method are also applicable to the device and the units contained therein, and will not be repeated here.

[0161] Further references Figure 8 Based on the above embodiments, the present application provides an embodiment of a text matching device, which can be specifically applied to various electronic devices.

[0162] like Figure 8 As shown, the text matching device 800 of this embodiment includes: a receiving unit 801, configured to receive a text similarity detection request, wherein the text similarity detection request includes a first text to be tested and a second text to be tested; an input unit 802, configured to input the first text to be tested and the second text to be tested into the trained model respectively to obtain the similarity between the first text to be tested and the second text to be tested; a returning unit 803, configured to determine whether the first text to be tested matches the second text to be tested based on the similarity, and return the matching result.

[0163] It is understood that the units described in the device are similar to those described in the reference Figure 5 Therefore, the operations, features and beneficial effects described above for the method are also applicable to the device and the units contained therein, and will not be repeated here.

[0164] The embodiment of the present application also provides a non-volatile readable storage medium, which stores one or more modules (programs). When the one or more modules are applied to a device, the device can execute instructions (instructions) of each method step in the embodiment of the present application.

[0165] The present application embodiment provides one or more machine-readable media on which instructions are stored, and when executed by one or more processors, an electronic device executes one or more of the methods described in the above embodiments. In the present application embodiment, the electronic device includes various types of devices such as terminal devices and servers (clusters).

[0166] The embodiments of the present disclosure may be implemented as a device configured as desired using any appropriate hardware, firmware, software, or any combination thereof, and the device may include electronic devices such as terminal devices and servers (clusters). Fig. 9 An exemplary apparatus 900 that can be used to implement various embodiments described in this application is schematically illustrated.

[0167] For one embodiment, Fig. 9 An exemplary apparatus 900 is shown having one or more processors 902, a control module (chip set) 904 coupled to at least one of the processor(s) 902, a memory 906 coupled to the control module 904, a non-volatile memory (NVM) / storage device 908 coupled to the control module 904, one or more input / output devices 910 coupled to the control module 904, and a network interface 912 coupled to the control module 904.

[0168] The processor 902 may include one or more single-core or multi-core processors, and the processor 902 may include any combination of general-purpose processors or special-purpose processors (such as graphics processors, application processors, baseband processors, etc.). In some embodiments, the device 900 can be used as a terminal device, server (cluster), etc. described in the embodiments of the present application.

[0169] In some embodiments, the apparatus 900 may include one or more computer-readable media (e.g., memory 906 or NVM / storage device 908) having instructions 914 and one or more processors 902 combined with the one or more computer-readable media and configured to execute the instructions 914 to implement a module to perform the actions described in the present disclosure.

[0170] For one embodiment, the control module 904 may include any suitable interface controller to provide any suitable interface to at least one of the processor(s) 902 and / or any suitable device or component in communication with the control module 904 .

[0171] The control module 904 may include a memory controller module to provide an interface to the memory 906. The memory controller module may be a hardware module, a software module, and / or a firmware module.

[0172] The memory 906 may be used, for example, to load and store data and / or instructions 914 for the device 900. For one embodiment, the memory 906 may include any suitable volatile memory, such as a suitable DRAM. In some embodiments, the memory 906 may include double data rate type four synchronous dynamic random access memory (DDR4 SDRAM).

[0173] For one embodiment, control module 904 may include one or more input / output controllers to provide an interface to NVM / storage device 908 and input / output device(s) 910 .

[0174] For example, NVM / storage 908 may be used to store data and / or instructions 914. NVM / storage 908 may include any suitable non-volatile memory (e.g., flash memory) and / or may include any suitable non-volatile storage device(s) (e.g., one or more hard disk drives (HDDs), one or more compact disk (CD) drives, and / or one or more digital versatile disk (DVD) drives).

[0175] NVM / storage device 908 may include storage resources that are physically part of the device on which apparatus 900 is installed, or it may be accessible to the device without being part of the device. For example, NVM / storage device 908 may be accessed via (one or more) input / output devices 910 over a network.

[0176] (One or more) input / output devices 910 may provide an interface for the apparatus 900 to communicate with any other appropriate device, and the input / output device 910 may include a communication component, an audio component, a sensor component, etc. The network interface 912 may provide an interface for the apparatus 900 to communicate through one or more networks, and the apparatus 900 may wirelessly communicate with one or more components of a wireless network according to any of one or more wireless network standards and / or protocols, for example, accessing a wireless network based on a communication standard, such as WiFi, 2G, 3G, 4G, 5G, etc., or a combination thereof for wireless communication.

[0177] For one embodiment, at least one of the processor(s) 902 may be packaged together with the logic of one or more controllers (e.g., a memory controller module) of the control module 904. For one embodiment, at least one of the processor(s) 902 may be packaged together with the logic of one or more controllers of the control module 904 to form a system-in-package (SiP). For one embodiment, at least one of the processor(s) 902 may be integrated on the same die with the logic of one or more controllers of the control module 904. For one embodiment, at least one of the processor(s) 902 may be integrated on the same die with the logic of one or more controllers of the control module 904 to form a system-on-chip (SoC).

[0178] In various embodiments, the device 900 may be, but is not limited to, a terminal device such as a server, a desktop computing device, or a mobile computing device (e.g., a laptop computing device, a handheld computing device, a tablet computer, a netbook, etc.). In various embodiments, the device 900 may have more or fewer components and / or a different architecture. For example, in some embodiments, the device 900 includes one or more cameras, a keyboard, a liquid crystal display (LCD) screen (including a touch screen display), a non-volatile memory port, multiple antennas, a graphics chip, an application-specific integrated circuit (ASIC), and a speaker.

[0179] Among them, the main control chip can be used as a processor or control module in the device, sensor data, location information, etc. are stored in a memory or NVM / storage device, the sensor group can be used as an input / output device, and the communication interface may include a network interface.

[0180] As for the device 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.

[0181] The various embodiments in this specification are described in a progressive manner, and each embodiment focuses on the differences from other embodiments. The same or similar parts between the various embodiments can be referenced to each other.

[0182] The present application embodiment is described with reference to the flowchart and / or block diagram of the method, terminal device (system) and computer program product according to the embodiment of the present application. It should be understood that each process and / or box in the flowchart and / or block diagram, and the combination of the process and / or box in the flowchart and / or block diagram can be realized 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 terminal device to produce a machine, so that the instructions executed by the processor of the computer or other programmable data processing terminal device produce a device for realizing the function specified in one process or multiple processes in the flowchart and / or one box or multiple boxes in the block diagram.

[0183] These computer program instructions may also be stored in a computer-readable memory that can direct a computer or other programmable data processing terminal device to operate in a specific manner, so that the instructions stored in the computer-readable memory produce a manufactured product including an instruction device that implements the functions specified in one or more processes in the flowchart and / or one or more boxes in the block diagram.

[0184] These computer program instructions can also be loaded onto a computer or other programmable data processing terminal device so that a series of operating steps are executed on the computer or other programmable terminal device to produce computer-implemented processing, so that the instructions executed on the computer or other programmable terminal device provide steps for implementing the functions specified in one or more processes in the flowchart and / or one or more boxes in the block diagram.

[0185] Although the preferred embodiments of the present application have been described, those skilled in the art may make additional changes and modifications to these embodiments once they have learned the basic creative concept. Therefore, the appended claims are intended to be interpreted as including the preferred embodiments and all changes and modifications that fall within the scope of the embodiments of the present application.

[0186] Finally, it should be noted that, in this article, relational terms such as first and second, etc. are only used to distinguish one entity or operation from another entity or operation, and do not necessarily require or imply any such actual relationship or order between these entities or operations. Moreover, the terms "include", "comprise" or any other variants thereof are intended to cover non-exclusive inclusion, so that a process, method, article or terminal 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, article or terminal device. In the absence of further restrictions, the elements defined by the sentence "comprise a ..." do not exclude the existence of other identical elements in the process, method, article or terminal device including the elements.

[0187] The text matching model training method, text matching method, device and electronic device provided by the present application are introduced in detail above. Specific examples are used in this article to illustrate the principles and implementation methods of the present application. The description of the above embodiments is only used to help understand the method of the present application and its core idea; at the same time, for general technical personnel in this field, according to the idea of ​​the present application, there will be changes in the specific implementation method and application scope. In summary, the content of this specification should not be understood as a limitation on the present application.

Claims

1. A text matching model training method, characterized in that: The method comprises: A basic model is obtained by training based on a labeled sample set, wherein each sample in the sample set includes a first text, a second text, and a label indicating whether the first text and the second text match, and each sample has an equal weight in the process of training the basic model; Calculating the similarity between the first text and the second text in each sample using the basic model, and calculating the weight of each sample according to the similarity; According to each sample and the weight of each sample, the basic model is trained to obtain a trained model; Calculating the weight of each sample according to the similarity includes: Determine positive samples and negative samples in the sample set, wherein the positive samples are samples in which the first text matches the second text, and the negative samples are samples in which the first text does not match the second text; The weight of the positive samples in the sample set is set to a value that is negatively correlated with the similarity, and the weight of the negative samples in the sample set is set to a value that is positively correlated with the similarity.

2. The method according to claim 1, characterized in that The samples in the sample set are generated by the following steps: Get a text set containing multiple texts; Randomly selecting a first text and a second text from the text set; determining a markup indicating whether the first text and the second text match; A triple consisting of the first text, the second text and the annotation is taken as a sample.

3. The method according to claim 1, characterized in that Calculating the weight of each sample according to the similarity includes: Determine positive samples and negative samples in the sample set, wherein the positive samples are samples in which the first text matches the second text, and the negative samples are samples in which the first text does not match the second text; Combining positive samples containing the same first text into a positive sample group, combining negative samples containing the same first text into a negative sample group, and sorting the positive samples in the positive sample group and the negative samples in the negative sample group according to the similarity of the texts; Based on the sorting order of the positive samples in the positive sample group, weights are set for the positive samples in the positive sample group, and based on the sorting order of the negative samples in the negative sample group, weights are set for the negative samples in the negative sample group.

4. The method according to claim 3, characterized in that The step of setting weights for the positive samples in the positive sample group based on the sorting order of the positive samples in the positive sample group includes: In response to the positive samples in the positive sample group being sorted in ascending order of similarity, the weights of the positive samples in the positive sample group are set to values ​​that are negatively correlated with the sorting order; In response to the positive samples in the positive sample group being sorted in descending order of similarity, the weights of the positive samples in the positive sample group are set to values ​​that are positively correlated with the sorting order.

5. The method according to claim 3, characterized in that: The step of setting weights for negative samples in the negative sample group based on the sorting order of the negative samples in the negative sample group includes: In response to the negative samples in the negative sample group being sorted in ascending order of similarity, the weights of the negative samples in the negative sample group are set to values ​​that are positively correlated with the sorting order; In response to the negative samples in the negative sample group being sorted in descending order of similarity, the weights of the negative samples in the negative sample group are set to values ​​that are negatively correlated with the sorting order.

6. The method according to claim 1, characterized in that Calculating the weight of each sample according to the similarity includes: Determine positive samples and negative samples in the sample set, wherein the positive samples are samples in which the first text matches the second text, and the negative samples are samples in which the first text does not match the second text; Combining positive samples containing the same first text into a positive sample group, combining negative samples containing the same first text into a negative sample group, and sorting the positive samples in the positive sample group and the negative samples in the negative sample group according to the similarity of the texts; Setting a first weight and a second weight for each sample respectively, wherein the first weight of the positive sample is negatively correlated with the similarity between the first text and the second text in the positive sample, the second weight of the negative sample is positively correlated with the similarity between the first text and the second text in the negative sample, the second weight of the positive sample is determined based on the sorting order in the positive sample group to which it belongs, and the second weight of the negative sample is determined based on the sorting order in the negative sample group to which it belongs; The first weight and the second weight of each sample are weighted summed to obtain the weight of each sample.

7. The method according to claim 1, characterized in that The step of training the basic model according to each sample and the weight of each sample to obtain a trained model includes: Extract samples in batches from the sample set, use the extracted samples as target samples, and perform the following training steps: input the first text and the second text in the target sample into the basic model, and determine the loss value of the target sample based on the output of the basic model; perform weighted summation on the loss value of the target sample based on the weight of the target sample to obtain a total loss value; adjust the parameters of the basic model based on the total loss value; If the preset training end condition is met, the basic model after adjusting the parameters is determined as the trained model; If the preset training end condition is not met, samples are re-extracted in batches from the sample set, the re-extracted samples are used as target samples, and the training step is re-executed using the basic model with adjusted parameters.

8. A text matching method, characterized in that: include: Receiving a question-and-answer request, wherein the question-and-answer request includes a user question text; Combining the preset question text in the knowledge base with the user question text respectively, inputting the combination into the model trained by the method according to any one of claims 1 to 7, and obtaining the similarity between the user question text and the preset question text; Based on the similarity, determining a target preset question text in the knowledge base that matches the user question text; The answer text associated with the target preset question text is obtained from the knowledge base, and the answer text is returned.

9. A text matching method, characterized in that: include: Receiving a text similarity detection request, wherein the text similarity detection request includes a first text to be tested and a second text to be tested; Inputting the first text to be tested and the second text to be tested into the model trained by the method according to any one of claims 1 to 7 respectively, and obtaining the similarity between the first text to be tested and the second text to be tested; Based on the similarity, determine whether the first text to be tested matches the second text to be tested, and return a matching result.

10. A text matching model training device, characterized in that: The device comprises: A first training unit is configured to obtain a basic model by training based on a labeled sample set, wherein each sample in the sample set includes a first text, a second text, and a label indicating whether the first text and the second text match, and each sample has an equal weight in the process of training the basic model; A similarity calculation unit is configured to calculate the similarity between the first text and the second text in each sample using the basic model, and calculate the weight of each sample according to the similarity; A second training unit is configured to train the basic model according to each sample and the weight of each sample to obtain a trained model; The similarity calculation unit is further used for: Determine positive samples and negative samples in the sample set, wherein the positive samples are samples in which the first text matches the second text, and the negative samples are samples in which the first text does not match the second text; The weight of the positive samples in the sample set is set to a value that is negatively correlated with the similarity, and the weight of the negative samples in the sample set is set to a value that is positively correlated with the similarity.

11. A text matching device, characterized in that: include: A receiving unit is configured to receive a question-and-answer request, wherein the question-and-answer request includes a user question text; An input unit, configured to respectively combine the preset question text in the knowledge base with the user question text, and input the combination into the model trained by the method according to any one of claims 1 to 7, to obtain the similarity between the user question text and the preset question text; A determination unit configured to determine a target preset question text in the knowledge base that matches the user question text based on the similarity; The returning unit is configured to obtain the answer text associated with the target preset question text from the knowledge base and return the answer text.

12. A text matching device, characterized in that: include: A receiving unit, configured to receive a text similarity detection request, wherein the text similarity detection request includes a first text to be tested and a second text to be tested; An input unit, configured to input the first text to be tested and the second text to be tested into the model trained by the method according to any one of claims 1 to 7, respectively, to obtain the similarity between the first text to be tested and the second text to be tested; The returning unit is configured to determine whether the first text to be tested matches the second text to be tested based on the similarity, and return a matching result.

13. An electronic device, characterized in that: include: processor; as well as A memory having executable codes stored thereon, which, when executed, cause the processor to perform the method according to one or more of claims 1-9.

14. One or more machine-readable media having executable codes stored thereon, which, when executed, cause a processor to perform the method according to one or more of claims 1-9.

Citation Information

Patent Citations

  • Determination method and device for similarities of text semantics

    CN106776503A

  • Problem matching method and device, equipment and medium

    CN110543558A

  • Method and system for training word weight model

    CN111324722A