Sample construction method, device and equipment and large language model fine tuning method

By obtaining subgraphs from the knowledge graph and building samples, the problem of poor performance of large language models in logical reasoning scenarios is solved, and the sample generation efficiency and the logical reasoning ability of the model are improved.

CN119047574APending Publication Date: 2024-11-29SHENZHEN INTELLIFUSION TECHNOLOGIES CO LTD

Patent Information

Application Number
CN202411035269.3
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2024-07-30
Publication Date
2024-11-29

AI Technical Summary

Technical Problem

Large language models perform poorly in slow thinking scenarios such as logical reasoning, making them difficult to effectively learn and apply logical reasoning capabilities, and obtain logical reasoning data inefficiently.

Method used

By obtaining multiple subgraphs from the knowledge graph, converting them into natural language text, generating related questions and answers, build samples to fine-tune the large language model.

Benefits of technology

It improves sample generation efficiency and diversity, and enhances the logical reasoning ability of fine-tuned large language models when facing diverse data.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN119047574A_ABST
    Figure CN119047574A_ABST
Patent Text Reader

Abstract

The invention provides a sample construction method, device and equipment and a large language model fine tuning method. The sample construction method provided by the invention comprises the following steps: for each question type, acquiring a plurality of sub-graphs corresponding to the question type from a knowledge graph; converting each group of triple data in each sub-graph into a natural language text to obtain a natural language text set corresponding to each sub-graph, and splicing all groups of triple data of each sub-graph and the natural language text set corresponding to each sub-graph into reference content corresponding to each sub-graph; generating 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; generating an answer to the question according to the reference content corresponding to each sub-graph and the question related to the reference content; and constructing a sample according to the question and the answer. The invention provides a sample construction method, a sample construction device, sample construction equipment and a large language model fine tuning method. Various samples can be efficiently obtained.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present application relates to the technical field of natural language processing, and in particular to a sample construction method, apparatus, device and large language model fine-tuning method. Background Art

[0002] At present, although the large language model can demonstrate human-like language organization and expression capabilities, it still performs poorly in some scenarios that require slow thinking such as logical reasoning, and the answers obtained may not correspond to the questions. To address this problem, it is expected that a large amount of logical reasoning data can be used to fine-tune the large language model, so that it can be familiar with the corresponding answer paradigm and stimulate its logical reasoning ability learned from a large amount of logical reasoning data. At this time, how to efficiently obtain logical reasoning data becomes the key to solving this problem. Summary of the invention

[0003] In view of this, the present application provides a sample construction method, apparatus, device and large language model fine-tuning method to efficiently generate samples for fine-tuning a large language model.

[0004] Specifically, the present application is implemented through the following technical solutions:

[0005] The first aspect of the present application provides a sample construction method, the method comprising:

[0006] For each of the preset multiple question types, obtain multiple subgraphs corresponding to the question type from the knowledge graph;

[0007] For each subgraph, convert each set of triple data in each subgraph into natural language text to obtain a natural language text set corresponding to each subgraph, and splice all sets of triple data of each subgraph and the natural language text set corresponding to each subgraph into reference content corresponding to each subgraph;

[0008] Generate questions related to the reference content according to the reference content corresponding to each subgraph and the question type corresponding to each subgraph;

[0009] Generate an answer to the question based on the reference content corresponding to each subgraph and the question related to the reference content;

[0010] A sample is constructed based on the questions and the answers.

[0011] A second aspect of the present application provides a large language model fine-tuning method, the method comprising:

[0012] Obtain a sample using any of the methods provided in the first aspect of the present application;

[0013] The samples are used to fine-tune parameters of the large language model.

[0014] The third aspect of the present application provides a sample construction device, which includes an acquisition module, a conversion module, a generation module and a construction module; wherein:

[0015] The acquisition module is used to acquire, for each question type among the preset multiple question types, multiple subgraphs corresponding to the question type from the knowledge graph;

[0016] The conversion module is used to convert each group of triple data in each subgraph into natural language text for each subgraph, obtain a natural language text set corresponding to each subgraph, and splice all groups of triple data of each subgraph and the natural language text set corresponding to each subgraph into reference content corresponding to each subgraph;

[0017] The generating module is used to generate questions related to the reference content according to the reference content corresponding to each sub-graph and the question type corresponding to each sub-graph;

[0018] The generating module is used 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;

[0019] The construction module is used to construct a sample according to the question and the answer.

[0020] The fourth aspect of the present application provides a sample construction device, including a memory, a processor, and a computer program stored in the memory and executable on the processor, wherein when the processor executes the program, the steps of any one of the methods provided in the first aspect of the present application are implemented.

[0021] The sample construction method, device, equipment and large language model acquisition method provided in the present application, by obtaining multiple subgraphs corresponding to the question type from the knowledge graph for each question type in the preset multiple question types, and then for each subgraph, each group of triple data in each subgraph is converted into natural language text, and the natural language text set corresponding to each subgraph is obtained, and all groups of triple data of each subgraph and the natural language text set corresponding to each subgraph are spliced ​​into the reference content corresponding to each subgraph, so as to generate questions related to the reference content according to the reference content corresponding to each subgraph and the question type corresponding to each subgraph, and generate answers to the questions according to the reference content corresponding to each subgraph and the questions related to the reference content, and then construct samples according to the questions and the answers. In this way, samples can be generated based on the rich structured information and multi-hop information in the knowledge graph, which 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 diverse topics provided by the knowledge graph, so as to improve the logical reasoning ability of the fine-tuned large language model when facing diverse data. BRIEF DESCRIPTION OF THE DRAWINGS

