Instruction dataset construction method and apparatus, electronic device, and storage medium

CN118916692BActive Publication Date: 2026-10-16PENG CHENG LAB
View PDF 2 Cites 0 Cited by

Patent Information

Application Number
CN202410697065.X
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2024-05-30
Publication Date
2026-10-16
Estimated Expiration
2044-05-30

AI Technical Summary

Technical Problem

[0003]相关技术中,构建指令数据集依赖于格式化现有的原始数据集,容易将原始数据的问题传递到生成的指令数据集,并且固定的模板无法适应多样性的原始数据集,导致生成的指令过于具体或过于笼统,降低了指令数据集的质量

Benefits of technology

[0017] The instruction dataset construction method, apparatus, electronic device, and storage medium proposed in this application have the following beneficial effects: First, they acquire sample corpus text and the names of multiple nested background levels within the sample corpus text. These nested level names can fully reflect the contextual theme of the sample corpus text to varying degrees of generalization and specificity. Second, they acquire a preset prompt template, using multiple level names as keywords, and sequentially filling multiple empty spaces in the prompt template according to the corresponding background level order to generate a first prompt text. This is suitable for corpora with structural information, generating a more informative and adaptable first prompt text that better helps in understanding the meaning of the sample corpus text and the needs for generating instructions, thus improving the comprehensibility of the prompt text. Third, they generate target prompt text based on the first prompt text and the sample corpus text, and input the target prompt text into a preset large language model to obtain target question-answer pairs related to the sample corpus text. The obtained target question-answer pairs can more accurately capture the characteristics of the sample corpus text, improving the quality of the generated target question-answer pairs. Constructing an instruction dataset based on these target question-answer pairs can improve the quality of the constructed instruction dataset.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN118916692B_ABST
    Figure CN118916692B_ABST
Patent Text Reader

Abstract

The embodiment of the application provides a kind of instruction data set construction method, device, electronic equipment and storage medium, belong to natural language processing technical field.The method includes: obtaining sample corpus text, and the level name of multiple nested background levels where sample corpus text is located;Obtain the preset prompt template, multiple level names are used as key words, and are sequentially filled into multiple positions in the prompt template according to the order of corresponding background levels, to generate first prompt text;According to first prompt text and sample corpus text, generate target prompt text, and input target prompt text into preset large language model, obtain target question and answer pair related to sample corpus text;Instruction data set is constructed based on target question and answer pair.The instruction data set construction method, device, electronic equipment and storage medium provided in the embodiment of the application can improve the quality of the instruction data set constructed.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] This application relates to the field of natural language processing technology, and in particular to a method, apparatus, electronic device and storage medium for constructing instruction datasets. Background Technology

[0002] Instruction datasets are an important data resource used in the training and fine-tuning of large language models, thereby improving the general dialogue capabilities of these models. Instruction datasets include instructions or tasks with clear objectives and structures, which can be used in question-and-answer application scenarios.

[0003] In related technologies, constructing instruction datasets relies on formatting existing raw datasets, which can easily transfer problems from the raw data to the generated instruction datasets. Furthermore, fixed templates cannot adapt to diverse raw datasets, resulting in generated instructions that are either too specific or too general, thus reducing the quality of the instruction dataset. Summary of the Invention

[0004] The main objective of this application is to provide a method, apparatus, electronic device, and storage medium for constructing instruction datasets, which can improve the quality of the constructed instruction datasets.

[0005] To achieve the above objectives, a first aspect of this application proposes a method for constructing an instruction dataset. The method includes: acquiring sample corpus text and the names of multiple nested background levels in which the sample corpus text is located; acquiring a preset prompt template, using the multiple level names as keywords, and sequentially filling multiple empty spaces in the prompt template according to the order of the corresponding background levels to generate a first prompt text; generating a target prompt text based on the first prompt text and the sample corpus text, and inputting the target prompt text into a preset large language model to obtain target question-answer pairs related to the sample corpus text; and constructing an instruction dataset based on the target question-answer pairs.

[0006] In some embodiments, obtaining a preset prompt template, using multiple level names as keywords, and sequentially filling them into multiple empty spaces in the prompt template according to the order of the corresponding background levels to generate first prompt text includes: constructing nested layer key-value pairs based on the level names of the sample corpus text and the multiple nested background levels in which the sample corpus text is located, wherein the layer key-value pairs include multiple title keys constructed based on the level names; obtaining a preset prompt template, and sequentially filling the title keys of the nested layer key-value pairs into multiple empty spaces in the prompt template to generate first prompt text.

[0007] In some embodiments, constructing nested layer key-value pairs based on the layer names of the sample corpus text and the multiple nested background layers in which the sample corpus text is located includes: constructing a first-level layer key-value pair based on the layer name of the first level and the text content of the sample corpus text, wherein the title key of the first-level layer key-value pair includes the layer name of the first level, and the value of the first-level layer key-value pair includes the text content of the sample corpus text; constructing layer key-value pairs above the first level based on the layer names of the layer above the first level and the layer key-value pairs of the corresponding next level, wherein the title key of the layer key-value pairs above the first level includes the layer name of the corresponding level, and the value includes the layer key-value pair of the corresponding next level.

[0008] In some embodiments, obtaining the sample corpus text and the level names of the multiple nested background levels in which the sample corpus text is located includes: obtaining the initial corpus text; extracting multiple nested semantic keywords corresponding to the text content in the initial corpus text based on a pre-trained semantic analysis model; obtaining the sample corpus text based on the text content of the initial corpus text; and obtaining the level names of the multiple nested background levels in which the sample corpus text is located based on the multiple nested semantic keywords.

[0009] In some embodiments, obtaining a preset prompt template, using multiple level names as keywords, and sequentially filling them into multiple empty spaces in the prompt template according to the corresponding background level order to generate a first prompt text includes: obtaining a preset prompt template, using multiple level names as keywords, and sequentially filling them into multiple empty spaces in the prompt template according to the corresponding background level order; determining the number of prompt outputs based on the number of sentences and sentence length of the sample corpus text, and generating the first prompt text.

[0010] In some embodiments, generating target prompt text based on the first prompt text and the sample corpus text, and inputting the target prompt text into a preset large language model to obtain target question-answer pairs related to the sample corpus text, includes: generating target prompt text based on the first prompt text and the sample corpus text, and inputting the target prompt text into a preset large language model; and extracting target question-answer pairs corresponding to the number of prompt outputs from the sample corpus text based on the target prompt text using the preset large language model.

