Knowledge base question and answer method and system under full-process large language model small sample learning
By employing a full-process large language model few-shot learning method, and leveraging the powerful natural language capabilities of the large language model, the knowledge base question-answering process is simplified and its accuracy is improved. This addresses the problem of insufficient model robustness in existing technologies and enhances the generalization ability of knowledge base question answering.
Patent Information
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- ZHEJIANG UNIV
- Filing Date
- 2024-05-27
- Publication Date
- 2026-06-02
AI Technical Summary
In existing technologies, the process of knowledge base question answering is complex and the models are not robust enough, making it difficult to efficiently complete each sub-task using large language models.
The method employs a full-process large language model few-shot learning approach, leveraging the few-shot learning capability of the large language model to achieve question parsing, query template generation, knowledge base linking, and answer generation. It utilizes pre-built knowledge base information indexes and prompt words to complete various sub-tasks of knowledge base question answering.
No additional model training is required for knowledge base question answering tasks, which improves the robustness and accuracy of knowledge base question answering and enhances the model's generalization performance across different knowledge bases.
Smart Images

Figure CN118520086B_ABST
Abstract
Description
Technical Field
[0001] This invention belongs to the field of natural language processing, and in particular relates to a knowledge base question answering method and system based on small-sample learning of a large language model throughout the entire process. Background Technology
[0002] In late 2022, the emergence of ChatGPT demonstrated the powerful language capabilities of large-scale language models. In the traditional knowledge base question answering field, dedicated models are often trained for different steps of the knowledge base question answering process to complete various sub-tasks. This makes the knowledge base question answering construction process complex and the models less robust. Therefore, how to leverage the powerful natural language capabilities of large language models and reconstruct the knowledge base question answering process based on their strengths, so that each sub-process can be completed by a single large language model, is a pressing problem that needs to be solved. Summary of the Invention
[0003] The purpose of this invention is to solve the problems existing in the prior art and to provide a knowledge base question answering method and system based on small sample learning of a large language model throughout the entire process.
[0004] To achieve the above-mentioned objectives, the present invention specifically adopts the following technical solution:
[0005] Firstly, this invention provides a knowledge base question answering method based on small-sample learning of a large language model throughout the entire process, including the following steps:
[0006] S1. Obtain a user question expressed in natural language. Input the user question, a set of question parsing examples, and pre-constructed first prompt words into the large language model. Use the small sample learning capability of the large language model to realize question parsing, identify multiple candidate triples in the user question and construct a candidate triple set, and output the type of the user question.
[0007] S2. Input the candidate triple set, user question type, a set of query template generation examples, and pre-constructed second prompt words into the large language model. Through the small sample learning capability of the large language model, query templates are generated to obtain query statement templates for knowledge base queries.
[0008] S3. For each named entity and the relationship between entities in the query statement template, the constructed knowledge base and entity information index are used, and the knowledge base is linked by the small sample learning ability of the large language model. Then, a set of candidate entity or relationship knowledge base representations are obtained according to the knowledge base linking method.
[0009] S4. Replace the named entities in the query statement template with a set of candidate entity knowledge base representations, and replace the relations in the query statement template with a set of candidate relation knowledge base representations. After replacement, a set of query statements is formed. Use the query statements to search in the knowledge base to obtain the query results. Based on the type of user question and the query results, adopt different strategies to generate answers and output the final results.
[0010] Based on the above scheme, each step can be implemented in the following preferred manner.
[0011] Preferably, in step S1, the user question belongs to one of three types: entity query, yes / no judgment, and counting.
[0012] Preferably, in step S2, the query statement template includes a set of entities and the relationships between entities, wherein the entities in the query statement template are named entities or placeholder entities.
[0013] As a preferred embodiment, the specific process of obtaining a set of candidate entity or relation knowledge base representations according to the knowledge base linking method in step S3 is as follows:
[0014] S31. Obtain the entity information index from the knowledge base. The entity information index includes the entity name, the unique representation in the knowledge base, and the entity description information.
[0015] S32. For named entities in the query statement template, query the entity information index according to the name of the named entity to obtain a set of candidate entities, wherein each entity in the entity set contains a unique representation and entity description information in the knowledge base;
[0016] S33. Input the user question, entity name, a set of candidate entity sets, a set of knowledge base link examples, and pre-constructed third prompt words into the large language model. Through the small-sample learning driving capability of the large language model, knowledge base linking is realized to obtain a set of candidate entity knowledge base representations.
[0017] S34. For the relation in the query statement template, after obtaining the knowledge base representation of the two entities corresponding to the relation, query in the knowledge base to obtain the relation representation that is related to the two entities in the knowledge base, and after semantic sorting, form a set of candidate relation representations;
[0018] S35. Input the user question, the knowledge base representations of the two entities corresponding to the relationship, a set of candidate relationship representations, a set of new knowledge base link examples, and the pre-constructed fourth prompt word into the large language model. Through the small-sample learning driving capability of the large language model, the knowledge base is linked to obtain a set of candidate relationship knowledge base representations.
[0019] Preferably, the specific process of step S4 is as follows:
[0020] If the user's question is a yes / no judgment and the query result is no, the pre-constructed fifth prompt word and the user's question are input into the large language model, and the large language model is required to output yes or no. The output of the large language model is then taken as the final result.
[0021] If the user's question is a yes / no judgment and the query result is yes, then the final result is yes;
[0022] If the user's question is not a yes / no question and a query result is returned, then the query result will be used as the final result.
[0023] If the user's question is not a true / false question and no query results are returned, the pre-constructed sixth prompt word and the user's question are input into the large language model. The large language model is required to output a set of answer entities, and the knowledge base representation of the answer entity corresponding to the answer entity is obtained through the knowledge base linking method in S3. The answer entity knowledge base representation is used as the final result.
[0024] As a preferred option, Elasticsearch is used when retrieving entity information indexes from the knowledge base.
[0025] Secondly, this invention provides a knowledge base question-answering system based on small-sample learning of a large language model throughout the entire process, comprising:
[0026] The question parsing module is used to obtain a user question expressed in natural language. The user question, a set of question parsing examples, and pre-constructed first prompt words are input into the large language model. The large language model realizes question parsing through few-shot learning ability, identifies multiple candidate triples in the user question and constructs a candidate triple set, and outputs the type of the user question.
[0027] The query template generation module is used to input the candidate triple set, the user question type, a set of query template generation examples, and the pre-constructed second prompt words into the large language model. The query template is generated through the small sample learning capability of the large language model to obtain a query statement template for knowledge base query.
[0028] The knowledge base linking module is used to index each named entity and the relationship between entities in the query statement template using the constructed knowledge base and entity information, and to achieve knowledge base linking by the small sample learning capability of the large language model, thereby obtaining a set of candidate entity or relationship knowledge base representations according to the knowledge base linking method;
[0029] The answer generation module is used to replace named entities in the query statement template with a set of candidate entity knowledge base representations, and replace relations in the query statement template with a set of candidate relation knowledge base representations. After replacement, a set of query statements are formed. The query statements are used to search the knowledge base to obtain the query results. Different strategies are adopted to generate answers based on the type of user question and the query results, and the final result is output.
[0030] Thirdly, the present invention provides a computer-readable storage medium storing a computer program that, when executed by a processor, implements the knowledge base question-answering method under the full-process large language model few-shot learning described in the first aspect.
[0031] Fourthly, the present invention provides a computer electronic device, including a memory and a processor;
[0032] The memory is used to store computer programs;
[0033] The processor is configured to implement the knowledge base question answering method under the full-process large language model few-shot learning described in the first aspect when executing the computer program.
[0034] Fifthly, the present invention provides a computer program product, including a computer program / instruction, which, when executed by a processor, can realize the knowledge base question answering method under the full-process large language model small-sample learning described in the first aspect.
[0035] Compared with the prior art, the present invention has the following advantages:
[0036] 1) Leveraging the powerful few-shot learning capabilities of large language models, no additional model training is required for knowledge base question answering tasks;
[0037] 2) It exhibits strong robustness across different knowledge bases, enhancing the generalization performance of knowledge base question answering;
[0038] 3) Leverage the powerful knowledge reserves of large language models to improve the accuracy of knowledge base question answering. Attached Figure Description
[0039] Figure 1 This is a schematic diagram of the steps of the method of the present invention;
[0040] Figure 2 This is a system block diagram of the method of the present invention;
[0041] Figure 3 This is a detailed flowchart of the method of the present invention. Detailed Implementation
[0042] To make the above-mentioned objects, features, and advantages of the present invention more apparent and understandable, the specific embodiments of the present invention will be described in detail below with reference to the accompanying drawings. Many specific details are set forth in the following description to provide a thorough understanding of the present invention. However, the present invention can be practiced in many other ways different from those described herein, and those skilled in the art can make similar modifications without departing from the spirit of the present invention. Therefore, the present invention is not limited to the specific embodiments disclosed below. Technical features in the various embodiments of the present invention can be combined accordingly without mutual conflict.
[0043] In the description of this invention, it should be understood that the terms "first" and "second" are used only for descriptive purposes and should not be construed as indicating or implying relative importance or implicitly specifying the number of indicated technical features. Therefore, a feature defined with "first" and "second" may explicitly or implicitly include at least one of those features.
[0044] Leveraging the powerful natural language capabilities of large language models, this invention reconstructs the knowledge base question-answering process based on the strengths of these models, ensuring that each sub-process can be completed by a single large language model. The key feature of this invention is that the entire knowledge base question-answering process is handled by the large language model. This model does not require separate training for each sub-process; instead, it utilizes few-shot learning, leveraging the small-shot learning capabilities of the large language model to complete each sub-process, thus achieving zero-training knowledge base question-answering. Figure 3 As shown.
[0045] The knowledge base question answering task is defined as follows: given a user question expressed in natural language, the user question is parsed and processed to form a graph database query statement that can be queried in the knowledge base, and relevant knowledge entities are retrieved in the knowledge base to answer the user's question.
[0046] like Figure 1 As shown, in a preferred implementation of the present invention, the knowledge base question answering method under the full-process large language model few-shot learning mainly divides the knowledge base question answering task into the following four sub-tasks: question parsing, query template construction, knowledge base linking, and answer generation. These four sub-tasks are related to each other and cooperate with each other to form the knowledge base question answering method of the present invention. The knowledge base question answering method under the full-process large language model few-shot learning of the present invention includes steps S1 to S4, each step corresponding to the implementation of a sub-task. The specific implementation process is described in detail below.
[0047] I. Problem Analysis
[0048] S1. Obtain a user question expressed in natural language. Input the user question, a set of question parsing examples, and pre-constructed first prompt words into the large language model. Use the small sample learning capability of the large language model to perform question parsing, identify multiple candidate triples in the user question and construct a candidate triple set, and output the type of the user question.
[0049] In step S1 of this invention, the types of user questions mentioned above include three types: entity query, yes / no judgment, and counting.
[0050] It should be noted that the problem analysis subtask mainly involves multi-dimensional analysis of user questions given in natural language representation, in order to facilitate the subsequent process. It mainly includes the following two aspects of analysis: (1) determining the type of user question and selecting from three types: <count> / <query> / <yes / no judgment>; (2) determining which potential triples (i.e., candidate triples) are contained in the user question. The triple is represented as <entity, relation, entity>. Unknown or unqueried entities can be represented by placeholders.
[0051] For a user question Q, implement a question parser using the language capabilities of a large language model. Given a set of question parsing examples... and the pre-built first prompt word Prompt parser The requirement is for the large language model to analyze the user question Q and extract the set of candidate triples T = {t1, t2, ..., t...} n} and the type of user problem Q t .in, These are the first, second, and third examples in a set of problem-solving examples; t i For the i-th triplet, it can be represented in detail as t i = <head i ,p i ,tail i >, head i and tail i All are named entities or placeholder entities, represented by the placeholder symbol ? variable, p i head i and tail i The relationship between them.
[0052] II. Query Template Generation
[0053] S2. Input the candidate triple set, user question type, a set of query template generation examples, and pre-constructed second prompt words into the large language model. Through the small-sample learning capability of the large language model, query templates are generated to obtain query statement templates for knowledge base queries.
[0054] In step S2 of the present invention, the query statement template includes a set of entities and the relationships between entities, wherein the entities in the query statement template are named entities or placeholder entities.
[0055] It should be noted that the query template generation subtask constructs a query statement (SPARQL) template for knowledge base querying based on the question parsing results in the question parsing, targeting the user question in natural language. This template is not a statement that can be directly queried. It needs to replace the representation in this template in subsequent steps to convert it into a statement that can be directly queried in the knowledge base (KB), so as to match the precise knowledge in the knowledge base that can answer the user question.
[0056] For the user question Q mentioned above, the language capabilities of the large language model are used to implement the query template generation constructor. In the query template generation subtask, the user question Q and the candidate triplet set T = {t1, t2, ..., t} parsed in the previous step are used. n} and Question Type Q t Examples are provided to the same large language model, supplemented by a set of query templates. and the pre-built second prompt word Prompt constructor The requirement is for the large language model to generate a query statement template, where... These are the first, second, and third examples generated from a set of query templates, respectively.
[0057] III. Knowledge Base Links
[0058] S3. For each named entity and the relationship between entities in the query statement template, the constructed knowledge base and entity information index are used, and the knowledge base is linked by the small sample learning capability of the large language model. Then, a set of candidate entity or relationship knowledge base representations are obtained according to the knowledge base linking method.
[0059] In step S3 of this invention, when obtaining the entity information index in the knowledge base, the Elasticsearch tool is used.
[0060] In step S3 of this invention, the specific process of obtaining a set of candidate entity or relation knowledge base representations according to the knowledge base linking method is as follows:
[0061] S31. Obtain the entity information index from the knowledge base. The entity information index includes the entity name, the unique representation in the knowledge base, and the entity description information.
[0062] S32. For named entities in the query statement template, query the entity information index according to the name of the named entity to obtain a set of candidate entities, wherein each entity in the entity set contains a unique representation and entity description information in the knowledge base;
[0063] S33. Input the user question, entity name, a set of candidate entity sets, a set of knowledge base link examples, and pre-constructed third prompt words into the large language model. Through the small-sample learning driving capability of the large language model, knowledge base linking is realized to obtain a set of candidate entity knowledge base representations.
[0064] S34. For the relation in the query statement template, after obtaining the knowledge base representation of the two entities corresponding to the relation, query in the knowledge base to obtain the relation representation that is related to the two entities in the knowledge base, and after semantic sorting, form a set of candidate relation representations;
[0065] S35. Input the user question, the knowledge base representations of the two entities corresponding to the relationship, a set of candidate relationship representations, a set of new knowledge base link examples, and the pre-constructed fourth prompt word into the large language model. Through the small-sample learning driving capability of the large language model, the knowledge base is linked to obtain a set of candidate relationship knowledge base representations.
[0066] It should be noted that the knowledge base linking subtask mainly targets a given user question. After question parsing and query template generation, it links the resulting set of candidate triples to relevant entities and relation representations in the knowledge base. Since knowledge in the knowledge base is mostly expressed in formal formats such as URIs, which differ somewhat from human natural language, a knowledge base linking step is needed to convert it for subsequent steps.
[0067] 1) Preliminary steps
[0068] For a given Knowledge Base (KB), use Elasticsearch tools to build an index of entity information within the Knowledge Base (KB). e This facilitates efficient subsequent queries. The entity information index should at least store the unique URIs of entities and relationships in the knowledge base, along with abstract descriptions of the entities and relationships.
[0069] 2) Method
[0070] For user queries, after obtaining the result of question parsing (candidate triple set) T and query statement template, the knowledge base linking step needs to process the named entities and relationships between entities in the query statement template Template one by one, and match a set of candidate knowledge base representations in the pre-built knowledge base KB.
[0071] Specifically, the knowledge base linking process proposed in this invention, Linker, queries the entity information index for the names of named entities, retrieves the top k entities, constructs a candidate entity set, and provides a prompt to the large language model through input. linker The task is to have the large language model select a set of candidate entity knowledge base representations from the aforementioned candidate entity set. It is important to note that the knowledge base linking process does not process placeholder entities; it only retains the original representation of the variable.
[0072] Furthermore, the method of this invention also requires linking relationships between entities in the knowledge base linking subtask Linker. Specifically, for each relationship in the query statement template, the relationship representations of all relationships connected to its two end entities are obtained in the knowledge base, and semantically sorted to finally obtain a set of candidate relationship representations, Candidates(p i This set contains the top k possible relation representations; by providing a prompt to the large language model... linker The requirement is for a large language model to select a set of candidate relation knowledge base representations from a set of candidate relation representations.
[0073] Through the above steps, the method of the present invention can match named entities and relationships between entities in the query statement template to a set of candidate knowledge base representations, wherein each named entity obtains a set of candidate entity knowledge base representations, and each relationship obtains a set of candidate relationship knowledge base representations.
[0074] IV. Answer Generation
[0075] S4. Replace the named entities in the query statement template with a set of candidate entity knowledge base representations, and replace the relations in the query statement template with a set of candidate relation knowledge base representations. After replacement, a set of query statements is formed. Use the query statements to search in the knowledge base to obtain the query results. Based on the type of user question and the query results, adopt different strategies to generate answers and output the final results.
[0076] The specific process of step S4 of the present invention is as follows:
[0077] If the user's question is a yes / no judgment and the query result is no, the pre-constructed fifth prompt word and the user's question are input into the large language model, and the large language model is required to output yes or no. The output of the large language model is then taken as the final result.
[0078] If the user's question is a yes / no judgment and the query result is yes, then the final result is yes;
[0079] If the user's question is not a yes / no question and a query result is returned, then the query result will be used as the final result.
[0080] If the user's question is not a true / false question and no query results are returned, the pre-constructed sixth prompt word and the user's question are input into the large language model. The large language model is required to output a set of answer entities, and the knowledge base representation of the answer entity corresponding to the answer entity is obtained through the knowledge base linking method in S3. The answer entity knowledge base representation is used as the final result.
[0081] It should be noted that the Generator subtask is mainly responsible for organizing the final answer, returning the final relevant entities that match the user's question to the user, and finally completing the entire task.
[0082] The answer generation subtask first generates a set of candidate knowledge base query statements (Candidates(SPARQL) = {SPARQL1, SPARQL2, ..., SPARQL3}) based on the knowledge base query template (Template), a set of candidate entity knowledge base representations, and a set of candidate relation knowledge base representations. n The system then searches the knowledge base and records the SPARQL query results that yield the results. Based on the type of user question and the query results, different strategies are adopted to generate answers and output the final results.
[0083] a. If the user's question belongs to type Q t If the query result in KB is "No" and the query is "Yes or No", the pre-constructed fifth prompt word and the user's question are input into the large language model. The large language model is required to output "Yes" or "No", and the output of the large language model is taken as the final result.
[0084] b. If the user's question belongs to type Q t If the query result in KB is "yes" and the query result in KB is "yes", then the final output result will be "yes".
[0085] c. If the user's question belongs to type Q t If the query result is not a "yes or no" statement and a query result is returned in KB, then the query result in KB will be taken as the final result.
[0086] d. If the type Q to which the user's question belongs t is not <Yes / No Judgment> and no query result is returned in the KB, the pre-constructed sixth prompt word and the user's question are input into the large language model, and the large language model is required to output a set of answer entities, and the knowledge base linking method in step S3 is used for knowledge base linking to obtain the knowledge base representation of the answer entity corresponding to the answer entity, and the knowledge base representation of the answer entity is used as the final result. In addition, when obtaining the knowledge base representation of the answer entity, the method for obtaining a set of candidate knowledge base representations corresponding to the named entity is the same, that is, it can be obtained according to the step process of S31~S33, which will not be elaborated in this embodiment.
[0087] To better demonstrate the specific implementation and technical effects of the present invention, the knowledge base question-answering method under the few-shot learning of the large language model shown in steps S1~S4 in the above preferred implementation manner will be applied to a specific example below. The implementation process of each step is as described above and will not be elaborated.
[0088] Embodiment
[0089] The following gives an example of using the method described in the present invention for knowledge base question-answering. For the user question Q: Which television show's producer is Stephen E. Ambrose and written by Erik Jendresen?, the Chinese translation of this question is: "Which TV drama has Stephen E. Ambrose as the producer and Erik Jendresen as the writer?"
[0090] I. Problem analysis
[0091] a) Triple parsing:
[0092] i. The prompt Prompt_parser provided to the large language model in the problem analysis part is "You are an assistant, and your task is to extract triples from the specified sentence. The following are the requirements for you: (1) The given sentence should contain at least one triple; (2) The format of the triple is <entity, relationship, entity>; (3) The entity should be the smallest semantic unit and cannot contain any descriptive information; (4) The entity can be explicit or implicit. An explicit entity is a specific resource that can be directly named, while an implicit entity is an uncertain object; (5) Whether it is an implicit or explicit entity, it should be a noun. (6) For an implicit entity, use a variable in the format of '? variable' to represent it, for example,? place,? country, etc. (7) The relationship can also be implicit and should be inferred from the sentence as much as possible."
[0093] ii. An example of a set of problem analysis For: "### Input sentence: Which city was founded by John Forbes? Output triple: <?city,foundeer,John Forbes>### Input sentence: How many races did the horses bred by Jacques Van't Hart participate in? Output triple: <?horse,participatedin,?race><?horse,breeder,Jacques Van't Hart>### Input sentence: Do camels belong to the phylum Chordata? Output triple:"<camel,phylum,chordate> ###".
[0094] Example E of the above set of problem analyses parser The document contains three examples, with ### marking the start or end of each example. The Chinese translations of <? city, founder, John Forbes> are: <? city, founder, John Forbes>; <? horse, participated in, race> are: <? horse, participated in, race>; and <? horse, breeder, Jacques Van't Hart> are: <? horse, breeder, Jacques Van't Hart>.<camel,phylum,chordate> The Chinese expression for it is <camel, phylum, chordate>.
[0095] iii. For example problem Q, after applying the problem parsing method described in S1, the set of candidate triples output by the problem parsing part is T = {t1, t2, ..., t...} n The string is: "<?television_show,producer,Stephen E.Ambrose><?television_show,written by,Erik Jendresen>", which is expressed in Chinese as <?television_show,producer,Stephen E.Ambrose><?television_show,written by,Erik Jendresen>.
[0096] b) Problem Type Analysis
[0097] i. The prompt provided to the large language model in the middle for question parsing is: "As an assistant, your task is to identify the type of a given question. The specific requirements are as follows: (1) You need to identify the most likely type of the input question; (2) Please enclose the question type in “<” and ">” symbols; (3) Identifiable question types include: <counting>, <entity query> and <yes or no>".
[0098] ii. Examples of problem analysis For the following questions: "### Input question: Which city was John Forbes the founder of? Question type: <Entity query>### Input question: How many races did Jacques van der Hart's horses participate in? Question type: <Counting>### Input question: Does the camel belong to the phylum Chordata? Question type: <True / False>###"
[0099] Example E of the above set of problem analyses parser The document contains three examples, with ### marking the start or end of an example.
[0100] iii. For example question Q, after applying the question parsing method described in S1, the question parser outputs the question type Q. t For <entity query>.
[0101] II. Query Template Generation
[0102] a) Prompt provided to the large language model generated from the query template constructor "You are an assistant who writes SPARQL queries specifically to answer questions, and you need to generate a SPARQL template. The requirements are as follows: (1) Do not include 'PREFIX' or ':' in the generated SPARQL query; (2) The generated SPARQL query should be as simple as possible; (3) Entities and predicates in the conditions should be enclosed in <>, such as..." <entity>or <predicate>(4) The generated SPARQL query must conform to the general SPARQL standard; (5) The generated SPARQL query should be able to answer the specified question; (6) Do not change the internal order of the provided triples; (7) Utilize the provided information as much as possible to help generate the SPARQL query.
[0103] b) Examples of query template generation Question: How many films did Stanley Kubrick direct? Question type: <count> Triple: <?movie, director, Stanley Kubrick> SPARQL: SELECT DISTINCT COUNT(?movies) WHERE {?movies <director><Stanley Kubrick>Question: What is the Fox show hosted by Ryan Seacrest? Question Type: <Entity Query> Triple: <? show, presenter, Ryan Seacrest><? show, channel, FoxBroadcasting Company> SPARQL: SELECT DISTINCT ? show WHERE {? show <presenter> <ryanseacrest>.?show <channel><Fox Broadcasting Company>Question: Was Galileo Galilei the discoverer of Ganymede? Question Type: <True / False> Triplet:<Ganymede,discoverer,GalileoGalilei> SPARQL:ASK WHERE{ <ganymede> <discoverer><Galileo Galilei>}##”
[0104] Example E generated from the above set of query templates constructor This document contains three examples, marked by ### to indicate the start or end of each example. In each example, the SPARQL clause represents a knowledge base query template: For the first example, `SELECT DISTINCT COUNT(?movies)` indicates a counting query, where the counted entity is "? movies" (or "movies" in Chinese). The content within the curly braces after `WHERE` represents the query conditions, such as "? movies". <director> <stanleykubrick>The query conditions, expressed in Chinese, are: ? Movie <Director><Stanley Kubrick>; For the second example, `SELECT DISTINCT ? show` means the statement queries entities in the knowledge base, where `? show` represents the entity being queried, meaning "program" in Chinese. The content within the curly braces after `WHERE` represents the query conditions, where `? show`... <presenter> <ryanseacrest>.?show <channel><Fox Broadcasting Company>The query conditions can be expressed in Chinese as: ? Program<Host><Ryan Seacrest>? Program<Channel><Fox Broadcasting Company>; In the third example, ASKWHERE indicates that the statement is a yes / no query, and the content in the curly braces after WHERE represents the query conditions. <ganymede> <discoverer><Galileo Galilei>The query criteria are expressed in Chinese as <Galileo Galilei>.
[0105] c) For this example problem Q, the problem type Q t The set of triples T generates a candidate query template statement. The template is: SELECT DISTINCT ? television_show WHERE { ? television_show <producer><Stephen E.Ambrose>.? television_show<written by><Erik Jendresen> The above statement is a template for a knowledge base query language. `SELECT DISTINCT ? television_show` represents the entity being queried from the knowledge base, where `? television_show` represents the entity being queried (meaning "TV series"). The content within the curly braces after `WHERE` represents the query conditions. <producer><Stephen E.Ambrose>.? television_show<written by><Erik Jendresen> The search criteria can be expressed in Chinese as: TV series <The Producer> <Stephen E. Ambrose>? TV series <The Writer> <Eric Jandson>.
[0106] III. Knowledge Base Links
[0107] This step will process all the contents within angle brackets, that is... <producer><Stephen E.Ambrose><written by><Erik Jendresen>The following is based on<Stephen E.Ambrose> <producer>To elaborate.
[0108] a)<Stephen E.Ambrose> processing
[0109] i. Combined in Index e Found in<Stephen E.Ambrose> Corresponding Candidates(<StephenE.Ambrose> The prompt provided to the large language model, `Prompt_linker`, states: "You will act as an assistant, responsible for selecting the most suitable URIs for a specific entity. Task requirements: Select the two best-matching URIs from the provided list. Gain insight into the semantic information of the entity by understanding the given question. The output should consist of two URIs from the provided list (one per line), and no more than two; you do not need to add any explanation." Question: Which television show's producer is Stephen E. Ambrose and written by Erik Jendresen? Entity:<Stephen E.Ambrose> All possible URIs:
[0110] http: / / dbpedia.org / resource / Stephen_E._Ambrose:Stephen Edward Ambrose(January 10,1936–October 13,2002)was an American historian and biographer ofU
[0111] http: / / dbpedia.org / resource / Ambrose_E._Gonzales:Ambrose ElliottGonzales(May 27,1857–July 11,1926) was born on a plantation in ColletonCounty,South Carolina
[0112] http: / / dbpedia.org / resource / Ambrose_E._B._Stephens:Ambrose EverettBurnside Stephens(*3
[0113] http: / / dbpedia.org / resource / Ambrose:Aurelius Ambrosius, better known in English as Saint Ambrose
[0114] http: / / dbpedia.org / resource / Stephen_E._Rivkin:Stephen E
[0115] Output: "
[0116] Each line following "all possible URIs" represents a candidate entity, containing the entity's representation in the knowledge base and descriptive information about the entity.
[0117] ii. For example question Q t and entities used for linking<Stephen E.Ambrose> The knowledge base output by Linker is represented as: http: / / dbpedia.org / resource / Stephen_E._Ambrose.
[0118] b) <producer>processing
[0119] i. Combined with information found in the Knowledge Base KB <producer>The corresponding candidate knowledge base is indicated by the prompt word provided to the large language model linking the knowledge base: "You are an assistant responsible for determining the type of entity relations in a sentence. Specific requirements are as follows: Each line provides two entities, in random order. Understand the semantics of the sentence to determine the relations between the entities. Possible relation types are also listed in rows. Your output contains at most three most likely relation types, sorted by probability. Output is limited to these three relation types (one per line), no explanation required. Input sentence: Which television show's producer is Stephen E. Ambrose and written by Erik Jendresen?'"
[0120] entity:
[0121] television_show
[0122] http: / / dbpedia.org / resource / Stephen_E._Ambrose
[0123] Possible relationship types:
[0124] http: / / dbpedia.org / ontology / author
[0125] http: / / dbpedia.org / ontology / producer
[0126] http: / / dbpedia.org / property / author
[0127] http: / / dbpedia.org / property / producer
[0128] http: / / xmlns.com / foaf / 0.1 / primaryTopic
[0129] Output: "
[0130] ii. Each line after "Possible relation types:" represents a candidate relation, containing the relation's representation in the knowledge base. The knowledge base representation output by Linker is: http: / / dbpedia.org / ontology / producer.
[0131] IV. Answer Generation
[0132] By combining the above results, the SPARQL query that can find the answer in KB is: SELECT DISTINCT ? television_show WHERE { ? television_show<http: / / dbpedia.org / ontology / producer><http: / / dbpedia.org / resource / Stephen_E._Ambrose> .? television_show<http: / / dbpedia.org / ontology / writer><http: / / dbpedia.org / resource / Erik_Jendresen> The above statement is a template for a knowledge base query language. `SELECT DISTINCT ? television_show` represents the entity being queried from the knowledge base, where `? television_show` represents the entity being queried (meaning "TV series"). The content within the curly braces after `WHERE` represents the query conditions.<http: / / dbpedia.org / ontology / producer> The knowledge base for <The Producer> indicates that...<http: / / dbpedia.org / resource / Stephen_E._Ambrose> For the knowledge base representation of <Stephen E. Ambrose>,<http: / / dbpedia.org / resource / Erik_Jendresen> For Eric Jandsen's knowledge base representation,<http: / / dbpedia.org / ontology / writer> This is a knowledge base representation for <Screenwriter>.
[0133] Due to the type of problem Q t If it is not a "yes or no" statement and a query result is returned in the KB, the final output will be the query result in the KB, namely http: / / dbpedia.org / resource / Band_of_Brothers_(miniseries), which is the representation of the movie "Band of Brothers" in the knowledge base.
[0134] In summary, the aforementioned knowledge base question answering method based on small-shot learning of a large language model, in the question parsing subtask, utilizes the small-shot learning capability of the large language model to parse the question type of the user's question and identify potential triples in the user's question. In the query template generation subtask, it uses the small-shot learning capability of the large language model to construct a knowledge base query statement template based on the user's question, containing placeholders that can be replaced by specific representations in the knowledge base. In the knowledge base linking subtask, it uses the small-shot learning capability of the large language model and, with the help of a pre-built knowledge base information index, matches the entities and relations in the candidate triples with standard expressions in the knowledge base. In the answer generation subtask, based on existing information, it generates a knowledge base query statement that can be queried in the knowledge base, and, according to the question type, utilizes the knowledge capabilities of the large language model to generate the final answer to the user's question.
[0135] It should also be noted that the knowledge base question answering method under the full-process large language model few-shot learning in the above embodiments can essentially be executed by a computer program or module. Therefore, similarly, based on the same inventive concept, another preferred embodiment of the present invention also provides a knowledge base question answering system under the full-process large language model few-shot learning, corresponding to the knowledge base question answering method under the full-process large language model few-shot learning provided in the above embodiments, such as... Figure 2 As shown, it includes:
[0136] The question parsing module is used to obtain a user question expressed in natural language. The user question, a set of question parsing examples, and pre-constructed first prompt words are input into the large language model. The large language model realizes question parsing through few-shot learning ability, identifies multiple candidate triples in the user question and constructs a candidate triple set, and outputs the type of the user question.
[0137] The query template generation module is used to input the candidate triple set, the user question type, a set of query template generation examples, and the pre-constructed second prompt words into the large language model. The query template is generated through the small sample learning capability of the large language model to obtain a query statement template for knowledge base query.
[0138] The knowledge base linking module is used to index each named entity and the relationship between entities in the query statement template using the constructed knowledge base and entity information, and to achieve knowledge base linking by the small sample learning capability of the large language model, thereby obtaining a set of candidate entity or relationship knowledge base representations according to the knowledge base linking method;
[0139] The answer generation module is used to replace named entities in the query statement template with a set of candidate entity knowledge base representations, and replace relations in the query statement template with a set of candidate relation knowledge base representations. After replacement, a set of query statements are formed. The query statements are used to search the knowledge base to obtain the query results. Different strategies are adopted to generate answers based on the type of user question and the query results, and the final result is output.
[0140] Similarly, based on the same inventive concept, another preferred embodiment of the present invention also provides a computer electronic device corresponding to the knowledge base question answering method under the full-process large language model small sample learning provided in the above embodiments, which includes a memory and a processor;
[0141] The memory is used to store computer programs;
[0142] The processor is configured to implement the knowledge base question answering method under the full-process large language model few-shot learning in the above embodiments when executing the computer program.
[0143] Furthermore, the logical instructions in the aforementioned memory can be implemented as software functional units and, when sold or used as independent products, can be stored in a computer-readable storage medium. Based on this understanding, the technical solution of the present invention, in essence, or the part that contributes to the prior art, or a portion of the technical solution, can be embodied in the form of a software product. This computer software product is stored in a storage medium and includes several instructions to cause a computer device (which may be a personal computer, server, or network device, etc.) to execute all or part of the steps of the methods described in the various embodiments of the present invention.
[0144] Therefore, based on the same inventive concept, another preferred embodiment of the present invention also provides a computer-readable storage medium corresponding to the knowledge base question answering method under the full-process large language model few-shot learning provided in the above embodiments. The storage medium stores a computer program, which, when executed by a processor, can realize the knowledge base question answering method under the full-process large language model few-shot learning in the above embodiments.
[0145] Similarly, based on the same inventive concept, another preferred embodiment of the present invention also provides a computer program product corresponding to the knowledge base question answering method under the full-process large language model few-shot learning provided in the above embodiments, including a computer program / instruction, which, when executed by a processor, can realize the knowledge base question answering method under the full-process large language model few-shot learning in the above embodiments.
[0146] It is understood that the aforementioned storage media may include random access memory (RAM) or non-volatile memory (NVM), such as at least one disk storage device. Furthermore, the storage media may also be various media capable of storing program code, such as USB flash drives, external hard drives, magnetic disks, or optical discs.
[0147] It is understood that the processors mentioned above can be general-purpose processors, including central processing units (CPUs), network processors (NPs), etc.; they can also be digital signal processors (DSPs), application-specific integrated circuits (ASICs), field-programmable gate arrays (FPGAs), or other programmable logic devices, discrete gate or transistor logic devices, or discrete hardware components.
[0148] It should also be noted that those skilled in the art will understand that, for the sake of convenience and brevity, the specific working process of the system described above can be referred to the corresponding process in the foregoing method embodiments, and will not be repeated here. In the embodiments provided in this application, the division of steps or modules in the system and method is merely a logical functional division, and there may be other division methods in actual implementation. For example, multiple modules or steps may be combined or integrated together, and a module or step may also be split.
[0149] The embodiments described above are merely preferred embodiments of the present invention and are not intended to limit the invention. Those skilled in the art can make various changes and modifications without departing from the spirit and scope of the invention. Therefore, all technical solutions obtained through equivalent substitution or transformation fall within the protection scope of the present invention.< / producer> < / producer> < / producer> < / producer> < / producer> < / producer> < / discoverer> < / ganymede> < / channel> < / ryanseacrest> < / presenter> < / stanleykubrick> < / director> < / discoverer> < / ganymede> < / channel> < / ryanseacrest> < / presenter> < / director> < / predicate> < / entity>
Claims
1. A knowledge base question answering method based on small-sample learning of a large language model throughout the entire process, characterized in that, Includes the following steps: S1. Obtain a user question expressed in natural language. Input the user question, a set of question parsing examples, and pre-constructed first prompt words into the large language model. Use the small sample learning capability of the large language model to realize question parsing, identify multiple candidate triples in the user question and construct a candidate triple set, and output the type of the user question. S2. Input the candidate triple set, user question type, a set of query template generation examples, and pre-constructed second prompt words into the large language model. Through the small sample learning capability of the large language model, query templates are generated to obtain query statement templates for knowledge base queries. S3. For each named entity and the relationship between entities in the query statement template, the constructed knowledge base and entity information index are used, and the knowledge base is linked by the small sample learning ability of the large language model. Then, a set of candidate entity or relationship knowledge base representations are obtained according to the knowledge base linking method. S4. Replace the named entities in the query statement template with a set of candidate entity knowledge base representations, and replace the relations in the query statement template with a set of candidate relation knowledge base representations. After replacement, a set of query statements is formed. Use the query statements to search in the knowledge base to obtain the query results. Different strategies are used to generate answers based on the type of user question and the query results, and the final result is output. In step S3, the specific process of obtaining a set of candidate entity or relation knowledge base representations based on the knowledge base linking method is as follows: S31. Obtain the entity information index from the knowledge base. The entity information index includes the entity name, the unique representation in the knowledge base, and the entity description information. S32. For named entities in the query statement template, query the entity information index according to the name of the named entity to obtain a set of candidate entities, wherein each entity in the entity set contains a unique representation and entity description information in the knowledge base; S33. Input the user question, entity name, a set of candidate entity sets, a set of knowledge base link examples, and pre-constructed third prompt words into the large language model. Through the small-sample learning driving capability of the large language model, knowledge base linking is realized to obtain a set of candidate entity knowledge base representations. S34. For the relation in the query statement template, after obtaining the knowledge base representation of the two entities corresponding to the relation, query in the knowledge base to obtain the relation representation that is related to the two entities in the knowledge base, and after semantic sorting, form a set of candidate relation representations; S35. Input the user question, the knowledge base representations of the two entities corresponding to the relationship, a set of candidate relationship representations, a set of new knowledge base link examples, and the pre-constructed fourth prompt word into the large language model. Through the small-sample learning driving capability of the large language model, the knowledge base is linked to obtain a set of candidate relationship knowledge base representations.
2. The knowledge base question answering method based on small-sample learning of a large language model throughout the entire process as described in claim 1, characterized in that, In step S1, the user question belongs to three types: entity query, yes / no judgment, and counting.
3. The knowledge base question answering method based on small-sample learning of a large language model throughout the entire process as described in claim 1, characterized in that... In step S2, the query statement template contains a set of entities and the relationships between entities, wherein the entities in the query statement template are named entities or placeholder entities.
4. The knowledge base question answering method based on small-sample learning of a large language model throughout the entire process as described in claim 1, characterized in that, The specific process of step S4 is as follows: If the user's question is a yes / no judgment and the query result is no, the pre-constructed fifth prompt word and the user's question are input into the large language model, and the large language model is required to output yes or no. The output of the large language model is then taken as the final result. If the user's question is a yes / no judgment and the query result is yes, then the final result is yes; If the user's question is not a yes / no question and a query result is returned, then the query result will be used as the final result. If the user's question is not a true / false question and no query results are returned, the pre-constructed sixth prompt word and the user's question are input into the large language model. The large language model is required to output a set of answer entities, and the knowledge base representation of the answer entity corresponding to the answer entity is obtained through the knowledge base linking method in S3. The answer entity knowledge base representation is used as the final result.
5. The knowledge base question answering method based on small-sample learning of a large language model throughout the entire process as described in claim 1, characterized in that, Elasticsearch is used to retrieve entity information indexes from the knowledge base.
6. A knowledge base question-answering system based on small-sample learning of a large language model throughout the entire process, characterized in that, include: The question parsing module is used to obtain a user question expressed in natural language. The user question, a set of question parsing examples, and pre-constructed first prompt words are input into the large language model. The large language model realizes question parsing through few-shot learning ability, identifies multiple candidate triples in the user question and constructs a candidate triple set, and outputs the type of the user question. The query template generation module is used to input the candidate triple set, the user question type, a set of query template generation examples, and the pre-constructed second prompt words into the large language model. The query template is generated through the small sample learning capability of the large language model to obtain a query statement template for knowledge base query. The knowledge base linking module is used to index each named entity and the relationship between entities in the query statement template using the constructed knowledge base and entity information, and to achieve knowledge base linking by the small sample learning capability of the large language model, thereby obtaining a set of candidate entity or relationship knowledge base representations according to the knowledge base linking method; The answer generation module is used to replace the named entities in the query statement template with a set of candidate entity knowledge base representations, and to replace the relations in the query statement template with a set of candidate relation knowledge base representations. After replacement, a set of query statements are formed, and the query statements are used to retrieve the query results from the knowledge base. Different strategies are used to generate answers based on the type of user question and the query results, and the final result is output. In the knowledge base linking module, the specific process of obtaining a set of candidate entity or relation knowledge base representations based on the knowledge base linking method is as follows: S31. Obtain the entity information index from the knowledge base. The entity information index includes the entity name, the unique representation in the knowledge base, and the entity description information. S32. For named entities in the query statement template, query the entity information index according to the name of the named entity to obtain a set of candidate entities, wherein each entity in the entity set contains a unique representation and entity description information in the knowledge base; S33. Input the user question, entity name, a set of candidate entity sets, a set of knowledge base link examples, and pre-constructed third prompt words into the large language model. Through the small-sample learning driving capability of the large language model, knowledge base linking is realized to obtain a set of candidate entity knowledge base representations. S34. For the relation in the query statement template, after obtaining the knowledge base representation of the two entities corresponding to the relation, query in the knowledge base to obtain the relation representation that is related to the two entities in the knowledge base, and after semantic sorting, form a set of candidate relation representations; S35. Input the user question, the knowledge base representations of the two entities corresponding to the relationship, a set of candidate relationship representations, a set of new knowledge base link examples, and the pre-constructed fourth prompt word into the large language model. Through the small-sample learning driving capability of the large language model, the knowledge base is linked to obtain a set of candidate relationship knowledge base representations.
7. A computer-readable storage medium, characterized in that, The storage medium stores a computer program, which, when executed by a processor, implements the knowledge base question answering method under small-sample learning of a large language model as described in any one of claims 1 to 5.
8. A computer electronic device, characterized in that, Including memory and processor; The memory is used to store computer programs; The processor is configured to implement the knowledge base question answering method under small-sample learning of a large language model as described in any one of claims 1 to 5 when executing the computer program.
9. A computer program product comprising a computer program / instructions, characterized in that, When the computer program / instruction is executed by the processor, it can implement the knowledge base question answering method under the small sample learning of the full-process large language model as described in any one of claims 1 to 5.