[0022] Figure 1 A flow chart of Example 1 of the sample construction method provided in this application;

[0023] Figure 2 A flow chart of Example 2 of the sample construction method provided in this application;

[0024] Figure 3 A flowchart of Example 3 of the sample construction method provided in this application;

[0025] Figure 4 A flowchart of Example 4 of the sample construction method provided in this application;

[0026] Figure 5 A flowchart of Example 5 of the sample construction method provided in this application;

[0027] Figure 6 A hardware structure diagram of a sample construction device where the sample construction device provided in this application is located;

[0028] Figure 7 This is a schematic diagram of the structure of Example 1 of the sample construction device provided in this application. DETAILED DESCRIPTION

[0029] Here, exemplary embodiments are described in detail, and examples thereof are shown in the accompanying drawings. When the following description refers to the drawings, unless otherwise indicated, the same numbers in different drawings represent the same or similar elements. The implementations described in the following exemplary embodiments do not represent all implementations consistent with the present application.

[0030] The terms used in this application are only for the purpose of describing specific embodiments and are not intended to limit this application. The singular forms of "a", "said" and "the" used in this application are also intended to include plural forms, unless the context clearly indicates other meanings. It should also be understood that the term "and / or" used in this article refers to and includes any or all possible combinations of one or more associated listed items.

[0031] It should be understood that although the terms first, second, third, etc. may be used in the present application to describe various information, these information should not be limited to these terms. These terms are only used to distinguish the same type of information from each other. For example, without departing from the scope of the present application, the first information may also be referred to as the second information, and similarly, the second information may also be referred to as the first information. Depending on the context, the word "if" as used herein may be interpreted as "at the time of" or "when" or "in response to determining".

[0032] Specific embodiments are given below to introduce the technical solution of the present application in detail.

[0033] Figure 1 This is a flow chart of Example 1 of the sample construction method provided in this application. Please refer to Figure 1 , the method provided in this embodiment may include:

[0034] S101. For each question type among a plurality of preset question types, obtain a plurality of subgraphs corresponding to the question type from the knowledge graph.

[0035] Specifically, the preset multiple question types are set according to actual needs and are not limited in this embodiment. For example, in a possible implementation, the preset multiple question types may include multi-hop reasoning questions, attribute-to-attribute questions, different instance attribute comparison questions, and error pattern recognition questions.

[0036] Among them, multi-hop reasoning problems refer to problems that require multi-step reasoning and logical inference to get answers; attribute-to-attribute problems refer to problems that infer another attribute from a known attribute; different instance attribute comparison problems refer to problems that require comparing and analyzing the attributes of different instances; error pattern recognition problems refer to problems that require identifying and analyzing possible errors, logical contradictions or inconsistencies in a given situation.

[0037] Combined with the above introduction, for example, question 1 is: Please infer the relationship between Li Yuan and Li Zhi, this question 1 is a multi-hop reasoning problem; another example is question 2: The telephone area code of a certain area is A, what is the license plate number of the area; this question 2 is an attribute-to-attribute problem; another example is question 3: Which one is larger, Hangzhou or Shanghai? This question 3 is a problem of comparing attributes of different instances. Another example is question 4: Analyze whether there are errors in experimental design or data analysis in the experimental report; this question 4 is an error pattern recognition problem.

[0038] Furthermore, it can be understood that the knowledge graph is a structured data model for representing and organizing knowledge, which systematically expresses entities and the relationships between entities in the form of a graph. It should be noted that the knowledge graph consists of nodes (nodes represent entities) and edges (edges represent the relationships between entities), and each node and edge carries attribute information.

[0039] In a possible implementation, the knowledge graph can be directly obtained from the Internet, or created according to one's actual needs, which is not limited in this embodiment.

[0040] In specific implementation, for each of the preset multiple question types, a target sampling rule corresponding to the question type can be obtained from the preset multiple sampling rules, and then subgraphs can be collected from the knowledge graph according to the target sampling rule to obtain multiple subgraphs corresponding to the question type.

[0041] It should be noted that different question types correspond to different sampling rules. The sampling rules corresponding to each question type are set according to actual needs and are not limited in this embodiment.

[0042] For example, for multi-hop reasoning problems, in one possible implementation, the corresponding sampling rule may be: within the set hop count range, randomly generate an integer as the actual hop count, randomly select a node from the knowledge graph as the starting node, select a neighboring node for jumping according to the randomly generated hop count, and repeat the jumping steps until the randomly generated hop count is reached. It should be noted that in each jump step, a node can be randomly selected from the neighboring nodes of the current node for jumping, and the neighboring nodes are not required to have the same attributes.

[0043] For another example, for attribute-to-attribute problems, in one possible implementation, the corresponding sampling rule may be: randomly select a node from the knowledge graph, and obtain the first-order domain of the node as the subgraph corresponding to the problem type.