[0011] In some embodiments, generating target prompt text based on the first prompt text and the sample corpus text, and inputting the target prompt text into a preset large language model to obtain target question-answer pairs related to the sample corpus text, includes: obtaining a text summary corresponding to the sample corpus text; generating target prompt text based on the first prompt text and the sample corpus text; and inputting the target prompt text and the text summary into a preset large language model to obtain target question-answer pairs related to the sample corpus text.

[0012] In some embodiments, constructing an instruction dataset based on the target question-answer pairs includes: filtering the target question-answer pairs according to preset filtering rules, wherein the filtering rules include keyword filtering and length filtering of question-answer pairs; calculating the similarity between the filtered target question-answer pairs; merging the target question-answer pairs with a similarity greater than a preset similarity threshold to obtain the instruction dataset.

[0013] In some embodiments, calculating the similarity between the filtered target question-answer pairs and merging the target question-answer pairs with a similarity greater than a preset similarity threshold to obtain the instruction dataset includes: encoding the question text and answer text of the filtered target question-answer pairs into question-answer semantic vectors based on a pre-trained semantic representation model; calculating the similarity between the question-answer semantic vectors; and merging the target question-answer pairs with a similarity greater than a preset similarity threshold to obtain the instruction dataset.

[0014] To achieve the above objectives, a second aspect of this application proposes an instruction dataset construction apparatus, comprising: a sample acquisition module, configured to acquire sample corpus text and the names of multiple nested background levels in which the sample corpus text is located; a prompt template module, configured to acquire a preset prompt template, use the multiple level names as keywords, and sequentially fill multiple empty spaces in the prompt template according to the order of the corresponding background levels to generate a first prompt text; a question-answer pair module, configured to generate target prompt text based on the first prompt text and the sample corpus text, and input the target prompt text into a preset large language model to obtain target question-answer pairs related to the sample corpus text; and a dataset module, configured to construct an instruction dataset based on the target question-answer pairs.

[0015] To achieve the above objectives, a third aspect of this application provides an electronic device, which includes a memory and a processor. The memory stores a computer program, and the processor executes the computer program to implement the method described in the first aspect of the embodiment.

[0016] To achieve the above objectives, a fourth aspect of the present application provides a storage medium, which is a computer-readable storage medium storing a computer program that, when executed by a processor, implements the method described in the first aspect of the present application.

[0017] The instruction dataset construction method, apparatus, electronic device, and storage medium proposed in this application have the following beneficial effects: First, they acquire sample corpus text and the names of multiple nested background levels within the sample corpus text. These nested level names can fully reflect the contextual theme of the sample corpus text to varying degrees of generalization and specificity. Second, they acquire a preset prompt template, using multiple level names as keywords, and sequentially filling multiple empty spaces in the prompt template according to the corresponding background level order to generate a first prompt text. This is suitable for corpora with structural information, generating a more informative and adaptable first prompt text that better helps in understanding the meaning of the sample corpus text and the needs for generating instructions, thus improving the comprehensibility of the prompt text. Third, they generate target prompt text based on the first prompt text and the sample corpus text, and input the target prompt text into a preset large language model to obtain target question-answer pairs related to the sample corpus text. The obtained target question-answer pairs can more accurately capture the characteristics of the sample corpus text, improving the quality of the generated target question-answer pairs. Constructing an instruction dataset based on these target question-answer pairs can improve the quality of the constructed instruction dataset. Attached Figure Description

[0018] Figure 1 This is a flowchart of the instruction dataset construction method provided in the embodiments of this application;

[0019] Figure 2 yes Figure 1 Flowchart for step 102;

[0020] Figure 3 yes Figure 2 The flowchart for step 201 in the document;

[0021] Figure 4 yes Figure 1 Flowchart of step 101;

[0022] Figure 5 yes Figure 1 Another flowchart for step 102;

[0023] Figure 6 yes Figure 1 Flowchart for step 103;

[0024] Figure 7 yes Figure 1 Another flowchart for step 103;

[0025] Figure 8 This is a schematic diagram of the text summary and target prompt text provided in the embodiments of this application;

[0026] Figure 9 yes Figure 1 Flowchart for step 104;

[0027] Figure 10 yes Figure 9 Flowchart for step 802;

[0028] Figure 11 This is a schematic diagram of the instruction dataset construction method provided in the embodiments of this application;

[0029] Figure 12 This is a flowchart of the data loader provided in the embodiments of this application;

[0030] Figure 13 This is a schematic diagram of the functional modules of the instruction dataset construction device provided in the embodiments of this application;

[0031] Figure 14 This is a schematic diagram of the hardware structure of the electronic device provided in the embodiments of this application. Detailed Implementation

[0032] To make the objectives, technical solutions, and advantages of this application clearer, the following detailed description is provided in conjunction with the accompanying drawings and embodiments. It should be understood that the specific embodiments described herein are merely illustrative and not intended to limit the scope of this application.

[0033] It should be noted that although functional modules are divided in the device schematic diagram and the logical order is shown in the flowchart, in some cases, the steps shown or described may be performed in a different order than the module division in the device or the order in the flowchart.

[0034] Unless otherwise defined, all technical and scientific terms used herein have the same meaning as commonly understood by one of ordinary skill in the art to which this application belongs. The terminology used herein is for the purpose of describing embodiments of this application only and is not intended to limit this application.

[0035] Instruction datasets are an important data resource used in the training and fine-tuning of large language models, thereby improving the general dialogue capabilities of these models. Instruction datasets include instructions or tasks with clear objectives and structures, which can be used in question-and-answer application scenarios.

[0036] In the training and fine-tuning of modern large language models, instruction datasets provide task-specific and domain-specific knowledge for fine-tuning, thereby improving the general dialogue capabilities of large models. There are generally two main approaches to constructing high-quality instruction datasets: manual annotation and methods based on formatted raw datasets. While these methods have achieved success in some aspects, they also have challenges and limitations. Manual annotation is a traditional method for generating high-quality instruction data, but it requires significant human and time resources, limiting the scale and diversity of the data. Methods based on formatted raw datasets use fixed templates and placeholders, which may result in generated instructions that are either too specific or too general in some cases, making it difficult to adapt to the diversity of various input samples. Furthermore, automatically applying and replacing templates can lead to grammatical errors, awkward phrasing, or ambiguity in the generated instructions. The process of generating instructions relies on text samples from the original dataset; if the original data has problems, such as noise, errors, or inconsistent annotations, these issues may be passed on to the generated instruction dataset, affecting its quality and reliability.

[0037] In related technologies, constructing instruction datasets relies on formatting existing raw datasets, which can easily transfer problems from the raw data to the generated instruction datasets. Furthermore, fixed templates cannot adapt to diverse raw datasets, resulting in generated instructions that are either too specific or too general, thus reducing the quality of the instruction dataset.

