Instruction data generation method and device, computer equipment and storage medium

By obtaining initial samples from the question and answer data set, adjusting the format and determining the prompt template, the instruction data suitable for the artificial intelligence model is generated, which solves the problems of high data generation cost and narrow scope of application in the field of professional knowledge, and achieves low-cost, wide-ranging Applicable command data generation.

CN118798216APending Publication Date: 2024-10-18INSPUR SUZHOU INTELLIGENT TECH CO LTD
View PDF 0 Cites 4 Cited by

Patent Information

Application Number
CN202410787327.1
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2024-06-18
Publication Date
2024-10-18

AI Technical Summary

Technical Problem

Existing instruction data generation technology has the problems of high data generation cost and narrow scope of application in the field of professional knowledge. Especially when large language models lack sufficient prior knowledge and data, it is difficult to meet the needs of learning and training. The existing technology is only suitable for For closed question and answer types and text classification types, it cannot be applied to open question and answer type generation tasks.

Method used

By obtaining initial data samples from the preset question and answer data set, adjust the format and determine the prompt template, generate data to generate prompts, input the preset model to generate target instruction data, support open question and answer and closed question and answer formats, and use multiple prompt templates Cover different format types and meet the data generation conditions of constraint prompts.

Benefits of technology

It achieves low-cost and wide-range instruction data generation, can generate target instruction data consistent with the initial data sample format type, meets the data generation needs in professional knowledge fields, and reduces the cost of manual labeling and data preparation.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN118798216A_ABST
    Figure CN118798216A_ABST
Patent Text Reader

Abstract

The embodiment of the invention relates to the technical field of artificial intelligence, in particular to an instruction data generation method and device, computer equipment and a storage medium. The method mainly comprises the steps of obtaining an initial data sample from a preset question and answer data set for format adjustment, generating a format sample, determining a target prompt template from a plurality of preset prompt templates according to the format type of the initial data sample, editing an example data prompt of the target prompt template according to the format sample, and displaying the example data prompt. And generating a data generation prompt, inputting the data generation prompt into a preset model, and generating target instruction data for the artificial intelligence model to perform training learning. According to the method, the initial sample data in the open question and answer format and the closed question and answer format can be covered through the multiple preset prompt templates, the application range is wide, and the target instruction data which is consistent with the initial data sample format type and meets the data generation condition represented by the constraint prompt can be generated.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present disclosure relates to the field of artificial intelligence technology, and in particular to a method, apparatus, computer device and storage medium for generating instruction data. Background Art

[0002] With the development of artificial intelligence technology, the application of artificial intelligence models in various industries can greatly promote social innovation and progress. In many fields such as medicine, finance, education, and transportation, artificial intelligence models have become a key tool for solving problems. For example, intelligent question-answering systems based on artificial intelligence models can generate accurate answers to user questions based on questions and answers in training.

[0003] As an important part of the artificial intelligence model training process, instruction data can guide the model to learn and generate outputs that meet user expectations. Instruction data plays an important role in improving the model's instruction-following ability and generalization ability.

[0004] Currently, for professional knowledge and technology fields (such as biomedicine, legal knowledge, etc.), due to the lack of sufficient prior knowledge and data, the amount of instruction data is small, which makes it difficult to meet the learning and training needs of artificial intelligence models, especially large language models. The time and labor costs of obtaining instruction data through manual labeling are high. Although there are solutions in the relevant technology to generate instruction data that meets the needs through deep learning models (such as generative adversarial networks) or large language models, the scope of application of their data generation methods is relatively narrow, and is limited to data generation tasks of closed question and answer types and text classification types (sentiment analysis). Most of the generation tasks in the professional knowledge and technology field are open question and answer types, and the existing closed question and answer type and text classification type data generation methods are not applicable.

[0005] Therefore, the current data generation technology has technical problems such as high data generation cost and narrow scope of application. Summary of the invention

[0006] Based on this, it is necessary to provide a low-cost, widely applicable instruction data generation method, device, computer equipment and storage medium to address at least one of the above technical problems.

[0007] In a first aspect, an embodiment of the present disclosure provides a method for generating instruction data, the method comprising:

[0008] Get an initial data sample from a pre-set question-answering dataset;

[0009] Adjusting the format of the initial data sample to generate a format sample, wherein the format sample at least includes a question item, an option item corresponding to the question item, and an answer item;

[0010] Determine a target prompt template from a plurality of preset prompt templates according to the format type of the initial data sample;

[0011] Edit the sample data prompt of the target prompt template according to the format sample to generate the data generation prompt;

[0012] The data generation prompt is input into the preset model to generate target instruction data for training and learning the artificial intelligence model, wherein the target instruction data is consistent with the format type of the initial data sample.

[0013] Among them, the format types at least include an open question-and-answer format in which the answer data of the initial data sample is non-fixed content and a closed question-and-answer format in which the answer data of the initial data sample is fixed content, and the prompt template includes a constraint prompt for indicating the conditions for limiting the generation of corresponding instruction data and an example data prompt for providing a reference for the generation content of the corresponding instruction data.

[0014] In some embodiments, the example data prompt includes a question label, an option label, and an answer label. The plurality of prompt templates includes a first prompt template corresponding to an open question and answer format, and a second prompt template corresponding to a closed question and answer format.

[0015] The labels of the first prompt template are arranged in the order of question label, option label and answer label.

[0016] The labels of the second prompt template are arranged in the order of option label, answer label and question label.

[0017] In some embodiments, the constraint hint of the second hint template includes an option tag constraint hint, and the option tag constraint hint is used to restrict the option tag content in the instruction data to be consistent with the option tag content in the example data.

[0018] In some embodiments, the constraint prompts of the first prompt template and the second prompt template both include quantity constraint prompts, content constraint prompts, and format constraint prompts. The quantity constraint prompts, content constraint prompts, and format constraint prompts are used to respectively indicate the constraint conditions for limiting the quantity, content, and output format of the corresponding instruction data, wherein the output format is in JSON format.