[0044] For another example, for the problem of comparing attributes of different instances, in one possible implementation, the corresponding sampling rule is: select different nodes with the same attributes from the knowledge graph for sampling to obtain multiple subgraphs.

[0045] Combined with the above introduction, for example, in one embodiment, for the attribute to attribute class problem, the obtained sub Figure 1 The triple form is ("Jiaxing", "license plate number", "Zhejiang F"), ("Jiaxing", "telephone area code", "0573").

[0046] For another example, in another embodiment, for multi-hop reasoning problems, the triple form of the obtained subgraph can be (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).

[0047] S102. For each subgraph, each group of triple data in each subgraph is converted into natural language text to obtain a natural language text set corresponding to each subgraph, and all groups of triple data of each subgraph and the natural language text set corresponding to each subgraph are concatenated into reference content corresponding to each subgraph.

[0048] Specifically, each subgraph may contain multiple sets of triple data. Furthermore, a large language model may be used to convert the triple data into natural language text.

[0049] 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, referred to as GPT), BERT (Bidirectional Encoder Representations from Transformers, referred to as BERT), BLOOM (Big Science Large Open-science Open-access Multilingual Language Model, referred to as BLOOM), etc.

[0050] Combined with the above example, for the child Figure 1 , the child Figure 1 The triple form is ("Jiaxing", "license plate number", "Zhejiang F"), ("Jiaxing", "telephone area code", "0573"); Figure 1 After each set of triple data is converted into natural language text, the sub Figure 1 The corresponding natural language text set is: the license plate number of Jiaxing City is Zhejiang F, and the telephone area code of Jiaxing City is 0573.

[0051] Furthermore, after obtaining the natural language text corresponding to the subgraph, all the triplet data of the subgraph and the natural language text set corresponding to the subgraph can be spliced ​​together according to the preset splicing template to obtain the splicing result, which is the reference content corresponding to each subgraph. The preset splicing template is set according to actual needs and is not limited in this embodiment. For example, in a possible implementation, the preset splicing template can be: the triplet data in each subgraph; the natural language text set corresponding to each subgraph;

[0052] Combining the above example, for example, Figure 1 , the child Figure 1 The corresponding reference content is: ("Jiaxing", "license plate number", "Zhe F"), ("Jiaxing", "telephone area code", "0573"); the license plate number of Jiaxing City is Zhejiang F, and the telephone area code of Jiaxing City is 0573.

[0053] S103: Generate questions related to the reference content according to the reference content corresponding to each subgraph and the question type corresponding to each subgraph.

[0054] Specifically, the large language model can be used to generate questions related to the reference content based on the reference content corresponding to each sub-graph and the question type corresponding to each sub-graph. For example, in one possible implementation, the reference content corresponding to each sub-graph and the question type corresponding to each sub-graph can be input into the large language model, and the large language model outputs questions related to the reference content.

[0055] 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 is input into the large language model, and the large language model outputs questions related to the reference content. Among them, the preset format model is set according to actual needs, and it is not limited in this embodiment. For example, in a possible implementation, the preset format template can be: question type is **; reference content is **.

[0056] Combining the above example, for example, Figure 1 , input the following content into the large language model: the question type is an attribute-to-attribute problem; the reference content is: ("Jiaxing", "license plate number", "Zhe F"), ("Jiaxing", "telephone area code", "0573"); the license plate number of Jiaxing City is Zhejiang 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 plate code of the place with the telephone area code 0573?

[0057] S104: Generate an answer to the question based on the reference content corresponding to each sub-graph and the question related to the reference content.

[0058] Specifically, the answer to the question can be generated using a large language model. In a specific implementation, the reference content and the question can be simultaneously input into the large language model, and the large language model can infer the question in combination with the reference content to generate the 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 splicing result can be input into the large language model, and the answer to the question can be generated by the large language model. Among them, the preset format template is set according to actual needs, and in this embodiment, it is not limited. For example, in a possible implementation, the preset format template can be: "Please answer the following questions based on the following reference content. The reference content is:...; the question is:... ".

[0059] Combined with the above example, in this embodiment, the following content can be input into the large language model: "Please answer the following questions based on the following reference content, the reference content is: ("Jiaxing", "license plate number", "Zhe F"), ("Jiaxing", "telephone area code", "0573"); the license plate number of Jiaxing City is Zhejiang F, and the telephone area code of Jiaxing City is 0573; the question is: What is the license plate code for the place with the telephone area code 0573?".

[0060] At this time, for example, in one embodiment, the output result of the large language model is: the place with telephone area code 0573 is Jiaxing City, Zhejiang Province, and its license plate code is Zhejiang F.

[0061] It should be noted that after receiving 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 more accurately summarize the correct answer from the reference content.

[0062] S105: Construct a sample according to the question and the answer.

[0063] In specific implementation, in one embodiment, a sample can be constructed directly using questions and answers. In combination with the above example, in this step, the constructed sample is as follows: What is the license plate code of the place with telephone area code 0573? The place with telephone area code 0573 is Jiaxing City, Zhejiang Province, and its license plate code is Zhejiang F.