[0038] Based on this, embodiments of this application provide a method, apparatus, electronic device, and storage medium for constructing an instruction dataset, which can improve the quality of the constructed instruction dataset.

[0039] The instruction dataset construction method, apparatus, electronic device, and storage medium provided in this application are specifically described through the following embodiments. First, the instruction dataset construction method in this application is described. The instruction dataset construction method in this application can be described through the following embodiments.

[0040] Figure 1 This is an optional flowchart of the instruction dataset construction method provided in the embodiments of this application. Figure 1 The method may include, but is not limited to, steps 101 to 104.

[0041] Step 101: Obtain the sample text and the names of the multiple nested background levels in which the sample text is located.

[0042] Understandably, sample corpus text refers to raw text data, such as paragraphs and sentences, encompassing various text types, such as news articles, dialogue transcripts, and expository texts. Background levels refer to the various contextual information or knowledge background within the sample corpus text. These background levels are nested, meaning one level is contained within another broader level. For example, an article may belong to the field of "technology," which in turn belongs to the larger field of "knowledge," thus forming nested background levels.

[0043] For example, the names of the sample corpus text and the multiple nested background levels in which the sample corpus text is located are shown in Table 1. The sample corpus text is located in four nested background levels, and the names of the levels in ascending order are "Specific Aspect Name", "Aspect Name", "Topic Name", and "Domain Name".

[0044]

[0045] Table 1. Examples of sample texts and their nested background levels.

[0046] For example, sample texts and the names of multiple nested background levels within a knowledge forest-type raw corpus can be obtained. This type of corpus has a structured organization that closely links text content with its domain, topic, knowledge points, and other contextual information, thus forming a "knowledge forest" structure. This corpus format is suitable for training and evaluating natural language processing models, providing them with rich background knowledge to help them better understand the text and generate relevant content.

[0047] Understandably, knowledge forest corpora, as high-quality raw data, can provide quality assurance for subsequent applications such as generation and training. Knowledge forest corpora are considered high-quality because they encompass a wide range of topics and domains, from encyclopedias to literary works, offering extensive coverage. Furthermore, these corpora contain a large amount of authentic, natural language expression, covering various styles and tones, which helps models learn more natural and vivid language use. Knowledge forest corpora possess numerous advantages, including broad topic coverage, rich language expression, large data volume, reliable quality control, and diversity, and are widely regarded as high-quality corpora for training natural language processing models. These characteristics enable them to play a crucial role in many downstream tasks.

[0048] For example, one can obtain the sample corpus text and the names of the multiple nested background levels in which the sample corpus text resides. Alternatively, one can perform semantic analysis and other processing on unstructured general knowledge corpora to extract key information from the general knowledge corpora as nested background levels. For instance, for general knowledge corpora in a specific domain, one can also search for relevant domain classification systems and use the classification levels corresponding to the general knowledge corpora as nested background levels.

[0049] Step 102: Obtain the preset prompt template, use multiple level names as keywords, and fill them into multiple empty spaces in the prompt template in the order of the corresponding background levels to generate the first prompt text.

[0050] Understandably, the preset prompt templates refer to standardized prompts or guidance provided to the large language model when interacting with it, thereby guiding the model to complete tasks. These templates can include information such as task descriptions, input content, and expected output format. For example, different prompt templates can be used, such as imperative statements ("Write an article about [content]") or question-and-answer formats ("Based on the following background information, answer the question: [background information]. The question is: [question]?").

[0051] For example, multiple level names are used as keywords and sequentially filled into multiple empty spaces in the prompt template according to the corresponding background level order to generate the first prompt text. That is, the empty spaces or placeholders in the prompt template are filled with level names according to the background level order. For example, the first prompt text generated from the sample corpus text shown in Table 1 is: "Please combine keywords such as "high school cell", "cell structure", "organelles", and "cell composition" to extract question-answer pairs from the text."

[0052] Step 103: Generate target prompt text based on the first prompt text and the sample corpus text, and input the target prompt text into the preset large language model to obtain target question-answer pairs related to the sample corpus text.

[0053] Understandably, a large language model refers to a pre-trained language model based on deep learning. It possesses a large number of parameters and training data, enabling it to learn rich linguistic knowledge and general semantic understanding capabilities from vast amounts of text data. It performs exceptionally well on multiple natural language tasks, including text generation, question answering, and sentiment analysis. Large language models can be applied to question answering systems to build high-quality question-answer pairs or to answer user questions.

[0054] Understandably, the target question-answer pair consists of a question and its answer related to the sample corpus text. Target prompt text is generated based on the first prompt text and the sample corpus text. The target prompt text includes the sample corpus text to be processed and the first prompt text matching the sample corpus text. The target prompt text is then input into a pre-defined large language model to obtain the target question-answer pair related to the sample corpus text.

[0055] For example, the first prompt text is: "Please extract question-and-answer pairs from the text by combining keywords such as 'high school cell,' 'cell structure,' 'organelles,' and 'cell composition.'" The sample corpus text is: "The cell is the basic structural and functional unit of an organism. The cell is composed of many different organelles, each responsible for specific life activities. For example, the nucleus is the cell's 'command center,' controlling the cell's genetic information and cell division; mitochondria are the cell's 'power plant,' responsible for the cell's energy metabolism; and the endoplasmic reticulum is the cell's 'transport system,' responsible for protein synthesis and transport. The coordinated work of these organelles maintains the cell's life activities. Only by mastering the basic structure of the cell and the functions of its components can we better understand the mysteries of life phenomena." Inputting the target prompt text into a preset large language model yields target question-and-answer pairs related to the sample corpus text. The question in the target question-and-answer pair is: "What organelles make up the inside of a cell?" The answer to the target question-and-answer pair is: "The organelles inside a cell include the nucleus, mitochondria, and endoplasmic reticulum. The nucleus is the cell's command center, mitochondria are responsible for the cell's energy metabolism, and the endoplasmic reticulum is responsible for protein synthesis and transport."

[0056] Step 104: Construct an instruction dataset based on the target question-answer pair.

[0057] Understandably, an instruction dataset is a special type of dataset used to train artificial intelligence models capable of executing various instructions and tasks. It contains a large number of question-answer pairs and their corresponding execution instructions. Building an instruction dataset can be used to train general-purpose AI assistants or dialogue systems that can understand and execute multiple instructions, thereby improving the model's language understanding, task execution capabilities, and flexibility.

[0058] For example, a large number of high-quality target question-answer pairs are generated through a large language model. These target question-answer pairs cover various topics and scenarios. For each target question-answer pair, corresponding execution instructions are written, which describe how to complete the task. Each target question-answer pair and its corresponding execution instructions are organized into a unified dataset format to construct an instruction dataset.

