Sample construction method, apparatus and device, and large language model fine-tuning method
By extracting subgraphs from knowledge graphs and generating related questions and answers, the problem of low answer generation efficiency in logical reasoning scenarios of large language models is solved, achieving efficient and diverse sample construction and improving the model's logical reasoning ability.
Patent Information
- Application Number
- PCT/CN2024/129939
- Authority / Receiving Office
- WO · WO
- Patent Type
- Applications
- Current Assignee / Owner
- Priority Date
- 2024-07-30
- Filing Date
- 2024-11-05
- Publication Date
- 2026-02-05
AI Technical Summary
Large language models perform poorly in logical reasoning scenarios, making it difficult to efficiently generate answers that correspond to questions.
By extracting multiple subgraphs from the knowledge graph, converting them into natural language text, generating relevant questions and answers, constructing samples, and fine-tuning the parameters of a large language model.
It improves the efficiency and accuracy of answer generation for large language models in logical reasoning scenarios, reduces sample generation costs, and enhances diversity and logical reasoning capabilities.
Smart Images

Figure CN2024129939_05022026_PF_FP_ABST
Abstract
Description
Sample construction method, device and equipment and large language model fine-tuning method TECHNICAL FIELD
[0001] The present application relates to the technical field of natural language processing, and particularly relates to a sample construction method, device and equipment and a large language model fine-tuning method.
[0002] The present application claims priority to the Chinese patent application No. 202411035269.3, filed on July 30, 2024, and entitled "Sample construction method, device and equipment and large language model fine-tuning method", the whole content of which is incorporated herein by reference. BACKGROUND
[0003] At present, although a large language model can exhibit human-like language organization and expression ability, it still performs poorly in some slow thinking scenarios that require logical reasoning, and may appear the phenomenon that the obtained answer does not correspond to the question. In view of this problem, it is expected to fine-tune the large language model through a large amount of logical reasoning data, so that the large language model is familiar with the corresponding answer paradigm and stimulates the logical reasoning ability learned in a large amount of logical reasoning data. At this time, how to efficiently obtain logical reasoning data becomes the key to solving the problem. TECHNICAL PROBLEM
[0004] The sample construction method, device and equipment and large language model fine-tuning method provided by the embodiments of the present application can efficiently generate samples for fine-tuning the large language model.
[0005] Specifically, the present application is realized by the following technical solutions:
[0006] The first aspect of the present application provides a sample construction method, which comprises:
[0007] For each question type in a plurality of preset question types, a plurality of sub-graphs corresponding to the question type are obtained from a knowledge graph;
[0008] For each sub-graph, each group of triple data in each sub-graph is converted into natural language text to obtain a set of natural language texts corresponding to each sub-graph, and all groups of triple data of each sub-graph and the set of natural language texts corresponding to each sub-graph are spliced into reference content corresponding to each sub-graph;
[0009] According to the reference content corresponding to each sub-graph and the question type corresponding to each sub-graph, a question related to the reference content is generated;
[0010] According to the reference content corresponding to each sub-graph and the question related to the reference content, an answer to the question is generated;
[0011] A sample is constructed according to the question and the answer.
[0012] The second aspect of the present application provides a large language model fine-tuning method, the method comprising:
[0013] The sample is obtained by using any of the methods provided in the first aspect of the present application.
[0014] The parameters of the large language model are fine-tuned using the sample.
[0015] The third aspect of the present application provides a sample construction device, the device comprising an acquisition module, a conversion module, a generation module and a construction module; wherein,
[0016] The acquisition module is configured to acquire, for each of a plurality of preset question types, a plurality of subgraphs corresponding to the question type from a knowledge graph.
[0017] The conversion module is configured to convert each set of triple data in each subgraph into natural language text to obtain a set of natural language texts corresponding to each subgraph, and concatenate all sets of triple data of each subgraph and the set of natural language texts corresponding to each subgraph as reference content corresponding to each subgraph.
[0018] The generation module is configured to generate a question related to the reference content according to the reference content corresponding to each subgraph and the question type corresponding to each subgraph.
[0019] The generation module is configured to generate an answer to the question according to the reference content corresponding to each subgraph and the question related to the reference content.
[0020] The construction module is configured to construct a sample according to the question and the answer.
[0021] The fourth aspect of the present application provides a sample construction device, comprising a memory, a processor and a computer program stored on the memory and executable on the processor, wherein the processor executes the program to implement the steps of any of the methods provided in the first aspect of the present application.
[0022] The sample construction method, apparatus, device, and large language model acquisition method provided in this application obtain multiple subgraphs corresponding to each of the preset multiple question types from a knowledge graph. Then, for each subgraph, each set of triples is converted into natural language text, resulting in a natural language text set for each subgraph. All sets of triples from each subgraph and the corresponding natural language text set are concatenated to form reference content for each subgraph. Based on the reference content and the question type of each subgraph, a question related to that reference content is generated. Finally, an answer to that question is generated based on the reference content and the related question. A sample is then constructed based on the question and the answer. This method generates samples based on the rich structured and multi-hop information in the knowledge graph, achieving automatic sample generation, improving generation efficiency, and reducing generation costs. Furthermore, it enhances sample diversity by leveraging the diverse topics provided by the knowledge graph, thereby improving the logical reasoning ability of the fine-tuned large language model when facing diverse data. Attached Figure Description
[0023] Figure 1 is a flowchart of an embodiment of the sample construction method provided in this application;
[0024] Figure 2 is a flowchart of Embodiment 2 of the sample construction method provided in this application;
[0025] Figure 3 is a flowchart of Embodiment 3 of the sample construction method provided in this application;
[0026] Figure 4 is a flowchart of Embodiment 4 of the sample construction method provided in this application;
[0027] Figure 5 is a flowchart of Embodiment 5 of the sample construction method provided in this application;
[0028] Figure 6 is a hardware structure diagram of the sample construction device where the sample construction device provided in this application is located;
[0029] Figure 7 is a schematic diagram of the structure of the sample construction device according to Embodiment 1 provided in this application. Embodiments of the present invention
[0030] Exemplary embodiments will now be described in detail, examples of which are illustrated in the accompanying drawings. When the following description relates to the drawings, unless otherwise indicated, the same numbers in different drawings represent the same or similar elements. The embodiments described in the following exemplary embodiments do not represent all embodiments consistent with this application.
[0031] The terminology used in this application is for the purpose of describing particular embodiments only and is not intended to be limiting of the application. The singular forms “a,” “the,” and “the” used herein are also intended to include the plural forms unless the context clearly indicates otherwise. It should also be understood that the term “and / or” as used herein refers to and includes any and all possible combinations of one or more of the associated listed items.
[0032] It should be understood that although the terms first, second, third, etc., may be used in this application to describe various information, such information should not be limited to these terms. These terms are only used to distinguish information of the same type from one another. For example, without departing from the scope of this application, first information may also be referred to as second information, and similarly, second information may also be referred to as first information. Depending on the context, the word "if" as used herein may be interpreted as "when," "when," or "in response to determination."
[0033] The following specific embodiments are given to illustrate the technical solution of this application in detail.
[0034] Figure 1 is a flowchart of an embodiment of the sample construction method provided in this application. Referring to Figure 1, the method provided in this embodiment may include:
[0035] S101. For each of the preset multiple question types, obtain multiple subgraphs corresponding to the question type from the knowledge graph.
[0036] Specifically, the preset question types are set according to actual needs, and are not limited in this embodiment. For example, in one possible implementation, the preset question types may include multi-hop reasoning questions, attribute-to-attribute questions, different instance attribute comparison questions, and error pattern recognition questions.
[0037] Among them, multi-hop reasoning problems refer to problems that require multiple steps of reasoning and logical deduction to arrive at the answer; attribute-to-attribute problems refer to problems that require inferring one attribute from another known attribute; different instance attribute comparison problems refer to problems that require comparing and analyzing the attributes between different instances; and error pattern recognition problems refer to problems that require identifying and analyzing possible errors, logical contradictions, or inconsistencies in a given situation.
[0038] For example, question 1 is: please infer the relationship between Li Yuan and Li Zhi. Question 1 is a multi-hop reasoning type question. For example, question 2 is: what is the license plate number of an area whose telephone area code is A. Question 2 is an attribute-to-attribute type question. For example, question 3 is: which of Hangzhou and Shanghai has a larger area. Question 3 is a different instance attribute comparison type question. For example, question 4 is: analyze whether there is an error in experimental design or data analysis in the experimental report. Question 4 is an error pattern recognition type question.
[0039] Further, it can be understood that the knowledge graph is a structured data model for representing and organizing knowledge, which systematically expresses entities and relationships between entities in the form of a graph. It should be noted that the knowledge graph is composed of nodes (nodes represent entities) and edges (edges represent relationships between entities), and each node and edge has attribute information.
[0040] In a possible implementation, the knowledge graph can be directly obtained from the network or created by itself according to actual needs. In this embodiment, it is not limited.
[0041] In a specific implementation, for each question type in the preset plurality of question types, a target sampling rule corresponding to the question type can be obtained from the preset plurality of sampling rules, and then a subgraph corresponding to the question type can be obtained by collecting the subgraph from the knowledge graph according to the target sampling rule.
[0042] It should be noted that the sampling rules corresponding to different question types are different. The sampling rules corresponding to each question type are set according to actual needs, and are not limited in this embodiment.
[0043] For example, for a multi-hop reasoning type question, in a possible implementation, the corresponding sampling rule can be: randomly generate an integer as the actual number of hops within a set hop range, randomly select a node from the knowledge graph as a starting node, select a neighbor node to jump according to the randomly generated number of hops, and repeat the step of jumping until the randomly generated number of hops is reached. It should be noted that in each step of jumping, a node can be randomly selected from the neighbor nodes of the current node for jumping, and the neighbor nodes do not require the same attributes.
[0044] For example, for an attribute-to-attribute type question, in a possible implementation, the corresponding sampling rule can be: randomly select a node from the knowledge graph, and obtain the first-order domain of the node as the subgraph corresponding to the question type.
[0045] For example, in one possible implementation of a problem comparing attributes of different instances, the sampling rule is to select different nodes with the same attribute from the knowledge graph for sampling, thereby obtaining multiple subgraphs.
[0046] Based on the preceding description, for example, in one embodiment, for the attribute-to-attribute class problem, the obtained triplet form of subgraph 1 is ("Jiaxing", "license plate number", "Zhejiang F") and ("Jiaxing", "area code", "0573").
[0047] For example, in another embodiment, for multi-hop reasoning problems, the triples of the obtained subgraph can be in the form of (Duke Yuan of Lu, father and son, Duke Mu of Lu), (Duke Mu of Lu, father and son, Duke Gong of Lu), (Duke Gong of Lu, father and son, Duke Kang of Lu).
[0048] S102. For each subgraph, convert each set of triples in each subgraph into natural language text to obtain the natural language text set corresponding to each subgraph. Then, concatenate all sets of triples in each subgraph and the natural language text set corresponding to each subgraph to form the reference content corresponding to each subgraph.
[0049] Specifically, each subgraph can contain multiple sets of triples. Furthermore, a large language model can be used to convert the triple data into natural language text.
[0050] It should be noted that the large language model in this article refers to a model with a large scale and a large number of parameters. For example, it can be GPT (Generative Pre-trained Transformer), BERT (Bidirectional Encoder Representations from Transformers), BLOOM (BigScience Large Open-science Open-access Multilingual Language Model), etc.
[0051] Combining the example above, for subgraph 1, the triplet form of subgraph 1 is ("Jiaxing", "license plate number", "Zhejiang F") and ("Jiaxing", "area code", "0573"). After converting each triplet data of subgraph 1 into natural language text, the natural language text set corresponding to subgraph 1 is: the license plate number of Jiaxing City is Zhejiang F, and the area code of Jiaxing City is 0573.
[0052] Further, after obtaining the natural language text corresponding to the subgraph, all group triple data of the subgraph and the natural language text set corresponding to the subgraph can be spliced together according to a preset splicing template to obtain a splicing result, and the splicing result is the reference content corresponding to each subgraph. The preset splicing template is set according to actual needs, which is not limited in the embodiment. For example, in a possible implementation, the preset splicing template can be: triple data in each subgraph; the natural language text set corresponding to each subgraph.
[0053] For example, for subgraph 1, the reference content corresponding to the subgraph 1 is: (“Jiaxing”, “license plate number”, “Zhe F”), (“Jiaxing”, “telephone area code”, “0573”); the license plate number of Jiaxing City is Zhe F, and the telephone area code of Jiaxing City is 0573.
[0054] S103, generating a question related to the reference content according to the reference content corresponding to each subgraph and the question type corresponding to each subgraph.
[0055] Specifically, a large language model can be used to generate a question related to the reference content according to the reference content corresponding to each subgraph and the question type corresponding to each subgraph. For example, in a possible implementation, the reference content corresponding to each subgraph and the question type corresponding to each subgraph can be input into a large language model, and the large language model outputs a question related to the reference content.
[0056] In a specific implementation, the reference content and the question type can be spliced together according to a preset format template, and then the spliced text can be input into a large language model, and the large language model outputs a question related to the reference content. The preset format template is set according to actual needs, which is not limited in the embodiment. For example, in a possible implementation, the preset format template can be: the question type is **; the reference content is **.
[0057] For example, for subgraph 1, the following content can be input into a large language model: the question type is an attribute-to-attribute question; the reference content is: (“Jiaxing”, “license plate number”, “Zhe F”), (“Jiaxing”, “telephone area code”, “0573”); the license plate number of Jiaxing City is Zhe F, and the telephone area code of Jiaxing City is 0573. At this time, the question generated by the large language model can be: What is the license code of the place where the telephone area code is 0573?
[0058] S104, generating an answer to the question according to the reference content corresponding to each subgraph and the question related to the reference content.
[0059] Specifically, the large language model can be used to generate an answer to a question. In actual implementation, the reference content and the question can be input into the large language model at the same time, and the large language model can infer the question based on the reference content to generate an answer to the question. For example, in one possible implementation, the reference content and the question can be spliced together according to a preset format template, and then the spliced result can be input into the large language model to generate an answer to the question. The preset format template is set according to actual needs, and is not limited in this embodiment. For example, in one possible implementation, the preset format template can be: "Please answer the following question based on the reference content below. The reference content is: ……; the question is: ……."
[0060] In combination with the above example, in this embodiment, the following content can be input into the large language model: "Please answer the following question based on the reference content below. The reference content is: ('Jiaxing', 'license plate number', 'ZheF'), ('Jiaxing', 'telephone area code', '0573'); the license plate number of Jiaxing City is ZheF, and the telephone area code of Jiaxing City is 0573; the question is: What is the license code of the place with the telephone area code 0573?"
[0061] At this time, for example, in one embodiment, the output result of the large language model is: the place with the telephone area code 0573 is Jiaxing City in Zhejiang Province, and the license code thereof is ZheF.
[0062] It should be noted that after obtaining the question, the large language model is called again to answer the generated question and the given reference content. Since the reference content has been given, the large language model can accurately induce the correct answer from the reference content.
[0063] S105, constructing a sample according to the question and the answer.
[0064] In one embodiment, the question and the answer can be used to directly construct a sample in actual implementation. In combination with the above example, in this step, the constructed sample is as follows: What is the license code of the place with the telephone area code 0573? The place with the telephone area code 0573 is Jiaxing City in Zhejiang Province, and the license code thereof is ZheF.
[0065] The method provided in this embodiment can generate samples based on the rich structured information and multi-hop information in the knowledge graph, can not only achieve the purpose of automatically generating samples, improve the generation efficiency of samples, and reduce the generation cost of samples, but also can improve the diversity of samples based on the diversified topics provided by the knowledge graph, so as to improve the logical reasoning ability of the fine-tuned large language model when facing diversified data.
[0066] FIG. 2 is a flowchart of an embodiment two of the sample construction method provided in the present application. Referring to FIG. 2, the method provided in this embodiment, based on the above-mentioned embodiment, constructs a sample according to the question and the answer, comprising:
[0067] S201, verifying the correctness of the answer relative to the question.
[0068] Specifically, after obtaining the answer to the question, the correctness of the answer relative to the question can be verified first to ensure the accuracy of the finally constructed sample.
[0069] Optionally, a large language model can be used as a judge to verify the correctness of the answer relative to the question. Specifically, the question and the answer can be input into the large language model, and the large language model can verify the correctness of the answer relative to the question.
[0070] In a specific implementation, the question and the answer are then spliced together according to a preset format template, and then the spliced result is input into the large language model to verify the correctness of the answer relative to the question. The preset format template is set according to actual needs, which is not limited in this embodiment. For example, in one possible implementation, the preset format template can be: please verify the correctness of the following answer relative to the following question, the question is: ……? The answer is: ……
[0071] With the above example, in this step, the following content is input into the large language model: Please check the correctness of the following answer with respect to the following question: What is the license plate code of the place with the phone area code 0573? The answer is that the place with the phone area code 0573 is Zhejiang Jiaxing City, and its license plate code is ZheF.
[0072] Optionally, in a possible implementation manner, the specific implementation process of this step can include:
[0073] Step 1: Obtain a third prompt word related to the question type; wherein the third prompt word is used to guide the large language model to check the answer.
[0074] Specifically, in an embodiment, the third prompt word related to the question type can be obtained from a pre-established third prompt word library. It should be noted that the third prompt word library records third prompt words related to various question types, and the third prompt words related to various question types are different. The third prompt word corresponding to each question type is constructed by the user in advance. In addition, in another embodiment, the third prompt word can also be constructed in real time.
[0075] With the above example, for example, in a possible implementation manner, when the question type is an attribute-to-attribute type question, at this time, the obtained third prompt word is as follows:
[0076] "Please check the following error types:
[0077] 1. Insufficient number of hops. The answer does not follow the logical chain from the question to the answer.
[0078] 2. Reasoning error. Attribute 1 may point to other entities.
[0079] 3. Please give a reason first. The output [1] indicates correct, and the output [2] indicates error or cannot be judged."
[0080] For another example, in another possible implementation manner, for a multi-hop reasoning type question, the obtained third prompt word can be:
[0081] "Please check the following error types for the question and answer given above:
[0082] 1. Insufficient number of hops required for solving the problem. This question requires at least 2 hops to solve.
[0083] 2. Insufficient number of hops in the answer. The answer should be thought out step by step, and cannot give the answer at once.
[0084] 3. Too many hops in the answer. The answer should follow the shortest reasoning path, and cannot intentionally take a detour.
[0085] 4. Reasoning error. There is an error in the reasoning process in the answer.
[0086] 5. Redundant information. The answer cannot mention the knowledge graph.
[0087] 6. Please give the reason first, and finally output [1] to indicate correct, and output [2] to indicate error or cannot be judged.
[0088] It should be noted that the third prompt words in the third prompt word library are constructed by the user in advance. When constructing the third prompt words, the user can construct the third prompt words based on the logical chain from the question to the answer and the possible alternative error types that may exist from the question to the answer, so that the third prompt words clearly indicate the logical chain from the question to the answer and the possible alternative errors.
[0089] It should be noted that the logical chain from the question to the answer refers to the logical steps followed when answering the question, and how these logical steps lead to the final answer. For example, for attribute-to-attribute type questions, the logic from the question to the answer is to derive a unique entity based on an attribute (attr1), and then derive another attribute (attr2) of the entity from the entity (entity), i.e. its logical chain is: Who is the unique entity corresponding to attribute 1, and what is the attribute 2 of the entity.
[0090] Further, for a certain type of question, there may be multiple types of errors from the question to the answer. For example, for attribute-to-attribute type questions, possible alternative error types can be: 1. Insufficient number of hops, i.e. the answer does not follow the reasoning of attribute 1-entity-attribute 2; 2. Reasoning error, for example, attribute 1 may point to other entities.
[0091] As previously introduced, when constructing the third prompt words, the third prompt words can be constructed based on the logical chain from the question to the answer and the alternative error types from the question to the answer.
[0092] Step 2, input the third prompt word, the question and the answer into the large language model, to verify the correctness of the answer relative to the question according to the third prompt word by the large language model, and output the verification result.
[0093] In specific implementation, the third prompt word, the question and the answer can be spliced together according to a preset format template, and then the spliced result can be input into the large language model. The preset format template is set according to actual needs, which is not limited in the embodiment. For example, in one possible implementation, the preset format template can be: "third prompt word: ……, question: ……? Answer: …….".
[0094] In a specific implementation, in combination with the first example above, at this time, the following information can be input into the large language model for verification by the large language model:
[0095] “Third prompt word:
[0096] 1. Insufficient hops. The answer does not follow the logical chain from question to answer.
[0097] 2. Reasoning error. Property 1 may point to other entities.
[0098] 3. Please give the reason first, and finally output [1] to indicate correct, or output [2] to indicate error or cannot be judged.
[0099] Question: What is the license plate code of the place with phone area code 0573?
[0100] Answer: The place with phone area code 0573 is Jiaxing City, Zhejiang, and its license plate code is Zhe F.”
[0101] In combination with the example above, for example, in an embodiment, the output of the large language model is as follows:
[0102] “Hop check: The answer makes two jumps, first deducing the entity “Jiaxing City, Zhejiang” from the phone area code 0573, and then deducing its license plate code “Zhe F” from the entity “Jiaxing City, Zhejiang”, which conforms to the two-hop structure of property 1-entity-property 2.
[0103] Reasoning check: 0573 is indeed the phone area code of Jiaxing City, Zhejiang, and the license plate code of Jiaxing City, Zhejiang is indeed Zhe F. Therefore, the reasoning is correct.
[0104] Verification result: [1], verification is correct”.
[0105] In this embodiment, by obtaining the third prompt word, the large language model can be guided to verify the answer according to the prompt word, reducing the time of the large language model generating irrelevant content, improving the interaction efficiency, and obtaining the verification result more quickly and accurately.
[0106] S202, combining the question and the answer as a sample when the answer is correct.
[0107] In a specific implementation, only when the answer is correct, the question and the answer are combined as a sample, which can ensure the accuracy of the sample.
[0108] The method provided in this embodiment verifies the correctness of the answer relative to the question, and then combines the question and the answer as a sample when the answer is correct, which can ensure the accuracy of the sample.
[0109] FIG. 3 is a flowchart of an embodiment three of the sample construction method provided by the present application. Referring to FIG. 3, on the basis of the above embodiments, the generating of the related question of the reference content according to the obtained reference content and the question type of the subgraph comprises:
[0110] S301, obtaining a first prompt word related to the question type; wherein the first prompt word is used to guide the large language model to make a deduction question related to the question type according to the input reference content.
[0111] Specifically, the first prompt word is used to guide the large language model to make a deduction question related to the question type according to the input reference content, and different question types correspond to different first prompt words.
[0112] In a specific implementation, in an embodiment, the first prompt word related to the question type can be obtained from a pre-established first prompt word library, wherein the first prompt word library stores the first prompt word corresponding to each question type, the first prompt word corresponding to each question type is different, and the first prompt word corresponding to each question type is constructed by the user in advance. In another embodiment, the first prompt word can also be constructed in real time.
[0113] It should be noted that the construction method of the first prompt word corresponding to different question types is different, which is not limited in the present embodiment. For example, for the attribute-to-attribute question, the first prompt word should clearly require the large language model to deduce the corresponding entity according to the given attribute 1, and then deduce the attribute 2 of the entity. The first prompt word is mainly used to guide the large language model to make an attribute-to-attribute deduction question according to the given reference content.
[0114] In addition, for the attribute-to-attribute question, when constructing the first prompt word, the large language model also needs to be guided by the first prompt word to deduce a unique entity according to the given attribute 1.
[0115] Combining the above example, for example, for subgraph 1, the first prompt word is as follows:
[0116] “Please make a question according to the reference content based on your existing knowledge, and the requirements are:
[0117] The type of the question needs to be an “attribute-to-attribute question”, that is, it needs to deduce the corresponding entity according to attribute 1, and then deduce the attribute 2 of the entity;
[0118] Ensure that the value of attribute 1 is unique and only corresponds to the entity and cannot correspond to other entities;
[0119] If it cannot be questioned, please answer “none”.
[0120] S302, input the first prompt word and the reference content into the large language model to generate a question related to the reference content by the large language model.
[0121] Specifically, after the first prompt word is constructed, the first prompt word and the reference content can be input into the large language model to generate a question related to the reference content by the large language model. In specific implementation, the first prompt word and the reference content can be spliced together according to a preset format template, and then the spliced result is input into the large language model. The preset format template is set according to actual needs, which is not limited in the embodiment. For example, in one possible implementation, the preset format template can be: "first prompt word. Constraint condition - reference content: ……".
[0122] In combination with the first example above, the following information is input into the large language model in this step:
[0123] "Please ask questions based on your existing knowledge and the reference content. Requirements:
[0124] 1. The type of the question needs to be "attribute to attribute", that is, the corresponding entity needs to be deduced according to attribute 1, and then the attribute 2 of the entity needs to be deduced;
[0125] 2. Ensure that the value of attribute 1 is unique and only corresponds to the entity and cannot correspond to other entities;
[0126] 3. If it is not possible to ask questions, please answer "no".
[0127] Constraint condition - reference content:
[0128] ("Jiaxing", "license plate number", "ZheF"), ("Jiaxing", "telephone area code", "0573"); The license plate number of Jiaxing City is ZheF, and the telephone area code of Jiaxing City is 0573."
[0129] The method provided in the embodiment, when generating a question related to the reference content according to the reference content corresponding to the subgraph and the question corresponding to the subgraph, constructs a first prompt word related to the type of the question, and then inputs the first prompt word and the reference content into the large language model to generate a question related to the reference content by the large language model. In this way, the large language model can be guided by the first prompt word to make deductions related to the type of the question based on the input reference content, which not only makes the generated question more closely related to the core points of the reference content, avoids generating ambiguous or inaccurate questions, improves the relevance, pertinence and accuracy of the question, but also enables the large language model to generate diversified questions through different prompt words, covering various aspects of the reference content, to further improve the diversity of the sample.
[0130] FIG. 4 is a flowchart of an embodiment four of the sample generation method provided by the present application. Referring to FIG. 4, the method provided by the present embodiment, on the basis of the above-mentioned embodiments, comprises:
[0131] S401, a second prompt word is obtained; wherein the second prompt word is used to guide the large language model to reason according to the existing knowledge and the input reference content, and answer the question based on the reasoning.
[0132] Specifically, in order to better guide the large language model to reason according to the existing knowledge and the input reference content, and answer the question based on the reasoning, the second prompt word needs to be obtained to guide the large language model to reason and answer the question according to the existing knowledge and the reference content, so as to ensure the accuracy, logical integrity and rationality of the answer.
[0133] In specific implementation, the second prompt word can be directly obtained from a pre-constructed prompt word library, or be constructed in real time, which is not limited in the present embodiment. For example, in an embodiment, the obtained second prompt word is as follows:
[0134] "Please answer the following questions based on your existing knowledge and the reference content. Requirements:
[0135] 1. Think step by step first, and then give the answer;
[0136] 2. Do not mention the reference content;
[0137] 3. You can add your own knowledge and understanding, and please correct the factual errors therein."
[0138] S402, the second prompt word, the reference content corresponding to each subgraph, and the question related to the reference content are input into the large language model, so that the large language model reasons the question related to the reference content according to the second prompt word and the reference content corresponding to each subgraph, and generates an answer to the question.
[0139] In specific implementation, the second prompt word, the reference content corresponding to each subgraph, and the question related to the reference content can be spliced together according to a preset format template, and then the spliced result is input into the large language model. The preset format template is set according to actual needs, which is not limited in the present embodiment.
[0140] In combination with the above example of subgraph 1, for example, in a possible implementation manner, the following information is input into the large language model in this step:
[0141] "Please answer the following questions based on your existing knowledge and the reference content. Requirements:
[0142] 1. Think step by step first, and then give the answer;
[0143] 2. Cannot mention reference content;
[0144] 3. You can add your own knowledge and understanding, and please correct the factual errors.
[0145] [Start of triple data]
[0146] ("Jiaxing", "license plate number", "ZheF"), ("Jiaxing", "telephone area code", "0573")
[0147] [End of triple data]
[0148] [Start of natural language text]
[0149] The license plate number of Jiaxing City is ZheF, and the telephone area code is 0573.
[0150] [End of natural language text]
[0151] [Start of question]
[0152] What is the license plate code of the place with telephone area code 0573?
[0153] [End of question]
[0154] Further, for example, in one embodiment, in combination with the above introduction, the output of the large language model is: The place with telephone area code 0573 is Jiaxing City, Zhejiang Province, and its license plate code is ZheF.
[0155] The method provided in this embodiment, when generating the answer to the question related to the reference content corresponding to each subgraph and the reference content, constructs a second prompt word, and then inputs the second prompt word, the reference content corresponding to each subgraph, and the question related to the reference content into the large language model, so that the large language model can infer the question related to the reference content according to the second prompt word and the reference content corresponding to each subgraph, and generate the answer to the question. In this way, through the second prompt word, the key points that need to be paid attention to in the reasoning process of the large language model can be clearly indicated, so that the large language model can better understand the background and details of the question, integrate existing knowledge and reference content, and improve the relevance, logic and accuracy of the generated answer.
[0156] Figure 5 is a flowchart of the fifth embodiment of the sample construction method provided by the present application. Please refer to Figure 5, the method provided in this embodiment can include:
[0157] S501, for each of the plurality of preset question types, obtain a plurality of subgraphs corresponding to the question type from the knowledge graph.
[0158] Specifically, for the specific implementation process and principle of step S501, refer to the description in the previous embodiments, which will not be described here.
[0159] S502, obtain a fourth prompt word; wherein the fourth prompt word is used to guide the large language model to convert the triple data into natural language text.
[0160] Specifically, the fourth prompt word is used to guide the large language model to convert the triple data into natural data text. Wherein, the fourth prompt word can be obtained from the preset prompt word library or constructed in real time, which is not limited in this embodiment, for example, in one possible implementation, the obtained fourth prompt word can be: please combine your existing knowledge to express the knowledge graph path represented by the following triple (subject, relation, object) into natural language text.
[0161] S503, for each subgraph, input the fourth prompt word and all triple data in the subgraph into the large language model to output a set of natural language texts corresponding to the subgraph by the large language model.
[0162] In specific implementation, the fourth prompt word and all triple data in the subgraph can be spliced together according to a preset format template, and then the spliced result is input into the large language model. Wherein, the preset format template is set according to actual needs, which is not limited in this embodiment.
[0163] For example, combined with the example of subgraph 1 above, the following content is input into the large language model in this step:
[0164] "Please combine your existing knowledge to express the knowledge graph path represented by the following triple (subject, relation, object) into natural language text. [Triple data starts] (“Jiaxing”, “license plate number”, “ZheF”), (“Jiaxing”, “telephone area code”, “0573”) [Triple data ends]”.
[0165] The method provided in this embodiment, when converting each set of triple data in each subgraph into natural language text to obtain a set of natural language texts corresponding to each subgraph, constructs a fourth prompt word, and then inputs the fourth prompt word and all triple data in the subgraph into the large language model to output a set of natural language texts corresponding to the subgraph by the large language model, which can reduce the understanding and processing time of the large language model when generating natural language text, improve the conversion efficiency, and enable the large language model to generate natural language text more quickly.
[0166] S504, splice all group triplet data of the subgraph and the natural language text set corresponding to the subgraph as reference content corresponding to the subgraph.
[0167] Specifically, the specific implementation principle and implementation process of step S504 can be referred to the description in the foregoing embodiments, which will not be repeated here.
[0168] S505, obtain a first prompt word related to the question type; wherein the first prompt word is used to guide the large language model to make inferences related to the question type according to the input reference content.
[0169] The specific implementation process and implementation principle of this step can be referred to the description in the foregoing embodiments. For example, in an embodiment, for different instance attribute comparison type questions, in an embodiment, the constructed first prompt word is as follows:
[0170] "According to the above introduction, design a question, requirements:
[0171] 1. The question is about the comparison of a single attribute of multiple entities;
[0172] 2. The question has an objective answer;
[0173] 3. Only give the question, do not give additional explanations."
[0174] S506, input the first prompt word and the reference content into the large language model to generate a question related to the reference content by the large language model.
[0175] S507, obtain a second prompt word; wherein the second prompt word is used to guide the large language model to make inferences based on existing knowledge and input reference content, and answer questions based on inferences.
[0176] S508, input the second prompt word, the reference content corresponding to each subgraph, and the question related to the reference content into the large language model, to make inferences on the question related to the reference content by the large language model according to the second prompt word and the reference content corresponding to each subgraph, and generate an answer to the question.
[0177] S509, obtain a third prompt word; wherein the third prompt word is used to guide the large language model to verify the answer.
[0178] S510, input the third prompt word, the question and the answer into the large language model, to verify the correctness of the answer with respect to the question according to the third prompt word by the large language model, and output a verification result.
[0179] S511、in the case that the answer is correct, combining the question and the answer as a sample.
[0180] Specifically, the specific implementation principles and implementation processes of steps S506 to S511 can be referred to the descriptions in the foregoing embodiments, which will not be described here again.
[0181] The method provided in this embodiment, by acquiring, for each of a plurality of preset question types, a plurality of sub-graphs corresponding to the question type from a knowledge graph, and then for each sub-graph, converting each group of triple data in the sub-graph into natural language text to obtain a set of natural language texts corresponding to the sub-graph, and splicing all groups of triple data of each sub-graph and the set of natural language texts corresponding to the sub-graph as reference content corresponding to each sub-graph, the method generates a question related to the reference content according to the reference content corresponding to each sub-graph and the question type corresponding to each sub-graph, and generates an answer to the question according to the reference content corresponding to each sub-graph and the question related to the reference content, and then constructs a sample according to the question and the answer. In this way, the sample can be generated based on the rich structured information and multi-hop information in the knowledge graph, not only achieving the purpose of automatically generating the sample, improving the generation efficiency of the sample, and reducing the generation cost of the sample, but also improving the diversity of the sample based on the diversified topics provided by the knowledge graph, so as to improve the logical reasoning ability of the fine-tuned large language model when facing diversified data.
[0182] The present application also provides a large language model fine-tuning method, the method comprising:
[0183] acquiring a sample;
[0184] In specific implementation, any method provided in the first aspect of the present application can be used to acquire the sample, which will not be described here again.
[0185] (2) fine-tuning the parameters of the large language model using the sample.
[0186] The method provided in this embodiment improves the logical reasoning ability of the large language model by acquiring the sample and then fine-tuning the large language model using the sample.
[0187] Corresponding to the foregoing embodiments of the sample construction method, the present application also provides an embodiment of a sample construction device.
[0188] Embodiments of the sample construction device provided in the present application can be applied to a sample construction apparatus. The device embodiments can be implemented by software, or by hardware or a combination of software and hardware. For example, in software, as a logical device, it is formed by reading the corresponding computer program instructions in the non-volatile memory into the memory for running by the processor of the sample construction apparatus in which the device is located. From the hardware level, as shown in FIG. 6, the hardware structure diagram of the sample construction apparatus in which the sample construction device provided in the present application is located. In addition to the processor, memory, network interface, and non-volatile memory shown in FIG. 6, the sample construction apparatus in which the device is located in the embodiments can also include other hardware according to the actual functions of the sample construction device, and will not be described here.
[0189] FIG. 7 is a structural schematic diagram of an embodiment of the sample construction device provided in the present application. Referring to FIG. 7, the device provided in the present embodiment includes an acquisition module 710, a conversion module 720, a generation module 730, and a construction module 740; wherein,
[0190] The acquisition module 710 is configured to acquire, for each of a plurality of preset question types, a plurality of sub-graphs corresponding to the question type from a knowledge graph;
[0191] The conversion module 720 is configured to, for each sub-graph, convert each group of triple data in the sub-graph into natural language text to obtain a set of natural language texts corresponding to the sub-graph, and splice all groups of triple data of the sub-graph and the set of natural language texts corresponding to the sub-graph as reference content corresponding to the sub-graph;
[0192] The generation module 730 is configured to generate a question related to the reference content according to the reference content corresponding to each sub-graph and the question type corresponding to each sub-graph;
[0193] The generation module 730 is configured to generate an answer to the question according to the reference content corresponding to each sub-graph and the question related to the reference content;
[0194] The construction module 740 is configured to construct a sample according to the question and the answer.
[0195] The device of the present embodiment can be used to execute the steps of the method embodiment shown in FIG. 1, and the specific implementation principles and implementation processes are similar, which will not be described here.
[0196] Please continue to refer to FIG. 6, the present application also provides a sample construction apparatus, including a memory, a processor and a computer program stored on the memory and executable on the processor, when the processor executes the program, the steps of the method provided by any one of the first aspect of the present application are implemented.
[0197] The application further provides a computer readable storage medium, which stores a computer program, and the program is executed by a processor to implement steps of any method provided by the application.
[0198] The implementation process of the functions and roles of each unit in the above device is specifically described in the implementation process of the corresponding steps in the above method, and will not be repeated here.
[0199] For the device embodiment, since it basically corresponds to the method embodiment, the related parts can be referred to the part of the method embodiment. The above described device embodiment is only schematic, and the units described as separate components can or can not be physically separate, and the components displayed as units can or can not be physical units, that is, they can be located in one place, or distributed on multiple network units. According to the actual needs, part or all of the modules can be selected to achieve the purpose of the application. Those skilled in the art can understand and implement without creative labor.
[0200] The above only describes the preferred embodiment of the application, and does not limit the application. Any modification, equivalent replacement, improvement, etc. within the spirit and principle of the application shall be included in the protection scope of the application.
Claims
1. A method of sample construction, characterized by, The method comprises: For each question type in a plurality of preset question types, a plurality of subgraphs corresponding to the question type are acquired from a knowledge graph; For each subgraph, each set of triple data in each subgraph is converted into natural language text to obtain a set of natural language texts corresponding to each subgraph, and all sets of triple data of each subgraph and the set of natural language texts corresponding to each subgraph are spliced into reference content corresponding to each subgraph; According to the reference content corresponding to each subgraph and the question type corresponding to each subgraph, a question related to the reference content is generated; According to the reference content corresponding to each subgraph and the question related to the reference content, an answer to the question is generated; A sample is constructed according to the question and the answer.
2. The method of claim 1, wherein, The method comprises: For each question type in a plurality of preset question types, a target sampling rule corresponding to the question type is acquired from a plurality of preset sampling rules; wherein the sampling rules corresponding to different question types are different; According to the target sampling rule, subgraphs are collected from the knowledge graph to obtain a plurality of subgraphs corresponding to the question type.
3. The method of claim 1, wherein, The method comprises: The correctness of the answer relative to the question is verified; When the answer is correct, the question and the answer are combined into a sample.
4. The method of claim 1, wherein, The method comprises: A first prompt word related to the question type is acquired; wherein the first prompt word is used to guide a large language model to make inferences related to the question type according to input reference content; The first prompt word and the reference content are input into the large language model to generate a question related to the reference content by the large language model.
5. The method of claim 1, wherein, The method comprises: A second prompt word is acquired; wherein the second prompt word is used to guide a large language model to make inferences based on existing knowledge and input reference content, and answer questions based on the inferences; The second prompt word, the reference content corresponding to each subgraph, and the question related to the reference content are input into the large language model to make inferences on the question related to the reference content according to the second prompt word and the reference content corresponding to each subgraph by the large language model, and generate an answer to the question.
6. The method of claim 3, wherein, The method comprises: A third prompt word related to the question type is acquired; wherein the third prompt word is used to guide a large language model to verify the answer; The third prompt word, the question, and the answer are input into the large language model to verify the correctness of the answer relative to the question according to the third prompt word by the large language model, and output a verification result.
7. The method of claim 1, wherein, The method comprises: obtaining a fourth prompt; wherein the fourth prompt is used to guide the large language model to convert the triple data into natural language text; inputting the fourth prompt and all triple data in the subgraph into the large language model to output a set of natural language texts corresponding to the subgraph by the large language model.
8. A large language model fine-tuning method, characterized in that, The method comprises: obtaining a sample by the method of any one of claims 1-7; fine-tuning parameters of the large language model using the sample.
9. An apparatus for constructing a sample, characterized by The device comprises an obtaining module, a converting module, a generating module and a constructing module; wherein, The obtaining module is configured to obtain, for each question type in a plurality of preset question types, a plurality of subgraphs corresponding to the question type from a knowledge graph; The converting module is configured to convert each set of triple data in each subgraph into natural language text to obtain a set of natural language texts corresponding to each subgraph, and concatenate all sets of triple data of each subgraph and the set of natural language texts corresponding to each subgraph as reference content corresponding to each subgraph; The generating module is configured to generate a question related to the reference content according to the reference content corresponding to each subgraph and the question type corresponding to each subgraph; The generating module is configured to generate an answer to the question according to the reference content corresponding to each subgraph and the question related to the reference content; The constructing module is configured to construct a sample according to the question and the answer.
10. An apparatus for constructing a sample, characterized by A computer program product comprising a memory, a processor and a computer program stored on the memory and executable on the processor, wherein the processor implements the steps of the method of any one of claims 1-7 when executing the program.
Citation Information
Patent Citations
Knowledge graph generation type question answering method and system based on large language model
CN117033608A
Method and device for generating prompt data based on knowledge graph
CN117077792A
Question and answer method and device for knowledge in field of literature and blog, equipment and medium
CN117216194A
Fine adjustment method, system and equipment based on large language model and medium
CN117290480A
Question and answer data construction method and device based on large language model
CN117591661A