[0019] In some embodiments, the target instruction data includes a plurality of question and answer data. The instruction data generation method may further include:

[0020] Target question and answer data are obtained from multiple question and answer data as samples for this round of data. Sample data of the target prompt template is edited according to the samples for this round of data to generate prompts for this round of data. The prompts for generating this round of data are input into a preset model to generate instruction data for this round.

[0021] In some embodiments, the current round of instruction data includes a plurality of current round of question and answer data, and the instruction data generation method may further include:

[0022] The target question and answer data of this round is obtained from multiple question and answer data of this round as the data sample of the next round. The sample data of the target prompt template is edited according to the data sample of the next round to generate the prompt for generating the data of the next round. The prompt for generating the data of the next round is input into the preset model to generate the instruction data of the next round.

[0023] In some embodiments, obtaining the current round target question and answer data from the plurality of current round question and answer data as the next round data sample may include:

[0024] Randomly select the target question and answer data of this round from multiple question and answer data of this round as the data sample of the next round. Or,

[0025] Select the question-and-answer data with the highest semantic similarity to the format sample of the previous round from multiple question-and-answer data of this round as the data sample of the next round. Or,

[0026] Select the question-and-answer data with the lowest semantic similarity to the format sample of the previous round from multiple question-and-answer data of this round as the data sample of the next round. Or,

[0027] Question and answer data with a preset semantic similarity to the format samples of the previous round are selected from multiple question and answer data of this round as data samples of the next round.

[0028] In some embodiments, the instruction data generating method may further include:

[0029] The format type of the initial data sample is determined according to the name information of the question-answering dataset and a preset correspondence table, wherein the correspondence table is used to indicate the correspondence between the name information and the format type.

[0030] In some embodiments, the preset question and answer data set is a professional knowledge question and answer data set in the target technical field. The instruction data generation method may also include:

[0031] The target instruction data is input into the preset artificial intelligence model so that the artificial intelligence model can be trained and learned to generate a new artificial intelligence model. The new artificial intelligence model has professional knowledge and capabilities in the target technology field.

[0032] Alternatively, the target instruction data is input into a preset artificial intelligence model for the artificial intelligence model to perform model fine-tuning to enhance the artificial intelligence model's ability to follow instructions in the target technology field.

[0033] In a second aspect, an embodiment of the present disclosure provides an instruction data generating device, the device comprising:

[0034] The sample acquisition module is used to obtain initial data samples from the preset question-answering dataset.

[0035] The format sample generation module is used to adjust the format of the initial data sample to generate a format sample, and the format sample at least includes a question item, an option item corresponding to the question item, and an answer item.

[0036] The prompt template determination module is used to determine a target prompt template from a plurality of preset prompt templates according to the format type of the initial data sample. The format type at least includes an open question-answer format in which the answer of the initial data sample is a non-fixed content and a closed question-answer format in which the answer of the initial data sample is a fixed content. The prompt template includes a constraint prompt for limiting the corresponding instruction data generation conditions and an example data prompt for providing a reference for the corresponding instruction data generation content.

[0037] The prompt generation module is used for editing the sample data prompt of the target prompt template according to the format sample and generating the data generation prompt.

[0038] The data generation module is used to input data generation prompts into a preset model to generate target instruction data for training and learning of the artificial intelligence model.

[0039] In a third aspect, an embodiment of the present disclosure provides a computer device, comprising a memory, a processor, and a computer program stored in the memory and executable on the processor, wherein when the processor executes the computer program, the steps of the instruction data generation method provided in any embodiment of the present disclosure in the first aspect are implemented.

[0040] In a fourth aspect, an embodiment of the present disclosure provides a computer-readable storage medium having a computer program stored thereon, which, when executed by a processor, implements the steps of the instruction data generation method provided in any embodiment of the present disclosure in the first aspect.

[0041] The above-mentioned instruction data generation method, device, computer equipment and storage medium obtain an initial data sample from a preset question and answer data set, determine the corresponding target prompt template according to the format type of the initial sample data, and generate a format sample after format adjustment according to the initial data sample, edit the sample data prompt in the target prompt template to generate a data generation prompt input into a preset model to generate target instruction data, wherein the format type may include an open question and answer format and a closed question and answer format, and the prompt template includes a constraint prompt and a sample data prompt. In the above-mentioned instruction data generation method, generating instruction data through a preset model has the effect of low data generation cost, and at the same time, the preset multiple prompt templates can cover the initial sample data of the open question and answer format and the closed question and answer format, and have a wide range of applications, and can generate target instruction data that is consistent with the format type of the initial data sample and satisfies the data generation conditions represented by the constraint prompt. BRIEF DESCRIPTION OF THE DRAWINGS

[0042] Figure 1 is a flowchart of a method for generating instruction data in some embodiments;

[0043] Figure 2 A schematic diagram of a question-answering example of a question-answering dataset in some embodiments;

[0044] Figure 3 A schematic diagram of a question-answering example of a question-answering dataset in some other embodiments;

[0045] Figure 4 is a schematic diagram of format samples involved in some embodiments;

[0046] Figure 5 is a schematic diagram of a prompt template in some embodiments;

[0047] Figure 6 is a schematic diagram of a first prompt template in some embodiments;

[0048] Figure 7 is a schematic diagram of a second prompt template in some embodiments;

[0049] Figure 8 A schematic diagram of a process involving iterative data generation in some embodiments;

[0050] Fig. 9 A schematic diagram of a process flow involving iterative data generation in some other embodiments;

[0051] Fig.10 is a structural block diagram of an instruction data generating device in some embodiments;

[0052] Fig.11 1 is a diagram of the internal structure of a computer device in some embodiments. DETAILED DESCRIPTION

[0053] In order to make the technical solutions and advantages of the present disclosure more clearly understood, the embodiments of the present disclosure and related technical contents are further described in detail below in combination with the accompanying drawings and text descriptions. It should be understood that the implementation methods described below are only used to explain the technical solutions of the embodiments of the present disclosure, and are not used to limit more possible implementation methods of the present disclosure.