[0064] The method provided in this embodiment obtains multiple subgraphs corresponding to the question type from the knowledge graph for each question type in the preset multiple question types, and then for each subgraph, converts each group of triple data in each subgraph into natural language text to obtain the natural language text set corresponding to each subgraph, and splices all the groups of triple data of each subgraph and the natural language text set corresponding to each subgraph into the reference content corresponding to each subgraph, thereby generating questions related to the reference content according to the reference content corresponding to each subgraph and the question type corresponding to each subgraph, and generating answers to the questions according to the reference content corresponding to each subgraph and the questions related to the reference content, and then constructing samples according to the questions and the answers. In this way, samples can be generated based on the rich structured information and multi-hop information in the knowledge graph, which 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 improve the diversity of samples based on the diverse topics provided by the knowledge graph, so as to improve the logical reasoning ability of the fine-tuned large language model when facing diverse data.

[0065] Figure 2 This is a flow chart of Example 2 of the sample construction method provided in this application. Please refer to Figure 2 The method provided in this embodiment, based on the above embodiment, constructs a sample according to the question and the answer, including:

[0066] S201, verifying the correctness of the answer relative to the question.

[0067] 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 sample finally constructed.

[0068] Optionally, a large language model can be used as a referee 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 verifies the correctness of the answer relative to the question.

[0069] In a specific implementation, the question and the answer are spliced ​​together according to a preset format template, and the splicing result is input into a large language model, and the large language model verifies the correctness of the answer relative to the question. The preset format template is set according to actual needs, and is not limited in this embodiment. For example, in a possible implementation, the preset format template may be: Please verify the correctness of the following answer relative to the following question, the question is: ...? The answer is ....

[0070] Combined with the above example, in this step, the following content is input into the large language model: Please verify the correctness of the following answer to the following question: What is the license plate code of the place with telephone area code 0573? The answer is that the place with telephone area code 0573 is Jiaxing City, Zhejiang Province, and its license plate code is Zhejiang F.

[0071] Optionally, in a possible implementation manner, the specific implementation process of this step may include:

[0072] 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 verify the answer.

[0073] Specifically, in one 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 the third prompt words related to each question type, and the third prompt words related to each question type are different. The third prompt words corresponding to each question type are constructed in advance by the user. In addition, in another embodiment, the third prompt word can also be constructed in real time.

[0074] In combination with the above example, for example, in a possible implementation, when the question type is an attribute to attribute question, the third prompt word obtained is as follows:

[0075] "Please check for the following error types:

[0076] 1. Insufficient hops. The answer does not follow a logical chain from question to answer.

[0077] 2. Inference error. Attribute 1 may refer to other entities.

[0078] 3. Please give your reasons first. Finally, output [1] indicates correctness, and output [2] indicates error or inability to judge. "

[0079] For another example, in another possible implementation, for multi-hop reasoning problems, the third prompt word obtained may be:

[0080] "For the questions and answers given above, please check for the following types of errors:

[0081] 1. Insufficient number of jumps required to solve the problem. This problem requires at least 2 jumps to solve.

[0082] 2. Not enough steps in the answer. You should think about the answer step by step and not give the answer all at once.

[0083] 3. There are too many hops in the answer. The answer should follow the shortest reasoning path and should not deliberately detour.

[0084] 4. Incorrect reasoning. There is an error in the reasoning process in the answer.

[0085] 5. Redundant information. Knowledge graphs cannot be mentioned in the answers.

[0086] 6. Please give your reasons first. Finally, output [1] means correct, and output [2] means wrong or unable to judge. "

[0087] It should be noted that the third prompt words in the third prompt word library are constructed in advance by the user. 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 from the question to the answer, so that the third prompt words clearly point out the logical chain from the question to the answer and the possible alternative errors.

[0088] It should be noted that the logical chain from question to 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 questions, the logic from question to answer is to deduce a unique entity based on an attribute (attr1), and then deduce another attribute (attr2) of the entity from the entity (entity), that is, its logical chain is: who is the unique entity corresponding to attribute 1, and what is attribute 2 of the entity.

[0089] Furthermore, for a certain type of question, there may be multiple types of errors from question to answer. For example, for attribute-to-attribute questions, the possible alternative error types may be: 1. Insufficient hops, that is, the answer is not reasoned according to attribute 1-entity-attribute 2; 2. Reasoning error, for example, attribute 1 may point to other entities.

[0090] Referring to the above introduction, in this way, when constructing the third prompt word, the third prompt word 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.

[0091] Step 2: Input the third prompt word, the question and the answer into the large language model, so that the large language model verifies the correctness of the answer relative to the question according to the third prompt word, and outputs the verification result.

[0092] In a specific implementation, the third prompt word, the question and the answer can be spliced ​​together according to a preset format template, and then the splicing result can be input into the large language model. Among them, the preset format template is set according to actual needs, and is not limited in this embodiment. For example, in a possible implementation, the preset format template can be: "Third prompt word: .... Question: ...? Answer: ....".

[0093] In the specific implementation, combined with the first example above, the following information can be input into the large language model for verification:

[0094] The third prompt:

[0095] 1. Insufficient hops. The answer does not follow a logical chain from question to answer.

[0096] 2. Inference error. Attribute 1 may refer to other entities.

