Model training method, knowledge retrieval method, electronic equipment and storage medium
By integrating contextual information and knowledge entries from users' historical dialogues into a large model and adjusting parameters using a cross-attention mechanism, the inaccuracy of knowledge retrieval in human-computer dialogue by large models is solved, achieving higher relevance prediction and recall rates.
Patent Information
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2025-12-04
- Publication Date
- 2026-04-07
AI Technical Summary
Large models are prone to illusions in human-computer dialogue due to the universality of training data, resulting in incomplete and inaccurate knowledge retrieval results. Traditional knowledge retrieval techniques ignore historical and implicit intentions in multi-turn dialogues, leading to semantic breaks and recalls that deviate from the real needs.
By extracting contextual information from users' historical dialogues, user questions, contextual information, and knowledge entries are input into the model for encoding and fusion. The model uses a cross-attention mechanism to capture logical relationships, adjusts model parameters to improve relevance prediction capabilities, and fits different data distributions.
This improves the model's ability to accurately capture the contextual logic and implicit intent of user questions, thereby enhancing the accuracy and recall of knowledge retrieval and meeting users' real needs.
Smart Images

Figure CN121808003A_ABST
Abstract
Description
Technical Field
[0001] This application relates to the fields of artificial intelligence and natural language processing technology, and in particular to a model training method, a knowledge retrieval method, an electronic device, and a storage medium. Background Technology
[0002] With the widespread application of large-scale models in human-computer dialogue, they possess significant capabilities in semantic understanding, multi-turn dialogue, and personalized interaction. In some business scenarios, it is often necessary to accurately understand user needs and efficiently match knowledge from the knowledge base. While large-scale models have generalization capabilities, they are prone to "illusions" (i.e. generating responses that do not conform to business facts) due to the universality of the training data.
[0003] To suppress hallucinations, the system typically first retrieves knowledge similar to the user's question from a knowledge base, and then generates a final response based on the retrieved knowledge. It's clear that this method relies on the accuracy of knowledge retrieval, but the knowledge retrieved using traditional knowledge retrieval techniques often deviates from the actual needs, resulting in incomplete and inaccurate search results. Summary of the Invention
[0004] The purpose of this application is to provide a model training method, a knowledge retrieval method, an electronic device, and a storage medium to solve the above-mentioned technical problems.
[0005] To achieve the above objectives, the embodiments of this application adopt the following technical solutions: In a first aspect, embodiments of this application provide a model training method, including: The first user question, the first context information of the first user question, and the first knowledge item are input into the first model to obtain the predicted relevance between the first user question and the first knowledge item. The first context information is obtained from the user's historical dialogue. After encoding the first user question, the first context information, and the first knowledge item, the first model fuses the encoded vector of the first user question and the encoded vector of the first context information to obtain a first fusion vector. The predicted relevance is obtained by performing relevance prediction based on the first fusion vector and the encoded vector of the first knowledge item. Based on the predicted relevance and the reference relevance between the first user question and the first knowledge item, the parameters of the first model are adjusted.
[0006] The model training method provided in this application can, on the one hand, improve the first model's ability to accurately capture the contextual logic and implicit intent of user questions and its ability to predict relevance; on the other hand, enable the first model to better fit the different data distributions between user questions, contextual information and knowledge items, thereby improving the generalization and upper limit of the prediction effect of the first model.
[0007] Secondly, embodiments of this application provide a knowledge retrieval method, including: In response to a second user question entered by the user during a conversation, second contextual information of the second user question is obtained from the user's historical conversations. The second user question, the second context information, and the knowledge entries in the knowledge base are input into the first model to obtain the predicted relevance between the second user question and the knowledge entries; after encoding the second user question, the second context information, and the knowledge entries, the first model fuses the encoded vector of the second user question and the encoded vector of the second context information to obtain a first fusion vector, and performs relevance prediction based on the first fusion vector and the encoded vector of the knowledge entries to obtain the predicted relevance; Based on the predicted relevance, at least one second knowledge entry is recalled from the knowledge base to respond to the second user's question.
[0008] The knowledge retrieval method provided in this application enables the first model to better fit the different data distributions among the second user question, the second context information, and the knowledge items, and to accurately understand the logical relationship between the second user question and the second context information, and to accurately capture the implicit intent of the second user question from the logical relationship, thereby more accurately predicting the relevance between the second user question and the knowledge items; finally, based on the relevance, knowledge items can be recalled in the knowledge base, which can improve the accuracy and recall rate of knowledge retrieval.
[0009] Thirdly, embodiments of this application provide a model training apparatus, comprising: The first input module is used to input a user's first user question, the first context information of the first user question, and the first knowledge item into a first model to obtain the predicted relevance between the first user question and the first knowledge item; wherein, the first context information is obtained from the user's historical dialogue, the first model encodes the first user question, the first context information, and the first knowledge item, fuses the encoded vector of the first user question and the encoded vector of the first context information to obtain a first fusion vector, and performs relevance prediction based on the first fusion vector and the encoded vector of the first knowledge item to obtain the predicted relevance. The adjustment module is used to adjust the parameters of the first model based on the predicted relevance and the reference relevance between the first user question and the first knowledge item.
[0010] Fourthly, embodiments of this application provide a knowledge retrieval device, including: The acquisition module is used to acquire second contextual information of the second user question from the user's historical dialogue in response to the second user question entered by the user during the dialogue. The second input module is used to input the second user question, the second context information, and the knowledge entries in the knowledge base into the first model to obtain the predicted relevance between the second user question and the knowledge entries; after encoding the second user question, the second context information, and the knowledge entries, the first model fuses the encoded vector of the second user question and the encoded vector of the first context information to obtain a first fusion vector, and performs relevance prediction based on the first fusion vector and the encoded vector of the knowledge entries to obtain the predicted relevance. The recall module is used to recall at least one second knowledge entry from the knowledge base to respond to the second user's question, based on the predicted relevance.
[0011] Fifthly, embodiments of this application provide an electronic device, including: processor; Memory used to store the processor's executable instructions; The processor is configured to execute the instructions to implement the model training method provided in the first aspect or the knowledge retrieval method provided in the second aspect.
[0012] In a sixth aspect, embodiments of this application provide a computer-readable storage medium, wherein when instructions in the storage medium are executed by a processor of an electronic device, the electronic device is able to perform a model training method as provided in the first aspect or a knowledge retrieval method as provided in the second aspect. Attached Figure Description
[0013] The accompanying drawings, which are included to provide a further understanding of this application and form part of this application, illustrate exemplary embodiments and are used to explain this application, but do not constitute an undue limitation of this application. In the drawings: Figure 1 This is a schematic diagram of an example environment in which embodiments of this application can be implemented; Figure 2 A schematic flowchart illustrating a model training method provided in an embodiment of this application; Figure 3 This is a schematic diagram of the structure of a first model provided in an embodiment of this application; Figure 4 A flowchart illustrating a knowledge retrieval method provided in an embodiment of this application; Figure 5 This is a schematic diagram of the structure of a model training device provided in an embodiment of this application; Figure 6This is a schematic diagram of the structure of a knowledge retrieval device provided in an embodiment of this application; Figure 7 This is a schematic diagram of the structure of an electronic device provided in an embodiment of this application. Detailed Implementation
[0014] To make the objectives, technical solutions, and advantages of this application clearer, the technical solutions of this application will be clearly and completely described below in conjunction with specific embodiments and corresponding drawings. Obviously, the described embodiments are only a part of the embodiments of this application, and not all of them. Based on the embodiments in this application, all other embodiments obtained by those skilled in the art without creative effort are within the scope of protection of this application.
[0015] The term "comprising" and its variations as used in this document are open-ended, meaning "including but not limited to". The term "based on" means "at least partially based on". The term "one embodiment" means "at least one embodiment"; the term "another embodiment" means "at least one additional embodiment"; the term "some embodiments" means "at least some embodiments". Definitions of other terms will be given in the following description. The term "in response to" indicates that the performed operation depends on a condition or state. When the dependent condition or state is met, one or more operations may be performed in real time or with a set delay. Unless otherwise specified, there is no restriction on the order in which multiple operations are performed.
[0016] It should be noted that the concepts of "first" and "second" mentioned in this document are used only to distinguish different devices, modules or units, and are not used to restrict the order of functions performed by these devices, modules or units or their interdependencies.
[0017] It should be noted that the terms "one" and "more" used in this document are illustrative rather than restrictive, and those skilled in the art should understand that, unless explicitly stated otherwise in the context, they should be understood as "one or more".
[0018] The names of messages or information exchanged between multiple devices in the embodiments of this document are for illustrative purposes only and are not intended to limit the scope of these messages or information.
[0019] As mentioned earlier, the knowledge retrieved based on traditional knowledge retrieval techniques often deviates from the actual needs, resulting in incomplete and inaccurate search results.
[0020] Through extensive research, the inventors discovered that the main reasons why retrieved knowledge deviates from actual needs in traditional knowledge retrieval technologies include: First, traditional knowledge retrieval techniques encode the user's current question as a static vector, ignoring the historical intent accumulated over multiple rounds of dialogue (such as the contextual logic of successive questions). When the user's current question depends on previous dialogues, independent encoding leads to semantic breaks and misses key knowledge.
[0021] Second, user questions often imply unspoken needs, but traditional knowledge retrieval technologies rely solely on the literal similarity between the user's current question and the knowledge provided, failing to connect to the implicit intent within the business context. This is because general encoding technologies are not optimized for the distribution of business knowledge and lack sufficient semantic differentiation between synonyms and domain-specific terms.
[0022] In view of this, this application proposes a model training method. First contextual information of a user's first question is obtained from the user's historical dialogue. The first user question, first contextual information, and first knowledge item are input into a first model. After encoding the first user question, first contextual information, and first knowledge item, the first model fuses the encoded vector of the first user question and the encoded vector of the first contextual information to obtain a first fusion vector. This first fusion vector contains the logical relationship between the first user question and the first contextual information, effectively avoiding semantic breaks caused by independent encoding. Based on the first fusion vector and the encoded vector of the first knowledge item, the first model performs relevance prediction, accurately capturing the implicit intent of the first user question from the logical relationship contained in the first fusion vector, thus improving the accuracy of relevance prediction. Furthermore, based on the predicted relevance and the reference relevance between the first user question and the first knowledge item, the parameters of the first model are adjusted. This improves the first model's ability to accurately capture the contextual logic and implicit intent of the user question, as well as its relevance prediction ability. It also allows the first model to better fit different data distributions among the user question, contextual information, and knowledge item, improving the generalization and upper limit of the prediction effect of the first model.
[0023] Based on the same inventive concept, embodiments of this application also provide a knowledge retrieval method. In response to a second user question input by a user during a dialogue, second contextual information of the second user question is obtained from the user's historical dialogue. The second user question, the second contextual information, and knowledge entries from the knowledge base are input into a first model, enabling the first model to better fit the different data distributions among the second user question, the second contextual information, and the knowledge entries. Furthermore, the first model can accurately understand the logical relationship between the second user question and the second contextual information, and precisely capture the implicit intent of the second user question from this logical relationship, thereby more accurately predicting the relevance between the second user question and knowledge entries in the knowledge base. Finally, knowledge entries are recalled in the knowledge base based on the relevance, which can improve the accuracy and recall rate of knowledge retrieval.
[0024] The model training method and knowledge retrieval method provided in this application embodiment can be executed by an electronic device. The electronic device referred to herein may include terminals, such as but not limited to mobile phones, tablets, laptops, desktop computers, smart voice interaction devices, smart home appliances, smart wearable devices, vehicle terminals, aircraft, etc.; or, the electronic device may also include a server, such as an independent physical server, or a server cluster or distributed system composed of multiple physical servers, or a cloud server providing cloud computing services.
[0025] The model training method and knowledge retrieval method provided in this application can be applied to scenarios that require accurate matching of user intent and business knowledge, such as intelligent customer service and outbound call information recommendation.
[0026] The technical solutions provided by the various embodiments of this application are described in detail below with reference to the accompanying drawings.
[0027] Figure 1 A schematic diagram of an example environment in which embodiments of this application can be implemented is shown. This example environment includes a terminal device 100 and a server 200.
[0028] The terminal device 100 and the server 200 establish a communication connection, which may include, but is not limited to, at least one of the following: wired connection and wireless connection.
[0029] Terminal device 100 includes, but is not limited to, smartphones, tablets, laptops, desktop computers, smart voice interaction devices, smart home appliances, smartwatches, vehicle terminals, and aircraft. Server 200 can be a standalone physical server, a server cluster or distributed system composed of multiple physical servers, or a cloud server providing cloud computing services.
[0030] Terminal device 100 can provide a dialog interface through which users can engage in human-computer interaction. Terminal device 100 can receive relevant parameters input by the user and send these parameters to server 200. Server 200 can obtain a processing result based on the received parameters and return the processing result to terminal device 100.
[0031] It should be understood that in some embodiments, the terminal device 100 may obtain the processing result itself based on the relevant parameters input by the user, without needing to interact with the server 200. This application embodiment does not limit this.
[0032] Based on the example environment described above, this application provides a model training method. Please refer to... Figure 2 The above is a flowchart illustrating a model training method provided in an embodiment of this application. The method includes the following steps: S202, input the user's first user question, the first context information of the first user question, and the first knowledge item into the first model to obtain the predicted correlation between the first user question and the first knowledge item.
[0033] The first user question can be understood as the user question used as training data. The first contextual information is obtained from the user's historical dialogue, which may include, but is not limited to: the dialogue text of at least one round preceding the first user question in the historical dialogue, user profile information, etc.
[0034] In practice, large-scale multi-turn human-machine dialogue data can be collected from real-world application scenarios. This dialogue data includes user questions and system responses. For example, in a robot outbound call scenario, complete dialogue data between the user and the customer service robot can be collected, including multiple questions asked by the user and the responses given by the customer service robot.
[0035] Furthermore, the collected dialogue data is cleaned to remove irrelevant content (such as user greetings and duplicate user questions) and corrected (such as typos and grammatical errors). Multiple user questions are then extracted, and each extracted user question is taken as a first user question. For each first user question, one or more rounds of dialogue preceding the first user question in the dialogue data are taken as the first context information of the first user question. For example, historical user questions from several rounds (such as 3 to 5 rounds) preceding the first user question are extracted from the dialogue data in chronological order. These historical user questions are concatenated into a context sequence, and the length of the context sequence is truncated or supplemented to maintain a consistent length, thus obtaining the first context information.
[0036] For example, the maximum length of the first context information is set to 200 characters. If the length of the context sequence exceeds 200 characters, the first 200 characters are extracted from the historical user question closest to the first user question. If the length of the context sequence is less than 200 characters, a special marker (such as [PAD]) is added to the end of the context sequence to make it reach 200 characters. In this way, highly informative content can be prioritized and redundant interference can be reduced.
[0037] Each first user question has a corresponding first knowledge entry. The first knowledge entry may or may not be related to the first user question. The first knowledge entry originates from the knowledge base of the scenario to which the first user question belongs. This knowledge base can be a Frequently Asked Questions (FAQ) database, which contains multiple knowledge entries, each including a reference question and a reference answer. In this case, the first knowledge entry includes the first reference question and the first reference answer. For example, if the first user question belongs to a robot outbound calling scenario, then the first knowledge entry comes from the FAQ database for robot outbound calling. The FAQ database can be obtained through manual compilation, extraction from an enterprise knowledge base, etc.
[0038] The first model obtains the predicted correlation in the following way: Step a: After encoding the first user question, the first context information, and the first knowledge item, the encoded vector of the first user question and the encoded vector of the first context information are fused to obtain the first fused vector.
[0039] Step b: Based on the first fusion vector and the encoding vector of the first knowledge entry, perform relevance prediction to obtain the predicted relevance.
[0040] Specifically, in step a, the first model has an encoder, which can encode the first user question, the first context information, and the first knowledge item to obtain the encoded vector of these information.
[0041] In some implementations, considering that the first user question, the first context information, and the first knowledge entry belong to different semantic spaces, encoding these information using the same encoder may lead to feature confusion and representation degradation, resulting in insufficient semantic differentiation of synonyms and domain terms, thus affecting subsequent relevance prediction results. Therefore, an independent encoder is set up for each type of information to learn the features of different information in a targeted manner, avoiding representation degradation caused by distribution conflicts, and increasing the first model's ability to semantically distinguish synonyms and domain terms, thereby improving the accuracy of the first model in relevance prediction.
[0042] The encoder used here can be any encoder with encoding function commonly used in the field, such as BERT (Bidirectional Encoder Representation from Transformers), etc., and this application embodiment does not limit it.
[0043] For example, Figure 3A schematic diagram of a first model is shown, which includes an input layer and four independent encoders (denoted as T1, T2, T3, and T4). These encoders can share all or some parameters. In this way, the characteristics of different information can be fully utilized, reducing model complexity and resource consumption while ensuring model performance, thus giving the first model good scalability and robustness.
[0044] Based on this, after the input layer performs embedding processing on the first user question, it provides the embedding processing result to T1 for encoding, obtaining the encoding vector of the first user question; after the input layer performs embedding processing on the first context information, it provides the embedding processing result to T2 for encoding, obtaining the encoding vector of the first context information; after the input layer performs embedding processing on the first reference question in the first knowledge entry, it provides the embedding processing result to T3 for encoding, obtaining the encoding vector of the first reference question; after the input layer performs embedding processing on the first reference answer in the first knowledge entry, it provides the embedding processing result to T4 for encoding, obtaining the encoding vector of the first reference answer.
[0045] Subsequently, the first fusion vector can be obtained through various appropriate methods, which are not limited in the embodiments of this application.
[0046] In some implementations, the encoding vector of the first user question and the encoding vector of the first context information are added together to obtain the first fusion vector.
[0047] In some other implementations, a first similarity is determined between the encoding vector of the first user question and the encoding vector of the first context information; based on the first similarity, the encoding vector of the first user question and the encoding vector of the first context information are fused to obtain a first fused vector.
[0048] Specifically, in some examples, the distance between the encoded vector of the first user question and the encoded vector of the first context information, such as Euclidean distance, can be calculated, and then the first similarity can be determined based on this distance. Further, the weight of the first context information can be determined based on the first similarity, for example, the greater the first similarity, the greater the weight of the first context information. Finally, based on the weight of the first context information, the encoded vector of the first user question and the encoded vector of the first context information are weighted and summed to achieve the fusion of the two and obtain the first fused vector.
[0049] In other examples, in order to more accurately capture the logical relationship between the first user question and the first context information, a cross-attention mechanism can be used to fuse the encoding vector of the first user question and the encoding vector of the first context information.
[0050] Specifically, determining the first similarity between the encoding vector of the first user question and the encoding vector of the first context information may include: mapping the encoding vector of the first user question to obtain a first query vector; mapping the encoding vector of the first context information to obtain a first key vector and a first value vector; and determining the similarity between the first query vector and the first key vector as the first similarity.
[0051] Furthermore, based on the first similarity, the encoding vector of the first user question and the encoding vector of the first context information are fused to obtain the first fused vector, which may include: determining the weight corresponding to the first value vector based on the first similarity; and performing a weighted summation of the first value vector based on the weight to obtain the first fused vector.
[0052] More specifically, the cross-attention mechanism is as follows: crossAttention(Ti, Tj) = LayerNorm(sum(softmax(Q*K^T / sqrt(d))*V)) Where crossAttention(Ti, Tj) represents the fused vector obtained by fusing the encoding vectors Ti and Tj based on the cross-attention mechanism, Q represents the query vector, K represents the key vector, K^T represents the transpose of the key vector, V represents the value vector, d represents the dimension of the value vector, Q*K^T represents the similarity between the query vector and the key vector, softmax(Q*K^T / sqrt(d)) represents the weights corresponding to the value vector, softmax represents the softmax function, sum represents the summation operation, and LayerNorm represents the layer normalization process.
[0053] In practical applications, such as Figure 3 As shown, the first model also includes an attention gating layer, which is based on a cross-attention mechanism to achieve the fusion between the encoding vector of the first user question and the encoding vector of the first context information.
[0054] Understandably, in real-world conversations, user questions are often brief, sometimes even containing references and omissions. The aforementioned fusion method cross-references the first user question with the first contextual information, helping to accurately capture the user's true intent and the complete query context. For example, in a real conversation, a user first enters the question "How do I take a screenshot on a phone of brand A?", then enters the question "What about brand B?". Without contextual information, the first model cannot understand that "brand B" refers to the action of "taking a screenshot." However, through the aforementioned fusion method, the first model can allow the question "What about brand B?" to proactively "ask" the historical question "How do I take a screenshot on a phone of brand A?", thereby generating a first fusion vector that contains more complete information and richer semantics.
[0055] In step b above, correlation prediction can be performed in various ways, and the embodiments of this application do not limit this.
[0056] In some examples, the similarity between the first fusion vector and the encoding vector of the first knowledge entry can be calculated, and then this similarity can be used as the predicted relevance between the first user question and the first knowledge entry.
[0057] In other implementations, where the first knowledge entry includes a first reference question and a first reference answer, the encoding vector of the first knowledge entry may include the encoding vector of the first reference question and the encoding vector of the first reference answer. Accordingly, step b above may include: Step b1: The encoding vector of the first reference question and the encoding vector of the first reference answer are fused to obtain the second fused vector.
[0058] In some examples, the encoding vector of the first reference question can be added to the encoding vector of the first reference answer to obtain the second fusion vector.
[0059] In other examples, a second similarity is determined between the encoding vector of the first reference question and the encoding vector of the first reference answer; based on the second similarity, the encoding vector of the first reference question and the encoding vector of the first reference answer are fused to obtain a second fused vector.
[0060] Specifically, in order to more accurately capture the logical relationship between the first reference question and the first reference answer, a cross-attention mechanism can be used to fuse the encoding vectors of the first reference question and the first reference answer.
[0061] More specifically, determining the second similarity between the encoding vector of the first reference question and the encoding vector of the first reference answer includes: mapping the encoding vector of the first reference question to obtain a second query vector; mapping the encoding vector of the first reference answer to obtain a second key vector and a second value vector; and determining the similarity between the second query vector and the second key vector as the second similarity.
[0062] Furthermore, based on the second similarity, the encoding vector of the first reference question and the encoding vector of the first reference answer are fused to obtain the second fused vector. This may include: determining the weights corresponding to the second value vector based on the second similarity; and performing a weighted summation of the second value vector based on the weights corresponding to the second value vector to obtain the second fused vector.
[0063] The specific implementation process of obtaining the second fusion vector based on the cross-attention mechanism described above is similar to the specific implementation process of obtaining the first fusion vector based on the cross-attention mechanism described above, and will not be repeated here.
[0064] In practical applications, such as Figure 3 As shown, the first model also includes an attention gating layer, which is based on a cross-attention mechanism to achieve the fusion between the encoding vector of the first reference question and the encoding vector of the first reference answer.
[0065] Understandably, the above fusion method achieves the intersection of the first reference question and the first reference answer, which helps to accurately capture the complete semantics of the first knowledge item, thereby generating a second fusion vector that contains more complete information and richer semantics.
[0066] Step b2: Based on the first fusion vector and the second fusion vector, perform correlation prediction to obtain the predicted correlation.
[0067] In some examples, the similarity between the first fusion vector and the second fusion vector can be calculated, and that similarity can be used to determine the relevance between the first user question and the first knowledge entry.
[0068] In other examples, the predicted relevance indicates whether the first user question is relevant to the first knowledge item. Therefore, relevance prediction can be treated as a binary classification task, obtained by: determining the weights of the first fusion vector based on the first similarity between the encoded vector of the first user question and the encoded vector of the first context information; determining the weights of the second fusion vector based on the second similarity between the encoded vector of the first reference question and the encoded vector of the first reference answer; weighting the first and second fusion vectors based on their respective weights to obtain a third fusion vector; and classifying the third fusion vector to obtain the predicted relevance.
[0069] Specifically, the weights corresponding to the second and third fusion vectors can be determined by the following formula: sigmoid(Ti*Tj^T / sqrt(d)). Where, for the weights corresponding to the first fusion vector, Ti represents the encoding vector of the first user question, Tj represents the encoding vector of the first context information, Tj^T represents the transpose of the encoding vector of the first context information, and d represents the dimension of the encoding vector. For the weights corresponding to the second fusion vector, Ti represents the encoding vector of the first reference question, Tj represents the encoding vector of the first reference answer, Tj^T represents the transpose of the encoding vector of the first reference answer, and d represents the dimension of the encoding vector.
[0070] In practical applications, such as Figure 3 As shown, the attention gating layer includes a classifier, and the classification of the third fused vector can be achieved through the classifier.
[0071] It is evident that the weights calculated in the above manner can adapt to the various characteristics of different fusion vectors. By weighted summation of the first and second fusion vectors based on the calculated weights and then classifying them, a deep interaction between the user's true intent and the first knowledge item can be achieved, and the alignment of key semantics can be strengthened, thus solving the intent drift problem caused by long-distance dependence.
[0072] Understandably, traditional knowledge retrieval technologies often match user questions with reference questions in knowledge entries within a knowledge base. If the two are similar, the reference answer from that knowledge entry is retrieved. This approach doesn't consider the relevance between the user question, its context, and the reference answer, resulting in retrieved knowledge entries that don't meet the user's actual needs. The relevance prediction method described above, however, treats the first user question and its context as a whole, and the first reference question and answer as a whole, performing relevance prediction based on these two wholes. This improves the accuracy of relevance prediction, providing data support for subsequently retrieving knowledge entries that meet the user's actual needs.
[0073] S204, Based on the predicted relevance and the reference relevance between the first user question and the first knowledge item, adjust the parameters of the first model.
[0074] Specifically, the loss of the first model is determined based on the difference between the predicted correlation and the reference correlation; the parameters of the first model are adjusted using gradient descent, backpropagation, and other algorithms.
[0075] Reference relevance can represent whether the first user question is related to the first knowledge item. In some examples, reference relevance can be obtained by professional annotation. In other examples, a cue word engineering approach can be adopted to instruct a large model to identify and annotate the relevance between the first user question and the first knowledge item. In still other examples, a strategy of using large model annotation as the primary method and human annotation as a supplement is used to annotate reference relevance.
[0076] The model training method provided in this application obtains the first contextual information of a user's first question from the user's historical dialogue, and inputs the first user question, the first contextual information, and the first knowledge item into a first model. After encoding the first user question, the first contextual information, and the first knowledge item, the first model fuses the encoded vector of the first user question and the encoded vector of the first contextual information to obtain a first fusion vector. This first fusion vector contains the logical relationship between the first user question and the first contextual information, effectively avoiding semantic breaks caused by independent encoding. The first model performs relevance prediction based on the first fusion vector and the encoded vector of the first knowledge item, which can accurately capture the implicit intent of the first user question from the logical relationship contained in the first fusion vector, improving the accuracy of relevance prediction. Furthermore, based on the predicted relevance and the reference relevance between the first user question and the first knowledge item, the parameters of the first model are adjusted. On the one hand, this improves the first model's ability to accurately capture the contextual logic and implicit intent of the user question and its relevance prediction ability. On the other hand, it enables the first model to better fit different data distributions among the user question, contextual information, and knowledge item, improving the generalization and upper limit of the prediction effect of the first model.
[0077] Based on the same inventive concept, embodiments of this application also provide a knowledge retrieval method. Please refer to... Figure 4 The above is a flowchart illustrating a knowledge retrieval method provided in an embodiment of this application. The method includes the following steps: S402, in response to a second user question entered by the user during the dialogue, obtains second contextual information of the second user question from the user's historical dialogue.
[0078] The second user question can be understood as the user's current input question. The historical dialogue can be understood as the dialogue that took place before the second user question. Secondary contextual information may include, but is not limited to: the text of at least one round of dialogue in the historical dialogue preceding the second user question, user profile information, etc. It should be noted that the user here is different from the aforementioned... Figure 2 The users in the illustrated embodiments may differ.
[0079] The specific implementation method for obtaining the second context information is similar to the method for obtaining the first context information mentioned above, and will not be repeated here.
[0080] S404, input the second user question, the second context information, and the knowledge entries in the knowledge base into the first model to obtain the predicted correlation between the second user question and the knowledge entries.
[0081] The first model here can be trained using the model training method provided in the embodiments of this application.
[0082] After encoding the second user question, the second context information, and the knowledge item, the first model fuses the encoded vector of the second user question and the encoded vector of the second context information to obtain a first fused vector, and performs correlation prediction based on the first fused vector and the encoded vector of the knowledge item to obtain the predicted correlation.
[0083] The specific implementation of S404 is similar to that of S202, and will not be repeated here.
[0084] S406, based on predicted relevance, recall at least one second knowledge entry from the knowledge base to respond to a second user's question.
[0085] Specifically, knowledge entries related to the second user's question can be retrieved from the knowledge base as the second knowledge entry. Alternatively, knowledge entries related to the second user's question can be retrieved from the knowledge base, and some or all of these knowledge entries can be selected as the second knowledge entry.
[0086] The knowledge retrieval method provided in this application responds to a second user question input by the user during a dialogue. It obtains second contextual information about the second user question from the user's historical dialogue. The second user question, the second contextual information, and knowledge entries from the knowledge base are input into a first model. This allows the first model to better fit the different data distributions among the second user question, the second contextual information, and the knowledge entries, and to accurately understand the logical relationship between the second user question and the second contextual information. Furthermore, it accurately captures the implicit intent of the second user question from this logical relationship, thereby more accurately predicting the relevance between the second user question and knowledge entries in the knowledge base. Finally, based on this relevance, knowledge entries are recalled in the knowledge base, which can improve the accuracy and recall rate of knowledge retrieval.
[0087] Based on the same inventive concept, embodiments of this application also provide a model training device. Please refer to... Figure 5 This is a schematic diagram of the structure of a model training device 500 provided in an embodiment of this application. The device 500 includes a first input module 510 and an adjustment module 520.
[0088] The first input module 510 is used to input the user's first user question, the first context information of the first user question, and the first knowledge item into the first model to obtain the predicted correlation between the first user question and the first knowledge item.
[0089] Wherein, the first context information is obtained from the user's historical dialogue; the first model encodes the first user question, the first context information, and the first knowledge item, then fuses the encoded vector of the first user question and the encoded vector of the first context information to obtain a first fusion vector; and based on the first fusion vector and the encoded vector of the first knowledge item, a correlation prediction is performed to obtain the predicted correlation.
[0090] The adjustment module 520 is used to adjust the parameters of the first model based on the predicted relevance and the reference relevance between the first user question and the first knowledge item.
[0091] Obviously, the model training device provided in the embodiments of this application can be used as the above-mentioned... Figure 2 The illustrated model training method is the main execution body, thus enabling the model training device to perform... Figure 2 The functions implemented are the same, so they will not be described in detail here.
[0092] Based on the same inventive concept, embodiments of this application also provide a knowledge retrieval device. Please refer to... Figure 6 This is a schematic diagram of the structure of a knowledge retrieval device 600 provided in an embodiment of this application. The device 600 includes: an acquisition module 610, a second input module 620, and a recall module 630.
[0093] The acquisition module 610 is used to acquire second contextual information of the second user question from the user's historical dialogue in response to the second user question entered by the user during the dialogue.
[0094] The second input module 620 is used to input the second user question, the second context information, and the knowledge entries in the knowledge base into the first model to obtain the predicted correlation between the second user question and the knowledge entries.
[0095] After encoding the second user question, the second context information, and the knowledge item, the first model fuses the encoded vector of the second user question and the encoded vector of the second context information to obtain a first fusion vector, and performs relevance prediction based on the first fusion vector and the encoded vector of the knowledge item to obtain the predicted relevance. The recall module 630 is used to recall at least one second knowledge entry from the knowledge base to respond to the second user's question, based on the predicted relevance.
[0096] Obviously, the knowledge retrieval device provided in the embodiments of this application can be used as the above-mentioned... Figure 4 The entity executing the knowledge retrieval method shown is therefore capable of enabling the knowledge retrieval device to perform... Figure 4 The functions implemented are the same, so they will not be described in detail here.
[0097] The foregoing has described specific embodiments of this specification. Other embodiments are within the scope of the appended claims. In some cases, the actions or steps recited in the claims may be performed in a different order than that shown in the embodiments and may still achieve the desired result. Furthermore, the processes depicted in the drawings do not necessarily require the specific or sequential order shown to achieve the desired result. In some embodiments, multitasking and parallel processing are possible or may be advantageous.
[0098] Figure 7 This is a schematic diagram of the structure of an electronic device provided in one embodiment of this application. Please refer to it. Figure 7 At the hardware level, the electronic device includes a processor, and optionally also includes an internal bus, a network interface, and memory. The memory may include main memory, such as high-speed random-access memory (RAM), or non-volatile memory, such as at least one disk drive. Of course, the electronic device may also include other hardware required for other business operations.
[0099] The processor, network interface, and memory can be interconnected via an internal bus, which can be an ISA (Industry Standard Architecture) bus, a PCI (Peripheral Component Interconnect) bus, or an EISA (Extended Industry Standard Architecture) bus, etc. This bus can be divided into address bus, data bus, control bus, etc. For ease of representation, Figure 7 The symbol is represented by a single double-headed arrow, but this does not mean that there is only one bus or one type of bus.
[0100] Memory is used to store programs. Specifically, programs may include program code, which includes computer operation instructions. Memory may include main memory and non-volatile memory, and provides instructions and data to the processor.
[0101] The processor reads the corresponding computer program from non-volatile memory into main memory and then runs it, forming a model training device at the logical level. The processor executes the program stored in memory and specifically performs the following operations: The first user question, the first context information of the first user question, and the first knowledge item are input into the first model to obtain the predicted relevance between the first user question and the first knowledge item. The first context information is obtained from the user's historical dialogue. After encoding the first user question, the first context information, and the first knowledge item, the first model fuses the encoded vector of the first user question and the encoded vector of the first context information to obtain a first fusion vector. The predicted relevance is obtained by performing relevance prediction based on the first fusion vector and the encoded vector of the first knowledge item. Based on the predicted relevance and the reference relevance between the first user question and the first knowledge item, the parameters of the first model are adjusted.
[0102] Alternatively, the processor reads the corresponding computer program from non-volatile memory into memory and runs it, forming a knowledge retrieval device at the logical level. The processor executes the program stored in memory and specifically performs the following operations: In response to a second user question entered by the user during a conversation, second contextual information of the second user question is obtained from the user's historical conversations. The second user question, the second context information, and the knowledge entries in the knowledge base are input into the first model to obtain the predicted relevance between the second user question and the knowledge entries; after encoding the second user question, the second context information, and the knowledge entries, the first model fuses the encoded vector of the second user question and the encoded vector of the second context information to obtain a first fusion vector, and performs relevance prediction based on the first fusion vector and the encoded vector of the knowledge entries to obtain the predicted relevance; Based on the predicted relevance, at least one second knowledge entry is recalled from the knowledge base to respond to the second user's question.
[0103] The above is as stated in this application. Figure 2 The illustrated embodiments disclose the method performed by the model training apparatus, or as described in this application. Figure 4The method executed by the knowledge retrieval device disclosed in the illustrated embodiments can be applied to a processor or implemented by a processor. The processor may be an integrated circuit chip with signal processing capabilities. During implementation, each step of the above method can be completed by integrated logic circuits in the processor's hardware or by instructions in software form. The processor can be a general-purpose processor, including a Central Processing Unit (CPU), a Network Processor (NP), etc.; it can also be a Digital Signal Processor (DSP), an Application Specific Integrated Circuit (ASIC), a Field-Programmable Gate Array (FPGA), or other programmable logic devices, discrete gate or transistor logic devices, or discrete hardware components. It can implement or execute the methods, steps, and logic block diagrams disclosed in the embodiments of this application. The general-purpose processor can be a microprocessor or any conventional processor. The steps of the method disclosed in the embodiments of this application can be directly embodied in the execution of a hardware decoding processor, or executed by a combination of hardware and software modules in the decoding processor. The software module can reside in a mature storage medium in the field, such as random access memory, flash memory, read-only memory, programmable read-only memory, electrically erasable programmable memory, or registers. This storage medium is located in memory, and the processor reads information from the memory and, in conjunction with its hardware, completes the steps of the above method.
[0104] The electronic device can also perform Figure 2 The method, and implement the model training device in Figure 2 The illustrated embodiment may also perform the functions of the electronic device, or the electronic device may also perform the functions of the embodiment. Figure 4 The method, and realize the knowledge retrieval device in Figure 4 The functions of the embodiments shown are not described in detail here.
[0105] Of course, in addition to software implementation, the electronic device of this application does not exclude other implementation methods, such as logic devices or a combination of hardware and software, etc. In other words, the execution subject of the following processing flow is not limited to each logic unit, but can also be hardware or logic devices.
[0106] This application also proposes a computer-readable storage medium that stores one or more programs, the programs including instructions that, when executed by an electronic device including multiple applications, enable the electronic device to perform... Figure 2The method of the illustrated embodiment is specifically used to perform the following operations: The first user question, the first context information of the first user question, and the first knowledge item are input into the first model to obtain the predicted relevance between the first user question and the first knowledge item. The first context information is obtained from the user's historical dialogue. After encoding the first user question, the first context information, and the first knowledge item, the first model fuses the encoded vector of the first user question and the encoded vector of the first context information to obtain a first fusion vector. The predicted relevance is obtained by performing relevance prediction based on the first fusion vector and the encoded vector of the first knowledge item. Based on the predicted relevance and the reference relevance between the first user question and the first knowledge item, the parameters of the first model are adjusted.
[0107] Alternatively, when executed by an electronic device that includes multiple applications, the instruction can cause the electronic device to perform... Figure 4 The method of the illustrated embodiment is specifically used to perform the following operations: In response to a second user question entered by the user during a conversation, second contextual information of the second user question is obtained from the user's historical conversations. The second user question, the second context information, and the knowledge entries in the knowledge base are input into the first model to obtain the predicted relevance between the second user question and the knowledge entries; after encoding the second user question, the second context information, and the knowledge entries, the first model fuses the encoded vector of the second user question and the encoded vector of the second context information to obtain a first fusion vector, and performs relevance prediction based on the first fusion vector and the encoded vector of the knowledge entries to obtain the predicted relevance; Based on the predicted relevance, at least one second knowledge entry is recalled from the knowledge base to respond to the second user's question.
[0108] In summary, the above description is merely a preferred embodiment of this application and is not intended to limit the scope of protection of this application. Any modifications, equivalent substitutions, improvements, etc., made within the spirit and principles of this application should be included within the scope of protection of this application.
[0109] The systems, devices, modules, or units described in the above embodiments can be implemented by computer chips or entities, or by products with certain functions. A typical implementation device is a computer. Specifically, a computer can be, for example, a personal computer, laptop computer, cellular phone, camera phone, smartphone, personal digital assistant, media player, navigation device, email device, game console, tablet computer, wearable device, or any combination of these devices.
[0110] Computer-readable media includes both permanent and non-permanent, removable and non-removable media that can store information using any method or technology. Information can be computer-readable instructions, data structures, modules of programs, or other data. Examples of computer storage media include, but are not limited to, phase-change memory (PRAM), static random access memory (SRAM), dynamic random access memory (DRAM), other types of random access memory (RAM), read-only memory (ROM), electrically erasable programmable read-only memory (EEPROM), flash memory or other memory technologies, CD-ROM, digital versatile optical disc (DVD) or other optical storage, magnetic tape, magnetic disk storage or other magnetic storage devices, or any other non-transferable medium that can be used to store information accessible by a computing device. As defined herein, computer-readable media does not include transient computer-readable media, such as modulated data signals and carrier waves.
[0111] It should also be noted that the terms "comprising," "including," or any other variations thereof are intended to cover non-exclusive inclusion, such that a process, method, article, or apparatus that comprises a list of elements includes not only those elements but also other elements not expressly listed, or elements inherent to such a process, method, article, or apparatus. Without further limitation, an element defined by the phrase "comprising one..." does not exclude the presence of other identical elements in the process, method, article, or apparatus that includes said element.
[0112] The various embodiments in this specification are described in a progressive manner. Similar or identical parts between embodiments can be referred to interchangeably. Each embodiment focuses on describing the differences from other embodiments. In particular, the system embodiments are basically similar to the method embodiments, so the description is relatively simple; relevant parts can be referred to the descriptions in the method embodiments.
Claims
1. A model training method, characterized in that, include: The first user question, the first context information of the first user question, and the first knowledge item are input into the first model to obtain the predicted relevance between the first user question and the first knowledge item. The first context information is obtained from the user's historical dialogue. After encoding the first user question, the first context information, and the first knowledge item, the first model fuses the encoded vector of the first user question and the encoded vector of the first context information to obtain a first fusion vector. The predicted relevance is obtained by performing relevance prediction based on the first fusion vector and the encoded vector of the first knowledge item. Based on the predicted relevance and the reference relevance between the first user question and the first knowledge item, the parameters of the first model are adjusted.
2. The method according to claim 1, characterized in that, The process of fusing the encoded vector of the first user question and the encoded vector of the first context information to obtain the first fused vector includes: Determine the first similarity between the encoded vector of the first user question and the encoded vector of the first context information; Based on the first similarity, the encoded vector of the first user question and the encoded vector of the first context information are fused to obtain a first fused vector.
3. The method according to claim 2, characterized in that, Determining the first similarity between the encoding vector of the first user question and the encoding vector of the first context information includes: The encoding vector of the first user question is mapped to obtain the first query vector; The encoded vector of the first context information is mapped to obtain a first key vector and a first value vector; The similarity between the first query vector and the first key vector is determined as the first similarity. The step of fusing the encoded vector of the first user question with the encoded vector of the first context information based on the first similarity to obtain a first fused vector includes: Based on the first similarity, determine the weight corresponding to the first value vector; The first value vector is obtained by weighted summation based on the weights corresponding to the first value vector.
4. The method according to claim 1, characterized in that, The first knowledge entry includes a first reference question and a first reference answer; the encoding vector of the first knowledge entry includes the encoding vector of the first reference question and the encoding vector of the first reference answer. The step of obtaining the predicted relevance by performing relevance prediction based on the first fusion vector and the encoding vector of the first knowledge entry includes: The encoding vector of the first reference question and the encoding vector of the first reference answer are fused to obtain a second fused vector; Based on the first fusion vector and the second fusion vector, correlation prediction is performed to obtain the predicted correlation.
5. The method according to claim 4, characterized in that, The process of fusing the encoding vector of the first reference question and the encoding vector of the first reference answer to obtain a second fused vector includes: Determine the second similarity between the encoding vector of the first reference question and the encoding vector of the first reference answer; Based on the second similarity, the encoding vector of the first reference question and the encoding vector of the first reference answer are fused to obtain the second fused vector.
6. The method according to claim 5, characterized in that, Determining the second similarity between the encoding vector of the first reference question and the encoding vector of the first reference answer includes: The encoding vector of the first reference problem is mapped to obtain the second query vector; The encoding vector of the first reference answer is mapped to obtain the second key vector and the second value vector; The similarity between the second query vector and the second key vector is determined as the second similarity. The step of fusing the encoding vector of the first reference question and the encoding vector of the first reference answer based on the second similarity to obtain the second fused vector includes: Based on the second similarity, determine the weight corresponding to the second value vector; The second value vector is obtained by weighted summation based on the weights corresponding to the second value vector.
7. The method according to claim 4, characterized in that, The predicted relevance indicates whether the first user question is related to the first knowledge item; The step of performing correlation prediction based on the first fusion vector and the second fusion vector to obtain the predicted correlation includes: Based on the first similarity between the encoding vector of the first user question and the encoding vector of the first context information, the weight corresponding to the first fusion vector is determined. The weights corresponding to the second fusion vector are determined based on the second similarity between the encoding vector of the first reference question and the encoding vector of the first reference answer. Based on the weights corresponding to the first fusion vector and the weights corresponding to the second fusion vector, the first fusion vector and the second fusion vector are weighted and summed to obtain the third fusion vector; The third fusion vector is classified to obtain the predicted relevance.
8. A knowledge retrieval method, characterized in that, include: In response to a second user question entered by the user during a conversation, second contextual information of the second user question is obtained from the user's historical conversations. The second user question, the second context information, and the knowledge entries in the knowledge base are input into the first model to obtain the predicted correlation between the second user question and the knowledge entries. After encoding the second user question, the second context information, and the knowledge item, the first model fuses the encoded vector of the second user question and the encoded vector of the second context information to obtain a first fusion vector, and performs relevance prediction based on the first fusion vector and the encoded vector of the knowledge item to obtain the predicted relevance. Based on the predicted relevance, at least one second knowledge entry is recalled from the knowledge base to respond to the second user's question.
9. An electronic device, characterized in that, include: processor; Memory used to store the processor's executable instructions; The processor is configured to execute the instructions to implement the model training method as described in any one of claims 1 to 7 or the knowledge retrieval method as described in claim 8.
10. A computer-readable storage medium, characterized in that, When the instructions in the storage medium are executed by the processor of the electronic device, the electronic device is able to perform the model training method as described in any one of claims 1 to 7 or the knowledge retrieval method as described in claim 8.