[0059] For example, the target question-and-answer pairs generated by the large language model can be deduplicated for each sample text input. Text comparison can then be performed on the corresponding target question-and-answer pairs to identify duplicate or highly similar content. Text similarity calculation methods, such as cosine similarity and edit distance, can be used to deduplicate the target question-and-answer pairs, avoiding excessively similar pairs generated from the same sample text. Alternatively, the target question-and-answer pairs after individual deduplication of all sample texts can be deduplicated as a whole, effectively optimizing the target question-and-answer pairs generated by the large language model and improving their quality and informational value.

[0060] Through steps 101 to 104 above, sample corpus text and the names of multiple nested background levels in which the sample corpus text is located are obtained. The nested level names can fully reflect the contextual theme of the sample corpus text to a generalized or specific degree. A preset prompt template is obtained, and multiple level names are used as keywords and filled into multiple empty spaces in the prompt template in the order of the corresponding background levels to generate the first prompt text. This is suitable for corpora with structural information and generates a more informative and adaptable first prompt text, which can better help understand the meaning of the sample corpus text and the needs of generating instructions, thus improving the comprehensibility of the prompt text. Target prompt text is generated based on the first prompt text and the sample corpus text, and the target prompt text is input into a preset large language model to obtain target question-answer pairs related to the sample corpus text. The obtained target question-answer pairs can more accurately capture the characteristics of the sample corpus text, improving the quality of the generated target question-answer pairs. An instruction dataset is constructed based on the target question-answer pairs, which can improve the quality of the constructed instruction dataset.

[0061] See Figure 2 In some embodiments, step 102 may include steps 201 to 202:

[0062] Step 201: Construct nested layer key-value pairs based on the sample corpus text and the layer names of the multiple nested background layers in which the sample corpus text is located.

[0063] The layer key-value pairs include multiple title keys constructed based on the layer name.

[0064] Understandably, a layered key-value pair refers to a structure composed of multiple nested key-value pairs. A key-value pair is a structure consisting of a key and a value. For example, a k-level nested layered key-value pair can be represented as item = {key1: {key2: {key3: ... {key...}}. k :value}}}}, where the layer key-value pairs include multiple title keys key1, key2, key3... key constructed based on the layer name. k , value is the value.

[0065] Step 202: Obtain the preset prompt template, and fill the multiple empty spaces in the prompt template with the title keys of the nested layer key-value pairs in sequence to generate the first prompt text.

[0066] Understandably, the title key order of the nested layer key-value pairs constructed from the sample corpus text shown in Table 1 is "Senior High Biology", "Cell Structure", "Organisms", and "Cell Composition". The title key order of the nested layer key-value pairs is sequentially filled into multiple empty spaces in the prompt template or the placeholders in the prompt template are replaced to generate the first prompt text, such as "Please combine the keywords "Senior High Cell", "Cell Structure", "Organisms", and "Cell Composition" to extract the question-answer pair from the text.

[0067] Through steps 201 to 202 above, nested layer key-value pairs are constructed based on the sample corpus text and the layer names of the multiple nested background layers in which the sample corpus text is located. A preset prompt template is obtained, and the title keys of the nested layer key-value pairs are sequentially filled into multiple empty spaces in the prompt template to generate the first prompt text. The sample corpus text is arranged into a nested dictionary format in the form of key-value pairs, which can more clearly express its structured information. Filling the prompt template with the title keys in sequence to generate the first prompt text helps the large language model to better understand the sample corpus text and improves the quality of the generated target question-answer pairs.

[0068] participate Figure 3 In some embodiments, step 201 may include steps 301 to 302:

[0069] Step 301: Construct the first-level layer key-value pairs based on the first-level layer name and the text content of the sample corpus text.

[0070] In this structure, the title key of the first-level layer key-value pair includes the first-level layer name, and the value of the first-level layer key-value pair includes the text content of the sample corpus text. For example, the first-level layer name is key. k The first-level layer key-value pairs are the text content (value) of the sample corpus text. The first-level layer key-value pairs, item1 = {key...}, are constructed based on the first-level layer name and the text content of the sample corpus text. k :value}.

[0071] Step 302: Construct layer key-value pairs for the first level and above based on the layer names of the first level and above and the corresponding layer key-value pairs of the next level.

[0072] In this context, the title key of the layer key-value pairs at the first level and above includes the level name of the corresponding level, and the value includes the layer key-value pair of the next lower level. For example, the title key of the layer key-value pairs at the second level is `key`. k-1The value is a key-value pair of the first level, i.e., item2 = {key} k-1 :{key k :value}}.

[0073] For example, the sample text in Table 1 and the layer names of its multiple nested background layers construct nested layer key-value pairs as follows: {High School Biology: {Cell Structure: {Organisms: {Cell Composition: The cell is the basic structural and functional unit of an organism. The cell is composed of many different organelles, each responsible for specific life activities. For example, the nucleus is the cell's "command center," controlling the cell's genetic information and cell division; mitochondria are the cell's "power plant," responsible for the cell's energy metabolism; and the endoplasmic reticulum is the cell's "transport system," responsible for protein synthesis and transport. The coordinated work of these organelles maintains the cell's life activities. Only by mastering the basic structure of the cell and the functions of its components can we better understand the mysteries of life phenomena}}}}.

[0074] Through steps 301 to 302, first-level layer key-value pairs are constructed based on the first-level layer name and the text content of the sample corpus text. Based on the layer names above the first level and the corresponding next-level layer key-value pairs, layer key-value pairs above the first level are constructed, forming nested layer key-value pairs layer by layer, which better reflects the hierarchical structure and internal connections of knowledge in the sample corpus text.

[0075] See Figure 4 In some embodiments, step 101 may include steps 401 to 402:

[0076] Step 401: Obtain the initial corpus text and extract multiple nested semantic keywords corresponding to the text content in the initial corpus text based on the pre-trained semantic analysis model.

[0077] Step 402: Obtain sample corpus text based on the text content of the initial corpus text, and obtain the level names of the multiple nested background levels in which the sample corpus text is located based on multiple nested semantic keywords.

[0078] It is understandable that semantic analysis models refer to machine learning models that can extract semantic information from text, such as pre-trained models like BERT and GPT. Semantic analysis models can capture the semantic meaning and contextual relationships of words and phrases in the initial corpus text, identify keywords, discover hidden connections between words, extract the theme and intent of the initial corpus text, and obtain nested semantic keywords.

