Question answering method and device for continuing pre-training based on large model, equipment and medium
Through the continued pre-training Q&A method based on large models, the problem of manual labeling data dependence in the existing technology is solved, training efficiency and accuracy are improved, cost and workload are reduced, and efficient and accurate Q&A model generation is achieved.
Patent Information
- Application Number
- CN202510107801.6
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2025-01-23
- Publication Date
- 2025-04-18
AI Technical Summary
In the knowledge Q&A scenario, the prior art relies on manual labeling training data, resulting in high labor costs and workload, poor training results and insufficient efficiency and accuracy.
The continuous pre-training question and answer method based on the big model is adopted. By obtaining multiple preset length threshold training data sets and hyperparameters, the pre-trained big model is continued to be trained, the initial question and answer model is generated, and the optimal question and answer model is determined through the test set to avoid the dependence of manually labeling data.
This improves the continuous training efficiency and accuracy of the model, reduces labor costs and workload, and ensures the efficiency and accuracy of the Q&A model.
Smart Images

Figure CN119848216A_ABST
Abstract
Description
Technical Field
[0001] The present application relates to the field of large model training, and in particular to a question-answering method, device, equipment and medium for continued pre-training based on a large model. Background Art
[0002] Traditional knowledge question-answering methods rely on pre-built knowledge bases to provide accurate answers. The core of the method is to select the knowledge base that best matches the question and retrieve the answer from the knowledge base. However, with the continuous expansion and updating of the knowledge field, the efficiency and accuracy of question-answering are becoming more and more obvious when facing large-scale knowledge bases.
[0003] The prior art uses a method based on SFT fine-tuning (Supervised Fine-Tuning), which uses a large-scale corpus to perform preliminary training on the pre-trained model so that it has basic language understanding and generation capabilities; it mainly targets specific knowledge question-answering scenarios, selects a part of question-answer pairs as training data through manual labeling, and fine-tunes the model so that the model can directly generate corresponding answers based on the input questions without selecting a specific knowledge base. However, since SFT fine-tuning requires manual labeling of training data, this brings huge labor costs and workload in practical applications, and there may be errors in labeling, but the training effect is general. Therefore, the method based on SFT fine-tuning has certain shortcomings in terms of efficiency and accuracy. Summary of the invention
[0004] The purpose of this application is to provide a question-answering method, device, equipment and medium for continued pre-training based on a large model, which can improve the efficiency and accuracy of continued training of the model, and in the process of continued training, there is no need to rely on manually labeled training data, thereby reducing labor costs and workload.
[0005] First, a question answering method based on continued pre-training of a large model is provided, including:
[0006] Obtaining training data sets, multiple hyperparameters, and a pre-trained large model corresponding to each of a plurality of preset length thresholds, wherein the training data set corresponding to each preset length threshold includes a plurality of training data, and the plurality of training data are obtained by slicing the training text based on the preset length threshold;
[0007] For each training data set, the pre-trained large model is further trained according to multiple hyperparameters to obtain the initial question-answering models corresponding to the multiple hyperparameters.
[0008] Based on multiple initial question-answering models corresponding to each of the multiple training data sets, a test set is used to perform testing to determine a question-answering model from the multiple initial question-answering models, wherein the question-answering model is used to output a reply content corresponding to the question sentence based on the question sentence.
[0009] In a preferred example, the present application can be further configured as follows: according to a plurality of initial question-answering models corresponding to each of the plurality of training data sets, a test set is used to perform a test to determine a question-answering model from the plurality of initial question-answering models, including:
[0010] According to the multiple initial question-answering models corresponding to the multiple training data sets, the test set is used to test and obtain the accuracy corresponding to the multiple initial question-answering models;
[0011] A question-answering model is determined from the multiple initial question-answering models according to the respective accuracies corresponding to the multiple initial question-answering models.
[0012] In a preferred example, the present application can be further configured as follows: it also includes a process of configuring various parameters during the training process, specifically including:
[0013] Use the highest level zero redundancy optimizer to optimize the third stage;
[0014] Offloading optimizer state to the CPU;
[0015] Locks the CPU's memory into physical memory.
[0016] In a preferred example, the present application can be further configured to: obtain a plurality of training data sets corresponding to respective preset length thresholds, including:
[0017] Get training samples;
[0018] Slicing the training sample according to a target preset length threshold to obtain a plurality of slice data corresponding to the target preset length threshold, wherein the target preset length threshold is any threshold among the plurality of preset length thresholds;
[0019] According to the plurality of slice data corresponding to the target preset length threshold, a training data set corresponding to the target preset length threshold is determined to obtain training data sets corresponding to each of the plurality of preset length thresholds.
[0020] In a preferred example, the present application can be further configured as follows: the training sample includes multiple lines of data, and there is a blank line between the paragraphs of the training sample.
[0021] According to the target preset length threshold, the training sample is sliced to obtain a plurality of slice data corresponding to the target preset length threshold, including:
[0022] Traverse each row of data of the training sample so that during the slicing process, if the current row is a blank row and the current slice data length is greater than 0, it is determined that the current slicing task is completed and then the next slicing task is performed;
[0023] If the current row is not an empty row, determining whether the total length of the current row data and the current slice data is greater than the target preset length threshold;
[0024] If it is greater than the target preset length threshold, within the target preset length threshold, select the nearest segmentation mark as the slicing point, obtain slicing data, complete the current slicing task, and then proceed to the next slicing task;
[0025] If it is not greater than the target preset length threshold, continue to process the next row of data until the slicing point of the current slicing task is determined to obtain slicing data;
[0026] After the slices of the target preset length threshold are completed, a plurality of slice data corresponding to the target preset length threshold are obtained.
[0027] In a preferred example, the present application may be further configured as follows: determining a training data set corresponding to the target preset length threshold according to a plurality of slice data corresponding to the target preset length threshold, including:
[0028] splicing a plurality of slice data corresponding to the target preset length threshold and a plurality of slice data corresponding to other preset length thresholds to obtain a plurality of new training samples; the other preset length thresholds are thresholds among the plurality of preset length thresholds except the target preset length threshold;
[0029] Slicing each new training sample according to the target preset length threshold to obtain a plurality of new slice data;
[0030] The plurality of slice data corresponding to the target preset length threshold and the plurality of new slice data are used as the training data set corresponding to the target preset length threshold.
[0031] In a preferred example, the present application may be further configured as follows: for each training data set, the pre-trained large model is continuously trained according to multiple hyperparameters, and after obtaining the initial question-answering models corresponding to the multiple hyperparameters, the following further includes:
[0032] Encapsulate the model service corresponding to the initial question-answering model into an accessible interface service;
[0033] Define application programming interface parameters corresponding to the interface service.
[0034] In a second aspect, a question-answering device based on continuous pre-training of a large model is provided, comprising:
[0035] An acquisition module is used to acquire training data sets corresponding to a plurality of preset length thresholds, a plurality of hyperparameters, and a pre-trained large model, wherein the training data set corresponding to each preset length threshold includes a plurality of training data, and the plurality of training data are obtained by slicing the training text based on the preset length threshold;
[0036] A training module is used to continue training the pre-trained large model according to multiple hyperparameters for each training data set to obtain an initial question-answering model corresponding to each of the multiple hyperparameters;
[0037] The testing module is used to perform testing using a test set based on multiple initial question-answering models corresponding to each of the multiple training data sets, so as to determine a question-answering model from the multiple initial question-answering models, wherein the question-answering model is used to output a reply content corresponding to a question sentence based on the question sentence.
[0038] According to a third aspect, an electronic device is provided, comprising a memory and a processor, wherein a computer program is stored in the memory, and when the processor runs the computer program, the question-answering method based on continued pre-training of a large model as described in any one of the first aspects is executed.
[0039] In a fourth aspect, a computer-readable storage medium is provided, wherein at least one program code is stored in the computer-readable storage medium, and the program code is loaded and executed by a processor to implement the question-answering method based on continued pre-training of a large model as described in any one of the first aspects.
[0040] In a fifth aspect, a computer program product is provided, comprising a computer program or instructions, which, when executed by a processor, implements the question-answering method based on continued pre-training of a large model as described in any one of the first aspects.
[0041] In summary, the question-answering method based on continued pre-training of a large model provided in this application includes the following beneficial technical effects:
[0042] Acquire multiple training data sets based on slice data with different preset length thresholds; continue to train the pre-trained large model using multiple hyperparameters to obtain multiple initial question-answering models, which can use training data of different lengths and different hyperparameters to enable the model to learn texts of different lengths in an unsupervised manner under different hyperparameters; test multiple initial question-answering models through a test set, and compare the learning conditions of different initial question-answering models, so as to determine the optimal question-answering model from multiple initial question-answering models, and accurately determine the model with the optimal text length and hyperparameters that meet the scenario, so that the final question-answering model has excellent accuracy and reliability, and does not need to rely on manually labeled training data during continued training, thereby reducing labor costs and workload.
[0043] In addition, the present application also provides a question-answering device, equipment and medium for continued pre-training based on a large model, all of which have the above-mentioned beneficial technical effects. BRIEF DESCRIPTION OF THE DRAWINGS
[0044] In order to more clearly illustrate the embodiments of the present application or the technical solutions of the prior art, the drawings required for use in the embodiments or the description of the prior art will be briefly introduced below. Obviously, the drawings described below are only some embodiments of the present application. For ordinary technicians in this field, other drawings can be obtained based on these drawings without paying any creative work.
[0045] Figure 1 It is a flowchart of a question-answering method based on continued pre-training of a large model provided in an embodiment of the present application;
[0046] Figure 2 It is a flowchart of another question-answering method based on continued pre-training of a large model provided in an embodiment of the present application;
[0047] Figure 3 It is a flowchart of a data processing provided by an embodiment of the present application;
[0048] Figure 4 It is a structural schematic diagram of a question-answering device based on continuous pre-training of a large model provided in an embodiment of the present application;
[0049] Figure 5 It is a structural schematic diagram of an electronic device provided in an embodiment of the present application. DETAILED DESCRIPTION
[0050] This specific embodiment is merely an explanation of the present application and is not a limitation of the present application. After reading this specification, a person skilled in the art may make non-creative modifications to the present embodiment as needed, but such modifications are protected by the patent law as long as they are within the scope of the present application.
[0051] It should be noted that in the optional embodiments of the present application, the object information and other related data involved, when the embodiments in the present application are applied to specific products or technologies, need to obtain the permission or consent of the object, and the collection, use and processing of the relevant data need to comply with the relevant laws, regulations and standards of the relevant countries and regions. In other words, if the embodiments of the present application involve data related to the object, it needs to be obtained with the authorization and consent of the object, the authorization and consent of the relevant departments, and in compliance with the relevant laws, regulations and standards of the country and region. If personal information is involved in the embodiments, the acquisition of all personal information needs to obtain the consent of the individual. If sensitive information is involved, the separate consent of the information subject needs to be obtained. The embodiments also need to be implemented with the authorization and consent of the object.
[0052] In order to make the purpose, technical solution and advantages of the embodiments of the present application clearer, the technical solution in the embodiments of the present application will be clearly and completely described below in conjunction with the drawings in the embodiments of the present application. Obviously, the described embodiments are part of the embodiments of the present application, not all of the embodiments. Based on the embodiments in the present application, all other embodiments obtained by ordinary technicians in this field without creative work are within the scope of protection of this application.
[0053] In addition, the term "and / or" in this article is only a description of the association relationship of associated objects, indicating that there can be three relationships. For example, A and / or B can represent: A exists alone, A and B exist at the same time, and B exists alone. In addition, the character " / " in this article, unless otherwise specified, generally means that the associated objects before and after are in an "or" relationship.
[0054] Pre-training is a machine learning technique that uses a large amount of unlabeled data to preliminarily train the model so that the model has certain prior knowledge and common sense, thereby improving the model's performance on various tasks. Pre-training technology is widely used in natural language processing, computer vision, speech recognition and other fields, and has achieved remarkable results.
[0055] Continued pre-training refers to the process of further training the model based on the existing pre-trained model for a dataset of a specific field or task. Pre-trained models are usually trained on large-scale general datasets, and continued pre-training is to make the model better adapt to the data distribution and task requirements of a specific field, thereby improving the performance of the model in that field or task.
[0056] Continuing pre-training can improve the adaptability of the model in the field, significantly reduce the demand for manually labeled data, and accelerate the progress of model development.
[0057] The purpose of the present invention is to provide a knowledge question answering system and method for continuous pre-training based on a large model in the IT industry, to solve the universality problem of the knowledge question answering scenario model, to avoid the drawbacks of the traditional knowledge question answering scenario that requires the selection of a knowledge base, and at the same time to avoid the huge workload of manual labeling brought by SFT (Supervised Fine-Tuning), thereby improving work efficiency.
[0058] The present invention can collect and organize a large amount of company regulations document data, input it into a large model, and continue to pre-train it, thereby realizing unsupervised learning of internal documents and regulations of IT companies, and finally realizing intelligent question answering, while greatly reducing the workload of manual annotation and greatly improving work efficiency. Of course, the above scenario is only an example, and the embodiments of the present application can also be applied to other scenarios.
[0059] Specifically, the embodiment of the present application provides a question-answering method based on continued pre-training of a large model, such as Figure 1 As shown, the method provided in the embodiment of the present application can be executed by an electronic device, and the electronic device is a server. The server can be an independent physical server, or a server cluster or distributed system composed of multiple physical servers, or a cloud server that provides cloud computing services. The terminal device can be a smart phone, a tablet computer, a laptop computer, a desktop computer, etc., but is not limited to this. The terminal device and the electronic device can be directly or indirectly connected via wired or wireless communication, which is not limited in the embodiment of the present application. The method includes:
[0060] S101, obtaining a plurality of training data sets corresponding to respective preset length thresholds, a plurality of hyperparameters and a pre-trained large model,
[0061] Wherein, the training data set corresponding to each preset length threshold includes a plurality of training data, and the plurality of training data are obtained by slicing the training text based on the preset length threshold;
[0062] Among them, the preset length threshold is a preset text length limit, which is used to cut a longer training text into multiple shorter slice data. The number of multiple preset length thresholds is not limited in the embodiment of this application, and the user can customize the setting. Exemplarily, the multiple preset length thresholds can be set to 750, 1000, 2000, 3000, 4000, 5000, and 6000. The training data set corresponding to each preset length threshold includes multiple training data, and each training data is data with a length within the preset length threshold range. For the content type of the training data, the embodiment of this application is no longer limited, and the user can set it according to actual needs. For example, when it is used for questions and answers about internal company documents and regulations in the IT industry, the training text corresponding to the training data is the company's internal documents and regulations.
[0063] Pre-trained large models are deep learning models that have been pre-trained on large-scale datasets. They contain rich language knowledge and semantic representation capabilities. By fine-tuning these pre-trained models, they can be quickly adapted to the needs of specific fields.
[0064] Hyperparameters are parameters set manually before training the pre-trained large model, which affect the training process and final performance of the model. Among them, multiple hyperparameters are set, such as setting the training stage to "pt", specifying the fine-tuning type to "full", specifying two GPU (Graphics Processing Unit, graphics processor) cards, the truncation length to "4096", the number of worker threads to "2", the training batch size on each device (GPU) to "7", the number of gradient accumulation steps to "500", the initial learning rate to "1e-5", and using 16-bit floating point precision.
[0065] S102. For each training data set, continue training the pre-trained large model according to multiple hyperparameters to obtain initial question-answering models corresponding to the multiple hyperparameters;
[0066] For each training data set, continue training based on each hyperparameter. For example, if there are 3 sets of hyperparameters, then based on training data set a, continue training the pre-trained large model of the first set of hyperparameters to obtain the first initial question-answering model; based on training data set a, continue training the pre-trained large model of the second set of hyperparameters to obtain the second initial question-answering model; based on training data set a, continue training the pre-trained large model of the third set of hyperparameters to obtain the third initial question-answering model.
[0067] In some feasible embodiments, DeepSpeed is used for continued pre-training, hyperparameters are continuously adjusted, the training effects of models with different parameters are tested, logs of all training models are collected, hyperparameters are extracted, and train-loss graphs of all models are exported and summarized into an Excel table for analysis.
[0068] S103, testing the multiple initial question-answering models corresponding to the multiple training data sets using the test set to determine a question-answering model from the multiple initial question-answering models;
[0069] The question-answering model is used to output the answer content corresponding to the question.
[0070] The test set is used to evaluate the performance of the model, and includes questions and corresponding correct answers. Among them, according to the multiple initial question-and-answer models corresponding to each of the multiple training data sets, the test set is used for testing to obtain the accuracy corresponding to each of the multiple initial question-and-answer models; according to the accuracy corresponding to each of the multiple initial question-and-answer models, the question-and-answer model is determined from the multiple initial question-and-answer models. According to each test question in the test set, the initial question-and-answer model is input to obtain the question-and-answer result; when the similarity between the question-and-answer result and the correct answer reaches a preset threshold, it means that the answer is correct, so as to obtain the accuracy corresponding to each initial question-and-answer model, and then, according to the accuracy corresponding to each of the multiple initial question-and-answer models, the initial question-and-answer model with the highest accuracy is determined from the multiple initial question-and-answer models as the question-and-answer model. Of course, the accuracy, recall rate and other indicators of the model can also be evaluated to select the question-and-answer model, and the embodiments of the present application are no longer limited.
[0071] It can be seen that in an embodiment of the present application, multiple training data sets based on slice data with different preset length thresholds are obtained; the pre-trained large model is further trained using multiple hyperparameters to obtain multiple initial question-answering models, which can use training data of different lengths and different hyperparameters to enable the model to learn texts of different lengths in an unsupervised manner under different hyperparameters; multiple initial question-answering models are tested through a test set, and the learning conditions of different initial question-answering models are compared to facilitate determining the optimal question-answering model from multiple initial question-answering models, and the model that is able to accurately determine the optimal text length and hyperparameters that meet the scenario, so that the final question-answering model has excellent accuracy and reliability, and does not need to rely on manually labeled training data during continued training, thereby reducing labor costs and workload.
[0072] The model continuous training method provided in the embodiment of the present invention needs to process the training samples. A possible implementation method of the embodiment of the present application obtains a training data set corresponding to each of multiple preset length thresholds, including: SA1-SA3 (not shown in the drawings), wherein:
[0073] SA1, obtain training samples;
[0074] In the embodiment of the present application, the original training sample documents are collected, and the formats may include PDF, Word and TXT; the original PDF and Word documents are converted into TXT text document format through OCR image recognition and format conversion tools. For the documents that have been converted to TXT, the end of each natural paragraph is identified, and an identifier (such as a blank line) is inserted between each natural paragraph; after the insertion is completed, multiple blank lines between each natural paragraph are merged into one blank line.
[0075] In some possible embodiments, when processing original training sample documents such as massive company rules and regulations documents, it is necessary to read the content of each text file. In order to ensure the smooth progress of the file reading process, a detailed file reading strategy needs to be formulated, including handling abnormal situations such as file non-existence and file reading errors. The following are the specific steps: by specifying the file path, open the file using an encoding format, which can be UTF-8 (8-bit Unicode Transformation Format), and read the file content line by line; the file path needs to be verified to ensure that the path is valid and the file exists; when reading each line of text, remove the leading and trailing blank characters of each line to ensure the neatness and standardization of the text content; if the file does not exist or an error occurs during the reading process, an error log needs to be recorded to facilitate subsequent investigation and processing.
[0076] SA2 slices the training sample according to the target preset length threshold to obtain a plurality of slice data corresponding to the target preset length threshold, where the target preset length threshold is any threshold among the plurality of preset length thresholds;
[0077] SA3 determines a training data set corresponding to the target preset length threshold according to the multiple slice data corresponding to the target preset length threshold, so as to obtain training data sets corresponding to each of the multiple preset length thresholds.
[0078] Specifically, after obtaining the sliced data of the text, it needs to be converted into a training sample object for subsequent model training and data processing. Each training data object contains instruction text (instruction) and output text (output). The instruction text is the sliced data after slicing, and the output text is left blank for subsequent model training generation.
[0079] Convert each training data object of the preset length threshold into a dictionary format and save it as a JSON (JavaScript Object Notation) format file. Specifically, create a corresponding directory structure according to the output file path and ensure that the path exists. Save each slice data as a separate JSON file, ensure that the file is encoded in UTF-8, set appropriate indentation to improve readability, and name it as the file name corresponding to the original text file.
[0080] In some possible cases, in order to uniformly process all text files in a directory, it is necessary to define a method to batch process these files. Specifically, check the input and output directories to ensure that the input and output directories exist, and create them if they do not exist; traverse all text files in the input directory, read, process and save the slice data in turn; after processing all text files, merge all slice data of each preset length threshold and save them as a whole JSON file.
[0081] Slicing of the training sample is further described. In a possible implementation of the embodiment of the present application, the training sample includes multiple lines of data, and there is a blank line between the paragraphs of the training sample.
[0082] According to the target preset length threshold, the training sample is sliced to obtain multiple slice data corresponding to the target preset length threshold, including:
[0083] Traverse each row of data of the training sample so that during the slicing process, if the current row is a blank row and the current slice data length is greater than 0, it is determined that the current slicing task is completed and then the next slicing task is performed;
[0084] If the current row is not an empty row, determine whether the total length of the current row data and the current slice data is greater than the target preset length threshold;
[0085] If it is greater than the target preset length threshold, within the target preset length threshold, select the nearest segmentation mark as the slicing point, obtain the slicing data, complete the current slicing task, and then proceed to the next slicing task;
[0086] If it is not greater than the target preset length threshold, continue to process the next row of data until the slicing point of the current slicing task is determined and the slicing data is obtained;
[0087] After the slices of the target preset length threshold are completed, a plurality of slice data corresponding to the target preset length threshold are obtained.
[0088] In an embodiment of the present application, when slicing, encountering a blank line indicates that slicing is to be performed across paragraphs. At this time, in order to ensure the semantic integrity of the data, if the current slicing task has a data length, the data of the current slicing task is directly used as the slicing data for this time; if the current slicing task has no data length, it indicates that this is the beginning of the current slicing task, and then execution can continue; and, in the slicing process, semantic integrity must also be considered to avoid slicing in the middle of a sentence.
[0089] Specifically, create a variable for storing the current slice content (such as current_slice) and a variable for recording the current slice length (such as current_length); traverse each line of text to determine whether it is an empty line; if it is an empty line and the current text length is greater than 0, end the processing of the current text, add it to the text list, and reset the text variable; after traversing all lines of text, if the current slice content is not empty, add it to the slice list.
[0090] Create a list (such as slices) for storing the final slices; if the current training text exceeds the preset length threshold, search for the nearest period or line break within the preset length threshold as the segmentation point. If not found, segment directly at the limit length; add the segmented text segment to the slice list, and repeat the above steps until the text is completely segmented.
[0091] In the embodiment of the present application, each line of data of the training sample is traversed, and the slicing point is determined according to the blank line and sentence segmentation mark, thereby ensuring the paragraph structure and integrity of the sliced data and the semantic coherence, and improving the quality of the training data set.
[0092] A possible implementation of the embodiment of the present application is to determine a training data set corresponding to a target preset length threshold according to a plurality of slice data corresponding to a target preset length threshold, including:
[0093] splicing a plurality of slice data corresponding to a target preset length threshold and a plurality of slice data corresponding to other preset length thresholds to obtain a plurality of new training samples; the other preset length thresholds are thresholds other than the target preset length threshold among the plurality of preset length thresholds;
[0094] Each new training sample is sliced according to a target preset length threshold to obtain multiple new slice data;
[0095] A plurality of slice data corresponding to the target preset length threshold and a plurality of new slice data are used as a training data set corresponding to the target preset length threshold.
[0096] Among them, after the original data is cut into multiple slice data according to the preset length threshold, in order to generate more diverse training samples, the slice data corresponding to the target preset length threshold can be spliced with the slice data corresponding to other preset length thresholds; the splicing operation can be performed according to actual needs, such as the number of splicing, the order of splicing, random splicing, etc. Through splicing, multiple new training samples with different lengths and features can be obtained. Slice data of different threshold lengths are mixed and superimposed to generate data with different total amounts of data. 1G, 5G, 10G, and 50G are trained separately to observe the training results.
[0097] In the embodiment of the present application, when determining the training data set, not only the slice data under the threshold is considered, but also the slice data under other preset length thresholds are spliced and re-sliced to increase the diversity and richness of the training data set.
[0098] A possible implementation method of an embodiment of the present application also includes a process for configuring various parameters during the training process, specifically including: using the highest level zero-redundancy optimizer to optimize the third stage; unloading the optimizer state to the central processing unit; and locking the memory of the central processing unit in the physical memory.
[0099] Among them, you can install the necessary environment dependencies and ensure that the large model service is deployed in the environment; ensure that the GPU card resources are sufficient.
[0100] Configure various parameters in the deepspeed distributed training process so that resource overhead must be minimized for resource-constrained scenarios. Among them, use the highest level of zero-redundancy optimizer ZeRO to optimize stage: "3" to minimize video memory usage. Configure the optimizer state to be unloaded to the central processing unit CPU so that when the model is large, the optimizer state such as gradients and dynamic parameters can easily occupy a large amount of GPU video memory. Unloading the optimizer state to the CPU can significantly reduce video memory usage. Configure to enable memory locking (pin_memory) to improve data transmission efficiency.
[0101] In an embodiment of the present application, the highest level zero-redundancy optimizer is configured during the training process, and the third stage is optimized to reduce unnecessary computing overhead and improve training efficiency; the optimizer state is unloaded to the central processing unit, and the memory of the central processing unit is locked in the physical memory, so that the system maintains sufficient memory to avoid training interruptions due to insufficient memory.
[0102] A possible implementation method of an embodiment of the present application is to continue training the pre-trained large model according to multiple hyperparameters for each training data set to obtain initial question-answering models corresponding to the multiple hyperparameters, and further include: encapsulating the model service corresponding to the initial question-answering model into an accessible interface service; and defining the application programming interface parameters corresponding to the interface service.
[0103] Among them, the model service is encapsulated as an accessible interface service, so that external applications can interact with the model through API (Application Programming Interface) calls. This process includes API interface definition, request processing, security check and response processing. Among them, API interface definition defines the API interface provided by the service to the outside, including request path, request method, request parameters and response format. For request processing: after receiving the user request, the request is first pre-processed, including parameter parsing, security check and logging. For security check: through the pre-configured security check mechanism, the user request and model response are verified for security to ensure that their content is legal and secure. For response processing: the response of the model service is processed and returned to the client in a predefined format. For service startup and operation: finally start the encapsulated interface service so that it can provide stable API services to the outside.
[0104] Furthermore, the method also includes: receiving a question and answer request input by a user; determining an answer using a question and answer model according to the question and answer request, and outputting the answer.
[0105] Further, after receiving the question-and-answer request input by the user, the question in the question-and-answer request is evaluated for validity, so as to determine whether the question lacks key information, the key information including the time and event corresponding to the question;
[0106] If the evaluation is passed, that is, the question is clearly expressed and the information is complete, then the question-answering model is used to determine at least one answer based on the question-answering request and output the answer;
[0107] If the question fails the evaluation, i.e., the question is vague, the information is insufficient, or the structure is incomplete, the question is automatically improved based on the user's historical behavior to obtain at least one improved question; specifically, the at least one improved question can be inferred based on the missing content and the common question-and-answer request patterns used by the user;
[0108] The improved question is answered using the question-answering model and the answer is output.
[0109] For example, the user's question and answer request is "query the required punch-in time", and it is known that the punch-in time is divided into summer punch-in and other season punch-in; therefore, the question and answer request lacks time; if the current time is autumn, it is predicted that the user wants to ask about the punch-in time in other seasons, so the question is improved to "query the required punch-in time in autumn".
[0110] Based on any of the above embodiments, see Figure 2 and Figure 3, the embodiment of the present application provides a method for continuing pre-training knowledge question answering based on a large model in the IT industry, including:
[0111] Step 1, primary processing of raw data;
[0112] Step 2: Slice and convert the massive amount of company rules and regulations documents that have been collected into the corresponding JSON format;
[0113] Step 3, training the set training data;
[0114] Step 4: Configure the start and stop mode for the trained model and encapsulate the interface;
[0115] Step 5: Design a suitable testing method for the knowledge question and answer scenario.
[0116] Wherein, step 1 specifically includes:
[0117] Step 1.1, collect raw data documents, the formats may include PDF, Word and TXT;
[0118] Step 1.2: Convert the original PDF and Word documents into TXT text document format using OCR and format conversion tools;
[0119] Step 1.3, for the document that has been converted to TXT, identify the end of each paragraph, insert a blank line between each paragraph, and merge multiple blank lines into one blank line.
[0120] Wherein, step 2 specifically includes:
[0121] Step 2.1, read the text file and perform the first file processing, including opening the file, removing blank characters and recording logs;
[0122] Step 2.2, slicing the text content and performing a second file processing, specifically slicing according to length limit, paragraph recognition and semantic integrity;
[0123] Step 2.3, further segment the text, preferably select the period or line break as the slicing point, generate and save the slices, and return the slice list;
[0124] Step 2.4, convert the slice content into a training sample object;
[0125] Step 2.5, save the processed data as a single JSON format file, and merge the data and save it as a JSON format file;
[0126] Step 2.6, process all documents, including checking input and output directories, traversing all text files, and merging and saving all data.
[0127] Among them, step 3 specifically includes: environment preparation, configuring various parameters in the DeepSpeed distributed training process, using DeepSpeed for continued pre-training, and trying to train source data with different slice threshold lengths.
[0128] Among them, step 4 specifically includes: starting the model service and encapsulating the interface service.
[0129] Wherein, step 5 specifically includes:
[0130] Step 5.1, determine the test data source, clarify the test data source, ensure that the test data is representative and covers a wide range of scenarios. The test data source can be extracted from existing company rules and regulations, FAQs, and actual user problems;
[0131] Step 5.2, Test Environment Configuration, configure a stable test environment, including setting up a logger to capture key information during the test, and installing and configuring necessary libraries and dependencies;
[0132] Step 5.3, test execution, traverses each question in the test data set, constructs the corresponding API request message body, sends the request to the API interface of the knowledge question answering system, parses the response content, and compares the returned answer with the expected answer;
[0133] Step 5.4, result analysis, count the total number of test questions, the number of consistent questions, and the number of questions that need manual verification, record and analyze any errors or exceptions that occur during the test, so as to carry out targeted optimization and improvement;
[0134] Step 5.5, result saving and reporting, save the test results back to the Excel file, and generate a detailed test report, including an overview of the test data, the configuration of the test environment, the process of test execution, result analysis, and any suggestions or improvements. The embodiment of the present invention constructs a universal cross-knowledge domain question-and-answer platform that can quickly produce results, and an unsupervised learning training method that does not require manual annotation, which significantly releases manpower, saves a lot of manpower training time, and greatly improves training efficiency.
[0135] The following is an introduction to a device provided in an embodiment of the present application. The device described below and the method described above can be referred to each other. The device of this embodiment is set in an electronic device, refer to,4, Figure 4 It is a structural block diagram of a device of one embodiment of the present application, comprising:
[0136] An acquisition module 210 is used to acquire training data sets corresponding to a plurality of preset length thresholds, a plurality of hyperparameters, and a pre-trained large model, wherein the training data set corresponding to each preset length threshold includes a plurality of training data, and the plurality of training data are obtained by slicing the training text based on the preset length threshold;
[0137] A training module 220 is used to continue training the pre-trained large model according to multiple hyperparameters for each training data set to obtain an initial question-answering model corresponding to each of the multiple hyperparameters;
[0138] The testing module 230 is used to perform testing using a test set based on multiple initial question-answering models corresponding to each of the multiple training data sets, so as to determine a question-answering model from the multiple initial question-answering models, where the question-answering model is used to output a reply content corresponding to the question based on the question.
[0139] In a preferred example, the present application can be further configured as: a test module 230 for:
[0140] According to the multiple initial question-answering models corresponding to the multiple training data sets, the test set is used to test and obtain the accuracy corresponding to the multiple initial question-answering models;
[0141] A question-answering model is determined from the multiple initial question-answering models according to the respective accuracies of the multiple initial question-answering models.
[0142] In a preferred example, the present application can be further configured as follows: the training module 220 is also used to:
[0143] Use the highest level zero redundancy optimizer to optimize the third stage;
[0144] Offloading optimizer state to the CPU;
[0145] Locks the CPU's memory into physical memory.
[0146] In a preferred example, the present application can be further configured as follows: the acquisition module 210 includes:
[0147] Data collection submodule, used to obtain training samples;
[0148] The input data preprocessing submodule is used to slice the training samples according to the target preset length threshold to obtain multiple slice data corresponding to the target preset length threshold, where the target preset length threshold is any threshold among the multiple preset length thresholds; based on the multiple slice data corresponding to the target preset length threshold, determine the training data set corresponding to the target preset length threshold to obtain the training data sets corresponding to each of the multiple preset length thresholds.
[0149] In a preferred example, the present application can be further configured as follows: the training sample includes multiple lines of data, and there is a blank line between the paragraphs of the training sample.
[0150] Input data preprocessing submodule, used to:
[0151] Traverse each row of data of the training sample so that during the slicing process, if the current row is a blank row and the current slice data length is greater than 0, it is determined that the current slicing task is completed and then the next slicing task is performed;
[0152] If the current row is not an empty row, determine whether the total length of the current row data and the current slice data is greater than the target preset length threshold;
[0153] If it is greater than the target preset length threshold, within the target preset length threshold, select the nearest segmentation mark as the slicing point, obtain the slicing data, complete the current slicing task, and then proceed to the next slicing task;
[0154] If it is not greater than the target preset length threshold, continue to process the next row of data until the slicing point of the current slicing task is determined and the slicing data is obtained;
[0155] After the slices of the target preset length threshold are completed, a plurality of slice data corresponding to the target preset length threshold are obtained.
[0156] In a preferred example, the present application can be further configured as follows: the input data preprocessing submodule is also used to:
[0157] splicing a plurality of slice data corresponding to a target preset length threshold and a plurality of slice data corresponding to other preset length thresholds to obtain a plurality of new training samples; the other preset length thresholds are thresholds other than the target preset length threshold among the plurality of preset length thresholds;
[0158] Each new training sample is sliced according to a target preset length threshold to obtain multiple new slice data;
[0159] A plurality of slice data corresponding to the target preset length threshold and a plurality of new slice data are used as a training data set corresponding to the target preset length threshold.
[0160] In a preferred example, the present application can be further configured as follows:
[0161] The encapsulation module is used to encapsulate the model service corresponding to the initial question-answering model into an accessible interface service;
[0162] The definition module is used to define the application programming interface parameters corresponding to the interface service.
[0163] In a preferred example, the present application can be further configured as follows:
[0164] The output module is used to enable the model to provide the ability to provide questions and answers to the outside world. Specifically, it receives question and answer requests input by users; based on the question and answer requests, it uses the question and answer model to determine the answers and output the answers.
[0165] An electronic device is provided in an embodiment of the present application, such as Figure 5 As shown, Figure 5 The electronic device 300 shown includes: at least one processor 301 ( Figure 5 301 and memory 303. The processor 301 and memory 303 are connected, such as through a bus 302. Optionally, the electronic device 300 may further include a transceiver 304. It should be noted that in actual applications, the transceiver 304 is not limited to one, and the structure of the electronic device 300 does not constitute a limitation on the embodiments of the present application.
[0166] The processor 301 may be a CPU (Central Processing Unit), a general-purpose processor, a DSP (Digital Signal Processor), an ASIC (Application Specific Integrated Circuit), an FPGA (Field Programmable Gate Array) or other programmable logic devices, transistor logic devices, hardware components or any combination thereof. It may implement or execute various exemplary logic blocks, modules and circuits described in conjunction with the disclosure of this application. The processor 301 may also be a combination that implements computing functions, such as a combination of one or more microprocessors, a combination of a DSP and a microprocessor, etc.
[0167] The bus 302 may include a path to transmit information between the above components. The bus 302 may be a PCI (Peripheral Component Interconnect) bus or an EISA (Extended Industry Standard Architecture) bus. The bus 302 may be divided into an address bus, a data bus, a control bus, etc. For ease of representation, Figure 5 Only one thick line is used in the diagram, but this does not mean that there is only one bus or only one type of bus.
[0168] The memory 303 may be a ROM (Read Only Memory) or other types of static storage devices that can store static information and instructions, a RAM (Random Access Memory) or other types of dynamic storage devices that can store information and instructions, or an EEPROM (Electrically Erasable Programmable Read Only Memory), a CD-ROM (Compact Disc Read Only Memory) or other optical disk storage, optical disk storage (including compressed optical disk, laser disk, optical disk, digital versatile disk, Blu-ray disk, etc.), a magnetic disk storage medium or other magnetic storage device, or any other medium that can be used to carry or store the desired program code in the form of instructions or data structures and can be accessed by a computer, but is not limited thereto.
[0169] The memory 303 is used to store the application code for executing the solution of the present application, and the execution is controlled by the processor 301. The processor 301 is used to execute the application code stored in the memory 303 to implement the contents shown in the above method embodiment.
[0170] Figure 5 The electronic device shown is merely an example and should not bring any limitation to the functions and scope of use of the embodiments of the present application.
[0171] An embodiment of the present application provides a computer-readable storage medium, in which at least one program code is stored. When the computer-readable storage medium is run on a computer, the computer can execute the corresponding content of the aforementioned method embodiment.
[0172] An embodiment of the present application provides a computer program product, including a computer program or instructions, which implement the corresponding contents of the aforementioned method embodiment when the computer program or instructions are executed by a processor.
[0173] It should be understood that, although the steps in the flowchart of the accompanying drawings are displayed in sequence as indicated by the arrows, these steps are not necessarily executed in sequence in the order indicated by the arrows. Unless otherwise specified herein, there is no strict order restriction on the execution of these steps, and they can be executed in other orders. Moreover, at least a part of the steps in the flowchart of the accompanying drawings may include multiple sub-steps or multiple stages, and these sub-steps or stages are not necessarily executed at the same time, but can be executed at different times, and their execution order is not necessarily sequential, but can be executed in turn or alternately with other steps or at least a part of the sub-steps or stages of other steps.
[0174] The above are only some implementation methods of the present application. It should be pointed out that for ordinary technicians in this technical field, several improvements and modifications can be made without departing from the principles of the present application. These improvements and modifications should also be regarded as the scope of protection of the present application.
Claims
1. A question-answering method based on continuous pre-training of a large model, characterized in that: include: Obtaining training data sets, multiple hyperparameters, and a pre-trained large model corresponding to each of a plurality of preset length thresholds, wherein the training data set corresponding to each preset length threshold includes a plurality of training data, and the plurality of training data are obtained by slicing the training text based on the preset length threshold; For each training data set, the pre-trained large model is further trained according to multiple hyperparameters to obtain the initial question-answering models corresponding to the multiple hyperparameters. Based on multiple initial question-answering models corresponding to each of the multiple training data sets, a test set is used to perform testing to determine a question-answering model from the multiple initial question-answering models, wherein the question-answering model is used to output a reply content corresponding to the question sentence based on the question sentence.
2. The question answering method based on continuous pre-training of a large model according to claim 1, characterized in that: According to the multiple initial question-answering models corresponding to the multiple training data sets, respectively, testing is performed using a test set to determine a question-answering model from the multiple initial question-answering models, including: According to the multiple initial question-answering models corresponding to the multiple training data sets, the test set is used to test and obtain the accuracy corresponding to the multiple initial question-answering models; A question-answering model is determined from the multiple initial question-answering models according to the respective accuracies corresponding to the multiple initial question-answering models.
3. The question answering method based on continuous pre-training of a large model according to claim 1, characterized in that: It also includes the process of configuring various parameters during training, including: Use the highest level zero redundancy optimizer to optimize the third stage; Offloading optimizer state to the CPU; Locks the CPU's memory into physical memory.
4. The question answering method based on continued pre-training of a large model according to any one of claims 1 to 3, characterized in that: Obtain training data sets corresponding to multiple preset length thresholds, including: Get training samples; Slicing the training sample according to a target preset length threshold to obtain a plurality of slice data corresponding to the target preset length threshold, wherein the target preset length threshold is any threshold among the plurality of preset length thresholds; According to the plurality of slice data corresponding to the target preset length threshold, a training data set corresponding to the target preset length threshold is determined to obtain training data sets corresponding to each of the plurality of preset length thresholds.
5. The question answering method based on continuous pre-training of a large model according to claim 4, characterized in that: The training sample includes multiple lines of data, and there is a blank line between the paragraphs of the training sample. According to the target preset length threshold, the training sample is sliced to obtain a plurality of slice data corresponding to the target preset length threshold, including: Traverse each row of data of the training sample so that during the slicing process, if the current row is a blank row and the current slice data length is greater than 0, it is determined that the current slicing task is completed and then the next slicing task is performed; If the current row is not an empty row, determining whether the total length of the current row data and the current slice data is greater than the target preset length threshold; If it is greater than the target preset length threshold, within the target preset length threshold, select the nearest segmentation mark as the slicing point, obtain slicing data, complete the current slicing task, and then proceed to the next slicing task; If it is not greater than the target preset length threshold, continue to process the next row of data until the slicing point of the current slicing task is determined to obtain slicing data; After the slices of the target preset length threshold are completed, a plurality of slice data corresponding to the target preset length threshold are obtained.
6. The question answering method based on continuous pre-training of a large model according to claim 4, characterized in that: Determining a training data set corresponding to the target preset length threshold according to a plurality of slice data corresponding to the target preset length threshold includes: splicing a plurality of slice data corresponding to the target preset length threshold and a plurality of slice data corresponding to other preset length thresholds to obtain a plurality of new training samples; the other preset length thresholds are thresholds among the plurality of preset length thresholds except the target preset length threshold; Slicing each new training sample according to the target preset length threshold to obtain a plurality of new slice data; The plurality of slice data corresponding to the target preset length threshold and the plurality of new slice data are used as the training data set corresponding to the target preset length threshold.
7. The question answering method based on continuous pre-training of a large model according to claim 1, characterized in that: For each training data set, the pre-trained large model is further trained according to multiple hyperparameters to obtain the initial question-answering model corresponding to each of the multiple hyperparameters. The following steps are also included: Encapsulate the model service corresponding to the initial question-answering model into an accessible interface service; Define application programming interface parameters corresponding to the interface service.
8. A question-answering device based on continuous pre-training of a large model, characterized in that: include: An acquisition module is used to acquire training data sets corresponding to a plurality of preset length thresholds, a plurality of hyperparameters, and a pre-trained large model, wherein the training data set corresponding to each preset length threshold includes a plurality of training data, and the plurality of training data are obtained by slicing the training text based on the preset length threshold; A training module is used to continue training the pre-trained large model according to multiple hyperparameters for each training data set to obtain an initial question-answering model corresponding to each of the multiple hyperparameters; The testing module is used to perform testing using a test set based on multiple initial question-answering models corresponding to each of the multiple training data sets, so as to determine a question-answering model from the multiple initial question-answering models, wherein the question-answering model is used to output a reply content corresponding to a question sentence based on the question sentence.
9. An electronic device, characterized in that: The electronic device includes a memory and a processor, wherein a computer program is stored in the memory, and when the processor runs the computer program, the question-answering method based on continued pre-training of a large model as described in any one of claims 1 to 7 is executed.
10. A computer-readable storage medium, characterized in that: At least one program code is stored in the computer-readable storage medium, and the program code is loaded and executed by the processor to implement the question-answering method based on continued pre-training of a large model as described in any one of claims 1 to 7.