[0054] It should be noted that the relational terms such as "first", "second" and the like appearing in this document are only used to distinguish things, states or actions, and do not necessarily indicate or imply relative importance or sequential relationships. The terms "include", "comprises" or any other variants thereof are used to indicate non-exclusive inclusion, and the included objects may not be limited to the objects listed in this document. The term "plurality" or other variants are used to indicate that the number of objects is two or more.

[0055] The instruction data generation method provided in the present application can be applied to a computer device, which can be a server or a terminal. The terminal can be, but is not limited to, various personal computers, laptops, smart phones, tablet computers, portable wearable devices, vehicle terminals, smart robots and other intelligent terminal devices, and the server can be implemented as an independent server or a server cluster composed of multiple servers.

[0056] In a first aspect, an embodiment of the present disclosure provides a method for generating instruction data, such as Figure 1 As shown, the instruction data generation method includes steps S101 to S105 that can be executed by a computer device. Each step is described below.

[0057] Step 101: Obtain an initial data sample from a preset question-answering dataset.

[0058] Among them, the question-answering dataset is a data set including multiple question-answering examples, which can be a public dataset that can be obtained through public channels, or a pre-created non-public dataset. Taking the public dataset as an example, the preset question-answering dataset can be PIQA (Physical Interaction: Question Answering, a set of question-answering examples based on physical common sense reasoning), PubMedQA (biomedical question-answering dataset), commensense QA (common sense question-answering dataset), or fingpt-fiqa_qa (financial intelligent question-answering dataset) in the financial field, or DISC-Law-SFT (legal field dataset) in the legal knowledge field.

[0059] The question-answering examples in the question-answering dataset may include at least question data and answer data corresponding to the question. For example, the question-answering examples in PIQA may be as follows: Figure 2 As shown in FIG. 2 , it includes question data 201, option data 202, and answer data 203. For another example, the question and answer example in PubMedQA can be as follows: Figure 3 As shown, it includes question data 301 , context data 302 , and answer data 303 .

[0060] Specifically, obtaining the initial data sample from the preset question and answer data set may be to randomly obtain a question and answer example from the preset question and answer data set, and use the randomly obtained question and answer example as the initial data sample. In some examples, the number of randomly selected question and answer examples may also be multiple.

[0061] Step 102: Adjust the format of the initial data sample to generate a format sample.

[0062] The format sample includes at least a question item, an option item corresponding to the question item, and an answer item. The question item is used to represent the question content of the question and answer example, the option item is used to represent multiple optional answer options corresponding to the question content, and the answer item is used to represent the best answer corresponding to the question content, wherein the content of the answer item is one of the multiple optional answer options included in the option item.

[0063] In some specific implementations, the format sample may include a question item, an option item, and an answer item. In some other specific implementations, the format sample may also include a context information item. The schematic diagram of the format sample may be as follows: Figure 4 The format sample may include a question item 401 , a context information item 402 , an option item 403 , and an answer item 404 .

[0064] Specifically, the data content included in the initial data sample is adjusted according to the format of the preset format sample to generate the format sample. The format sample question items can be generated according to the question data in the initial data sample, the answer items in the format sample can be generated according to the answer data in the initial data sample, and the option items of the format sample can be edited and generated according to the option data or answer data in the initial data sample.

[0065] In some specific examples, the initial data sample has option data, and the option items can be edited directly according to the option data. In some other specific examples, the initial data sample does not include option data. If the answer data in the initial data sample includes "yes" or "no", or "true" or "false", or other fixed answers that represent affirmative or negative meanings such as yes or no, right or wrong, option items can be generated according to the answer data. Accordingly, when the answer data is "yes" or "no", the content of the option items includes "yes" and "no".

[0066] Step 103: Determine a target prompt template from a plurality of preset prompt templates according to the format type of the initial data sample.

[0067] The format types include at least an open question and answer format and a closed question and answer format. The answer data of the initial data sample in the open question and answer format is non-fixed content, while the answer data of the initial data sample in the closed question and answer format is fixed content, that is, the meaning represented by the answer data is fixed, and only includes content representing positive or negative meanings, such as: "yes", "no", "true", "false", "right" or "wrong". Correspondingly, the answer data of the initial data sample in the open question and answer format is non-fixed content, that is, the meaning represented by the answer data is non-fixed, and is not like the positive or negative meaning in the closed question and answer format, for example, it can be a phrase or long sentence with a specific meaning.

[0068] The prompt template may include constraint prompts and sample data prompts, wherein the constraint prompts are used to indicate the conditions for limiting the generation of the corresponding instruction data, and the sample data prompts can be used to provide a reference for the generation of the corresponding instruction data. The constraint prompts may include one or more specific prompts. When the user has multiple instruction data generation conditions, multiple constraint prompts may be set to indicate multiple conditions for limiting the generation of instruction data. The sample data prompt may include one or more examples to provide a reference for the generation of instruction data.

[0069] Typically, in an artificial intelligence model, such as a large language model, a prompt can be a question, a description, a task description, or other data used to represent constraints on the model output content. By inputting the prompt into the model, the model is guided to analyze and reason based on the content of the prompt and generate an answer or text that meets the prompt requirements.

[0070] In some specific implementations, the schematic diagram of the structure of the prompt template can be as follows: Figure 5 As shown, the prompt template may include a constraint prompt 501 and an example data prompt 502 .

[0071] Specifically, by determining that the format type of the initial data sample is an open question and answer format or a closed question and answer format, a template corresponding to the format type can be determined from a plurality of preset prompt templates as a target prompt template.

[0072] Step 104: Edit the sample data prompt of the target prompt template according to the format sample to generate a data generation prompt.

[0073] In some specific examples, the prompt template can be an editable code, and both the constraint prompt and the sample data prompt can be edited and modified. By editing and modifying the content of the constraint prompt and the sample data prompt, different instruction data generation requirements can be met. The sample data prompt can be a specific example, and the sample data prompt can include a question label, an option label, and an answer label, and each label includes corresponding content information.

