Knowledge retrieval and question answering generation method, device, equipment, medium and program product
By combining a pre-trained retrieval network and a response generation network, and utilizing hard prompting templates and soft prompting techniques, the problem of low response accuracy in complex question-and-answer scenarios is solved, achieving high-precision response generation.
Patent Information
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- CHINA SOUTHERN POWER GRID ARTIFICIAL INTELLIGENCE TECHNOLOGY CO LTD
- Filing Date
- 2026-01-30
- Publication Date
- 2026-05-29
AI Technical Summary
Existing technologies do not achieve high accuracy in knowledge retrieval and question-answer generation when faced with complex questions and answers.
By using a pre-trained retrieval network to retrieve candidate knowledge fragments that match the question content from the knowledge base, and then using a pre-set hard prompt template for structured combination, combined with target soft prompts from a pre-trained response generation network, a response is generated, thereby improving the accuracy of the response.
It effectively reduces interference from irrelevant knowledge fragments, improves the accuracy of responses, and ensures that the responses are both factually based and meet the needs of the question.
Smart Images

Figure CN122114155A_ABST
Abstract
Description
Technical Field
[0001] This application relates to the field of artificial intelligence technology, and in particular to a method, apparatus, device, medium, and program product for knowledge retrieval and question answering generation. Background Technology
[0002] With the rapid development of big data and artificial intelligence technologies, knowledge retrieval and question-answer generation technologies have emerged. The demand for knowledge retrieval and question-answer generation technologies in fields such as intelligent customer service, knowledge management, public opinion analysis, legal consultation, and medical assistance is growing.
[0003] In related technologies, keyword retrieval strategies are typically used for knowledge retrieval and response generation. However, when faced with complex questions and answers, there is a problem of low response accuracy. Summary of the Invention
[0004] Therefore, it is necessary to provide a knowledge retrieval and question-answering generation method, apparatus, equipment, medium, and program product that can improve the accuracy of question answering in order to address the above-mentioned technical problems.
[0005] Firstly, this application provides a knowledge retrieval and question-answering generation method, including:
[0006] Get the question content;
[0007] The pre-trained retrieval network performs knowledge retrieval in the knowledge base based on the question content to obtain candidate knowledge fragments;
[0008] Based on a preset hard hint template, the question content and the candidate knowledge fragments are combined to obtain hard hint content;
[0009] Based on the hard prompts and the target soft prompts corresponding to the pre-trained response generation network, the fused question content is obtained;
[0010] The response generation network generates a response based on the fused question content to obtain the target response content.
[0011] In one embodiment, the training process of the retrieval network includes:
[0012] Acquire labeled and unlabeled corpus samples; perform label fusion based on the labeled and unlabeled corpus samples to obtain pseudo-labeled corpus samples; perform adversarial enhancement processing based on the labeled and pseudo-labeled corpus samples to obtain adversarial corpus samples; have the retrieval network to be trained perform label prediction based on the labeled and adversarial corpus samples to determine the target loss; adjust the parameters of the retrieval network to be trained based on the target loss until the first training termination condition is met to obtain the trained retrieval network.
[0013] In one embodiment, the retrieval network to be trained performs label prediction based on the labeled corpus samples and the adversarial corpus samples to determine the target loss, including:
[0014] The retrieval network to be trained predicts labels based on the labeled corpus samples to obtain a first predicted label for the labeled corpus samples; a first loss is determined based on the first predicted label and the labels contained in the labeled corpus samples; the retrieval network to be trained predicts labels based on the adversarial corpus samples to obtain a second predicted label for the adversarial corpus samples; a second loss is determined based on the second predicted label and the labels contained in the adversarial corpus samples; and a target loss is obtained by weighted summation of the first loss and the second loss.
[0015] In one embodiment, the pre-trained retrieval network performs knowledge retrieval in the knowledge base based on the question content to obtain candidate knowledge fragments, including:
[0016] The retrieval network performs tag prediction on the question content to obtain question content tags; based on the distance between the question content tags and the knowledge tags corresponding to each of the multiple knowledge segments in the knowledge base, candidate knowledge segments are determined from the multiple knowledge segments in the knowledge base; wherein, the knowledge tags corresponding to each of the multiple knowledge segments in the knowledge base are obtained by the retrieval network performing tag prediction.
[0017] In one embodiment, the training process of the response generation network includes:
[0018] The process involves: acquiring sample question content, a reference knowledge fragment of the sample question content, and a reference answer content; wherein the reference knowledge fragment is determined by the retrieval network based on knowledge retrieval of the sample question content; combining the sample question content and the reference knowledge fragment based on a preset hard hint template to obtain sample hard hint content; determining sample fusion question content based on the sample hard hint content and the target soft hint corresponding to the answer generation network; generating a predicted answer content by the answer generation network to be trained based on the sample fusion question content; determining the answer loss based on the target soft hint, the predicted answer content, the reference answer content, and the reference knowledge fragment; and adjusting at least one parameter of the answer generation network to be trained, the target soft hint, and the retrieval network based on the answer loss until a second training termination condition is met to obtain the trained answer generation network.
[0019] In one embodiment, determining the response loss based on the target soft prompt, the predicted response content, the reference response content, and the reference knowledge fragment includes:
[0020] Based on the predicted response content and the reference response content, a generation loss is determined; based on the target soft hint, a soft hint loss is determined; based on the predicted response content and the reference knowledge fragment, a consistency loss is determined; and a weighted sum of the response loss, the soft hint loss, and the consistency loss is performed to obtain the response loss.
[0021] Secondly, this application also provides a knowledge retrieval and question-answering generation device, including:
[0022] The retrieval module is used to retrieve the content of the question.
[0023] The retrieval module is used to perform knowledge retrieval in the knowledge base based on the question content by a pre-trained retrieval network to obtain candidate knowledge fragments;
[0024] The hard hint fine-tuning module is used to combine the question content and the candidate knowledge fragments based on a preset hard hint template to obtain hard hint content;
[0025] The soft prompt fine-tuning module is used to obtain the fused question content by generating the target soft prompt based on the hard prompt content and the pre-trained response generation network.
[0026] The output module is used to generate a response from the response generation network based on the fused question content, thereby obtaining the target response content.
[0027] Thirdly, this application also provides a computer device, including a memory and a processor, wherein the memory stores a computer program, and the processor executes the computer program to implement the steps of the above-described method.
[0028] Fourthly, this application also provides a computer-readable storage medium having a computer program stored thereon, which, when executed by a processor, implements the steps of the above-described method.
[0029] Fifthly, this application also provides a computer program product, including a computer program that, when executed by a processor, implements the steps of the above-described method.
[0030] The aforementioned knowledge retrieval and question-answering generation methods, devices, equipment, media, and program products, based on a pre-trained retrieval network, selectively retrieve candidate knowledge fragments from a knowledge base that match the question content. This identifies candidate knowledge fragments highly relevant to the question content, effectively reducing the possibility of answer illusions caused by interference from other irrelevant knowledge fragments. Then, using a pre-set hard hint template, the question content and candidate knowledge fragments are standardized and structurally combined to obtain hard hint content. This hard hint content is then fused with target soft hints corresponding to a pre-trained answer generation network to obtain fused question content. The hard hint template allows the answer generation network to clearly distinguish between questions and knowledge, guiding it to answer around the question content and using candidate knowledge fragments as the core basis, strengthening the constraint of candidate knowledge fragments on the answer. The target soft hints guide the model capabilities of the answer generation network. Finally, the answer generation network generates the target answer content based on the fused question content, ensuring that the target answer content is both factually accurate and meets the question's requirements, thereby improving the accuracy of the answer. Attached Figure Description
[0031] To more clearly illustrate the technical solutions in the embodiments of this application or related technologies, the drawings used in the description of the embodiments of this application or related technologies will be briefly introduced below. Obviously, the drawings described below are only some embodiments of this application. For those skilled in the art, other related drawings can be obtained based on these drawings without creative effort.
[0032] Figure 1 This is an application environment diagram of the knowledge retrieval and question answering generation method in one embodiment;
[0033] Figure 2 This is a flowchart illustrating a knowledge retrieval and question-answering generation method in one embodiment;
[0034] Figure 3 This is a schematic diagram of the training process of the retrieval network in one embodiment;
[0035] Figure 4 This is a schematic diagram of the architecture of a knowledge retrieval and question answering generation system in one embodiment.
[0036] Figure 5 This is a flowchart illustrating fine-tuning and optimization in one embodiment;
[0037] Figure 6 This is a structural block diagram of a knowledge retrieval and question-answering generation device in one embodiment;
[0038] Figure 7 This is an internal structural diagram of a computer device in one embodiment. Detailed Implementation
[0039] To make the objectives, technical solutions, and advantages of this application clearer, the following detailed description is provided in conjunction with the accompanying drawings and embodiments. It should be understood that the specific embodiments described herein are merely illustrative and not intended to limit the scope of this application.
[0040] It should be noted that the terms "first," "second," etc., used in this application can be used to describe various elements, but these elements are not limited by these terms. These terms are only used to distinguish the first element from the second element. The terms "comprising" and "having," and any variations thereof, used in this application, are intended to cover non-exclusive inclusion. The term "multiple" used in this application refers to two or more. The term "and / or" used in this application refers to one of the embodiments, or any combination of multiple embodiments.
[0041] The knowledge retrieval and question-answering generation method provided in this application can be applied to, for example... Figure 1 In the application environment shown, terminal 101 communicates with server 102 via a network. A data storage system can store the data that server 102 needs to process. The data storage system can be integrated onto server 102, or it can be located in the cloud or on other network servers; server 102 can deploy a retrieval network and a response generation network.
[0042] For example, a user can input a question through terminal 101, or simultaneously input the question and reference materials. Terminal 101 sends the received question to server 102. Server 102, based on the received question, uses a pre-trained retrieval network to perform knowledge retrieval in the knowledge base to obtain candidate knowledge fragments; it then combines the question and candidate knowledge fragments based on a preset hard hint template to obtain hard hint content; based on the hard hint content and the target soft hint corresponding to the pre-trained response generation network, it obtains fused question content; the response generation network then generates a response based on the fused question content to obtain the target response content; finally, server 102 sends the generated target response content to terminal 101 so that terminal 101 can display the target response content to the user.
[0043] In some embodiments, a user can provide feedback on the target response content through terminal 101, such as a response score. Terminal 101 can send the response feedback to server 102, and server 102 can iteratively optimize at least one of the retrieval network and the response generation network based on the response feedback.
[0044] Terminal 101 can be, but is not limited to, various personal computers, laptops, smartphones, tablets, drones, low-altitude aircraft, IoT devices, and portable wearable devices. IoT devices can include smart speakers, smart TVs, smart air conditioners, smart in-vehicle devices, and projection equipment. Portable wearable devices can include smartwatches, smart bracelets, and head-mounted displays. Head-mounted displays can be virtual reality (VR) devices, augmented reality (AR) devices, and smart glasses. Server 102 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.
[0045] In one exemplary embodiment, such as Figure 2 As shown, a knowledge retrieval and question-answering generation method is provided, which is then applied to... Figure 1 Taking the server in the example, the explanation includes the following steps 201 to 205. Wherein:
[0046] Step 201: Obtain the question content.
[0047] In some embodiments, the question content can be obtained by extracting text from user input; it can also be obtained by speech recognition of user voice commands; or it can be a preset text content determined based on user selection operations; the specific method of obtaining the question content is not limited here.
[0048] In some embodiments, after obtaining the question content, data preprocessing can be performed on the question content, and subsequent knowledge retrieval and response can be performed based on the preprocessed question content. Among them, data preprocessing can be text cleaning, terminology standardization, format structuring and other processing operations. For example, if the user inputs the question text "How much electricity did you use last year", "last year" can be standardized to a specific year, such as "year a", and "how much electricity did you use" can be converted into the standardized technical expression "how many kilowatt-hours of electricity were consumed", thereby obtaining the question content "how many kilowatt-hours of electricity were consumed in year a".
[0049] In some embodiments, users can provide reference documents while entering their questions. In this case, the server needs to obtain both the question content and the reference documents. Subsequently, the obtained reference documents can be added to the knowledge base for knowledge retrieval.
[0050] Step 202: The pre-trained retrieval network performs knowledge retrieval in the knowledge base based on the question content to obtain candidate knowledge fragments.
[0051] Among them, the pre-trained retrieval network refers to a deep learning model with knowledge retrieval capabilities.
[0052] In some embodiments, the knowledge base may include a pre-built collection of knowledge fragments with a large number of knowledge segments, and may also include reference documents provided by users; in addition, the knowledge base may also include feature vectors for each knowledge segment, wherein the feature vectors of the knowledge segments may be obtained in advance by feature extraction of the knowledge segments. When performing knowledge retrieval, the candidate knowledge segments that meet the requirements can be determined by matching the feature vectors of the question content with the feature vectors of each knowledge segment.
[0053] In other embodiments, knowledge retrieval can also be achieved through keyword matching, knowledge graph retrieval, etc. For example, keyword matching can involve first performing word segmentation and stop word removal on the query content to extract core keywords, and then performing precise or fuzzy matching on the knowledge base based on these core keywords to filter out knowledge fragments containing the core keywords as candidate knowledge fragments. Knowledge graph retrieval can involve a pre-constructed knowledge graph, which forms a structured knowledge network with entities as nodes and relationships between entities as edges. During the retrieval process, the server first performs entity recognition and relationship extraction on the query content to determine the core entity and relationships to be queried, and then mines the entity relationship information matching the query content by traversing entity nodes and corresponding relationship paths in the knowledge graph, thereby extracting knowledge fragments containing the target entity and relationships as candidate knowledge fragments.
[0054] Clearly, the candidate knowledge fragments determined based on the question content are also the knowledge fragments in the knowledge base that are highly related to the question content.
[0055] Step 203: Based on the preset hard hint template, combine the question content and candidate knowledge fragments to obtain hard hint content.
[0056] Hard cues refer to the guidance information embedded in the input sequence in a fixed, explicit structured text form when using a model to perform a generation task. Hard cues can standardize the model's input sequence through text instructions, information splicing rules, format constraints, etc., thereby guiding the model to focus on the core task objective.
[0057] Pre-defined hard cue templates refer to a standardized text structure framework that integrates question content with candidate knowledge fragments. By combining question content and candidate knowledge fragments according to the pre-defined hard cue templates, hard cue content with a unified structure and complete information can be quickly generated, thus providing clear and explicit input guidance for the subsequent model's response generation.
[0058] For example, a preset hard hint template could be "Please answer the following question: B based on the search results: A", where A represents the previously retrieved candidate knowledge fragments and B represents the question content. In this way, after obtaining the question content and candidate knowledge fragments, filling them into the specified positions in the preset hard hint template will yield standardized hard hint content.
[0059] Step 204: Based on the hard prompts and the target soft prompts corresponding to the pre-trained response generation network, the fused question content is obtained.
[0060] Among them, the pre-trained response generation network refers to a deep learning model with the ability to generate responses.
[0061] Among them, soft prompts are non-textual explicit guidance information that differs from hard prompts. They are a prompt learning technique that implicitly guides the model to focus on specific task objectives and adapt to different application scenarios by adding learnable continuous vector representations to the input layer or hidden layer of the model.
[0062] The target soft cue corresponding to the pre-trained response generation network refers to the soft cue obtained by fine-tuning the response generation network during the training process for the specific task scenario of response generation. Obviously, the target soft cue, after task adaptation optimization, can accurately match the semantic encoding logic of the response generation network, effectively improving the model's ability to capture the core information in the hard cue content and the fit of the generated content.
[0063] In some embodiments, the hard prompt content and the target soft prompt are combined to obtain the fused question content. This can be achieved by concatenating the vector representation of the target soft prompt with the encoded vector of the hard prompt content to form a fused feature vector, thereby obtaining the fused question content. Alternatively, the vector representation of the target soft prompt and the encoded vector of the hard prompt content can be weighted and fused, and the explicit instruction guidance of the hard prompt and the implicit task adaptation of the soft prompt can be balanced by a preset weight coefficient.
[0064] Step 205: The response generation network generates a response based on the fused question content to obtain the target response content.
[0065] In some embodiments, the response generation network may include an encoding layer and a decoding layer. The encoding layer is used to extract deep semantic features from the input fused question content. For example, the encoding layer may adopt a multi-head attention mechanism-based architecture, first converting the text information in the fused question content into word embedding representations in vector form, then capturing the correlation between different semantic units within the text through a self-attention module, and simultaneously combining a feedforward neural network to perform nonlinear transformation and dimensional mapping on the extracted initial semantic features, finally outputting an encoded feature vector that can comprehensively represent the core semantics of the fused question content. Subsequently, the decoding layer uses the encoded feature vector output by the encoding layer as a basis to gradually construct the target response content using an autoregressive generation method.
[0066] In the aforementioned knowledge retrieval and question-answering generation method, a pre-trained retrieval network retrieves candidate knowledge fragments from the knowledge base that match the question content. This identifies candidate knowledge fragments highly relevant to the question content, effectively reducing the possibility of answer illusions caused by interference from other irrelevant knowledge fragments. Then, using a pre-defined hard cue template, the question content and candidate knowledge fragments are standardized and structurally combined to obtain hard cue content. This hard cue content is then fused with the target soft cue corresponding to the pre-trained answer generation network to obtain fused question content. The hard cue template allows the answer generation network to clearly distinguish between questions and knowledge, guiding it to answer based on the question content and candidate knowledge fragments, thus strengthening the constraint of candidate knowledge fragments on the answer. The target soft cue guides the model capabilities of the answer generation network. Finally, the answer generation network generates the target answer content based on the fused question content, ensuring that the target answer content is both factually accurate and meets the question's requirements, thereby improving the accuracy of the answer.
[0067] In one exemplary embodiment, such as Figure 3 As shown, Figure 3 A schematic diagram of the training process for the retrieval network is provided. The training process of the retrieval network includes steps 301 to 305, wherein:
[0068] Step 301: Obtain labeled and unlabeled corpus samples.
[0069] Labeled corpus samples refer to corpus samples that carry labels. The labels can be manually annotated or automatically annotated through other methods, such as automatic annotation by annotation algorithms. Unlabeled corpus samples refer to corpus samples that do not carry labels.
[0070] The labels of the corpus samples can be used to indicate information such as the category, attributes, and semantics of the corpus samples; for example, for the corpus text "When a short circuit occurs in the line, the current increases sharply, the protection device operates, and the circuit breaker trips", the label can be "the reason for the trip".
[0071] In some embodiments, since the retrieval network is trained for a question-answering task in the target domain, the labeled and unlabeled corpus samples can be corpora belonging to the same target domain.
[0072] In some embodiments, corpus of the target domain can be collected first, and the collected corpus can be preprocessed. Some of the corpus can be manually labeled to obtain labeled corpus samples, while the unlabeled corpus can be used as unlabeled corpus samples.
[0073] Taking the power customer service field as an example, we can collect multi-source corpus data in the power customer service field, such as structured documents like regulations and manuals, semi-structured work orders, historical question-and-answer pairs, voice recordings and their transcribed text, and on-site photos. Then, we can process the collected data, including but not limited to unified encoding, removal of control characters and noise, sentence and word segmentation, standardization of professional terms (e.g., replacing "10kV line short circuit" with "10 kV line short circuit"), name entity recognition to extract candidate entities, speech recognition transcription and extraction of acoustic features, and image visual encoder to extract visual features and identify key information such as equipment models and scale values. Finally, we can partially label the processed data to obtain labeled and unlabeled corpus samples.
[0074] Step 302: Perform label fusion based on labeled and unlabeled corpus samples to obtain pseudo-labeled corpus samples.
[0075] Label fusion refers to generating high-quality pseudo-labels for unlabeled corpus samples based on labeled corpus samples.
[0076] In some embodiments, a teacher model can be trained first using labeled corpus samples. Then, the trained teacher model performs label prediction on unlabeled corpus samples to obtain pseudo-labeled corpus samples. The pseudo-labeled corpus samples are a combination of unlabeled corpus samples and corresponding pseudo-labels.
[0077] In some embodiments, the teacher model can be a classification model or an extraction model based on a Transformer architecture. If the teacher model is a classification model, its input is unlabeled corpus samples, and its output is the pseudo-label probability distribution of the unlabeled corpus samples. Thus, based on the pseudo-label probability distribution, the candidate pseudo-label with the highest confidence can be determined. If the confidence of the candidate pseudo-label is higher than a preset confidence threshold, the candidate pseudo-label can be determined as the pseudo-label of the unlabeled corpus sample, resulting in a pseudo-labeled corpus sample. If the confidence of the candidate pseudo-label is not higher than the preset confidence threshold, the corpus can be discarded, or label prediction can be performed again.
[0078] In some embodiments, the pseudo-labeled corpus samples may include the confidence level of the pseudo-labels in addition to the pseudo-labels and corpus samples.
[0079] Step 303: Based on the labeled corpus samples and pseudo-labeled corpus samples, perform adversarial enhancement processing to obtain adversarial corpus samples.
[0080] In some embodiments, adversarial enhancement processing can be performed on labeled corpus samples to obtain adversarial corpus samples; and adversarial enhancement processing can be performed on pseudo-labeled corpus samples to obtain adversarial corpus samples.
[0081] In some embodiments, at least two different adversarial enhancement processes can be performed on the same input corpus sample (including labeled corpus samples and pseudo-labeled corpus samples) to obtain a set of adversarial corpus sample combinations that can be used for consistency detection. In this way, when calculating the loss in the subsequent process, the consistency loss can be calculated for the adversarial corpus sample combination, thereby further improving the prediction consistency of the retrieval network in the interference scenario.
[0082] Adversarial enhancement refers to the process of adding interference to input corpus samples (including labeled corpus samples and pseudo-labeled corpus samples); adversarial enhancement can include adversarial perturbation processing at the embedding layer, semantic-level enhancement processing, etc.
[0083] Among them, adversarial perturbation processing refers to the process of introducing gradient-driven perturbation vectors to generate new adversarial embedding representations based on the word vector representations of the input corpus samples (including labeled corpus samples and pseudo-labeled corpus samples). Then, the adversarial corpus samples are obtained by decoding based on the adversarial embedding representations.
[0084] In some embodiments, adversarial interference can be added to the corpus samples using methods such as Fast Gradient Sign Method (FGSM) and Projected Gradient Descent (PGD).
[0085] Semantic enhancement refers to changing the presentation of a corpus while maintaining its semantics. For example, semantic enhancement can be achieved through synonym replacement, entity replacement, sentence transformation, and backward translation.
[0086] In some embodiments, the labels of adversarial corpus samples are consistent with the labels of the corpus samples before adversarial enhancement; for example, adversarial enhancement is performed on corpus sample a to obtain adversarial corpus sample a1. If the label of corpus sample a is c, then the label of adversarial corpus sample a1 is also c.
[0087] Step 304: The retrieval network to be trained performs label prediction based on labeled corpus samples and adversarial corpus samples to determine the target loss.
[0088] In some embodiments, the target loss can be calculated using a loss function, such as the cross-entropy loss function or the cosine similarity loss function.
[0089] The target loss is used to measure the degree of deviation between the label prediction results of the retrieval network and the actual results.
[0090] In some embodiments, the retrieval network to be trained can predict labels for labeled corpus samples and adversarial corpus samples respectively to obtain their corresponding predicted labels. Based on the predicted labels and the labels carried by the corpus samples, the losses are calculated separately. Finally, the losses of the two types of corpus samples are combined to obtain the target loss.
[0091] In some embodiments, as described above, the adversarial corpus samples may further include a combination of adversarial corpus samples obtained by performing at least two different adversarial enhancement processes on the same input corpus sample (including labeled corpus samples and pseudo-labeled corpus samples). In this way, during the calculation of the target loss, the retrieval network to be trained can also perform label prediction for the labeled corpus samples and the adversarial corpus samples respectively to obtain their respective predicted labels. Based on the predicted labels and the labels carried by the corpus samples, the loss corresponding to the labeled corpus samples and the loss corresponding to the adversarial corpus samples are calculated respectively. At the same time, the consistency loss can also be calculated based on the consistency between the prediction results of different adversarial corpus samples in the adversarial corpus sample combination. Finally, the three losses are combined to obtain the target loss.
[0092] Step 305: Adjust the parameters of the retrieval network to be trained based on the target loss until the first training termination condition is met, and obtain the trained retrieval network.
[0093] In some embodiments, the parameters of the retrieval network to be trained are adjusted in the direction of minimizing the target loss until a first training termination condition is met; wherein, the first training termination condition may be that the target loss is less than a loss threshold, or that the number of iterations of training reaches a prediction number threshold.
[0094] In the above embodiments, labeled corpus samples and adversarial corpus samples are used together to train the retrieval network to be trained. The adversarial corpus samples can simulate complex document scenarios and noisy input scenarios, prompting the retrieval network to learn the ability to identify and filter interference information during the training process, thereby significantly enhancing the robustness of the retrieval network in practical applications. The labeled corpus samples provide clear label annotations for the retrieval network, ensuring the accuracy of the retrieval network's predictions, thereby effectively improving the stability and reliability of the retrieval network's prediction results.
[0095] In an exemplary embodiment, the retrieval network to be trained performs label prediction based on labeled corpus samples and adversarial corpus samples to determine the target loss, including:
[0096] The retrieval network to be trained predicts labels based on labeled corpus samples to obtain the first predicted label of the labeled corpus samples.
[0097] The labeled corpus sample includes labels and corpus. The corpus contained in the labeled corpus sample is input into the retrieval network to be trained. The retrieval network performs label prediction based on the corpus to obtain the first predicted label of the labeled corpus sample.
[0098] The first loss is determined based on the first predicted label and the labels contained in the labeled corpus samples.
[0099] In some embodiments, the first loss can be calculated using a loss function, such as the cross-entropy loss function, the cosine similarity loss function, etc.
[0100] The first loss is used to measure the degree of deviation between the first predicted label of the retrieval network and the labels included in the labeled corpus samples.
[0101] The retrieval network to be trained performs label prediction based on adversarial corpus samples to obtain the second predicted label of the adversarial corpus samples.
[0102] The adversarial corpus sample includes adversarial corpus and labels inherited from the corpus sample before adversarial training. The adversarial corpus sample is input into the retrieval network to be trained, and the retrieval network performs label prediction based on the adversarial corpus to obtain the second predicted label of the adversarial corpus sample.
[0103] The second loss is determined based on the second predicted label and the labels contained in the adversarial corpus samples.
[0104] In some embodiments, the second loss can be calculated using a loss function, such as the cross-entropy loss function, the cosine similarity loss function, etc.
[0105] In some embodiments, since the adversarial corpus samples are obtained by adversarial enhancement based on labeled corpus samples and pseudo-labeled corpus samples, it is obvious that the confidence of the labels carried by the pseudo-labeled corpus samples is lower than that of the labeled corpus samples. At the same time, there are also differences in the confidence of different pseudo-labeled corpus samples. Therefore, different training weights can be set for different adversarial corpus samples. For example, if the adversarial corpus samples are obtained by adversarial enhancement based on labeled corpus samples, the training weights of the adversarial corpus samples are higher. Meanwhile, if the adversarial corpus samples are obtained by adversarial enhancement based on pseudo-labeled corpus samples, the training weights of the adversarial corpus samples are consistent with the confidence of the pseudo-labeled corpus samples. The higher the confidence of the pseudo-labeled corpus samples, the higher the training weights of the adversarial corpus samples.
[0106] In addition, to avoid the excessive influence of individual high-confidence pseudo-labels on model training, a smoothing coefficient can be introduced to adjust the weights of each adversarial corpus sample, and a weighted loss function can be used to optimize the pseudo-label samples during the model training phase.
[0107] The second loss measures the degree of deviation between the second predicted label of the retrieval network and the labels included in the adversarial corpus samples.
[0108] The target loss is obtained by weighted summation of the first loss and the second loss.
[0109] In some embodiments, the target loss can be obtained by the following formula. .
[0110] Among them, L sup As the first loss, L adv This is the second loss. These are weighting coefficients; adjusted... This can balance the relationship between the performance of the retrieval network in the original task and its robustness against adversarial attacks.
[0111] In the above embodiments, a first loss is obtained by training with labeled corpus samples; a second loss is obtained by training with adversarial corpus samples; and a target loss is obtained by weighted summation of the first and second losses. Thus, by adjusting the weights of the first and second losses, the retrieval network can achieve a balance between original task performance and adversarial robustness.
[0112] In some embodiments, a pre-trained retrieval network performs knowledge retrieval in a knowledge base based on the question content to obtain candidate knowledge fragments, including:
[0113] The retrieval network predicts the tags for the question content, thus obtaining the question content tags.
[0114] Candidate knowledge segments are determined from multiple knowledge segments in the knowledge base based on the distance between the question content tags and the corresponding knowledge tags of each knowledge segment in the knowledge base.
[0115] In this context, the knowledge tags corresponding to each of the multiple knowledge fragments in the knowledge base are obtained by the retrieval network through tag prediction.
[0116] The distance between labels can be calculated using methods such as cosine similarity, Euclidean distance, and Manhattan distance.
[0117] In some embodiments, a distance threshold can be preset. If the distance between the question content tag and the knowledge tag is less than the distance threshold, the knowledge fragment corresponding to the knowledge tag is determined as a candidate knowledge fragment. Alternatively, a preset selection number can be preset, that is, a preset number of knowledge fragments are selected as candidate knowledge fragments in order of increasing distance.
[0118] In some embodiments, the question content and question content tags may be vector-encoded separately, and the encoded vectors may be fused, such as by concatenation or weighted addition, to obtain a fused first vector. Additionally, the knowledge fragments and their corresponding knowledge fragment tags may be vector-encoded, and the encoded vectors may be fused, such as by concatenation or weighted addition, to obtain a fused second vector. Then, candidate knowledge fragments may be determined from multiple knowledge fragments in the knowledge base based on the distance between the first and second vectors.
[0119] In the above embodiments, candidate knowledge fragments related to the question content are filtered by the distance between tags, so that there is no need to perform word-by-word matching in the entire knowledge base. Instead, information is located at the semantic level, which significantly improves the retrieval speed and recall rate.
[0120] In one exemplary embodiment, the training process of the response generator network includes:
[0121] The system retrieves sample question content, reference knowledge fragments of the sample question content, and reference answer content; the reference knowledge fragments are determined by the retrieval network based on the sample question content.
[0122] Among them, the reference knowledge fragment is a knowledge fragment determined by the retrieval network based on the sample question content and by performing knowledge retrieval in the knowledge base.
[0123] The sample response can be a manually generated answer to the sample question.
[0124] Based on a preset hard prompt template, the sample question content and reference knowledge fragments are combined to obtain the sample hard prompt content.
[0125] For example, a preset hard-signal template can be a spliced template, and its mathematical form is as follows: ,in, This represents a concatenation operation, which concatenates the question and knowledge to obtain sample hard hints. Then, the obtained sample hard hints are embedded; that is, the embedded representation of the sample hard hints can be: ,in, () represents the embedding operation, R is the set of real numbers, L represents the sequence length, and d represents the embedding dimension.
[0126] Based on the hard cues from the samples and the soft cues from the response generation network, the content of the sample fusion question is determined.
[0127] In some embodiments, the embedded representation of the sample hard prompt content and the target soft prompt corresponding to the response generation network can be combined to obtain the sample fused question content.
[0128] For example, the target soft cue can be a soft cue matrix. Where m is the number of soft cue lexical units, and d represents the embedding dimension of the lexical units; the embedding representation of the sample hard cue content... With soft cue matrix By combining the samples, we obtain the fused question content. .
[0129] The response generation network to be trained generates responses based on sample fusion of question content, thus obtaining predicted response content.
[0130] In some embodiments, the response generation network to be trained can be built on a Transformer architecture. The Transformer architecture includes an encoder and decoder based on a self-attention mechanism. The encoder encodes the content of the fused sample questions. Since the fused sample questions contain target soft cues, the self-attention layer can introduce a soft cue bias term to adjust the attention distribution during the calculation of the attention score. ,in, Represents the attention mechanism, Here, Q represents the query, K represents the key, and V represents the value. From the soft cue matrix It is learned; finally, the decoder outputs the predicted response.
[0131] Based on target soft prompts, predicted response content, reference response content, and reference knowledge fragments, the response loss is determined.
[0132] The response loss can be calculated using a loss function, such as cross-entropy loss or cosine similarity loss.
[0133] Based on the response loss, at least one parameter in the response generation network, target soft cue, and retrieval network to be trained is adjusted until the second training termination condition is met, resulting in the trained response generation network.
[0134] In some embodiments, since the reference knowledge fragments of the sample question content are determined by the retrieval network and the target soft cue is a trainable virtual vector, in the process of adjusting the parameters according to the response loss, in addition to adjusting the parameters of the response generation network, at least one parameter of the target soft cue and the retrieval network can also be adjusted until the second training termination condition is met, and the trained response generation network is obtained.
[0135] For example, the parameters in the response generation network to be trained can be adjusted based on the response loss until the second training termination condition is met, resulting in a trained response generation network; or the parameters in the response generation network and target soft hints to be trained can be adjusted based on the response loss until the second training termination condition is met, resulting in a trained response generation network and adjusted target soft hints; or the parameters in the response generation network, target soft hints, and retrieval network to be trained can be adjusted based on the response loss until the second training termination condition is met, resulting in a trained response generation network, retrieval network, and adjusted target soft hints.
[0136] In some embodiments, the second training termination condition may be that the response loss is less than a loss threshold, or that the number of training iterations reaches a threshold.
[0137] During the training of the above-mentioned response generation network, the response generation network, target soft prompting, and retrieval network are regarded as a co-optimized whole. By applying the response loss to both the knowledge retrieval and question answering processes, joint optimization of different task stages is achieved.
[0138] In an exemplary embodiment, the response loss can be a joint loss, that is, the response loss is determined based on the target soft cue, the predicted response content, the referenced response content, and the referenced knowledge fragments, and may include:
[0139] The generated loss is determined based on the predicted response content and the reference response content.
[0140] The generation loss is used to measure the degree of difference between the reference response and the predicted response.
[0141] In some embodiments, the generation loss can be the cross-entropy loss, which is calculated as follows: - .
[0142] Where H represents the input sample fusion question content, This represents the historical sequence up to the t-th word. Represents the t-th word element. This represents predicting the next term given the historical sequence and the input. The probability of.
[0143] Based on the target soft cue, determine the soft cue loss.
[0144] In some embodiments, the soft cueing loss can be calculated through regularization, i.e., the soft cueing loss is... ,in, This is a hyperparameter used to control the strength of regularization. It is a trainable soft cue vector matrix It is the squared norm of a matrix, used to measure the overall size of the matrix.
[0145] Based on the predicted response content and reference knowledge fragments, determine the consistency loss;
[0146] Among them, consistency loss is used to measure the degree of consistency between the predicted response content and the reference knowledge fragment, thereby ensuring that the generated predicted response content is as consistent as possible with the knowledge facts of the reference knowledge fragment, reducing the possibility of the model outputting fictitious information.
[0147] In some embodiments, the consistency loss can be calculated using the following formula:
[0148] .
[0149] in, This represents a loss of consistency. The weight representing the i-th reference knowledge fragment can be determined by the similarity between the reference knowledge fragment and the reference question content. Represents cosine similarity calculation. This represents the pooling operation performed on the question H related to sample fusion. Represents the i-th reference knowledge fragment D i Embedding processing is performed.
[0150] The response loss is obtained by weighted summation of generation loss, soft hint loss, and consistency loss.
[0151] For example, the formula for calculating the response loss is as follows:
[0152] .
[0153] Where L represents the response loss, Represents the generation loss. This represents a soft warning loss. This represents a loss of consistency. This represents hyperparameters.
[0154] In the above calculation of response loss, the response loss, soft cue loss and consistency loss are weighted and integrated to obtain the response loss. This can ensure that the response generated by the model matches the reference text highly, prevent overfitting of soft cue through regularization constraints, and force the generated content to be semantically consistent with the retrieved knowledge fragments. This achieves synergistic optimization of generation quality, generalization ability and knowledge accuracy, and improves training effect.
[0155] The following explanation will use a question-and-answer system in the power customer service field as an example. Please refer to [link / reference]. Figure 4 , Figure 4 The diagram illustrates the architecture of a knowledge retrieval and question-answering generation system, including a data preparation module, a data optimization module, a network optimization module, and an application module.
[0156] The data preparation module is used to collect and preprocess data from the power customer service field. For example, it collects multi-source corpora from power customer service, including structured documents (such as regulations and manuals), semi-structured work orders, historical question-and-answer pairs, voice recordings and their transcribed text, and on-site photos. The collected multi-source corpora undergo preprocessing, such as unified encoding, removal of control characters and noise, sentence and word segmentation, standardization of professional terminology, extraction of candidate entities, speech-to-text transcription, and image information recognition. Finally, the preprocessed data is used to construct training samples, for example, constructing labeled corpus samples D. L ={(x i ,y i )}, where x i Representative corpus, y i Representing corpus labels, and constructing the unlabeled set D U ={u j}, u j Representative corpus; in some embodiments, the corpus samples are uniformly stored in the form of text + meta-information, and used as input for the data optimization module.
[0157] The data optimization module includes a label fusion module and an adversarial data augmentation module. The label fusion module generates high-quality pseudo-labels by combining unlabeled corpus samples with limited labeled corpus samples, and expands the training set in a credibility-weighted manner, thereby improving the labeling system's coverage and adaptability to domain knowledge.
[0158] In some embodiments, labeled corpus samples D can be used. L Training teacher model f θ(T), the teacher model can be a Transformer-based classification model or an extraction model. Then, the teacher model processes each unlabeled corpus sample u. j ∈D U Predicting Pseudo-Labels And record the confidence level of each pseudo-label. At the same time, a reliability threshold is set. When c j ≥ At that time, Included in the pseudo-label corpus sample set .
[0159] In some embodiments, after obtaining the pseudo-labels corresponding to the unlabeled corpus samples, a corresponding weight value can be assigned to each pseudo-label sample based on the prediction confidence of the pseudo-labels. Samples with higher confidence will have a larger weight in subsequent training. Simultaneously, to avoid individual high-confidence pseudo-labels having an excessive impact on model training, a smoothing coefficient is introduced to adjust the weights, and a weighted loss function is used to optimize the pseudo-label samples during the model training phase. Furthermore, a consistency regularization strategy can be introduced to suppress pseudo-label noise. For example, two different perturbation methods are applied to the same unlabeled sample, such as random data augmentation or random dropout during model inference, to obtain corresponding prediction results. Subsequently, by calculating the difference between the two prediction results, inconsistencies in prediction are penalized, thereby prompting the model to produce consistent prediction results for the same sample under different perturbation conditions, further improving the stability and reliability of pseudo-labels.
[0160] In some embodiments, the set of labeled corpus samples and the set of pseudo-labeled corpus samples can be fused, and a resampling or class reweighting strategy can be used on the mixed data to avoid bias caused by class imbalance.
[0161] In some embodiments, the tag information can be encoded into a vector and fused with the corresponding vector in the corpus to improve the domain matching accuracy during the retrieval stage. This fusion operation can introduce the domain information in the tags into the retrieval model, thereby improving the domain matching accuracy between the corpus text and the user's question.
[0162] Among them, the adversarial data augmentation module is used to enhance the robustness of the retrieval network under complex documents and noisy inputs, and to obtain adversarial corpus samples.
[0163] In some embodiments, adversarial enhancement includes two types of strategies: embedding-level adversarial perturbation and semantic-level enhancement. Embedding-level adversarial perturbation refers to introducing gradient-driven perturbation vectors based on the word vector representation (e) of the input corpus sample x. Generate new adversarial embedding representations .
[0164] In some embodiments, the fast gradient sign method can be used to determine the perturbation vector. ,Right now:
[0165] .
[0166] in, For the disturbance amplitude to exceed the parameter, For loss function, To search the network, This is a sign function used to compress gradients. The input corresponding to the loss function The gradient.
[0167] In other embodiments, projected gradient descent can also be used to determine the perturbation vector. ,Right now:
[0168] .
[0169] in, Let be the perturbation value in the (t+1)th iteration. Let be the perturbation value in the t-th iteration. Step size, This is a projection operator used to project the updated perturbation onto a constraint range. inside, This is a sign function used to compress gradients. The input corresponding to the loss function The gradient.
[0170] In some embodiments, semantic enhancement may include synonym replacement, which uses word vector similarity or a thesaurus to replace some keywords in the text with semantically equivalent words, for example, replacing "power outage accident" with "power failure event"; entity replacement, which replaces entities of the same category, such as replacing "10 kV line" with "35 kV line"; sentence transformation, which maintains semantic integrity and generates variants by adjusting passive or active voice and word order; and backward translation, which translates the text into another language (such as English) and then back into the original language to obtain diverse expressions.
[0171] For example, the original text "A short circuit in the line caused the trip" can be transformed into "The trip was caused by a short circuit in the line", "The equipment tripped because a short circuit occurred in the line", and "The circuit breaker operated because of a short circuit in the line". These semantically equivalent variants can train the model to be robust to different expressions.
[0172] The network optimization module includes retrieval network optimization and suggestion fine-tuning optimization.
[0173] The retrieval network optimization can employ a joint loss function, namely, joint adversarial loss and original supervised loss. The original supervised loss (i.e., the first loss in this application) is: The damages against the claim (i.e., the second loss of this application) are The target loss obtained is ; among which, L sup As the first loss, L adv This is the second loss. These are weighting coefficients; adjusted... This can balance the relationship between the performance of the retrieval network in the original task and its robustness against adversarial attacks.
[0174] The process of fine-tuning and optimization is as follows: Figure 5 As shown, after obtaining the user question Q and knowledge fragment D, the first concatenation is performed using a hard prompt concatenation template. Then, soft prompts are injected to combine hard and soft prompts, achieving efficient semantic alignment between the user question and the knowledge fragment. This improves the model's ability to understand and generate answers for complex power industry documents. The core idea is that hard prompts are responsible for explicitly expressing the logical relationship between the question and the knowledge, while soft prompts are responsible for implicitly guiding the model's parameter space adaptation. Finally, semantic fusion is performed to output high-quality question-and-answer results that conform to semantic constraints.
[0175] The application module is used to perform knowledge retrieval and response generation based on the trained retrieval network and response generation network.
[0176] In some embodiments, after a user inputs a question, the retrieval network needs to quickly locate candidate knowledge fragments related to the question within a pre-built knowledge base. The knowledge base can be sourced from internal enterprise documents, business operation specifications, historical work order records, or authoritative external databases. To improve retrieval efficiency and accuracy, the question and knowledge fragments are first vectorized and mapped to a unified semantic space. This allows the retrieval network to quickly filter out several candidate documents most relevant to the user's question through similarity search. This process ensures that the system does not directly match word-for-word throughout the entire knowledge base, but rather locates information at the semantic level, thereby significantly improving retrieval speed and recall.
[0177] In some embodiments, the candidate documents initially retrieved often contain noise and redundancy, and may not accurately answer the user's question. Therefore, further filtering and ranking of the candidate results are necessary. The system comprehensively considers multiple features, such as semantic similarity, keyword coverage, contextual matching, document authority, and timeliness, to calculate a comprehensive relevance score. Then, a ranking model is used to prioritize the candidate fragments, retaining the most valuable subset of knowledge. This process not only eliminates results with low relevance to the question but also highlights the content that best meets semantic requirements, thereby ensuring more accurate input for subsequent answer generation.
[0178] After obtaining the sorted knowledge fragments, the knowledge fragments and the user's question are input into the response generation model, which has been fine-tuned with prompts. Under the dual constraints of question semantics and knowledge content, the model generates an answer in natural language form.
[0179] Because the results generated by the response generation model may contain redundant or inconsistent information, the answers need to be optimized and validated before final output. Optimization steps include removing duplicate information, merging redundant expressions, and adjusting word order to improve fluency. Simultaneously, a consistency check mechanism can be introduced to ensure that the generated answer is consistent with the knowledge fragment at the factual level. If the check finds contradictions or errors in the generated answer, the system will automatically backtrack to the previous stage and regenerate or adjust the answer. After this process, the final output answer is accurate, reliable, concise, and fluent, directly meeting the user's needs.
[0180] It should be understood that although the steps in the flowcharts of the above embodiments are shown sequentially according to the arrows, these steps are not necessarily executed in the order indicated by the arrows. Unless explicitly stated herein, there is no strict order restriction on the execution of these steps, and they can be executed in other orders. Moreover, at least some steps in the flowcharts of the above embodiments may include multiple steps or multiple stages. These steps or stages are not necessarily completed at the same time, but can be executed at different times. The execution order of these steps or stages is not necessarily sequential, but can be performed alternately or in turn with other steps or at least some of the steps or stages in other steps. It is understood that the steps in different embodiments can be freely combined as needed, and all non-contradictory solutions formed by such combinations are within the scope of protection of this application.
[0181] Based on the same inventive concept, this application also provides a knowledge retrieval and question-answer generation apparatus for implementing the knowledge retrieval and question-answer generation method described above. The solution provided by this apparatus is similar to the solution described in the above method; therefore, the specific limitations of one or more knowledge retrieval and question-answer generation apparatus embodiments provided below can be found in the limitations of the knowledge retrieval and question-answer generation method described above, and will not be repeated here.
[0182] In one exemplary embodiment, such as Figure 6 As shown, a schematic diagram of a knowledge retrieval and question-answering generation device is provided. The knowledge retrieval and question-answering generation device 500 includes:
[0183] Module 501 is used to retrieve the content of the question.
[0184] The retrieval module 502 is used by a pre-trained retrieval network to perform knowledge retrieval in the knowledge base based on the question content, and obtain candidate knowledge fragments.
[0185] The hard hint fine-tuning module 503 is used to combine the question content and candidate knowledge fragments based on a preset hard hint template to obtain hard hint content.
[0186] The soft prompt fine-tuning module 504 is used to obtain the fused question content based on the hard prompt content and the target soft prompt corresponding to the pre-trained response generation network.
[0187] The output module 505 is used to generate the target response content by the response generation network based on the fused question content.
[0188] In one embodiment, the knowledge retrieval and question answering generation device 500 further includes a first training module, configured to: acquire labeled corpus samples and unlabeled corpus samples; perform label fusion based on the labeled corpus samples and unlabeled corpus samples to obtain pseudo-labeled corpus samples; perform adversarial enhancement processing based on the labeled corpus samples and pseudo-labeled corpus samples to obtain adversarial corpus samples; have the retrieval network to be trained perform label prediction based on the labeled corpus samples and adversarial corpus samples to determine the target loss; and adjust the parameters of the retrieval network to be trained based on the target loss until a first training termination condition is met to obtain the trained retrieval network.
[0189] In one embodiment, the first training module is specifically configured to: perform label prediction on labeled corpus samples by the retrieval network to be trained, to obtain a first predicted label for the labeled corpus samples; determine a first loss based on the first predicted label and the labels contained in the labeled corpus samples; perform label prediction on adversarial corpus samples by the retrieval network to be trained, to obtain a second predicted label for the adversarial corpus samples; determine a second loss based on the second predicted label and the labels contained in the adversarial corpus samples; and perform a weighted summation of the first loss and the second loss to obtain a target loss.
[0190] In one embodiment, the retrieval module 502 is specifically used to: predict the tags of the question content using a retrieval network to obtain question content tags; and determine candidate knowledge segments from multiple knowledge segments in the knowledge base based on the distance between the question content tags and the knowledge tags corresponding to each of the multiple knowledge segments in the knowledge base; wherein the knowledge tags corresponding to each of the multiple knowledge segments in the knowledge base are obtained by the retrieval network through tag prediction.
[0191] In one embodiment, the knowledge retrieval and question-answering generation device 500 further includes a second training module, used to: acquire sample question content, reference knowledge fragments of the sample question content, and reference answer content; wherein the reference knowledge fragments are determined by the retrieval network based on the sample question content; combine the sample question content and the reference knowledge fragments based on a preset hard hint template to obtain sample hard hint content; determine sample fusion question content based on the sample hard hint content and the target soft hints corresponding to the answer generation network; generate a predicted answer content by the answer generation network to be trained based on the sample fusion question content; determine the answer loss based on the target soft hints, the predicted answer content, the reference answer content, and the reference knowledge fragments; and adjust at least one parameter of the answer generation network to be trained, the target soft hints, and the retrieval network based on the answer loss until a second training termination condition is met to obtain the trained answer generation network.
[0192] In one embodiment, the second training module is specifically used to: determine the generation loss based on the predicted response content and the reference response content; determine the soft prompt loss based on the target soft prompt; determine the consistency loss based on the predicted response content and the reference knowledge fragment; and obtain the response loss by performing a weighted summation of the response loss, the soft prompt loss, and the consistency loss.
[0193] Each module in the aforementioned knowledge retrieval and question-answering generation device can be implemented entirely or partially through software, hardware, or a combination thereof. These modules can be embedded in or independent of the processor in a computer device, or stored in the memory of a computer device as software, so that the processor can call and execute the operations corresponding to each module.
[0194] In one exemplary embodiment, a computer device is provided, which may be a server, and its internal structure diagram may be as follows: Figure 7As shown, this computer device includes a processor, memory, input / output (I / O) interfaces, and a communication interface. The processor, memory, and I / O interfaces are connected via a system bus, and the communication interface is also connected to the system bus via the I / O interfaces. The processor provides computational and control capabilities. The memory includes non-volatile storage media and internal memory. The non-volatile storage media stores the operating system, computer programs, and a database. The internal memory provides the environment for the operation of the operating system and computer programs stored in the non-volatile storage media. The database stores data involved in knowledge retrieval and question-answering generation. The I / O interfaces are used for exchanging information between the processor and external devices. The communication interface is used for communication with external terminals via a network connection. When the computer program is executed by the processor, it implements a knowledge retrieval and question-answering generation method.
[0195] Those skilled in the art will understand that Figure 7 The structure shown is merely a block diagram of a portion of the structure related to the present application and does not constitute a limitation on the computer device to which the present application is applied. Specific computer devices may include more or fewer components than those shown in the figure, or combine certain components, or have different component arrangements.
[0196] In one exemplary embodiment, a computer device is provided, including a memory and a processor, wherein the memory stores a computer program, and the processor executes the computer program to implement the steps of the method described above.
[0197] In one embodiment, a computer-readable storage medium is provided having a computer program stored thereon, which, when executed by a processor, implements the steps of the above-described method.
[0198] In one embodiment, a computer program product is provided, including a computer program that, when executed by a processor, implements the steps of the method described above.
[0199] It should be noted that the user information (including but not limited to user device information, user personal information, etc.) and data (including but not limited to data used for analysis, data stored, data displayed, etc.) involved in this application are all information and data authorized by the user or fully authorized by all parties, and the collection, use and processing of the relevant data must comply with relevant regulations.
[0200] Those skilled in the art will understand that all or part of the processes in the methods of the above embodiments can be implemented by a computer program instructing related hardware. The computer program can be stored in a non-volatile computer-readable storage medium, and when executed, it can include the processes of the embodiments of the above methods. Any references to memory, databases, or other media used in the embodiments provided in this application can include at least one of non-volatile memory and volatile memory. Non-volatile memory can include read-only memory (ROM), magnetic tape, floppy disk, flash memory, optical memory, high-density embedded non-volatile memory, resistive random access memory (ReRAM), magnetic random access memory (MRAM), ferroelectric random access memory (FRAM), phase change memory (PCM), graphene memory, etc. Volatile memory can include random access memory (RAM) or external cache memory, etc. By way of illustration and not limitation, RAM can take many forms, such as Static Random Access Memory (SRAM) or Dynamic Random Access Memory (DRAM). The databases involved in the embodiments provided in this application may include at least one type of relational database and non-relational database. Non-relational databases may include, but are not limited to, blockchain-based distributed databases. The processors involved in the embodiments provided in this application may be general-purpose processors, central processing units, graphics processing units, digital signal processors, programmable logic devices, quantum computing-based data processing logic devices, artificial intelligence (AI) processors, etc., and are not limited to these.
[0201] The technical features of the above embodiments can be combined in any way. For the sake of brevity, not all possible combinations of the technical features in the above embodiments are described. However, as long as there is no contradiction in the combination of these technical features, they should be considered to be within the scope of this application.
[0202] The embodiments described above are merely illustrative of several implementation methods of this application, and while the descriptions are specific and detailed, they should not be construed as limiting the scope of this patent application. It should be noted that those skilled in the art can make various modifications and improvements without departing from the concept of this application, and these all fall within the protection scope of this application. Therefore, the protection scope of this application should be determined by the appended claims.
Claims
1. A knowledge retrieval and question-answering generation method, characterized in that, The method includes: Get the question content; The pre-trained retrieval network performs knowledge retrieval in the knowledge base based on the question content to obtain candidate knowledge fragments; Based on a preset hard hint template, the question content and the candidate knowledge fragments are combined to obtain hard hint content; Based on the hard prompts and the target soft prompts corresponding to the pre-trained response generation network, the fused question content is obtained; The response generation network generates a response based on the fused question content to obtain the target response content.
2. The method according to claim 1, characterized in that, The training process of the retrieval network includes: Obtain labeled and unlabeled language samples; Based on the labeled corpus samples and the unlabeled corpus samples, label fusion is performed to obtain pseudo-labeled corpus samples; Based on the labeled corpus samples and the pseudo-labeled corpus samples, adversarial enhancement processing is performed to obtain adversarial corpus samples; The retrieval network to be trained performs label prediction based on the labeled corpus samples and the adversarial corpus samples to determine the target loss; The parameters of the retrieval network to be trained are adjusted based on the target loss until the first training termination condition is met, thereby obtaining the trained retrieval network.
3. The method according to claim 2, characterized in that, The retrieval network to be trained performs label prediction based on the labeled corpus samples and the adversarial corpus samples, and determines the target loss, including: The retrieval network to be trained performs label prediction based on the labeled corpus samples to obtain the first predicted label of the labeled corpus samples; Based on the first predicted label and the labels contained in the labeled corpus samples, a first loss is determined; The retrieval network to be trained performs label prediction based on the adversarial corpus samples to obtain the second predicted label of the adversarial corpus samples; Based on the second predicted label and the labels contained in the adversarial corpus samples, a second loss is determined; The target loss is obtained by weighted summation of the first loss and the second loss.
4. The method according to claim 1, characterized in that, The pre-trained retrieval network performs knowledge retrieval in the knowledge base based on the question content to obtain candidate knowledge fragments, including: The retrieval network performs tag prediction on the question content to obtain question content tags; Based on the distance between the question content tags and the knowledge tags corresponding to each of the multiple knowledge segments in the knowledge base, candidate knowledge segments are determined from the multiple knowledge segments in the knowledge base; The knowledge tags corresponding to each of the multiple knowledge fragments in the knowledge base are obtained by the retrieval network through tag prediction.
5. The method according to claim 1, characterized in that, The training process of the response generation network includes: The system obtains sample question content, reference knowledge fragments of the sample question content, and reference answer content; wherein, the reference knowledge fragments are determined by the retrieval network based on the sample question content. Based on a preset hard prompt template, the sample question content and the reference knowledge fragment are combined to obtain the sample hard prompt content; Based on the hard prompts in the samples and the target soft prompts corresponding to the response generation network, the content of the sample fusion question is determined. The response generation network to be trained generates a response based on the sample fusion question content to obtain the predicted response content; Based on the target soft prompt, the predicted response content, the reference response content, and the reference knowledge fragment, determine the response loss; Based on the response loss, at least one parameter of the response generation network to be trained, the target soft prompt, and the retrieval network is adjusted until the second training termination condition is met, resulting in the trained response generation network.
6. The method according to claim 5, characterized in that, The step of determining the response loss based on the target soft prompt, the predicted response content, the reference response content, and the reference knowledge fragment includes: Based on the predicted response content and the reference response content, the generation loss is determined; Based on the target soft cue, determine the soft cue loss; Based on the predicted response content and the reference knowledge fragment, determine the consistency loss; The response loss is obtained by weighted summation of the response loss, the soft hint loss, and the consistency loss.
7. A knowledge retrieval and question-answering generation device, characterized in that, The device includes: The retrieval module is used to retrieve the content of the question. The retrieval module is used to perform knowledge retrieval in the knowledge base based on the question content by a pre-trained retrieval network to obtain candidate knowledge fragments; The hard hint fine-tuning module is used to combine the question content and the candidate knowledge fragments based on a preset hard hint template to obtain hard hint content; The soft prompt fine-tuning module is used to obtain the fused question content by generating the target soft prompt based on the hard prompt content and the pre-trained response generation network. The output module is used to generate a response from the response generation network based on the fused question content, thereby obtaining the target response content.
8. A computer device comprising a memory and a processor, wherein the memory stores a computer program, characterized in that, When the processor executes the computer program, it implements the steps of the method according to any one of claims 1 to 6.
9. A computer-readable storage medium having a computer program stored thereon, characterized in that, When the computer program is executed by a processor, it implements the steps of the method according to any one of claims 1 to 6.
10. A computer program product, comprising a computer program, characterized in that, When the computer program is executed by a processor, it implements the steps of the method according to any one of claims 1 to 6.