[0097] 3. Please give your reasons first. Finally, output [1] means correct, and output [2] means wrong or unable to judge.

[0098] Question: What is the license plate code for area code 0573?

[0099] Answer: The area code for the place with telephone area code 0573 is Jiaxing City, Zhejiang Province, and its license plate code is Zhejiang F.

[0100] In combination with the above example, for example, in one embodiment, the output of the large language model is as follows:

[0101] "Hop check: Two jumps are performed in the answer. First, the entity "Zhejiang Jiaxing City" is derived from the telephone area code 0573, and then the license plate code "Zhejiang F" is derived from the entity "Zhejiang Jiaxing City", which conforms to the two-hop structure of attribute 1-entity-attribute 2.

[0102] Reasoning check: 0573 is indeed the telephone area code of Jiaxing City, Zhejiang, and the license plate code of Jiaxing City, Zhejiang is indeed Zhejiang F. Therefore, the reasoning is correct.

[0103] Verification result: [1], verification is correct."

[0104] 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 for the large language model to generate irrelevant content, improving interaction efficiency, and obtaining verification results more quickly and accurately.

[0105] S202: When the answer is correct, combine the question and the answer into a sample.

[0106] In specific implementation, the question and the answer are combined into a sample only when the answer is correct, so that the accuracy of the sample can be guaranteed.

[0107] The method provided in this embodiment verifies the correctness of the answer relative to the question, and then combines the question and the answer into a sample when the answer is correct, so that the accuracy of the sample can be guaranteed.

[0108] Figure 3 This is a flow chart of Example 3 of the sample construction method provided in this application. Please refer to Figure 3 Based on the above embodiment, generating questions related to the reference content according to the obtained reference content and question type of the subgraph includes:

[0109] S301. Obtain a first prompt word related to the question type; wherein the first prompt word is used to guide the large language model to conduct derivation questions related to the question type based on input reference content.

[0110] Specifically, the first prompt word is used to guide the large language model to ask deductive questions related to the question type based on the input reference content, and different question types correspond to different first prompt words.

[0111] In specific implementation, in one 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 corresponding to each question type is stored in the first prompt word library, and each question type has a different first prompt word corresponding to it, and the first prompt word corresponding to each question type is constructed in advance by the user. In another embodiment, the first prompt word can also be constructed in real time.

[0112] It should be noted that the construction method of the first prompt word corresponding to different question types is different, and this embodiment does not limit it. For example, for attribute-to-attribute questions, the first prompt word should clearly require the large language model to be able to derive the corresponding entity based on the given attribute 1, and then derive the attribute 2 of the entity. The first prompt word is mainly used to guide the large language model to perform attribute-to-attribute derivation questions based on the given reference content.

[0113] In addition, for attribute-to-attribute problems, when constructing the first prompt word, it is also necessary to use the first prompt word to guide the large language model to deduce a unique entity based on the given attribute 1.

[0114] Combining the above example, for example, Figure 1 , the first prompt word is as follows:

[0115] "Please combine your existing knowledge and ask questions about the reference content, requiring:

[0116] 1. The question type needs to be an "attribute to attribute question", that is, you need to deduce the corresponding entity based on attribute 1, and then deduce attribute 2 of the entity;

[0117] 2. Ensure that the value of attribute 1 is unique and only corresponds to this entity and cannot correspond to other entities;

[0118] 3. If you are unable to ask a question, please answer “None.”

[0119] S302: Input the first prompt word and the reference content into the large language model, so that the large language model generates questions related to the reference content.

[0120] Specifically, after constructing the first prompt word, the first prompt word and the reference content can be input into the large language model, and the large language model generates questions related to the reference content. In specific implementation, the first prompt word and the reference content can be spliced ​​together according to a preset format template, and then the splicing result can be input into the large language model. Among them, the preset format template is set according to actual needs, and it is not limited in this embodiment. For example, in a possible implementation method, the preset format template can be: "First prompt word. Constraints-reference content: .......".

[0121] Combined with the first example above, in this step, the following information is input into the large language model:

[0122] "Please combine your existing knowledge and ask questions about the reference content, requiring:

[0123] 1. The question type needs to be "attribute to attribute", that is, the corresponding entity needs to be inferred based on attribute 1, and then attribute 2 of the entity needs to be inferred;

[0124] 2. Ensure that the value of attribute 1 is unique and only corresponds to this entity and cannot correspond to other entities;

[0125] 3. If you are unable to ask a question, please answer “None”.

[0126] Constraints - References:

[0127] ("Jiaxing", "license plate number", "Zhe F"), ("Jiaxing", "telephone area code", "0573"); Jiaxing's license plate number is Zhejiang F, and Jiaxing's telephone area code is 0573. "

[0128] The method provided in this embodiment, when generating questions related to the reference content according to the reference content corresponding to the subgraph and the questions corresponding to the subgraph, constructs a first prompt word related to the question type, and then inputs the first prompt word and the reference content into the large language model, so that the large language model generates questions related to the reference content. In this way, the large language model can be guided by the first prompt word to conduct derivation questions related to the question type according to the input reference content, which can not only make the generated questions closer to the core points of the reference content, avoid generating vague or inaccurate questions, and improve the relevance, pertinence and accuracy of the questions, but also guide the large language model to generate diversified questions through different prompt words, covering all aspects of the reference content, so as to further improve the diversity of samples.