[0074] Specifically, the sample data prompt of the target prompt template is edited according to the format sample to generate the data generation prompt, which can be to use the contents of the question item, option item and answer item in the format sample as the contents of the question label, option label and answer label in the sample data prompt, respectively. That is, the content of the format sample is edited into the sample data prompt.

[0075] Step 105: Input the data generation prompt into the preset model to generate target instruction data for training and learning the artificial intelligence model.

[0076] Among them, the preset model can be a GPT series model (such as GPT-3, GPT-4), command-R+ (a pre-trained language model), or other large language models or other generative models.

[0077] By inputting the data generation hint into the preset model, target instruction data can be generated, which can be used for training and learning of the artificial intelligence model to generate a new artificial intelligence model. The target instruction data is consistent with the format type of the initial data sample, and the target instruction data can meet the data generation conditions represented by the constraint hint. The target instruction data is generated based on the data generation hint, so the target instruction data meets one or more constraint hints and sample data hints in the data generation hint.

[0078] In some specific implementations, the target instruction data includes multiple question and answer data, whose format type is consistent with the initial data sample, and whose included content corresponds to the format sample, specifically, may include question items, option items, and answer items.

[0079] In the above instruction data generation method, the corresponding target prompt template is determined according to the format type of the initial sample data, and the format sample generated after the format adjustment is performed according to the initial data sample, and the sample data prompt in the target prompt template is edited to generate the data generation prompt input into the preset model to generate the target instruction data, wherein the format type may include an open question and answer format and a closed question and answer format, and the prompt template may include a constraint prompt and a sample data prompt. In the above instruction data generation method, generating instruction data through a preset model has the effect of low data generation cost, and at the same time, the preset multiple prompt templates can cover the initial sample data of the open question and answer format and the closed question and answer format, and have a wide range of applications, and can generate target instruction data that is consistent with the format type of the initial data sample and satisfies the data generation conditions represented by the constraint prompt.

[0080] In some embodiments, the example data prompt includes a question label, an option label, and an answer label, wherein the example data prompt may include a specific example, which may include three pieces of text information as question content, option content, and answer content, respectively. Accordingly, each piece of text information has a label, that is, the question content has a question label, the option content has an option label, and the answer content has an answer label. The text information in the question content is the question, the text information in the option content is multiple optional answers corresponding to the question, the text information in the answer content is the answer, and the answer is one of the multiple optional answers in the option content.

[0081] The plurality of prompt templates may include a first prompt template corresponding to an open question and answer format, and a second prompt template corresponding to a closed question and answer format.

[0082] The order of the labels of the first prompt template is question label, option label and answer label. The order of the labels of the second prompt template is option label, answer label and question label.

[0083] In some specific examples, the arrangement order of each label can be the presentation order of each label component in the prompt code, and the arrangement order of each label of the first prompt template is constructed in a logical order, that is, from the question label, to the option label, and then to the answer label. The arrangement order of each label of the second prompt template is from the option label, to the answer label, and then to the question label. In some cases, the arrangement order of each label can limit the order in which the question items, option items, and answer items in the target instruction data are generated when the model outputs the target instruction data.

[0084] For the second prompt template, a non-logical order is adopted to construct the label arrangement order, which can ensure that prompts are generated based on the data generated by the second prompt template. After inputting the preset model, the format type of the output target instruction data is a closed question and answer format corresponding to the second prompt template.

[0085] Since the order of label arrangement limits the order of generating question items, option items, and answer items when the model outputs target instruction data, when the model inputs the data generated according to the second prompt template to generate prompts, the content of the option items corresponding to the option labels is generated first, then the content of the answer items corresponding to the answer labels is generated, and finally the content of the question items corresponding to the question labels is generated. This can avoid the situation where the model generates the content of the option items in an open format when generating the content of the question items in a logical order, thereby causing the format type of the generated target instruction data to be inconsistent with the second prompt template. For example, it can avoid the situation where the content of the option items with non-fixed meanings is generated when the target instruction data in a closed question and answer format is generated by the autoregressive model in the large language model, resulting in the target instruction data being in an open question and answer format.

[0086] In some specific implementations, the structural diagram of the first prompt template is as follows Figure 6 As shown, the first prompt template 600 may include a constraint prompt 610 and an example data prompt 620, wherein the example data prompt 620 includes a question label 621, an option label 622, and an answer label 623. Figure 6 As shown, the first prompt template 700 may include a constraint prompt 710 and an example data prompt 720 , wherein the example data prompt 720 includes an option label 721 , an answer label 722 , and a question label 723 .

[0087] In some embodiments, the constraint hint of the second hint template includes an option tag constraint hint. The option tag constraint hint is used to constrain the option tag content in the instruction data to be consistent with the option tag content in the example data. In some specific examples, the option tag constraint hint can be a paragraph of text, and the content of the option tag constraint hint can be: "The created examples**must**have the same options as the providedexample." (The created examples**must**have the same options as the provided examples.)

[0088] In some embodiments, the constraint prompts of the first prompt template and the second prompt template both include quantity constraint prompts, content constraint prompts, and format constraint prompts.

[0089] The quantity constraint prompt, content constraint prompt and format constraint prompt are respectively used to indicate the constraint conditions for limiting the quantity, content and output format of the corresponding instruction data, where the output format is in JSON format.

[0090] Specifically, the quantity constraint prompt can be used to indicate the quantity condition that limits the corresponding instruction data. For example, the quantity condition can be 3, 5, 10, or other specific values. The input of the specific quantity condition can be realized by editing the variables in the quantity constraint prompt. In some specific examples, the quantity constraint prompt can be a piece of text. Specifically, the content of the quantity constraint prompt can be: "You are creating {num_examples} more examples that follow the format of the example provided, but with a different content." (You are creating {num_examples} more examples that follow the format of the example provided, but with a different content.), where "{num_examples}" is an editable variable, and "num_examples" can be edited to the value corresponding to the quantity condition. For example, when the quantity condition is to generate target instruction data with 10 question and answer data, the content of the quantity constraint prompt can be edited as: "You are creating "10" more examples that follow the format of the example provided, but with a different content.".

