Energy power policy file knowledge base retrieval method based on large model fine tuning
Through the RDF and NLP-based method, the energy and power policy documents are fine-tuned in large-scale models, SPARQL query statements are generated, and the answers are retrieved from the Freebase database, which solves the problems of difficulty in retrieving policy documents and high user thresholds, and achieves efficient and accurate retrieval effects.
Patent Information
- Application Number
- CN202411526920.7
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-10-30
- Publication Date
- 2025-03-14
AI Technical Summary
The integration and retrieval of energy and electricity policy documents is difficult, the threshold for users to use databases is high, and traditional search methods cannot effectively deal with the complexity of natural language.
Based on the Resource Description Framework (RDF) and Natural Language Processing (NLP), a knowledge base search method for energy power policy documents based on fine-tuning is proposed. The specific steps include: using the RDF semantic data model to annotate the original text data, constructing entity sets and fine-tuning data sets, fine-tuning the LLaMa2-7b model, generating candidate logical expressions, and retrieving answers from the Freebase database through SPARQL query statements.
The data format of energy and power policy documents has been unified and standardized, the accuracy of search is improved, the threshold for user use is lowered, and an efficient, accurate and user-friendly knowledge base search solution is provided.
Smart Images

Figure CN119621927A_ABST
Abstract
Description
Technical Field
[0001] The present invention belongs to the technical field of data retrieval, and in particular relates to an energy and power policy document knowledge base retrieval method based on large model fine-tuning. Background Art
[0002] Knowledge base retrieval technology has become an important means of acquiring, managing and utilizing information in various fields. From scientific research to business decision-making, from education and learning to daily life, the application of knowledge base retrieval technology is everywhere. Especially in the field of energy and power, with the transformation of the global energy structure and the rapid development of the power market, the demand for efficient retrieval and analysis of energy and power policy documents is growing. However, knowledge base retrieval in this field faces a series of challenges, the most prominent of which is the lack of standardization of knowledge base data and the high threshold of use.
[0003] Knowledge base retrieval technology enables users to find the required information quickly and accurately by building structured data storage and efficient retrieval algorithms. Energy and power policy documents are usually scattered across different sources and platforms, which makes it difficult to integrate and retrieve information. In addition, policy documents from different regions and institutions differ in format and content, which not only increases the difficulty of retrieval and comparison, but also raises the threshold for users to use the database. The lack of unified standards and specifications makes knowledge base retrieval of energy and power policy documents a complex and time-consuming process.
[0004] Traditional knowledge base retrieval methods mainly rely on keyword matching and Boolean logic. Users enter keywords and the system returns a list of documents containing these keywords. However, this method has obvious shortcomings. First, it relies on the user's accurate understanding of the retrieval content. If the user is not familiar with the domain terminology, he may not be able to accurately express the retrieval requirements. Secondly, traditional retrieval methods cannot handle the complexity of natural language, such as synonyms, polysemy, and contextual dependencies. In addition, traditional retrieval systems usually require users to have a certain technical background in order to effectively use advanced retrieval functions, which undoubtedly increases the user's usage threshold. Summary of the invention
[0005] The technical problem to be solved by the present invention is the difficulty in integrating and retrieving energy and power policy documents, and the high threshold for users to use the database. The present invention proposes a method for retrieving energy and power policy document knowledge base based on large model fine-tuning based on resource description framework (RDF) and natural language processing (NLP). Specifically, the method includes the following steps:
[0006] Step 1: annotate the original text data using the RDF semantic data model to obtain annotated RDF data, and import the annotated RDF data into the Freebase database;
[0007] Constructing an entity set E based on the RDF data, including a label e', a weight and an identifier of the entity e;
[0008] Step 2: Construct a fine-tuning dataset to fine-tune the LLaMa2-7b model and obtain the fine-tuned LLaMa2-7b model. Specifically:
[0009] Construct a natural language question set, input the natural language question into a logic generation function, and generate a logical expression matching the natural language question; the natural language question set and the logical expression matching the natural language question together constitute the fine-tuning data set; use the natural language question set in the fine-tuning data set as the input of the LLaMa2-7b model, and the logical expression corresponding to the natural language question set as the output of the LLaMa2-7b model, fine-tune the LLaMa2-7b model, and obtain the fine-tuned LLaMa2-7b model;
[0010] Step 3: annotate the natural language questions to be retrieved with RDF data, and then input them into the fine-tuned LLaMa2-7b model to generate candidate logical expressions C;
[0011] Step 4, based on the entity e and relationship r in the candidate logical expression list C, search the entities and relationships in the Freebase database, and update the candidate logical expression list C to a new candidate logical expression list C";
[0012] Step 5: Input the new candidate logical expression list C" into the SPARQL statement generation function to generate a SPARQL query statement, and use the SPARQL query statement to retrieve the answer to the natural language question from the Freebase database.
[0013] Further, the RDF data includes a namespace, a category of entity e, a label e' of entity e, and an identifier of entity e;
[0014] Furthermore, the logic generation function in step 2 is set as: (JOIN(R[namespace, category of entity e, relation r])[entity e]).
[0015] Furthermore, in step 2, the LoRA fine-tuning method is used to fine-tune the LLaMa2-7b model.
[0016] Furthermore, step 3 also includes using beam search to find the optimal solution or approximate optimal solution in the candidate logical expressions generated by the fine-tuned LLaMa2-7b model to obtain the candidate logical expression C.
[0017] Furthermore, in step 4, based on the entity e and relationship r in the candidate logical expression list C, entities and relationships in the Freebase database are retrieved, and the candidate logical expression list C is updated to a new candidate logical expression list C", including the following steps:
[0018] Step 4.1, based on the entity e in the candidate logical expression list C, search the entities in the Freebase database, take the entities with similarity before k1 and greater than the threshold t1, and form a new candidate logical expression list C'; the details are as follows:
[0019] Calculate the similarity Se between each entity e in the logical expression F and each entity with label e' in the entity set E of the Freebase database;
[0020] Sort the retrieved entities e according to the similarity Se, take out the entities e with similarity ke before and greater than the threshold te, obtain the entity search result elist corresponding to each entity e in the logical expression F, arrange the entities in the entity search result elist, obtain the entity result Flist after entity sorting, take out the entities with similarity k1 before and greater than the threshold t1, and form a new candidate logical expression list C';
[0021] Step 4.2: for each relation r' in the candidate logical expression list C', search the relations in the Freebase database, take the relations with the top k2 similarities and greater than the threshold t2, and form a new candidate logical expression list C'; the details are as follows:
[0022] Calculate the similarity sr between each relation r' in the candidate logical expression list C' and each candidate relation in the Freebase database, and extract the relation retrieval results rlist whose similarity is within kr and greater than the threshold tr. Arrange the relation retrieval results to obtain the retrieved relation results Flist, and then extract the relations whose similarity is within k2 and greater than the threshold t2 to form a new candidate logical expression list C".
[0023] Furthermore, the SPARQL statement generation function in step 5 is set to: “PREFIXns:<http: / / rdf.freebase.com / ns / > \nSELECT DISTINCT? x\nWHERE{\nFILTER(?x!=ns:identifier of entity e)\nFILTER(!isLiteral(?x)OR lang(?x)="OR langMatches(lang(?x),'en'))\nns:identifier of entity ens:namespace of entity e.category of entity e.predicate (relationship or attribute) of entity e?x.\n}".
[0024] Beneficial effects: The energy and power policy document knowledge base retrieval method based on large model fine-tuning proposed in the present invention, first, converts energy and power policy documents from different sources into RDF data, thereby realizing the unification and standardization of data formats. As a semantic network technology, RDF can express rich semantic relationships and provide strong support for knowledge base retrieval. Secondly, using the natural language processing model LLaMa2 model, the user's natural language questions can be converted into database query statements corresponding to the RDF data. This conversion not only improves the accuracy of the retrieval, but also greatly reduces the user's usage threshold.
[0025] In summary, the new knowledge base retrieval method I proposed provides an efficient, accurate and user-friendly solution for the retrieval of energy and power policy documents by integrating advanced semantic network technology and natural language processing technology. This research not only promotes the application of knowledge base retrieval technology in the field of energy and power, but also provides new ideas and methods for knowledge base retrieval in other fields.
[0026] Instruction Manual
[0027] Figure 1 It is a flow chart of the knowledge base retrieval method of the present invention. DETAILED DESCRIPTION
[0028] The following will be combined with the drawings in the embodiments of the present invention to clearly and completely describe the technical solutions in the embodiments of the present invention. Obviously, the described embodiments are only part of the embodiments of the present invention, not all of the embodiments. Based on the embodiments of the present invention, all other embodiments obtained by ordinary technicians in this field without creative work are within the scope of protection of the present invention.
[0029] A knowledge base retrieval method of the present invention is applied to the scenario of energy and power policy document retrieval, forming an energy and power policy document knowledge base retrieval method based on large model fine-tuning in this specific implementation manner, such as Figure 1 As shown, the specific steps include:
[0030] Step 1: Build RDF semantic data.
[0031] RDF (Resource Description Framework) is a semantic data model for describing network resources. It is designed to express information about network resources. The core idea of RDF is to express information as a series of triples, each of which contains three parts: entity (Subject), predicate (Predicate) and object (Object). This structure makes RDF very suitable for representing complex relationships and semantic information. The data model of RDF can be represented as a graph, in which nodes represent entities and objects, and edges represent predicates. This graph structure makes RDF very suitable for representing complex network relationships and data. Among them, entity (Subject): usually a resource, which can be anything.
[0032] The text data of the energy and power policy documents used in this paper is provided by the Economic and Technological Research Institute of Henan Electric Power Company of State Grid. The original text content is annotated and extracted according to the structure of the RDF semantic data model. The issuing agencies such as "Henan Power Grid", "State Grid", and "National Energy Administration" in the text data are annotated as entities; verbs or attributes such as "publish", "encourage", and "establish" in the text data are annotated as predicates; policy clauses such as "Henan Energy Big Data Center Data Management Measures" and "Notice of Henan Electric Power Company on Printing and Distributing the Negative List of Data Sharing of the Company's Business System" in the text data are annotated as objects; URI (Uniform Resource Identifier) is used to identify entities, predicates, and objects in RDF data. In addition, a new namespace electricity and a new category are defined. The namespace electricity indicates that the RDF data is data related to the power policy document. The RDF data is converted into a .ttl file format that can be recognized and imported by the Freebase database through a format conversion function, and the annotated RDF data is imported into the Freebase database. RDF data includes the category and namespace of entity e.
[0033] The categories of entity e include issuing authority, policy terms, region, characteristic industry, scientific research, demonstration area, base, center, facility, resource, indicator, project, special plan, institution, implementation plan, database, and project;
[0034] The namespace is defined for electricity.
[0035] Extract the annotated entities from the Freebase database, assign them fixed identifiers, and assign weights according to the frequency of their appearance in the document to form an entity set E. The format of entity set E is: entity e's label e', weight, and entity e's identifier;
[0036] For example, “State Grid Henan Electric Power “14th Five-Year Plan” Digital Planning Report
[0037] 0.08223684210526315m.dkgd974”; among them, “State Grid Henan Electric Power'14th Five-Year Plan'Digital Planning Report” is the label e' of the entity (Henan Electric Power State Grid Henan Electric Power), “0.08223684210526315” is the weight, and “m.dkgd974” is the identifier of the entity.
[0038] Step 2, generate a fine-tuning dataset for fine-tuning the LLaMa2-7b model;
[0039] First, we construct a natural language question set of energy and power policy documents, and then extract the corresponding entities and predicates (relations or attributes), entity identifiers, entity namespaces, and entity categories in the natural language question set from the Freebase database. The natural language question set and logical expressions are divided into training and test sets in a ratio of 5:1.
[0040] The natural language questions in the training set are input into the logic generation function to generate logical expressions that match the natural language questions in the training set; the logical expressions generated using the natural language questions in the training set are used to fine-tune the LLaMa2-7b model so that it learns the mapping relationship between natural language questions and logical expressions.
[0041] The SPARQL statement generation function generates a SPARQL query statement that matches the natural language question in the training set from the logical expression in the training set;
[0042] The SPARQL statement generation function is set to: "PREFIXns:<http: / / rdf.freebase.com / ns / > \nSELECT DISTINCT? x\nWHERE{\nFILTER(?x!=ns:identifier of entity e)\nFILTER(!isLiteral(?x)OR lang(?x)="OR langMatches(lang(?x),'en'))\nns:identifier of entity e ns:namespace of entity e.category of entity e.predicate (relationship or attribute) of entity e?x.\n}". Its purpose is to find all different values related to entity e (excluding the entity itself) from RDF data, and these values should be valid (i.e. non-text or English text).
[0043] For example, for the natural language question: "What kind of scientific research does the State Grid Henan Electric Power'14th Five-Year Plan'Digital Planning Report encourage?", the corresponding entity in the natural language question set extracted from the Freebase database is: State Grid Henan Electric Power'14th Five-Year Plan'Digital Planning Report; the predicate of entity e is: encourage; the identifier of entity e is: m.dkgd974; the namespace of entity e is: electricity; the category of entity e is: Policy_Terms; the weight of entity e is: 0.08223684210526315;
[0044] The natural language question "What kind of scientific research does the State Grid Henan Power "14th Five-Year Plan" Digital Planning Report encourage?" corresponds to the SPARQL query statement "PREFIXns:<http: / / rdf.freebase.com / ns / > \nSELECTDISTINCT? x\nWHERE{\nFILTER (?
[0045] "PREFIX" defines a prefix ns, which means that all URIs starting with ns: are based on http: / / rdf.freebase.com / ns / ; the line "SELECT DISTINCT?x" indicates that the goal of the query is to return a non-duplicate result set, that is, all different "?x" values; the "WHERE clause" part defines the query conditions, and the query results will be returned based on the conditions in this part. "FILTER(?x!=ns:m.dkgd974)" is a filter to ensure that the returned results do not contain the specific entry "ns:m.dkgd974"; "FILTER(!isLiteral(?x)OR lang(?x)="ORlangMatches(lang(?x),'en'))" is a filter used to ensure that the obtained "?x" value is valid. Specifically: "!isLiteral(?x)" means "? "x" is not a text value; "lang(?x)="" means that "?x" has no specified language; "langMatches(lang(?x),'en')" means that the language of "?x" is English; "ns:m.dkgd974ns:electricity.Policy_Terms.encourage?x." It means that the entry "ns:m.dkgd974" is related to a certain scientific research "(ns:electricity.Policy_Terms.encourage)" encouraged by an electricity policy document. In summary, the purpose of this SPARQL query is to find all different values related to the scientific research encouraged by a specific electricity policy document from the RDF data (excluding "ns:m.dkgd974" itself), and these values should be valid (that is, non-text or English text).
[0046] The logical generation function is set to: "(JOIN(R[namespace, entity e's category, relation r])[entity e])", where relation r is the relationship between entity e and the answer to the natural language question. This expression means: join a specific entity e from a namespace, entity e's category, and relation r. This is to extract or analyze specific information in entity e and associate it with related entities (the answer to the natural language question).
[0047] For example, the natural language question above, "What kind of scientific research does the State Grid Henan Electric Power "14th Five-Year Plan" Digital Planning Report encourage?" corresponds to the logical expression "(JOIN(R[electricity,Policy Terms,encourage])[StateGrid Henan Electric Power "14th Five-Year Plan" Digital Planning Report])", which indicates that the entity e to be searched is knowledge related to the namespace electricity, its category is the Policy Terms class, and the relationship between it and the answer is encourage. In addition, the restriction of the entity name [State Grid Henan Electric Power "14th Five-Year Plan" Digital Planning Report] can minimize the scope of the search in Freebase and find the answer. In order to facilitate subsequent model training.
[0048] Step 3: Fine-tune using the LLaMa2-7b model
[0049] Use the efficient fine-tuning of the Chinese large language model LLaMa2-7b to construct the guided fine-tuning training data, take the natural language question and the corresponding logical expression as "input" and "output" respectively, and add "Generate a Logical Form query that retrieves the information corresponding to the given question." as "instruction" to form the guided fine-tuning training data of the open source LLaMa2-7b model. For example: {"instruction":"Generate a Logical Form query that retrieves the information corresponding to the given question.\n","input":"Question:{What policy terms did Henan PowerGrid issue?}","output":"(JOIN(R[electricity,Issuing authority,release])[HenanPower Grid])","history":[]}.
[0050] To reduce the cost of fine-tuning with a large number of parameters, the parameter-efficient fine-tuning (PEFT) method is used to fine-tune only a small number of LLaMa2-7b model parameters and achieve performance comparable to full fine-tuning. Using LoRA fine-tuning, the memory footprint of large language models is reduced by changing the weights during fine-tuning using low-rank approximation.
[0051] Unlike the method of serially inserting training parameters into the pre-trained model, LoRA does not change the original model, but inserts a new weight matrix ΔW next to the pre-trained weight matrix W0 of the original model. In order to reduce the number of parameters and the amount of calculation, ΔW is low-rank decomposed into a reduced-dimensional matrix A and an increased-dimensional matrix B. During training, the pre-trained model is frozen, and there is no need to fine-tune the pre-trained parameters. W0 is not updated, and only the A and B matrices injected into the pre-trained model are trained.
[0052] Through fine-tuning, the LLaMa2-7b model has mastered the semantic parsing ability from natural language questions to logical expressions to a certain extent. Therefore, the fine-tuned LLaMa2-7b model is used to perform semantic parsing on new questions in the test set to generate candidate logical expressions; beam search is used, and the beam value is set to 8 to find the optimal solution or approximate optimal solution in the candidate logical expressions generated by the fine-tuned LLaMa2-7b model, and then a possible candidate logical expression list C is output, and the logical expression list C contains the logical expression F.
[0053] Step 4: Search and answer the entity e and relationship r of the candidate logical expression list C
[0054] The retrieval input is the generated candidate logical expression list C, and the logical expressions F in the logical expression list C are traversed one by one.
[0055] First, perform entity retrieval on the candidate logical expression F.
[0056] For each entity e in the logical expression F, calculate the similarity Se←SimiEntities(e,e') with each entity with label e' in the entity set E of the knowledge base Freebase. Sort the retrieved entities e according to the similarity, take out the entities with similarity before ke and greater than the threshold te, and get the retrieval result elist←TopKwithThreshold(elist,ke,te) of the entity e in the logical expression F. The function PermuteByEntity arranges the retrieved entities at each position and obtains the result Flist after the entities are sorted. According to the probability in Flist, take the new candidate logical expression list C'.append(TopKwithThreshold(Flist,k1,t1)) with similarity before k1 and greater than the threshold t1.
[0057] Next, perform relationship retrieval.
[0058] Similar to entity retrieval, but different in that for each relation r'∈F in the candidate logical expression list C', according to the entity set E of the logical expression F The neighborhood of r calculates the similarity sr←SimiRelations(r,r') between each candidate relation r'. The EF refers to the set of entities in the logical expression list C'; similarly, the retrieved relations are sorted according to the similarity, and the relation retrieval results rlist←TopKwithThreshold(rlist,kr,tr) whose similarities are before kr and greater than the threshold tr are taken out. By arranging the relation retrieval results at each position, the result Flist after relation retrieval is obtained, and then a new candidate logical expression list C" with similarities before k2 and greater than the threshold t2 is taken out.append(TopKwithThreshold(Flist,k2,t2)). The final candidate logical expression list C" is obtained, and then converted into an equivalent SPARQL query statement q=Convert(F), where Convert() represents the SPARQL statement generation function and F is the expression in the candidate logical expression list C".
[0059] Step 5: Perform SPARQL query
[0060] Use the SPARQL query generated in step 4 to perform query operations and retrieve the answers to natural language questions from the Freebase database.
[0061] The present invention proposes a knowledge base retrieval method that converts different policy documents into RDF data and unifies the standardized data format of energy and power policy documents from different sources. At the same time, the LLaMa2 model is used to convert the user's natural language questions into logical expressions corresponding to the RDF data and then into database query statements, thereby lowering the user usage threshold. The final results show that the accuracy of natural language questions converted into database query statements is 94.1%, the recall rate is 91.0%, and the F1 value is 92.5%, which greatly reduces the query time and user usage threshold while maintaining the query accuracy.
[0062] The number of natural language question-answer pairs in the energy and power policy document data is 1200, of which 1000 data are used as training sets and 200 data are used as test sets. This paper uses three different evaluation indicators, namely recall rate, precision rate and F1 value, to judge the performance of the new retrieval method. The recall rate is also called the recall rate, which represents the number of positive examples predicted correctly in the sample, and its expression is:
[0063]
[0064] In the above formula, TP represents the number of data predicted as positive samples and actually positive samples, and FN represents the number of data predicted as negative samples and actually negative samples. The recall rate is relative to the sample, that is, how many positive samples in the sample are predicted correctly, there are TP such samples, all positive samples have two destinations, one is judged as positive, and the other is wrongly judged as negative, so there are TP+FN in total. The expression of another evaluation index, precision, is shown in formula (7):
[0065]
[0066] In the above formula, TP has the same meaning as recall, and FP is the number of samples predicted as positive but actually negative in the data. Precision is relative to the prediction result, which indicates how many of the samples predicted as positive are correct; then there are two possible sources of samples predicted as positive, one is predicting positive as positive, which has TP, and the other is misjudging negative as positive, which has FP.
[0067]
[0068] In the above formula, the F1 score (F1Score), also known as the balanced F score (balanced F Score), is defined as the harmonic mean of precision and recall. It is an indicator used in statistics to measure the accuracy of a binary classification model. It takes into account both the precision and recall of the classification model. The F1 score can be regarded as a harmonic mean of the model's precision and recall. Its maximum value is 1 and its minimum value is 0.
[0069] Table 1 shows the results of various indicators after retrieval by the method in this paper. As can be seen from the table, the recall rate is 94.1%, which means the proportion of all relevant question-answer pairs that the model successfully identified and retrieved. This result shows that the model performs well in retrieving relevant information, but some relevant data is still not correctly identified. The precision rate is 91.0%, indicating that a considerable part of the question-answer pairs retrieved by the model are correct. The high precision rate indicates that the model has high accuracy in the retrieval process and reduces the occurrence of wrong information. The F1 value is 92.5%, which is a comprehensive indicator of recall rate and precision rate, reflecting the overall balance of the model in the retrieval task. The higher F1 value indicates that the model performs well in specific retrieval tasks and can effectively balance accuracy and coverage.
[0070] Overall, these results show that the proposed new retrieval method has good performance in question-answer retrieval of energy and power policy document data, can effectively identify and return relevant information, and greatly reduces the user's query difficulty and usage threshold while ensuring the accuracy of knowledge query.
[0071] Table 1 Knowledge base retrieval evaluation indicators
[0072] Table 1Indicators for assessing
[0073] knowledge base access
[0074]
[0075] For example, the natural language question to be retrieved is "What kind of scientific research does the State Grid Henan Electric Power "14th Five-Year Plan" Digital Planning Report encourage?" This is converted into RDF data format and imported into the freebase database. Then, the corresponding candidate logical expression table C is generated using the fine-tuned LLaMa2-7b model. Then, entity and relationship retrieval is performed and combined with beam search to update the candidate logical expression table C, and then the corresponding SPARQL query statement "PREFIX ns:<http: / / rdf.freebase.com / ns / > \nSELECT DISTINCT? x\nWHERE{\nFILTER(?x!=ns:m.dkgd974)\nFILTER(!isLiteral(?x)OR lang(?x)=”OR langMatches(lang(?x),'en'))\nns:m.dkgd974 ns:electricity.Issuing_authority.encourage?x.\n}”, input the generated SPARQL query statement into the Freebase database for query and return “http: / / rdf.med.com / ns / m.llksoqk”, “http: / / rdf.med.com / ns / m.llksoqk” is the URL corresponding to the answer to the natural language question in the database. If the database query statement is replaced, the retrieval method can be applied to other databases, and if the energy and electricity policy text data is replaced with other field text data, the retrieval method can be applied to new fields.
Claims
1. A knowledge base retrieval method, characterized in that: The steps include: Step 1: annotate the original text data using the RDF semantic data model to obtain annotated RDF data, and import the annotated RDF data into the Freebase database; Constructing an entity set E based on the RDF data, including a label e', a weight and an identifier of the entity e; Step 2, construct a fine-tuning dataset for fine-tuning the LLaMa2-7b model to obtain a fine-tuned LLaMa2-7b model; Construct a natural language question set, input the natural language question into the logic generation function, and generate a logical expression matching the natural language question; The natural language question set and the logical expressions matching the natural language question set together constitute the fine-tuning dataset; Step 3: annotate the natural language questions to be retrieved with RDF data, and then input them into the fine-tuned LLaMa2-7b model to generate candidate logical expressions C; Step 4, based on the entity e and relationship r in the candidate logical expression list C, search the entities and relationships in the Freebase database, and update the candidate logical expression list C to a new candidate logical expression list C"; Step 5: Input the new candidate logical expression list C" into the SPARQL statement generation function to generate a SPARQL query statement, and use the SPARQL query statement to retrieve the answer to the natural language question from the Freebase database.
2. A knowledge base retrieval method according to claim 1, characterized in that: The method comprises the following steps: the RDF data comprises a namespace, a category of an entity e, a label e' of the entity e and an identifier of the entity e.
3. A knowledge base retrieval method according to claim 2, characterized in that: The logic generation function in step 2 is set as: (JOIN(R[namespace, category of entity e, relation r])[entity e]).
4. A knowledge base retrieval method according to claim 1, characterized in that: In step 2, the natural language question set in the fine-tuning dataset is used as the input of the LLaMa2-7b model, and the logical expression corresponding to the natural language question set is used as the output of the LLaMa2-7b model. The LLaMa2-7b model is fine-tuned to obtain the fine-tuned LLaMa2-7b model.
5. A knowledge base retrieval method according to claim 1, characterized in that: In step 2, the LoRA fine-tuning method is used to fine-tune the LLaMa2-7b model.
6. A knowledge base retrieval method according to claim 1, characterized in that: Step 3 also includes using beam search to find the optimal solution or approximate optimal solution in the candidate logical expressions generated by the fine-tuned LLaMa2-7b model to obtain the candidate logical expression C.
7. A knowledge base retrieval method according to claim 1, characterized in that: In step 4, based on the entity e and relationship r in the candidate logical expression list C, the entities and relationships in the Freebase database are retrieved, and the candidate logical expression list C is updated to a new candidate logical expression list C", including the following steps: Step 4.1, based on the entity e in the candidate logical expression list C, search the entities in the Freebase database, take the entities with similarity before k1 and greater than the threshold t1, and form a new candidate logical expression list C'; Step 4.2: For each relation r' in the candidate logical expression list C', search the relations in the Freebase database, take the relations with the top k2 similarities and greater than the threshold t2, and form a new candidate logical expression list C".
8. A knowledge base retrieval method according to claim 1, characterized in that: The SPARQL statement generation function in step 5 is set to: "PREFIXns:<http: / / rdf.freebase.com / ns / > \nSELECT DISTINCT? x\nWHERE{\nFILTER(?x!=ns:identifier of entity e)\nFILTER(!isLiteral(?x)OR lang(?x)="ORlangMatches(lang(?x),'en'))\nns:identifier of entity e ns:namespace of entity e.category of entity e.predicate of entity e?x.\n}".
Citation Information
Cited By
Policy document consistency analysis method
CN122045389A