[0129] Figure 4 This is a flow chart of Example 4 of the sample generation method provided by this application. Please refer to Figure 4 The method provided in this embodiment, based on the above embodiment, generates an answer to the question according to the reference content corresponding to each sub-graph and the question related to the reference content, including:

[0130] S401. Obtain a second prompt word; wherein the second prompt word is used to guide the large language model to perform reasoning according to existing knowledge and input reference content, and answer questions based on the reasoning.

[0131] Specifically, in order to better guide the large language model to infer based on existing knowledge and input reference content and answer questions based on reasoning, it is necessary to obtain a second prompt word to guide the large language model to infer and answer questions based on existing knowledge and reference content to ensure the accuracy, logical integrity and rationality of the answer.

[0132] In specific implementation, the second prompt word can be directly obtained from a pre-built prompt word library, or the second prompt word can be constructed in real time. This embodiment is not limited thereto. For example, in one embodiment, the second prompt word obtained is as follows:

[0133] "Please combine your existing knowledge and reference content to answer the following questions. Requirements:

[0134] 1. Think step by step first, and then give the answer at the end;

[0135] 2. Reference content cannot be mentioned;

[0136] 3. You can add your own knowledge and understanding, and please correct any factual errors. "

[0137] S402. Input the second prompt word, the reference content corresponding to each subgraph, and questions 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 based on the second prompt word and the reference content corresponding to each subgraph to generate an answer to the question.

[0138] In specific implementation, the second prompt word, the reference content corresponding to each sub-graph, and the questions related to the reference content can be spliced ​​together according to the preset format template, and then the splicing result is input into the large language model. Among them, the preset format template is set according to actual needs and will not be limited in this embodiment.

[0139] Combined with the above sub Figure 1 Corresponding example, for example, in a possible implementation, in this step, the following information is input into the large language model:

[0140] "Please combine your existing knowledge and reference content to answer the following questions. Requirements:

[0141] 1. Think step by step first, and then give the answer at the end;

[0142] 2. Reference content cannot be mentioned;

[0143] 3. You may add your own knowledge and understanding, and please correct any factual errors.

[0144] [Triple data begins]

[0145] ("Jiaxing", "license plate number", "Zhejiang F"), ("Jiaxing", "telephone area code", "0573")

[0146] [End of triplet data]

[0147] [Natural language text begins]

[0148] The license plate number of Jiaxing City is Zhejiang F and the telephone area code is 0573.

[0149] [END OF NATURAL LANGUAGE TEXT]

[0150] [Question begins]

[0151] What is the license plate code for area code 0573?

[0152] [End of Questioning]”

[0153] Further, for example, in one embodiment, combined 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 Zhejiang F.

[0154] The method provided in this embodiment, when generating an answer to a question based on the reference content corresponding to each subgraph and the question related to 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 based on the second prompt word and the reference content corresponding to each subgraph to generate an answer to the question. In this way, the second prompt word can clearly indicate the key points that the large language model needs to pay attention to during the reasoning process, 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.

[0155] Figure 5 This is a flow chart of Example 5 of the sample construction method provided in this application. Please refer to Figure 5 , the method provided in this embodiment may include:

[0156] S501. For each question type among a plurality of preset question types, obtain a plurality of subgraphs corresponding to the question type from the knowledge graph.

[0157] Specifically, the specific implementation process and implementation principle of step S501 refer to the description in the previous embodiment and will not be described again here.

[0158] S502: Obtain a fourth prompt word; wherein the fourth prompt word is used to guide the large language model to convert triple data into natural language text.

[0159] Specifically, the fourth prompt word is used to guide the large language model to convert the triple data into natural data text. The fourth prompt word can be obtained from a preset prompt word library or constructed in real time. In this embodiment, it is not limited. For example, in a possible implementation, the fourth prompt word obtained can be: Please combine your existing knowledge to represent the knowledge graph path represented by the following triple (subject, relationship, object) into natural language text.

[0160] S503 . For each subgraph, input the fourth prompt word and all triplet data in the subgraph into the large language model, so that the large language model outputs a natural language text set corresponding to the subgraph.

[0161] In specific implementation, the fourth prompt word and all triplet data in the subgraph can be spliced ​​together according to a preset format template, and then the splicing result is input into the large language model. The preset format template is set according to actual needs and is not limited in this embodiment.

[0162] For example, combined with the above Figure 1 For example, in this step, the following content is input into the large language model:

[0163] "Please combine your existing knowledge to express the knowledge graph path represented by the following triples (subject, relationship, object) into natural language text. [Triple data starts] ("Jiaxing", "license plate number", "Zhejiang F"), ("Jiaxing", "telephone area code", "0573") [Triple data ends] ” 。

[0164] The method provided in this embodiment, when converting each group of triple data in each subgraph into natural language text to obtain the natural language text set 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, so that the large language model outputs the natural language text set corresponding to the subgraph. In this way, the understanding and processing time of the large language model when generating natural language text can be reduced, the conversion efficiency can be improved, and the large language model can generate natural language text more quickly.