[0091] The content constraint hint is used to indicate the content condition that restricts the corresponding instruction data. For example, the content condition may be a requirement that multiple question and answer data in the generated target instruction data need to have different answer contents, or a requirement that multiple question and answer data need to have different option contents. In some specific examples, the content constraint hint may be a piece of text. Specifically, the content of the content constraint hint may be: "The created examples**must**all have differentanswers." (The created examples**must**all have different answers.).

[0092] The format constraint hint is used to indicate the output format condition that restricts the corresponding instruction data. For example, the output format condition may be a requirement that the generated target instruction data be output in JSON format. In some specific examples, the output format condition may be a piece of text. Specifically, the content of the output format condition may be: "The output**must**be inunnumbered JSON format." (The output**must**be inunnumbered JSON format.).

[0093] In some embodiments, the target instruction data may include a plurality of question and answer data. Figure 8 As shown, the instruction data generating method further includes steps S801 to S803 of performing data iterative generation.

[0094] Step S801: Obtain target question and answer data from multiple question and answer data as data samples for this round.

[0095] Step S802: Edit the sample data of the target prompt template according to the data samples of this round to generate prompts for data generation of this round.

[0096] Step S803: Input the prompt for generating data for this round into the preset model to generate instruction data for this round.

[0097] After obtaining an initial data sample from a preset question-and-answer data set and generating target instruction data through multiple steps such as format adjustment, target prompt target determination, and prompt generation, the instruction data generation method may also include one or more rounds of iterative generation methods for instruction data.

[0098] Since the format type of the target instruction data generated in the above embodiment is consistent with the format type of the initial data sample, and since the presentation format of the target instruction data is consistent with the format sample, that is, the current round of data samples obtained from the target instruction data can be directly used as format samples to edit the corresponding prompt template, without the need to make format adjustments or determine the target prompt template based on the format type.

[0099] Specifically, the target instruction data generated according to the initial sample data includes multiple question and answer data, and the target question and answer data is obtained from the multiple question and answer data as the data sample for generating the current round of instruction data, which is equivalent to the initial data sample in the above embodiment. Then, the sample data of the target prompt template is edited according to the data sample for the current round to generate the prompt for generating the data for the current round, and the prompt for generating the data for the current round is input into the preset model to generate the instruction data for the current round.

[0100] In some embodiments, the current round of instruction data includes a plurality of current round of question and answer data. Fig. 9 As shown, the instruction data generating method further includes steps S901 to S903.

[0101] Step S901: Obtain target question and answer data for this round from multiple question and answer data for this round as data samples for the next round.

[0102] Step S902: Edit the sample data of the target prompt template according to the next round of data samples to generate prompts for the next round of data generation.

[0103] Step S903: Input the next round of data generation prompts into the preset model to generate the next round of instruction data.

[0104] After generating this round of instruction data by selecting this round of data samples from the target instruction data, the data generating method may further include one or more rounds of iterative generating methods for instruction data.

[0105] Since the format type of the current round of instruction data generated in the above embodiment is consistent with the format type of the target instruction data, and since the presentation format of the current round of instruction data is consistent with the format sample, the next round of data samples obtained from the current round of instruction data can be directly used as format samples to edit the corresponding prompt template, without the need to make format adjustments or determine the target prompt template based on the format type.

[0106] Specifically, the current round of instruction data includes multiple current round of question and answer data, and the target question and answer data is obtained from the multiple current round of question and answer data as the next round of data samples generated by the next round of instruction data, which is equivalent to the current round of data samples in the above embodiment. Then, the sample data of the target prompt template is edited according to the next round of data samples to generate the next round of data generation prompt, and the next round of data generation prompt is input into the preset model to generate the next round of instruction data.

[0107] In some embodiments, the instruction data generation method may also include multiple rounds. Specifically, the number of rounds of instruction iteration is related to the number of instruction data generated in each round and the total number of instruction data required to be generated. It is easy to understand that the generation of instruction data in each round can obtain data samples from the instruction data generated in the previous round, and edit the sample data of the corresponding prompt template according to the data sample, generate data generation prompts, and then input the data generation prompts into the preset model to obtain a new round of instruction data. The number of instruction data generated in each round and the total number of instruction data required to be generated can be set by those skilled in the art according to actual conditions.

[0108] Through multiple rounds of instruction data generation methods, multiple instruction data with unified formats but different contents can be obtained from an initial data sample.

[0109] In some embodiments, the method for obtaining the next round of data samples involved in step S901 may include multiple methods.

[0110] Method 1: Randomly select the target question and answer data of this round from multiple question and answer data of this round as the data sample of the next round.

[0111] Method 2: Select the question and answer data with the highest semantic similarity to the format samples of the previous round from multiple question and answer data of this round as the data samples of the next round.

[0112] Method 3: Select the question and answer data with the lowest semantic similarity with the format sample of the previous round from multiple question and answer data of this round as the data sample of the next round.

[0113] Method 4: Select question and answer data whose semantic similarity with the format samples of the previous round is a preset value from multiple question and answer data of this round as data samples of the next round.

[0114] In the iterative multi-round instruction data generation method, each round of data samples are obtained from the instruction data generated in the previous round, and the acquisition method may include random selection, selection with the highest semantic similarity value, selection with the lowest semantic similarity value, and selection with a preset semantic similarity value. The data samples are selected according to the semantic similarity, which may be to compare the semantic similarity of multiple current round question and answer data included in the current round target instruction data with the data samples (i.e., format samples) of the previous round, and then select the question and answer data with the highest, lowest or preset similarity as the data samples for the next round.

