Similarity joint model training, semantic matching method and device
By training a joint similarity model and fusing similarity features from multiple semantic levels, the problem of insufficient semantic matching accuracy in existing technologies is solved, and higher semantic matching accuracy is achieved.
Patent Information
- Application Number
- CN202111150006.3
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2021-09-29
- Publication Date
- 2026-01-16
- Estimated Expiration
- 2041-09-29
AI Technical Summary
Existing semantic matching methods are inaccurate in calculating the similarity between target statements and candidate statements, resulting in insufficient accuracy in semantic matching.
By acquiring sample datasets, a joint similarity model is trained using multiple semantic similarity calculation models. By fusing similarity features from different semantic levels, the feature similarity between the target statement and the candidate statement at multiple semantic levels is obtained.
This improves the accuracy of similarity between the target statement and candidate statements, thereby enhancing the accuracy of semantic matching.
Smart Images

Figure CN113868377B_ABST
Abstract
Description
TECHNICAL FIELD
[0001] Embodiments of the present application relate to natural language processing technology. More specifically, it relates to a similarity joint model training method, a semantic matching method and device. BACKGROUND
[0002] An electronic device such as a smart TV or a smart refrigerator can receive a user's voice signal and make corresponding operations (such as outputting relevant recommendations or controlling the electronic device to make corresponding operations, etc.) according to the voice signal. Taking a smart TV as an example, after receiving a user's voice signal, the smart TV can convert the voice signal into a corresponding sentence. Then, the smart TV can perform semantic matching on the sentence to obtain the semantic corresponding to the sentence. According to the semantic corresponding to the sentence, the smart TV can make corresponding operations.
[0003] The existing method for performing semantic matching on a target sentence mainly includes the following steps: 1. Obtain a plurality of candidate sentences corresponding to the target sentence. 2. Calculate the similarity between the target sentence and each candidate sentence, and take the candidate sentence with the highest similarity with the target sentence as the target semantic sentence of the target sentence.
[0004] However, the existing method for calculating the similarity between the target sentence and each candidate sentence has the problem of poor accuracy, which may further lead to poor accuracy of semantic matching on the sentence. SUMMARY
[0005] Exemplary embodiments of the present application provide a similarity joint model training method, a semantic matching method and device to improve the accuracy of semantic matching.
[0006] In a first aspect, the present application provides a similarity joint model training method, which comprises:
[0007] Obtain a sample data set, the sample data set comprising at least one sample subset; each sample subset comprising at least two sample similarities between a sample sentence and any sample candidate sentence corresponding to the sample sentence, and a sample target similarity between the sample sentence and the sample candidate sentence obtained based on the at least two sample similarities; for any sample subset, the semantic level to which each sample similarity in the sample subset belongs is different;
[0008] Train the similarity joint model using the sample data set to obtain a trained similarity joint model; the trained similarity joint model is used to obtain a target similarity between a target sentence and any candidate sentence corresponding to the target sentence based on at least two similarities between the target sentence and the candidate sentence.
[0009] In some embodiments, the sample data set is obtained, comprising:
[0010] For any sample sentence, at any semantic level, at least two similarity calculation models of the semantic level are used to obtain a sample similarity between the sample sentence and any sample candidate sentence corresponding to the sample sentence.
[0011] In some embodiments, the at least two similarity calculation models of the semantic level are used to obtain a sample similarity between the sample sentence and any sample candidate sentence corresponding to the sample sentence, comprising:
[0012] Using any similarity calculation model, an initial sample similarity between the sample sentence and any sample candidate sentence corresponding to the sample sentence is obtained;
[0013] The average of a plurality of the initial sample similarities is taken as the sample similarity between the sample sentence and any sample candidate sentence corresponding to the sample sentence.
[0014] In some embodiments, the semantic level includes at least two levels: a character level of a sentence, a word level of a sentence, and a structure level of a sentence.
[0015] In a second aspect, the present application provides a semantic matching method, comprising:
[0016] Obtaining a target sentence and a plurality of candidate sentences corresponding to the target sentence;
[0017] Using at least two similarity calculation models of semantic levels, at least two similarities between the target sentence and any candidate sentence corresponding to the target sentence are obtained;
[0018] Each of the similarities is input into a trained similarity joint model to obtain a target similarity between the target sentence and any candidate sentence corresponding to the target sentence; wherein the similarity joint model is trained using the method of any one of claims 1-4;
[0019] According to the target similarity between the target sentence and any candidate sentence corresponding to the target sentence, a target semantic sentence matching the target sentence is obtained; the target semantic sentence is any one of the plurality of candidate sentences.
[0020] In some embodiments, before the target semantic sentence matching the target sentence is obtained according to the target similarity between the target sentence and any candidate sentence corresponding to the target sentence, further comprising:
[0021] extracting synonyms and antonyms of each target entity of the target sentence from the candidate sentence to obtain a number of synonym word pairs and a number of antonym word pairs between the candidate sentence and the target sentence;
[0022] The target semantic sentence matched with the target sentence is obtained according to the target similarity between the target sentence and any candidate sentence corresponding to the target sentence.
[0023] A coefficient of the target similarity between the target sentence and the candidate sentence is obtained according to the number of synonym word pairs and the number of antonym word pairs between the target sentence and the candidate sentence.
[0024] The target semantic sentence matched with the target sentence is obtained according to the target similarity between the target sentence and any candidate sentence corresponding to the target sentence, and the coefficient corresponding to each target similarity.
[0025] In some embodiments, the coefficient of the target similarity between the target sentence and the candidate sentence is obtained according to the number of synonym word pairs and the number of antonym word pairs between the target sentence and the candidate sentence, including:
[0026] The coefficient of the target similarity between the target sentence and the candidate sentence is obtained according to the following formula (1):
[0027] k = ae + be -a s (1)
[0028] Wherein, the k represents the coefficient of the target similarity between the target sentence and the candidate sentence, the a and the b are both preset parameters, the a represents the number of antonym word pairs between the candidate sentence and the target sentence, and the s represents the number of synonym word pairs between the candidate sentence and the target sentence.
[0029] In some embodiments, the synonyms and antonyms of each target entity of the target sentence are extracted from the candidate sentence to obtain the number of synonym word pairs and the number of antonym word pairs between the candidate sentence and the target sentence, including:
[0030] The target sentence and the candidate sentence are input into a trained keyword extraction model to obtain at least one key target entity of the target sentence and at least one keyword of the candidate sentence.
[0031] The synonyms and antonyms of the at least one key target entity of the target sentence are extracted from the at least one keyword of the candidate sentence to obtain the number of synonym word pairs and the number of antonym word pairs between the candidate sentence and the target sentence.
[0032] In some embodiments, after the target semantic sentence matching the target sentence is obtained, the method further comprises:
[0033] According to the target semantic sentence, a control instruction corresponding to the target semantic sentence is executed.
[0034] In a third aspect, the present application provides a similarity joint model training device, the device comprising:
[0035] An obtaining module is configured to obtain a sample data set, the sample data set comprising at least one sample subset; each sample subset comprising at least two sample similarities between a sample sentence and any sample candidate sentence corresponding to the sample sentence, and a sample target similarity between the sample sentence and the sample candidate sentence obtained based on the at least two sample similarities; for any sample subset, the semantic levels to which each sample similarity in the sample subset belongs are all different;
[0036] A training module is configured to train the similarity joint model using the sample data set to obtain a trained similarity joint model; the trained similarity joint model is configured to obtain a target similarity between a target sentence and any candidate sentence corresponding to the target sentence based on at least two similarities between the target sentence and the candidate sentence.
[0037] In a fourth aspect, the present application provides a semantic matching device, the device comprising:
[0038] A first obtaining module is configured to obtain a target sentence and a plurality of candidate sentences corresponding to the target sentence;
[0039] A second obtaining module is configured to obtain at least two similarities between the target sentence and any candidate sentence corresponding to the target sentence using similarity calculation models of at least two semantic levels;
[0040] A processing module is configured to input each similarity into a trained similarity joint model to obtain a target similarity between the target sentence and any candidate sentence corresponding to the target sentence; wherein the similarity joint model is trained using the method of any one of the first aspect;
[0041] A third obtaining module is configured to obtain a target semantic sentence matching the target sentence according to the target similarity between the target sentence and any candidate sentence corresponding to the target sentence; the target semantic sentence is any one of the plurality of candidate sentences.
[0042] The similarity joint model training method provided in the application uses sample similarities of different semantic levels and sample target similarities corresponding to the sample similarities of the different semantic levels to train a similarity joint model, and obtains a trained similarity joint model. Through the above method, the trained similarity joint model can combine input sample similarities of multiple semantic levels to obtain a target similarity with multiple semantic levels. Compared with the similarity obtained by using a similarity calculation model based on only one semantic level, the trained similarity joint model can obtain a target similarity with multiple semantic levels between a target sentence and a candidate sentence corresponding to the target sentence, improves the accuracy of determining the target similarity between the target sentence and the candidate sentence corresponding to the target sentence, and further improves the accuracy of performing semantic matching on the target sentence based on the target similarity. BRIEF DESCRIPTION OF DRAWINGS
[0043] In order to more clearly illustrate the embodiments of the application or the implementation manners in the related art, the drawings needed to be used in the embodiments or the related art description will be briefly introduced. Obviously, the drawings in the following description are some embodiments of the application, and other drawings can also be obtained by those skilled in the art based on these drawings.
[0044] Figure 1 A scene schematic diagram of user and display device voice interaction provided by the application;
[0045] Figure 2 A flowchart of a similarity joint model training method provided by the application;
[0046] Figure 3 A flowchart of another similarity joint model training method provided by the application;
[0047] Figure 4 A flowchart of a semantic matching method provided by the application;
[0048] Figure 5 A flowchart of a method of obtaining a target semantic sentence of a target sentence according to a target similarity provided by the application;
[0049] Figure 6 A flowchart of another semantic matching method provided by the application;
[0050] Figure 7 A structural schematic diagram of a similarity joint model training device 500 provided by the application;
[0051] Figure 8 A structural schematic diagram of a semantic matching device 600 provided by the application;
[0052] Figure 9 A structural schematic diagram of an electronic device is provided. DETAILED DESCRIPTION
[0053] For the purpose of making the objects, implementations and advantages of the present application more clear, the following will combine the drawings in the exemplary embodiments of the present application to make a clear and complete description of the exemplary embodiments of the present application. Obviously, the described exemplary embodiments are only a part of the embodiments of the present application, but not all the embodiments.
[0054] Based on the exemplary embodiments described in the present application, all other embodiments obtained by those skilled in the art without making creative efforts fall within the scope of the claims of the present application. In addition, although the disclosure in the present application is introduced according to one or more examples, it should be understood that each aspect of the disclosure can also constitute a complete embodiment independently.
[0055] It should be noted that the brief description of the terms in the present application is only for the convenience of understanding the following described embodiments, and is not intended to limit the embodiments of the present application. Unless otherwise specified, these terms should be understood according to their ordinary and general meanings.
[0056] The terms "first", "second", "third" and the like in the specification and claims of the present application and the above-described drawings are used to distinguish similar or similar objects or entities, and do not necessarily mean to limit the specific order or sequence, unless otherwise indicated. It should be understood that the terms used in this way can be interchanged under appropriate circumstances, for example, those other than the order given in the embodiment illustration or description of the present application can be implemented.
[0057] In addition, the terms "include" and "have" and any variations thereof are intended to cover but not exclusive inclusion, for example, a product or device including a series of components does not necessarily limit to those components clearly listed, but can include other components not clearly listed or inherent to these products or devices.
[0058] The term "module" used in the present application refers to any known or later developed hardware, software, firmware, artificial intelligence, fuzzy logic or combination of hardware or / and software code capable of performing functions related to the element.
[0059] With the development of science and technology, more and more electronic devices can interact with users through voice. Taking the electronic device as a display device (such as a smart television) as an example, the exemplary, Figure 1A scenario of a user interacting with a display device by voice is provided. As shown in Figure 1 The display device 200 can receive a voice signal of the user, and perform a corresponding operation on the display device 200 according to the voice signal.
[0060] For example, the display device 200 can perform content recommendation, play a video, or adjust the volume according to the semantics of the voice signal of the user.
[0061] In some embodiments, as shown in Figure 1 After receiving the voice signal of the user, the display device 200 can transmit the voice signal to the server 400 through the Internet. The server 400 can first determine the semantics of the voice signal. Then, according to the semantics of the voice signal, the server 400 can determine an operation instruction corresponding to the voice signal, and send the operation instruction to the display device 200. Then, the display device 200 can control the display device 200 according to the operation instruction.
[0062] In some embodiments, the display device 200 can also store a voice signal processing algorithm. Through the voice signal processing algorithm, the display device 200 can obtain the semantics of the voice signal of the user. Then, the display device 200 can determine an operation instruction corresponding to the voice signal according to the semantics of the voice signal, and control the display device 200 according to the operation instruction.
[0063] It should be understood that Figure 1 The above is only an example of a voice interaction scenario using an electronic device as an example. In actual implementation, the electronic device can also be other terminals with processing functions, or servers, etc. For example, smart TVs, smart refrigerators, smart speakers, etc. smart home, or mobile phones, tablet computers, notebook computers, desktop computers, smart watches, etc. electronic devices.
[0064] As mentioned above, after receiving the voice signal of the user, the electronic device needs to determine the semantics corresponding to the voice signal before performing a corresponding operation. For the process of determining the semantics corresponding to the voice signal, in some embodiments, the electronic device can first convert the received voice signal into a corresponding sentence. Then, the electronic device can perform semantic matching on the sentence to obtain the semantics corresponding to the sentence.
[0065] At present, the existing method of performing semantic matching on a sentence includes the following two main steps:
[0066] 1. Obtain a plurality of candidate sentences corresponding to a target sentence. The target sentence is based on the sentence to be semantically matched.
[0067] The specific implementation of obtaining the plurality of candidate sentences of the target sentence can refer to the existing implementation, which will not be described here.
[0068] 2. Calculate the similarity between the target sentence and each candidate sentence, and take the candidate sentence with the highest similarity to the target sentence as the target semantic sentence of the target sentence.
[0069] For example, the candidate sentences corresponding to the target sentence can be candidate sentence 1, candidate sentence 2, and candidate sentence 3. The similarity between the target sentence and candidate sentence 1 is similarity 1, the similarity between the target sentence and candidate sentence 2 is similarity 2, and the similarity between the target sentence and candidate sentence 3 is similarity 3. If similarity 1 is greater than similarity 2, and similarity 2 is greater than similarity 3, then candidate sentence 1 can be taken as the target semantic sentence of the target sentence.
[0070] At present, according to the semantic level to which the similarity between the target sentence and each candidate sentence belongs, the method of calculating the above similarity can be divided into the following:
[0071] 1. Character level of the sentence. The similarity between the target sentence and each candidate sentence is calculated at the character level of the sentence. Mainly, for any candidate sentence, the similarity between the candidate sentence and the target sentence is calculated according to the number of repeated characters between the target sentence and the candidate sentence. The similarity between the candidate sentence and the target sentence is positively correlated with the number of repeated characters between the target sentence and the candidate sentence.
[0072] However, the above method of calculating the similarity at the character level of the sentence does not consider the target sentence as a word for semantic consideration, nor does it consider the influence of the structure of the target sentence on the semantics. Only the number of repeated characters is used to determine the similarity, which may result in poor accuracy of the similarity determined at the character level.
[0073] 2. Word level of the sentence. The similarity between the target sentence and each candidate sentence is calculated at the word level of the sentence. Mainly, the similarity between the candidate sentence and the target sentence is calculated based on the number of times the candidate sentence appears in the preset corpus. The similarity between the candidate sentence and the target sentence is positively correlated with the number of times the candidate sentence appears in the preset corpus.
[0074] The above method of calculating the similarity at the word level of the sentence, although considers the target sentence as a word for calculating the similarity, still does not consider the influence of the structure of the target sentence on the semantics, which may also result in poor accuracy of the similarity determined at the word level of the sentence.
[0075] 3. The structure level of the sentence. The similarity between the target sentence and each candidate sentence can be calculated at the structure level of the sentence based on the structure of the target sentence to determine the similarity between the target sentence and the candidate sentence, and further determine the target semantics corresponding to the target sentence. In some embodiments, the similarity at the structure level of the sentence can be obtained by the sentence shallow semantic correlation algorithm, or the sentence deep semantic correlation algorithm.
[0076] The similarity between the target sentence and each candidate sentence is calculated by the sentence shallow semantic correlation algorithm. First, the target entities of the target sentence and the entity words in each candidate sentence are converted into word vectors based on the word segmentation word list containing a large number of words. Then, the similarity between the target sentence and the candidate sentence is calculated based on the word vectors corresponding to the target entities and the word vectors corresponding to the entity words in the candidate sentence. The above method of calculating the similarity by the sentence shallow semantic correlation algorithm may still result in poor accuracy of the similarity determined by the structure level of the sentence if the target entity does not exist in the word segmentation word list or the entity in the candidate sentence.
[0077] The method of calculating the similarity between the target sentence and each candidate sentence by the sentence deep semantic correlation algorithm mainly uses a deep neural network to calculate the similarity. When calculating the similarity by the deep neural network, the deep neural network needs to have a large number of layers to achieve good accuracy. However, the more layers the deep neural network has, the slower the efficiency of training the deep neural network will be, and the slower the efficiency of calculating the similarity using the trained deep neural network will be. In order to ensure the efficiency of calculating the similarity, the number of layers of the deep neural network often needs to be reduced, which results in poor accuracy of the above method. That is, even if the existing sentence deep semantic correlation algorithm considers the influence of the structure of the target sentence on the semantics, the accuracy of the similarity may still be poor.
[0078] Therefore, the existing methods of calculating the similarity between the target sentence and each candidate sentence all have the problem of poor accuracy, which may further result in poor accuracy of the semantic matching of the target sentence based on the similarity.
[0079] The existing semantic matching method does not comprehensively consider the similarity between the target sentence and each candidate sentence in multiple semantic levels to determine the semantic of the target semantic, resulting in the problem of poor accuracy of the existing semantic matching method. Therefore, the application provides a method for training a similarity joint model using sample similarities in multiple semantic levels, so that the trained similarity joint model can fuse the similarities in multiple semantic levels to obtain a target similarity that fuses the features of multiple semantic levels. Based on the target similarity between the target sentence and each candidate sentence that fuses the features of multiple semantic levels, the semantic of the target sentence is determined, which improves the accuracy of semantic matching of the target sentence compared with the existing method of only based on the similarity in a single semantic level for semantic matching.
[0080] It should be understood that the execution subject of the above-mentioned similarity joint model training method and the execution subject of the above-mentioned semantic matching method can be the same electronic device or different electronic devices. For example, the execution subject of the above-mentioned similarity joint model training method can be, for example, the server 400 shown in Figure 1 . The execution subject of the above-mentioned semantic matching method can be, for example, the display device 200 or the server 400 shown in Figure 1 .
[0081] In addition, it should be understood that Figure 1 The semantic matching method provided by the application can also be applied to, for example, information retrieval, question and answer systems, dialogue systems and the like. Among them, information retrieval can be regarded as semantic matching of query items and documents, question and answer systems can be regarded as semantic matching of questions and candidate answers, and dialogue systems can be regarded as semantic matching of dialogue sentences and reply sentences.
[0082] First, the technical solution of training the above-mentioned similarity joint model will be described in detail in combination with specific embodiments. The following specific embodiments can be combined with each other, and the same or similar concepts or processes can not be described in some embodiments.
[0083] Figure 2 A flowchart of a similarity joint model training method provided by the application. As shown in Figure 2 , the method comprises the following steps:
[0084] S101, obtaining a sample data set.
[0085] The sample data set includes at least one sample subset. Each sample subset includes at least two sample similarities between a sample sentence and any sample candidate sentence corresponding to the sample sentence, and a sample target similarity between the sample sentence and the sample candidate sentence obtained based on the at least two sample similarities. For any sample subset, the semantic levels to which the sample similarities in the sample subset belong are different. The sample target similarity between the sample sentence and the sample candidate sentence obtained based on the at least two sample similarities may be, for example, offline labeled by a user.
[0086] In some embodiments, the at least two sample similarities between the sample sentence and any sample candidate sentence corresponding to the sample sentence are obtained based on similarity calculation models of at least two semantic levels. For example, the semantic levels may include at least two of the following: a character level of a sentence, a word level of a sentence, and a structure level of a sentence.
[0087] It should be understood that the application does not limit the similarity calculation models of the semantic levels. Table 1 shows an example of the similarity calculation models corresponding to the semantic levels.
[0088] Table 1
[0089]
[0090]
[0091] wherein N in the N-gram algorithm is a positive integer greater than or equal to 2. The TF-IDF algorithm and the LSI algorithm are trained algorithms. The self-training word vector algorithm may be, for example, a static word vector word2vec algorithm, a Glove algorithm, and a dynamic word vector EIMo algorithm. The pre-trained neural network model may be, for example, a pre-trained BERT model. The representation type deep semantic model may be, for example, a trained SiaGRU model (a natural language processing model that can determine the similarity between two sentences). The interactive type deep semantic model may be, for example, an Enhanced Sequential Inference Model (ESIM).
[0092] As a possible implementation, for any sample sentence, the electronic device can obtain, at any semantic level, a sample similarity between the sample sentence and any sample candidate sentence corresponding to the sample sentence by using at least two similarity calculation models of the semantic level. By the above method, the sample similarity at the same semantic level is obtained by combining different similarity calculation models, thereby improving the accuracy of determining the sample similarity between the sample sentence at any semantic level and any sample candidate sentence corresponding to the sample sentence.
[0093] It should be understood that the present application does not limit the manner in which the electronic device obtains the plurality of sample candidate sentences corresponding to the sample sentence. In some embodiments, the electronic device may, for example, obtain a sample sentence input by a user, and a plurality of sample candidate sentences corresponding to the sample sentence input by the user. For example, the electronic device may, for example, receive the sample sentence input by the user and the plurality of sample candidate sentences corresponding to the sample sentence through an Application Programming Interface (API) or a Graphical User Interface (GUI).
[0094] In some embodiments, the electronic device may, after receiving the sample sentence input by the user, determine the plurality of sample candidate sentences corresponding to the sample sentence by using a preset candidate sentence determination algorithm. The preset candidate sentence determination algorithm may, for example, refer to the existing implementation, which will not be described herein.
[0095] After obtaining at least one sample sentence and a plurality of sample candidate sentences corresponding to each sample sentence, in some embodiments, the electronic device may, for example, obtain an initial sample similarity between the sample sentence and any sample candidate sentence corresponding to the sample sentence by using any similarity calculation model. Then, for a plurality of similarity calculation models of the same semantic level, the electronic device may, for example, take the average of the plurality of initial sample similarities obtained by the plurality of similarity calculation models as the sample similarity between the sample sentence and any sample candidate sentence corresponding to the sample sentence.
[0096] In some embodiments, for different similarity calculation models at the same semantic level, the electronic device may, for example, calculate the sample similarity between the sample sentence at the semantic level and any sample candidate sentence corresponding to the sample sentence based on a preset weight corresponding to each similarity model. The preset weight corresponding to each similarity model may, for example, be pre-stored in the electronic device by the user.
[0097] S102, training the similarity joint model using the sample data set to obtain a trained similarity joint model.
[0098] The trained similarity joint model is configured to obtain a target similarity between the target sentence and any candidate sentence corresponding to the target sentence based on at least two similarities between the target sentence and the candidate sentence.
[0099] For example, the similarity joint model can be an eXtreme Gradient Boosting (xgboost) algorithm.
[0100] It should be understood that the present application does not limit the preset parameters such as learning rate used when training the similarity joint model, or the loss function.
[0101] In some embodiments, the similarity joint model can also be a pre-trained similarity joint model to improve the efficiency of training the similarity joint model using the sample data set by the electronic device. The subject performing the pre-training of the similarity joint model can be the electronic device or another device with processing function different from the electronic device. The specific implementation of pre-training the similarity joint model can refer to the pre-training method of existing natural language processing models, which will not be described here.
[0102] In the present embodiment, the similarity joint model is trained using sample similarities of different semantic levels and sample target similarities corresponding to the sample similarities of different semantic levels, to obtain a trained similarity joint model. Through the above method, the trained similarity joint model can combine multiple semantic levels of input sample similarities to obtain a target similarity with multiple semantic levels of characteristics. Compared with the existing similarity calculation model based on only one semantic level, the trained similarity joint model can obtain a target similarity between a target sentence and a candidate sentence corresponding to the target sentence with multiple semantic levels of characteristics, thereby improving the accuracy of determining the target similarity between the target sentence and the candidate sentence corresponding to the target sentence, and further improving the accuracy of semantic matching of the target sentence based on the target similarity.
[0103] For example, a sample sub-set includes four sample similarities between a sample sentence and any sample candidate sentence corresponding to the sample sentence, and the semantic levels of the four sample similarities are respectively the character level of the sentence, the word level of the sentence, and the structure level of the sentence. Figure 3 Another flowchart of a similarity joint model training method provided by the present application is shown in FIG. 3. As shown in FIG. 3, the method includes the following steps: Figure 3
[0104] Step 1, the N-gram algorithm, the Jaccard correlation coefficient algorithm, and the edit distance algorithm are used as the similarity calculation model at the character level of the sentence; the TF-IDF algorithm trained using a large-scale training corpus and the LSI algorithm trained using a large-scale training corpus are used as the similarity calculation model at the word level of the sentence; the above self-training word vector algorithm and other shallow semantic related algorithms, and the SiaGRU model and the ESIM model and other deep semantic related algorithms are used as the similarity calculation model at the structure level of the sentence;
[0105] The SiaGRU model and the ESIM model can be pre-trained models. The large-scale training corpus can be a publicly available dataset for training semantic matching neural networks, such as the LCQMC (a publicly available dataset name) dataset.
[0106] The dataset used to pre-train the SiaGRU model and the ESIM model can also be the LCQMC dataset. The embedding layer of the SiaGRU model and the embedding layer of the ESIM model can both use the output vector of the last layer of the hidden layer of the Bidirectional Encoder Representations from Transformers (BERT) pre-training model. The difference is that the SiaGRU model training process encodes the sample sentence and the candidate sentence into vectors of the same length through a Long Short-Term Memory (LSTM) network after the embedding layer, and then calculates the similarity between the two sentence vectors through Manhattan Distance. The training process of the ESIM model is to extract the sentence features of the sample sentence and the candidate sentence through a Bi-directional LSTM (BiLSTM) network after the embedding layer, then obtain the interaction representation information of the two sentences through an attention mechanism, then concatenate the interaction representation information, capture local reasoning information and context information of the two sentences through BiLSTM, and finally pass through max-pooling and average-pooling algorithms, enter the fully connected layer, and output the similarity between the candidate sentence and the target sentence through the softmax output layer.
[0107] Step 2, input the sample sentence and the plurality of sample candidate sentences corresponding to each sample sentence into each similarity calculation model at each semantic level to obtain the initial sample similarity corresponding to each similarity calculation model.
[0108] Step 3, for multiple similarity calculation models of the same semantic level, the average value of the initial sample similarity corresponding to each similarity calculation model is taken as the sample similarity of the semantic level.
[0109] As shown in Figure 3 char represents the sample similarity of the character level of the sentence, f stat represents the sample similarity of the word level of the sentence, f bn represents the sample similarity of the structure level of the sentence based on the shallow semantic correlation algorithm, f dm represents the sample similarity of the structure level of the sentence based on the deep semantic correlation algorithm.
[0110] Step 4, based on the sample similarity of each semantic level and the sample target similarity corresponding to the sample similarity of each semantic level, a sample subset is constituted.
[0111] Step 5, using at least one of the above sample subsets to train the xgboost algorithm to obtain a trained similarity joint model.
[0112] The xgboost algorithm can include n (n is an integer greater than or equal to 2) trainable decision trees (such as Tree_1 to Tree_n shown in Figure 3 Each decision tree can output an initial predicted sample target similarity based on the sample similarity in the input sample subset. The electronic device can add the initial predicted sample target similarity output by each decision tree to obtain the predicted sample target similarity output by the xgboost algorithm (such as y shown in Figure 3 Based on the predicted sample target similarity and the sample target similarity corresponding to each semantic level, the xgboost algorithm can be trained.
[0113] In this embodiment, based on multiple similarity calculation models of the character level of the sentence, the word level of the sentence, and the structure level of the sentence, a sample data set for training the similarity joint model is obtained. The similarity joint model is trained using the sample data set, so that the trained similarity joint model can output a target similarity that fuses the features of the character level of the sentence, the word level of the sentence, and the structure level of the sentence based on the input similarity.
[0114] After obtaining the trained similarity joint model, the trained similarity joint model can be used for semantic matching of a target sentence. The following detailed description is made in combination with specific embodiments of how the trained similarity joint model is used for semantic matching. The following specific embodiments can be combined with each other, and the same or similar concepts or processes can not be described in some embodiments.
[0115] Figure 4 A flowchart of a semantic matching method provided by the present application is shown in FIG. 1. As shown in FIG. 1, the method comprises the following steps: Figure 4
[0116] S201, obtaining a target sentence and a plurality of candidate sentences corresponding to the target sentence.
[0117] As a first possible implementation manner, the electronic device can first obtain a target sentence, and then obtain a plurality of candidate sentences corresponding to the target sentence according to the obtained target sentence.
[0118] In this implementation manner, in some embodiments, the electronic device can receive a voice signal input by a user, and obtain a target sentence by performing voice recognition on the voice signal. For example, the electronic device can perform voice recognition on the voice signal by using a trained neural network model pre-stored in the electronic device, to obtain a target sentence corresponding to the voice signal. The trained neural network model can convert the voice signal into the target sentence.
[0119] In some embodiments, the electronic device can also receive a target sentence input by a user. For example, the electronic device can receive a target sentence input by a user through a GUI or an API.
[0120] After obtaining the target sentence, in some embodiments, the electronic device can obtain a plurality of candidate sentences corresponding to the target sentence by using the aforementioned pre-set candidate sentence determination algorithm. The specific implementation manner can refer to the existing implementation manner, which will not be described herein.
[0121] As a second possible implementation manner, the electronic device can directly receive a target sentence input by a user and a plurality of candidate sentences corresponding to the target sentence.
[0122] S202, obtaining at least two similarities between the target sentence and any candidate sentence corresponding to the target sentence by using at least two similarity calculation models of semantic levels.
[0123] For example, the similarity calculation model of each semantic level can refer to the example of Table 1, which will not be described herein.
[0124] In some embodiments, the electronic device can obtain, for any semantic layer, at least one similarity between the target sentence of the semantic layer and any candidate sentence corresponding to the target sentence.
[0125] Taking the electronic device obtaining one similarity of each semantic layer as an example, in some embodiments, the electronic device can obtain, for any semantic layer, one similarity between the target sentence of the semantic layer and any candidate sentence corresponding to the target sentence based on one similarity calculation model of the semantic layer.
[0126] For any semantic layer, the electronic device can also obtain multiple initial similarities between the target sentence of the semantic layer and any candidate sentence corresponding thereto using multiple similarity calculation models of the semantic layer.
[0127] Then, in some embodiments, the electronic device can obtain one similarity between the target sentence of the semantic layer and any candidate sentence corresponding thereto based on the multiple initial similarities. For example, the electronic device can take the average of the multiple initial similarities as the similarity between the target sentence of the semantic layer and any candidate sentence corresponding thereto. Alternatively, in some embodiments, the electronic device can also take each of the multiple initial similarities as the similarity between the target sentence of the semantic layer and any candidate sentence corresponding thereto.
[0128] S203, input each similarity into the trained similarity joint model to obtain a target similarity between the target sentence and any candidate sentence corresponding to the target sentence.
[0129] Wherein the similarity joint model is obtained by training using the similarity joint model training method described in any of the preceding embodiments.
[0130] S204, obtain a target semantic sentence matching the target sentence according to the target similarity between the target sentence and any candidate sentence corresponding to the target sentence.
[0131] Wherein the target semantic sentence is any of the multiple candidate sentences. In some embodiments, the electronic device may, for example, take the candidate sentence with the largest target similarity with the target sentence as the target semantic sentence corresponding to the target sentence.
[0132] In this embodiment, at least two similarities between the target sentence and any candidate sentence corresponding to the target sentence can be obtained through at least two similarity calculation models of semantic levels. The at least two similarities are combined by using the aforementioned trained similarity joint model to obtain a target similarity between the target sentence and any candidate sentence corresponding to the target sentence, which has at least two characteristics of semantic levels. Based on the target similarity having at least two characteristics of semantic levels, the electronic device can perform semantic matching on the target sentence to obtain the semantics of the target sentence. Compared with the existing semantic matching method, the semantic matching method provided in this application can consider the similarities of multiple semantic levels to determine the target similarity between the target sentence and each candidate sentence, thereby improving the accuracy of determining the target similarity between the target sentence and each candidate sentence, and further improving the accuracy of determining the semantics of the target sentence based on the target similarity.
[0133] Further, as a possible implementation manner, after the electronic device performs semantic matching on the target sentence, the electronic device can further execute a control instruction corresponding to the target semantic sentence according to the target semantic sentence.
[0134] In some embodiments, the electronic device can pre-store a mapping relationship between semantic sentences and control instructions, for example. After obtaining the target semantic sentence of the target sentence, the electronic device can determine the control instruction corresponding to the target semantic sentence according to the target semantic sentence and the mapping relationship between semantic sentences and control instructions. After determining the control instruction, the electronic device can execute the control instruction so that the electronic device can work according to the control instruction.
[0135] For example, taking the target semantic sentence "turn up the volume" as an example, the electronic device can determine that the control instruction corresponding to the target semantic sentence is to turn up the volume of the loudspeaker. Therefore, the electronic device can control the volume of the loudspeaker to increase.
[0136] In some embodiments, the aforementioned control instruction can also be an instruction for controlling the electronic device to interact with other electronic devices, for example. For example, taking the target semantic sentence "play E song" as an example, the electronic device can send the target semantic sentence to a server to obtain a playing resource corresponding to the E song from the server.
[0137] The following describes in detail how the electronic device obtains the target semantic sentence matched with the target sentence according to the target similarity between the target sentence and any candidate sentence corresponding to the target sentence. Figure 5 A method flowchart provided in this application for obtaining a target semantic sentence of a target sentence according to a target similarity is shown in FIG. 8. Figure 5 As a possible implementation manner, the step S204 includes the following steps:
[0138] S301, from the candidate sentence, extract the synonym and antonym of each target entity of the target sentence, obtain the number of synonym word pairs between the candidate sentence and the target sentence, and the number of antonym word pairs.
[0139] As a possible implementation, the electronic device can obtain the number of synonym word pairs and the number of antonym word pairs between the candidate sentence and the target sentence based on the keywords in the candidate sentence and the keywords in the target sentence, to improve the efficiency of determining the number of synonym word pairs and the number of antonym word pairs.
[0140] In this implementation, the electronic device can input the target sentence and the candidate sentence into the trained keyword extraction model to obtain at least one key target entity of the target sentence and at least one keyword of the candidate sentence. Then, the electronic device can extract the synonym and antonym of the at least one key target entity from the at least one keyword of the candidate sentence, to obtain the number of synonym word pairs and the number of antonym word pairs between the candidate sentence and the target sentence.
[0141] For example, the keyword extraction model can be a trained TF-IDF algorithm, which can output at least one keyword of the target sentence and at least one keyword of the candidate sentence based on the input target sentence and candidate sentence. The at least one keyword of the target sentence can be used as at least one key target entity of the target sentence.
[0142] In some embodiments, the electronic device can first search for the at least one key target entity of the target sentence and the at least one keyword of the candidate sentence in a preset synonym dictionary to determine whether there is a synonym between the target sentence and the candidate sentence, and calculate the number of synonym word pairs when there is a synonym between the target sentence and the candidate sentence. The electronic device can first search for the at least one key target entity of the target sentence and the at least one keyword of the candidate sentence in a preset antonym dictionary to determine whether there is an antonym between the target sentence and the candidate sentence, and calculate the number of antonym word pairs when there is an antonym between the target sentence and the candidate sentence.
[0143] In some embodiments, the electronic device can further calculate the similarity between each key target entity of the target sentence and each keyword of the candidate sentence according to a preset similarity calculation model. Then, the electronic device can take the key target entity and the keyword of the candidate sentence with a similarity greater than or equal to a first preset similarity threshold as a pair of synonyms, and take the key target entity and the keyword of the candidate sentence with a similarity less than or equal to a second preset similarity threshold as a pair of antonyms. The first preset similarity threshold is greater than the second preset similarity threshold. For example, the first preset similarity threshold and the second preset similarity threshold can be pre-stored in the electronic device by the user.
[0144] In some embodiments, the electronic device can further extract synonyms and antonyms of at least one key target entity of the target sentence from at least one keyword of the candidate sentence based on the preset similarity calculation model, the preset synonym dictionary, and the preset antonym dictionary, so as to improve the accuracy of determining the number of synonym pairs and the number of antonym pairs.
[0145] In this implementation, for example, the electronic device can first determine the initial synonym pairs and the initial antonym pairs between the candidate sentence and the target sentence according to the preset synonym dictionary and the preset antonym dictionary. Then, the similarity of each initial synonym pair and the similarity of each initial antonym pair are calculated using the preset similarity calculation model. In this implementation, the electronic device can take the initial synonym pair with a similarity greater than or equal to the first preset similarity threshold as a pair of synonyms, and take the initial antonym pair with a similarity less than or equal to the second preset similarity threshold as a pair of antonyms.
[0146] Alternatively, the electronic device can first obtain the initial synonym pairs and the initial antonym pairs using the preset similarity calculation model. Then, the electronic device can search for each initial synonym pair in the preset synonym dictionary. If the initial synonym pair exists in the preset synonym dictionary, the initial synonym pair is taken as a pair of synonyms. The electronic device can search for each initial antonym pair in the preset synonym dictionary. If the initial antonym pair exists in the preset synonym dictionary, the initial antonym pair is taken as a pair of antonyms.
[0147] Alternatively, the electronic device can further determine initial synonym word pairs and initial antonym word pairs between the candidate sentence and the target sentence from a preset synonym dictionary and a preset antonym dictionary when inputting at least one key target entity of the target sentence and at least one keyword of the candidate sentence into a preset similarity calculation model to obtain similarities between each key target entity of the target sentence and each keyword of the candidate sentence. Then the electronic device can take the key target entity and the keyword of the candidate sentence belonging to the initial synonym word pairs as a pair of synonyms when the similarity is greater than or equal to a first preset similarity threshold; and take the key target entity and the keyword of the candidate sentence belonging to the initial antonym word pairs as a pair of antonyms when the similarity is less than or equal to a second preset similarity threshold.
[0148] S302, according to the number of synonym word pairs and the number of antonym word pairs between the candidate sentence and the target sentence, obtaining a coefficient of the target similarity between the target sentence and the candidate sentence.
[0149] As a possible implementation manner, the electronic device can obtain the coefficient of the target similarity between the target sentence and the candidate sentence according to the following formula (1):
[0150] k = αe -a + βs s (1)
[0151] Wherein, k represents the coefficient of the target similarity between the target sentence and the candidate sentence. α and β are both preset parameters. α and β can both be constants greater than 0. The α and β can be calibrated by the user through offline experiments and pre-stored in the electronic device. The α can be used as the weight corresponding to the number of antonym word pairs, and the β can be used as the weight corresponding to the number of synonym word pairs. a represents the number of antonym word pairs between the candidate sentence and the target sentence, and s represents the number of synonym word pairs between the candidate sentence and the target sentence.
[0152] e -a in formula (1) is a negative correlation function, that is, with the increase of the number of antonym word pairs between the candidate sentence and the target sentence, e -a decreases, and the above coefficient k is smaller, which represents that the target similarity between the candidate sentence and the target sentence decreases. e s in formula (1) is a positive correlation function, that is, with the increase of the number of synonym word pairs between the candidate sentence and the target sentence, e s increases, and the above coefficient k is larger, which represents that the target similarity between the candidate sentence and the target sentence increases.
[0153] As another possible implementation manner, the electronic device can also take the number of antonym word pairs between the candidate sentence and the target sentence as a variable of the other type of negative correlation function, and take the number of synonym word pairs between the candidate sentence and the target sentence as a variable of the other type of positive correlation function. The specific implementation manner can refer to the formula (1) and will not be described here again.
[0154] S303, obtaining the target semantic sentence matched with the target sentence according to the target similarity between the target sentence and any candidate sentence corresponding to the target sentence, and the coefficient corresponding to each target similarity.
[0155] In some embodiments, for any target similarity, the electronic device can take the product of the target similarity and the coefficient corresponding to the target similarity as the constrained target similarity corresponding to the target similarity. Then, for any target entity, the electronic device can take, for example, the candidate sentence with the largest constrained target similarity between the target sentence as the target semantic sentence corresponding to the target sentence.
[0156] In this embodiment, the coefficient of the target similarity between the candidate sentence and the target sentence is determined by the number of synonym word pairs between the candidate sentence and the target sentence and the number of antonym word pairs between the candidate sentence and the target sentence. Through the coefficient, the target similarity is constrained, and then the target semantic sentence of the target sentence is obtained based on the constrained target similarity. The number of synonym word pairs and the number of antonym word pairs between the candidate sentence and the target sentence can represent the semantic similarity degree between the candidate sentence and the target sentence. Therefore, through the above method, the accuracy of semantic matching of the target sentence is further improved.
[0157] Figure 6 Another flowchart of a semantic matching method provided in the present application is shown in FIG. 4. As shown in FIG. 4, the method includes the following steps: Figure 6
[0158] S401, obtaining a target sentence and each candidate sentence corresponding to the target sentence.
[0159] After performing step S401, the electronic device can first perform steps S402-S403, and then perform steps S404-S405; or first perform steps S404-S405, and then perform steps S402-S403; or simultaneously perform steps S402-S403 and steps S404-S405.
[0160] S402, obtaining at least three similarities between the target sentence and any candidate sentence by using similarity calculation models of three semantic levels of character level of the sentence, word level of the sentence, and structure level of the sentence.
[0161] S403, input the above at least three similarities into the trained similarity joint model to obtain a target similarity between the target sentence and any candidate sentence.
[0162] S404, input the above target sentence and candidate sentence into the trained keyword extraction model to obtain at least one key target entity of the target sentence and at least one keyword of the candidate sentence.
[0163] S405, based on the preset similarity calculation model, and the preset synonym dictionary and antonym dictionary, obtain the number of synonym word pairs and the number of antonym word pairs between the candidate sentence and the target sentence.
[0164] The specific implementation can refer to the foregoing embodiments, which will not be repeated here.
[0165] S406, constrain the above target similarity using the number of synonym word pairs and the number of antonym word pairs between the candidate sentence and the target sentence to obtain a constrained target similarity.
[0166] The electronic device can constrain the target similarity by using a constraint function shown in the following formula (2):
[0167] score output =(αe -a +βe s )×score union (2)
[0168] Wherein, score output represents the constrained target similarity, and score union represents the target similarity output by the electronic device executing S403.
[0169] S407, according to the constrained target similarity between the target sentence and each candidate sentence, obtain a target semantic sentence matched with the target sentence.
[0170] In this embodiment, based on the trained similarity joint model, the similarities at each semantic level are combined to obtain a target similarity between the target statement and each candidate statement, possessing features at three semantic levels. This improves the accuracy of determining the target similarity, and consequently, the accuracy of determining the target semantic statement. Furthermore, the target similarity is constrained based on a coefficient determined by the number of synonym pairs and antonym pairs between the candidate and target statements, resulting in a constrained target similarity. This constrained target similarity is positively correlated with the number of synonym pairs and negatively correlated with the number of antonym pairs, further improving the accuracy of semantic matching of the target statement based on this target similarity.
[0171] Figure 7 This is a schematic diagram of the structure of a similarity joint model training device 500 provided in this application. Figure 7 As shown, the device 500 may include: an acquisition module 501 and a training module 502. Wherein,
[0172] The acquisition module 501 is used to acquire a sample dataset. The sample dataset includes at least one sample subset; each sample subset includes at least two sample similarities between a sample statement and any corresponding candidate sample statement, and a target sample similarity between the sample statement and the candidate sample statement based on the at least two sample similarities; for any sample subset, the semantic levels to which each sample similarity belongs are different.
[0173] Training module 502 is used to train the joint similarity model using the sample dataset to obtain a trained joint similarity model. The trained joint similarity model is used to obtain a target similarity between the target statement and any corresponding candidate statement based on at least two similarities between the target statement and any candidate statement.
[0174] In some embodiments, the acquisition module 501 is specifically used to obtain the sample similarity between the sample statement and any sample candidate statement corresponding to the sample statement at any semantic level using at least two similarity calculation models at that semantic level.
[0175] In some embodiments, the acquisition module 501 is specifically used to obtain the initial sample similarity between the sample statement and any sample candidate statement corresponding to the sample statement by using any similarity calculation model; and to take the average of the multiple initial sample similarities as the sample similarity between the sample statement and any sample candidate statement corresponding to the sample statement.
[0176] In some embodiments, the semantic levels include at least two of a character level of a sentence, a word level of a sentence, and a structure level of a sentence.
[0177] The similarity joint model training apparatus 500 provided by the embodiment can execute the similarity joint model training method provided by the above-mentioned embodiment, and has similar implementation principles and technical effects, which will not be described here again.
[0178] Figure 8 A structural schematic diagram of a semantic matching apparatus 600 provided by the present application is shown in FIG. 6. As shown in the figure, the apparatus 600 can include a first obtaining module 601, a second obtaining module 602, a processing module 603, and a third obtaining module 604. Among them, Figure 8
[0179] The first obtaining module 601 is configured to obtain a target sentence and a plurality of candidate sentences corresponding to the target sentence.
[0180] The second obtaining module 602 is configured to obtain at least two similarities between the target sentence and any candidate sentence corresponding to the target sentence by using similarity calculation models of at least two semantic levels.
[0181] The processing module 603 is configured to input each of the similarities into a trained similarity joint model to obtain a target similarity between the target sentence and any candidate sentence corresponding to the target sentence; the similarity joint model is obtained by training using the similarity joint model training method according to any of the preceding embodiments.
[0182] The third obtaining module 604 is configured to obtain a target semantic sentence matched with the target sentence according to the target similarity between the target sentence and any candidate sentence corresponding to the target sentence; the target semantic sentence is any of the plurality of candidate sentences.
[0183] In some embodiments, the first obtaining module 601 is further configured to, before obtaining the target semantic sentence matched with the target sentence according to the target similarity between the target sentence and any candidate sentence corresponding to the target sentence, extract synonyms and antonyms of each target entity of the target sentence from the candidate sentences to obtain a number of synonym word pairs and a number of antonym word pairs between the candidate sentence and the target sentence. In this implementation, the third obtaining module 604 is specifically configured to obtain a coefficient of the target similarity between the target sentence and the candidate sentence according to the number of synonym word pairs and the number of antonym word pairs between the candidate sentence and the target sentence; and obtain the target semantic sentence matched with the target sentence according to the target similarity between the target sentence and any candidate sentence corresponding to the target sentence and the coefficient corresponding to each target similarity.
[0184] In some embodiments, the third acquisition module 604 is specifically used to obtain the coefficient of target similarity between the target statement and the candidate statement according to the following formula (1):
[0185] k=αe -a +βe s (1)
[0186] Wherein, k represents the target similarity coefficient between the target statement and the candidate statement, α and β are preset parameters, a represents the number of antonym pairs between the candidate statement and the target statement, and s represents the number of synonym pairs between the candidate statement and the target statement.
[0187] In some embodiments, the third acquisition module 604 is specifically used to input the target statement and the candidate statement into a trained keyword extraction model to obtain at least one key target entity of the target statement and at least one keyword of the candidate statement; extract synonyms and antonyms of at least one key target entity of the target statement from at least one keyword of the candidate statement to obtain the number of synonym pairs and the number of antonym pairs between the candidate statement and the target statement.
[0188] In some embodiments, the semantic matching device 600 may further include an execution module 605, which, after obtaining a target semantic statement that matches the target statement, executes a control instruction corresponding to the target semantic statement based on the target semantic statement.
[0189] The semantic matching device 600 provided in this embodiment can execute the semantic matching method embodiment described above. Its implementation principle and technical effect are similar, and will not be described again here.
[0190] Figure 9 This is a schematic diagram of the structure of an electronic device provided in this application. Figure 9 As shown, the electronic device 700 may include at least one processor 701 and a memory 702. Wherein,
[0191] The memory 702 is used to store programs. Specifically, the program may include program code, which includes computer operation instructions.
[0192] The memory 702 may include high-speed RAM memory, and may also include non-volatile memory, such as at least one disk storage device.
[0193] The processor 701 is configured to execute the computer-executable instructions stored in the memory 702 to implement the similarity joint model training method or the semantic matching method described in the foregoing method embodiments. The processor 701 can be a central processing unit (CPU), an application specific integrated circuit (ASIC), or one or more integrated circuits configured to implement the embodiments of the present application.
[0194] Optionally, the electronic device 700 can further include a communication interface 703. In a specific implementation, if the communication interface 703, the memory 702, and the processor 701 are implemented independently, the communication interface 703, the memory 702, and the processor 701 can be connected to each other through a bus and complete communication therebetween. The bus can be an industry standard architecture (ISA) bus, a peripheral component (PCI) bus, or an extended industry standard architecture (EISA) bus, etc. The bus can be divided into an address bus, a data bus, a control bus, etc., but does not mean that there is only one bus or one type of bus.
[0195] Optionally, in a specific implementation, if the communication interface 703, the memory 702, and the processor 701 are integrated on a chip, the communication interface 703, the memory 702, and the processor 701 can complete communication through an internal interface.
[0196] The present application also provides a computer readable storage medium, which can include a U disk, a mobile hard disk, a read-only memory (ROM), a random access memory (RAM), a magnetic disk or an optical disk, and various media that can store program codes. Specifically, the computer readable storage medium stores program instructions, and the program instructions are used for the method in the foregoing embodiments.
[0197] The present application also provides a program product, which includes execution instructions stored in a readable storage medium. At least one processor of an electronic device can read the execution instructions from the readable storage medium, and the at least one processor executes the execution instructions to enable the electronic device to implement the similarity joint model training method or the semantic matching method provided in the various embodiments.
[0198] Finally, it should be noted that the above embodiments are only used to illustrate the technical solutions of the present application, and are not intended to limit the present application; although the present application has been described in detail with reference to the foregoing embodiments, those skilled in the art should understand that the technical solutions recorded in the foregoing embodiments can still be modified, or some or all of the technical features can be replaced by equivalents; and these modifications or replacements do not make the essence of the corresponding technical solutions deviate from the scope of the technical solutions of the embodiments of the present application.
[0199] The foregoing description has been set forth in conjunction with a particular embodiment and implementations, for purposes of convenience and illustration. However, the foregoing discussion is not intended to be exhaustive or to limit the embodiments to the precise forms disclosed. Various modifications and changes are possible in light of the teachings above. The selection and arrangement of various elements described or claimed in the foregoing embodiments are presented to provide the best description possible of the principles and the practical applications of the embodiments. It is intended that the described embodiments be considered as exemplary only, with the scope of the embodiments being indicated by the following claims.
Claims
1. A method of semantic matching, the method comprising: The method comprises: acquiring a target sentence, and a plurality of candidate sentences corresponding to the target sentence; acquiring at least two similarities between the target sentence and any candidate sentence corresponding to the target sentence by using at least two semantic level similarity calculation models; wherein the semantic level comprises at least two levels of character level of the sentence, word level of the sentence, and structure level of the sentence; inputting each similarity into a trained similarity joint model to obtain a target similarity between the target sentence and any candidate sentence corresponding to the target sentence; wherein the similarity joint model is trained by using a sample data set, and sample data in the sample data set comprises at least two sample similarities between a sample sentence and any sample candidate sentence in different semantic levels, and a sample target similarity obtained based on the at least two sample similarities; inputting the target sentence and the candidate sentence into a trained keyword extraction model to obtain at least one key target entity of the target sentence and at least one keyword of the candidate sentence; extracting synonyms and antonyms of the at least one key target entity of the target sentence from the at least one keyword of the candidate sentence to obtain a number of synonym word pairs and a number of antonym word pairs between the candidate sentence and the target sentence; acquiring a coefficient of the target similarity between the target sentence and the candidate sentence according to the number of synonym word pairs and the number of antonym word pairs between the candidate sentence and the target sentence; acquiring a constrained target similarity according to the target similarity between the target sentence and any candidate sentence corresponding to the target sentence and the coefficient corresponding to each target similarity; acquiring a target semantic sentence matched with the target sentence according to the constrained target similarity; the target semantic sentence is any one of the plurality of candidate sentences; the acquiring of the coefficient of the target similarity between the target sentence and the candidate sentence according to the number of synonym word pairs and the number of antonym word pairs between the candidate sentence and the target sentence comprises: acquiring the coefficient of the target similarity between the target sentence and the candidate sentence according to formula (1): (1) Wherein, k represents the coefficient of target similarity between the target statement and the candidate statement, and the... , and, the All are preset parameters, the This indicates the number of antonym pairs between the candidate statement and the target statement. This indicates the number of synonym pairs between the candidate statement and the target statement.
2. The method of claim 1, wherein, after the acquiring of the target semantic sentence matched with the target sentence, the method further comprises: executing a control instruction corresponding to the target semantic sentence according to the target semantic sentence.
3. A similarity joint model training method, characterized in that, The method comprises: acquiring a sample data set comprising at least one sample subset; each sample subset comprises at least two sample similarities between a sample sentence and any sample candidate sentence corresponding to the sample sentence, and a sample target similarity between the sample sentence and the sample candidate sentence obtained based on the at least two sample similarities; for any sample subset, the semantic levels of each sample similarity in the sample subset are different; The sample data set is used to train the similarity joint model, and a trained similarity joint model is obtained; the trained similarity joint model is used to obtain a target similarity between a target sentence and any candidate sentence corresponding to the target sentence based on at least two similarities between the target sentence and the candidate sentence; and the similarity joint model is used to implement the semantic matching method of claim 1 or 2.
4. The method of claim 3, wherein, The sample data set is obtained, including: For any sample sentence, at least two similarity calculation models of any semantic level are used to obtain a sample similarity between the sample sentence and any sample candidate sentence corresponding to the sample sentence.
5. The method of claim 4, wherein, The sample similarity between the sample sentence and the sample candidate sentence corresponding to the sample sentence is obtained by using at least two similarity calculation models of the semantic level, including: Any similarity calculation model is used to obtain an initial sample similarity between the sample sentence and the sample candidate sentence corresponding to the sample sentence; The average of a plurality of initial sample similarities is used as the sample similarity between the sample sentence and the sample candidate sentence corresponding to the sample sentence. 6.A similarity joint model training apparatus, characterized in that, The device includes: An obtaining module is configured to obtain a sample data set, the sample data set including at least one sample subset; each sample subset including at least two sample similarities between a sample sentence and any sample candidate sentence corresponding to the sample sentence, and a sample target similarity between the sample sentence and the sample candidate sentence obtained based on the at least two sample similarities; for any sample subset, the semantic levels to which the sample similarities in the sample subset belong are all different; A training module is configured to use the sample data set to train the similarity joint model, and obtain a trained similarity joint model; the trained similarity joint model is used to obtain a target similarity between a target sentence and any candidate sentence corresponding to the target sentence based on at least two similarities between the target sentence and the candidate sentence; and the similarity joint model is used to implement the semantic matching method of claim 1 or 2.
7. A semantic matching apparatus, characterized by, The device includes: A first obtaining module is configured to obtain a target sentence and a plurality of candidate sentences corresponding to the target sentence; A second obtaining module is configured to use at least two similarity calculation models of semantic levels to obtain at least two similarities between the target sentence and any candidate sentence corresponding to the target sentence; and the semantic levels include at least two levels, i.e., a character level of a sentence, a word level of a sentence, and a structure level of a sentence. The processing module is configured to input each of the similarities into a trained similarity joint model to obtain a target similarity between the target sentence and any candidate sentence corresponding to the target sentence; the similarity joint model is trained using a sample data set, and sample data in the sample data set includes at least two sample similarities between a sample sentence and any sample candidate sentence that are different in semantic levels, and a sample target similarity obtained based on the at least two sample similarities; The third obtaining module is configured to input the target sentence and the candidate sentence into a trained keyword extraction model to obtain at least one key target entity of the target sentence and at least one keyword of the candidate sentence, extract synonyms and antonyms of the at least one key target entity of the target sentence from the at least one keyword of the candidate sentence, obtain a number of synonym word pairs and a number of antonym word pairs between the candidate sentence and the target sentence, obtain a coefficient of a target similarity between the target sentence and the candidate sentence according to the number of synonym word pairs and the number of antonym word pairs between the candidate sentence and the target sentence, obtain a constrained target similarity according to the target similarity between the target sentence and any candidate sentence corresponding to the target sentence and the coefficient corresponding to each target similarity, and obtain a target semantic sentence matched with the target sentence according to the constrained target similarity; the target semantic sentence is any one of the plurality of candidate sentences. The third obtaining module is specifically configured to obtain the coefficient of the target similarity between the target sentence and the candidate sentence according to the following formula (1): (1) Wherein, the k represents a coefficient of target similarity between the target sentence and the candidate sentence, the , and the are all preset parameters, the represents the number of antonym word pairs between the candidate sentence and the target sentence, and the represents the number of synonym word pairs between the candidate sentence and the target sentence.
Citation Information
Patent Citations
Problem similarity calculation method based on a plurality of features
CN109344236A
Problem processing method and device, computer equipment and storage medium
CN111400470A