Small-domain vertical-domain expert large model automatic fine-tuning training method and device
Patent Information
- Application Number
- CN202311181934.5
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2023-09-14
- Publication Date
- 2026-10-09
- Estimated Expiration
- 2043-09-14
AI Technical Summary
随着电网规模的扩大与复杂化,电力系统的运行和发展过程积累了海量的文本数据,但目前还未有一种可行的、在能够避免数据隐私泄露以及安全风险的条件下,有效利用大模型的方法
[0022] 1. This invention is applicable to scenarios based on local knowledge. Based on local data, a large model is fine-tuned and trained to build a private large model. While utilizing the advantages of the large model, it can avoid data privacy leakage and security risks, and can achieve more accurate and efficient vertical domain question answering while ensuring data security.
Smart Images

Figure CN117216564B_ABST
Abstract
Description
Technical Field
[0001] This invention relates to the field of natural language processing technology, and in particular to an automated fine-tuning training method and device for large models of experts in a small domain. Background Technology
[0002] Large models refer to machine learning models with a large number of parameters and complex structures. These models can be applied to handle large-scale data and complex problems. The advantages of pre-trained large language models can be summarized as follows: they can learn general language representations using massive amounts of unlabeled corpus data and improve the performance of downstream tasks; they can better initialize other models, accelerate model training, and improve performance; pre-training can reduce the risk of overfitting to small datasets in downstream tasks.
[0003] As large-scale models are released and iterated, they become increasingly intelligent. However, this process presents significant data security and privacy challenges. When leveraging the capabilities of large-scale models, people generally desire complete control over their private data and environment to avoid any data privacy leaks and security risks. With the expansion and increasing complexity of power grids, the operation and development of power systems have accumulated massive amounts of text data. Currently, however, there is no feasible method to effectively utilize large-scale models while avoiding data privacy leaks and security risks. Summary of the Invention
[0004] The purpose of this invention is to overcome the shortcomings of the existing technology and provide an automated fine-tuning training method and device for large models of small domain experts, so as to realize the reliable application of small domain dialogue language models while reducing computing power and equipment requirements, avoiding data privacy leakage and security risks.
[0005] The objective of this invention can be achieved through the following technical solutions:
[0006] An automated fine-tuning training method for large models of experts in a small domain includes the following steps:
[0007] Obtain local unstructured text, preprocess the local unstructured text, and generate a structured training set;
[0008] Using a large language model, a question-answer pair dataset with a specified format is generated based on the structured training set.
[0009] Using the question-answer pair dataset, the large language model is fine-tuned based on the P-Tuning v2 method to obtain the final small-domain vertical dialogue language model.
[0010] Furthermore, the preprocessing includes embedding mapping and vectorization.
[0011] Furthermore, the large language model is the chatGLM-6B model.
[0012] Furthermore, a prompt for the large language model is constructed based on the structured training set, and the prompt is input into the large language model to generate a question-answer pair dataset with a specified format.
[0013] Furthermore, the prompt for constructing the large language model based on the structured training set is specifically as follows:
[0014] Obtain the initial question text and preprocess it;
[0015] Based on the preprocessed initial question text, the most similar text blocks are found from the structured training set, and the text blocks are combined to form the prompt.
[0016] Furthermore, the preprocessing includes embedding mapping and vectorization.
[0017] Furthermore, the fine-tuning based on the P-Tuning v2 method is a prefix fine-tuning.
[0018] Furthermore, before using the question-and-answer pair dataset, the question-and-answer pair dataset is cleaned.
[0019] The present invention also provides an automated fine-tuning training device for a large model of a small domain expert, including a memory, a processor, and a program stored in the memory, wherein the processor executes the program to implement the method described above.
[0020] The present invention also provides a storage medium having a program stored thereon, wherein the program, when executed, implements the method described above.
[0021] Compared with the prior art, the present invention has the following beneficial effects:
[0022] 1. This invention is applicable to scenarios based on local knowledge. Based on local data, a large model is fine-tuned and trained to build a private large model. While utilizing the advantages of the large model, it can avoid data privacy leakage and security risks, and can achieve more accurate and efficient vertical domain question answering while ensuring data security.
[0023] 2. The computational and equipment requirements of existing full-parameter fine-tuning large language models are beyond the reach of ordinary laboratories and even enterprises. However, this invention uses fine-tuning based on the P-Tuning v2 method to fine-tune and train large models, enabling small-domain vertical dialogue language models to be trained at low training cost.
[0024] 3. The present invention provides a method for extracting structured text datasets from everyday texts, which expands the ways to obtain datasets and lays the foundation for establishing dialogue language models for specific domains. Attached Figure Description
[0025] Figure 1 This is a schematic diagram of the process of the present invention;
[0026] Figure 2 This is a structural diagram of the P-Tuning v2 used in this invention;
[0027] Figure 3 This is a schematic diagram of the prompt text constructed for this invention;
[0028] Figure 4 This is a schematic diagram of the electricity Q&A data obtained in an embodiment of the present invention. Detailed Implementation
[0029] The present invention will now be described in detail with reference to the accompanying drawings and specific embodiments. These embodiments are based on the technical solution of the present invention and provide detailed implementation methods and specific operating procedures. However, the scope of protection of the present invention is not limited to the following embodiments.
[0030] This invention provides a complete private large-scale model solution for scenarios based on local knowledge. It supports local deployment and can be applied not only to independent private environments but also to independent deployment and isolation based on business modules. This ensures that the capabilities of the large-scale model are absolutely private, secure, and controllable, thereby improving data security.
[0031] This invention, based on the large model chatGLM-6B, utilizes the LangChain method. It first extracts a dataset from local knowledge, then uses this dataset to perform prompt fine-tuning of the chatGLM-6B model, achieving an automated process for a local knowledge-based, niche-domain dialogue language model. LangChain is a powerful framework designed to help developers build end-to-end applications using language models. It provides a set of tools, components, and interfaces to simplify the process of creating applications powered by large language models (LLMs) and chat models.
[0032] Example 1
[0033] refer to Figure 1 As shown, this embodiment provides an automated fine-tuning training method for a large model of a small domain expert, including the following steps:
[0034] Step S1: Obtain local unstructured text, preprocess the local unstructured text, and generate a structured training set.
[0035] like Figure 1As shown, the Unstructured Loader obtains local documents, generates text to be processed, extracts text chunks through a text splitter, performs embedding mapping and vectorization on the text chunks, and saves them in a vector store as a structured training set.
[0036] Step S2: Using a large language model, generate a question-answer pair dataset with a specified format based on the structured training set.
[0037] The large language model used in this embodiment is the chatGLM-6B model. ChatGLM-6B is an open-source text-generative dialogue model based on the General Language Model (GLM) framework, which can realize functions such as self-awareness, copywriting, outline writing, and information extraction.
[0038] In this embodiment, a prompt for the large language model is constructed based on the structured training set, and the prompt is input into the large language model to generate a question-answer pair dataset with a specified format.
[0039] The prompts for constructing a large language model based on a structured training set specifically include:
[0040] Obtain the initial question text and preprocess it;
[0041] Based on the preprocessed initial question text, the most similar text blocks are found from the structured training set, and the text blocks are combined to form the prompt.
[0042] like Figure 1 As shown, the initial input question text (Query) is also preprocessed with embedding mapping and vectorization to obtain the question vector (Query Vector). The similarity of a vector with the previously vectorized local text is calculated (Vector Similarity). The K most similar Docs (Related Text Chunks), i.e., text chunks related to the proposed question, are found. Based on the prompt template, the prompt for obtaining the required Large Language Model (LLM) is constructed. The LLM obtains the corresponding question-answering result (Answer) based on the input prompt.
[0043] For example, we can input text related to electricity knowledge into the framework, and when inputting the question, explicitly state "Please output the corresponding dataset based on the relevant text", and specify the corresponding format: "content:", "summary:"; thus obtaining structured data.
[0044] Step S3: Using the question-answer pair dataset, fine-tune the large language model based on the P-Tuning v2 method to obtain the final small-domain vertical dialogue language model.
[0045] P-Tuning v2 applies prefix-tuning to NLU tasks, and its principle is as follows: Figure 2 As shown.
[0046] Prefix-tuning, initially applied to NLG tasks, consists of three parts: [Prefix, x, y], as shown in the diagram above: Prefix is the prefix, x is the input, and y is the output. Prefix-tuning fixes the pre-trained parameters and fine-tunes the prefix parameters: not only on the embedding but also on the transformer's embedding input at each layer. P-tuning v2 is essentially prefix-tuning; in the prefix part, the embedding input of each transformer layer needs to be tuned. This significantly reduces the number of parameters requiring fine-tuning, allowing fine-tuning of large language models to be performed on consumer-grade GPUs. The computational and equipment requirements of existing fully parameter-tuned large language models are prohibitive for ordinary laboratories and even enterprises. However, fine-tuning large models using the P-Tuning v2 method allows for the training of small-domain, vertical-domain dialogue language models at a low training cost.
[0047] In a preferred embodiment, before using the question-answer pair dataset, the dataset is cleaned to remove question-answer pairs that deviate significantly from the text or are duplicated, thereby improving the training effect.
[0048] In one specific implementation, a prompt is first input into the large model, local power-related text data is uploaded, and a question-and-answer pair dataset related to the text content is generated, specifying the corresponding format as "content:" and "summary:". The prompt constructed in this embodiment is as follows: Figure 3 As shown.
[0049] The generated question-and-answer pair dataset was cleaned, removing pairs that deviated significantly from the text and duplicates. The generated question-and-answer pairs were in the following format: Figure 4 As shown.
[0050] To illustrate the effectiveness of the above method, this embodiment uses the generated power question-and-answer pairs data to simultaneously fine-tune the ChatGLM-6B model based on Finetune and P-Tuning v2. The parameter settings for Finetune and P-tuning v2 are shown in Table 1.
[0051] Table 1 Parameter Settings
[0052]
[0053] The evaluation metrics used were the Chinese Rouge score and BLEU-4, and the results are shown in Table 2. Table 2 shows that fine-tuning based on P-Tuning v2 yields better results.
[0054] Table 2 Evaluation Results
[0055]
[0056]
[0057] If the above methods are implemented as software functional units and sold or used as independent products, they can be stored in a computer-readable storage medium. Based on this understanding, the technical solution of this invention, or the part that contributes to the prior art, or a part of the technical solution, can be embodied in the form of a software product. This computer software product is stored in a storage medium and includes several instructions to cause a computer device (which may be a personal computer, server, or network device, etc.) to execute all or part of the steps of the methods described in the various embodiments of this invention. The aforementioned storage medium includes various media capable of storing program code, such as USB flash drives, portable hard drives, read-only memory (ROM), random access memory (RAM), magnetic disks, or optical disks.
[0058] Example 2
[0059] This embodiment provides an automated fine-tuning training device for a large model of a small-domain vertical expert, including a structured processing module, a model prompting construction module, and a fine-tuning module. The structured processing module acquires local unstructured text, preprocesses the unstructured text, and generates a structured training set. The model prompting construction module uses a large language model and the structured training set to generate a question-answer pair dataset with a specified format. The fine-tuning module uses the question-answer pair dataset to fine-tune the large language model based on the P-Tuning v2 method to obtain the final small-domain vertical dialogue language model. The rest is the same as in Embodiment 1.
[0060] Those skilled in the art will understand that embodiments of the present invention can be provided as methods, systems, or computer program products. Therefore, the present invention can take the form of a completely hardware embodiment, a completely software embodiment, or an embodiment combining software and hardware aspects. Furthermore, the present invention can take the form of a computer program product implemented on one or more computer-usable storage media (including but not limited to disk storage, CD-ROM, optical storage, etc.) containing computer-usable program code. The solutions in the embodiments of the present invention can be implemented using various computer languages, such as the object-oriented programming language Java and the interpreted scripting language JavaScript.
[0061] This invention is described with reference to flowchart illustrations and / or block diagrams of methods, apparatus (systems), and computer program products according to embodiments of the invention. It will be understood that each block of the flowchart illustrations and / or block diagrams, and combinations of blocks in the flowchart illustrations and / or block diagrams, can be implemented by computer program instructions. These computer program instructions can be provided to a processor of a general-purpose computer, special-purpose computer, embedded processor, or other programmable data processing apparatus to produce a machine, such that the instructions, which execute via the processor of the computer or other programmable data processing apparatus, generate instructions for implementing the flowchart illustrations and / or block diagrams. Figure 1 One or more processes and / or boxes Figure 1 A device that provides the functions specified in one or more boxes.
[0062] The preferred embodiments of the present invention have been described in detail above. It should be understood that those skilled in the art can make numerous modifications and variations based on the concept of the present invention without creative effort. Therefore, all technical solutions that can be obtained by those skilled in the art based on the concept of the present invention through logical analysis, reasoning, or limited experimentation on the basis of existing technology should be within the scope of protection defined by the claims.
Claims
1. A method for automated fine-tuning training of a large model of experts in a small domain, characterized in that, Includes the following steps: Obtain local unstructured text, preprocess the local unstructured text to generate a structured training set, the preprocessing including embedding mapping and vectorization; Using a large language model, a prompt for the large language model is constructed based on the structured training set. The prompt is then input into the large language model to generate a question-answer pair dataset with a specified format. The large language model is the chatGLM-6B model. The specified format includes a content field and a summary field, where the content field records the question text and the summary field records the answer text corresponding to the question. Using the question-answer pair dataset, the large language model is fine-tuned based on the P-Tuning v2 method to obtain the final small-domain vertical dialogue language model. Before using the question-answer pair dataset, the dataset is cleaned. The fine-tuning based on the P-Tuning v2 method is a prefix fine-tuning. The data cleaning includes deleting question-answer pairs with large text deviations and duplicates. The prompt for constructing a large language model based on the structured training set is as follows: Obtain the initial question text and preprocess it; Based on the preprocessed initial question text, the most similar text blocks are found from the structured training set, and the text blocks are combined to form the prompt.
2. An automated fine-tuning training device for a large model of a small-domain vertical expert, comprising a memory, a processor, and a program stored in the memory, characterized in that, When the processor executes the program, it implements the method as described in any one of claims 1.
3. A storage medium having a program stored thereon, characterized in that, When the program is executed, it implements the method as described in any of claims 1.
Citation Information
Patent Citations
Professional field document abstract generation method and system under small sample condition
CN116662537A
SOFTWARE PROGRAM TEST CREATION FOR COMPUTING SYSTEMS AND APPLICATIONS
DE102025133017A1