[0115] Specifically, the comparison of semantic similarity can be performed by converting multiple question-and-answer data to be compared through Tokenizer (a class used to vectorize text and convert text into a sequence), converting the question-and-answer data in text form into a sequence, and then vectorizing the sequence, further calculating the cosine similarity between the converted question-and-answer data, and selecting the corresponding target question-and-answer data as the next round of data samples according to the cosine similarity. Accordingly, the closer the cosine similarity is to 1, the more similar the two vectors are, and the closer the cosine similarity is to 0, the less similar the two vectors are. The question-and-answer data with the highest semantic similarity is selected as the next round of data samples, that is, a question-and-answer data with a cosine similarity closest to 1 with the format sample of the previous round is selected from the question-and-answer data of this round as the data sample of the next round. The question-and-answer data with the lowest semantic similarity is selected as the data sample of the next round, that is, a question-and-answer data with a cosine similarity closest to 0 with the format sample of the previous round is selected from the question-and-answer data of this round as the data sample of the next round. Select question and answer data whose semantic similarity with the format sample of the previous round is a preset value, that is, select a question and answer data whose cosine similarity with the format sample of the previous round is a preset value from the current round of question and answer data as the data sample of the next round, where the preset value can be a specific numerical value between 0 and 1, or a specific interval range, such as 0.5 or an interval range greater than 0.3 and less than or equal to 0.6.

[0116] In some specific implementations, multiple methods for obtaining data samples for the next round may be fixed to one type of selection method, or multiple selection methods may be used in combination. For example: when generating instruction data in the i-1th round of iteration, the question and answer data with the highest similarity to the format sample (i.e., data sample) of the i-2th round is selected from the instruction data generated in the i-2th round as the data sample of the i-1th round, and when generating instruction data in the i-th round of iteration, the data sample is randomly selected from the instruction data generated in the i-1th round, that is, when generating instruction data in the i+1th round of iteration, the question and answer data with the lowest similarity to the format sample (i.e., data sample) of the i-th round is selected from the instruction data generated in the i-th round as the data sample of the i+1th round.

[0117] Regarding the method of obtaining each round of data samples, compared with the method of selecting in sequence from a preset question-and-answer data set in the related art, this embodiment can improve the randomness and flexibility of data sample selection by randomly selecting from the instruction data generated in the previous round or selecting based on semantic similarity. At the same time, by selecting data samples for generating a new round of instruction data from the instruction data generated in the previous round, the diversity and stability of data samples can be improved, and the richness of the generated instruction data can be increased.

[0118] In some embodiments, the instruction data generation method further includes: determining the format type of the initial data sample according to the name information of the question and answer data set and a preset correspondence table, wherein the correspondence table is used to indicate the correspondence between the name information and the format type.

[0119] Usually, the format type of question and answer data in a question and answer dataset is the same. A correspondence table between the question and answer dataset name and format type can be set in advance. According to the name information of the question and answer dataset and the preset correspondence table, the format type of the initial data sample can be quickly determined.

[0120] In some embodiments, by adding the name information of a new question and answer dataset in the code, a preset program or script may be called through a preset command line to obtain initial sample data from the question and answer dataset.

[0121] In some embodiments, the preset question and answer data set is a professional knowledge question and answer data set in the target technical field. The instruction data generation method may also include: inputting the target instruction data into a preset artificial intelligence model so that the artificial intelligence model can be trained and learned to generate a new artificial intelligence model, and the new artificial intelligence model has the professional knowledge ability in the target technical field. Or, inputting the target instruction data into a preset artificial intelligence model so that the artificial intelligence model can fine-tune the model to improve the ability of the artificial intelligence model to follow instructions in the target technical field.

[0122] The target technical field may be a biomedical technical field, a chemical knowledge technical field, a legal knowledge field, or a technical field of other professional knowledge. The preset artificial intelligence model may be any language model.

[0123] After the instruction data is generated through the above embodiments, the instruction data can be input into a preset artificial intelligence model, such as a large language model, so that the model can use the instruction data for training and learning to generate a new artificial intelligence model. The new artificial intelligence model is injected with professional knowledge and capabilities in the target technical field. It can then be applied to intelligent systems in related technical fields, such as chatbot systems, intelligent question-and-answer systems, etc.

[0124] Instruction data can also be used to input into preset artificial intelligence models for model fine-tuning. Since the instruction data is generated based on the professional knowledge question and answer dataset in the target technical field, by using the instruction data for fine-tuning, the model can better understand and follow the natural language instructions related to professional knowledge given by the user, and make outputs that meet user needs, thereby improving the model's instruction-following ability.

[0125] It should be understood that although Figure 1 , Figure 8 and Fig. 9The steps in the flowchart are displayed in sequence as indicated by the arrows, but these steps are not necessarily executed in the order indicated by the arrows. Figure 1 , Figure 8 and Fig. 9 Unless otherwise specified herein, the steps shown and the steps involved in other embodiments are not strictly limited in order of execution, and the steps can be executed in other orders. Moreover, at least a part of the steps in the aforementioned embodiments 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 the execution order of these sub-steps or stages 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.

[0126] In a second aspect, an embodiment of the present disclosure provides an instruction data generating device, such as Fig.10 As shown, the instruction data generating device 1000 includes: a sample acquisition module 1010 , a format sample generating module 1020 , a prompt template determining module 1030 , a prompt generating module 1040 and a data generating module 1050 .

[0127] The sample acquisition module 1010 is used to obtain an initial data sample from a preset question-answer data set.

[0128] The format sample generating module 1020 is used to adjust the format of the initial data sample to generate a format sample, where the format sample at least includes a question item, option items corresponding to the question item, and an answer item.

[0129] The prompt template determination module 1030 is used to determine a target prompt template from a plurality of preset prompt templates according to the format type of the initial data sample.

[0130] Among them, the format types include at least an open question-and-answer format in which the answers to the initial data samples are non-fixed content and a closed question-and-answer format in which the answers to the initial data samples are fixed content, and the prompt template includes constraint prompts for limiting the corresponding instruction data generation conditions and example data prompts for providing references for the corresponding instruction data generation content.