[0079] For example, the initial corpus text refers to relevant text data in text format, unstructured data existing in text form. For a news article about artificial intelligence, the semantic analysis model can extract multi-layered nested semantic keywords such as "artificial intelligence," "machine learning," and "deep learning," reflecting the article's theme and key content, providing valuable structured information for subsequent text processing and analysis. Based on these nested semantic keywords, the hierarchical names of the multiple nested background levels of the sample corpus text are obtained; that is, the nested semantic keywords are used as hierarchical names.

[0080] Steps 401 to 402 extract keywords from the initial corpus text based on the pre-trained semantic analysis model. Based on multiple nested semantic keywords, the hierarchical names of multiple nested background levels of the sample corpus text are obtained. The unstructured initial corpus problem is constructed into structured information with hierarchical names of multiple nested background levels through the extracted semantic keywords, thereby improving the applicability of the instruction dataset construction method.

[0081] See Figure 5 In some embodiments, step 102 may include steps 501 to 502:

[0082] Step 501: Obtain the preset prompt template, use multiple level names as keywords, and fill them into multiple empty spaces in the prompt template in the order of the corresponding background levels.

[0083] Step 502: Determine the number of prompts to be output based on the number of sentences and sentence length in the sample corpus text, and generate the first prompt text.

[0084] Understandably, the sample corpus text can include multiple sentences. The design of the prompt template and the number of prompts output can be determined based on specific application scenarios and needs, which can significantly improve the quality and relevance of text generation. The number of target question-answer pairs generated can be determined based on the complexity of the sample corpus text, i.e., the number and length of sentences.

[0085] For example, text processing tools can be used to analyze the sample corpus text. If the sample corpus text is relatively simple, with few sentences or short sentence lengths, a smaller number of prompts can be determined. Conversely, if the sample corpus text is relatively complex, with many sentences or long sentence lengths, a larger number of prompts can be determined. Determining the number of prompts based on the number and length of sentences in the sample corpus text ensures that the number of target question-answer pairs matches the complexity of the sample corpus text, thereby providing better support for the subsequent generation of target prompt texts and question-answer pairs.

[0086] Steps 501 to 502 are used to obtain a preset prompt template. Multiple level names are used as keywords and are filled into multiple empty spaces in the prompt template in the order of the corresponding background levels. The number of prompt outputs is determined according to the number and length of sentences in the sample corpus text. The first prompt text is generated, which can ensure that the number of target question-answer pairs generated matches the complexity of the sample corpus text and provides more information for the generation of target question-answer pairs.

[0087] See Figure 6 In some embodiments, step 103 may include steps 601 to 602:

[0088] Step 601: Generate target prompt text based on the first prompt text and the sample corpus text, and input the target prompt text into the preset large language model.

[0089] Step 602: Based on the preset large language model, extract the target question-answer pairs with the corresponding number of prompt outputs from the sample corpus text according to the target prompt text.

[0090] Understandably, based on the initial prompt text and the original sample corpus text, a target prompt text is generated. This target prompt text can more specifically reflect the content and background of the sample corpus. Then, the generated target prompt text is input into a pre-set large language model for processing. This large language model is a pre-trained model capable of outputting corresponding question-answer pairs based on the input prompt text. The large language model extracts a corresponding number of target question-answer pairs from the sample corpus text based on the content of the target prompt text. The number of these target question-answer pairs is consistent with the number of prompts output based on the number of sentences in the sample corpus text.

[0091] For example, consider a sample text about the "Winter Olympics," which contains rich background information such as event dates and locations, participating countries, and major events. First, obtain the sample text and extract the various levels of background information. Next, using a pre-defined prompt template, fill in this background information in an orderly manner to generate the first prompt text. Then, based on the complexity of the sample text, determine the number of prompt outputs to be 5. These first prompt texts can then be combined with the original sample text to generate more targeted target prompt texts. These target prompt texts are then input into a pre-trained large language model to extract 5 corresponding high-quality target question-answer pairs from the sample text, serving as the instruction dataset. This construction process yields a highly targeted and broadly covered instruction dataset, providing excellent training resources for subsequent natural language processing tasks.

[0092] Through steps 601 to 602 above, based on the preset large language model, the target question-answer pairs corresponding to the number of prompts are extracted from the sample corpus text according to the target prompt text. Based on the input target prompt text, a corresponding number of high-quality target question-answer pairs can be extracted from the sample corpus text, ensuring that the number of generated target question-answer pairs matches the complexity of the sample corpus text, and avoiding too many or too few target question-answer pairs.

[0093] participate Figure 7 In some embodiments, step 103 may include steps 701 to 702:

[0094] Step 701: Obtain the text summary corresponding to the sample corpus text, and generate the target prompt text based on the first prompt text and the sample corpus text.

[0095] Step 702: Input the target prompt text and text summary into the preset large language model to obtain target question-answer pairs related to the sample corpus text.

[0096] Understandably, the text summary is a high-level generalization and summary of the content of the sample corpus text, which can provide the key information of the article. Then, combined with the generated first prompt text and the original sample corpus text, a more targeted target prompt text is generated.

[0097] Understandably, the target prompt text can focus more on the core content of the sample corpus text. Then, the target prompt text and the text summary of the sample corpus text are input together into a pre-set large language model for processing. The large language model will extract a series of related target question-answer pairs from the sample corpus text based on these inputs. The target question-answer pairs can better reflect the core content and key information of the sample corpus text.

[0098] Through steps 701 to 702 above, combined with the text summary corresponding to the sample corpus text, the target prompt text and the text summary are input into the preset large language model. The text summary provides information that summarizes and concludes the main points, which can better help the large language model understand the sample corpus text and extract high-quality target question-answer pairs.

[0099] See Figure 8 For example, the text summary of the sample corpus text shown in Table 1 is: "This is a list of knowledge points for primary and secondary schools compiled by school teachers." The first prompt text is: "Please extract a question-and-answer pair from the text by combining keywords such as 'high school cell,' 'cell structure,' 'organelles,' and 'cell composition.'" This prompt text, combined with the sample corpus text, forms the target prompt text, which is then input into the preset large language model along with the text summary.

[0100] See Figure 9In some embodiments, step 104 may include steps 801 to 802:

[0101] Step 801: Filter the target question-answer pairs according to preset filtering rules, including keyword filtering and length filtering.

[0102] Understandably, keyword filtering can involve checking the question and answer parts of the target question-and-answer pair for keywords, removing irrelevant or noisy pairs, or requiring answers to include keywords such as "question" or "answer." Length filtering can involve setting minimum and maximum length thresholds for target question-and-answer pairs to remove those with unreasonable lengths. Through such filtering processes, the quality of the generated target question-and-answer pairs can be further improved by removing low-quality or irrelevant samples.

