Method, apparatus, electronic device and medium for determining text relevance
By determining the initial and target weights of service words in the service knowledge graph, combining language representation and attention model, the problem of inaccurate correlation in text matching is solved, and the accuracy and user experience of correlation determination are improved.
Patent Information
- Application Number
- CN202110039115.1
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2021-01-12
- Publication Date
- 2025-07-11
- Estimated Expiration
- 2041-01-12
AI Technical Summary
In the prior art, when text matching, the correlation obtained through semantic matching models does not match the true correlation between text, resulting in inaccurate predicted correlation.
By obtaining the service word set corresponding to the first text and the second text in the service knowledge graph, the initial weight of each service word is determined, and the target weight is calculated using the language representation model and attention model, and text correlation information is obtained in combination with the text matching model.
It improves the accuracy of service correlation determination, reduces the mismatch between text correlation and actual service correlation, and improves the user experience.
Smart Images

Figure CN113392181B_ABST
Abstract
Description
Technical Field
[0001] This application relates to the technical field of natural language processing, and in particular, to a method, apparatus, electronic device, and medium for determining text relevance. Background Art
[0002] Currently, there are many scenarios that require text matching to push information, provide services, etc. based on text relevance. For example, a semantic matching model can be used to calculate the relevance between a user's search keyword and a service database document for text matching. However, the inventors have found in practice that: when performing text matching currently, the relevance obtained through the semantic matching model often does not match the true relevance between texts, and the predicted relevance is inaccurate. Summary of the Invention
[0003] Embodiments of this application provide a method, apparatus, electronic device, and medium for determining text relevance, which can improve the accuracy of service relevance determination and effectively reduce the situation where the determined text relevance does not match the actual service relevance.
[0004] On the one hand, embodiments of this application provide a method for determining text relevance, the method comprising:
[0005] Obtain a first service word set corresponding to a first text in a service knowledge graph, and a second service word set corresponding to a second text in the service knowledge graph, where both the first service word set and the second service word set include at least one service word;
[0006] Determine the initial weight of each service word in the first service word set according to the first text and the first service word set, and determine the initial weight of each service word in the second service word set according to the second text and the second service word set;
[0007] Determine the target weight of each service word in the first service word set according to the first text, the first service word set, and the initial weight of each service word in the first service word set, and determine the target weight of each service word in the second service word set according to the second text, the second service word set, and the initial weight of each service word in the second service word set;
[0008] Obtain the relevance information between the first text and the second text according to the first service word set, the target weight of each service word in the first service word set, the second service word set, and the target weight of each service word in the second service word set.
[0009] On the one hand, embodiments of this application provide a device for determining text relevance, the device comprising:
[0010] An acquisition module, configured to acquire a first service word set corresponding to a first text in a service knowledge graph and a second service word set corresponding to a second text in the service knowledge graph, where both the first service word set and the second service word set include at least one service word;
[0011] A determination module, configured to determine initial weights of each service word in the first service word set according to the first text and the first service word set, and determine initial weights of each service word in the second service word set according to the second text and the second service word set;
[0012] The determination module is further configured to determine target weights of each service word in the first service word set according to the first text, the first service word set, and the initial weights of each service word in the first service word set, and determine target weights of each service word in the second service word set according to the second text, the second service word set, and the initial weights of each service word in the second service word set;
[0013] A processing module, configured to obtain correlation information between the first text and the second text according to the first service word set, the target weights of each service word in the first service word set, the second service word set, and the target weights of each service word in the second service word set.
[0014] On the one hand, an embodiment of the present application provides an electronic device, characterized in that the electronic device includes a processor and a memory, the processor is interconnected with the memory, where the memory is used to store computer program instructions, and the processor is configured to execute the computer program instructions to implement some or all of the steps in the above method.
[0015] On the one hand, an embodiment of the present application provides a computer-readable storage medium, in which computer program instructions are stored, and when the computer program instructions are executed by a processor, they are used to execute some or all of the steps in the above method.
[0016] In an embodiment of the present application, the first service word set corresponding to the first text in the service knowledge graph and the second service word set corresponding to the second text in the service knowledge graph can be obtained, and the initial weights of the service words in the first service word set and the initial weights of the service words in the second service word set can be determined respectively. Furthermore, the target weights of the service words in the first service word set and the target weights of the service words in the second service word set can be determined respectively, and the relevance information between the first text and the second text can be obtained according to the first service word set, the target weights of the service words in the first service word set, the second service word set, and the target weights of the service words in the second service word set. By implementing the above method, the accuracy of service relevance determination can be improved to a certain extent, and the situation where the determined text relevance does not match the actual service relevance can be effectively reduced. BRIEF DESCRIPTION OF THE DRAWINGS
[0017] In order to more clearly illustrate the technical solutions of the embodiments of the present application, the drawings required for the description of the embodiments will be briefly introduced below. Obviously, the drawings in the following description are some embodiments of the present application. For those of ordinary skill in the art, other drawings can be obtained based on these drawings without creative efforts.
[0018] Figure 1 It is a schematic diagram for determining service relevance;
[0019] Figure 2 It is a schematic flowchart of a method for determining text relevance provided by an embodiment of the present application;
[0020] Figure 3 It is a schematic flowchart of a method for constructing a service knowledge graph provided by an embodiment of the present application;
[0021] Figure 4 It is a schematic diagram of the effect of a service knowledge graph provided by an embodiment of the present application;
[0022] Figure 5 It is a schematic flowchart of another method for determining text relevance provided by an embodiment of the present application;
[0023] Figure 6a It is a schematic diagram of a specific scenario for determining text relevance provided by an embodiment of the present application;
[0024] Figure 6b It is a schematic diagram of another specific scenario for determining text relevance provided by an embodiment of the present application;
[0025] Figure 7 It is a schematic diagram of the effect of another service knowledge graph provided by an embodiment of the present application;
[0026] Figure 8aSchematic diagram of a specific scenario of a matching model based on graph reasoning provided by an embodiment of the present application;
[0027] Figure 8b Schematic diagram of another specific scenario of a matching model based on graph reasoning provided by an embodiment of the present application;
[0028] Figure 8c Schematic diagram of yet another specific scenario of a matching model based on graph reasoning provided by an embodiment of the present application;
[0029] Figure 8d Schematic diagram of yet another specific scenario of a matching model based on graph reasoning provided by an embodiment of the present application;
[0030] Figure 8e Schematic diagram of yet another specific scenario of a matching model based on graph reasoning provided by an embodiment of the present application;
[0031] Figure 8f Schematic diagram of yet another specific scenario of a matching model based on graph reasoning provided by an embodiment of the present application;
[0032] Figure 8g Schematic diagram of yet another specific scenario of a matching model based on graph reasoning provided by an embodiment of the present application;
[0033] Figure 8h Schematic diagram of yet another specific scenario of a matching model based on graph reasoning provided by an embodiment of the present application;
[0034] Figure 8i Schematic diagram of yet another specific scenario of a matching model based on graph reasoning provided by an embodiment of the present application;
[0035] Figure 9 Schematic diagram of the structure of a device for determining text relevance provided by an embodiment of the present application;
[0036] Figure 10 Schematic diagram of the structure of an electronic device provided by an embodiment of the present application. Detailed implementation manners
[0037] Next, the technical solutions in the embodiments of the present application will be clearly and completely described in conjunction with the accompanying drawings in the embodiments of the present application.
[0038] An embodiment of the present application proposes a method for determining text relevance, which can fuse a service knowledge graph and a semantic matching model to determine the relevance between texts, thereby improving the accuracy of service relevance determination and effectively reducing the situation where the determined text relevance does not match the actual service relevance.
[0039] The technical solution of this application can be applied to an electronic device, which can be a terminal, a server, or other devices for determining text relevance. This application does not make any limitations here. Among them, the terminal can include a smart phone, a tablet computer, a laptop computer, a palm computer, a desktop computer, etc., which will not be listed one by one here.
[0040] The embodiments of this application relate to the field of natural language processing technology. Natural language processing technology (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 humans and computers in natural language. Natural language processing is a science that integrates linguistics, computer science, and mathematics. Therefore, the research in this field will involve natural language, that is, the language that people use in daily life, so it has a close connection with the research of linguistics. Natural language processing technology usually includes technologies such as text processing, semantic understanding, and knowledge graphs.
[0041] With the research and progress 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, driverless, autonomous driving, drones, robots, smart healthcare, smart customer service, etc. It is believed that with the development of technology, artificial intelligence technology will be applied in more fields and play an increasingly important role.
[0042] Optionally, in some embodiments, the text involved in this application can be heterogeneous text, and two texts (such as the first text and the second text) can be heterogeneous to each other. That is, the semantic spaces of the matching first text such as text A and the second text such as text B are different. The first text can be a service search text, and the second text can be a database text. For example, text A corresponds to the user input query, such as the query text, which is the service search text, and text B corresponds to the retrieved document, such as the doc text, which is the database text. The heterogeneity is reflected in that the query length is generally shorter, while the doc length is longer; and the words that make up the query are more colloquial, and the words that make up the doc contain more proper nouns.
[0043] Optionally, this application can also be specifically applied to the applications or functions of an electronic device such as a terminal. For example, the method for determining text relevance can be applied to the search function of WeChat. The search function can search for moments, articles, official accounts, novels, music, emojis, etc. according to keywords. Further optionally, this application can be specifically applied to the field of vertical search (vertical search), such as specifically applied to service search in vertical search.
[0044] Among them, vertical search is a subdivision and extension of search engines. For example, it can refer to a professional search (engine) for a specific industry. It can integrate a certain type of specialized information in the library once, extract the required data by field in a targeted manner, process it, and then return it to the user in a certain form. For example, in the search function of the application client, it can specifically refer to the search for a certain type of results, such as public account search, mini-program search, etc.
[0045] Service search can refer to presenting corresponding service search results according to the user's service search request. For example, it can directly display the services that meet the user's query to the user. For example, when searching for a nanny, the service search can directly provide the nanny service menu; another example is that when the user enters the keyword "clothes cleaning", the search results can provide channels that offer the "clothes cleaning" service. In addition, the search function can also have other types of search results, such as the account results of public accounts or mini-programs, which cannot directly provide services and do not meet the user's needs as directly as service search.
[0046] In some embodiments, the electronic device can execute the method for determining text relevance according to actual business requirements. For example, in an actual application scenario, after detecting that the user enters a service search text, the electronic device executes the method for determining text relevance in this document to find service search results with strong relevance to the text entered by the user from numerous background data. Further, the service search results can be sorted and displayed according to the strength of relevance. This can reduce the situation where the text semantic relevance does not match the actual service, improve the accuracy of service relevance determination, and ensure the user experience during the service search process. Another example is that the online processing part of service search is divided into query intent recognition, recall and ranking, refined ranking, and finally the posterior module. The technical solution of this application can be specifically applied to the posterior module. After determining multiple docs (service search results) corresponding to the query, it can filter out service search results with poor relevance to the query and further give relevance grading for mixed sorting. This can remove results with poor relevance in the search results and ensure the user experience.
[0047] For example, as Figure 1 shown, the predicted probability of relevance between "check traffic violations" and "traffic violation query" with strong semantic model correlation is less than the predicted probability of relevance between "traffic condition query" and "traffic violation query" without correlation. In order to obtain the result of "check traffic violations", it will release "traffic condition query" that is not relevant to the actual service, resulting in inaccurate judgment. Also, "driver's license renewal" and "driver's license score inquiry" are not strongly relevant, and the judgment is inaccurate. By implementing the method for determining text relevance of this application, it can be determined that the relevance between "traffic condition query" and "traffic violation query" is low, and the relevance between "driver's license renewal" and "driver's license score inquiry" is low, improving the judgment accuracy.
[0048] Optionally, data involved in this application, such as relevance information, service knowledge graph, and / or weights, etc., can be stored in a database, or can be stored in a blockchain, such as through blockchain distributed storage. This application does not make any limitations.
[0049] It can be understood that the above scenarios are only examples and do not constitute limitations on the application scenarios of the technical solutions provided by the embodiments of this application. The technical solutions of this application can also be applied to other scenarios. For example, as is known to those of ordinary skill in the art, with the evolution of the system architecture and the emergence of new business scenarios, the technical solutions provided by the embodiments of this application are equally applicable to similar technical problems.
[0050] The solution provided by the embodiments of this application involves technologies such as natural language processing technology in artificial intelligence, and will be specifically described through the following embodiments.
[0051] Based on the above description, a method for determining text relevance proposed by the embodiments of this application can be executed by the above-mentioned electronic device, and the description here will be illustrated by taking a terminal as an example. As Figure 2 shown, the process of the method for determining text relevance in this embodiment may include:
[0052] S201. Obtain a first set of service words corresponding to the first text in the service knowledge graph, and a second set of service words corresponding to the second text in the service knowledge graph.
[0053] Among them, the first set of service words and the second set of service words include at least one service word. Each service word has a corresponding service attribute. Optionally, each service word can be associated with the corresponding service attribute; or, the service attributes corresponding to each service word can also be obtained, and the set of service words (the first set of service words and the second set of service words) can include at least one service word and its service attribute. Further optionally, the service attribute may include service entity (word), service behavior (word), service status (word), service brand (word), service composite (word), etc. Further optionally, each service word may correspond to one or more knowledge categories, or specific service words such as entity words may correspond to one or more knowledge categories.
[0054] Optionally, the service knowledge graph can be pre-generated or trained based on samples (such as the above-mentioned query text and doc text, etc.). Specifically, the service knowledge graph can be constructed based on the service words and their service attributes of the samples. Further optionally, the knowledge categories to which the samples belong can also be combined to construct the service knowledge graph, so as to realize fast and reliable knowledge linkage based on the service knowledge graph. For example, the construction of the service knowledge graph is specifically as shown in steps S301 - S303.
[0055] In a possible implementation, the specific method for obtaining the first service word set corresponding to the first text in the service knowledge graph may be that the terminal determines the target knowledge category to which the first text belongs, performs word segmentation on the first text to obtain each word segment of the first text, and the terminal semantically matches each word segment of the first text with the service words under the target knowledge category of the service knowledge graph to obtain the service words included in the first text (corresponding service words), and uses the service words included in the first text as the first service word set. Optionally, the terminal may further obtain an associated service word set of the service words included in the first text, where the service words in the associated service word set have a connection relationship with at least one of the service words included in the first text in the service knowledge graph, such as one or more of the extended words, synonyms, and hypernyms of the service words included in the first text, and the terminal may use the service words included in the first text and the associated service word set as the first service word set.
[0056] Optionally, the knowledge category can be different knowledge categories such as housekeeping, transportation, repair, catering, etc. If there is only one knowledge category in the service knowledge graph, the service knowledge graph can be directly determined as the target knowledge category. When semantically matching each of the segmented words with all the service words in the target knowledge category, various semantic matching models can be used for the matching. For example, the semantic matching models used can include, but are not limited to: deep text matching models, such as the Convolutional-Kernel-based Neural Ranking Model (CONV-KNRM); language representation models, such as the Bidirectional Encoder Representation from Transformers (BERT) model; deep semantic matching models, such as the Deep Structured Semantic Model (DSSM) and / or the Convolutional Latent Semantic Model (CLSM), etc. Optionally, the terminal can determine the service words with semantic relevance greater than a preset value as the service words corresponding to each segmented word according to the results of the semantic matching. Further optionally, obtaining the associated service word set can be through the service knowledge graph. There are relationships between various service words in the service knowledge graph. When it is detected that the service words included in the first text have a connection relationship with other service words in the service knowledge graph and are one or more of the extended words, synonyms, and hypernyms, the service words are obtained and used as the associated service word set. For example, the service words included in the first text are "fast", "air conditioner", "clean". Among them, from the service knowledge graph, it is obtained that "home appliance" has a connection relationship with "air conditioner" and is the hypernym of "air conditioner", and "cleaning" has a connection relationship with "clean" and is the synonym of "clean". Therefore, "home appliance" and "cleaning" are extracted as the associated service word set of the service words included in the first text.
[0057] In a possible implementation manner, when multiple service words (with the same service attribute) are matched from the target knowledge category of the service knowledge graph for the segmented words obtained by segmenting the first text, the terminal can use the service word with the lowest level among the multiple service words as the service word corresponding to at least one phrase, that is, the service word included in the first text. For example, when the phrase is "electric iron", the phrase is semantically matched with the service words in the target knowledge category, and the service (entity) words with semantic relevance greater than the preset value are "electrical appliance" and "electric welding". In the service knowledge graph, "electric welding" belongs to the hyponym of "electrical appliance", so "electric welding" is selected as the service word corresponding to the phrase and the service word is included in the first service word set.
[0058] Optionally, the method for obtaining the second service word set of the second text may be the same as that of the first service word set of the first text, which will not be elaborated here.
[0059] S202. Determine the initial weights of the service words in the first service word set according to the first text and the first service word set, and determine the initial weights of the service words in the second service word set according to the second text and the second service word set.
[0060] In a possible implementation manner, the specific method for determining the initial weights of the service words in the first service word set may be obtained based on a pre-established correspondence, and / or may be determined based on a model algorithm, and / or may be determined according to the service attributes of each service word, and / or may be set according to empirical values, and / or may be obtained according to a service knowledge graph, and so on. Among them, the initial weight may be a numerical value or a vector.
[0061] In a possible implementation manner, the method for determining the initial weights is, when constructing a service knowledge graph, to calculate the initial weights of service words using multiple training samples, and establish an index table according to the service words and their corresponding initial weights, or establish an index table according to text segmentation, the service words corresponding to the text segmentation, and the initial weights. When the first service word set is obtained, the initial weights of the service words in the first service word set corresponding to the first text can be obtained according to the correspondence determined by the index table. Among them, calculating the initial weights of service words using multiple training samples can be to calculate the initial weights of service words through the Term Frequency–Inverse Document Frequency (TF-IDF) algorithm, that is, first calculate the term frequency of the service word in the training samples, then calculate the logarithm of the ratio of the total number of training samples to the number of training samples where the service word is located to obtain the inverse sample frequency of the training samples where the service word is located, and take the product of the term frequency of the service word and the corresponding inverse sample frequency as the initial weight of the service word.
[0062] In a possible implementation manner, the method for determining the initial weights may also be obtained through a model. For example, using a language representation model, such as the Knowledge-enabled Bidirectional Encoder Representation from Transformers (K-BERT) model (which is a knowledge-enabled language representation model), to determine the visibility matrix of the service word, and then using the self-attention mechanism and according to the visibility matrix of the service word to determine the initial weights of the service words in the first service word set.
[0063] In a possible implementation manner, the way to determine the initial weights can also be through service attributes. For example, service words with different service attributes are given different weights. Among them, the service attributes of service words can be obtained according to the service knowledge graph. In the service knowledge graph, each service word has corresponding service attributes, such as service entity words, service behavior words, service status words, service compound words, service entity brand words, and other service attributes, which are not limited here. After obtaining the first set of service words, the service attributes of each service word in the first set of service words can be obtained according to the service knowledge graph. For example, if the first text is "furniture delivery to the door", the first text is segmented, and the segmented words are mapped to the service knowledge graph. It can be determined that the service attribute of the service word "furniture" is a service entity word, the service attribute of "delivery" is a service behavior word, and the service attribute of "to the door" is a service status word. Then, the initial weights can be determined for service words with different service attributes. For example, the initial weights of service words corresponding to each service attribute are determined according to the knowledge category to which the first text belongs.
[0064] In a possible implementation manner, the way to determine the initial weights can be that when constructing the service knowledge graph, multiple training samples are used to calculate the initial weights of service words, and the service knowledge graph is constructed based on the service words and their corresponding initial weights. That is, the service knowledge graph can also include the initial weights corresponding to each service word. Optionally, each service word can correspond to one or more initial weights. Further optionally, when a service word corresponds to multiple initial weights, the key service attribute can also be determined in combination with the knowledge category to which the first text belongs, and the initial weights of each service word are determined based on the key service attribute. For example, for the service word corresponding to the key service attribute, the highest weight among the corresponding one or more initial weights is taken, and for the service words corresponding to the remaining service attributes, the lowest weight among the corresponding one or more initial weights is taken. Thus, the initial weights of each service word can be determined based on the constructed service knowledge graph.
[0065] Optionally, the specific way to determine the initial weights of each service word in the second set of service words of the second text can be similar to the specific way to determine the initial weights of each service word in the first set of service words of the first text, which will not be elaborated here.
[0066] S203. Determine the target weights of each service word in the first set of service words according to the first text, the first set of service words, and the initial weights of each service word in the first set of service words, and determine the target weights of each service word in the second set of service words according to the second text, the second set of service words, and the initial weights of each service word in the second set of service words.
[0067] In a possible implementation, the specific method for determining the target weight of each service word in the first service word set can be determined according to the service attributes of each service word, and / or can be determined according to the target knowledge category to which the first text belongs, and / or can be determined based on a model algorithm, and / or, and / or, can be set / adjusted according to empirical values, etc.
[0068] In a possible implementation, after the terminal determines the initial weight, it can further adjust the initial weight according to the service attributes corresponding to each service word to obtain the target weight of each service word in the first service word set. For example, service words with different service attributes have different impacts on the first text. If the impact of service entity words is greater, the initial weight of the service word with the service attribute of service entity word can be increased, such as multiplying by a first weighting coefficient.
[0069] In a possible implementation, after the terminal determines the initial weight, it can determine the key service attributes of the target knowledge category according to the target knowledge category to which the first text belongs, and perform weighted processing on the initial weight of the key service attributes to determine the target weight of each service word. For example, under the target knowledge category, if the impact of service behavior words is greater, the initial weight of the service word with the service attribute of service behavior word can be increased, such as multiplying by a second weighting coefficient.
[0070] In a possible implementation, the method for determining the target weight can also be obtained through a model. For example, use an attention model such as the attention attention model to determine the weighting coefficient corresponding to the initial weight of each service word in the first service word set, and perform weighting on the initial weight of each service word according to the weighting coefficient to obtain the target weight of each service word.
[0071] Optionally, the specific method for determining the target weight of each service word in the second service word set of the second text can be similar to the specific method for determining the target weight of each service word in the first service word set of the first text, and will not be elaborated here.
[0072] S204. Obtain the correlation information of the first text and the second text according to the first service word set, the target weights of each service word in the first service word set, the second service word set, and the target weights of each service word in the second service word set.
[0073] Among them, the correlation information of the first text and the second text can be used to characterize or indicate the correlation between the first text and the second text. For example, the correlation information can be the correlation score of the first text and the second text, or can also include the correlation rating of the first text and the second text, or can also include the correlation level of the first text and the second text, such as level one, level two or level three, or strong correlation, medium correlation, weak correlation, etc., which is not limited here.
[0074] In a possible implementation, if the target weight is a numerical value, for example, the first service word set can be regarded as a vector, where each component corresponds to a service word, and the component value is the target weight value of the service word. Optionally, a vector can also be constructed according to the service attributes of the service words, where each component corresponds to a service attribute, and the component value is the target weight of the service word corresponding to the service attribute. When there are multiple service words for a service attribute, the average target weight can be taken as the component value. Also, if there is no corresponding service word for a service attribute, the component value is 0. For example, the first service word set is "fast", "air conditioner", "clean", and their target weights are 1, 6.2, and 7 respectively. The vector constructed according to the service attributes is [service entity word, service behavior word, service status word, service compound word, service entity brand word]. Therefore, the vector of the first service word set is [6.2, 7, 1, 0, 0].
[0075] In a possible implementation, if the target weight is a vector, the target weights of the service words in the first service word set can be summed to obtain the vector of the first service word set.
[0076] Optionally, the specific method for determining the vector of the second service word set of the second text can be similar to the specific method for determining the vector of the first service word set of the first text, which will not be elaborated here.
[0077] In a possible implementation, the correlation information between the first text and the second text can be obtained based on the vectors of the first service word set and the second service word set. For example, the cosine theorem can be used to calculate the two vectors to obtain the correlation score between the first text and the second text. The closer the two vectors are, the higher the correlation score between the two texts.
[0078] In a possible implementation, the way to obtain the correlation information can also be through a model. For example, using a text matching model such as the CONV-KNRM model and based on the target weights of the service words in the first service word set and the target weights of the service words in the second service word set to obtain the correlation score between the first text and the second text, and the correlation information between the first text and the second text can be obtained according to the correlation score.
[0079] In a possible implementation, the relevance information between the first text and the second text is a relevance score. When determining the relevance score, it may include: obtaining the relevance score between the first text and the second text, and obtaining the relevance score corresponding to the relevance score according to the preset relevance score standard. Among them, the preset relevance score standard may include the correspondence between the relevance score between texts and the relevance score. For example, the preset relevance score standard may be: when the relevance score is a - b, the relevance score is 10; when the relevance score is b - c, the relevance score is 9, and so on, which will not be elaborated here. Then, when the relevance score between the first text and the second text is a score between a - b, querying the preset relevance score standard, it can be obtained that the relevance score between the first text and the second text is 10.
[0080] In a possible implementation, when the relevance information between the first text and the second text is a relevance level, it may include: obtaining the relevance score between the first text and the second text, and obtaining the relevance level corresponding to the relevance score according to the preset relevance level standard. Among them, the preset relevance score standard may include the correspondence between the relevance score between texts and the relevance level. For example, the preset relevance score standard may be: when the relevance score is a - b, the relevance level is weakly relevant; when the relevance score is b - c, the relevance level is moderately relevant; when the relevance score is c - d, the relevance level is strongly relevant, and so on, which will not be elaborated here. Then, when the relevance score between the first text and the second text is a score between a - b, querying the preset relevance level, it can be obtained that the relevance level between the first text and the second text is weakly relevant.
[0081] In a possible implementation, after determining the relevance information between the first text and the second text, the relevance information, the content of the first text and the second text can be stored, and it can be stored in the memory of an electronic device such as a terminal, or it can be stored in the cloud, or it can be stored in the blockchain, which is not limited here. When the user requests to determine the relevance information between the first text and the second text again, directly retrieve the previous service relevance result. In an actual application scenario, the user inputs a service search text, and through this method, the content with similar text relevance information is found and displayed. When the user inputs the same service search text again, directly retrieve the previous search result and display it.
[0082] In the embodiments of the present application, the terminal can obtain the first service word set corresponding to the first text in the service knowledge graph, and the second service word set corresponding to the second text in the service knowledge graph, and determine the initial weights of the service words in the first service word set and the initial weights of the service words in the second service word set, and then determine the target weights of the service words in the first service word set and the target weights of the service words in the second service word set, and obtain the correlation information between the first text and the second text according to the first service word set, the target weights of the service words in the first service word set, the second service word set, and the target weights of the service words in the second service word set. By implementing the above method, the accuracy of service relevance determination can be improved, and the situation where the determined text relevance does not match the actual service relevance can be effectively reduced.
[0083] Figure 3 A method for constructing a service knowledge graph proposed in the embodiments of the present application can be executed by the above-mentioned electronic device, and the description here will be illustrated by taking a terminal as an example. As Figure 3 shown, the process of the method for constructing a service knowledge graph in this embodiment may include:
[0084] S301. Obtain a plurality of training samples, and perform word segmentation processing on the plurality of training samples to obtain the service words of each training sample.
[0085] It can be understood that in the present application, the service word can also be called word segmentation, word, or other names, which are not limited in the present application.
[0086] In a possible implementation manner, the plurality of training samples can be obtained from each existing database or from a database established by the user himself, which is not limited here. Performing word segmentation processing on the plurality of training samples can obtain a plurality of word segments, and extracting the obtained word segments can obtain a plurality of service words. For example, a plurality of service words can be extracted by removing stop words in the plurality of word segments, removing incorrect word segments, etc., which is not limited here.
[0087] S302. Respectively determine the knowledge category to which each training sample belongs, and the service attributes of the service words of each training sample.
[0088] Optionally, the knowledge category may refer to the field to which the training sample belongs, such as different knowledge categories such as housekeeping, transportation, repair, and catering. By dividing the knowledge categories of the training samples, the service judgment of the text can be made more accurate. For example, the service word "apple" may refer to a kind of fruit or a brand of an electronic device, and the two belong to different knowledge categories.
[0089] Optionally, the service attributes of service words can include multiple types, such as service entity words, service behavior words, service status words, service compound words, service (entity) brand words, etc., which are not limited here. For example, for the training sample text of "Home cleaning of A air conditioner", it can be determined that the service attribute of service word "A" is service entity brand word, the service attribute of "air conditioner" is service entity word, the service attribute of "home" is service status word, and the service attribute of "cleaning" is service behavior word.
[0090] S303. Construct a service knowledge graph according to the knowledge categories to which the training samples belong, the service words of the training samples, and the service attributes of the service words.
[0091] In a possible implementation manner, constructing a service knowledge graph according to the knowledge categories to which the training samples belong, the service words of the training samples, and the service attributes of the service words can specifically be, according to the knowledge category system to which the training samples belong, taking the service words and the service attributes of the service words under the same knowledge category system as one piece of knowledge. There are certain relationships between each piece of knowledge. Mine the knowledge associations and connect them through these relationships to form a service knowledge graph. For example, the relationship between the service word "air conditioner" and "electrical appliance" is a hyponymy relationship (superior-inferior relationship), and the relationship between the service word "air conditioner" and "home" is that home is a state of the air conditioner. As Figure 4 shown, it is a schematic diagram of a service knowledge graph provided by an embodiment of the present application.
[0092] Optionally, in a possible implementation manner, the construction of the service knowledge graph can also be not associated with the category system, that is, construct the service knowledge graph only according to the service words of the training samples and the service attributes of the service words.
[0093] In a possible implementation manner, after constructing the service knowledge graph, a service attribute mapping table can be established to determine the service attributes of the service words. Specifically, in order to make the determination of the service attributes of the service words closer to the actual scenario, a service attribute mapping table can also be established. The service attribute mapping table can include each service word and the service attribute corresponding to each service word. Further, the service attribute mapping table records at least one service attribute that may exist for the same service word in different scenarios. For example, the service word "service word 1" may be a service compound word or a service status word, and the service attribute in the corresponding scenario can be queried according to the service attribute mapping table.
[0094] In the embodiments of the present application, the terminal obtains a plurality of training samples, performs word segmentation processing on the plurality of training samples to obtain service words of each training sample, respectively determines the knowledge categories to which each training sample belongs, and the service attributes of each service word of each training sample, and constructs a service knowledge graph according to the knowledge categories to which each training sample belongs, the service words of each training sample, and the service attributes of each service word. By implementing the above method, a service knowledge graph specifically for service search can be constructed, which can be used as prior information when determining service search relevance, so as to achieve more accurate text relevance matching.
[0095] Figure 5 A method for determining text relevance proposed in the embodiments of the present application can be executed by the above-mentioned electronic device, and the description here will be illustrated by taking the terminal as an example. As Figure 3 shown, the process of the method for determining text relevance in this embodiment may include:
[0096] S501. Obtain a first set of service words corresponding to the first text in the service knowledge graph, and a second set of service words corresponding to the second text in the service knowledge graph.
[0097] Among them, the specific implementation manner of step S501 can refer to the relevant description of step S201 in the above embodiment, which will not be elaborated here.
[0098] S502. Use a language representation model to determine the initial weights of each service word in the first set of service words according to the first text and the first set of service words, and use the language representation model to determine the initial weights of each service word in the second set of service words according to the second text and the second set of service words.
[0099] In a possible implementation manner, the specific method for determining the initial weights of each service word in the first set of service words may be that the terminal uses a language representation model such as the K-BERT model to identify the connection relationship between the service words included in the first text and the service words in the associated service word set in the service knowledge graph, and inserts each service word in the associated service word set into the corresponding position of the first text based on this connection relationship to obtain a first text connection tree, uses soft position encoding to record the positions of each service word in the first text connection tree to obtain a visibility matrix of each service word, and calculates the initial weights of each service word in the first set of service words based on the visibility matrix of each service word. Among them, the visibility matrix indicates whether a service word and other service words in the corresponding visibility matrix are visible, that is, whether they are relevant.
[0100] Optionally, the way to record the positions of each service word in the first text connection tree using soft position encoding can be as follows: First, sequentially number the service words included in the first text in the first text connection tree, and then sequentially number the service words connected to the service word based on this number. Among them, the numbering method can be to number the entire service word or each character of the service word. For example, in the first text connection tree, the service words included in the first text are "fast", "air conditioner", and "clean", which are numbered "1", "2", and "3" respectively. And the service word "air conditioner" is connected to the service word "household appliance", then based on the number "2" of "air conditioner", "household appliance" is numbered "3". And the service word "clean" is connected to the service word "cleaning", then based on the number "3" of "clean", "cleaning" is numbered "4", as Figure 6a shown.
[0101] In a possible implementation manner, the specific way to calculate the initial weight of a target service word among each service word based on the visibility matrix of each service word can be: Determine the service words that are irrelevant to the target service word, and mask the irrelevant service words, and use the service words that are relevant to the target service word as the visible service words of the visibility matrix corresponding to the target service word, and determine the initial weight of the target service word based on the target service word and the visible service words of the corresponding visibility matrix.
[0102] Optionally, the way to determine the service words that are relevant or irrelevant to the target service word can be: If the target service word is a service word included in the first text, the relevant service words are the service words included in the first text and the associated service words connected to the target service word. If the target service word is a service word in the associated service word set, the relevant service words are the service words connected to the target service word and itself. Optionally, the visible service words of the target service word can be marked at the corresponding positions in its visibility matrix (such as marked in red or recorded as 1), and the invisible service words can be marked at the corresponding positions in its visibility matrix (such as marked in blue or recorded as 0). The marking method of the visibility matrix is not limited here. For example, in Figure 6a the first text connection tree shown, if the target service word is "air conditioner", the visible service words are "fast", "air conditioner", "clean", "household appliance", and the invisible service word is "cleaning". If the target service word is "household appliance", the visible service words are "air conditioner", "household appliance", and the invisible service words are "fast", "clean", "cleaning", and the corresponding visibility matrix is as Figure 6b shown.
[0103] Optionally, the specific method for determining the initial weight of the target service word based on the target service word and the visible service words in the corresponding visible matrix can be to use the self-attention mechanism, that is, according to the visible matrix of the target service word, perform word vectorization processing on the visible service words of the target service word to obtain the word vector of the target service word and the word vectors of the visible service words, multiply the word vector of the target service word by the word vectors of the visible service words respectively, and normalize the product of the word vectors. Take the normalized product of the word vectors as the weighted coefficient corresponding to the visible service word, and perform weighted summation on the word vectors of the visible service words to obtain the initial weight of the target service word. Further optionally, after obtaining the weighted coefficient, the weighted coefficient can be further adjusted according to the service attribute corresponding to the visible service word and / or the target knowledge category to which the text belongs. For example, if the service word with the service attribute of service entity word has a greater impact on the correlation value between the first text and the second text, then increase the proportion of the weighted coefficient of the visible service word with the service attribute of service entity word. Another example is that under the target knowledge category, the service word behavior word has a greater impact, then increase the proportion of the weighted coefficient of the visible service word with the service attribute of service behavior word. Another example is that for visible service words with the same service attribute, the proportion of the weighted coefficient of the service word included in the first text among the visible service words with the same service attribute can be increased relative to the weighted coefficient of the service word in the associated service word set.
[0104] For example, as Figure 6a shown, if the target service word is "air conditioner", the visible service words are "fast", "air conditioner", "clean", "home appliance", and the service attribute of service entity word has the greatest impact, followed by service behavior word, and service status word has the least impact. After performing word vector processing on the visible service words, the word vectors obtained are [1, 1, 2], [1, 2, 3], [5, 1, 2], [1, 1, 6] respectively. Multiply the target service word by the visible service words respectively to obtain the word vector products 9, 14, 13, 21 respectively, and normalize the similarity to obtain the weighted coefficients of the visible service words 0.158, 0.246, 0.228, 0.368 respectively. Since "air conditioner" and "home appliance" among the visible service words are service entity words, and "air conditioner" is the service word included in the first text, "home appliance" is the service word in the associated service word set, "clean" is the service behavior word, and "fast" is the service status word, the weighted coefficients adjusted based on the service attribute are 0.036, 0.39, 0.185, 0.389 respectively. Therefore, performing weighted summation on the word vectors of the visible service words to obtain the initial weight of the target service word is 0.036 * [1, 1, 2] + 0.39 * [1, 2, 3] + 0.185 * [5, 1, 2] + 0.389 * [1, 1, 6] = [1.74, 1.39, 3.761].
[0105] Optionally, the specific method for determining the initial weights of the service words in the second service word set of the second text may be the same as that of the service words in the first service word set of the first text, which will not be elaborated here.
[0106] S503. Use the attention model and determine the target weights of the service words in the first service word set according to the first text, the first service word set, and the initial weights of the service words in the first service word set. Use the attention model and determine the target weights of the service words in the second service word set according to the second text, the second service word set, and the initial weights of the service words in the second service word set.
[0107] In a possible implementation manner, the specific method for determining the target weights of the service words in the first service word set may be that the terminal uses the service words in the first service word set as the keywords (i.e., key) in the attention model, and uses the initial weights of the service words as the values corresponding to the respective keywords in the attention model (i.e., value). The terminal performs word vectorization processing on the first text and the service words in the first service word set to obtain a first word vector corresponding to the first text and second word vectors corresponding to the service words in the first service word set. Then, based on the first word vector and the respective second word vectors, the terminal determines the weighting coefficients of the keywords corresponding to the service words in the first service word set. The terminal weights the values corresponding to the respective keywords according to the weighting coefficients of the keywords corresponding to the service words in the first service word set to obtain the target weights of the service words corresponding to the respective keywords. Among them, the attention model may be an attention attention model.
[0108] Optionally, the word vectorization processing may be to pre - establish a dictionary that stores the correspondence between word vectors and service words. If the semantics of the service words in the dictionary are similar, the distances between the word vectors of the service words are also similar. Alternatively, the word2vec tool can be used to construct a word vector model and train the word vector model so that the trained word vector model can output the word vector corresponding to each service word, and the closer the distances between the word vectors corresponding to the more semantically similar service words are.
[0109] In a possible implementation, the specific method for determining the weighting coefficients of the keywords corresponding to each service word in the first service word set may be to multiply the word vector of the first text by the word vectors of each service word, and normalize the product of the word vectors. The normalized product of the word vectors is used as the weighting coefficient of the corresponding visible service word. Further optionally, after obtaining the weighting coefficients, the weighting coefficients can be further adjusted according to the service attributes of each service word and / or the target knowledge graph to which the first text belongs. For example, if a service word with a service attribute of a service entity word has a greater impact on the first text, the proportion of the weighting coefficient of the visible service word with a service attribute of a service entity word is increased. For another example, under the target knowledge category, if a service word of a service behavior word has a greater impact, the proportion of the weighting coefficient of the service word with a service attribute of a service behavior word is increased. For yet another example, for service words with the same service attribute, the proportion of the weighting coefficient of the service word included in the first text among the service words with the same service attribute can be increased relative to the weighting coefficient of the service word in the associated service word set.
[0110] For example, the first text is "Fast air conditioner cleaning", and the word vector obtained after word vector processing is [1, 3, 2]. The service words in the first service word set are "fast", "air conditioner", "cleaning", "household appliances", "clean", and are keywords in the attention model. The word vectors obtained after word vector processing are [1, 1, 2], [1, 2, 3], [5, 1, 2], [1, 1, 6], [1, 2, 1] respectively. The initial weights of each service word in the first service word set are [3, 3.5, 4], [1, 2.5, 3.6], [5, 3.5, 2.4], [1, 2, 1.2], [3, 2, 3.2] respectively, and are the values corresponding to the keywords. And the service attribute of the service entity word has the greatest impact, followed by the service behavior word, and the service status word has the least impact. Multiply the word vector of the first text by the word vectors of each service word in the first service word set respectively to obtain the word vector products of 8, 13, 12, 16, 9. Normalize the word vector products to obtain the weighting coefficients of each service word, which are 0.138, 0.224, 0.207, 0.276, 0.155 respectively. Optionally, the weighting coefficients can also be adjusted based on the service attributes of each service word, that is, 0.034, 0.364, 0.203, 0.298, 0.101 respectively. Therefore, using the adjusted weighting coefficients to weight the initial weights of each service word, the target weights of each service word are [0.102, 0.0.119, 0.136], [0.364, 0.91, 1.3104], [1.015, 0.7105, 0.4872], [0.298, 0.596, 0.3576], [0.303, 0.202, 0.3232] respectively.
[0111] S504. Use a text matching model and obtain the relevance information between the first text and the second text according to the first service word set, the target weights of each service word in the first service word set, the second service word set, and the target weights of each service word in the second service word set.
[0112] Among them, the target weight can be the target word vector of the service word.
[0113] In a possible implementation manner, the specific way to obtain the relevance information between the first text and the second text can be that the terminal uses a text matching model and obtains at least two vector matrices according to the target word vectors of each service word in the first service word set and the target word vectors of each service word in the second service word set, respectively match the at least two vector matrices pairwise to obtain at least one matching matrix, process the at least one matching matrix to obtain at least one feature vector, obtain the target feature vector according to the at least one feature vector, and obtain the relevance information between the first text and the second text based on the target feature vector. Among them, the text matching model can be the CONV-KNRM model. Since this model is suitable for relevance matching of weighted phrases, the target weight of the service word can be used as the target word vector, and the relevance information of the two texts can be obtained based on the target weight. Among them, two vector matrices are matched to obtain a matching matrix, and one matching matrix is processed to obtain one feature vector.
[0114] In a possible implementation manner, a first vector matrix can be constructed according to the target word vectors of each service word in the first service word set, and a second vector matrix can be constructed according to the target word vectors of each service word in the second service word set, thereby obtaining at least two vector matrices. Optionally, a convolutional neural network (CNN) can be used to combine the target word vectors of each service word in the first service word set and the target word vectors of each service word in the second service word set respectively to obtain N-gram word vector information, and multiple new N-gram matching matrices can be obtained according to the multiple N-gram word vector information, so as to expand the target feature vector finally used for matching. For example, use CNN to perform convolution on the target word vectors of every two service words in the first service word set to obtain multiple first convolutional word vectors, and construct a third vector matrix according to the multiple first convolutional word vectors, and use CNN to perform convolution on the target word vectors of every two service words in the second service word set to obtain multiple second convolutional word vectors, and construct a fourth vector matrix according to the multiple second convolutional word vectors.
[0115] In a possible implementation, the specific way to match two vector matrices to obtain a matching matrix can be as follows. For two vector matrices, such as the first vector matrix and the second vector matrix, the cosine function is used to calculate the values of each target word vector in the first vector matrix and each target word vector in the second vector matrix, and then the obtained values are filled into the corresponding positions in the matching matrix, thereby obtaining a matching matrix. For example, if we want to calculate the value of M12 in the matching matrix of the first vector matrix and the second vector matrix, we use the cosine function to calculate the value of the first target word vector in the first vector matrix and the second target word vector in the second vector matrix.
[0116] Optionally, when there are more than two vector matrices, pairwise matching of the vector matrices is required. It should be noted that it is only necessary to match the vector matrix directly or indirectly constructed from the first service word set with the vector matrix directly or indirectly constructed from the second service word set. For example, the first vector matrix mentioned above is directly constructed from the first service word set, the third vector matrix is indirectly constructed from the first service word set, the second vector matrix is directly constructed from the second service word set, and the fourth vector matrix is indirectly constructed from the second service word set. Therefore, the first matrix and the second matrix, the first matrix and the fourth matrix, the third matrix and the second matrix, and the third matrix and the fourth matrix are matched to obtain four matching matrices.
[0117] In a possible implementation, the specific way to process a matching matrix to obtain a feature vector can be as follows. Gaussian kernel transformation is performed on each row of the matching matrix. After Gaussian kernel transformation is performed on each row, an intermediate vector is obtained, and multiple intermediate vectors form an intermediate matrix. Then, the logarithm of each row of the intermediate matrix is taken and summed to obtain the feature vector corresponding to the matching matrix. For example, the radial basis function kernel (RBF Kernel) in the CONV-KNRM model is used to perform Gaussian kernel transformation on each row of the matching matrix, and the elements in the obtained vector represent the values of different Kernel transformations. Multiple vectors form the intermediate matrix in the Kernel pooling layer of the CONV-KNRM model.
[0118] Optionally, when there is only one matching matrix, that is, when a feature vector is obtained, this feature vector is the target feature vector. When there are more than one matching matrix, that is, when multiple feature vectors are obtained, these multiple feature vectors are concatenated to obtain the target feature vector.
[0119] In a possible implementation, the specific way to obtain the relevance information between the first text and the second text based on the target feature vector can be to use the target feature vector as the input of the fully connected layer in the text matching model, so as to output the relevance between the two texts. For example, through the fully connected layer of the CONV-KNRM model, the relevance scores of the first text and the second text are input.
[0120] The following takes applying the text relevance determination method proposed in the embodiments of the present application to a service search-related client or model as an example to elaborate on this relevance determination method. For example, a matching model based on graph reasoning can well integrate the information of the knowledge graph model and the semantic matching model, so as to achieve better results when calculating the service search relevance. Among them, the knowledge graph is a service search knowledge graph specifically constructed for the service search application scenario. When the user inputs the service search text "quick air conditioner cleaning", an electronic device such as a terminal can determine the service relevance between this service search text and all texts in the database based on the relevance determination method of the present application, and extract the texts with relatively strong relevance to the service search text for display. Here, taking the database text "A home appliance cleaning" as an example, the service relevance information between "quick air conditioner cleaning" and "A home appliance cleaning" is determined. Specifically, the service search text and the database text can be segmented, and the knowledge categories of the service knowledge graph to which the two texts belong can be determined respectively. Here, it can be determined that the two texts can belong to the knowledge category of housekeeping. Then, in the service knowledge graph, the service words corresponding to each segmentation of the two texts are determined. The service words of "quick air conditioner cleaning" can include: quick, air conditioner, cleaning, and the service words of "A home appliance cleaning" can include: A, home appliance, cleaning; according to the service attributes corresponding to the service words in the service knowledge graph, the service entity word of the service search text is determined to be air conditioner, the service behavior word is cleaning, the service status word is quick, the service entity word of the database text is home appliance, the service behavior word is cleaning, and the service entity brand word is A. Please refer to Figure 7 , Figure 7 FIG. shows a schematic diagram of the effect of determining service words and service attributes of the segmentations of the two texts in the knowledge graph.
[0121] The terminal can obtain the service word sets of the two texts according to the service knowledge graph, and input the two texts and the service word sets of the two texts into the graph reasoning-based matching model obtained by the text relevance determination method of the present application, such as Figure 8a shown, where Figure 8a The [CLS] and [SEP] in are special delimiters used to classify the model and separate sentences respectively (that is, to disconnect the user input service search text, the service word set of the service search text from the database text and the service word set of the database text), and Figure 8a The specific model involved is only one of the solutions that can implement the embodiments of the present application, and does not limit the embodiments of the present application.
[0122] Next, taking the user input service search text "quick air conditioner cleaning" and the service word set of the service search text "quick, air conditioner, cleaning, household appliances, cleaning" as an example for description, the related operations of the database text and the service word set of the database text are the same as those of the first text and the first service word set. The terminal inputs the user input service search text and the service word set of the service search text into the K-BERT model. The K-BERT model identifies the connection relationship of the service words in the user input service search text and the service word set according to the service knowledge graph, generates a text connection tree based on the connection relationship, and uses soft position encoding to record the text connection tree structure information, such as Figure 8b shown, where Figure 8b numbers each character of the service word. After determining the relevant service words and irrelevant service words of each service word according to the text connection tree, a visible matrix is constructed based on the numbered text connection tree. The visible matrix is used to mask the irrelevant service words to eliminate the influence of the irrelevant service words in the process of determining the initial weight, so that in the process of determining the initial weight, the irrelevant service words do not affect each other. For example, the knowledge graph entities linked by different service words of the first text do not affect each other. As Figure 8c shown, it shows the visible service words and invisible service words of the service word "household appliances", where Figure 8c only shows two of the layers of the visible matrix. The actual number of layers of the visible matrix is determined according to the number of service words in the service word set. Each service word in the service word set determines the initial weight of each service word based on the corresponding visible matrix. The terminal inputs the user input service search text and the service word set of the service search text with the initial weight into the attention attention model, as Figure 8d shown. The attention attention model consists of three parts: Q, K, and V. Q is the word vector of the user input service search text, K is the word vector of each service word in the service word set, and V is the initial weight of each service word in the service word set. Calculate the word vector product of Q and K through a vector product function (such as MatMul), and then normalize the word vector product through a normalization function (such as Softmax) to obtain a weighting coefficient. Finally, weight V through MatMul to obtain the target weight of each service word. Among them, the target weight of each service word is the target word vector of each service word.
[0123] Another example is taking the user input service search text "traffic accident truck insurance" and the service word set of the service search text as "traffic accident, traffic violation, truck, freight truck, insurance, social insurance, vehicle insurance". The terminal inputs the user input service search text and the service word set of the service search text into the K-BERT model, obtains a text connection tree, and uses soft position encoding to record the text connection tree structure information, such as Figure 8eAs shown. A visible matrix can be constructed based on the numbered text connection tree, and this visible matrix is used to mask irrelevant service words to eliminate the influence of irrelevant service words in the process of determining the initial weight. For example Figure 8f As shown, it shows the visible service words and invisible service words of the service word "traffic violation". The terminal inputs the service word set of the user input service search text and the service search text with the initial weight into the attention attention model, as Figure 8g As shown, the attention attention model consists of three parts: Q, K, and V. Among them, Q is the average of the BERT token embeddings of the entire original text sentence, that is, it is converted into a vector form using the BERT model. K and V are various knowledges. That is, K is the average of the BERT token embeddings of the service words, and V is the initial weight of each service word in the service word set. Through this model, the target weight of each service word is output. Among them, the target weight of each service word is the target word vector of each service word. Using the attention attention model can solve the problem of "knowledge deviating from the original semantics" and make the text focus on service words with similar semantics.
[0124] After the terminal obtains the target weights of the service word set of the user input service search text and the service word set of the database text, it inputs the user input service search text, the service word set of the service search text with the target weight, the database text, and the service word set of the database text with the target weight into the CONV-KNRM model, as Figure 8h As shown, the service word set of the service search text with the target weight (i.e., the target word vector), and the service word set of the database text with the target weight (i.e., the target word vector) obtain at least two vector matrices through the convolutional layer, and then at least two vector matrices obtain at least one matching matrix through the interactive matching layer. The at least one matching matrix obtains at least one feature target quantity through the Gaussian kernel pooling layer (i.e., the Kernel pooling layer), thereby obtaining the target feature vector, and obtaining the correlation information between the two texts such as the correlation score based on the target feature vector. Optionally, the target feature vector can be input into the fully connected layer to obtain the correlation score.
[0125] Figure 8i The following are the evaluation index results obtained from a large number of tests on the matching model based on graph reasoning. For example Figure 8i As shown, it shows that through the embodiments of the present application, both the accuracy and the recall rate have been improved to a certain extent.
[0126] Optionally, the relevance information between two texts can be obtained through the relevance scores of the two texts. Further optionally, the present application can respectively determine the relevance information between the first text and multiple second texts, and then perform result pushing or display according to the relevance information between the first text and each second text. For example, the second texts whose relevance information does not meet the conditions can be filtered out, and the remaining second texts can be pushed or displayed. That the relevance information does not meet the conditions may mean that the relevance level is lower than a preset level, the relevance score is lower than a preset score, the relevance does not belong to the top N (N>0, such as N=10) after sorting by relevance from high to low, etc., which are not listed one by one here. This is to screen out irrelevant or low-relevance second texts and improve the reliability of the finally obtained second texts, such as service search results.
[0127] In the embodiments of the present application, the terminal obtains the first service word set corresponding to the first text in the service knowledge graph, and the second service word set corresponding to the second text in the service knowledge graph, uses a language representation model to determine the initial weights of the service words in the first service word set and the initial weights of the service words in the second service word set, uses an attention model to determine the target weights of the service words in the first service word set and the target weights of the service words in the second service word set, and uses a text matching model and according to the first service word set, the target weights of the service words in the first service word set, the second service word set, and the target weights of the service words in the second service word set, to obtain the relevance information between the first text and the second text. By implementing the above method, the accuracy of service relevance determination can be improved to a certain extent, and the situation where the determined text relevance does not match the actual service relevance can be effectively reduced.
[0128] The following will Figure 9 introduce in detail a device for determining text relevance provided by the embodiments of the present application. It should be noted that the Figure 9 shown device for determining text relevance is used to execute the method of the embodiments of the present application Figure 2 、 Figure 3 and Figure 5 shown. For the sake of illustration, only the parts related to the embodiments of the present application are shown, and the specific technical details are not disclosed. Please refer to the embodiments of the present application Figure 2 、 Figure 3 and Figure 5 shown.
[0129] Please refer to Figure 9 , which is a schematic structural diagram of a device for determining text relevance provided by the present application. The device 900 for determining text relevance may include: an acquisition module 901, a determination module 902, and a processing module 903.
[0130] An acquisition module 901, configured to acquire a first service word set corresponding to a first text in a service knowledge graph and a second service word set corresponding to a second text in the service knowledge graph, where both the first service word set and the second service word set include at least one service word;
[0131] A determination module 902, configured to determine initial weights of each service word in the first service word set according to the first text and / or the first service word set, and determine initial weights of each service word in the second service word set according to the second text and the second service word set;
[0132] The determination module 902 is further configured to determine target weights of each service word in the first service word set according to the first text, the first service word set, and / or the initial weights of each service word in the first service word set, and determine target weights of each service word in the second service word set according to the second text, the second service word set, and / or the initial weights of each service word in the second service word set;
[0133] A processing module 903, configured to obtain correlation information between the first text and the second text according to the first service word set, the target weights of each service word in the first service word set, the second service word set, and / or the target weights of each service word in the second service word set.
[0134] In an implementation manner, the processing module 903 is specifically configured to:
[0135] Acquire a plurality of training samples, perform word segmentation processing on the plurality of training samples to obtain service words of each training sample; respectively determine knowledge categories to which the training samples belong and service attributes of the service words of the training samples; and construct the service knowledge graph according to the knowledge categories to which the training samples belong, the service words of the training samples, and the service attributes of the service words.
[0136] In an implementation manner, the acquisition module 901 is specifically configured to:
[0137] Determine the target knowledge category to which the first text belongs, and perform word segmentation on the first text to obtain the segmented words of the first text; semantically match the segmented words of the first text with the service words under the target knowledge category of the service knowledge graph to obtain the service words included in the first text; obtain the associated service word set of the service words included in the first text, where the service words in the associated service word set have a connection relationship with at least one of the service words included in the first text in the service knowledge graph, and the service words in the associated service word set are one or more of the extended words, synonyms, and hypernyms of the service words included in the first text; use the service words included in the first text and the associated service word set as the first service word set.
[0138] In one implementation, the determining module 902 is specifically configured to:
[0139] Use a language representation model to identify the connection relationship between the service words included in the first text and the service words in the associated service word set in the service knowledge graph; based on the connection relationship, insert the service words in the associated service word set into the corresponding positions of the first text to obtain a first text connection tree; use soft position encoding to record the positions of each service word in the first text connection tree to obtain the visibility matrix of each service word; determine the initial weights of each service word in the first service word set based on the visibility matrix.
[0140] In one implementation, the determining module 902 is specifically configured to:
[0141] Determine the service words that are irrelevant to the target service word, mask the irrelevant service words, and use the service words related to the target service word as the visible service words of the visibility matrix corresponding to the target service word; where the target service word is any one of each service word in the first service word set; determine the initial weight of the target service word based on the target service word and the visible service words of the corresponding visibility matrix.
[0142] In one implementation, the determining module 902 is specifically configured to:
[0143] Use each service word in the first service word set as a keyword in the attention model, and use the initial weight of each service word as the value corresponding to each keyword in the attention model; perform word vectorization processing on the first text and each service word in the first service word set to obtain a first word vector corresponding to the first text and second word vectors corresponding to each service word in the first service word set; determine the weighting coefficients of the keywords corresponding to each service word in the first service word set based on the first word vector and each of the second word vectors; weight the values corresponding to each keyword according to the weighting coefficients of the keywords corresponding to each service word in the first service word set to obtain the target weights of the service words corresponding to each keyword.
[0144] In one implementation manner, the processing module 903 is specifically configured to:
[0145] Use a text matching model and, according to the target word vectors of each service word in the first service word set and the target word vectors of each service word in the second service word set, obtain at least two vector matrices; respectively perform pairwise matching on the at least two vector matrices to obtain at least one matching matrix; process the at least one matching matrix to obtain at least one feature vector, and obtain a target feature vector according to the at least one feature vector; obtain the relevance information between the first text and the second text based on the target feature vector.
[0146] In each embodiment of the present application, each functional module may be integrated into one processing module, or each module may exist physically alone, or two or more modules may be integrated into one module. The above integrated module may be implemented in the form of hardware or in the form of a software functional module, which is not limited in the present application.
[0147] Please refer to Figure 10 , which is a schematic structural diagram of an electronic device provided by an embodiment of the present application. As Figure 10 shown, the electronic device 1000 includes: at least one processor 1001 and a memory 1002. Optionally, the electronic device may further include a network interface 1003. Among them, data can be exchanged between the processor 1001, the memory 1002, and the network interface 1003. The network interface 1003 is controlled by the processor to send and receive messages. The memory 1002 is used to store a computer program, and the computer program includes program instructions. The processor 1001 is used to execute the program instructions stored in the memory 1002. Among them, the processor 1001 is configured to call the program instructions to execute the above method.
[0148] The memory 1002 may include a volatile memory, such as a random-access memory (RAM); the memory 1002 may also include a non-volatile memory, such as a flash memory, a solid-state drive (SSD), etc.; the memory 1002 may further include a combination of the above types of memories.
[0149] The processor 1001 may be a central processing unit 1001 (CPU). In one embodiment, the processor 1001 may also be a Graphics Processing Unit (GPU). The processor 1001 may also be a combination of a CPU and a GPU.
[0150] In one embodiment, the memory 1002 is used to store program instructions. The processor 1001 may call the program instructions to perform the following steps:
[0151] Obtain a first set of service words corresponding to the first text in the service knowledge graph, and a second set of service words corresponding to the second text in the service knowledge graph, where both the first set of service words and the second set of service words include at least one service word;
[0152] Determine the initial weights of the service words in the first set of service words according to the first text and / or the first set of service words, and determine the initial weights of the service words in the second set of service words according to the second text and / or the second set of service words;
[0153] Determine the target weights of the service words in the first set of service words according to the first text, the first set of service words and / or the initial weights of the service words in the first set of service words, and determine the target weights of the service words in the second set of service words according to the second text, the second set of service words and / or the initial weights of the service words in the second set of service words;
[0154] Obtain the relevance information between the first text and the second text according to the first set of service words, the target weights of the service words in the first set of service words, the second set of service words and / or the target weights of the service words in the second set of service words.
[0155] In one embodiment, the processor 1001 may also be used to perform: obtaining a plurality of training samples, performing word segmentation processing on the plurality of training samples to obtain service words of each training sample; respectively determining knowledge categories to which the respective training samples belong, and service attributes of service words of the respective training samples; constructing the service knowledge graph according to the knowledge categories to which the respective training samples belong, the service words of the respective training samples, and the service attributes of the service words.
[0156] In one embodiment, the processor 1001 may also be used to perform: determining a target knowledge category to which the first text belongs, and performing word segmentation processing on the first text to obtain respective word segments of the first text; semantically matching the respective word segments of the first text with service words under the target knowledge category of the service knowledge graph to obtain service words included in the first text; obtaining an associated service word set of the service words included in the first text, where service words in the associated service word set have a connection relationship with at least one service word among the service words included in the first text in the service knowledge graph, and the service words in the associated service word set are one or more of extended words, synonyms, and hypernyms of the service words included in the first text; using the service words included in the first text and the associated service word set as a first service word set.
[0157] In one embodiment, the processor 1001 may also be used to perform: using a language representation model to identify connection relationships of service words included in the first text and service words in the associated service word set in the service knowledge graph; inserting service words in the associated service word set into corresponding positions of the first text based on the connection relationships to obtain a first text connection tree; using soft position encoding to record positions of each service word in the first text connection tree to obtain a visibility matrix of each service word; determining initial weights of each service word in the first service word set based on the visibility matrix.
[0158] In one embodiment, the processor 1001 may also be used to perform: determining service words irrelevant to the target service word, masking the irrelevant service words, and using service words relevant to the target service word as visible service words of the visibility matrix corresponding to the target service word; where the target service word is any one of each service word in the first service word set; determining the initial weight of the target service word based on the target service word and the visible service words of the corresponding visibility matrix.
[0159] In one implementation, the processor 1001 may further be configured to: use each service word in the first service word set as a keyword in the attention model, and use the initial weight of each service word as the value corresponding to each keyword in the attention model; perform word vectorization processing on the first text and each service word in the first service word set to obtain a first word vector corresponding to the first text and second word vectors corresponding to each service word in the first service word set; determine a weighting coefficient of the keyword corresponding to each service word in the first service word set based on the first word vector and each of the second word vectors; and weight the value corresponding to each keyword according to the weighting coefficient of the keyword corresponding to each service word in the first service word set to obtain a target weight of the service word corresponding to each keyword.
[0160] In one implementation, the processor 1001 may further be configured to: use the text matching model and, according to the target word vectors of each service word in the first service word set and the target word vectors of each service word in the second service word set, obtain at least two vector matrices; respectively perform pairwise matching on the at least two vector matrices to obtain at least one matching matrix; process the at least one matching matrix to obtain at least one feature vector, and obtain a target feature vector according to the at least one feature vector; and obtain correlation information between the first text and the second text based on the target feature vector.
[0161] In specific implementation, the apparatuses, the processor 1001, the memory 1002, etc. described in the embodiments of the present application may execute the implementation manners described in the above method embodiments, which will not be elaborated herein.
[0162] The embodiments of the present application further provide a computer (readable) storage medium. The computer storage medium stores a computer program, and the computer program includes program instructions. When the program instructions are executed by a processor, part or all of the steps executed in the above method embodiments may be executed. Optionally, the computer storage medium may be volatile or non-volatile.
[0163] As used herein, "a plurality of" means two or more. "And / or" describes the association relationship of associated objects and indicates that three relationships may exist. For example, A and / or B may represent: A exists alone, A and B exist simultaneously, and B exists alone. The character " / " generally represents an "or" relationship between the associated objects before and after.
[0164] Those of ordinary skill in the art can understand that all or part of the processes in the methods of the above embodiments can be completed by instructing relevant hardware through a computer program. The program can be stored in a computer storage medium, which can be a computer-readable storage medium. When the program is executed, it can include the processes of the embodiments of the above methods. Among them, the storage medium can be a magnetic disk, an optical disk, a read-only memory (ROM), or a random access memory (RAM), etc.
[0165] The above-disclosed are only some embodiments of the present application. Of course, the scope of rights of the present application cannot be limited thereby. Those of ordinary skill in the art can understand all or part of the processes of the above embodiments, and the equivalent changes made according to the claims of the present application still fall within the scope covered by the present application.
Claims
1. A method for determining text relevance, characterized in that Including: Obtain a first set of service words corresponding to the first text in the service knowledge graph, and a second set of service words corresponding to the second text in the service knowledge graph, where both the first set of service words and the second set of service words include at least one service word; Determine the initial weights of the service words in the first set of service words according to the first text and the first set of service words, and determine the initial weights of the service words in the second set of service words according to the second text and the second set of service words; Determine the target weights of the service words in the first set of service words according to the first text, the first set of service words, and the initial weights of the service words in the first set of service words, and determine the target weights of the service words in the second set of service words according to the second text, the second set of service words, and the initial weights of the service words in the second set of service words; wherein, the method for determining the target weights of the service words in the first set of service words is as follows: use the service words in the first set of service words as keywords in the attention model, and use the initial weights of the service words as the values corresponding to the keywords in the attention model; perform word vectorization processing on the first text and the service words in the first set of service words to obtain a first word vector corresponding to the first text and second word vectors corresponding to the service words in the first set of service words; based on the first word vector and the second word vectors, determine the weighting coefficients of the keywords corresponding to the service words in the first set of service words; according to the weighting coefficients of the keywords corresponding to the service words in the first set of service words, weight the values corresponding to the keywords to obtain the target weights of the service words corresponding to the keywords; Obtain the relevance information between the first text and the second text according to the first set of service words, the target weights of the service words in the first set of service words, the second set of service words, and the target weights of the service words in the second set of service words.
2. The method according to claim 1, wherein The method further includes: Obtain a plurality of training samples, and perform word segmentation processing on the plurality of training samples to obtain the service words of each training sample; Respectively determine the knowledge categories to which the training samples belong, and the service attributes of the service words of the training samples; Construct the service knowledge graph according to the knowledge categories to which the training samples belong, the service words of the training samples, and the service attributes of the service words.
3. The method according to claim 1, wherein The obtaining of the first set of service words corresponding to the first text in the service knowledge graph includes: Determine the target knowledge category to which the first text belongs, and perform word segmentation processing on the first text to obtain the word segments of the first text; Perform semantic matching between the word segments of the first text and the service words under the target knowledge category of the service knowledge graph to obtain the service words included in the first text; Obtain an associated service word set of the service words included in the first text, where the service words in the associated service word set are connected to at least one of the service words included in the first text in the service knowledge graph, and the service words in the associated service word set are one or more of the extended words, synonyms, and hypernyms of the service words included in the first text; Use the service words included in the first text and the associated service word set as the first service word set.
4. The method according to claim 3, wherein The determining the initial weights of the service words in the first service word set according to the first text and the first service word set includes: Use a language representation model to identify the connection relationships of the service words included in the first text and the service words in the associated service word set in the service knowledge graph; Based on the connection relationships, insert the service words in the associated service word set into the corresponding positions of the first text to obtain a first text connection tree; Use soft position encoding to record the positions of the service words in the first text connection tree to obtain the visibility matrix of each service word; Determine the initial weights of the service words in the first service word set based on the visibility matrix.
5. The method according to claim 4, characterized in that, The determining the initial weights of the service words in the first service word set based on the visibility matrix includes: Determine the service words that are irrelevant to the target service word, mask the irrelevant service words, and use the service words related to the target service word as the visible service words of the visibility matrix corresponding to the target service word; where the target service word is any one of the service words in the first service word set; Determine the initial weight of the target service word based on the target service word and the visible service words of the corresponding visibility matrix.
6. The method according to any one of claims 1 to 5, characterized in that, The target weight is a target word vector; the obtaining the relevance information between the first text and the second text according to the first service word set, the target weights of the service words in the first service word set, the second service word set, and the target weights of the service words in the second service word set includes: Use a text matching model and according to the target word vectors of the service words in the first service word set and the target word vectors of the service words in the second service word set to obtain at least two vector matrices; Match the at least two vector matrices pairwise to obtain at least one matching matrix; Process the at least one matching matrix to obtain at least one feature vector, and obtain a target feature vector according to the at least one feature vector; Obtain the relevance information between the first text and the second text based on the target feature vector.
7. An apparatus for determining text relevance, characterized in that, Includes: An obtaining module, configured to obtain a first service word set corresponding to the first text in the service knowledge graph, and a second service word set corresponding to the second text in the service knowledge graph, where both the first service word set and the second service word set include at least one service word; A determining module, configured to determine the initial weights of the service words in the first service word set according to the first text and the first service word set, and determine the initial weights of the service words in the second service word set according to the second text and the second service word set; The determining module is further configured to determine the target weights of the service words in the first service word set according to the first text, the first service word set, and the initial weights of the service words in the first service word set, and determine the target weights of the service words in the second service word set according to the second text, the second service word set, and the initial weights of the service words in the second service word set; wherein, the method for determining the target weights of the service words in the first service word set is as follows: taking the service words in the first service word set as keywords in the attention model, and taking the initial weights of the service words as the values corresponding to the respective keywords in the attention model; performing word vectorization processing on the first text and the service words in the first service word set to obtain a first word vector corresponding to the first text and second word vectors corresponding to the service words in the first service word set; determining the weighting coefficients of the keywords corresponding to the service words in the first service word set based on the first word vector and the second word vectors; weighting the values corresponding to the respective keywords according to the weighting coefficients of the keywords corresponding to the service words in the first service word set to obtain the target weights of the service words corresponding to the respective keywords. The processing module is configured to obtain the relevance information between the first text and the second text according to the first service word set, the target weights of the service words in the first service word set, the second service word set, and the target weights of the service words in the second service word set.
8. An electronic device, characterized in that, It includes a processor and a memory, and the processor is interconnected with the memory. Wherein, the memory is used to store computer program instructions, and the processor is configured to execute the program instructions to implement the method according to any one of claims 1-6.
9. A computer-readable storage medium, characterized in that, The computer-readable storage medium stores a computer program, and the computer program includes program instructions, and when the program instructions are executed by the processor, the processor is caused to execute the method according to any one of claims 1-6.
Citation Information
Patent Citations
Text matching method and device, computer system and readable storage medium
CN111539197A