Knowledge-enhanced question-answering method based on large language model and electronic equipment
Through knowledge-enhanced question-and-answer methods based on large language models, segment and vectorize knowledge text data, and fine-tune the model to generate accurate knowledge answers, solving the problems of inefficient search and inaccurate answers in the prior art, achieving more efficient and accurate knowledge acquisition.
Patent Information
- Application Number
- CN202411911823.X
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-12-24
- Publication Date
- 2025-04-25
- Estimated Expiration
- 2044-12-24
AI Technical Summary
The existing technology has problems such as inefficient search efficiency and inaccurate generation of answers in professional knowledge management and acquisition, mainly because direct vectorized matching is difficult to explore the deep meaning of the problem, and the lack of professional understanding of open source models.
The knowledge-enhanced question-and-answer method based on a large language model is adopted. By obtaining original knowledge text data, segmenting it into multiple knowledge text blocks, extracting keywords and vectorizing them, generating relevant knowledge questions and reference answers, and fine-tuning the keyword extraction model and knowledge question-and-answer model to improve the accuracy of the answers.
It effectively improves the accuracy of generating target knowledge answers, reduces data redundancy, improves data processing speed and accuracy, and reduces storage costs.
Smart Images

Figure CN119884309A_ABST
Abstract
Description
Technical Field
[0001] The present disclosure relates to the field of computer technology, and in particular to a knowledge-enhanced question-answering method and electronic device based on a large language model. Background Art
[0002] In practical applications, professional knowledge management and acquisition are key links in the development of modern society. In related technologies, professional knowledge is usually included in the knowledge base, and the relevant professional knowledge is obtained by directly matching the question with the professional knowledge in the knowledge base through vectorization, and then the open source big model is used to organize and generate the answer to the question. However, the direct vectorization matching method is prone to obtain a large amount of similar and incompletely related texts, and the existing open source big models lack an in-depth understanding of professional field knowledge, resulting in low retrieval efficiency and inaccurate generated answers. Summary of the invention
[0003] The following is a summary of the subject matter of the detailed description of the present disclosure. This summary is not intended to limit the scope of the claims.
[0004] The disclosed embodiment provides a knowledge-enhanced question-answering method based on a large language model, which effectively improves the accuracy of generating target knowledge answers.
[0005] On the one hand, the present disclosure provides a knowledge-enhanced question-answering method based on a large language model, including: Acquire original knowledge text data, and obtain initial knowledge text data based on the original knowledge text data; The initial knowledge text data is segmented to obtain a plurality of knowledge text blocks, knowledge text keywords in the knowledge text blocks are extracted, and the knowledge text keywords are vectorized to obtain knowledge text keyword vectors, wherein the knowledge text blocks contain rich context information, and knowledge questions related to the knowledge text blocks and reference knowledge answers corresponding to the knowledge questions are generated based on the knowledge text blocks; Extracting question keywords from the knowledge question, fine-tuning a keyword extraction model based on the question keywords, and fine-tuning a knowledge question answering model based on the knowledge question and the reference knowledge answer, wherein when fine-tuning the knowledge question answering model, the knowledge question answering model is also fine-tuned based on self-cognition data, and the self-cognition data is used to shape the identity cognition of the knowledge question answering model; A query question keyword vector corresponding to the query question keyword of the query question is generated according to the fine-tuned keyword extraction model, and a candidate knowledge text block related to the query question is determined according to the query question keyword vector and the knowledge text keyword vector, so that the fine-tuned knowledge question and answer model generates a target knowledge answer corresponding to the query question based on the candidate knowledge text block.
[0006] On the other hand, an embodiment of the present disclosure further provides an electronic device, including a memory and a processor, wherein the memory stores a computer program, and the processor implements the above-mentioned knowledge-enhanced question-answering method based on a large language model when executing the computer program.
[0007] The disclosed embodiments include at least the following beneficial effects: obtaining original knowledge text data, obtaining initial knowledge text data based on the original knowledge text data, segmenting the initial knowledge text data to obtain multiple knowledge text blocks, extracting knowledge text keywords in the knowledge text blocks, vectorizing the knowledge text keywords, and obtaining knowledge text keyword vectors; streamlining data content by segmenting the initial knowledge text data and then performing keyword extraction, thereby helping to reduce data redundancy and improve the accuracy of subsequent matching; further, converting knowledge text keywords into a vector form suitable for data processing, thereby improving the speed and accuracy of data processing while reducing storage costs; generating knowledge questions related to the knowledge text blocks and knowledge question responses based on the knowledge text blocks; Based on the corresponding reference knowledge answers, question keywords are extracted from knowledge questions, and the keyword extraction model is fine-tuned based on the question keywords. The knowledge question and answer model is fine-tuned based on the knowledge questions and reference knowledge answers, so that the model can learn the associations and rules between knowledge questions and question keywords, and between knowledge questions and reference knowledge answers. On this basis, the question keyword vector corresponding to the query question keywords of the query question is generated according to the fine-tuned keyword extraction model, and the candidate knowledge text blocks related to the query question are determined according to the question keyword vector and the knowledge text keyword vector, so that the fine-tuned knowledge question and answer model generates the target knowledge answer corresponding to the query question based on the candidate knowledge text blocks, which effectively improves the accuracy of generating the target knowledge answer.
[0008] Other features and advantages of the present disclosure will be set forth in the following description, and in part will be apparent from the description, or may be learned by practicing the present disclosure. BRIEF DESCRIPTION OF THE DRAWINGS
[0009] The accompanying drawings are used to provide further understanding of the technical solution of the present disclosure and constitute a part of the specification. Together with the embodiments of the present disclosure, they are used to explain the technical solution of the present disclosure and do not constitute a limitation on the technical solution of the present disclosure.
[0010] Figure 1A schematic diagram of an optional implementation environment provided for an embodiment of the present disclosure; Figure 2 An optional flowchart of a knowledge-enhanced question-answering method based on a large language model provided in an embodiment of the present disclosure; Figure 3 An optional schematic diagram of a vector database structure provided in an embodiment of the present disclosure; Figure 4 An optional flow chart of fine-tuning a model provided in an embodiment of the present disclosure; Figure 5 An optional flow chart of generating target knowledge answers provided by an embodiment of the present disclosure; Figure 6 An optional overall process of fine-tuning training for the knowledge-enhanced question-answering method based on a large language model provided in an embodiment of the present disclosure; Figure 7 An optional schematic diagram of generating target knowledge answers by the knowledge question answering model provided in an embodiment of the present disclosure. DETAILED DESCRIPTION
[0011] In order to make the purpose, technical solution and advantages of the present disclosure more clear, the present disclosure is further described in detail below in conjunction with the accompanying drawings and embodiments. It should be understood that the specific embodiments described herein are only used to explain the present disclosure and are not used to limit the present disclosure.
[0012] It should be noted that in various specific embodiments of the present disclosure, when it comes to the need to perform relevant processing based on data related to the characteristics of the target object such as the target object attribute information or attribute information set, the permission or consent of the target object will be obtained first, and the collection, use and processing of these data will comply with relevant laws, regulations and standards. Among them, the target object can be a user. In addition, when the embodiment of the present disclosure needs to obtain the attribute information of the target object, the separate permission or separate consent of the target object will be obtained through a pop-up window or by jumping to a confirmation page. After clearly obtaining the separate permission or separate consent of the target object, the necessary target object-related data used to enable the normal operation of the embodiment of the present disclosure will be obtained.
[0013] In the embodiments of the present disclosure, the term "module" or "unit" refers to a computer program or a part of a computer program that has a predetermined function and works together with other related parts to achieve a predetermined goal, and can be implemented in whole or in part by using software, hardware (such as processing circuits or memories), or a combination thereof. Similarly, a processor (or multiple processors or memories) can be used to implement one or more modules or units. In addition, each module or unit can be part of an overall module or unit that includes the function of the module or unit.
[0014] To facilitate understanding of the technical solution provided by the embodiments of the present disclosure, some key terms used in the embodiments of the present disclosure are explained here: Knowledge question-answering model: uses natural language processing technology, deep learning technology, and a large knowledge base or corpus to understand, analyze, and answer natural language questions raised by users. This model can simulate human question-answering behavior and achieve efficient and accurate information acquisition and communication.
[0015] Back propagation operation: Using the chain rule, the gradients of the network parameters of the neural network are calculated layer by layer, and these gradients are used to update the network parameters.
[0016] Low rank matrix: A low rank matrix is a matrix whose rank is relatively low, that is, the rank of the matrix is much smaller than the smaller of its number of rows and columns.
[0017] BGE embedding model: is a text embedding model that is mostly used in natural language processing tasks. It aims to convert text into vector representation and simplify the calculation and analysis process.
[0018] In practical applications, professional knowledge management and professional knowledge acquisition are key links in the development of modern society. At present, professional knowledge is usually generated by directly vectorizing and matching questions with professional knowledge in the knowledge base, and then using the answer generation function of the open source big model to generate answers. However, users' query questions are usually relatively short, making it difficult for the direct vectorization matching method to fully explore the deep meaning behind the question, and it is easy to obtain a large number of similar and incompletely related texts. At the same time, the existing open source big models are mainly trained based on general domain data, lacking an in-depth understanding of professional domain knowledge. When generating answers, it is difficult to generate systematic answers based on professional knowledge, resulting in the lack of reliability and accuracy of the generated answers.
[0019] Based on this, the embodiments of the present disclosure provide a knowledge-enhanced question-answering method based on a large language model, which effectively improves the accuracy of generating target knowledge answers.
[0020] Reference Figure 1 , Figure 1A schematic diagram of an optional implementation environment provided for an embodiment of the present disclosure, the implementation environment includes a terminal 101. Specifically, original knowledge text data is obtained in the terminal 101, initial knowledge text data is obtained based on the original knowledge text data, the initial knowledge text data is segmented to obtain multiple knowledge text blocks, knowledge text keywords in the knowledge text blocks are extracted, the knowledge text keywords are vectorized to obtain knowledge text keyword vectors, and then, knowledge questions related to the knowledge text blocks and reference knowledge answers corresponding to the knowledge questions are generated based on the knowledge text blocks. Question keywords are extracted from the knowledge questions, the keyword extraction model is fine-tuned based on the question keywords, the knowledge question and answer model is fine-tuned based on the knowledge questions, the reference knowledge answers and the self-cognition data, the query question keyword vector corresponding to the query question keyword of the query question is generated according to the fine-tuned keyword extraction model, the candidate knowledge text blocks related to the query question are determined according to the query question keyword vector and the knowledge text keyword vector, so that the fine-tuned knowledge question and answer model generates the target knowledge answer corresponding to the query question based on the candidate knowledge text blocks, and the target knowledge answer is displayed on the display page of the terminal 101.
[0021] It is understandable that the above process of generating target knowledge answers can also be carried out in the server, by obtaining original knowledge text data in terminal 101, uploading the original knowledge text data to the server, performing steps such as keyword extraction, keyword vectorization, and fine-tuning the model in the server to generate target knowledge answers, sending the target knowledge answers to terminal 101, and displaying the target knowledge answers on the display page of terminal 101.
[0022] Reference Figure 2 , Figure 2 An optional flow chart of a knowledge-enhanced question-answering method based on a large language model provided in an embodiment of the present disclosure may specifically include but not be limited to the following steps S201 to S204: Step S201: Acquire original knowledge text data, and obtain initial knowledge text data based on the original knowledge text data.
[0023] Specifically, the original knowledge text data is the knowledge text knowledge in the professional field obtained from the open world knowledge source, and the initial knowledge text data is the original knowledge text data after data processing. The original knowledge text data is obtained from the open world knowledge source, and the original knowledge text data is processed, which can be processed by manual cleaning or by using a general large model. In the process of data preprocessing, the noise information of the original knowledge text data is first removed. The noise information includes information irrelevant to professional field knowledge, text format errors, non-standard language, etc. Then, the repeated or similar knowledge texts in the original knowledge text data with noise information removed are merged. When merging, the most complete and representative content can be selected for merging, or repeated content can be extracted for integration, while retaining their different contents. By processing the original knowledge text data, the accuracy and conciseness of the knowledge text data can be improved, and the interference of irrelevant content on the generated results can be avoided.
[0024] Next, the original knowledge text data after data processing is classified according to the knowledge content, and the knowledge text data with the same knowledge content is divided into the same independent document, and finally multiple independent documents storing different knowledge contents are obtained, and these independent documents are used as the initial knowledge text data. For example, the knowledge content of the original knowledge text data after data processing includes the planting of apple trees, the causes of apple tree diseases, the prevention and control measures of apple trees, the planting of rice, and the prevention and control measures of grapevines. According to the knowledge content, the planting of apple trees, the causes of apple tree diseases, and the prevention and control measures of apple trees can be divided into document A, the planting of rice can be divided into document B, and the prevention and control measures of grapevines can be divided into document C, and 3 independent documents can be obtained as the initial knowledge text data.
[0025] It should also be noted that, in addition to classifying the original knowledge text data according to the knowledge content, data can also be divided according to rules such as knowledge type, which is not specifically limited in this application. In order to ensure the security of the knowledge text data, the initial knowledge text data can be saved and backed up, which is convenient for inspection and recovery when data corruption occurs during operation; or when new original knowledge text data is collected, it can effectively prevent the risk of data loss caused by the historical initial knowledge text data being overwritten by the new initial knowledge text data, further ensuring the integrity of the initial knowledge text data.
[0026] Step S202: Segment the initial knowledge text data to obtain a plurality of knowledge text blocks, extract knowledge text keywords from the knowledge text blocks, vectorize the knowledge text keywords, and obtain knowledge text keyword vectors.
[0027] Among them, the knowledge text keyword vector contains the semantic information of the knowledge text keywords, which is used for vector matching in vector retrieval; the knowledge text block contains rich contextual information. The knowledge text block can be a text paragraph, a sentence, or a phrase. Based on the knowledge text block, knowledge questions related to the knowledge text block and reference knowledge answers corresponding to the knowledge questions are generated.
[0028] In one possible implementation, the initial knowledge text data is segmented to obtain a plurality of knowledge text blocks, and the knowledge text blocks are input into a universal large language model so that the universal large language model generates knowledge text keywords corresponding to each knowledge text block, and the knowledge text keywords are vectorized to obtain knowledge text keyword vectors.
[0029] Specifically, the knowledge text data of each document in the initial knowledge text data is segmented according to the text title, paragraph, punctuation or semantic information to obtain multiple knowledge text blocks. The knowledge text blocks are input into the general large language model, and the keyword generation task based on the general large language model generates multiple corresponding knowledge text keywords for each knowledge text block. Finally, the knowledge text keywords are vectorized to obtain knowledge text keyword vectors. By segmenting the initial knowledge text data into multiple knowledge text blocks, the content of the knowledge text blocks is made more targeted, thereby effectively improving the efficiency and accuracy of retrieval. Based on this, the knowledge question and answer model can generate more accurate answers based on the retrieved knowledge text blocks, effectively improving the response speed of the knowledge question and answer model and the quality of generated answers.
[0030] In one possible implementation, the knowledge text keywords are converted into vector representations based on a text embedding model to obtain knowledge text keyword vectors. Specifically, the text embedding model is used to convert text data into vector representations, and the text embedding model may be a BGE embedding model. The knowledge text keywords are input into the text embedding model, and vector calculations are performed on the encoded knowledge text keywords to obtain knowledge text keyword vectors that can capture the semantic information of the knowledge text keywords, wherein the vector dimension of the knowledge text keyword vector may be 1024. By vectorizing the knowledge text keywords, not only can the deep semantic information of the knowledge text keywords be captured, but also the knowledge text keywords can be converted into numerical forms that can be efficiently processed by computers, so that the knowledge text keyword vectors can perform complex query and retrieval operations, effectively improving the speed and accuracy of vector retrieval. In a possible implementation, after the knowledge text keywords are vectorized to obtain the knowledge text keyword vector, the knowledge text block, the knowledge text keywords, and the knowledge text keyword vector can be stored in a vector database, so that the vector database assigns a corresponding vector identifier to the knowledge text keyword vector. The vector identifier is a unique identifier for each vector data, which is used to mark and distinguish each vector data; the vector data is vectorized data, including the knowledge text keyword vector and the knowledge text block vector; the vector database is used to store and retrieve the vector data, and can be a custom-built database or a Milvus database.
[0031] Specifically, the knowledge text blocks, knowledge text keywords, and knowledge text keyword vectors are stored in a vector database, and a corresponding keyword vector identifier is assigned to each knowledge text keyword vector in the vector database to distinguish each knowledge text keyword vector. Figure 3 , Figure 3 An optional schematic diagram of a vector database structure provided for an embodiment of the present disclosure. When searching in a vector database, the corresponding knowledge text keywords are obtained by matching with the knowledge text keyword vector, and the corresponding knowledge text block is found according to the knowledge text keyword. Alternatively, when storing the knowledge text block in a vector database, the knowledge text block can also be converted into a knowledge text block vector through a text embedding model, and the corresponding text block vector identifier is assigned to the knowledge text block vector, and the text block vector identifier, the knowledge text keyword, and the knowledge text keyword vector are associated. When searching in a vector database, the corresponding knowledge text keyword is obtained by matching with the knowledge text keyword vector, and the corresponding text block vector identifier is found according to the knowledge text keyword, and then the corresponding knowledge text block is retrieved according to the text block vector identifier. Since the vector database has good scalability, the vector database can cope with the growth of the amount of stored data, ensuring the smoothness and security of the storage of data such as knowledge text blocks. In addition, since vector data can capture the deep semantic information and contextual information of knowledge text data, vector retrieval through a vector database can effectively improve the accuracy of retrieval. In addition, vector databases have the ability to process multiple data items simultaneously. This capability reduces the computational complexity of the retrieval process, effectively improves the retrieval speed, and thus optimizes the response speed of the knowledge question-answering model.
[0032] After obtaining the knowledge text blocks through segmentation, the knowledge text blocks are input into the general large language model. Based on the question generation task of the general large language model, at least one corresponding knowledge question is generated for each knowledge text block, and corresponding knowledge answers are formed according to the generated knowledge questions. The knowledge answers are used as reference knowledge answers for model fine-tuning in subsequent steps.
[0033] Step S203: extract question keywords from the knowledge questions, fine-tune the keyword extraction model based on the question keywords, and fine-tune the knowledge question answering model based on the knowledge questions and reference knowledge answers.
[0034] Among them, the keyword extraction model is a pre-trained model used to extract keywords from query questions, and can be a large language model based on text processing; the knowledge question answering model is a pre-trained model used to generate target knowledge answers corresponding to query questions, and can be a generative language model. When fine-tuning the knowledge question answering model, the knowledge question answering model is also fine-tuned based on self-cognition data. The self-cognition data provides dialogue data in a professional question-answering style, which is used to shape the identity cognition of the knowledge question answering model.
[0035] Reference Figure 4 , Figure 4 An optional flow chart of fine-tuning a model provided in an embodiment of the present disclosure, when the pre-trained model is a keyword extraction model, the input data is question keywords, and the keyword extraction model is fine-tuned based on the fine-tuning module to obtain a fine-tuned keyword extraction model. When the pre-trained model is a knowledge question and answer model, the input data is knowledge questions, reference knowledge answers, and self-cognition data, and the knowledge question and answer model is fine-tuned based on the fine-tuning module to obtain a fine-tuned knowledge question and answer model.
[0036] In a possible implementation, the fine-tuning of the knowledge question-answering model is also based on self-cognition data. In the process of fine-tuning the model, it can be specifically inputting knowledge questions into a general large language model so that the general large language model generates question keywords based on the knowledge questions, fine-tuning the keyword extraction model based on the question keywords, fine-tuning the generated content of the knowledge question-answering model based on the knowledge questions and reference knowledge answers, and fine-tuning the interactive identity of the knowledge question-answering model based on the self-cognition data. Specifically, a keyword generation task is constructed in the general large language model, the knowledge questions are input into the general large language model, a plurality of relevant question keywords are generated for the knowledge questions, and the keyword extraction model is fine-tuned based on the generated question keywords. In order to further improve the extraction ability of the keyword extraction model so that it can more accurately capture the keywords that reflect the core information of the text content, in addition to fine-tuning using question keywords, the keyword extraction model can also be fine-tuned in combination with question keywords and knowledge text keywords, so that the keyword extraction model can better understand the intrinsic connection between question keywords and knowledge text keywords, thereby improving the accuracy of the keyword extraction model when extracting keywords.
[0037] Among them, in order to ensure that the generated question keywords are highly relevant to the knowledge questions, the generated question keywords can be verified through manual review, or the semantic similarity between the knowledge questions and the question keywords can be evaluated through a large language model to determine the correlation between the knowledge questions and the question keywords.
[0038] Next, the knowledge questions and reference knowledge answers are input into the knowledge question and answer model for fine-tuning, so that the knowledge question and answer model can learn the intrinsic connection between the knowledge questions and the reference knowledge answers, and adjust the generated answer content based on this. Then, the self-cognition data is input into the knowledge question and answer model for fine-tuning, so that the knowledge question and answer model shapes the model identity cognition based on the self-cognition data, thereby determining the interactive identity of the knowledge question and answer model. When the knowledge question and answer model generates answers related to knowledge questions, it can generate professional and complete knowledge answers based on the model identity cognition; or, when the knowledge question and answer model generates answers about its own information, it can provide consistent and expected answers. The knowledge question and answer model is fine-tuned through self-cognition data, so that the knowledge question and answer model can form a stable self-cognition, thereby improving the professionalism and accuracy of generating target knowledge answers, and enhancing the interactive experience of the knowledge question and answer model. Furthermore, the knowledge question and answer model is fine-tuned in both directions through knowledge question and answer data and self-cognition data, so that the knowledge question and answer model can adapt to various types of knowledge answers, effectively improving the practicality of the knowledge question and answer model.
[0039] It should also be noted that a knowledge question and answer dataset can be constructed based on knowledge questions and reference knowledge answers, and a self-cognition dataset can be constructed based on self-cognition data. When fine-tuning the knowledge question and answer model, the knowledge question and answer dataset can be used to independently fine-tune the knowledge question and answer model, and then the self-cognition dataset can be used to fine-tune the knowledge question and answer model on this basis to obtain the final fine-tuned knowledge question and answer model; alternatively, the knowledge question and answer model can be jointly fine-tuned using the knowledge question and answer dataset and the self-cognition dataset.
[0040] It should also be noted that when fine-tuning the keyword extraction model and the knowledge question and answer model, the keyword extraction model and the knowledge question and answer model can be fine-tuned independently, or the keyword extraction model and the knowledge question and answer model can be fine-tuned jointly. The fine-tuning method can be adjusted according to actual conditions, and this application does not make any specific limitations.
[0041] In one possible implementation, the keyword extraction model includes a plurality of first processing blocks cascaded in sequence, the first processing block including a fine-tuning module. In the process of fine-tuning the problem keywords, the problem keywords can be specifically input into the keyword extraction model. For the first round, the first weight parameters of the fine-tuning modules corresponding to each first processing block are obtained based on a back-propagation operation, the keyword extraction model is trained for the next round based on the first weight parameters, the second weight parameters of the fine-tuning modules corresponding to each first processing block in the next round are obtained based on a back-propagation operation, and the keyword extraction model is continuously trained based on the second weight parameters until a fine-tuned keyword extraction model is obtained after a predetermined number of iterations.
[0042] Specifically, the problem keywords are input into the keyword extraction model, and for the first round, the output of the keyword extraction model in the first round is obtained. Based on the output of the first round, a back propagation operation is performed to update the weights of the fine-tuning modules corresponding to each first processing block to obtain a first weight parameter. The keyword extraction model is trained for the next round based on the first weight parameter, and based on the output of the next round, a back propagation operation is performed to update the weights of the fine-tuning modules corresponding to each first processing block to obtain a second weight parameter. The keyword extraction model is continued to be trained based on the second weight parameter until a fine-tuned keyword extraction model is obtained after completing a predetermined number of iterations. The keyword extraction model is fine-tuned based on the weight parameters updated by the fine-tuning module, so that the keyword extraction model can better adapt to the data distribution and characteristics of the problem keywords, thereby improving the accuracy and generalization of the keyword extraction model.
[0043] In one possible implementation, the fine-tuning module includes at least one trainable weight matrix. Before obtaining the first weight parameters of the fine-tuning module corresponding to each first processing block based on the back-propagation operation, the original weight matrix of the first processing block can be obtained, decomposed based on the original weight matrix to obtain the first trainable weight matrix and the second trainable weight matrix of the fine-tuning module, feature extraction is performed on the question keyword to obtain the first embedded feature, the first embedded feature is input into the first first processing block of the keyword extraction model, the first embedded feature is reduced in dimension by the first trainable weight matrix to obtain the first intermediate feature, the first intermediate feature is increased in dimension by the second trainable weight matrix to obtain the second intermediate feature with the same output dimension as the original weight matrix, the third intermediate feature output by the fine-tuning module is determined according to the sum of the original feature of the original weight matrix and the second intermediate feature, the first intermediate output of the first first processing block is obtained based on the third intermediate feature, and the first intermediate output is input into the next first processing block until the first output feature of the keyword extraction model in the current round is obtained. Among them, the original weight matrix is the weight matrix of the pre-trained keyword extraction model. During the fine-tuning process of the keyword extraction model, the original weight matrix in each first processing block is in a frozen state, and the keyword extraction model is fine-tuned by updating the trainable weight matrix of the fine-tuning module in each first processing block; the trainable weight matrix is a matrix that can update weight parameters, which is used to fine-tune the keyword extraction model, and can be a low-rank matrix.
[0044] Specifically, the original weight matrix of the first processing block is obtained, and the original weight matrix is low-rank decomposed to decompose the high-dimensional, dense original weight matrix into a low-dimensional, sparse first trainable weight matrix and a second trainable weight matrix. The question keywords are input into the keyword extraction model for feature extraction to obtain the first embedded feature, and the first embedded feature is input into the first first processing block. In the first first processing block, the first embedded feature is reduced in dimension by the first trainable weight matrix to obtain the first intermediate feature, and then the first intermediate feature is increased in dimension by the second trainable weight matrix to obtain the second intermediate feature with the same output dimension as the original weight matrix. It should be noted that there may be other processing layers between the first trainable weight matrix and the second trainable weight matrix, such as convolutional layers, normalization layers, pooling layers, activation functions, etc., and these processing layers can perform feature extraction, feature mapping and other operations on the first embedded feature. Then, the third intermediate feature is obtained according to the sum of the original feature and the second intermediate feature of the original weight matrix, and the first intermediate output of the first first processing block is obtained based on the third intermediate feature. After obtaining the third intermediate feature, the third intermediate feature can be normalized, or the third intermediate feature can continue to be convolved, which is not specifically limited in this application. By performing low-rank decomposition on the original weight matrix to obtain multiple trainable weight matrices, fine-tuning the keyword extraction model based on the trainable weight matrix can effectively reduce the consumption of computing resources and the computational complexity during the fine-tuning process, and speed up the fine-tuning speed. In addition, since the product of multiple trainable weight matrices approximates the original weight matrix, the fine-tuned keyword extraction model can further enhance the keyword extraction ability of knowledge texts and knowledge questions while retaining the original performance.
[0045] Next, the first intermediate output is input to the next first processing block until the first output feature of the keyword extraction model in the current round is obtained. Finally, a back propagation operation is performed based on the first output feature to update the parameters of the first trainable weight matrix and the second trainable weight matrix of the fine-tuning module to obtain the first weight parameters of the fine-tuning module corresponding to each first processing block.
[0046] In addition, when decomposing the original weight matrix, it can also be decomposed into at least two trainable weight matrices. The number of decomposed trainable weight matrices is not specifically limited. By superimposing multiple trainable weight matrices, the keyword extraction model is fine-tuned to gradually optimize the performance of the keyword extraction model.
[0047] In a possible implementation, the knowledge question and answer model includes a plurality of second processing blocks cascaded in sequence, and the second processing blocks include a fine-tuning module. In the process of fine-tuning the generated content of the knowledge question and answer model, specifically, for the first round, the knowledge question and the reference knowledge answer are input into the knowledge question and answer model for feature extraction to obtain a second embedded feature, the second embedded feature is input into the first second processing block of the knowledge question and answer model to obtain a second intermediate output of the first second processing block, and the second intermediate output is input into the next second processing block until the second output feature of the knowledge question and answer model in the first round is obtained. A back propagation operation is performed based on the second output feature, and the parameters of the trainable weight matrix of the fine-tuning module are updated to obtain the third weight parameters of the fine-tuning model corresponding to each second processing block, and the generated content of the knowledge question and answer model is fine-tuned based on the third weight parameters until the predetermined iterative rounds are completed to obtain the fine-tuned knowledge question and answer model.
[0048] Specifically, for the first round, the knowledge question and the reference knowledge answer are input into the knowledge question and answer model for feature extraction to obtain the second embedded feature, the second embedded feature is input into the first second processing block of the knowledge question and answer model, the second embedded feature is self-attention calculated and fully connected in the second processing block, the second intermediate output of the first second processing block is obtained, and the second intermediate output is input into the next second processing block until the second output feature of the knowledge question and answer model in the first round is obtained. Then, a back propagation operation is performed based on the second output feature, and the first trainable parameter matrix and the second trainable parameter matrix are updated to obtain the third weight parameter of the fine-tuning module corresponding to each second processing block. The generated content of the knowledge question and answer model is adjusted based on the third weight parameter until the fine-tuned knowledge question and answer model is obtained after the predetermined iterative rounds are completed. The knowledge question and answer model is fine-tuned based on the knowledge question and the reference knowledge answer, so that the knowledge question and answer model can learn the intrinsic relationship and law between the knowledge question and the reference knowledge answer, which helps to improve the accuracy of the answers generated by the knowledge question and answer model.
[0049] In addition, the method and steps for fine-tuning the knowledge question and answer model based on self-cognition data are the same as the method and steps for fine-tuning the knowledge question and answer model based on knowledge questions and reference knowledge answers mentioned above, and will not be repeated here.
[0050] Step S204: Generate a question keyword vector corresponding to the query question keyword of the query question based on the fine-tuned keyword extraction model, determine the candidate knowledge text block related to the query question based on the question keyword vector and the knowledge text keyword vector, so that the fine-tuned knowledge question and answer model generates the target knowledge answer corresponding to the query question based on the candidate knowledge text block.
[0051] According to the above steps S201-S203, the original knowledge text data is obtained, the initial knowledge text data is obtained based on the original knowledge text data, the initial knowledge text data is segmented to obtain multiple knowledge text blocks, the knowledge text keywords in the knowledge text blocks are extracted, the knowledge text keywords are vectorized based on the text embedding model to obtain the knowledge text keyword vector, the question keywords are extracted from the knowledge questions, the keyword extraction model is fine-tuned based on the question keywords, and the knowledge question and answer model is fine-tuned based on the knowledge questions and reference knowledge answers. Finally, the question keyword vector corresponding to the query question keyword of the query question is generated according to the fine-tuned keyword extraction model, and the candidate knowledge text blocks related to the query question are determined according to the question keyword vector and the knowledge text keyword vector, so that the fine-tuned knowledge question and answer model generates the target knowledge answer corresponding to the query question based on the candidate knowledge text block. Among them, the query question is a question similar to but not the same as the knowledge question; the candidate knowledge text block is a knowledge text block retrieved from the vector database.
[0052] Specifically, refer to Figure 5 , Figure 5 An optional flow chart for generating target knowledge answers provided in an embodiment of the present disclosure, wherein a query question is input into a fine-tuned keyword extraction model to generate query question keywords, and the query question keywords are converted into query question keyword vectors based on a text embedding model. The query question keyword vector is searched in a vector database, matched with the knowledge text keyword vector in the vector database, and a candidate knowledge text block is obtained based on the matching result. The candidate knowledge text block and the query question are input into a fine-tuned knowledge question and answer model, and the knowledge question and answer model generates a corresponding target knowledge answer based on the query question and the candidate knowledge text block.
[0053] In one possible implementation, in the process of determining the candidate knowledge text blocks related to the query question based on the query question keyword vector and the knowledge text keyword vector, specifically, a vector similarity calculation can be performed on the query question keyword vector and the knowledge text keyword vector to obtain a vector similarity score, and the knowledge text block corresponding to the knowledge text keyword is retrieved from the vector database based on the vector similarity score, and the retrieved knowledge text block is determined as the candidate knowledge text block.
[0054] Specifically, the vector similarity of the query question keyword vector and the knowledge text keyword vector is calculated to obtain a vector similarity score. Among them, the vector similarity score can be calculated by methods such as cosine similarity, Euclidean distance, Manhattan distance, Chebyshev distance, Mahalanobis distance, etc., and this application does not specifically limit the vector similarity calculation method. Then, according to the vector similarity score, a vector similarity search is performed in the vector database to retrieve the knowledge text blocks corresponding to the knowledge text keywords that match the query question keyword vector. The knowledge text blocks corresponding to the knowledge text keywords with the highest vector similarity scores can be selected, and these n knowledge text blocks are determined as candidate knowledge text blocks. By performing vector similarity calculations on the query question keyword vector and the knowledge text keyword vector, it is possible to quickly retrieve the knowledge text blocks that are more matched with the question keywords corresponding to the question keyword vector based on the vector similarity score, providing a reliable text data foundation for generating target knowledge answers in subsequent steps.
[0055] In a possible implementation, when the application scenario of the embodiment of the present application is agricultural knowledge question answering, refer to Figure 6 , Figure 6 An optional overall fine-tuning training process for the knowledge-enhanced question-answering method based on a large language model provided in an embodiment of the present disclosure.
[0056] First, we obtain original knowledge text data from open world knowledge sources. The original knowledge text data can be knowledge texts related to crop varieties and pests and diseases. We manually clean the collected original knowledge text data, remove noise information, and merge repeated or similar knowledge text data to ensure the accuracy and simplicity of the knowledge text data. Then, we classify and organize the original knowledge text data after manual cleaning according to the knowledge content, and divide the knowledge text data with the same knowledge content into the same independent document, and use these independent documents as the initial knowledge text data.
[0057] Next, a database is constructed based on the initial knowledge text data. Documents with more content in the initial knowledge text data are segmented to obtain multiple knowledge text blocks, ensuring that each knowledge text block contains the necessary contextual content. The knowledge text block is input into a general large language model, and at least one knowledge question corresponding to the knowledge text block is generated based on the question generation task of the general large language model. Then, reference knowledge answers corresponding to the knowledge questions are generated based on the knowledge text block and the knowledge questions to form question-answer pair data, and a professional knowledge question-answering dataset is constructed based on the knowledge questions and reference knowledge answers. On the basis of the professional knowledge question-answering dataset, multiple knowledge text keywords and question keywords are generated for each knowledge text block and knowledge question based on the keyword generation task of the general large language model, and manual verification is performed to ensure that the generated keywords can accurately reflect the key content of the knowledge text block and knowledge question. In addition, self-cognition data is obtained from the open world knowledge source to construct a self-cognition dataset. The self-cognition dataset provides dialogue data in a professional question-answering style, which is used to shape the identity cognition of the knowledge question-answering model.
[0058] Next, the knowledge text keywords are vectorized through the BGE embedding model, and the knowledge text keywords are converted into knowledge text keyword vectors with a vector dimension of 1024. The knowledge text blocks, knowledge text keywords, and knowledge text keyword vectors are stored in the vector database, and a unique vector identifier is assigned to each knowledge text keyword vector in the vector database. A complete vector database is constructed based on the vector identifier, knowledge text blocks, knowledge text keywords, and knowledge text keyword vectors. In subsequent query retrieval, the efficient indexing and retrieval functions of the vector database can be used to quickly find the matching knowledge text blocks.
[0059] Next, the keyword extraction model and the knowledge question answering model are fine-tuned through the fine-tuning module to achieve efficient vertical field adaptation. The keyword extraction model is fine-tuned based on the question-keyword dataset, while the knowledge question answering model is fine-tuned based on the professional knowledge question answering dataset and the self-cognition dataset. During the fine-tuning process, the original weight matrix is frozen, and the model is fine-tuned by updating the weight parameters of the low-rank matrix in the fine-tuning module, thereby further enhancing the model performance while retaining the keyword extraction model and the knowledge question answering model.
[0060] After completing the fine-tuning training of the keyword extraction model and the knowledge question answering model, the fine-tuned keyword extraction model and the fine-tuned knowledge question answering model are obtained, and agricultural knowledge question answering is performed based on the fine-tuned models. The user's query question is input into the keyword extraction model, and the keyword extraction model extracts the query question keywords from the query question, and generates the query question keyword vector based on the BGE embedding model. Vector similarity retrieval is performed in the vector database based on the query question keyword vector, and candidate knowledge text blocks about crop varieties or pests and diseases that match the query question keyword vector are found according to the retrieval results. The candidate knowledge text blocks and the query question are input into the knowledge question answering model, and the knowledge question answering model generates the target knowledge answer corresponding to the query question based on the candidate knowledge text, and returns the generated target knowledge answer to the user, completing an agricultural knowledge question answering.
[0061] For example, the query question entered by the user is "What causes litchi downy mildew?" The query question keywords extracted by the keyword extraction model from the query question may be "litchi", "downy mildew disease" and "cause of disease". The query question keywords are vectorized, and the candidate knowledge text blocks retrieved from the vector database based on the query question keyword vector may be "Knowledge Text 1: Litchi downy mildew disease is one of the main diseases of litchi, a killer of litchi in the rainy season...", "Knowledge Text 2: The damage of litchi downy mildew disease is that small brown spots appear on the leaf surface at first, and then expand into brown irregular spots...", "Knowledge Text 3: The pathogen litchi downy mildew is an oomycete...", "Knowledge Text 4: I. Litchi downy mildew disease 1. Disease introduction Litchi downy mildew disease is caused by litchi downy mildew fungus (Peronophythora litchii)...", "Knowledge Text 5: Recommended drugs: mancozeb (Pen Ke), methyl frost·mancozeb (Golden Redomil)...". The answers generated by the knowledge question answering model based on the candidate knowledge text blocks can be referred to Figure 7 , Figure 7 An optional schematic diagram of the knowledge question-answering model provided in the embodiment of the present disclosure generating target knowledge answers, answering from aspects such as pathogen overview, occurrence conditions, symptom manifestations, and prevention and control measures.
[0062] The knowledge-enhanced question-answering method based on a large language model provided by the disclosed embodiment effectively realizes the adaptive migration of the model's knowledge domain by using different data sets to fine-tune the keyword extraction model and the knowledge question-answering model, while retaining most of the weight structure of the initial model, thereby improving the knowledge question-answering performance for specific professional fields. On this basis, based on the fine-tuned keyword extraction model and knowledge question-answering model, question keyword extraction, vector retrieval and answer generation are performed, so that the knowledge question-answering model can respond quickly and generate accurate answers, realizing efficient and accurate knowledge question-answering.
[0063] The terms "first", "second", "third", "fourth", etc. (if any) in the specification of the present disclosure and the above-mentioned drawings are used to distinguish similar objects, and are not necessarily used to describe a specific order or sequence. It should be understood that the data used in this way can be interchanged where appropriate to describe the embodiments of the present disclosure, such as being able to be implemented in an order other than those illustrated or described herein. In addition, the terms "including" and "having" and any variations thereof are intended to cover non-exclusive inclusions, for example, a process, method, system, product or device that includes a series of steps or units is not necessarily limited to those steps or units clearly listed, but may include other steps or units that are not clearly listed or inherent to these processes, methods, products or devices.
[0064] It should be understood that in the present disclosure, "at least one (item)" means one or more, and "plurality" means two or more. "And / or" is used to describe the association relationship of associated objects, indicating that three relationships may exist. For example, "A and / or B" can mean: only A exists, only B exists, and A and B exist at the same time, where A and B can be singular or plural. The character " / " generally indicates that the objects associated before and after are in an "or" relationship. "At least one of the following" or similar expressions refers to any combination of these items, including any combination of single or plural items. For example, at least one of a, b or c can mean: a, b, c, "a and b", "a and c", "b and c", or "a and b and c", where a, b, c can be single or multiple.
[0065] It should be understood that in the description of the embodiments of the present disclosure, the meaning of multiple (or multiple items) is more than two, greater than, less than, exceed, etc. are understood to not include the number, and above, below, within, etc. are understood to include the number.
[0066] In the several embodiments provided in the present disclosure, it should be understood that the disclosed systems, devices and methods can be implemented in other ways. For example, the device embodiments described above are only schematic. For example, the division of units is only a logical function division. There may be other division methods in actual implementation. For example, multiple units or components can be combined or integrated into another system, or some features can be ignored or not executed. Another point is that the mutual coupling or direct coupling or communication connection shown or discussed can be an indirect coupling or communication connection through some interfaces, devices or units, which can be electrical, mechanical or other forms.
[0067] The units described as separate components may or may not be physically separated, and the components shown as units may or may not be physical units, that is, they may be located in one place or distributed on multiple network units. Some or all of the units may be selected according to actual needs to achieve the purpose of the solution of this embodiment.
[0068] In addition, each functional unit in each embodiment of the present disclosure may be integrated into one processing unit, or each unit may exist physically separately, or two or more units may be integrated into one unit. The above-mentioned integrated unit may be implemented in the form of hardware or in the form of software functional units.
[0069] If the integrated unit is implemented in the form of a software functional unit and sold or used as an independent product, it can be stored in a computer-readable storage medium. Based on this understanding, the technical solution of the present disclosure is essentially or the part that contributes to the prior art or all or part of the technical solution can be embodied in the form of a software product, and the computer software product is stored in a storage medium, including a number of instructions for a computer device (which can be a personal computer, a server, or a network device, etc.) to perform all or part of the steps of the various embodiments of the present disclosure. The aforementioned storage medium includes: U disk, mobile hard disk, read-only memory (Read-Only Memory, referred to as ROM), random access memory (Random Access Memory, referred to as RAM), disk or optical disk and other media that can store program codes.
[0070] It should also be understood that the various implementations provided in the embodiments of the present disclosure can be combined arbitrarily to achieve different technical effects.
[0071] The above is a specific description of the preferred implementation of the present disclosure, but the present disclosure is not limited to the above-mentioned implementation mode. Technical personnel familiar with the field can also make various equivalent deformations or substitutions under the shared conditions without violating the spirit of the present disclosure. These equivalent deformations or substitutions are all included in the scope defined by the claims of the present disclosure.
Claims
1. A knowledge-enhanced question-answering method based on a large language model, characterized in that: include: Acquire original knowledge text data, and obtain initial knowledge text data based on the original knowledge text data; The initial knowledge text data is segmented to obtain a plurality of knowledge text blocks, knowledge text keywords in the knowledge text blocks are extracted, and the knowledge text keywords are vectorized to obtain knowledge text keyword vectors, wherein the knowledge text blocks contain rich context information, and knowledge questions related to the knowledge text blocks and reference knowledge answers corresponding to the knowledge questions are generated based on the knowledge text blocks; Extracting question keywords from the knowledge question, fine-tuning a keyword extraction model based on the question keywords, and fine-tuning a knowledge question answering model based on the knowledge question and the reference knowledge answer, wherein when fine-tuning the knowledge question answering model, the knowledge question answering model is also fine-tuned based on self-cognition data, and the self-cognition data is used to shape the identity cognition of the knowledge question answering model; A query question keyword vector corresponding to the query question keyword of the query question is generated according to the fine-tuned keyword extraction model, and a candidate knowledge text block related to the query question is determined according to the query question keyword vector and the knowledge text keyword vector, so that the fine-tuned knowledge question and answer model generates a target knowledge answer corresponding to the query question based on the candidate knowledge text block.
2. The knowledge-enhanced question-answering method based on a large language model according to claim 1, characterized in that: The fine-tuning of the knowledge question answering model is also based on the self-cognition data, extracting question keywords from the knowledge questions, fine-tuning the keyword extraction model based on the question keywords, and fine-tuning the knowledge question answering model based on the knowledge questions and the reference knowledge answers, including: Inputting the knowledge question into a universal large language model so that the universal large language model generates the question keywords based on the knowledge question, and fine-tuning the keyword extraction model based on the question keywords; The generated content of the knowledge question and answer model is fine-tuned based on the knowledge question and the reference knowledge answer, and the interactive identity of the knowledge question and answer model is fine-tuned based on the self-cognition data.
3. The knowledge-enhanced question-answering method based on a large language model according to claim 2, characterized in that: The keyword extraction model includes a plurality of first processing blocks cascaded in sequence, wherein the first processing block includes a fine-tuning module, and the fine-tuning of the keyword extraction model based on the question keywords includes: The problem keywords are input into the keyword extraction model. For the first round, first weight parameters of the fine-tuning module corresponding to each of the first processing blocks are obtained based on a back-propagation operation. The keyword extraction model is trained for the next round based on the first weight parameters. Second weight parameters of the fine-tuning module corresponding to each of the first processing blocks in the next round are obtained based on a back-propagation operation. The keyword extraction model is continuously trained based on the second weight parameters until the predetermined iterative rounds are completed and the fine-tuned keyword extraction model is obtained.
4. The knowledge-enhanced question-answering method based on a large language model according to claim 3, characterized in that: The fine-tuning module includes at least one trainable weight matrix. Before obtaining the first weight parameters of the fine-tuning module corresponding to each of the first processing blocks based on the back-propagation operation, the knowledge-enhanced question-answering method based on the large language model further includes: Acquire an original weight matrix of the first processing block, and decompose based on the original weight matrix to obtain a first trainable weight matrix and a second trainable weight matrix of the fine-tuning module; Perform feature extraction on the question keyword to obtain a first embedded feature, input the first embedded feature to the first first processing block of the keyword extraction model, perform a dimension reduction operation on the first embedded feature through the first trainable weight matrix to obtain a first intermediate feature, perform a dimension increase operation on the first intermediate feature through the second trainable weight matrix to obtain a second intermediate feature with the same output dimension as the original weight matrix, determine a third intermediate feature output by the fine-tuning module according to the original feature of the original weight matrix and the sum of the second intermediate feature, obtain a first intermediate output of the first first processing block based on the third intermediate feature, and input the first intermediate output to the next first processing block until a first output feature of the keyword extraction model in the current round is obtained; The back-propagation operation is performed on the first output feature, and parameters of the trainable weight matrix of the fine-tuning module are updated based on the back-propagation operation to obtain the first weight parameters of the fine-tuning module corresponding to each of the first processing blocks.
5. The knowledge-enhanced question-answering method based on a large language model according to claim 2, characterized in that: The knowledge question and answer model includes a plurality of second processing blocks cascaded in sequence, and the second processing block includes a fine-tuning module, and the generated content of the knowledge question and answer model is fine-tuned based on the knowledge question and the reference knowledge answer, including: For the first round, the knowledge question and the reference knowledge answer are input into the knowledge question answering model for feature extraction to obtain a second embedded feature, the second embedded feature is input into the first second processing block of the knowledge question answering model to obtain a second intermediate output output by the first second processing block, and the second intermediate output is input into the next second processing block until the second output feature of the knowledge question answering model in the first round is obtained; The back propagation operation is performed based on the second output feature, the parameters of the trainable weight matrix of the fine-tuning module are updated to obtain the third weight parameters of the fine-tuning model corresponding to each second processing block, and the generated content of the knowledge question and answer model is fine-tuned based on the third weight parameters until a predetermined number of iterations are completed to obtain the fine-tuned knowledge question and answer model.
6. The knowledge-enhanced question-answering method based on a large language model according to claim 1, characterized in that: The step of segmenting the initial knowledge text data to obtain a plurality of knowledge text blocks, generating knowledge text keywords in the knowledge text blocks, and vectorizing the knowledge text keywords to obtain knowledge text keyword vectors includes: Segmenting the initial knowledge text data to obtain a plurality of the knowledge text blocks, and inputting the knowledge text blocks into the universal large language model so that the universal large language model generates the knowledge text keywords corresponding to each of the knowledge text blocks; The knowledge text keywords are vectorized to obtain the knowledge text keyword vectors.
7. The knowledge-enhanced question-answering method based on a large language model according to claim 6, characterized in that: The knowledge text keywords are converted into vector representations based on a text embedding model to obtain knowledge text keyword vectors.
8. The knowledge-enhanced question-answering method based on a large language model according to claim 6, characterized in that: After vectorizing the knowledge text keywords to obtain the knowledge text keyword vectors, the knowledge enhanced question answering method based on a large language model further includes: The knowledge text block, the knowledge text keyword and the knowledge text keyword vector are stored in a vector database, so that the vector database assigns a corresponding vector identifier to the knowledge text keyword vector.
9. The knowledge-enhanced question-answering method based on a large language model according to claim 1, characterized in that: The step of determining a candidate knowledge text block related to the query question according to the query question keyword vector and the knowledge text keyword vector comprises: Vector similarity calculation is performed on the query question keyword vector and the knowledge text keyword vector to obtain a vector similarity score, and the knowledge text block corresponding to the knowledge text keyword is retrieved from the vector database according to the vector similarity score, and the retrieved knowledge text block is determined as the candidate knowledge text block.
10. An electronic device comprising a memory and a processor, wherein the memory stores a computer program, wherein: When the processor executes the computer program, the knowledge-enhanced question-answering method based on a large language model as described in any one of claims 1 to 9 is implemented.
Citation Information
Patent Citations
Model reasoning method and device based on self-cognition and electronic equipment
CN116822633A
Model training method and question answering method for question answering system
CN118093841A
Model question answering system
CN118981517A
Methods and systems for transforming and retrieving information from document data using machine learning
WO2023242540A1