Knowledge-enhanced question-answering method and electronic device based on large language model
By segmenting and vectorizing the initial knowledge text data, extracting keywords and fine-tuning the knowledge question-answering model, the problem of insufficient understanding of professional domain knowledge by large open source models is solved, and more accurate and efficient professional knowledge acquisition is achieved.
Patent Information
- Application Number
- CN202411911823.X
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2024-12-24
- Publication Date
- 2025-10-03
- Estimated Expiration
- 2044-12-24
AI Technical Summary
Existing open source large models lack an in-depth understanding of professional domain knowledge, resulting in inefficient retrieval and inaccurate generated answers when acquiring professional knowledge.
By segmenting and vectorizing the initial knowledge text data, extracting knowledge text keywords, and fine-tuning the knowledge question-answering model based on question keywords, the model's identity cognition is shaped using self-cognition data to generate target knowledge answers.
It improves the accuracy and efficiency of generating target knowledge answers, reduces storage costs, and enhances the model's ability to understand professional fields.
Smart Images

Figure CN119884309B_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, expertise management and acquisition are key components of modern social development. In related technologies, expertise is typically stored in knowledge bases. This expertise is then directly vectorized and matched against questions, which is then collated and generated using large open-source models. However, direct vectorization matching methods often yield large amounts of similar but incompletely relevant text. Furthermore, existing large open-source models lack a deep understanding of domain knowledge, resulting in low retrieval efficiency and inaccurate answers. Summary of the Invention
[0003] The following is an overview of the subject matter described in detail in this disclosure. This overview is not intended to limit the scope of the claims.
[0004] The disclosed embodiments provide a knowledge-enhanced question-answering method based on a large language model, which effectively improves the accuracy of generating target knowledge answers.
[0005] In one aspect, the present disclosure provides a knowledge-enhanced question-answering method based on a large language model, comprising:
[0006] Acquiring original knowledge text data, and obtaining initial knowledge text data based on the original knowledge text data;
[0007] Segmenting the initial knowledge text data to obtain a plurality of knowledge text blocks, extracting knowledge text keywords from the knowledge text blocks, vectorizing the knowledge text keywords to obtain knowledge text keyword vectors, wherein the knowledge text blocks contain rich contextual information, and generating knowledge questions related to the knowledge text blocks and reference knowledge answers corresponding to the knowledge questions based on the knowledge text blocks;
[0008] 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;
[0009] 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.
[0010] 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.
[0011] 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. By performing keyword extraction after segmenting the initial knowledge text data into blocks, the data content is streamlined, which helps to reduce data redundancy and improve the accuracy of subsequent matching. Furthermore, the knowledge text keywords are converted into a vector form suitable for data processing, which can reduce storage costs while improving the speed and accuracy of data processing. Knowledge questions related to the knowledge text blocks and knowledge question responses are generated based on the knowledge text blocks. Based on the corresponding reference knowledge answers, question keywords are extracted from the knowledge questions, the keyword extraction model is fine-tuned based on the question keywords, and the knowledge question answering model is fine-tuned based on the knowledge questions and reference knowledge answers, so that the model can learn about 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 answering 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.
[0012] Other features and advantages of the present disclosure will be set forth in the description which follows, and in part will be apparent from the description, or may be learned by practicing the present disclosure. BRIEF DESCRIPTION OF THE DRAWINGS
[0013] The accompanying drawings are used to provide a 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 to the technical solution of the present disclosure.
[0014] Figure 1A schematic diagram of an optional implementation environment provided for an embodiment of the present disclosure;
[0015] 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;
[0016] Figure 3 An optional schematic diagram of a vector database structure provided in an embodiment of the present disclosure;
[0017] Figure 4 A schematic diagram of an optional process for fine-tuning a model provided in an embodiment of the present disclosure;
[0018] Figure 5 A schematic diagram of an optional process for generating target knowledge answers provided in an embodiment of the present disclosure;
[0019] 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;
[0020] 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
[0021] In order to make the purpose, technical solutions and advantages of the present disclosure more clearly understood, the present disclosure is further described in detail below with reference to 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 intended to limit the present disclosure.
[0022] 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 for the normal operation of the embodiment of the present disclosure will be obtained.
[0023] In the embodiments of the present disclosure, the term "module" or "unit" refers to a computer program or portion of a computer program that has a predetermined function and works together with other related components to achieve a predetermined goal. The ... that can be implemented in whole or in part using software, hardware (such as processing circuitry or memory), or a combination thereof. Similarly, a processor (or multiple processors or memories) can be used to implement one or more modules or units. Furthermore, each module or unit can be part of an overall module or unit that includes the functionality of that module or unit.
[0024] To facilitate understanding of the technical solutions provided by the embodiments of the present disclosure, some key terms used in the embodiments of the present disclosure are explained here:
[0025] Knowledge question-answering models leverage natural language processing, deep learning, and extensive knowledge bases or corpora to understand, analyze, and answer natural language questions posed by users. This model simulates human question-answering behavior, enabling efficient and accurate information acquisition and communication.
[0026] Backpropagation 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.
[0027] Low rank matrix: A low rank matrix is a matrix with relatively low rank, that is, the rank of the matrix is much smaller than the smaller of the number of its rows and columns.
[0028] BGE embedding model: is a text embedding model that is often used in natural language processing tasks. It aims to convert text into vector representations to simplify the calculation and analysis process.
[0029] In practical applications, the management and acquisition of expertise are key links in the development of modern society. Currently, expertise is typically generated by directly vectorizing and matching questions with expertise in a knowledge base, and then leveraging the answer generation capabilities of open-source large-scale models to generate answers. However, user queries are typically short, making it difficult for direct vectorization matching methods to fully explore the deeper meaning behind the questions, and they are prone to generating large amounts of similar but not completely relevant text. Furthermore, existing open-source large-scale models are primarily trained on general domain data and lack a deep understanding of specialized domain knowledge. This makes it difficult to generate systematic answers based on expertise, resulting in a lack of reliability and accuracy in the generated answers.
[0030] 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.
[0031] 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 keywords 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 displays the target knowledge answer on the display page of the terminal 101.
[0032] It is understandable that the above process of generating target knowledge answers can also be carried out in the server, obtaining the original knowledge text data in the 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 the target knowledge answers, sending the target knowledge answers to the terminal 101, and displaying the target knowledge answers on the display page of the terminal 101.
[0033] Reference Figure 2 , Figure 2 This is an optional flowchart of a knowledge-enhanced question-answering method based on a large language model provided in an embodiment of the present disclosure, which may specifically include but is not limited to the following steps S201 to S204:
[0034] Step S201: Acquire original knowledge text data, and obtain initial knowledge text data based on the original knowledge text data.
[0035] 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 that has been processed. The original knowledge text data is obtained from the open world knowledge source and data processing is performed on the original knowledge text data. This can be done through manual cleaning or with the help of 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 and integrated while retaining the different content of each. By processing the original knowledge text data, the accuracy and simplicity of the knowledge text data can be improved, and the interference of irrelevant content on the generated results can be avoided.
[0036] Next, the processed raw knowledge text data is classified according to its content. Knowledge text data with the same content is grouped into the same independent document. This results in multiple independent documents with different content, which serve as the initial knowledge text data. For example, the processed raw knowledge text data may contain information about apple tree planting, causes of apple tree disease, apple tree prevention and control measures, rice planting, and grapevine prevention and control measures. Based on the content, apple tree planting, causes of apple tree disease, and apple tree prevention and control measures can be grouped into Document A, rice planting into Document B, and grapevine prevention and control measures into Document C, resulting in three independent documents serving as the initial knowledge text data.
[0037] 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 historical initial knowledge text data being overwritten by new initial knowledge text data, further ensuring the integrity of the initial knowledge text data.
[0038] Step S202: Segment the initial knowledge text data to obtain multiple knowledge text blocks, extract knowledge text keywords from the knowledge text blocks, and vectorize the knowledge text keywords to obtain knowledge text keyword vectors.
[0039] 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.
[0040] In one possible implementation, the initial knowledge text data is segmented to obtain multiple 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.
[0041] Specifically, the knowledge text data of each document in the initial knowledge text data is segmented according to text titles, paragraphs, punctuation marks, or semantic information to obtain multiple knowledge text blocks. The knowledge text blocks are input into a universal large language model, and a keyword generation task based on the universal 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 the generated answers.
[0042] 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 calculation is 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 a numerical form 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.
[0043] In one possible implementation, after vectorizing the knowledge text keywords to obtain the knowledge text keyword vectors, the knowledge text blocks, knowledge text keywords, and knowledge text keyword vectors can be stored in a vector database, so that the vector database assigns corresponding vector identifiers to the knowledge text keyword vectors. The vector identifier is a unique identifier for each piece of vector data, used to mark and distinguish each piece of vector data; the vector data is vectorized data, including knowledge text keyword vectors and knowledge text block vectors; the vector database is used to store and retrieve vector data and can be a custom-built database or a Milvus database.
[0044] 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, corresponding knowledge text keywords are obtained by matching with knowledge text keyword vectors, and corresponding knowledge text blocks are found based on the knowledge text keywords. Alternatively, when storing knowledge text blocks in a vector database, the knowledge text blocks can also be converted into knowledge text block vectors through a text embedding model, and corresponding text block vector identifiers are assigned to the knowledge text block vectors, and the text block vector identifiers, knowledge text keywords, and knowledge text keyword vectors are associated. When searching in a vector database, corresponding knowledge text keywords are obtained by matching with knowledge text keyword vectors, and corresponding text block vector identifiers are found based on the knowledge text keywords, and then the corresponding knowledge text blocks are retrieved based on the text block vector identifiers. 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 ability 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.
[0045] After obtaining the knowledge text block through segmentation, the knowledge text block is 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 a corresponding knowledge answer is formed according to the generated knowledge question. The knowledge answer is used as a reference knowledge answer for model fine-tuning in subsequent steps.
[0046] 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.
[0047] 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 the query questions and can be a generative language model. When fine-tuning the knowledge question answering model, it is also fine-tuned based on self-perception data. This self-perception data provides conversational data with a professional question-answering style, which is used to shape the knowledge question answering model's identity recognition.
[0048] Reference Figure 4 , Figure 4 This is a schematic diagram of an optional process for 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 supervision of 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 supervision of the fine-tuning module to obtain a fine-tuned knowledge question and answer model.
[0049] In one 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, the knowledge question is input into the general large language model so that the general large language model generates question keywords based on the knowledge question, the keyword extraction model is fine-tuned based on the question keywords, the generated content of the knowledge question-answering model is fine-tuned based on the knowledge question and the reference knowledge answer, and the interactive identity of the knowledge question-answering model is fine-tuned based on the self-cognition data. Specifically, a keyword generation task is constructed in the general large language model, the knowledge question is input into the general large language model, a plurality of relevant question keywords are generated for the knowledge question, 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.
[0050] 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 relevance between the knowledge questions and the question keywords.
[0051] Next, the knowledge question and reference knowledge answer are input into the knowledge question answering model for fine-tuning. This allows the model to learn the intrinsic connection between the knowledge question and the reference knowledge answer and adjust the generated answer content based on this connection. Self-perception data is then input into the knowledge question answering model for fine-tuning. This allows the model to shape its identity based on the self-perception data, thereby determining the interactive identity of the knowledge question answering model. When generating answers related to knowledge questions, the knowledge question answering model can generate professional and complete knowledge answers based on this model identity; alternatively, when generating answers about its own information, the knowledge question answering model can provide consistent and expected answers. Fine-tuning the knowledge question answering model using self-perception data enables the knowledge question answering model to form a stable self-perception, thereby improving the professionalism and accuracy of the generated target knowledge answers and enhancing the interactive experience of the knowledge question answering model. Furthermore, bidirectional fine-tuning of the knowledge question answering model using both knowledge question answering data and self-perception data enables the knowledge question answering model to adapt to a variety of knowledge answers, effectively improving the practicality of the knowledge question answering model.
[0052] 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 model can be fine-tuned independently using the knowledge question and answer dataset first, 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.
[0053] 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 specific limitations.
[0054] In one possible implementation, the keyword extraction model includes multiple first processing blocks cascaded in sequence, and the first processing block includes 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 the back propagation operation, and 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 the back propagation operation, and the keyword extraction model is continued to be trained based on the second weight parameters until a fine-tuned keyword extraction model is obtained after completing the predetermined iterative rounds.
[0055] 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 the predetermined iterative rounds. 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.
[0056] 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, 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.
[0057] Specifically, the original weight matrix of the first processing block is obtained, and the original weight matrix is subjected to low-rank decomposition 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 a 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 using the first trainable weight matrix to obtain a first intermediate feature, and then the first intermediate feature is increased in dimension using the second trainable weight matrix to obtain a 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 convolution layers, normalization layers, pooling layers, activation functions, etc. These processing layers can perform operations such as feature extraction and feature mapping on the first embedded feature. Then, a third intermediate feature is obtained based on the sum of the original features and the second intermediate features 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 convolution operation can be continued on the third intermediate feature, 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 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.
[0058] Next, the first intermediate output is fed into the next first processing block until the first output feature of the keyword extraction model for the current round is obtained. Finally, a backpropagation operation is performed based on the first output feature to update the first and second trainable weight matrices of the fine-tuning module, obtaining the first weight parameters of the fine-tuning module corresponding to each first processing block.
[0059] 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.
[0060] In one 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 backpropagation 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. The generated content of the knowledge question and answer model is fine-tuned based on the third weight parameters until the fine-tuned knowledge question and answer model is obtained after completing the predetermined iterative rounds.
[0061] Specifically, 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, which is then input into the first second processing block of the knowledge question answering model. In the second processing block, the second embedded feature is self-attention calculated and fully connected to obtain the second intermediate output of the first second processing block. 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. Then, a backpropagation operation is performed based on the second output feature to update the parameters of the first trainable parameter matrix and the second trainable parameter matrix to obtain the third weight parameter of the fine-tuning module corresponding to each second processing block. The generated content of the knowledge question answering model is adjusted based on the third weight parameter until a fine-tuned knowledge question answering model is obtained after completing the predetermined iterative rounds. Fine-tuning the knowledge question answering model based on the knowledge question and the reference knowledge answer enables the knowledge question answering model to learn the intrinsic relationship and rules between the knowledge question and the reference knowledge answer, which helps to improve the accuracy of the answers generated by the knowledge question answering model.
[0062] 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.
[0063] 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.
[0064] 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 based on the fine-tuned keyword extraction model, and the candidate knowledge text blocks related to the query question are determined 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 blocks. Among them, the query question is a question that is similar to but not the same as the knowledge question; the candidate knowledge text block is the knowledge text block retrieved from the vector database.
[0065] Specifically, refer to Figure 5 , Figure 5 An optional flow chart for generating target knowledge answers provided in an embodiment of the present disclosure includes inputting a query question into a fine-tuned keyword extraction model to generate query question keywords, and converting the query question keywords into query question keyword vectors based on a text embedding model. A search is performed in a vector database based on the query question keyword vectors, and the vectors are matched with the knowledge text keyword vectors in the vector database, and candidate knowledge text blocks are obtained based on the matching results. The candidate knowledge text blocks and the query question are input into a fine-tuned knowledge question answering model, and the knowledge question answering model generates corresponding target knowledge answers based on the query question and the candidate knowledge text blocks.
[0066] In one possible implementation, in the process of determining candidate knowledge text blocks related to the query question based on the query question keyword vector and the knowledge text keyword vector, the query question keyword vector and the knowledge text keyword vector can be used to calculate vector similarity 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.
[0067] 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 first n (n>2) 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 calculation 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 closely 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.
[0068] 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.
[0069] First, we acquire raw knowledge text data from open-world knowledge sources. This raw knowledge text data can include knowledge text related to crop varieties and pests and diseases. We manually cleanse this collected raw knowledge text data to remove noise and merge duplicate or similar knowledge text data to ensure its accuracy and simplicity. Next, we classify and organize this manually cleaned raw knowledge text data based on its content. Knowledge text data with the same content is grouped into independent documents, which serve as the initial knowledge text data.
[0070] 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 open world knowledge sources to construct a self-cognition dataset. The self-cognition dataset provides conversation data in a professional question-answering style, which is used to shape the identity cognition of the knowledge question-answering model.
[0071] Next, the knowledge text keywords are vectorized using the BGE embedding model, converting them 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 a vector database. Within the vector database, each knowledge text keyword vector is assigned a unique vector identifier. A complete vector database is constructed based on the vector identifiers, knowledge text blocks, knowledge text keywords, and knowledge text keyword vectors. Subsequent queries and searches can leverage the efficient indexing and retrieval capabilities of the vector database to quickly find matching knowledge text blocks.
[0072] Next, the fine-tuning module performs supervised fine-tuning on the keyword extraction model and the knowledge question answering model to achieve efficient vertical domain 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-perception 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. This further enhances the model performance while retaining the keyword extraction model and the knowledge question answering model.
[0073] After completing fine-tuning training of the keyword extraction model and the knowledge question-answering model, a fine-tuned keyword extraction model and a 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. The keyword extraction model extracts query question keywords from the query question and generates a query question keyword vector based on the BGE embedding model. A vector similarity search is performed in the vector database based on the query question keyword vector. Based on the search results, candidate knowledge text blocks about crop varieties or pests and diseases that match the query question keyword vector are found. The candidate knowledge text blocks and the query question are input into the knowledge question-answering model. The knowledge question-answering model generates a 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 session.
[0074] For example, if a user enters the query "What causes litchi downy mildew?", the keyword extraction model might extract query keywords such as "litchi," "downy mildew," and "cause." The query keywords are vectorized, and candidate knowledge text blocks retrieved from the vector database based on the query keyword vectors might include: "Knowledge Text 1: Litchi downy mildew is a major litchi disease and a killer during the rainy season...", "Knowledge Text 2: The damage caused by litchi downy mildew initially appears as small brown spots on the leaves, which then expand into irregular brown spots...", "Knowledge Text 3: The pathogen, litchi downy mildew, is an oomycete...", "Knowledge Text 4: I. Litchi Downy Mildew 1. Disease Introduction: Litchi downy mildew is caused by the fungus Peronophythora litchii...", and "Knowledge Text 5: Recommended pesticides: Mancozeb (Penko), Mancozeb (Golden Redomicil)...". The answers generated by the knowledge question answering model based on the candidate knowledge text blocks can be referenced. 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, providing answers from aspects such as an overview of the pathogen, conditions of occurrence, symptom manifestations, and prevention and control measures.
[0075] The knowledge-enhanced question-answering method based on a large language model provided by the disclosed embodiments effectively achieves adaptive transfer of the model's knowledge domain by fine-tuning the keyword extraction model and the knowledge question-answering model using different data sets, 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, question keyword extraction, vector retrieval, and answer generation are performed based on the fine-tuned keyword extraction model and knowledge question-answering model, enabling the knowledge question-answering model to respond quickly and generate accurate answers, achieving efficient and accurate knowledge question-answering.
[0076] The terms "first," "second," "third," "fourth," and the like (if any) in the specification of the present disclosure and the accompanying drawings are used to distinguish similar objects and are not necessarily used to describe a particular order or precedence. It should be understood that the terms used in this manner are interchangeable where appropriate to describe embodiments of the present disclosure, e.g., capable of being implemented in orders 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, e.g., a process, method, system, product, or apparatus comprising a series of steps or elements is not necessarily limited to those steps or elements explicitly listed, but may include other steps or elements not explicitly listed or inherent to such processes, methods, products, or apparatus.
[0077] It should be understood that in the present disclosure, "at least one (item)" refers to one or more, and "plurality" refers to 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 previous and next associated objects are in an "or" relationship. "At least one of the following items" or similar expressions refers to any combination of these items, including any combination of single items 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.
[0078] 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 exclude the number itself, and above, below, within, etc. are understood to include the number itself.
[0079] 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 merely schematic. For example, the division of units is only a logical function division. In actual implementation, there may be other division methods, such as 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.
[0080] Units described as separate components may or may not be physically separate, and components shown as units may or may not be physical units, that is, they may be located in one place or distributed across multiple network units. Some or all of these units may be selected to achieve the purpose of this embodiment according to actual needs.
[0081] In addition, the functional units in the various embodiments of the present disclosure may be integrated into a single processing unit, or each unit may exist physically separately, or two or more units may be integrated into a single unit. The aforementioned integrated units may be implemented in the form of hardware or software functional units.
[0082] 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 enabling a computer device (which can be a personal computer, a server, or a network device, etc.) to execute 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 (ROM), random access memory (RAM), disk or optical disk, and other media that can store program code.
[0083] 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.
[0084] The above is a specific description of the preferred implementation of the present disclosure, but the present disclosure is not limited to the above implementation. Technical personnel familiar with the art can also make various equivalent modifications or substitutions under the shared conditions that do not violate the spirit of the present disclosure. These equivalent modifications 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: Acquiring original knowledge text data, and obtaining initial knowledge text data based on the original knowledge text data; Segmenting the initial knowledge text data to obtain a plurality of knowledge text blocks, extracting knowledge text keywords from the knowledge text blocks, vectorizing the knowledge text keywords to obtain knowledge text keyword vectors, wherein the knowledge text blocks contain rich contextual information, and generating knowledge questions related to the knowledge text blocks and reference knowledge answers corresponding to the knowledge questions based on the knowledge text blocks; Extract question keywords from the knowledge question, fine-tune the keyword extraction model based on the question keywords and the knowledge text keywords, and fine-tune the knowledge question and answer model based on the knowledge question and the reference knowledge answer. When fine-tuning the knowledge question and answer model, the knowledge question and answer model is also fine-tuned based on self-cognition data. The self-cognition data provides conversation data with a professional question and answer style, which is used to shape the identity cognition of the knowledge question and answer model and determine the interactive identity of the knowledge question and answer model. The knowledge question and answer model is fine-tuned based on the knowledge question, the reference knowledge answer and the self-cognition data. The keyword extraction model and the knowledge question answering model include a fine-tuning module. When fine-tuning the keyword extraction model and the knowledge question answering model, the original weight matrices of the keyword extraction model and the knowledge question answering model are frozen, and the keyword extraction model and the knowledge question answering model are jointly fine-tuned by updating the trainable weight matrix of the fine-tuning module. The trainable weight matrix is a low-rank matrix. 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: Fine-tuning 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 blocks include 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, the first weight parameters of the fine-tuning module corresponding to each of the first processing blocks are obtained based on the 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 module corresponding to each of the first processing blocks in the next round are obtained based on the back propagation operation. The keyword extraction model is continued to be trained based on the second weight parameters until the fine-tuned keyword extraction model is obtained after completing the predetermined iterative rounds.
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 a back-propagation operation, the knowledge-enhanced question-answering method based on a large language model further includes: Obtaining an original weight matrix of the first processing block, and performing decomposition 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 into the first first processing block of the keyword extraction model, perform a dimensionality reduction operation on the first embedded feature using the first trainable weight matrix to obtain a first intermediate feature, perform a dimensionality increase operation on the first intermediate feature using 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 based on the sum of the original features of the original weight matrix and the second intermediate features, obtain a first intermediate output of the first first processing block based on the third intermediate feature, input the first intermediate output into the next first processing block, and until a first output feature of the keyword extraction model in the current round is obtained; A 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 answering model includes a plurality of second processing blocks cascaded in sequence, wherein the second processing block includes a fine-tuning module, and the fine-tuning of the generated content of the knowledge question answering model based on the knowledge question and the reference knowledge answer includes: 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 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 answering model in the first round is obtained; Based on the second output feature, a backpropagation operation is performed, 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 module corresponding to each second processing block. Based on the third weight parameters, the generated content of the knowledge question and answer model is fine-tuned until the predetermined number of iterations is 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, extracting knowledge text keywords from 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 a 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 allocates 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 determining of candidate knowledge text blocks related to the query question based on the query question keyword vector and the knowledge text keyword vector includes: A vector similarity calculation is performed on the query question keyword vector and the knowledge text keyword vector to obtain a vector similarity score. 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.
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 according to any one of claims 1 to 9 is implemented.
Citation Information
Patent Citations
Model training method and question answering method for question answering system
CN118093841A
Model question answering system
CN118981517A