[0165] S504: Concatenate all the triplet data of the subgraph and the natural language text set corresponding to the subgraph into reference content corresponding to the subgraph.

[0166] Specifically, the specific implementation principle and implementation process of step S504 can be found in the description of the previous embodiment, which will not be repeated here.

[0167] 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 ask derivation questions related to the question type based on the input reference content.

[0168] The specific implementation process and implementation principle of this step can refer to the description in the previous embodiment. For example, in one embodiment, for the problem of comparing different instance attributes, in one embodiment, the first prompt word constructed is as follows:

[0169] Based on the above introduction, design a question that requires:

[0170] 1. The problem is about comparing a single attribute of multiple entities;

[0171] 2. Questions should have objective answers;

[0172] 3. Just give the question, no extra explanation. "

[0173] S506: Input the first prompt word and the reference content into the large language model, so that the large language model generates questions related to the reference content.

[0174] S507, obtaining a second prompt word; wherein the second prompt word is used to guide the large language model to perform reasoning according to existing knowledge and input reference content, and answer questions based on the reasoning.

[0175] S508. Input the second prompt word, the reference content corresponding to each subgraph, and questions 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 based on the second prompt word and the reference content corresponding to each subgraph to generate an answer to the question.

[0176] S509, obtaining a third prompt word; wherein the third prompt word is used to guide the large language model to verify the answer.

[0177] S510: Input the third prompt word, the question and the answer into the large language model, so that the large language model verifies the correctness of the answer with respect to the question according to the third prompt word, and outputs a verification result.

[0178] S511. When the answer is correct, combine the question and the answer into a sample.

[0179] Specifically, the specific implementation principle and implementation process of steps S506 to S511 can be found in the description of the previous embodiment, and will not be repeated here.

[0180] The method provided in this embodiment obtains multiple subgraphs corresponding to the question type from the knowledge graph for each question type in the preset multiple question types, and then for each subgraph, converts each group of triple data in each subgraph into natural language text to obtain the natural language text set corresponding to each subgraph, and splices all the groups of triple data of each subgraph and the natural language text set corresponding to each subgraph into the reference content corresponding to each subgraph, thereby generating questions related to the reference content according to the reference content corresponding to each subgraph and the question type corresponding to each subgraph, and generating answers to the questions according to the reference content corresponding to each subgraph and the questions related to the reference content, and then constructing samples according to the questions and the answers. In this way, samples can be generated based on the rich structured information and multi-hop information in the knowledge graph, which 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 improve the diversity of samples based on the diverse topics provided by the knowledge graph, so as to improve the logical reasoning ability of the fine-tuned large language model when facing diverse data.

[0181] The present application also provides a large language model fine-tuning method, the method comprising:

[0182] (1) Obtaining samples;

[0183] In specific implementation, any method provided in the first aspect of the present application may be used to obtain samples, which will not be described in detail here.

[0184] (2) Using the sample to fine-tune the parameters of the large language model.

[0185] The method provided in this embodiment can improve the logical reasoning ability of the large language model by obtaining samples and then using the samples to fine-tune the large language model.

[0186] Corresponding to the aforementioned embodiment of a sample construction method, the present application also provides an embodiment of a sample construction device.

[0187] The embodiment of a sample construction device of the present application can be applied to a sample construction device. The device embodiment can be implemented by software, or by hardware or a combination of software and hardware. Taking software implementation as an example, as a device in a logical sense, it is formed by the processor of the sample construction device in which it is located reading the corresponding computer program instructions in the non-volatile memory into the memory and running them. From the hardware level, if Figure 6 As shown, it is a hardware structure diagram of the sample construction device provided by the present application where the sample construction device is located, except Figure 6In addition to the processor, memory, network interface, and non-volatile memory shown, the sample construction device where the device in the embodiment is located may also include other hardware according to the actual function of the sample construction device, which will not be described in detail.

[0188] Figure 7 This is a schematic diagram of the structure of the sample construction device embodiment 1 provided in this application. Figure 7 The device provided in this embodiment includes an acquisition module 710, a conversion module 720, a generation module 730 and a construction module 740; wherein,

[0189] The acquisition module 710 is used to acquire, for each question type among the preset multiple question types, multiple subgraphs corresponding to the question type from the knowledge graph;

[0190] The conversion module 720 is used to convert each group of triple data in each subgraph into natural language text for each subgraph, obtain a natural language text set corresponding to each subgraph, and splice all groups of triple data of each subgraph and the natural language text set corresponding to each subgraph into reference content corresponding to each subgraph;

[0191] The generating module 730 is used to generate questions related to the reference content according to the reference content corresponding to each sub-graph and the question type corresponding to each sub-graph;

[0192] The generating module 730 is used 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;

[0193] The construction module 740 is used to construct a sample according to the question and the answer.

[0194] The device of this embodiment can be used to perform Figure 1 The steps, specific implementation principles and implementation processes of the method embodiment shown are similar and will not be repeated here.

[0195] Please continue to refer to Figure 6 The present application also provides a sample construction device, including a memory, a processor, and a computer program stored in the memory and executable on the processor, wherein when the processor executes the program, the steps of any one of the methods provided in the first aspect of the present application are implemented.