[0103] For example, keyword filtering can be implemented based on a pre-established keyword dictionary. This dictionary contains common low-quality or noisy words, such as meaningless proper nouns, non-standard words, and spam. When processing each target question-and-answer pair, the question and answer parts can be segmented first, and then the segmentation results can be checked for keywords from the dictionary. If they are found, the question-and-answer pair is marked as needing filtering. In addition to filtering words from the keyword dictionary, a list of required keywords can also be created. Furthermore, when processing each target question-and-answer pair, it's necessary not only to check for exclusionary keywords in the question and answer but also to ensure that at least the specified required words are included. These required words can be core concept words related to the target task or domain. If neither the question nor the answer part of the target question-and-answer pair contains any required words, it is marked as needing filtering. In practical applications, both exclusionary keyword filtering and required word filtering can be used simultaneously. That is, the target question-and-answer pair must not contain exclusionary keywords, but it must also contain the specified required words. Only when both conditions are met can the target question-and-answer pair pass the keyword filtering stage and enter the subsequent processing flow.

[0104] Step 802: Calculate the similarity between the filtered target question-answer pairs, merge the target question-answer pairs with similarity greater than the preset similarity threshold, and obtain the instruction dataset.

[0105] Understandably, calculating the similarity between each target question-and-answer pair can employ text similarity calculation algorithms, such as cosine similarity and Euclidean distance. Then, a similarity threshold is set, and target question-and-answer pairs with similarity higher than this threshold are merged into one target question-and-answer pair to form the final instruction dataset. The purpose of this is to remove duplicates and refine the target question-and-answer pairs, ensuring that the final instruction dataset is more refined and of higher quality, and avoiding a large number of redundant or duplicate samples.

[0106] For example, the target question-and-answer pairs for each sample text can be deduplicated individually, and then all target question-and-answer pairs after individual deduplication can be deduplicated as a whole. Clustering algorithms (such as K-Means, DBSCAN, etc.) can be used to identify semantically similar target question-and-answer pairs. One or several representative target question-and-answer pairs can be retained from each clustering result, and redundant content can be removed. The two-step deduplication method can effectively avoid redundancy between target question-and-answer pairs generated from the same sample text, and can also eliminate duplicate content in the overall result, thereby improving the diversity and coverage of the result.

[0107] For example, the question length can be set between 5 and 50 characters, and the answer length between 10 and 100 characters. This ensures that the length of the target question-answer pair is neither too short nor too long, maintaining a certain degree of reasonableness. In actual processing, the question length and answer length of each target question-answer pair can be counted separately. If either part exceeds the preset range, the target question-answer pair is marked as needing to be filtered.

[0108] Through steps 801 to 802 above, the target question-answer pairs are filtered according to preset filtering rules, including question-answer pair keyword filtering and question-answer pair length filtering. The similarity between the filtered target question-answer pairs is calculated, and target question-answer pairs with similarity greater than the preset similarity threshold are merged. After filtering and deduplication, a higher quality instruction dataset is obtained.

[0109] See Figure 10 In some embodiments, step 802 may include steps 901 to 902:

[0110] Step 901: Based on the pre-trained semantic representation model, the question text and answer text of the filtered target question-answer pair are encoded into question-answer semantic vectors.

[0111] Understandably, pre-trained semantic representation models can convert text into dense semantic vectors, effectively capturing the semantic features of the text. Common semantic representation models include Word2Vec, GloVe, BERT, and Sentence-BERT. By encoding questions and answers into vectors, a semantic vector representation of each question-answer pair is obtained. In other words, the question text and answer text of the target question-answer pair are encoded into question-answer semantic vectors to facilitate subsequent similarity calculations.

[0112] Step 902: Calculate the similarity between question and answer semantic vectors, merge target question and answer pairs with similarity greater than a preset similarity threshold, and obtain the instruction dataset.

[0113] Understandably, the similarity between the question and answer semantic vectors of each question-answer pair can be calculated using cosine similarity, Euclidean distance, or Pearson correlation coefficient. After calculating the similarity, a similarity threshold is set. Any target question-answer pair with a similarity higher than this threshold is merged into a single target question-answer pair to form the final instruction dataset.

[0114] In some implementations, when merging highly similar question-and-answer pairs, it is also necessary to consider the difference in importance between the question text and the answer text. The question text contains the core requirements of the task and is the key part of the entire question-and-answer pair, while the answer text is a response to and supplement to the question text. Therefore, when calculating the similarity of the entire question-and-answer pair, a higher weight can be assigned to the similarity of the question text. For example, the similarity of the question text can account for 70% of the total similarity of the question-and-answer pair, while the similarity of the answer text can account for 30%, which can ensure that the importance of the question is reflected.

[0115] Through steps 901 to 902 above, the question text and answer text of the filtered target question-answer pair are encoded into question-answer semantic vectors based on the pre-trained semantic representation model. The similarity between the question-answer semantic vectors is calculated, and duplicate or similar question-answer pairs are eliminated, resulting in a higher quality and more refined instruction dataset, which better meets the needs of subsequent natural language processing tasks.

[0116] Please see Figure 11 , Figure 11This is a schematic diagram of the instruction dataset construction method provided in this application embodiment. The method involves preprocessing structured knowledge-based corpora to obtain dictionary-formatted sample corpus text and the names of its multiple nested background levels. A data loader reads the sample corpus text and its level names, combines them with a text summary and a preset prompt template, uses multiple level names as keywords, and sequentially fills multiple empty spaces in the prompt template according to the corresponding background level order to generate target prompt text. This target prompt text is then used as input to a large language model. The large language model generates target question-and-answer pairs based on the target prompt text and the sample corpus text. The target question-and-answer pairs are then validated, filtered, and saved. The system checks whether the sample corpus text has been processed completely; if not, the data loader continues loading the remaining sample corpus text. Once processing is complete, all obtained target question-and-answer pairs are deduplicated to obtain the instruction dataset. Please refer to [link to relevant documentation]. Figure 12 , Figure 12 This is a flowchart of the data loader provided in the embodiment of this application. First, the loader is initialized, and the sample corpus text and its level name are loaded from the initial position. After processing the data to obtain the target question-answer pair, the detection point of the current data is saved, and the loading is checked to see if it is complete. If it is not complete, the loading is returned to the detection point position to continue loading and processing until all sample corpus texts have been processed.