[0131] The prompt generation module 1040 is used to edit the sample data prompt of the target prompt template according to the format sample to generate a data generation prompt.

[0132] The data generation module 1050 is used to input the data generation prompt into a preset model to generate target instruction data for training and learning the artificial intelligence model.

[0133] In some embodiments, the target instruction data includes multiple question and answer data, and the instruction data generating device may further include a data iteration module, and the data iteration module includes an iteration sample acquisition unit, an iteration prompt generation unit and an iteration data generation unit.

[0134] The iterative sample acquisition unit is used to obtain target question and answer data from multiple question and answer data as the data sample of this round.

[0135] The iterative prompt generating unit is used to edit the sample data of the target prompt template according to the data samples of this round, and generate the prompts for generating the data of this round.

[0136] and an iterative data generation unit, which is used to input the prompts for generating data for this round into a preset model to generate instruction data for this round.

[0137] In some embodiments, the current round of instruction data includes a plurality of current round of question and answer data.

[0138] The iterative sample acquisition unit is also used to obtain the current round target question and answer data from multiple current round question and answer data as the next round of data samples.

[0139] The iterative prompt generating unit is further used to edit the sample data of the target prompt template according to the next round of data samples to generate the next round of data generation prompts.

[0140] The iterative data generation unit is also used to input the next round of data generation prompts into a preset model to generate the next round of instruction data.

[0141] In some embodiments, the iterative sample acquisition unit acquires samples by randomly selecting target question and answer data of this round from multiple question and answer data of this round as data samples of the next round. It may also be selecting question and answer data with the highest semantic similarity to the format sample of the previous round from multiple question and answer data of this round as data samples of the next round. It may also be selecting question and answer data with the lowest semantic similarity to the format sample of the previous round from multiple question and answer data of this round as data samples of the next round. It may also be selecting question and answer data with a preset semantic similarity to the format sample of the previous round from multiple question and answer data of this round as data samples of the next round.

[0142] In some embodiments, the instruction data generating device may further include a format determination unit, which is used to determine the format type of the initial data sample according to the name information of the question and answer data set and a preset correspondence table, wherein the correspondence table is used to indicate the correspondence between the name information and the format type.

[0143] In some embodiments, the preset question and answer data set is a professional knowledge question and answer data set in the target technical field. The instruction data generation device may also include a data application module, which may be used to input the target instruction data into a preset artificial intelligence model so that the artificial intelligence model can be trained and learned to generate a new artificial intelligence model, and the new artificial intelligence model has professional knowledge capabilities in the target technical field. The data application module may also be used to input the target instruction data into a preset artificial intelligence model so that the artificial intelligence model can perform model fine-tuning to enhance the artificial intelligence model's ability to follow instructions in the target technical field.

[0144] For more specific limitations on the instruction data generating device, please refer to the limitations on the instruction data generating method above. The instruction data generating device can also be used to execute more steps of the instruction data generating method in the embodiments of the present disclosure, which will not be repeated here. Each module in the above-mentioned instruction data generating device can be implemented in whole or in part by software, hardware and a combination thereof. The above-mentioned modules can be embedded in or independent of the processor in the computer device in the form of hardware, or can be stored in the memory in the computer device in the form of software, so that the processor can call and execute the operations corresponding to the above modules.

[0145] In a third aspect, an embodiment of the present disclosure provides a computer device, comprising a memory, a processor, and a computer program stored in the memory and executable on the processor, wherein the processor implements the steps of the instruction data generation method provided in any embodiment of the present disclosure in the first aspect when executing the computer program.

[0146] In some embodiments, the computer device may be a terminal, and its internal structure diagram may be as follows: Fig.11 As shown. The computer device includes a processor, a memory, a network interface, a display screen and an input device connected via 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 and a computer program. The internal memory provides an environment for the operation of the operating system and the computer program in the non-volatile storage medium. The network interface of the computer device is used to communicate with an external terminal via a network connection. When the computer program is executed by the processor, the instruction data generation method in any embodiment of the present invention is implemented. The display screen of the computer device can be a liquid crystal display screen or an electronic ink display screen, and the input device of the computer device can be a touch layer covered on the display screen, or a button, trackball or touchpad set on the computer device housing, or an external keyboard, touchpad or mouse, etc.

[0147] Those skilled in the art will understand that Fig.11The structure shown in the figure is merely a block diagram of a partial structure related to the embodiment scheme of the present disclosure, and does not constitute a limitation on the computer device to which the embodiment scheme of the present disclosure is applied. The specific computer device may include more or fewer components than those shown in the figure, or combine certain components, or have a different arrangement of components.

[0148] In a fourth aspect, an embodiment of the present disclosure provides a computer-readable storage medium having a computer program stored thereon, which, when executed by a processor, implements the steps of the instruction data generation method provided in any embodiment of the present disclosure in the first aspect.

[0149] The computer readable storage medium may be Fig.11 A computer-readable storage medium in the computer device shown.

[0150] Those of ordinary skill in the art can understand that all or part of the processes in the above-mentioned embodiment methods can be implemented by instructing related hardware through a computer program. The aforementioned 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-mentioned methods. Among them, any reference to memory, storage, database or other media used in the embodiments of the present disclosure may include non-volatile and / or volatile memory. Non-volatile memory may include read-only memory (ROM), programmable ROM (PROM), electrically programmable ROM (EPROM), electrically erasable programmable ROM (EEPROM) or flash memory. Volatile memory may 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 (DDRSDRAM), enhanced SDRAM (ESDRAM), synchronous link DRAM (SLDRAM), memory bus (Rambus) direct RAM (RDRAM), direct memory bus dynamic RAM (DRDRAM), and memory bus dynamic RAM (RDRAM), etc.

[0151] The technical features of the above embodiments may be arbitrarily combined. To make the description concise, not all possible combinations of the technical features in the above embodiments are described. However, as long as there is no contradiction in the combination of these technical features, they should be considered to be within the scope of the present disclosure.

