Semantic matching method, device, electronic device and storage medium
Through two-way hit processing and machine learning models, the problem of low semantic matching accuracy in the prior art is solved, and more efficient text correlation expression and matching accuracy are achieved.
Patent Information
- Application Number
- CN202110265862.7
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2021-03-11
- Publication Date
- 2024-11-15
- Estimated Expiration
- 2041-03-11
AI Technical Summary
The prior art fails to express the correlation between texts in semantic matching, resulting in low accuracy of semantic matching.
By obtaining the first text and the second text to be matched, a two-way hit processing is adopted, and the similarity matrix transformation and pooling are performed based on the text semantics, and combined with the machine learning model, the matching degree between texts is determined.
It improves the accuracy of semantic matching, avoids one-way matching bias, and enhances text correlation expression.
Smart Images

Figure CN113408293B_ABST
Abstract
Description
Technical Field
[0001] The present application relates to the field of artificial intelligence, and specifically to a semantic matching method, device, electronic device and storage medium. Background Art
[0002] With the development of Internet technology, semantic matching is often involved in all aspects of Internet applications. The accuracy of semantic matching directly or indirectly determines the quality of service provided by the application. In the prior art, the accuracy of semantic matching is low because the correlation between texts is not carefully expressed during semantic matching. Summary of the invention
[0003] One purpose of the present application is to provide a semantic matching method, device, electronic device and storage medium, which can improve the accuracy of semantic matching.
[0004] According to one aspect of an embodiment of the present application, a semantic matching method is disclosed, the method comprising:
[0005] Acquire a first text and at least two second texts to be matched with the first text;
[0006] Based on text semantics, matching the first text to each of the second texts to obtain a first matching result;
[0007] Based on text semantics, matching the second text to the first text respectively to obtain a second matching result;
[0008] Based on the first hit result and the second hit result, a second text matching the first text is determined.
[0009] According to one aspect of an embodiment of the present application, a semantic matching device is disclosed, the device comprising:
[0010] An acquisition module, configured to acquire a first text and at least two second texts to be matched with the first text;
[0011] A first matching module configured to match the first text to each of the second texts based on text semantics to obtain a first matching result;
[0012] A second matching module is configured to match the second text to the first text based on text semantics to obtain a second matching result;
[0013] The matching module is configured to determine a second text matching the first text based on the first hit result and the second hit result.
[0014] In an exemplary embodiment of the present application, the device is configured as follows:
[0015] Obtaining the similarity between the first text and each of the second texts;
[0016] Establishing a similarity matrix with the similarities as matrix elements;
[0017] Based on the transformation processing of the similarity matrix, the first text is matched to each of the second texts, and the second text is matched to the first text respectively, and the first matching result and the second matching result are obtained at the same time.
[0018] In an exemplary embodiment of the present application, the device is configured as follows:
[0019] Using a preset Gaussian kernel to perform pooling processing on the similarity matrix to obtain a pooled matrix;
[0020] Based on the column vector set and the row vector set of the pooled matrix, the first hit result and the second hit result are obtained.
[0021] In an exemplary embodiment of the present application, the device is configured as follows:
[0022] Segmenting the first text and the target second text to obtain a first keyword contained in the first text and a second keyword contained in the target second text;
[0023] determining a union of the first keyword and the second keyword;
[0024] Dividing the number of keywords in the union by the number of the first keywords to obtain the first hit result;
[0025] The second hit result is obtained by dividing the number of keywords in the union by the number of the second keywords.
[0026] In an exemplary embodiment of the present application, the device is configured as follows:
[0027] Inputting the first text and the second text into a preset machine learning model;
[0028] Matching the first text to each of the second texts through the machine learning model to obtain the first matching result;
[0029] Matching the second text to the first text respectively through the machine learning model to obtain the second matching result;
[0030] Determine a second text that matches the first text based on the first hit result and the second hit result through the machine learning model.
[0031] In an exemplary embodiment of the present application, the device is configured as follows:
[0032] Encoding the first text and the second text as input to obtain a first code corresponding to the first text and a second code corresponding to the second text respectively;
[0033] Hitting the first code with each of the second codes to obtain the first hit result;
[0034] Hitting the second code with the first code respectively to obtain the second hit result;
[0035] Based on the first hit result and the second hit result, a second text matching the first text is determined.
[0036] In an exemplary embodiment of the present application, the apparatus is configured to: adopt BERT as the encoder layer.
[0037] According to one aspect of an embodiment of the present application, an electronic device is disclosed, comprising: a memory storing computer-readable instructions; and a processor reading the computer-readable instructions stored in the memory to execute any one of the methods described in the above claims.
[0038] According to one aspect of an embodiment of the present application, a computer program medium is disclosed, on which computer-readable instructions are stored. When the computer-readable instructions are executed by a processor of a computer, the computer is caused to execute the method described in any one of the above claims.
[0039] According to one aspect of the embodiments of the present application, a computer program product or a computer program is provided, the computer program product or the computer program includes computer instructions, the computer instructions are stored in a computer-readable storage medium. A processor of a computer device reads the computer instructions from the computer-readable storage medium, and the processor executes the computer instructions, so that the computer device executes the methods provided in the above various optional implementations.
[0040] In the embodiment of the present application, for the first text to be matched and the second text to be matched with the first text, the second text to be matched with the first text is determined based on the process of the first text and the second text being hit mutually and bidirectionally. In this way, the matching deviation caused by the one-way semantic matching is avoided, the correlation expression between the texts is improved, and thus the accuracy of the semantic matching is improved.
[0041] Other features and advantages of the present application will become apparent from the following detailed description, or may be learned in part by the practice of the present application.
[0042] It should be understood that the foregoing general description and the following detailed description are exemplary only and are not restrictive of the present application. BRIEF DESCRIPTION OF THE DRAWINGS
[0043] The above and other objects, features and advantages of the present application will become more apparent by describing in detail exemplary embodiments thereof with reference to the attached drawings.
[0044] Figure 1 A system architecture diagram of semantic matching according to an embodiment of the present application is shown.
[0045] Figure 2 A flowchart of a semantic matching method according to an embodiment of the present application is shown.
[0046] Figure 3 A schematic diagram of the machine learning model structure according to an embodiment of the present application is shown.
[0047] Figure 4 A block diagram of a semantic matching device according to an embodiment of the present application is shown.
[0048] Figure 5 A hardware diagram of an electronic device according to an embodiment of the present application is shown. DETAILED DESCRIPTION
[0049] Example embodiments will now be described more fully with reference to the accompanying drawings. However, example embodiments can be implemented in a variety of forms and should not be construed as limited to the examples set forth herein; rather, these example embodiments are provided so that the description of the present application will be more comprehensive and complete and the concepts of the example embodiments will be fully conveyed to those skilled in the art. The accompanying drawings are only schematic illustrations of the present application and are not necessarily drawn to scale. The same reference numerals in the figures represent the same or similar parts, and thus their repeated description will be omitted.
[0050] In addition, the described features, structures or characteristics may be combined in one or more example embodiments in any suitable manner. In the following description, many specific details are provided to provide a full understanding of the example embodiments of the present application. However, those skilled in the art will appreciate that the technical solution of the present application may be practiced while omitting one or more of the specific details, or other methods, components, steps, etc. may be adopted. In other cases, known structures, methods, implementations or operations are not shown or described in detail to avoid obscuring the present application and making the various aspects of the present application obscure.
[0051] Some of the blocks shown in the accompanying drawings are functional entities that do not necessarily correspond to physically or logically independent entities. These functional entities can be implemented in software form, or in one or more hardware modules or integrated circuits, or in different networks and / or processor devices and / or microcontroller devices.
[0052] This application proposes a semantic matching method, which is mainly applied to natural language processing in the field of artificial intelligence. For example, the semantic matching method proposed in this application is applied to search engines related to natural language processing, so that the search engine can provide search services to the terminal according to the semantic matching method.
[0053] Among them, artificial intelligence (AI) is the theory, method, technology and application system that uses digital computers or machines controlled by digital computers to simulate, extend and expand human intelligence, perceive the environment, acquire knowledge and use knowledge to obtain the best results. In other words, artificial intelligence is a comprehensive technology in computer science that attempts to understand the essence of intelligence and produce a new intelligent machine that can respond in a similar way to human intelligence. Artificial intelligence is to study the design principles and implementation methods of various intelligent machines so that machines have the functions of perception, reasoning and decision-making.
[0054] Artificial intelligence technology is a comprehensive discipline that covers a wide range of fields, including both hardware-level and software-level technologies. The basic technologies of artificial intelligence generally include sensors, dedicated artificial intelligence chips, cloud computing, distributed storage, big data processing technology, operation / interaction systems, mechatronics and other technologies. Artificial intelligence software technology mainly includes computer vision technology, speech processing technology, natural language processing technology, and machine learning / deep learning.
[0055] Mainly related to this application, natural language processing (NLP) is an important direction in the fields of computer science and artificial intelligence. It studies various theories and methods that can achieve effective communication between people and computers using natural language. Natural language processing is a science that integrates linguistics, computer science, and mathematics. Therefore, research in this field will involve natural language, that is, the language people use in daily life, so it is closely related to the study of linguistics. Natural language processing technology usually includes technologies such as text processing, semantic understanding, machine translation, robot question answering, knowledge graphs, etc.
[0056] Machine Learning (ML) is a multi-disciplinary subject that involves probability theory, statistics, approximation theory, convex analysis, algorithm complexity theory and other disciplines. It specializes in studying how computers simulate or implement human learning behavior to acquire new knowledge or skills and reorganize existing knowledge structures to continuously improve their performance. Machine learning is the core of artificial intelligence and the fundamental way to make computers intelligent. Its applications are spread across all areas of artificial intelligence. Machine learning and deep learning usually include artificial neural networks, belief networks, reinforcement learning, transfer learning, inductive learning, and self-learning.
[0057] With the research and advancement of artificial intelligence technology, artificial intelligence technology has been studied and applied in many fields, such as common smart homes, smart wearable devices, virtual assistants, smart speakers, smart marketing, unmanned driving, automatic driving, drones, robots, smart medical care, smart customer service, etc. I believe that with the development of technology, artificial intelligence technology will be applied in more fields and play an increasingly important role.
[0058] Before presenting the specific implementation process of the embodiments of the present application in detail, some concepts involved in the present application are first briefly explained.
[0059] The first text refers to the text to be matched. In the application of natural language processing, it is generally the text entered by the user. For example, the user enters the text "orange" in the search box of the terminal, and the text "orange" is the first text; or the user speaks "pomelo" to the voice assistant of the terminal, and the text "pomelo" obtained after voice-to-text conversion is the first text.
[0060] The second text refers to the text used to match the first text to determine whether it matches the first text. The number of second texts is greater than or equal to two. For example: after the search engine obtains the first text "orange" input by the user, the second text "types of oranges" and the second text "which of the autumn fruits, apples, pomegranates, and tangerines is the most worth eating" are matched with the first text "orange" respectively to determine which of the two second texts matches the first text "orange".
[0061] The first keyword refers to the keyword contained in the first text.
[0062] The second keyword refers to a keyword included in the second text.
[0063] Figure 1 A system architecture diagram of semantic matching according to an embodiment of the present application is shown.
[0064] refer to Figure 1As shown, in this embodiment, the implementation of semantic matching mainly involves a server 10 and a terminal 20. Among them, the server 10 can be an independent physical server, or a server cluster or distributed system composed of multiple physical servers, or a cloud server that provides basic cloud computing services such as cloud services, cloud databases, cloud computing, cloud functions, cloud storage, network services, cloud communications, middleware services, domain name services, security services, CDN, and big data and artificial intelligence platforms. The terminal 20 can be a smart phone, a tablet computer, a laptop computer, a desktop computer, a smart speaker, a smart watch, etc., but is not limited to this. The terminal and the server can be directly or indirectly connected by wired or wireless communication, and this application is not limited here.
[0065] The terminal 20, as a collection end of the first text, collects original information including the first text information through interaction with the outside world, and uploads the original information to the server 10. After the server 10 extracts the first text from the original information, it matches the first text with each preset second text to obtain a first hit result, matches the second text with the first text to obtain a second hit result, and then determines the second text matching the first text based on the first hit result and the second hit result.
[0066] The original information collected by the terminal 20 may be text information input by the outside world through clicking or other interactive methods, or may be voice information input by the outside world through voice.
[0067] It should be noted that this embodiment is only an illustrative example of the system architecture that can be adopted by the present application and should not limit the function and scope of the embodiment of the present application.
[0068] It should be noted that, for the purpose of demonstrating the specific implementation process of the embodiments of the present application in actual applications, the subsequent embodiments are demonstrated in detail based on the application scenario of "the search engine provides search services to the terminal according to the semantic matching method proposed in the present application". However, it does not mean that the present application is only applicable to this application scenario.
[0069] Figure 2 A flowchart of a semantic matching method according to an embodiment of the present application is shown.
[0070] refer to Figure 2 As shown, the semantic matching method proposed in one embodiment of the present application includes:
[0071] Step S310: acquiring a first text and at least two second texts to be matched with the first text;
[0072] Step S320: Based on the text semantics, match the first text to each second text to obtain a first matching result;
[0073] Step S330: Based on the text semantics, the second text is matched with the first text to obtain a second matching result;
[0074] Step S340: Determine the second text that matches the first text based on the first hit result and the second hit result.
[0075] In the embodiment of the present application, for the first text to be matched and the second text to be matched with the first text, the second text to be matched with the first text is determined based on the process of the first text and the second text being hit mutually and bidirectionally. In this way, the matching deviation caused by the one-way semantic matching is avoided, the correlation expression between the texts is improved, and thus the accuracy of the semantic matching is improved.
[0076] In one embodiment, after the target speech to be matched is acquired, the first text is obtained by converting the target speech into text.
[0077] In this embodiment, after the search engine obtains the target speech from the terminal, it converts the target speech into text through a speech-to-text component (eg, a pre-trained language model component), thereby obtaining a first text.
[0078] In one embodiment, hit processing is performed by keyword hitting.
[0079] In this embodiment, the search engine performs word segmentation on the first text and each second text to obtain keywords contained in each text, wherein the text may contain multiple keywords.
[0080] For the target second text currently being hit, the search engine determines the union of the first keyword contained in the first text and the second keyword contained in the second text. Then, by dividing the number of keywords in the union by the number of first keywords, the first text is hit to the target second text, and the obtained value is the first hit result. And, by dividing the number of keywords in the union by the number of second keywords, the target second text is hit to the first text, and the obtained value is the second hit result.
[0081] The hit result obtained in this way is greater than or equal to 0 and less than or equal to 1, reflecting the degree of hit.
[0082] For example, the two second texts used to match the first text are respectively recorded as second text A and second text B. The first text contains the first keywords "orange" and "nutrition", the second text A contains the second keywords "orange" and "origin", and the second text B contains the second keywords "orange", "pomelo" and "autumn".
[0083] For the second text A, the number of its second keywords is 2, and the union of its second keywords and the first keywords is "orange". Therefore, it is determined that the first hit result obtained by hitting the first text with the second text A is 1 / 2=0.50, and the second hit result obtained by hitting the second text A with the first text is 1 / 2=0.50.
[0084] For the second text B, the number of its second keywords is 3, and the union of its second keywords and the first keywords is "orange". Therefore, it is determined that the first hit result obtained by hitting the first text with the second text B is 1 / 2=0.50, and the second hit result obtained by hitting the second text B with the first text is 1 / 3=0.33.
[0085] The average value of the hit results can be used as the matching degree of the corresponding second text and the first text, then the matching degree of the second text A and the first text is (0.50+0.50) / 2=0.50, and the matching degree of the second text B and the first text is (0.50+0.33) / 2=0.415. It can be seen that compared with the second text B, the second text A is more matched with the first text. If the second text with the highest matching degree is selected as the second text matching the first text, the second text A is determined as the second text matching the first text.
[0086] The advantage of this embodiment is that by performing hit processing on keywords in the vocabulary dimension, bidirectional hits between texts can be achieved quickly and efficiently.
[0087] In one embodiment, a similarity matrix is used to simultaneously implement bidirectional hit processing between the first text and the second text.
[0088] In this embodiment, the search engine obtains the similarity between the first text and each second text. The similarity may describe the semantic similarity between the first text and the corresponding second text in the dimension of the full text of the text, or may describe the semantic similarity between the keywords contained in the first text and the keywords contained in the corresponding second text in the dimension of the vocabulary that constitutes the text.
[0089] Then, a similarity matrix is established with similarity as matrix element, wherein when the row of the similarity matrix represents the first text, the column of the similarity matrix represents the second text; when the row of the similarity matrix represents the second text, the column of the similarity matrix represents the first text.
[0090] Then, by performing matrix transformation on the similarity matrix, the first text is matched to each second text, and the second text is matched to the first text respectively, and the first matching result and the second matching result are obtained at the same time.
[0091] In one embodiment, two second texts used to match the first text are respectively recorded as second text A and second text B. The first text contains two keywords, respectively recorded as q1 and q2; the second text A contains three keywords, respectively recorded as d1, d2, and d3; the second text B contains two keywords, respectively recorded as d4 and d5.
[0092] After vectorizing each keyword, we get the word vectors corresponding to each keyword. Then we take the vector distance between the word vectors as the similarity between the keywords. Then we use the obtained similarity as the matrix element to establish the similarity matrix MA and MB as shown below.
[0093]
[0094] In the similarity matrix MA, the first row and the second row represent q1 and q2 of the first text respectively; the first column, the second column and the third column represent d1, d2, d3 of the second text A respectively.
[0095] In the similarity matrix MB, the first row and the second row represent q1 and q2 of the first text respectively; the first column and the second column represent d4 and d5 of the second text B respectively.
[0096] q1d1 represents the similarity between q1 and d1, q1d2 represents the similarity between q1 and d2, and similarly, the meanings of other matrix elements are not repeated here.
[0097] The following reference matrices MA0 and MB0 are established for MA and MB respectively.
[0098]
[0099] Furthermore, by transforming the similarity matrix MA based on the reference matrix MA0, the first text is matched to the second text A while the second text A is matched to the first text. Similarly, by transforming the similarity matrix MB based on the reference matrix MB0, the first text is matched to the second text B while the second text B is matched to the first text.
[0100] Among them, bidirectional hit processing can be achieved by determining the similarity between the similarity matrix and the corresponding reference matrix. Specifically, by determining the similarity between the similarity matrix MA and the reference matrix MA0, bidirectional hit processing for the second text A is achieved; by determining the similarity between the similarity matrix MB and the reference matrix MB0, bidirectional hit processing for the second text B is achieved.
[0101] Bidirectional hit processing can also be achieved by merging the row vectors of the similarity matrix and merging the column vectors, and then matching them with the merged row vectors or merged column vectors of the corresponding reference matrix. Specifically, for the similarity matrix MA, the row vectors (q1d1, q1d2, q1d3) and the row vectors (q2d1, q2d2, q2d3) are merged to obtain the merged row vectors (q1d1+q2d1, q1d2+q2d2, q1d3+q2d3) of the similarity matrix MA. The column vectors (q1d1, q2d1), the column vectors (q1d2, q2d2) and the column vectors (q1d3, q2d3) are merged to obtain the merged column vectors (q1d1+q1d2+q1d3, q2d1+q2d2+q2d3) of the similarity matrix MA. By matching the merged row vector (q1d1+q2d1, q1d2+q2d2, q1d3+q2d3) of the similarity matrix MA with the merged row vector (2,2,2) of the reference matrix MA0, and matching the merged column vector (q1d1+q1d2+q1d3, q2d1+q2d2+q2d3) of the similarity matrix MA with the merged column vector (3,3,3) of the reference matrix MA0, a two-way hit processing for the second text A is achieved. Similarly, the two-way hit processing for the second text B is not described in detail here.
[0102] The advantage of this embodiment is that by achieving two-way matching between texts in the matrix dimension, semantic information is enriched, thereby improving the accuracy of semantic matching.
[0103] In one embodiment, pooling is performed on the similarity matrix to simultaneously achieve bidirectional hit processing between the first text and the second text.
[0104] In this embodiment, the search engine uses a preset Gaussian kernel to perform pooling processing on the similarity matrix to obtain a pooled matrix. Compared with the similarity matrix before the pooling processing, the pooled matrix improves the perception field of view and reduces the optimization difficulty.
[0105] Furthermore, when the rows of the pooled matrix represent the first text, the first hit result is obtained based on the row vector set of the pooled matrix, and the second hit result is obtained based on the column vector set of the pooled matrix; when the rows of the pooled matrix represent the second text, the first hit result is obtained based on the column vector set of the pooled matrix, and the second hit result is obtained based on the row vector set of the pooled matrix.
[0106] In one embodiment, a plurality of Gaussian kernels are used to perform pooling processing on the similarity matrix respectively, so as to obtain the first hit results and the second hit results at a plurality of scales.
[0107] The advantage of this embodiment is that, through the hit processing at multiple scales, the semantic information is enriched, thereby improving the accuracy of semantic matching.
[0108] In one embodiment, the semantic matching method proposed in this application is implemented through a machine learning model.
[0109] In this embodiment, a machine learning model is obtained by pre-training. The machine learning model takes the first text and each second text as input, and through the processing of the model parameters obtained by pre-training, the first text is matched with each second text to obtain a first hit result, and the second text is matched with the first text to obtain a second hit result, and then based on the first hit result and the second hit result, the second text matching the first text is determined.
[0110] The advantage of this embodiment is that the semantic matching method proposed in this application is implemented through a machine learning model, thereby improving the processing integration and modularity of semantic matching.
[0111] In one embodiment, the machine learning model used to implement the semantic matching method proposed in the present application includes an encoder layer, a hit processing layer, and a fully connected layer.
[0112] In this embodiment, the encoder layer is used to encode the text of the input model to obtain the first code corresponding to the first text and the second code corresponding to the second text.
[0113] The first code and the second code output by the encoder layer are input to the hit processing layer. The hit processing layer is used to implement bidirectional hit processing between the first text and the second text in parallel. The first code is hit to each second code to obtain a first hit result; and the second code is hit to each first code to obtain a second hit result.
[0114] The first hit result and the second hit result output by the hit processing layer are input into the fully connected layer. The fully connected layer is used to determine the second text that matches the first text based on the first hit result and the second hit result. Specifically, the fully connected layer classifies the first hit result and the second hit result through a classifier (e.g., a softmax function), outputs the probability that each second text matches the first text, and then determines the second text that matches the first text based on the probability.
[0115] In one embodiment, BERT is used as the encoder layer in the machine learning model proposed in this application.
[0116] It should be noted that this embodiment is only an exemplary description and should not limit the function and scope of use of the present disclosure.
[0117] In one embodiment, a neural network that implements a similarity matrix in matrix form is used as a hit processing layer in the machine learning model proposed in this application.
[0118] Figure 3 A schematic diagram of the machine learning model structure according to an embodiment of the present application is shown.
[0119] refer to Figure 3 As shown, in this embodiment, the machine learning model used to achieve semantic matching includes a decoder layer composed of BERT, a hit processing layer composed of a neural network that implements a similarity matrix in a matrixed manner, and a fully connected layer that outputs probabilities through a classifier.
[0120] In this embodiment, the first text Query (q1 to qm shown in the figure) and the second text Doc (d1 to dn shown in the figure) input to BERT are separated by the separator SEP. By encoding the input text, BERT outputs a token sequence for each word in the text.
[0121] The hit processing layer averages the token sequence to obtain the token embedding of each word, and then builds a similarity matrix based on this, and performs pooling processing according to the preset Gaussian kernel.
[0122] The row vector and column vector obtained after the pooling process are input into the fully connected layer. Under the processing of the classifier, the probability of the second text Doc matching the first text Query is output, and then the second text Doc matching the first text Query is determined on this basis.
[0123] It should be noted that this embodiment is only an exemplary description and should not limit the function and scope of use of the present disclosure.
[0124] Figure 4A semantic matching device according to an embodiment of the present application is shown, the device comprising:
[0125] An acquisition module 410 is configured to acquire a first text and at least two second texts to be matched with the first text;
[0126] A first matching module 420 is configured to match the first text to each of the second texts based on text semantics to obtain a first matching result;
[0127] A second matching module 430 is configured to match the second text to the first text based on text semantics to obtain a second matching result;
[0128] The matching module 440 is configured to determine a second text matching the first text based on the first hit result and the second hit result.
[0129] In an exemplary embodiment of the present application, the device is configured as follows:
[0130] Obtaining the similarity between the first text and each of the second texts;
[0131] Establishing a similarity matrix with the similarities as matrix elements;
[0132] Based on the transformation processing of the similarity matrix, the first text is matched to each of the second texts, and the second text is matched to the first text respectively, and the first matching result and the second matching result are obtained at the same time.
[0133] In an exemplary embodiment of the present application, the device is configured as follows:
[0134] Using a preset Gaussian kernel to perform pooling processing on the similarity matrix to obtain a pooled matrix;
[0135] Based on the column vector set and the row vector set of the pooled matrix, the first hit result and the second hit result are obtained.
[0136] In an exemplary embodiment of the present application, the device is configured as follows:
[0137] Segmenting the first text and the target second text to obtain a first keyword contained in the first text and a second keyword contained in the target second text;
[0138] determining a union of the first keyword and the second keyword;
[0139] Dividing the number of keywords in the union by the number of the first keywords to obtain the first hit result;
[0140] The second hit result is obtained by dividing the number of keywords in the union by the number of the second keywords.
[0141] In an exemplary embodiment of the present application, the device is configured as follows:
[0142] Inputting the first text and the second text into a preset machine learning model;
[0143] Matching the first text to each of the second texts through the machine learning model to obtain the first matching result;
[0144] Matching the second text to the first text respectively through the machine learning model to obtain the second matching result;
[0145] Determine a second text that matches the first text based on the first hit result and the second hit result through the machine learning model.
[0146] In an exemplary embodiment of the present application, the device is configured as follows:
[0147] Encoding the first text and the second text as input to obtain a first code corresponding to the first text and a second code corresponding to the second text respectively;
[0148] Hitting the first code with each of the second codes to obtain the first hit result;
[0149] Hitting the second code with the first code respectively to obtain the second hit result;
[0150] Based on the first hit result and the second hit result, a second text matching the first text is determined.
[0151] In an exemplary embodiment of the present application, the apparatus is configured to: adopt BERT as the encoder layer.
[0152] Reference below Figure 5 An electronic device 50 according to an embodiment of the present application is described. Figure 5 The electronic device 50 shown is merely an example and should not bring any limitation to the functions and scope of use of the embodiments of the present application.
[0153] like Figure 5 As shown, the electronic device 50 is in the form of a general computing device. The components of the electronic device 50 may include but are not limited to: at least one processing unit 510, at least one storage unit 520, and a bus 530 connecting different system components (including the storage unit 520 and the processing unit 510).
[0154] The storage unit stores program codes, which can be executed by the processing unit 510, so that the processing unit 510 performs the steps according to various exemplary embodiments of the present invention described in the description of the exemplary method described above in this specification. For example, the processing unit 510 can perform the following steps: Figure 2 The steps shown in .
[0155] The storage unit 520 may include a readable medium in the form of a volatile storage unit, such as a random access storage unit (RAM) 5201 and / or a cache storage unit 5202 , and may further include a read-only storage unit (ROM) 5203 .
[0156] The storage unit 520 may also include a program / utility 5204 having a set (at least one) of program modules 5205, such program modules 5205 including but not limited to: an operating system, one or more application programs, other program modules, and program data, each of which or some combination may include an implementation of a network environment.
[0157] Bus 530 may represent one or more of several types of bus structures, including a memory unit bus or memory unit controller, a peripheral bus, an accelerated graphics port, a processing unit, or a local bus using any of a variety of bus architectures.
[0158] The electronic device 50 may also communicate with one or more external devices 600 (e.g., keyboards, pointing devices, Bluetooth devices, etc.), may also communicate with one or more devices that enable a user to interact with the electronic device 50, and / or may communicate with any device that enables the electronic device 50 to communicate with one or more other computing devices (e.g., routers, modems, etc.). Such communication may be performed via an input / output (I / O) interface 550. The input / output (I / O) interface 550 is connected to a display unit 540. Furthermore, the electronic device 50 may also communicate with one or more networks (e.g., a local area network (LAN), a wide area network (WAN), and / or a public network, such as the Internet) via a network adapter 560. As shown, the network adapter 560 communicates with other modules of the electronic device 50 via a bus 530. It should be understood that, although not shown in the figure, other hardware and / or software modules may be used in conjunction with the electronic device 50, including but not limited to: microcode, device drivers, redundant processing units, external disk drive arrays, RAID systems, tape drives, and data backup storage systems.
[0159] Through the description of the above implementation methods, it is easy for those skilled in the art to understand that the example implementation methods described here can be implemented by software or by combining software with necessary hardware. Therefore, the technical solution according to the implementation methods of the present application can be embodied in the form of a software product, which can be stored in a non-volatile storage medium (which can be a CD-ROM, a USB flash drive, a mobile hard disk, etc.) or on a network, and includes several instructions to enable a computing device (which can be a personal computer, a server, a terminal device, or a network device, etc.) to execute the method according to the implementation methods of the present application.
[0160] In an exemplary embodiment of the present application, a computer-readable storage medium is further provided, on which computer-readable instructions are stored. When the computer-readable instructions are executed by a processor of a computer, the computer executes the method described in the above method embodiment.
[0161] According to one embodiment of the present application, a program product for implementing the method in the above method embodiment is also provided, which can adopt a portable compact disk read-only memory (CD-ROM) and include program code, and can be run on a terminal device, such as a personal computer. However, the program product of the present invention is not limited to this. In this document, a readable storage medium can be any tangible medium containing or storing a program, which can be used by or in combination with an instruction execution system, an apparatus or a device.
[0162] The program product may use any combination of one or more readable media. The readable medium may be a readable signal medium or a readable storage medium. The readable storage medium may be, for example, but not limited to, an electrical, magnetic, optical, electromagnetic, infrared, or semiconductor system, device or device, or any combination of the above. More specific examples (non-exhaustive list) of readable storage media include: an electrical connection with one or more wires, a portable disk, a hard disk, a random access memory (RAM), a read-only memory (ROM), an erasable programmable read-only memory (EPROM or flash memory), an optical fiber, a portable compact disk read-only memory (CD-ROM), an optical storage device, a magnetic storage device, or any suitable combination of the above.
[0163] Computer readable signal media may include data signals propagated in baseband or as part of a carrier wave, in which readable program code is carried. Such propagated data signals may take a variety of forms, including but not limited to electromagnetic signals, optical signals, or any suitable combination of the above. Readable signal media may also be any readable medium other than a readable storage medium, which may send, propagate, or transmit a program for use by or in conjunction with an instruction execution system, apparatus, or device.
[0164] The program code embodied on the readable medium may be transmitted using any appropriate medium, including but not limited to wireless, wired, optical cable, RF, etc., or any suitable combination of the foregoing.
[0165] Program code for performing the operations of the present invention may be written in any combination of one or more programming languages, including object-oriented programming languages such as JAVA, C++, etc., and conventional procedural programming languages such as "C" or similar programming languages. The program code may be executed entirely on the user computing device, partially on the user device, as a separate software package, partially on the user computing device and partially on a remote computing device, or entirely on a remote computing device or server. In the case of a remote computing device, the remote computing device may be connected to the user computing device through any type of network, including a local area network (LAN) or a wide area network (WAN), or may be connected to an external computing device (e.g., through the Internet using an Internet service provider).
[0166] It should be noted that, although several modules or units of the equipment for action execution are mentioned in the above detailed description, this division is not mandatory. In fact, according to the embodiments of the present application, the features and functions of two or more modules or units described above can be embodied in one module or unit. On the contrary, the features and functions of one module or unit described above can be further divided into being embodied by multiple modules or units.
[0167] In addition, although the steps of the method in the present application are described in a specific order in the drawings, this does not require or imply that the steps must be performed in this specific order, or that all the steps shown must be performed to achieve the desired results. Additionally or alternatively, some steps may be omitted, multiple steps may be combined into one step, and / or one step may be decomposed into multiple steps, etc.
[0168] Through the description of the above implementation methods, it is easy for those skilled in the art to understand that the example implementation methods described here can be implemented by software or by combining software with necessary hardware. Therefore, the technical solution according to the implementation methods of the present application can be embodied in the form of a software product, which can be stored in a non-volatile storage medium (which can be a CD-ROM, a USB flash drive, a mobile hard disk, etc.) or on a network, and includes several instructions to enable a computing device (which can be a personal computer, a server, a mobile terminal, or a network device, etc.) to execute the method according to the implementation methods of the present application.
[0169] Those skilled in the art will readily appreciate other embodiments of the present application after considering the specification and practicing the invention disclosed herein. The present application is intended to cover any modification, use or adaptation of the present application, which follows the general principles of the present application and includes common knowledge or customary techniques in the art that are not disclosed in the present application. The specification and examples are intended to be exemplary only, and the true scope and spirit of the present application are indicated by the appended claims.
Claims
1. A semantic matching method, characterized in that: The method comprises: Acquire a first text and at least two second texts to be matched with the first text; Based on text semantics, matching the first text to each of the second texts to obtain a first matching result; Based on text semantics, matching the second text to the first text respectively to obtain a second matching result; Determine a second text matching the first text based on the first hit result and the second hit result; The method further comprises: Segmenting the first text and the target second text to obtain a first keyword contained in the first text and a second keyword contained in the target second text; Determine an intersection of the first keyword and the second keyword; Dividing the number of keywords in the intersection by the number of the first keywords to obtain the first hit result; The second hit result is obtained by dividing the number of keywords in the intersection by the number of the second keywords.
2. The method according to claim 1, characterized in that The method further comprises: Obtaining the similarity between the first text and each of the second texts; Establishing a similarity matrix with the similarities as matrix elements; Based on the transformation processing of the similarity matrix, the first text is matched to each of the second texts, and the second text is matched to the first text respectively, and the first matching result and the second matching result are obtained at the same time.
3. The method according to claim 2, characterized in that The method further comprises: Using a preset Gaussian kernel to perform pooling processing on the similarity matrix to obtain a pooled matrix; Based on the column vector set and the row vector set of the pooled matrix, the first hit result and the second hit result are obtained.
4. The method according to claim 1, characterized in that: The method further comprises: Inputting the first text and the second text into a preset machine learning model; Matching the first text to each of the second texts through the machine learning model to obtain the first matching result; Matching the second text to the first text respectively through the machine learning model to obtain the second matching result; Determine a second text that matches the first text based on the first hit result and the second hit result through the machine learning model.
5. The method according to claim 4, characterized in that The machine learning model includes an encoder layer, a hit processing layer, and a fully connected layer, wherein: The encoder layer is configured to: encode the first text and the second text as input to obtain a first code corresponding to the first text and a second code corresponding to the second text respectively; The hit processing layer is configured as follows: Hitting the first code with each of the second codes to obtain the first hit result; Hitting the second code with the first code respectively to obtain the second hit result; The fully connected layer is configured to determine a second text that matches the first text based on the first hit result and the second hit result.
6. The method according to claim 5, characterized in that BERT is adopted as the encoder layer.
7. A semantic matching device, characterized in that: The device comprises: An acquisition module, configured to acquire a first text and at least two second texts to be matched with the first text; A first matching module configured to match the first text to each of the second texts based on text semantics to obtain a first matching result; A second matching module is configured to match the second text to the first text based on text semantics to obtain a second matching result; A matching module, configured to determine a second text matching the first text based on the first hit result and the second hit result; The device also includes: Segmenting the first text and the target second text to obtain a first keyword contained in the first text and a second keyword contained in the target second text; Determine an intersection of the first keyword and the second keyword; Dividing the number of keywords in the intersection by the number of the first keywords to obtain the first hit result; The second hit result is obtained by dividing the number of keywords in the intersection by the number of the second keywords.
8. An electronic device, characterized in that: include: a memory storing computer-readable instructions; The processor reads the computer readable instructions stored in the memory to execute the method according to any one of claims 1 to 6.
9. A computer-readable storage medium, characterized in that: Computer readable instructions are stored thereon, and when the computer readable instructions are executed by a processor of a computer, the computer is caused to execute the method of any one of claims 1-6.
10. A computer program product, comprising computer instructions, wherein the computer instructions are stored in a computer-readable storage medium; a processor of a computer device reads the computer instructions from the computer-readable storage medium, and the processor executes the computer instructions, so that the computer device executes the method described in any one of claims 1-6.