[0117] Please see Figure 13 This application also provides an instruction dataset construction apparatus that can implement the above-described instruction dataset construction method. The instruction dataset construction apparatus includes: a sample acquisition module, used to acquire sample corpus text and the names of multiple nested background levels in which the sample corpus text is located; a prompt template module, used to acquire a preset prompt template, use multiple level names as keywords, and fill them into multiple empty spaces in the prompt template in the order of the corresponding background levels to generate a first prompt text; a question-answer pair module, used to generate target prompt text based on the first prompt text and the sample corpus text, and input the target prompt text into a preset large language model to obtain target question-answer pairs related to the sample corpus text; and a dataset module, used to construct an instruction dataset based on the target question-answer pairs.

[0118] The specific implementation of the instruction dataset construction device is basically the same as the specific embodiment of the instruction dataset construction method described above, and will not be repeated here. Subject to meeting the requirements of the embodiments of this application, the instruction dataset construction device may also be equipped with other functional modules to implement the instruction dataset construction method in the above embodiments.

[0119] This application also provides an electronic device, which includes a memory and a processor. The memory stores a computer program, and the processor executes the computer program to implement the above-described instruction dataset construction method. This electronic device can be any smart terminal, including tablet computers, in-vehicle computers, etc.

[0120] Please see Figure 14 , Figure 14 The hardware structure of an electronic device according to another embodiment is illustrated. The electronic device includes:

[0121] The processor 1401 can be implemented using a general-purpose CPU (Central Processing Unit), microprocessor, application-specific integrated circuit (ASIC), or one or more integrated circuits, and is used to execute relevant programs to implement the technical solutions provided in the embodiments of this application.

[0122] The memory 1402 can be implemented as a read-only memory (ROM), a static storage device, a dynamic storage device, or a random access memory (RAM). The memory 1402 can store the operating system and other applications. When the technical solutions provided in the embodiments of this specification are implemented through software or firmware, the relevant program code is stored in the memory 1402 and is called and executed by the processor 1401 to execute the instruction dataset construction method of the embodiments of this application.

[0123] The input / output interface 1403 is used to implement information input and output;

[0124] The communication interface 1404 is used to enable communication and interaction between this device and other devices. Communication can be achieved through wired means (such as USB, Ethernet cable, etc.) or wireless means (such as mobile network, WIFI, Bluetooth, etc.).

[0125] Bus 1405 transmits information between various components of the device (e.g., processor 1401, memory 1402, input / output interface 1403, and communication interface 1404);

[0126] The processor 1401, memory 1402, input / output interface 1403 and communication interface 1404 are connected to each other within the device via bus 1405.

[0127] This application also provides a computer-readable storage medium storing a computer program that, when executed by a processor, implements the above-described instruction dataset construction method.

[0128] Memory, as a non-transitory computer-readable storage medium, can be used to store non-transitory software programs and non-transitory computer-executable programs. Furthermore, memory may include high-speed random access memory, and may also include non-transitory memory, such as at least one disk storage device, flash memory device, or other non-transitory solid-state storage device. In some embodiments, memory may optionally include memory remotely located relative to the processor, and these remote memories can be connected to the processor via a network. Examples of such networks include, but are not limited to, the Internet, intranets, local area networks, mobile communication networks, and combinations thereof.

[0129] The embodiments described in this application are for the purpose of more clearly illustrating the technical solutions of the embodiments of this application, and do not constitute a limitation on the technical solutions provided by the embodiments of this application. As those skilled in the art will know, with the evolution of technology and the emergence of new application scenarios, the technical solutions provided by the embodiments of this application are also applicable to similar technical problems.

[0130] Those skilled in the art will understand that the technical solutions shown in the figures do not constitute a limitation on the embodiments of this application, and may include more or fewer steps than shown, or combine certain steps, or different steps.

[0131] The device embodiments described above are merely illustrative. The units described as separate components may or may not be physically separate; that is, they may be located in one place or distributed across multiple network units. Some or all of the modules can be selected to achieve the purpose of this embodiment according to actual needs.

[0132] Those skilled in the art will understand that all or some of the steps in the methods disclosed above, as well as the functional modules / units in the systems and devices, can be implemented as software, firmware, hardware, or suitable combinations thereof.

[0133] The terms “first,” “second,” “third,” “fourth,” etc. (if present) in the specification and accompanying drawings of this application are used to distinguish similar objects and are not necessarily used to describe a specific order or sequence. It should be understood that such data can be interchanged where appropriate so that the embodiments of this application described herein can be implemented in orders other than those illustrated or described herein. Furthermore, the terms “comprising” and “having,” and any variations thereof, are intended to cover non-exclusive inclusion; for example, a process, method, system, product, or apparatus that comprises a series of steps or units is not necessarily limited to those steps or units explicitly listed, but may include other steps or units not explicitly listed or inherent to such processes, methods, products, or apparatus.

[0134] It should be understood that in this application, "at least one" and "several" refer to one or more, and "multiple" refers to two or more. "And / or" describes the relationship between related objects, indicating that three relationships can exist. For example, "A and / or B" can represent three cases: only A exists, only B exists, and both A and B exist simultaneously, where A and B can be singular or plural. The character " / " generally indicates that the preceding and following related objects are in an "or" relationship. "At least one of the following" or similar expressions refer to any combination of these items, including any combination of single or plural items. For example, at least one of a, b, or c can represent: a, b, c, "a and b", "a and c", "b and c", or "a and b and c", where a, b, and c can be single or multiple.

[0135] In the embodiments provided in this application, it should be understood that the disclosed systems and methods can be implemented in other ways. For example, the system embodiments described above are merely illustrative; for instance, the division of the units described above is only a logical functional division, and in actual implementation, there may be other division methods. For example, multiple units or components may be combined or integrated into another system, or some features may be ignored or not executed. The couplings or direct couplings or communication connections shown or discussed may be indirect couplings or communication connections through some interfaces, devices, or units, and may be electrical, mechanical, or other forms.

[0136] The units described above as separate components may or may not be physically separate. The components shown as units may or may not be physical units; that is, they may be located in one place or distributed across multiple network units. Some or all of the units can be selected to achieve the purpose of this embodiment according to actual needs.

[0137] Furthermore, the functional units in the various embodiments of this application can be integrated into one processing unit, or each unit can exist physically separately, or two or more units can be integrated into one unit. The integrated unit can be implemented in hardware or as a software functional unit.

[0138] If the integrated unit is implemented as a software functional unit and sold or used as an independent product, it can be stored in a computer-readable storage medium. Based on this understanding, the technical solution of this application, in essence, or the part that contributes to the prior art, or all or part of the technical solution, can be embodied in the form of a software product. This computer software product is stored in a storage medium and includes multiple instructions to cause a computer device (which may be a personal computer, server, or network device, etc.) to execute all or part of the steps of the methods of the various embodiments of this application. The aforementioned storage medium includes various media capable of storing programs, such as USB flash drives, portable hard drives, read-only memory (ROM), random access memory (RAM), magnetic disks, or optical disks.