[0196] The present application also provides a computer-readable storage medium having a computer program stored thereon, and when the program is executed by a processor, the steps of any one of the methods provided in the present application are implemented.

[0197] The implementation process of the functions and effects of each unit in the above-mentioned device is specifically described in the implementation process of the corresponding steps in the above-mentioned method, and will not be repeated here.

[0198] For the device embodiment, since it basically corresponds to the method embodiment, the relevant parts can refer to the partial description of the method embodiment. The device embodiment described above is only schematic, wherein the units described as separate components may or may not be physically separated, and the components displayed as units may or may not be physical units, that is, they may be located in one place, or they may be distributed on multiple network units. Some or all of the modules may be selected according to actual needs to achieve the purpose of the present application scheme. A person of ordinary skill in the art can understand and implement it without paying any creative work.

[0199] The above description is only a preferred embodiment of the present application and is not intended to limit the present application. Any modifications, equivalent substitutions, improvements, etc. made within the spirit and principles of the present application shall be included in the scope of protection of the present application.

Claims

1. A sample construction method, characterized in that: The method comprises: For each of the preset multiple question types, obtain multiple subgraphs corresponding to the question type from the knowledge graph; For each subgraph, convert each set of triple data in each subgraph into natural language text to obtain a natural language text set corresponding to each subgraph, and splice all sets of triple data of each subgraph and the natural language text set corresponding to each subgraph into reference content corresponding to each subgraph; Generate questions related to the reference content according to the reference content corresponding to each subgraph and the question type corresponding to each subgraph; Generate an answer to the question based on the reference content corresponding to each subgraph and the question related to the reference content; A sample is constructed based on the questions and the answers.

2. The method according to claim 1, characterized in that For each of the preset multiple question types, obtaining multiple subgraphs corresponding to the question type from the knowledge graph includes: For each of the preset multiple question types, a target sampling rule corresponding to the question type is obtained from the preset multiple sampling rules; wherein different question types correspond to different sampling rules; Subgraphs are collected from the knowledge graph according to the target sampling rule to obtain multiple subgraphs corresponding to the question type.

3. The method according to claim 1, characterized in that: Construct a sample based on the questions and answers, including: Verifying the correctness of the answer relative to the question; When the answer is correct, the question and the answer are combined into one sample.

4. The method according to claim 1, characterized in that: The generating of questions related to the reference content according to the reference content corresponding to each sub-graph and the question type corresponding to each sub-graph includes: Acquire a first prompt word related to the question type; wherein the first prompt word is used to guide the large language model to ask derivation questions related to the question type based on the input reference content; The first prompt word and the reference content are input into the large language model so that the large language model generates questions related to the reference content.

5. The method according to claim 1, characterized in that The step of generating an answer to a question based on the reference content corresponding to each subgraph and a question related to the reference content includes: Obtaining a second prompt word; wherein the second prompt word is used to guide the large language model to perform reasoning based on existing knowledge and input reference content, and answer questions based on reasoning; The second prompt word, the reference content corresponding to each subgraph, and questions related to the reference content are input into the large language model, so that the large language model can infer the question related to the reference content based on the second prompt word and the reference content corresponding to each subgraph to generate an answer to the question.

6. The method according to claim 3, characterized in that: Verifying the correctness of the answer includes: Acquire a third prompt word related to the question type; wherein the third prompt word is used to guide the large language model to verify the answer; The third prompt word, the question and the answer are input into the large language model, so that the large language model verifies the correctness of the answer with respect to the question according to the third prompt word, and outputs a verification result.

7. The method according to claim 1, characterized in that Each set of triple data in each subgraph is converted into natural language text, and the natural language text set corresponding to each subgraph is obtained, including: Obtaining 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; The fourth prompt word and all triplet data in the subgraph are input into the large language model, so that the large language model outputs a natural language text set corresponding to the subgraph.

8. A large language model fine-tuning method, characterized in that: The method comprises: Obtaining a sample using the method according to any one of claims 1 to 7; The samples are used to fine-tune parameters of the large language model.

9. A device for constructing a sample, characterized in that: The device comprises an acquisition module, a conversion module, a generation module and a construction module; wherein, The acquisition module is used to acquire, for each question type among the preset multiple question types, multiple subgraphs corresponding to the question type from the knowledge graph; The conversion module is used to convert each group of triple data in each subgraph into natural language text for each subgraph, obtain a natural language text set corresponding to each subgraph, and splice all groups of triple data of each subgraph and the natural language text set corresponding to each subgraph into reference content corresponding to each subgraph; The generating module is used to generate questions related to the reference content according to the reference content corresponding to each sub-graph and the question type corresponding to each sub-graph; The generating module is used 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; The construction module is used to construct a sample according to the question and the answer.

10. A device for constructing a sample, characterized in that The method comprises a memory, a processor and a computer program stored in the memory and executable on the processor, wherein the processor implements the steps of the method according to any one of claims 1 to 7 when executing the program.

Citation Information

Patent Citations

  • Question response method and device based on knowledge graph, medium and computer equipment

    CN116821301A

  • 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

Cited By

  • Corpus processing method and apparatus based on paradigm evolution, and device, medium, and product

    WO2026152886A1