Language model acquisition method and device, computer equipment and storage medium
By obtaining similar questions and answers in the Q&A database in the target field, the language model evaluation process is optimized, and the problems of waste of resources and long cycles in the existing technology are solved, and the goal of quickly obtaining high-performance language models is achieved.
Patent Information
- Application Number
- CN202311818508.8
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2023-12-26
- Publication Date
- 2025-07-01
AI Technical Summary
The prior art requires a large amount of corpus data and long training cycles when acquiring language models in the target field, resulting in waste of resources and increased costs.
By querying the Q&A database of the target field, similar questions and similar replies with high similarity to the original question, use the target prompt words to enter the original language model, combine similar replies for model evaluation, and optimize the language model to obtain the target language model of the target field.
Without processing large amounts of training corpus data and complex model training, quickly obtain language models in the target field, save resources and improve acquisition efficiency.
Smart Images

Figure CN120234575A_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to the field of deep learning, and in particular, to a method, device, computer device, and storage medium for obtaining a language model. Background Art
[0002] A language model (especially a large language model) can be applied in multiple fields to answer prompts and implement a question-and-answer function in the corresponding field. In the prior art, usually in a target field, a language model (especially a large language model) with high reply performance in the target field is trained to achieve the purpose of obtaining a language model (especially a large language model) in the target field. However, this method of obtaining a language model in the target field not only requires a large amount of corpus data in the target field, but also requires a long training period, resulting in a large waste of material resources and human resources. Therefore, how to quickly obtain a language model with high reply performance in the target field to save human resources and material resources and shorten the model acquisition period is a technical problem that needs to be solved urgently. Summary of the Invention
[0003] Embodiments of the present invention provide a method, device, computer device, and storage medium for obtaining a language model to solve the problem of how to quickly obtain a language model with high reply performance in the target field.
[0004] A method for obtaining a language model includes:
[0005] Obtain an original question in the target field;
[0006] Query a target question-and-answer database corresponding to the target field based on the original question, and determine the top K similar questions with a high similarity to the original question. Each similar question corresponds to a similar answer, where K is a positive integer;
[0007] Based on the original question and the K similar questions, obtain a target prompt;
[0008] Input the target prompt into an original language model corresponding to the target field to obtain a target answer to the original question;
[0009] Based on the target answer and the K similar answers, obtain a model evaluation result corresponding to the original language model;
[0010] Based on the model evaluation result, process the original language model to obtain a target language model corresponding to the target field.
[0011] Preferably, the obtaining a model evaluation result corresponding to the original language model based on the target answer and the K similar answers includes:
[0012] Calculate the similarity between each of the similar responses and the target response to obtain the response similarity corresponding to each of the similar responses, and determine the model accuracy corresponding to the original language model based on the response similarities corresponding to the K similar responses;
[0013] Score the target response to determine the response score of the target response, and determine the response effect corresponding to the original language model based on the response score of the target response.
[0014] Preferably, the model evaluation result includes model accuracy and response effect;
[0015] Preferably, the step of processing the original language model based on the model evaluation result to obtain the target language model corresponding to the target domain includes:
[0016] Process the original language model based on the model accuracy and response effect corresponding to the original language model to obtain the target language model corresponding to the target domain.
[0017] Preferably, the step of processing the original language model based on the model accuracy and response effect corresponding to the original language model to obtain the target language model corresponding to the target domain includes:
[0018] If the model accuracy is greater than the preset model accuracy and the response effect is a poor effect, then fine-tune the original language model using general corpus data to determine the target language model for the target domain;
[0019] If the model accuracy is greater than the preset model accuracy and the response effect is a good effect, then determine the original language model as the target language model for the target domain;
[0020] If the model accuracy is not greater than the preset model accuracy and the response effect is a good effect, then update the target Q&A database in the target domain, and repeat the step of querying the target Q&A database corresponding to the target domain based on the original question to determine the top K similar questions with a relatively high similarity to the original question;
[0021] If the model accuracy is not greater than the preset model accuracy and the response effect is a poor effect, then replace the original language model corresponding to the target domain, and repeat the step of inputting the target prompt into the original language model corresponding to the target domain to obtain the target response corresponding to the original question.
[0022] Preferably, before obtaining the original question of the target domain, the language model acquisition method further includes:
[0023] Obtain the first Q&A database in the target domain;
[0024] Deduplicate the first Q&A database to obtain the second Q&A database;
[0025] Score and label each Q&A data in the second Q&A database to obtain the scoring and labeling result corresponding to each Q&A data;
[0026] Filter the second Q&A database according to the scoring and labeling result corresponding to each Q&A data to obtain the target Q&A database.
[0027] Preferably, before obtaining the original question in the target domain, the language model acquisition method further includes:
[0028] Obtain at least one general language model, and count the training corpus distribution corresponding to each general language model and the domain corresponding to the training corpus distribution;
[0029] Obtain the top N general language models with a relatively large training corpus distribution in the target domain; where N is a positive integer;
[0030] Perform model screening and model fine-tuning on the N general language models to obtain the original language model.
[0031] Preferably, the performing model screening and model fine-tuning on the N general language models to obtain the original language model includes:
[0032] Obtain the perplexity of each general language model for the test corpus in the target domain;
[0033] Perform instruction fine-tuning on the general language model with the lowest perplexity to obtain the original language model.
[0034] A language model acquisition device includes:
[0035] An original question acquisition module, configured to obtain the original question in the target domain;
[0036] A similar question determination module, query the target Q&A database corresponding to the target domain based on the original question, and determine the top K similar questions with a relatively high similarity to the original question, and each similar question corresponds to a similar answer, where K is a positive integer;
[0037] A target prompt word determination module, based on the original question and the K similar questions, obtain the target prompt word;
[0038] A target answer acquisition module, configured to input the target prompt word into the original language model corresponding to the target domain to obtain the target answer to the original question;
[0039] A model evaluation result acquisition module, which acquires a model evaluation result corresponding to the original language model based on the target answer and the K similar answers.
[0040] A target language model acquisition module, which processes the original language model based on the model evaluation result to acquire a target language model corresponding to the target domain.
[0041] A computer device includes a memory, a processor, and a computer program stored in the memory and executable on the processor. When the processor executes the computer program, the above language model acquisition method is implemented.
[0042] A computer-readable storage medium stores a computer program. When the computer program is executed by a processor, the above language model acquisition method is implemented.
[0043] The above language model acquisition method, device, computer device, and storage medium obtain the top K similar questions with a relatively high similarity to the original question and the corresponding similar answers for each similar question in the target question-and-answer database corresponding to the target domain, obtain a target prompt word based on the original question and the K similar questions, and obtain a target answer to the original question output by the original language model based on the target prompt word, which is convenient for subsequent evaluation of the original language model based on the similar answers and the target answer to obtain a relatively accurate model evaluation result. Using the K similar answers corresponding to the K similar questions and the target answer as evaluation labels to evaluate the answer performance of the original language model, and determining a relatively accurate model evaluation result of the original language model. Processing the original language model according to the model evaluation result, and based on the original language model, a target language model with a high answer performance in the target domain can be obtained. There is no need to process a large amount of training corpus data, nor to perform a relatively complex model training process, which can save the acquisition cost of the target language model and does not require a long training cycle, achieving the purpose of quickly obtaining the target language model in the target domain. BRIEF DESCRIPTION OF THE DRAWINGS
[0044] In order to more clearly illustrate the technical solutions of the embodiments of the present invention, the drawings required for the description of the embodiments of the present invention will be briefly introduced below. Obviously, the drawings in the following description are only some embodiments of the present invention. For those of ordinary skill in the art, other drawings can be obtained based on these drawings without creative efforts.
[0045] Figure 1 is a flowchart of a language model acquisition method in an embodiment of the present invention;
[0046] Figure 2It is another flowchart of the language model acquisition method in an embodiment of the present invention;
[0047] Figure 3 It is another flowchart of the language model acquisition method in an embodiment of the present invention;
[0048] Figure 4 It is another flowchart of the language model acquisition method in an embodiment of the present invention;
[0049] Figure 5 It is another flowchart of the language model acquisition method in an embodiment of the present invention;
[0050] Figure 6 It is another flowchart of the language model acquisition method in an embodiment of the present invention;
[0051] Figure 7 It is a schematic diagram of a language model acquisition device in an embodiment of the present invention;
[0052] Figure 8 It is a schematic diagram of a computer device in an embodiment of the present invention. Detailed implementation manners
[0053] Next, the technical solutions in the embodiments of the present invention will be clearly and completely described in conjunction with the accompanying drawings in the embodiments of the present invention. Obviously, the described embodiments are part of the embodiments of the present invention, rather than all the embodiments. All other embodiments obtained by those of ordinary skill in the art based on the embodiments of the present invention without creative efforts shall fall within the protection scope of the present invention.
[0054] The embodiments of the present invention provide a language model acquisition method, which can be applied to a computer device to achieve the purpose of quickly obtaining a language model with high response performance in a target field.
[0055] In one embodiment, as Figure 1 shown, a language model acquisition method is provided. Taking the computer device in Figure 8 as an example for description, the method includes the following steps:
[0056] S101: Obtain the original questions in the target field;
[0057] S102: Query the target Q&A database corresponding to the target field based on the original questions, and determine the top K similar questions with a high similarity to the original questions. Each similar question corresponds to a similar answer, where K is a positive integer;
[0058] S103: Obtain the target prompt words based on the original questions and the K similar questions;
[0059] S104: Input the target prompt into the original language model corresponding to the target domain to obtain the target response to the original question;
[0060] S105: Based on the target response and K similar responses, obtain the model evaluation result corresponding to the original language model;
[0061] S106: Process the original language model based on the model evaluation result to obtain the target language model corresponding to the target domain.
[0062] Among them, the target domain is the domain where it is expected to obtain the target language model. For example, the legal domain, financial domain, medical domain, etc. can all be the target domain. The original question is a question selected in the target domain. Among them, the target language model refers to a language model with high response performance in the target domain.
[0063] As an example, in step S101, the computer device obtains the original question selected from the target domain, which is convenient for subsequently obtaining the target language model of the target domain according to the original question. For example, when the computer device determines that the target domain is the legal domain, it obtains any original question selected from the legal domain. Understandably, obtaining the original question of the target domain is convenient for subsequently obtaining similar questions in the target Q&A database according to the original question, so that the original language model can be evaluated based on the similar questions and the original question, and then it is feasible to obtain the target language model of the target domain.
[0064] Among them, the target Q&A database is a database that stores the preset questions in the target domain and the preset responses corresponding to the preset questions. Similar questions refer to the preset questions with high similarity to the original question. Similar responses refer to the preset responses corresponding to the similar questions in the target Q&A database. Among them, the preset question refers to a question related to the target domain. The preset response refers to the response corresponding to the preset question.
[0065] As an example, in step S102, the computer device queries the top K preset questions with relatively high similarity to the original question in the target Q&A database corresponding to the target field, determines the top K preset questions with relatively high similarity as the similar questions corresponding to the original question, and determines the preset answers corresponding to the top K preset questions with relatively high similarity as the similar answers. In this example, the target field may be the legal field. The original question may originate from the legal field. The target Q&A database in the target field may be a target Q&A database related to legal knowledge corresponding to the legal field. K is a positive integer. For example, K is taken as 3. In this example, in the target Q&A database corresponding to the target field, the top K similar questions with relatively high similarity to the original question and the corresponding similar answers for each similar question are obtained, which is convenient for subsequent model evaluation of the original language model based on the original question, the similar questions, and the similar answers corresponding to the similar questions, and further achieves the purpose of quickly obtaining the target language model in the target field.
[0066] Among them, the target prompt is the prompt for evaluating the original language model.
[0067] As an example, in step S103, after the computer device determines the K similar questions similar to the original question, it performs sampling processing on the original question and the K similar questions for the prompt, obtains at least one prompt existing in both the original question and the K similar questions, and determines the target prompt based on the obtained at least one prompt. It can be understood that the target prompt is jointly determined based on the original question and the similar questions. In the target Q&A database in the target field, each preset answer can accurately answer the corresponding preset question. Therefore, for each similar answer corresponding to a similar question from the target Q&A database, it can be used as an evaluation label for evaluating the performance of the original language model after the target prompt is input into the original language model. In this example, based on the original question and the K similar questions, the target prompt is obtained, which is convenient for subsequent use of the similar answers corresponding to the similar questions as evaluation labels for evaluating the original language model and obtaining a relatively accurate model evaluation result of the original language model.
[0068] In this example, the computer device first performs sampling processing on the question descriptions corresponding to the original question and the K similar questions to obtain at least one identical prompt corresponding to the original question and the K similar questions; secondly, performs feature extraction on all the identical prompts, and fuses the features extracted from all the identical prompts to obtain the target prompt corresponding to the original question and the K similar questions. For example, the computer device can obtain the target prompt based on the original question determined in the legal field and the similar answers determined in the target Q&A database corresponding to the legal field, which is convenient for subsequent obtaining of the target language model in the legal field.
[0069] In this example, a target prompt is obtained based on the original question and K similar questions, which facilitates using the similar answers corresponding to the similar questions as evaluation labels for evaluating the original language model later, and determining a relatively accurate model evaluation result.
[0070] Among them, the original language model is selected from all language models in the target domain and is used to obtain the basic model of the target language model. The target answer is the answer to the original question output by the original language model.
[0071] As an example, in step S104, the computer device inputs the target prompt into the original language model and outputs the target answer to the original question. It can be understood that since the target prompt is obtained based on the original question and K similar questions, the target answer generated by the original language model based on the target prompt is the target answer corresponding to the original question. Also, since the similar answers are selected from the preset answers in the target Q&A database in the target domain, and each preset answer in this target Q&A database can answer the corresponding preset question relatively accurately. If the target answer has a high similarity to all K similar questions, it indicates that the target answer is a relatively accurate answer to the original question, that is, the original language model has a good evaluation effect in the target domain. Therefore, in this example, obtaining the target answer to the original question output by the original language model based on the target prompt facilitates evaluating the original language model later based on the similar answers and the target answer, and obtaining a relatively accurate model evaluation result. In this example, the target prompt can be the target prompt corresponding to the legal field, and the original language model can be a large language model in the legal field.
[0072] Among them, the model evaluation result refers to the evaluation result of the answer performance of the original language model in the target domain. The answer performance is used to represent the applicable ability of the model in the target domain.
[0073] As an example, in step S105, the computer device uses K similar questions and the corresponding similar answers for each similar question as evaluation labels for evaluating the original language model. Based on the K similar answers corresponding to the K similar questions and the target answer, the computer device evaluates the answer performance of the original language model and determines the model evaluation result corresponding to the original language model. In this example, the model evaluation result corresponding to the original language model can be determined according to the similarity degree between the target answer and the K similar answers. Understandably, since the target prompt is obtained based on the original question and K similar questions that are relatively similar to the original question, the degree of difference between the target answer obtained by the original language model based on the target prompt and the K similar answers can reflect the answer performance of the original language model. Therefore, the K similar answers corresponding to the K similar questions and the target answer can be used as evaluation labels to evaluate the answer performance of the original language model and determine a relatively accurate model evaluation result for the original language model. In this example, the model evaluation result can be the evaluation result of the original language model in the legal field based on the target answer and the similar answers in the legal field.
[0074] As an example, in step S106, the computer device processes the original language model according to the obtained model evaluation result to obtain a target language model for the target field. In this example, when the computer device determines that the model evaluation result is good, it determines the original language model as the target language model for the target field; when it determines that the model evaluation result is poor, it further processes the original language model to obtain a target language model with higher answer performance. Understandably, for the original language model in the target field, if the model evaluation result is good, it indicates that the original language model has a good answer effect on the original questions in the target field, and the original language model is determined as the target language model for the target field so that the target language model has a good answer effect in the target field; if the model evaluation result is poor, the original language model needs to be further processed to obtain a target language model with higher answer performance. For example, the obtained target language model can be the target language model corresponding to the legal field so that the target language model has a good answer effect and higher model accuracy in the legal field.
[0075] In this example, according to the model evaluation result, the original language model is processed, and based on the original language model, a target language model with high answer performance in the target field can be obtained without processing a large amount of training corpus data or performing a relatively complex model training process. This method can not only save the acquisition cost of the target language model, does not require a long training cycle, but also can speed up the speed of obtaining the target language model for the target field.
[0076] In this embodiment, in the target Q&A database corresponding to the target domain, the top K similar questions with a high similarity to the original question and the corresponding similar answers for each similar question are obtained. A target prompt is generated based on the original question and the K similar questions, and the target answer of the original question output by the original language model based on the target prompt is obtained, which facilitates subsequent evaluation of the original language model based on the similar answers and the target answer to obtain a relatively accurate model evaluation result. The K similar answers corresponding to the K similar questions and the target answer are used as evaluation labels to evaluate the answer performance of the original language model, and a relatively accurate model evaluation result of the original language model is determined. The original language model is processed according to the model evaluation result, and based on the original language model, a target language model with good answer performance in the target domain can be obtained. There is no need to process a large amount of training corpus data, nor is it necessary to perform a relatively complex model training process, which can save the acquisition cost of the target language model and does not require a long training cycle, achieving the purpose of quickly obtaining the target language model in the target domain.
[0077] In one embodiment, as Figure 2 shown, step S105, that is, obtaining the model evaluation result corresponding to the original language model based on the target answer and the K similar answers, includes:
[0078] S201: Calculate the similarity between each similar answer and the target answer to obtain the answer similarity corresponding to each similar answer, and determine the model accuracy corresponding to the original language model based on the answer similarities corresponding to the K similar answers;
[0079] S202: Score the target answer to determine the answer score of the target answer, and determine the answer effect corresponding to the original language model based on the answer score of the target answer.
[0080] Among them, the model evaluation result includes the model accuracy corresponding to the original language model and the answer effect corresponding to the original language model.
[0081] Among them, the answer similarity refers to the similarity between each similar answer and the target answer. The model accuracy, as an answer performance evaluation index for evaluating the original language model, is used to reflect the answer performance of the original language model.
[0082] As an example, in step S201, after the computer device inputs the prompt into the original language model and obtains the target response, it calculates the similarity between the target response and K similar responses respectively, obtains the response similarity between each similar response and the target response, and performs statistical processing on each response similarity to obtain the model accuracy corresponding to the original language model. Understandably, since the target response is obtained by the original language model processing the target prompt, and the target prompt is based on the original question and K similar questions, therefore, the model accuracy of the original language model in the target domain can be determined according to the response similarity between the target response and each similar response. If the response similarity is high, it indicates that the model accuracy of the original language model in the target domain is high. If the response similarity is low, it indicates that the model accuracy of the original language model in the target domain is low. For example, the n-grams algorithm is used to calculate the similarity between the target response and K similar responses, obtain the response similarity between each similar response and the target response, perform weighted averaging on all response similarities, obtain the weighted average value corresponding to the response similarity, and determine the weighted average value as the model accuracy corresponding to the original language model. Among them, the n-grams algorithm is used to evaluate the similarity between the target response and K similar responses. In this example, by obtaining the response similarity corresponding to each similar response and based on the response similarities corresponding to K similar responses, the model accuracy of the original language model when applied to the target domain can be determined more accurately.
[0083] Among them, the response score refers to the score corresponding to the target response. The response effect is a response performance evaluation index for evaluating the original language model and is used to reflect the response performance of the original language model.
[0084] As an example, in step S202, the computer device obtains the response score after scoring the target response, and determines the response effect of the original language model in the target domain according to the response score. In this example, the target response can be scored by manual annotation to obtain the response score corresponding to the target response; or the target response can be scored by the reward model in the target domain to obtain the response score corresponding to the target response. The computer device determines whether the response score is greater than the preset score. If the response score is greater than the preset score, it is determined that the response effect of the original language model in the target domain is good. If the response score is not greater than the preset score, it is determined that the response effect of the original language model in the target domain is poor. Among them, the reward model is used to score and annotate each question and the corresponding response, which can save human resources and is more convenient. The preset score is a threshold preset for evaluating the quality of the response effect, and is specifically used to compare with the response score to determine the response effect of the original language model. In this example, based on the response score of the target response, the response effect corresponding to the original language model can be evaluated more accurately.
[0085] In this embodiment, based on the reply similarities corresponding to K similar replies, the model accuracy of the original language model when applied to the target domain is determined more precisely. Based on the reply scores of the target replies, the reply effect corresponding to the original language model is evaluated more accurately, and the reply performance of the original language model in the target domain can be determined more precisely, obtaining an accurate model evaluation result.
[0086] In one embodiment, step S106, that is, based on the model evaluation result, the original language model is processed to obtain a target language model corresponding to the target domain, including:
[0087] S1061: Based on the model accuracy and reply effect corresponding to the original language model, the original language model is processed to obtain a target language model corresponding to the target domain.
[0088] As an example, in step S1061, when the computer device determines the model accuracy and reply effect corresponding to the original language model, according to the model accuracy and reply effect corresponding to the original language model, the original language model is processed to obtain a target language model with better model accuracy and reply effect in the target domain. For example, for the original language model in the legal domain, when the computer device determines that the model accuracy and reply effect of the original language model are good, the original language model is determined as the target language model in the legal domain, so that the target language model has better model accuracy and reply effect in the legal domain; when the computer device determines that at least one of the model accuracy and reply effect of the original language model is poor, the original language model is further processed to obtain a target language model with better model accuracy and reply effect in the legal domain. Among them, when the target domain is the legal domain, the original language model can be the original large language model in the legal domain, and the target language model obtained after processing the original language model can be the target large language model obtained after processing the original large language model in the legal domain.
[0089] In this embodiment, according to the model accuracy and reply effect corresponding to the original language model, the original language model is processed, and a target language model with better model accuracy and reply effect in the target domain can be obtained. This method does not need to obtain a large amount of training corpus data in the target domain, nor does it need to perform a long-term training in the target domain, saving human and material resources and training costs, and can quickly obtain a target language model with better model accuracy and reply effect in the target domain.
[0090] In one embodiment, as Figure 3 shown, step S1061, that is, based on the model accuracy and reply effect corresponding to the original language model, the original language model is processed to obtain a target language model corresponding to the target domain, including:
[0091] S301: If the model accuracy is greater than the preset model accuracy and the response effect is poor, then use the general corpus data to fine-tune the original language model to determine the target language model for the target domain;
[0092] S302: If the model accuracy is greater than the preset model accuracy and the response effect is good, then determine the original language model as the target language model for the target domain;
[0093] S303: If the model accuracy is not greater than the preset model accuracy and the response effect is good, then update the target Q&A database in the target domain, and repeatedly execute querying the target Q&A database corresponding to the target domain based on the original question to determine the top K similar questions with a relatively high similarity to the original question;
[0094] S304: If the model accuracy is not greater than the preset model accuracy and the response effect is poor, then replace the original language model corresponding to the target domain, and repeatedly execute inputting the target prompt words into the original language model corresponding to the target domain to obtain the target response corresponding to the original question.
[0095] Among them, the preset model accuracy is used to evaluate the model accuracy. The general corpus data refers to the general questions in the target domain and the corresponding responses to each question. Understandably, the general corpus data is usually the relatively common questions and the corresponding responses in the target domain, with high Q&A quality, which is convenient for fine-tuning the model.
[0096] As an example, in step S301, when the computer device determines that the model accuracy is greater than the preset model accuracy and the response effect is poor, it uses the general corpus data to fine-tune the original language model, and determines the fine-tuned original language model as the target language model for the target domain. Understandably, since the model accuracy of the original language model is high, it indicates that the target response output by the original language model is a relatively accurate response to the original question, and this original language model can be applied in the target domain, but the response effect is poor, which may be due to the unsmooth word order and / or unclear logic of the target response output by the original language model. Therefore, in this example, the computer device uses the general corpus data of the target domain to fine-tune the original language model so that the target response output by the original language model has a better response effect, for example, a smoother word order and clearer logic, and determines the fine-tuned original language model as the target language model corresponding to the target domain. In this example, when the model accuracy is greater than the preset model accuracy and the response effect is poor, fine-tuning the original language model can improve the response effect of the original language model, so that the target language model obtained according to the fine-tuned original language model has a high response performance in the target domain.
[0097] As an example, in step S302, when the computer device determines that the model accuracy is greater than the preset model accuracy and the reply effect is a good effect, it directly determines the original language model as the target language model for the target field. Understandably, since the original language model has good model accuracy and a good reply effect, it indicates that the original language model can be directly used in the target field. Therefore, the original language model can be directly determined as the target language model. In this example, when the model accuracy is greater than the preset model accuracy and the reply effect is a good effect, the original language model is directly determined as the target language model for the target field, and the target language model corresponding to the target field can be obtained without complex training, which is relatively convenient and fast.
[0098] As an example, in step S303, when the computer device determines that the model accuracy is not greater than the preset model accuracy and the reply effect is a good effect, it further updates the target Q&A database in the target field and repeats the process of querying the target Q&A database corresponding to the target field based on the original question to determine the top K similar questions with a high similarity to the original question, in order to obtain a target language model with high model accuracy and good reply effect. In this example, when it is determined that the model accuracy is not greater than the preset model accuracy and the reply effect is a good effect, the target Q&A database in the target field is further updated, and then steps S102 to S106 are repeatedly executed until the model accuracy of the original language model is greater than the preset model accuracy and the reply effect is a good effect, and the original language model is directly determined as the target language model.
[0099] Understandably, if the model accuracy of the original language model is not greater than the preset model accuracy, but the reply effect is a good effect, it indicates that the preset questions and preset replies in the obtained target Q&A database in the target field cannot meet the current evaluation of the original language model. It may be that the scope of the target Q&A database is small, or the Q&A effect between the preset questions and preset replies in the target Q&A database is poor. It is necessary to further update and expand the target Q&A database so that the target Q&A database has relatively rich preset questions and preset replies in the target field and improves the Q&A effect between the preset questions and preset replies in the target Q&A database, enabling the target Q&A database to accurately evaluate the model accuracy of the original language model, and finally obtaining a target language model with high model accuracy and good reply effect.
[0100] As an example, in step S304, when the computer device determines that the model accuracy is not greater than the preset model accuracy and the reply effect is poor, it replaces the original language model corresponding to the target field, and repeats the steps of inputting the target prompt word into the original language model corresponding to the target field to obtain the target reply corresponding to the original question, that is, repeats steps S104 to S106 until a target language model with high model accuracy and good reply effect is obtained. Understandably, if the model accuracy is not greater than the preset model accuracy and the reply effect is poor, it indicates that the original language model selected for evaluation in the target field is not suitable for the Q&A function in the target field, and the original language model should be replaced to obtain an original language model that is more suitable for the Q&A function in the target field, and further evaluate the replaced original language model until a target language model with high model accuracy and good reply effect is obtained.
[0101] In this embodiment, according to the size relationship between the model accuracy of the original language model and the preset model accuracy, and the reply effect of the original language model, different steps are executed to determine the target language model suitable for the target field. This method can achieve the purpose of quickly obtaining a target language model with high model accuracy and good reply effect without complex and time-consuming model training, saving manpower and material costs, and being convenient and fast.
[0102] In another embodiment, as Figure 4 shown, before step S101, that is, before obtaining the original question in the target field, the language model acquisition method further includes:
[0103] S401: Obtain the first Q&A database in the target field;
[0104] S402: Perform deduplication processing on the first Q&A database to obtain the second Q&A database;
[0105] S403: Score and label each Q&A data in the second Q&A database to obtain the score and label result corresponding to each Q&A data;
[0106] S404: Screen the second Q&A database according to the score and label result corresponding to each Q&A data to obtain the target Q&A database.
[0107] Among them, the first Q&A database is a database that stores the questions in the target field and the replies corresponding to each question.
[0108] As an example, in step S401, the computer device collects multiple questions in the target domain and the corresponding answers to each question, and obtains the first Q&A database in the target domain. For example, in the legal domain, the computer device collects judgment documents, laws and regulations, legal examination questions, and common legal Q&A through legal websites to obtain the first Q&A database. Specifically, the computer device uses a question generation model to generate questions from judgment documents, laws and regulations, and legal examination questions, performs duplicate removal processing on the generated questions, and uses a general language model in the legal domain to process the questions after duplicate removal to obtain the corresponding answers to each question, stores the questions and answers correspondingly in the first Q&A database, and also stores the common legal Q&A in the first Q&A database to obtain the first Q&A database with relatively rich Q&A. In this example, obtaining the first Q&A database in the target domain facilitates obtaining the target Q&A database according to the first Q&A database storing rich Q&A data later.
[0109] Among them, the second Q&A database refers to the Q&A database obtained by performing duplicate removal processing on the first Q&A database.
[0110] As an example, in step S402, the computer device further performs duplicate removal processing on the questions and the corresponding answers in the first Q&A database to obtain the second Q&A database after duplicate removal processing. In this example, performing duplicate removal processing on the first Q&A database reduces redundant data, improves data processing efficiency, and facilitates quickly obtaining the target language model in the target domain later.
[0111] Among them, the Q&A data consists of at least one question in the target domain and the corresponding answer to each question. The scoring and annotation result refers to the score corresponding to each Q&A data in the second Q&A database.
[0112] As an example, in step S403, the computer device further scores and annotates each Q&A data in the second Q&A database to obtain the scoring and annotation result corresponding to each Q&A data in the second Q&A database. In this example, the computer device can obtain the scoring and annotation result corresponding to each Q&A data in the second Q&A database through manual scoring and annotation, or can score and annotate each Q&A data through a reward model to obtain the scoring and annotation result corresponding to each Q&A data in the second Q&A database. In this example, obtaining the scoring and annotation result corresponding to each Q&A data in the second Q&A database facilitates screening the Q&A data in the second Q&A database according to the scoring and annotation result corresponding to each Q&A data later to obtain the target Q&A database.
[0113] As an example, in step S404, the computer device filters out the Q&A data with a score greater than the preset score standard from the score annotation results corresponding to each Q&A data in the second Q&A database to form a target Q&A database. The preset score standard is used to filter the Q&A data in the second Q&A database to obtain a target Q&A database with higher scores. In this example, by scoring and annotating the Q&A data in the second Q&A database and filtering the second Q&A database, a target Q&A database with higher quality can be obtained, which is convenient for subsequent processing of the questions and the corresponding answers in the target Q&A database, obtaining similar questions similar to the original question, reducing the data processing difficulty, and accelerating the data processing efficiency.
[0114] In this embodiment, a first Q&A database is obtained in the target domain, the first Q&A database is de-duplicated to obtain a second Q&A database, the second Q&A database is scored and annotated, and a target Q&A database with higher quality is filtered out, which is convenient for subsequent data processing of the questions and the corresponding answers in the target Q&A database, reducing the data processing difficulty and accelerating the data processing efficiency.
[0115] In another embodiment, as Figure 5 shown, before step S101, that is, before obtaining the original questions in the target domain, the language model acquisition method further includes:
[0116] S501: Obtain at least one general language model, and count the training corpus distribution corresponding to each general language model and the domain corresponding to the training corpus distribution;
[0117] S502: Obtain the top N general language models with a larger training corpus distribution in the target domain; where N is a positive integer;
[0118] S503: Perform model screening and model fine-tuning on the N general language models to obtain an original language model.
[0119] Among them, the general language model is a language model that can process questions in various domains. In this embodiment, the general language model can select a general large language model so that the subsequent obtained original language model is a large language model and can process a large number of questions. The training corpus distribution is the distribution of the domains to which the training corpus used in the process of training the general language model belongs. For example, for a general language model, the distribution of the domains to which the training corpus used in the process of training the general language model belongs is counted. If the distribution of the training corpus in the legal domain is 0.7, the distribution in the financial domain is 0.2, and the distribution in the medical domain is 0.1, then the training corpus distribution in the legal domain is 0.7, the training corpus distribution in the financial domain is 0.2, and the training corpus distribution in the medical domain is 0.1.
[0120] As an example, in step S501, the computer device obtains at least one general language model, and counts the training corpus distribution corresponding to each general language model, as well as the field to which the training corpus distribution belongs. For example, for a general language model, the counted training corpus distribution corresponding to the training corpus and the field to which the training corpus distribution belongs are: the training corpus distribution in the legal field is 0.7, the training corpus distribution in the financial field is 0.2, and the training corpus distribution in the medical field is 0.1. In this example, determining the training corpus distribution corresponding to each general language model and the field corresponding to the training corpus distribution facilitates subsequent screening of the original language model corresponding to the target field according to the training corpus distribution and the field corresponding to the training corpus distribution.
[0121] As an example, in step S502, the computer device obtains the top N general language models with a relatively large training corpus distribution in the target field among the general language models. Where N is a positive integer. For example, if the target field is the legal field, the computer device screens the top 3 (N is taken as 3) general language models with a relatively large training corpus distribution in the legal field among all general language models. It can be understood that if the training corpus distribution of a general language model in the target field is relatively large, it indicates that the general language model has a higher response performance in the target field compared to the general language model with a relatively small training corpus distribution in the target field. Therefore, it is necessary to screen the general language models according to the size of the training corpus distribution in the target field, which facilitates subsequent obtaining of the original language model with a higher response performance in the target field, thereby accelerating the speed of obtaining the target language model.
[0122] As an example, in step S503, the computer device further screens the initially screened N general language models according to the response performance in the target field from high to low, obtains a general language model with a higher response performance in the target field, and fine-tunes the general language model, and determines the fine-tuned general language model as the original language model. In this example, model screening and model fine-tuning among the N general language models can obtain an original language model that is more suitable for the target field.
[0123] In this embodiment, screening the general language models according to the size of the training corpus distribution in the target field facilitates subsequent obtaining of the original language model with a higher response performance in the target field, thereby accelerating the speed of obtaining the target language model. Model screening and model fine-tuning among the N general language models facilitate obtaining an original language model with a higher response performance in the target field, so that the original language model is more suitable for the target field.
[0124] In one embodiment, as Figure 6As shown in the figure, step S503, that is, model screening and model fine-tuning are performed on N general language models to obtain the original language model, including:
[0125] S601: Obtain the perplexity of each general language model for the test corpus in the target domain;
[0126] S602: Perform instruction fine-tuning on the general language model with the lowest perplexity to obtain the original language model.
[0127] Among them, the perplexity is used as an indicator for screening general models, representing the response performance of the general language model in the target domain, and is used to screen the general language model in the target domain. The test corpus is a corpus composed of multiple questions in the target domain and the corresponding answers to each question. For example, if the target domain is the legal field, the test corpus is the legal-related corpus obtained in the legal field.
[0128] As an example, in step S601, the computer device obtains the test corpus in the target domain, uses each general language model to process the questions in the test corpus to obtain the corresponding answers to each question, and calculates the perplexity based on the answers corresponding to each question output by the general language model and the answers corresponding to each question in the test corpus, to obtain the perplexity corresponding to the general language model. Among the N general language models, the above calculation process is repeated for each general language model to obtain the perplexity corresponding to each general language model. In this example, obtaining the perplexity of each general language model in the N general language models for the test corpus in the target domain facilitates subsequent screening of the original language model according to the perplexity.
[0129] Among them, instruction fine-tuning is used to obtain the original language model with high response performance in the target domain.
[0130] As an example, in step S602, the computer device screens out the general language model with the lowest perplexity among the N general language models, and performs instruction fine-tuning on the screened general language model with the lowest perplexity to obtain the original language model. It can be understood that the lower the perplexity of the general language model for the test corpus in the target domain, the better the response performance of the general language model in the target domain. Therefore, selecting the general language model with the lowest perplexity facilitates obtaining the original language model with better response performance in the target domain. In this example, after the computer device obtains the general language model with the lowest perplexity, it obtains multiple new questions and the corresponding answers to each question in the target domain, and fine-tunes the original language model through the multiple new questions and the corresponding answers to each question to obtain the original language model that can better adapt to the target domain. In this example, screening the general language model with the lowest perplexity and performing instruction fine-tuning on the general language model with the lowest perplexity facilitates obtaining the original language model with high response performance in the target domain.
[0131] In this embodiment, the perplexity of each general language model in N general language models for the test corpus in the target domain is obtained, the language model with the lowest perplexity is selected, and the general language model with the lowest perplexity is fine-tuned with instructions, so as to obtain the original language model with high reply performance in the target domain, and the speed of obtaining the target language model with high reply performance in the target domain according to the original language model subsequently is accelerated.
[0132] It should be understood that the magnitudes of the sequence numbers of the steps in the above embodiments do not mean the order of execution, and the order of execution of each process should be determined according to its function and internal logic, and should not constitute any limitation to the implementation process of the embodiments of the present invention.
[0133] In one embodiment, a language model acquisition device is provided, and the language model acquisition device corresponds one-to-one with the language model acquisition method in the above embodiment. As Figure 7 shown, the language model acquisition device includes an original question acquisition module 701, a similar question determination module 702, a target prompt word determination module 703, a target reply acquisition module 704, a model evaluation result acquisition module 705, and a target language model acquisition module 706. The detailed descriptions of each functional module are as follows:
[0134] The original question acquisition module 701 is used to acquire the original question in the target domain;
[0135] The similar question determination module 702 queries the target Q&A database corresponding to the target domain based on the original question, and determines the top K similar questions with a high similarity to the original question, and each similar question corresponds to a similar reply, where K is a positive integer;
[0136] The target prompt word determination module 703 obtains the target prompt word based on the original question and the K similar questions;
[0137] The target reply acquisition module 704 is used to input the target prompt word into the original language model corresponding to the target domain to obtain the target reply corresponding to the original question;
[0138] The model evaluation result acquisition module 705 obtains the model evaluation result corresponding to the original language model based on the target reply and the K similar replies;
[0139] The target language model acquisition module 706 processes the original language model based on the model evaluation result to obtain the target language model corresponding to the target domain.
[0140] In one embodiment, the model evaluation result acquisition module 705 includes:
[0141] The model accuracy determination sub-module is used to calculate the similarity between each similar response and the target response to obtain the response similarity corresponding to each similar response, and determine the model accuracy corresponding to the original language model based on the response similarities corresponding to the K similar responses;
[0142] The response effect determination sub-module is used to score the target response to determine the response score of the target response, and determine the response effect corresponding to the original language model based on the response score of the target response.
[0143] In one embodiment, the target language model acquisition module 706 includes:
[0144] The target language model acquisition sub-module processes the original language model based on the model accuracy and response effect corresponding to the original language model to obtain the target language model corresponding to the target domain.
[0145] In one embodiment, the target language model acquisition sub-module includes:
[0146] The first target language model acquisition unit is used to fine-tune the original language model with general corpus data to determine the target language model of the target domain if the model accuracy is greater than the preset model accuracy and the response effect is a poor effect;
[0147] The second target language model acquisition unit is used to determine the original language model as the target language model of the target domain if the model accuracy is greater than the preset model accuracy and the response effect is a good effect;
[0148] The third target language model acquisition unit is used to update the target Q&A database in the target domain and repeatedly execute querying the target Q&A database corresponding to the target domain based on the original question to determine the top K similar questions with higher similarity to the original question if the model accuracy is not greater than the preset model accuracy and the response effect is a good effect;
[0149] The fourth target language model acquisition unit is used to replace the original language model corresponding to the target domain and repeatedly execute inputting the target prompt word into the original language model corresponding to the target domain to obtain the target response corresponding to the original question if the model accuracy is not greater than the preset model accuracy and the response effect is a poor effect.
[0150] In another embodiment, the language model acquisition device further includes:
[0151] The first Q&A database acquisition module is used to acquire the first Q&A database of the target domain;
[0152] The second Q&A database acquisition module is used to perform deduplication processing on the first Q&A database to obtain the second Q&A database;
[0153] The scoring and annotation result acquisition module is used to score and annotate each Q&A data in the second Q&A database, and obtain the scoring and annotation result corresponding to each Q&A data;
[0154] The target Q&A database determination module is used to screen the second Q&A database according to the scoring and annotation result corresponding to each Q&A data, and obtain the target Q&A database.
[0155] In another embodiment, the language model acquisition device further includes:
[0156] The statistics module is used to obtain at least one general language model, and statistically analyze the training corpus distribution corresponding to each general language model and the field corresponding to the training corpus distribution;
[0157] The screening module is used to obtain the top N general language models with a relatively large training corpus distribution in the target field; where N is a positive integer;
[0158] The original language model determination module is used to screen and fine-tune the N general language models to obtain the original language model.
[0159] In one embodiment, the original language model determination module includes:
[0160] The perplexity acquisition sub-module is used to obtain the perplexity of each general language model for the test corpus in the target field;
[0161] The original language model determination sub-module is used to perform instruction fine-tuning on the general language model with the lowest perplexity to obtain the original language model.
[0162] For the specific limitations of the language model acquisition device, reference can be made to the limitations on the language model acquisition method in the above text, which will not be elaborated here. Each module in the above language model acquisition device can be implemented in whole or in part through software, hardware, and their combination. The above modules can be embedded in the processor of the computer device in hardware form or be independent of it, or can be stored in the memory of the computer device in software form, so that the processor can call and execute the operations corresponding to the above modules.
[0163] In one embodiment, a computer device is provided. The computer device can be a server, and its internal structure diagram can be as Figure 8As shown in the figure. The computer device includes a processor, a memory, a network interface, and a database connected by a system bus. Among them, the processor of the computer device is used to provide computing and control capabilities. The memory of the computer device includes a non-volatile storage medium and an internal memory. The non-volatile storage medium stores an operating system, a computer program, and a database. The internal memory provides an environment for the operation of the operating system and the computer program in the non-volatile storage medium. The database of the computer device is used to store the data used or generated during the execution of the language model acquisition method. The network interface of the computer device is used to communicate with an external terminal through a network connection. When the computer program is executed by the processor, it implements a language model acquisition method.
[0164] In one embodiment, a computer device is provided, including a memory, a processor, and a computer program stored on the memory and executable on the processor. When the processor executes the computer program, it implements the language model acquisition method in the above embodiment, for example Figure 1 S101-S106 shown in the figure, or Figures 2 to 6 As shown in the figure, to avoid repetition, it will not be elaborated here. Or, when the processor executes the computer program, it implements the functions of each module / unit in this embodiment of the language model acquisition device, for example Figure 7 The functions of the original problem acquisition module 701, the similar problem determination module 702, the target prompt word determination module 703, the target answer acquisition module 704, the model evaluation result acquisition module 705, and the target language model acquisition module 706 shown in the figure. To avoid repetition, it will not be elaborated here.
[0165] In one embodiment, a computer-readable storage medium is provided. A computer program is stored on the computer-readable storage medium. When the computer program is executed by the processor, it implements the language model acquisition method in the above embodiment, for example Figure 1 S101-S106 shown in the figure, or Figures 2 to 6 As shown in the figure, to avoid repetition, it will not be elaborated here. Or, when the processor executes the computer program, it implements the functions of each module / unit in this embodiment of the language model acquisition device, for example Figure 7 The functions of the original problem acquisition module 701, the similar problem determination module 702, the target prompt word determination module 703, the target answer acquisition module 704, the model evaluation result acquisition module 705, and the target language model acquisition module 706 shown in the figure. To avoid repetition, it will not be elaborated here. The computer-readable storage medium can be non-volatile or volatile.
[0166] Those of ordinary skill in the art can understand that all or part of the processes in the methods of the above embodiments can be completed by instructing relevant hardware through a computer program. This computer program can be stored in a non-volatile computer-readable storage medium. When the computer program is executed, it can include the processes of the embodiments of the above methods. Among them, any reference to a memory, storage, database, or other medium used in the embodiments provided in the present application can include non-volatile and / or volatile memories. Non-volatile memory can include read-only memory (ROM), programmable ROM (PROM), electrically programmable ROM (EPROM), electrically erasable programmable ROM (EEPROM), or flash memory. Volatile memory can include random access memory (RAM) or external cache memory. By way of illustration and not limitation, RAM is available in many forms, such as static RAM (SRAM), dynamic RAM (DRAM), synchronous DRAM (SDRAM), double data rate SDRAM (DDR SDRAM), enhanced SDRAM (ESDRAM), synchronous link DRAM (SLDRAM), Rambus direct RAM (RDRAM), direct memory bus dynamic RAM (DRDRAM), and Rambus dynamic RAM (RDRAM), etc.
[0167] Those skilled in the art can clearly understand that, for the convenience and simplicity of description, only the above-mentioned division of each functional unit and module is used as an example. In actual applications, the above functions can be allocated to different functional units and modules according to needs, that is, the internal structure of the device can be divided into different functional units or modules to complete all or part of the functions described above.
[0168] The above embodiments are only used to illustrate the technical solutions of the present invention and are not intended to limit them. Although the present invention has been described in detail with reference to the foregoing embodiments, those of ordinary skill in the art should understand that they can still modify the technical solutions described in the foregoing embodiments or perform equivalent replacements for some of the technical features. These modifications or replacements do not cause the essence of the corresponding technical solutions to deviate from the spirit and scope of the technical solutions of the embodiments of the present invention and should all be included in the protection scope of the present invention.
Claims
1. A method for obtaining a language model, characterized in that, Including: Obtain the original question in the target domain; Query the target Q&A database corresponding to the target domain based on the original question, and determine the top K similar questions with a relatively high similarity to the original question. Each of the similar questions corresponds to a similar answer, where K is a positive integer; Based on the original question and the K similar questions, obtain the target prompt; Input the target prompt into the original language model corresponding to the target domain to obtain the target answer to the original question; Based on the target answer and the K similar answers, obtain the model evaluation result corresponding to the original language model; Based on the model evaluation result, process the original language model to obtain the target language model corresponding to the target domain.
2. The language model acquisition method according to claim 1, characterized in that The model evaluation result includes model accuracy and answer effect. The obtaining of the model evaluation result corresponding to the original language model based on the target answer and the K similar answers includes: Calculate the similarity between each similar answer and the target answer to obtain the answer similarity corresponding to each similar answer. Based on the answer similarities corresponding to the K similar answers, determine the model accuracy corresponding to the original language model; Score the target answer to determine the answer score of the target answer. Based on the answer score of the target answer, determine the answer effect corresponding to the original language model.
3. The language model acquisition method according to claim 1, wherein The model evaluation result includes model accuracy and answer effect; The processing of the original language model based on the model evaluation result to obtain the target language model corresponding to the target domain includes: Process the original language model based on the model accuracy and answer effect corresponding to the original language model to obtain the target language model corresponding to the target domain.
4. The language model acquisition method according to claim 3, wherein The processing of the original language model based on the model accuracy and answer effect corresponding to the original language model to obtain the target language model corresponding to the target domain includes: If the model accuracy is greater than the preset model accuracy and the answer effect is a poor effect, then fine-tune the original language model using general corpus data to determine the target language model for the target domain; If the model accuracy is greater than the preset model accuracy and the answer effect is a good effect, then determine the original language model as the target language model for the target domain; If the model accuracy is not greater than the preset model accuracy and the answer effect is a good effect, then update the target Q&A database in the target domain, and repeat the step of querying the target Q&A database corresponding to the target domain based on the original question to determine the top K similar questions with a relatively high similarity to the original question; If the model accuracy is not greater than the preset model accuracy and the answer effect is a poor effect, then replace the original language model corresponding to the target domain, and repeat the step of inputting the target prompt into the original language model corresponding to the target domain to obtain the target answer corresponding to the original question.
5. The method for obtaining a language model according to claim 1, characterized in that, Before obtaining the original question in the target domain, the language model acquisition method further includes: Obtain the first Q&A database of the target domain; Deduplicate the first Q&A database to obtain a second Q&A database; Score and annotate each Q&A data in the second Q&A database to obtain the score annotation result corresponding to each Q&A data; Filter the second Q&A database according to the score annotation result corresponding to each Q&A data to obtain a target Q&A database.
6. The language model acquisition method according to claim 1, characterized in that Before obtaining the original questions in the target field, the language model acquisition method further includes: Obtain at least one general language model, and count the training corpus distribution corresponding to each general language model and the field corresponding to the training corpus distribution; Obtain the top N general language models with a relatively large training corpus distribution in the target field; where N is a positive integer; Perform model screening and model fine-tuning on the N general language models to obtain the original language model.
7. The method for obtaining a language model according to claim 6, wherein, The performing model screening and model fine-tuning on the N general language models to obtain the original language model includes: Obtain the perplexity of each general language model for the test corpus in the target field; Perform instruction fine-tuning on the general language model with the lowest perplexity to obtain the original language model.
8. A language model acquisition device, characterized in that, Includes: An original question acquisition module, configured to acquire original questions in the target field; A similar question determination module, based on the original questions, query the target Q&A database corresponding to the target field, and determine the top K similar questions with a relatively high similarity to the original questions, each similar question corresponding to a similar answer, where K is a positive integer; A target prompt word determination module, based on the original questions and the K similar questions, obtain target prompt words; A target answer acquisition module, configured to input the target prompt words into the original language model corresponding to the target field to obtain the target answer to the original questions; A model evaluation result acquisition module, based on the target answer and the K similar answers, obtain the model evaluation result corresponding to the original language model; A target language model acquisition module, based on the model evaluation result, process the original language model to obtain the target language model corresponding to the target field.
9. A computer device, comprising a memory, a processor, and a computer program stored in the memory and executable on the processor, characterized in that, When the processor executes the computer program, it implements the language model acquisition method according to any one of claims 1 to 7.
10. A computer-readable storage medium storing a computer program, characterized in that, When the computer program is executed by the processor, it implements the language model acquisition method according to any one of claims 1 to 7.
Citation Information
Cited By
Data processing method and device applied to model training, equipment and medium
CN120950980A