[0139] The preferred embodiments of the present application have been described above with reference to the accompanying drawings, but this does not limit the scope of the claims of the present application. Any modifications, equivalent substitutions, and improvements made by those skilled in the art without departing from the scope and substance of the embodiments of the present application shall be within the scope of the claims of the present application.

Claims

1. A method for constructing an instruction dataset, characterized in that, include: Obtain the sample text and the names of the multiple nested background levels in which the sample text is located; Obtain a preset prompt template, use multiple level names as keywords, and fill them into multiple empty spaces in the prompt template in the order of the corresponding background levels to generate the first prompt text; Target prompt text is generated based on the first prompt text and the sample corpus text, and the target prompt text is input into a preset large language model to obtain target question-answer pairs related to the sample corpus text; Construct an instruction dataset based on the target question-answer pairs; The step of obtaining a preset prompt template, using multiple level names as keywords, and sequentially filling them into multiple empty spaces in the prompt template according to the corresponding background level order to generate the first prompt text includes: Nested layer key-value pairs are constructed based on the sample corpus text and the layer names of the multiple nested background layers in which the sample corpus text is located, wherein the layer key-value pairs include multiple title keys constructed based on the layer names; Obtain a preset prompt template, and fill the title key into multiple empty spaces in the prompt template in the order of the nested layer key-value pairs to generate the first prompt text.

2. The method for constructing an instruction dataset according to claim 1, characterized in that, The step of constructing nested layer key-value pairs based on the sample corpus text and the layer names of the multiple nested background layers in which the sample corpus text is located includes: A first-level layer key-value pair is constructed based on the layer name of the first level and the text content of the sample corpus text, wherein the title key of the first-level layer key-value pair includes the layer name of the first level, and the value of the first-level layer key-value pair includes the text content of the sample corpus text. Based on the level name of the first level and above and the corresponding level key-value pair, construct the level key-value pair of the first level and above, wherein the title key of the level key-value pair of the first level and above includes the level name of the corresponding level, and the value includes the level key-value pair of the corresponding level.

3. The method for constructing an instruction dataset according to claim 1, characterized in that, The acquisition of sample text corpus, and the hierarchical names of the multiple nested background levels in which the sample text corpus is located, includes: Obtain the initial corpus text, and extract multiple nested semantic keywords corresponding to the text content in the initial corpus text based on a pre-trained semantic analysis model; Sample corpus text is obtained based on the text content of the initial corpus text, and the level name of the multiple nested background levels in which the sample corpus text is located is obtained based on the multiple nested semantic keywords.

4. The method for constructing an instruction dataset according to claim 1, characterized in that, The step of obtaining a preset prompt template, using multiple level names as keywords, and sequentially filling them into multiple empty spaces in the prompt template according to the corresponding background level order to generate the first prompt text includes: Obtain a preset prompt template, use multiple level names as keywords, and fill them into multiple empty spaces in the prompt template in the order of the corresponding background levels; The number of prompts to be output is determined based on the number of sentences and the sentence length of the sample corpus text, and the first prompt text is generated.

5. The method for constructing an instruction dataset according to claim 4, characterized in that, The step of generating target prompt text based on the first prompt text and the sample corpus text, and inputting the target prompt text into a preset large language model to obtain target question-answer pairs related to the sample corpus text includes: Generate a target prompt text based on the first prompt text and the sample corpus text, and input the target prompt text into a preset large language model; Based on the target prompt text, the preset large language model is used to extract the target question-answer pairs corresponding to the number of prompt outputs from the sample corpus text.

6. The method for constructing an instruction dataset according to claim 1, characterized in that, The step of generating target prompt text based on the first prompt text and the sample corpus text, and inputting the target prompt text into a preset large language model to obtain target question-answer pairs related to the sample corpus text includes: Obtain a brief description of the text corresponding to the sample corpus text, and generate a target prompt text based on the first prompt text and the sample corpus text; The target prompt text and the text summary are input into a preset large language model to obtain target question-answer pairs related to the sample corpus text.

7. The method for constructing an instruction dataset according to claim 1, characterized in that, The construction of the instruction dataset based on the target question-answer pair includes: The target question-and-answer pairs are filtered according to preset filtering rules, wherein the filtering rules include question-and-answer pair keyword filtering and question-and-answer pair length filtering. Calculate the similarity between the filtered target question-answer pairs, merge the target question-answer pairs with a similarity greater than a preset similarity threshold, and obtain the instruction dataset.

8. The method for constructing an instruction dataset according to claim 7, characterized in that, The similarity between the target question-answer pairs after filtering is calculated, and the target question-answer pairs with a similarity greater than a preset similarity threshold are merged to obtain the instruction dataset, including: The pre-trained semantic representation model encodes the question and answer texts of the filtered target question-answer pairs into question-answer semantic vectors. Calculate the similarity between the question-answer semantic vectors, merge the target question-answer pairs with a similarity greater than a preset similarity threshold, and obtain the instruction dataset.

9. An instruction dataset construction apparatus, characterized in that, include: The sample acquisition module is used to acquire sample text and the names of multiple nested background levels in which the sample text is located; The prompt template module is used to obtain a preset prompt template, use multiple level names as keywords, and fill them into multiple empty spaces in the prompt template according to the order of the corresponding background levels to generate first prompt text; obtaining the preset prompt template, using multiple level names as keywords, and filling them into multiple empty spaces in the prompt template according to the order of the corresponding background levels to generate first prompt text includes: constructing nested layer key-value pairs based on the sample corpus text and the level names of multiple nested background levels in which the sample corpus text is located, wherein the layer key-value pairs include multiple title keys constructed based on the level names; obtaining the preset prompt template, and filling the title keys into multiple empty spaces in the prompt template according to the order of the nested layer key-value pairs to generate first prompt text; The question-answering module is used to generate target prompt text based on the first prompt text and the sample corpus text, and input the target prompt text into a preset large language model to obtain target question-answering pairs related to the sample corpus text; The dataset module is used to construct an instruction dataset based on the target question-answer pair.

10. An electronic device, characterized in that, The electronic device includes a memory and a processor, the memory storing a computer program, and the processor executing the computer program to implement the instruction dataset construction method according to any one of claims 1 to 8.

11. A computer-readable storage medium storing a computer program, characterized in that, When the computer program is executed by the processor, it implements the instruction dataset construction method according to any one of claims 1 to 8.

Citation Information

Patent Citations

  • Method and device for generating high-quality question and answer data by using large language model

    CN117217315A

  • Text processing method and device, storage medium and electronic equipment

    CN117313719A