Method and system for generating personalized question-answering large language model
By extracting and preprocessing expertise, combined with P-tuning v2 and LoRA technology, efficient parameters fine-tuning of the language model is solved, and the common language model lacks professional knowledge in specific fields is achieved, and the model is efficiently adapted and improved output quality in specific fields.
Patent Information
- Application Number
- CN202411390993.8
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2024-10-08
- Publication Date
- 2025-05-13
- Estimated Expiration
- 2044-10-08
AI Technical Summary
The existing general-purpose large language models lack professional knowledge understanding when dealing with specific fields, resulting in invalid or harmful outputs, and the full parameter fine-tuning requires high computing resources, which can easily lead to overfitting and inefficiency.
By extracting professional knowledge content, preprocessing and generating Q&A datasets, combining P-tuning v2 and LoRA efficient parameter fine-tuning techniques, the basic Q&A model is gradually transformed into a vertical model suitable for specific fields.
It realizes efficient adaptation of the model in a specific field, improves the ability to process complex information, reduces the computing resource requirements, avoids overfitting, and ensures the quality and safety of model output.
Smart Images

Figure CN118898257B_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to the technical field of artificial intelligence and natural language processing, and in particular to a method and system for generating a personalized question-and-answer large language model. Background Art
[0002] Large-scale general language models (LLMs) have shown superior performance in a variety of different scenarios due to their extensive training data sources and strong generalization capabilities. However, a significant limitation of these models is that they lack the understanding and adaptation of in-depth knowledge in specific fields, especially those that require highly specialized information, such as the field of medicine and antibiotics, and law. Therefore, when large-scale general language models are used to deal with problems in the field of antibiotics and medicine, the model will output unhelpful, unhealthy, or even toxic and harmful answers because of the lack of knowledge in the field of antibiotics and medicine, which will have a negative impact on users.
[0003] If you want to build a professional large-scale language model in a specialized field, you can perform full parameter fine-tuning on the general language model. However, full parameter fine-tuning has high computing resource requirements. Since all parameters of the entire model need to be fine-tuned, full parameter fine-tuning usually requires more computing resources, including more GPU / CPU resources and longer training time. Secondly, full parameter fine-tuning has high storage requirements and needs to store the parameters of the entire model, which requires a larger storage space to save the weights and other parameters of the model. Finally, full parameter fine-tuning will increase the risk of overfitting. Fine-tuning all parameters may cause the model to overfit on the training data, resulting in poor generalization ability of the model. And fine-tuning the model using only one fine-tuning method alone is likely to lead to insufficient generalization ability of the model, that is, the model cannot answer overly professional questions. Insufficient generalization ability does not mean that it cannot answer overly professional questions, but that it cannot answer questions outside the training set. It can only answer questions and answers prepared for it in the training set.
[0004] In summary, in the existing technologies, the models lack the ability to adapt to the details and characteristics of certain specific fields and cannot capture important concepts and contexts in the field. Fine-tuning all parameters may cause the model to overfit on the training data, resulting in poor generalization ability of the model. Full parameter fine-tuning has high requirements for computing resources. Since all parameters of the entire model need to be fine-tuned, full parameter fine-tuning usually requires more computing resources and longer training time, resulting in inefficiency. Moreover, using only one fine-tuning method to fine-tune the model can easily lead to insufficient generalization ability of the model, that is, the model cannot correctly answer questions that are different from the form in the training set. Summary of the invention
[0005] Based on this, the purpose of the present invention is to provide a method and system for generating a personalized question-answering large language model, so as to at least solve the deficiencies in the above-mentioned prior art.
[0006] In a first aspect, the present invention provides a method for generating a personalized question-answering large language model, the method comprising:
[0007] Extracting professional knowledge content and preprocessing the professional knowledge content to obtain a professional knowledge data set;
[0008] Using a preset model to ask questions to the professional knowledge dataset to generate a question-answer dataset;
[0009] Based on the question-answering dataset, fine-tune the basic question-answering model using P-tuning v2 to obtain a fine-tuned basic question-answering model, and combine the fine-tuned basic question-answering model with the basic question-answering model to obtain a combined basic question-answering model;
[0010] Obtain a specific task and a data set related to the specific task, perform LoRA efficient parameter fine-tuning on the combined basic question-answering model based on the data set to obtain a fine-tuned combined basic question-answering model, and combine the fine-tuned combined basic question-answering model with the combined basic question-answering model to obtain a personalized large language model.
[0011] Compared with the prior art, the beneficial effects of the present invention are as follows: by performing P-tuning v2 efficient parameter fine-tuning on the basic question-answering model, the basic question-answering model can be fine-tuned into a vertical model applied in a professional field, and in the process of P-tuning v2 efficient parameter fine-tuning, fewer parameters need to be adjusted, and the model's ability to process complex information can be improved, especially when processing difficult tasks such as sequence labeling, it can show better performance, and only fine-tuning some parameters will not cause catastrophic forgetting, and by performing LoRA efficient parameter fine-tuning on the basic question-answering model, not only the amount of parameters that need to be stored and updated during model fine-tuning is reduced, but also the transformation of the basic question-answering model into a vertical model in a professional field can be completed, so that the model can interact with the inserted vector through the attention mechanism, thereby more deeply affecting the content of the model output, making the model of better quality, and in the process of LoRA efficient parameter fine-tuning, less computing resources are required and high adaptability is high, and overfitting can be prevented, while ensuring most of the structure of the model, the model can be effectively optimized.
[0012] Furthermore, the step of extracting professional knowledge content and preprocessing the professional knowledge content includes:
[0013] Extracting professional knowledge in the field of antibiotics, and converting the professional knowledge in the field of antibiotics into txt document content;
[0014] Review, typeset, annotate and repair the contents of the txt document.
[0015] Furthermore, the step of using a preset model to ask questions to the professional knowledge dataset to generate a question-answer dataset includes:
[0016] Using a preset large language model to ask content questions to the professional knowledge dataset to generate professional questions and professional answers, and generating a question-answering dataset based on the professional questions and the professional answers;
[0017] Determine whether the question-answering dataset meets the HHH standard;
[0018] If so, the question-answering dataset is typeset according to the fine-tuned format of the basic question-answering model.
[0019] Furthermore, the expression of the P-tuning v2 efficient parameter fine-tuning is:
[0020] ;
[0021] In the formula, ⊕ represents the fusion operation, represents the set of pre-trained parameters, Represents the parameter set of the fine-tuning task, Represents the minimization task characteristic parameter The objective function is represents a task-specific loss function.
[0022] Furthermore, the step of fine-tuning the LoRA efficient parameters based on the basic question-answering model based on the data set includes:
[0023] Perform low-rank decomposition on the pre-trained weight matrix to obtain adaptation matrix A and adaptation matrix B;
[0024] Setting the adaptation matrix A and the adaptation matrix B as trainable parameters;
[0025] The adaptation matrix A and the adaptation matrix B are updated by minimizing the loss function of the adaptation task through the back-propagation algorithm to fine-tune the combined basic question-answering model.
[0026] Furthermore, the expression for the LoRA efficient parameter fine-tuning is:
[0027] ;
[0028] In the formula, x represents the input vector, b represents the bias term, represents a low-rank matrix, represents the pre-trained model weights, A represents the adaptation matrix A, B represents the adaptation matrix B, where , W Represents the pre-trained weight matrix.
[0029] In a second aspect, the present invention further provides a system for generating a personalized question-answering large language model, the system comprising:
[0030] An extraction and processing module, used to extract professional knowledge content and pre-process the professional knowledge content to obtain a professional knowledge data set;
[0031] A question generation module, used to ask questions to the professional knowledge dataset using a preset model to generate a question-answer dataset;
[0032] A first fine-tuning module is used to perform P-tuning v2 efficient parameter fine-tuning on the basic question-answering model based on the question-answering dataset to obtain a fine-tuned basic question-answering model, and combine the fine-tuned basic question-answering model with the basic question-answering model to obtain a combined basic question-answering model;
[0033] The second fine-tuning module is used to obtain a specific task and a data set related to the specific task, and based on the data set, perform LoRA efficient parameter fine-tuning on the combined basic question-answering model to obtain a fine-tuned combined basic question-answering model, and combine the fine-tuned combined basic question-answering model with the combined basic question-answering model to obtain a personalized large language model.
[0034] Furthermore, the extraction processing module includes:
[0035] An extraction unit, used for extracting professional knowledge in the field of antibiotics, and converting the professional knowledge in the field of antibiotics into txt document content;
[0036] The processing unit is used to review, typeset, annotate and repair the content of the txt document.
[0037] Furthermore, the question generation module includes:
[0038] A questioning unit, configured to use a preset large language model to ask content questions to the professional knowledge dataset to generate professional questions and professional answers, and to generate a question-answering dataset based on the professional questions and the professional answers;
[0039] A judging unit, used to judge whether the question-answering data set meets the HHH standard;
[0040] A typesetting unit is used to typeset the question and answer dataset according to a fine-tuned format of the basic question and answer model if the question and answer dataset meets the HHH standard.
[0041] Furthermore, the second fine-tuning module includes:
[0042] A decomposition unit, used for performing low-rank decomposition on the pre-trained weight matrix to obtain an adaptation matrix A and an adaptation matrix B;
[0043] A setting unit, used for setting the adaptation matrix A and the adaptation matrix B as trainable parameters;
[0044] An updating unit is used to minimize the loss function of the adaptation task through a back-propagation algorithm to update the adaptation matrix A and the adaptation matrix B, so as to fine-tune the combined basic question-answering model. BRIEF DESCRIPTION OF THE DRAWINGS
[0045] Figure 1 This is a flowchart of a method for generating a personalized question-answering large language model in the first embodiment of the present invention;
[0046] Figure 2 4 is a structural block diagram of a system for generating a personalized question-answering large language model in a second embodiment of the present invention.
[0047] Description of main component symbols:
[0048] 10. Extraction processing module;
[0049] 20. Question generation module;
[0050] 30. The first fine-tuning module;
[0051] 40. The second fine-tuning module.
[0052] The following specific implementation manner will further illustrate the present invention in conjunction with the above-mentioned drawings. DETAILED DESCRIPTION
[0053] Embodiment 1
[0054] See also Figure 1 , which shows a method for generating a personalized question-answering large language model in a first embodiment of the present invention, and the method includes steps S1 to S4:
[0055] S1, extracting professional knowledge content and preprocessing the professional knowledge content to obtain a professional knowledge dataset;
[0056] Specifically, the step S1 includes steps S11 to S12:
[0057] S11, extracting professional knowledge in the field of antibiotics, and converting the professional knowledge in the field of antibiotics into txt document content;
[0058] S12, reviewing, typeset, annotating and repairing the contents of the txt document;
[0059] What needs to be explained is that professional knowledge content is extracted from professional paper documents in the field of antibiotics, the PDF document content of the paper is converted into TXT document content, and reviewed to avoid the presence of non-professional content. The TXT document content is then typeset and annotated, and problematic professional knowledge content is repaired to obtain a correct professional knowledge data set in the field of antibiotic knowledge.
[0060] S2, using a preset model to ask questions to the professional knowledge dataset to generate a question-answering dataset;
[0061] Specifically, the step S2 includes steps S21 to S23:
[0062] S21, using a preset large language model to ask content questions to the professional knowledge dataset to generate professional questions and professional answers, and generating a question-answering dataset based on the professional questions and the professional answers;
[0063] It should be explained that, in this embodiment, one of the large language models such as ChatGPT-3.5, baichuan or Tongyi Qianwen is used to ask content questions about the professional knowledge dataset, and the professional questions and professional answers generated after the questions are asked are used to generate a question-and-answer dataset.
[0064] S22, determining whether the question-answering dataset meets the HHH standard;
[0065] It is understandable that after obtaining the question-answering dataset, it is necessary to review the question-answering dataset to determine whether the question-answering dataset meets the HHH standard, that is, whether the question-answering dataset meets the authenticity, healthiness, and helpfulness;
[0066] S23, if yes, then typeset the question-answering dataset according to the fine-tuned format of the basic question-answering model;
[0067] It is understandable that after judging that the question-answering dataset meets the HHH standard, it is typeset according to the fine-tuned format of ChatGLM3-6B.
[0068] S3, performing P-tuning v2 efficient parameter fine-tuning on the basic question-answering model based on the question-answering dataset to obtain a fine-tuned basic question-answering model, and combining the fine-tuned basic question-answering model with the basic question-answering model to obtain a combined basic question-answering model;
[0069] It is worth noting that before step S3, steps S031 to S032 are also included:
[0070] S031, designing task-related text prompts, and embedding the text prompts into a basic question-answering model;
[0071] S032, fusing the pre-training parameter set and the parameter set of the fine-tuning task to obtain a new parameter set;
[0072] It is understandable that before fine-tuning the basic question-answering model, it is necessary to design task-related text prompts, that is, to design task-related text prompts and embed the text prompts into the basic question-answering model to guide the subsequent fine-tuning process.
[0073] It is worth noting that the working principle of P-tuning v2 is to use continuous prompts and parameter fusion techniques to fine-tune the basic question-answering model by minimizing the task-specific loss function, thereby achieving efficient parameter fine-tuning and improving the performance of the basic question-answering model on specific tasks. In this embodiment, the basic question-answering model is ChatGLM3-6B, and the expression of the efficient parameter fine-tuning of P-tuning v2 is:
[0074] ;
[0075] In the formula, ⊕ represents the fusion operation, represents the set of pre-trained parameters, Represents the parameter set of the fine-tuning task, Represents the minimization task characteristic parameter The objective function is represents the task-specific loss function;
[0076] It should be explained that in order to find With fixed pre-trained model parameters When combined, find the best set of It can make the loss function on a specific task Reach the minimum.
[0077] In addition, the parameter set of the fine-tuning task is iteratively updated by using the stochastic gradient descent optimization algorithm, so that the loss function gradually converges.
[0078] S4, obtaining a specific task and a data set related to the specific task, performing LoRA efficient parameter fine-tuning on the combined basic question-answering model based on the data set to obtain a fine-tuned combined basic question-answering model, and combining the fine-tuned combined basic question-answering model with the combined basic question-answering model to obtain a personalized large language model.
[0079] Specifically, the step S4 includes steps S41 to S43:
[0080] S41, performing low-rank decomposition on the pre-trained weight matrix to obtain an adaptation matrix A and an adaptation matrix B;
[0081] S42, setting the adaptation matrix A and the adaptation matrix B as trainable parameters;
[0082] S43, minimizing the loss function of the adaptation task by a back propagation algorithm to update the adaptation matrix A and the adaptation matrix B, so as to fine-tune the combined basic question-answering model;
[0083] It should be explained that before performing efficient parameter fine-tuning of LoRA, it is first necessary to determine the specific task of fine-tuning, such as text classification and content question and answer, and then obtain a data set related to the specific task, and ensure that the data set matches the task, fine-tune the low-rank matrix, obtain the adaptation matrix A and the adaptation matrix B, and then set the adaptation matrix A and the adaptation matrix B as trainable parameters, and minimize the loss function of the adaptation task through the back-propagation algorithm to update the adaptation matrix A and the adaptation matrix B, so as to fine-tune the combined basic question and answer model;
[0084] It is worth noting that given a pre-trained language model parameter W∈R d×d , LoRA achieves efficient parameter fine-tuning by introducing trainable low-rank adaptation matrix A and adaptation matrix B. In each layer, the expression of LoRA efficient parameter fine-tuning is:
[0085] ;
[0086] In the formula, x represents the input vector, b represents the bias term, represents a low-rank matrix, represents the pre-trained model weights, A represents the adaptation matrix A, B represents the adaptation matrix B, where , W Represents the pre-trained weight matrix. In this way, LoRA can only update the parameters of the low-rank adaptation matrix A and the adaptation matrix B during the fine-tuning process, while keeping the pre-trained weight matrix W unchanged, thereby achieving efficient parameter fine-tuning.
[0087] It should be explained that, in this embodiment, the original weight matrix W Instead of updating directly, a low-rank matrix is introduced To enhance the original weight matrix. For the model's weight matrix W It can be regarded as a low-rank matrix and pre-trained model weights The sum of ,in It can be expressed as ,in , , r is much smaller than d and k The rank of . Then, the adaptation matrices A and B are minimized using the back propagation algorithm to minimize the loss function of the adaptation task, and the adaptation matrices A and B are updated. By modifying the adaptation matrices A and B, the purpose of fine-tuning the general large language model is achieved.
[0088] It should be noted that P-tuning v2 only focuses on optimizing some parameters of the basic question-answering model during the fine-tuning of the pre-trained language model, which significantly reduces the number of parameters that need to be trained and reduces the computational cost. LoRA freezes the parameters of the original basic question-answering model and introduces an additional set of low-rank matrices. The modified low-rank matrix is added to the frozen parameters of the original basic question-answering model to achieve the purpose of fine-tuning the model. The amount of parameters that need to be stored and updated when fine-tuning the basic question-answering model is significantly reduced. Because the two methods used require very few parameters to be updated, the conversion of the general large-scale language model to the antibiotic medicine professional field model can be completed without high training costs during the fine-tuning process. P-tuning v2 mainly guides the basic question-answering model to generate appropriate output content for different downstream tasks by adding additional learnable "hints" to the input sequence of the basic question-answering model. Then, the LoRA fine-tuning strategy is used to introduce a set of low-rank matrices while retaining the integrity of the main weight structure of the basic question-answering model. By optimizing the parameters of these low-rank matrices separately, the fine-tuning of the basic question-answering model is achieved, and the recognition sensitivity and response flexibility of the basic question-answering model to the input information are enhanced, thereby significantly improving the quality of the output content and its adaptability to specific tasks. By combining these two fine-tuning methods, the general large language model is trained using a training set of professional medical antibiotics knowledge, which fills the knowledge gap of the general model in the field of medical antibiotics and overcomes the limitation of the lack of professional knowledge of the large language model when dealing with problems in specific fields. Therefore, P-Tuning v2 adds a learnable prefix vector before each layer of the Transformer decoder part of the basic question-answering model input, that is, the large language model, to guide the basic question-answering model to generate corresponding outputs according to specific tasks. LoRA does not change most of the original weights of the basic question-answering model, but controls the degree of fine-tuning of the basic question-answering model through a few low-rank matrices, which can affect the sensitivity and response of the basic question-answering model to the input data, and then adjust the quality and pertinence of the output content of the basic question-answering model. In layman's terms, LoRA achieves the purpose of fine-tuning the basic question-answering model by adding a low-rank matrix to the internal weights of the basic question-answering model. By combining these two fine-tuning methods, a general large language model is trained using a training set with professional knowledge content, which fills the gap in professional knowledge content of the general large language model and solves the lack of professional knowledge content in specific fields. This largely avoids the model from generating useless, unhealthy, or even toxic and harmful answers.
[0089] Because the LoRA fine-tuning method adjusts the weights of the basic question-answering model by introducing a pair of low-rank matrices (adaptation matrix A and adaptation matrix B), the computing resources and storage space required for fine-tuning are greatly reduced, thereby reducing the cost of fine-tuning. Moreover, for large models, adjusting the overall parameters of the model is prone to overfitting, especially when there is only limited training data. LoRA helps to alleviate overfitting by constraining the spatial dimension of parameter changes. Finally, since LoRA does not make major changes to the basic structure of the basic question-answering model, it can retain the general language representation learned by the pre-training model to a certain extent, which is crucial to maintaining the generalization ability and adaptability of the basic question-answering model to multiple tasks. P-tuning v2 mainly adapts to specific tasks by fine-tuning the prompt parameters in the basic question-answering model, rather than directly updating all the parameters of the basic question-answering model. In addition, P-Tuning v2 improves the model's ability to migrate between different tasks, allowing the same large model to adapt to various downstream tasks through simple prompt adjustments.
[0090] Combining the fine-tuning methods of LoRA and P-tuning v2, it is possible to adjust the general large language model more comprehensively and deeply in the field of professional knowledge. It can improve the generalization ability of the fine-tuned large language model. And it does not require high training costs. It solves the problem of requiring a lot of computing and economic costs when fine-tuning the model, and effectively avoids the model outputting inaccurate, irrelevant or even harmful information, ensuring the quality and security of the model output content, and to a certain extent reducing the risk of hallucination problems in the model.
[0091] In addition, it should be noted that the P-Tuning v2 method is used to fine-tune the ChatGLM3-6B model, and then the LoRA method is applied on this basis to fine-tune the parameters. This sequential application method allows the model to first generate relevant text based on the prompt embedding learning, and then generate professional answers in the field of antibiotics through the optimized internal parameters of the personalized large language model. The specific process is as follows:
[0092] We select P-tuning v2 to fine-tune the basic question-answering model, introduce trainable prompt embedding, and guide the fine-tuning of the basic question-answering model to generate text related to antibiotics, so that the basic question-answering model can adapt to the question-answering task of knowledge content in the field of antibiotics. For example, the prompt template of P-tuning v2 is:
[0093] "input_text": "Drug name: Ceftazidime, trade name: Fudaxin. What types of diseases can be treated with Ceftazidime?"
[0094] "output_label": "Respiratory tract infections: such as bacterial pneumonia, etc. Skin and soft tissue infections: such as burn infections, etc. Urinary tract infections: such as cystitis, etc. Otitis media: ear infections. Bone and joint infections: such as arthritis, etc."
[0095] "input_text": "Gastrointestinal, biliary and abdominal infections: including peritonitis caused by Escherichia coli, Klebsiella spp. and Staphylococcus aureus (methicillin-susceptible strains), and polymicrobial infections caused by aerobic and anaerobic organisms. What drugs should be used in this case and how should they be administered?"
[0096] "output_label": "Use ceftazidime (trade name: Fudaxin). This antibiotic has a broad antibacterial spectrum and can effectively treat infections caused by Escherichia coli, Klebsiella, etc."
[0097] "input_text": "What happens if ceftazidime is not appropriately reduced in patients with renal impairment?"
[0098] "output_label": "Common: Vascular disturbances, diarrhea, or transient elevation of one or more liver enzymes, and possible maculopapular or urticarial rash. Uncommon: Nausea, vomiting, abdominal pain, and colitis, pruritus, or angioedema."
[0099] Then, after ensuring that the basic question-answering model can answer professional knowledge-based content after p-tuning v2, save the fine-tuned basic question-answering model parameters. Directly use the LoRA efficient parameter fine-tuning method on the fine-tuned basic question-answering model. Through the given prompt, the general large language model is optimized as a whole to obtain a personalized large language model;
[0100] In this embodiment, the prompt template of LoRA is as follows:
[0101] {"conversations": [{"role": "user", "content": "What are the indications of Amoxicillin Clavulanate Potassium Tablets?"}, {"role": "assistant", "content": "Indications: This product is suitable for various infections caused by sensitive bacteria, such as: 1. Upper respiratory tract infections. 2. Lower respiratory tract infections. 3. Urinary tract infections. 4. Skin and soft tissue infections. 5. Other infections, otitis media, osteomyelitis, sepsis, peritonitis and postoperative infections."}]}
[0102] {"conversations": [{"role": "user", "content": "What are Amoxicillin and Clavulanate Potassium Tablets?"}, {"role": "assistant", "content": "Amoxicillin and Clavulanate Potassium Tablets are compound preparations, which are composed of amoxicillin and clavulanate potassium in a ratio of 4:1. Each tablet contains 0.25g of amoxicillin and 0.0625g of clavulanic acid. Properties of Amoxicillin and Clavulanate Potassium Tablets: Film-coated tablets, which are off-white to light yellow in color after removing the coating."}]}
[0103] Finally, the hyperparameters of the model are adjusted according to the output content, and a personalized large language model in the field of antibiotics is obtained based on p-tuning v2 and LoRA fine-tuning large language model.
[0104] In summary, the method for generating a personalized question-answering large language model in the above embodiment of the present invention can fine-tune the basic question-answering model into a vertical model applied in a professional field by performing P-tuning v2 efficient parameter fine-tuning on the basic question-answering model, and in the process of P-tuning v2 efficient parameter fine-tuning, fewer parameters need to be adjusted, and the model's ability to process complex information can be improved, especially when processing difficult tasks such as sequence labeling, it can show better performance, and only fine-tuning some parameters will not cause catastrophic forgetting, and by performing LoRA efficient parameter fine-tuning on the basic question-answering model, not only the amount of parameters that need to be stored and updated during model fine-tuning is reduced, but also the transformation of the basic question-answering model into a vertical model in a professional field can be completed, so that the model can interact with the inserted vector through the attention mechanism, thereby more deeply affecting the content of the model output, and strengthening the performance of the model in the field of medical antibiotics from many aspects, so that the overall performance of the model is improved, and in the process of LoRA efficient parameter fine-tuning, the computational efficiency can be improved, and the required computing resources are small and the adaptability is high, and overfitting can be prevented, while ensuring most of the structure of the model, the model can be effectively optimized.
[0105] Embodiment 2
[0106] See also Figure 2 , which is a system for generating a personalized question-answering large language model in a second embodiment of the present invention, and the system includes:
[0107] An extraction processing module 10 is used to extract professional knowledge content and pre-process the professional knowledge content to obtain a professional knowledge data set;
[0108] A question generation module 20, configured to use a preset model to ask questions to the professional knowledge dataset to generate a question-answer dataset;
[0109] A first fine-tuning module 30 is used to perform P-tuning v2 efficient parameter fine-tuning on the basic question-answering model based on the question-answering dataset to obtain a fine-tuned basic question-answering model, and combine the fine-tuned basic question-answering model with the basic question-answering model to obtain a combined basic question-answering model;
[0110] The expression of the P-tuning v2 efficient parameter fine-tuning is:
[0111] ;
[0112] In the formula, ⊕ represents the fusion operation, represents the set of pre-trained parameters, Represents the parameter set of the fine-tuning task, Represents the minimization task characteristic parameter The objective function is represents a task-specific loss function.
[0113] A second fine-tuning module 40 is used to obtain a specific task and a data set related to the specific task, and perform LoRA efficient parameter fine-tuning on the combined basic question-answering model based on the data set to obtain a fine-tuned combined basic question-answering model, and combine the fine-tuned combined basic question-answering model with the combined basic question-answering model to obtain a personalized large language model;
[0114] The expression of the LoRA efficient parameter fine-tuning is:
[0115] ;
[0116] In the formula, x represents the input vector, b represents the bias term, represents a low-rank matrix, represents the pre-trained model weights, A represents the adaptation matrix A, B represents the adaptation matrix B, where , W Represents the pre-trained weight matrix.
[0117] In some optional embodiments, the extraction processing module 10 includes:
[0118] An extraction unit, used for extracting professional knowledge in the field of antibiotics, and converting the professional knowledge in the field of antibiotics into txt document content;
[0119] The processing unit is used to review, typeset, annotate and repair the content of the txt document.
[0120] In some optional embodiments, the question generating module 20 includes:
[0121] A questioning unit, configured to use a preset large language model to ask content questions to the professional knowledge dataset to generate professional questions and professional answers, and to generate a question-answering dataset based on the professional questions and the professional answers;
[0122] A judging unit, used to judge whether the question-answering data set meets the HHH standard;
[0123] A typesetting unit is used to, if yes, typeset the question and answer dataset according to a fine-tuned format of the basic question and answer model.
[0124] In some optional embodiments, the second fine-tuning module 40 includes:
[0125] A decomposition unit, used for performing low-rank decomposition on the pre-trained weight matrix to obtain an adaptation matrix A and an adaptation matrix B;
[0126] A setting unit, used for setting the adaptation matrix A and the adaptation matrix B as trainable parameters;
[0127] An updating unit is used to minimize the loss function of the adaptation task through a back-propagation algorithm to update the adaptation matrix A and the adaptation matrix B, so as to fine-tune the combined basic question-answering model.
[0128] The functions or operation steps implemented when the above modules and units are executed are generally the same as those in the above method embodiments, and will not be repeated here.
[0129] The system for generating a personalized question-and-answer large language model provided in the embodiment of the present invention has the same implementation principle and technical effects as those in the aforementioned method embodiment. For the sake of brief description, for matters not mentioned in the system embodiment, reference may be made to the corresponding contents in the aforementioned method embodiment.
[0130] In the description of this specification, the description with reference to the terms "one embodiment", "some embodiments", "examples", "specific examples", or "some examples" means that the specific features, structures, materials or characteristics described in conjunction with the embodiment or example are included in at least one embodiment or example of the present invention. In this specification, the schematic representation of the above terms does not necessarily refer to the same embodiment or example. Moreover, the specific features, structures, materials or characteristics described may be combined in any one or more embodiments or examples in a suitable manner.
[0131] The above-mentioned embodiments only express several implementation methods of the present invention, and the description thereof is relatively specific and detailed, but it cannot be understood as limiting the scope of the patent of the present invention. It should be pointed out that, for ordinary technicians in this field, several variations and improvements can be made without departing from the concept of the present invention, which all belong to the protection scope of the present invention. Therefore, the protection scope of the patent of the present invention shall be subject to the attached claims.
Claims
1. A method for generating a personalized question-answering large language model, characterized in that: The method comprises: Extracting professional knowledge content and preprocessing the professional knowledge content to obtain a professional knowledge data set; Using a preset model to ask questions to the professional knowledge dataset to generate a question-answer dataset; The step of using a preset model to ask questions to the professional knowledge dataset to generate a question-answer dataset includes: Using a preset large language model to ask content questions to the professional knowledge dataset to generate professional questions and professional answers, and generating a question-answering dataset based on the professional questions and the professional answers; Determining whether the question-answering dataset meets the HHH standard, wherein the HHH standard is authenticity, healthiness, and helpfulness; If yes, formatting the question-answering dataset according to the fine-tuned format of the basic question-answering model; Based on the question-answering dataset, fine-tune the basic question-answering model using P-tuning v2 to obtain a fine-tuned basic question-answering model, and combine the fine-tuned basic question-answering model with the basic question-answering model to obtain a combined basic question-answering model; Obtain a specific task and a data set related to the specific task, perform LoRA efficient parameter fine-tuning on the combined basic question-answering model based on the data set to obtain a fine-tuned combined basic question-answering model, and combine the fine-tuned combined basic question-answering model with the combined basic question-answering model to obtain a personalized large language model; The step of fine-tuning the LoRA efficient parameters based on the data set combined with the basic question-answering model comprises: Perform low-rank decomposition on the pre-trained weight matrix to obtain adaptation matrix A and adaptation matrix B; Setting the adaptation matrix A and the adaptation matrix B as trainable parameters; The adaptation matrix A and the adaptation matrix B are updated by minimizing the loss function of the adaptation task through the back-propagation algorithm to fine-tune the combined basic question-answering model.
2. The method for generating a personalized question-answering large language model according to claim 1, characterized in that: The step of extracting professional knowledge content and preprocessing the professional knowledge content includes: Extracting professional knowledge in the field of antibiotics, and converting the professional knowledge in the field of antibiotics into txt document content; Review, typeset, annotate and repair the contents of the txt document.
3. The method for generating a personalized question-answering large language model according to claim 1, characterized in that: The expression of the P-tuning v2 efficient parameter fine-tuning is: ; In the formula, ⊕ represents the fusion operation, represents the set of pre-trained parameters, Represents the parameter set of the fine-tuning task, Represents the minimization task characteristic parameter The objective function is represents a task-specific loss function.
4. The method for generating a personalized question-answering large language model according to claim 1, characterized in that: The expression for the LoRA efficient parameter fine-tuning is: ; In the formula, x represents the input vector, b represents the bias term, represents a low-rank matrix, represents the pre-trained model weights, A represents the adaptation matrix A, B represents the adaptation matrix B, where , W Represents the pre-trained weight matrix.
5. A system for generating a personalized question-answering large language model, characterized in that: The system comprises: An extraction and processing module, used to extract professional knowledge content and pre-process the professional knowledge content to obtain a professional knowledge data set; A question generation module, used to ask questions to the professional knowledge dataset using a preset model to generate a question-answer dataset; The question generation module comprises: A questioning unit, configured to use a preset large language model to ask content questions to the professional knowledge dataset to generate professional questions and professional answers, and to generate a question-answering dataset based on the professional questions and the professional answers; A judging unit, configured to judge whether the question-answering data set meets the HHH standard, wherein the HHH standard is authenticity, healthiness, and helpfulness; A typesetting unit, configured to typeset the question-answering dataset according to a fine-tuned format of a basic question-answering model if the question-answering dataset meets the HHH standard; A first fine-tuning module is used to perform P-tuning v2 efficient parameter fine-tuning on the basic question-answering model based on the question-answering dataset to obtain a fine-tuned basic question-answering model, and combine the fine-tuned basic question-answering model with the basic question-answering model to obtain a combined basic question-answering model; A second fine-tuning module is used to obtain a specific task and a data set related to the specific task, and perform LoRA efficient parameter fine-tuning on the combined basic question-answering model based on the data set to obtain a fine-tuned combined basic question-answering model, and combine the fine-tuned combined basic question-answering model with the combined basic question-answering model to obtain a personalized large language model; The second fine-tuning module comprises: A decomposition unit, used for performing low-rank decomposition on the pre-trained weight matrix to obtain an adaptation matrix A and an adaptation matrix B; A setting unit, used to set the adaptation matrix A and the adaptation matrix B as trainable parameters; An updating unit is used to minimize the loss function of the adaptation task through a back-propagation algorithm to update the adaptation matrix A and the adaptation matrix B, so as to fine-tune the combined basic question-answering model.
6. The system for generating a personalized question-answering large language model according to claim 5, characterized in that: The extraction processing module comprises: An extraction unit, used for extracting professional knowledge in the field of antibiotics, and converting the professional knowledge in the field of antibiotics into txt document content; The processing unit is used to review, typeset, annotate and repair the content of the txt document.
Citation Information
Patent Citations
Knowledge graph generation type question answering method and system based on large language model
CN117033608A
Pre-hospital first-aid text classification labeling method based on ChatGLM model, electronic equipment, storage medium and computer program product
CN118277573A