[0152] The above embodiments only express several implementation methods of the present disclosure, and the descriptions thereof are relatively specific and detailed, but they cannot be understood as limiting the protection scope of the present disclosure. It should be pointed out that, for those of ordinary skill in the art, several modifications and improvements can be made without departing from the concept of the present disclosure, and these all belong to the protection scope of the present disclosure. Therefore, the protection scope of the present disclosure shall be subject to the attached claims.

Claims

1. A method for generating instruction data, characterized in that: The method comprises: Get an initial data sample from a pre-set question-answering dataset; Adjusting the format of the initial data sample to generate a format sample, wherein the format sample at least includes a question item, option items corresponding to the question item, and an answer item; According to the format type of the initial data sample, a target prompt template is determined from a plurality of preset prompt templates; wherein the format type at least includes an open question-answer format in which the answer data of the initial data sample is non-fixed content and a closed question-answer format in which the answer data of the initial data sample is fixed content, and the prompt template includes a constraint prompt for indicating a condition for limiting the generation of corresponding instruction data and an example data prompt for providing a reference for the generation content of the corresponding instruction data; Edit the sample data prompt of the target prompt template according to the format sample to generate a data generation prompt; The data generation prompt is input into a preset model to generate target instruction data for training and learning the artificial intelligence model, wherein the target instruction data is consistent with the format type of the initial data sample.

2. The method according to claim 1, characterized in that The example data prompt includes a question label, an option label, and an answer label; the plurality of prompt templates include a first prompt template corresponding to the open question and answer format, and a second prompt template corresponding to the closed question and answer format; The labels of the first prompt template are arranged in the order of question label, option label and answer label; The labels of the second prompt template are arranged in the order of option label, answer label and question label.

3. The method according to claim 2, characterized in that The constraint prompt of the second prompt template includes an option tag constraint prompt, and the option tag constraint prompt is used to restrict the option tag content in the instruction data to be consistent with the option tag content in the example data.

4. The method according to claim 2, characterized in that: The constraint prompts of the first prompt template and the second prompt template both include quantity constraint prompts, content constraint prompts and format constraint prompts; the quantity constraint prompts, the content constraint prompts and the format constraint prompts are respectively used to represent the constraint conditions for limiting the quantity, content and output format of the corresponding instruction data, wherein the output format is in JSON format.

5. The method according to claim 1, characterized in that The target instruction data includes a plurality of question-answer data; the method further includes: Obtain target question and answer data from the multiple question and answer data as data samples for this round; The example data of the target prompt template is edited according to the data samples of this round to generate prompts for generating data of this round; and the prompts for generating data of this round are input into the preset model to generate instruction data of this round.

6. The method according to claim 5, characterized in that The current round of instruction data includes a plurality of current round of question and answer data, and the method further includes: Acquire the current round target question and answer data from the multiple current round question and answer data as the next round data sample; Edit the sample data of the target prompt template according to the next round of data samples to generate a next round of data generation prompt; The next round of data generation prompt is input into the preset model to generate the next round of instruction data.

7. The method according to claim 6, characterized in that The step of obtaining the current round target question and answer data from the multiple current round question and answer data as the next round data sample includes: Randomly select the current round target question and answer data from the multiple current round question and answer data as the next round data sample; or, Selecting the question-and-answer data with the highest semantic similarity to the format sample of the previous round from the multiple question-and-answer data of the current round as the data sample of the next round; or, Selecting the question-and-answer data with the lowest semantic similarity to the format sample of the previous round from the multiple question-and-answer data of the current round as the data sample of the next round; or, Question and answer data having a preset semantic similarity with the format sample of the previous round is selected from the multiple question and answer data of the current round as the data sample of the next round.

8. The method according to claim 1, characterized in that The method further comprises: The format type of the initial data sample is determined according to the name information of the question and answer data set and a preset correspondence table; wherein the correspondence table is used to represent the correspondence between the name information and the format type.

9. The method according to claim 1, characterized in that: The preset question-and-answer data set is a professional knowledge question-and-answer data set in the target technical field; the method further comprises: Inputting the target instruction data into a preset artificial intelligence model so that the artificial intelligence model can be trained and learned to generate a new artificial intelligence model, wherein the new artificial intelligence model has professional knowledge and capabilities in the target technical field; Alternatively, the target instruction data is input into the preset artificial intelligence model so that the artificial intelligence model can perform model fine-tuning to enhance the ability of the artificial intelligence model to follow instructions in the target technology field.

10. A command data generating device, characterized in that: The device comprises: A sample acquisition module is used to obtain initial data samples from a preset question-answering dataset; A format sample generating module, used for formatting the initial data sample to generate a format sample, wherein the format sample at least includes a question item, an option item corresponding to the question item, and an answer item; a prompt template determination module, configured to determine a target prompt template from a plurality of preset prompt templates according to the format type of the initial data sample; wherein the format type at least includes an open question-and-answer format in which the answer to the initial data sample is a non-fixed content and a closed question-and-answer format in which the answer to the initial data sample is a fixed content, and the prompt template includes a constraint prompt for limiting the corresponding instruction data generation condition and an example data prompt for providing a reference for the corresponding instruction data generation content; a prompt generation module, used for editing the sample data prompt of the target prompt template according to the format sample to generate a data generation prompt; The data generation module is used to input the data generation prompt into a preset model to generate target instruction data for training and learning of the artificial intelligence model.

11. 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, the steps of the method according to any one of claims 1 to 9 are implemented.

12. A computer-readable storage medium having a computer program stored thereon, characterized in that: When the computer program is executed by a processor, the steps of the method according to any one of claims 1 to 9 are implemented.

Citation Information

Cited By

  • Large language model training method and device, electronic equipment and storage medium

    CN119647586A

  • Training method and device of large language model, electronic equipment and storage medium

    CN119647586B

  • Training sample data generation method and device, readable storage medium and program product

    CN120277419A

  • Training sample data generation method, device, readable storage medium and program product

    CN120277419B