Enhanced traditional folk custom intelligent question and answer method and system based on knowledge graph
By constructing a traditional folk custom knowledge graph and two-stage search enhancement generation framework, the problem of factual illusion of large language models in the traditional folk customs field is solved, the accuracy and reliability of question-and-answer are improved, and the integrity and consistency of folk knowledge is ensured.
Patent Information
- Application Number
- CN202410982724.4
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-07-22
- Publication Date
- 2024-11-05
- Estimated Expiration
- Not applicable · inactive patent
Smart Images

Figure CN118897882A_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to the field of computer technology, and in particular to a traditional folk custom intelligent question-answering method and system based on knowledge graph enhancement. Background Art
[0002] Ontology is a conceptual model that describes the world or its parts, in which classes and attributes are defined. A knowledge graph can be seen as a collection of data instances driven by an ontology. The information organization structure of a knowledge graph includes an ontology layer and a data layer. The ontology layer is used to normalize and constrain the data layer; the data layer mainly consists of a series of facts, and knowledge will be stored in units of facts. In the field of cultural heritage, ontology plays a key role in describing and analyzing literature, and provides a new perspective for integrating cultural heritage data. The ontology layer can be constructed through ontology.
[0003] Triples are the basic building blocks in knowledge graphs, usually structured as (head entity, relationship, tail entity). An entity corresponds to a specific individual described by an ontology. To store triples in a database, such as the neo4j graph database, each entity needs to be labeled accordingly. The label is the name of the defined ontology.
[0004] CIDOC CRM (CRM) is a standard and extensible semantic framework that provides description and integration of cultural heritage information. After more than 20 years of development, CRM has become a universal and mature tool in the field of cultural heritage. Using the classes and attributes in CRM to build ontologies is widely used in the field of cultural heritage.
[0005] Retrieval-augmented generation (RAG) is a technique that improves the accuracy and reliability of generative AI models by using external knowledge sources. It is particularly suitable for knowledge-intensive tasks and allows continuous knowledge updating and integration of domain-specific information. The idea is: given an auxiliary knowledge base and an input query, use the RAG architecture to find documents in the knowledge base that are similar to the input query. These documents are then added to the input query to provide the model with similar context about the query topic to improve the quality of the response.
[0006] In order to ensure the integrity of the knowledge in the traditional folklore knowledge graph, crawlers are used to crawl traditional folklore data for the construction of the traditional folklore knowledge graph. A crawler is a program or script that can automatically crawl information on the World Wide Web according to certain rules, and can collect a large amount of initial data for the construction of the knowledge graph.
[0007] The continuous expansion and development of artificial intelligence has provided fertile soil for the popularization of large-scale language models (LLMs). Large language models such as InstructGPT, ChatGPT, GPT4, LLaMA, and ChatGLM have made remarkable progress in key areas. Through extensive pre-training and instruction fine-tuning on massive text corpora, they have demonstrated excellent performance in various downstream tasks, highlighting their great potential in understanding and generating natural language. For example, currently in the field of natural language processing (NLP), LLM can be used as a general language task solver to a certain extent, and the research paradigm has shifted to the use of LLM.
[0008] Despite the progress, large language models still face significant challenges, including the need to adapt to specific tasks and domains, the risk of large model hallucination problems, and limitations in handling highly specialized queries. The hallucination problems can be divided into two main categories: factual hallucination and faithfulness hallucination. In particular, in the specific field of traditional folklore, the main problem is factual hallucination, that is, the difference between the generated content and the verifiable real-world facts, which is usually manifested as inconsistent or fabricated facts. The main reason for factual hallucination is that the large language model does not have or lacks traditional folklore-related corpus in the pre-training corpus, resulting in a gap or sparseness in the knowledge related to the folklore field, so that facts are fabricated when answering questions. The factual hallucination problem faced by this LLM will affect its reliability in answering questions in the folklore field. In the prior art, due to the complexity and particularity of traditional folklore knowledge caused by changes in social environment and culture, if folklore knowledge is stored in plain text and a simple retrieval enhancement generation method based on text vector embedding is used, it will cause fragmentation and confusion of folklore knowledge, making it difficult to generate an accurate knowledge network and retrieve data related to the query. Summary of the invention
[0009] In order to alleviate the insufficiency of existing large language models in the field of traditional folklore knowledge and the problem of factual illusion, the present invention provides a traditional folklore intelligent question-answering method and system based on knowledge graph enhancement, which expands and enriches the content of the knowledge graph in the field of folklore. The present invention realizes crawling and integrating traditional folklore data on the Internet based on the traditional folklore catalog and crawler algorithm; constructs the traditional folklore ontology TFOnto based on the CIDOC CRM conceptual model, proposes a zero-sample traditional folklore triple extraction framework ZFTE, realizes the extraction of triples by ZFTE driven by TFOnto and constructs the traditional folklore knowledge graph TFKG; proposes a two-stage retrieval enhancement generation framework TFKG_RAG based on TFKG, which provides the large language model with traditional folklore knowledge for question-answering.
[0010] The technical solution of the present invention is:
[0011] A traditional folk custom intelligent question-answering method based on knowledge graph enhancement first collects traditional folk custom catalog information from the official websites of various provinces, then uses crawlers to crawl data related to the names of traditional folk custom catalogs on relevant websites, uses TFOnto to drive the ZFTE framework to extract triples from the crawled traditional folk custom data, and writes the extracted triples into the graph database to construct the traditional folk custom knowledge graph TFKG. When users query questions related to the folk custom field, a two-stage retrieval enhancement generation module based on TFKG is used to retrieve data information related to the user's query in TFKG, and the user's interjection and related data are input into the large language model for question answering.
[0012] Further, the steps of the method are as follows:
[0013] Step 1) Constructing the traditional folklore knowledge graph: first manually collect traditional folklore catalog information from the official websites of each province, then crawl the collected traditional folklore catalog related data from the given subject website through a crawler, build the traditional folklore ontology TFOnto based on the CIDOC CRM conceptual model, use TFOnto to drive the ZFTE framework to extract the triples corresponding to the predefined relationships in the ontology from the crawled data, and finally write the extracted triples into the graph database to construct the traditional folklore knowledge graph;
[0014] Step 2) The two-stage retrieval enhancement generation based on TFKG provides query-related data for the large language model: This step involves entity recognition, entity vector retrieval stage and knowledge block re-ranking stage; first, the user inputs a query related to the folklore field, then entity recognition is performed on the query to identify the folklore entities in the query, similar entities are retrieved for the identified entities in the vector database in the entity vector retrieval stage, relevant triple information of the retrieved entities is queried in TFKG, the triples are converted into folklore knowledge blocks, the folklore knowledge blocks are re-ranked in the knowledge block re-ranking stage, and the knowledge blocks most relevant to the user query are returned to the large language model for folklore knowledge question and answering; since the performance of the re-ranking affects the question and answer effect of the large language model, the re-ranking is fine-tuned using contrastive learning to enhance the question and answer performance of the large language model.
[0015] Furthermore, in step 1), the traditional folklore ontology TFOnto is constructed as follows:
[0016] The classes in TFOnto include CRM:E1 Entity, E53 Place, E21 Person, E22 Man-MadeObject, E7 Activity, E89 Propositional Object, E52 Time-Span, E41 Appellation, E42Identifier, E74 Group, and E55 Type. Folklore is used as the top-level structure. Each folklore belongs to the scope of CRM:E1Entity. Place is used to describe the reporting area or unit location of the folklore, the popular area or regional information; Person represents the inheritor of the folklore or the belief / commemoration figure of the folklore; Man-Made Object refers to an object specially created by human activities, which is used to represent the sacrificial objects and food in folklore; Activity represents the activities held during the folklore; Propositional Object describes concepts, beliefs or knowledge, and is used to express meaning; Time-Span is used to indicate the origin time and festival time of folklore; Appellation refers to all types of names, labels and titles, and is used to indicate the alias of folklore; Identifier is used to indicate the batch and number of folklore; Group indicates the ethnic group to which the folklore belongs; Type refers to various types, categories, classifications and types, and indicates the level type of folklore;
[0017] The zero-shot traditional folk triple extraction framework ZFTE is as follows:
[0018] The zero-shot traditional folk triple extraction framework designs the triple extraction task as a chain extraction mode, which is divided into two stages. Stage 1 is responsible for identifying the relationship in the text and filtering out the non-existent element types to reduce the search space and computational complexity, which is conducive to the extraction of triples; Stage 2 is responsible for extracting the tail entity corresponding to the relationship identified in Stage 1;
[0019] Phase 1: This phase only includes relation identification. In order to identify the type of relation presented in the sentence, we first use a template specific to the phase 1 task to combine the folk entity entity, the relation relation in the folk ontology, and the folk text sentence as the input of the large language model. Since it is difficult to predict all the relations in the folk ontology at one time and it is not easy to expand, the framework adopts a polling method to divide the relations in the ontology and identify a fixed number of relations each time; if the ontology is too long, it will be divided into multiple groups and input into the large language model in turn, and it is set to ask 4 types of relations each time; in order to alleviate the deviation of the large language model in understanding relations in the folk field, each relation has a customized relation interpretation instruction in the format of {relation: detailed definition of the relation, specific example}. To facilitate the extraction of the answer, the system is required to reply in the form of a tuple. If the sentence does not contain any relation type, the answer is "none";
[0020] Phase II: This phase includes tail entity recognition. In Phase I, the relation type contained in the folk text was identified, but the corresponding entity has not been obtained. The task template of the second phase is designed as a slot filling problem. First, the template specific to the Phase II task is used to take the folk entity entity, folk text sentence, the relation type identified in Phase I and its corresponding relation interpretation instructions and the head and tail entity types as the input of the large language model to identify the tail entity. Since there may be multiple relations provided in Phase I, Phase II requires multiple rounds of question and answer. For complex folk texts, the length of the chain of complex object value extraction in entity relation triple extraction is greater than or equal to 1, that is, the number of tail entities is greater than or equal to 1. The tail entity extraction in Phase II depends on the relation identification in Phase I, so the task template of Phase II is called a chain template. Similarly, in order to facilitate the extraction of answers, the system is required to reply in the form of tuples. If the sentence does not contain any relation type, the answer is "none". Finally, the tail entity extracted in each round is combined into a triple with the folk ontology and relation type.
[0021] The zero-shot traditional folk triple extraction framework is expressed by the formula:
[0022]
[0023] Among them, ZFTE is the triple extraction task, R is the final extracted triple result, R1 and R2 are the return results of the large language model in stage one and stage two respectively, s is the folk entity, p is the predefined relationship list after segmentation, n represents the relationship interpretation instruction, p1...p m is the m relations in the relation list extracted in stage 1, o is the entity with p relations to s, d is the description information of the folk entity, q1 is the prompt question in stage 1, This is the prompt question for stage 2;
[0024] After ZFTE, driven by TFOnto, performs triple extraction on traditional folk texts, the extracted triples are written into the graph database to construct the traditional folk knowledge graph TFKG.
[0025] Furthermore, in step 2), the folk entity recognition method uses a zero-sample prompt method on a large language model, and the system prompt is designed to extract folk entities from the input text and return them in JSON format.
[0026] Going further, the entity vector retrieval stage is as follows:
[0027] The embeddings of all folklore nodes in TFKG are pre-computed using the sentence embedding model, which converts the names of all folklore nodes into dense vector space, making them suitable for semantic search. These folklore node embeddings are stored in the vector database. When searching, the folklore names with the highest vector similarity to the entities identified in the user query are selected for subsequent contextual retrieval. The retrieval process is characterized by the ability to quickly retrieve similar entities from a large number of entities. If the zero-shot hint method for folklore entity recognition fails to identify the folklore entity in the user query, the five folklore entities with the highest vector similarity to the entire user query are selected from the vector database;
[0028] The triples (subject, predicate, object) related to the retrieved folk nodes are queried from TFKG and then converted into natural language to make it compatible with the input of LLMs. The natural language sentences converted from triples are called knowledge blocks.
[0029] The knowledge block reordering stage is as follows:
[0030] The relevant knowledge blocks obtained in the entity vector retrieval stage are not all relevant to the user query, and the retrieval is random, so it is not suitable to input all the texts into the large language model; next, it is necessary to filter the extracted folk knowledge blocks by selecting the most relevant content required by the user query; the retrieval ranking model will use more complex judgment functions to obtain more refined correlation relationships and calculate the scores one by one in a small range, so that the retrieved similar texts are more in line with the query. First, the re-ranking model is used to calculate the correlation scores between the user query and all the extracted folk knowledge blocks; next, only the knowledge blocks with higher scores with the input prompt are selected. For knowledge block selection, the cosine similarity of the prompt knowledge block should meet two conditions: (i) greater than 75% of the similarity distribution of all knowledge blocks related to the selected folk node, and (ii) have a similarity value of at least 0.5.
[0031] The reordering model fine-tuning method is as follows:
[0032] The reranking model is bge-reranker-large, which is pre-trained on a mixed multilingual dataset and fine-tuned using contrastive learning. The format of the fine-tuning dataset is set to {"query":str, "pos":List[str], "neg":List[str]}, where query corresponds to the user's query, pos is a list of positively related samples, and neg is a list of negatively related samples. One of the key factors in contrastive learning is negative samples; the original model is fine-tuned to distinguish between positive and negative samples in folklore question-answering, and it is expected to assign higher scores to the positive samples of the query. The fine-tuning process aims to minimize the cross-encoder loss, and the loss function is set as shown below.
[0033]
[0034] In the above formula, p is the query text, q is the positive sample, q′∈Q′ is the negative sample, τ is the temperature, <e p ,e q > represents the inner product of the embedding vectors of p and q;
[0035] After TFKG retrieves query-related information, it will input the user query into the big language model. The big language model will answer the user query based on the folklore-related information provided, greatly alleviating the factual illusion problem of the big language model in the field of traditional folklore.
[0036] A traditional folk custom intelligent question-answering system based on knowledge graph enhancement, including the following two modules:
[0037] The traditional folklore knowledge graph construction module is used to crawl the corresponding traditional folklore data according to the traditional folklore catalog. TFOnto drives the ZFTE framework to extract triples from the crawled traditional folklore data and use the triples to build the traditional folklore knowledge graph.
[0038] A two-stage retrieval enhancement generation module based on TFKG is used to retrieve relevant data in the traditional folk knowledge graph according to user queries, and input the queries and related data into the large language model for question answering.
[0039] The beneficial effects of the present invention are as follows: the present invention proposes a traditional folklore ontology TFOnto and a zero-sample traditional folklore triple extraction framework ZFTE, and extracts triples by driving ZFTE with TFOnto, thereby constructing a traditional folklore knowledge graph TFKG; the present invention proposes a two-stage retrieval enhancement generation framework based on TFKG, which provides query-related data information for the large language model, greatly alleviating the factual illusion problem of the large language model in the field of traditional folklore. The above whole process is a traditional folklore intelligent question-answering system based on knowledge graph enhancement proposed by the present invention. BRIEF DESCRIPTION OF THE DRAWINGS
[0040] Figure 1 This is the overall architecture diagram of the present invention;
[0041] Figure 2 Constructing a flow chart for the traditional folklore knowledge graph of the present invention;
[0042] Figure 3 It is the traditional folklore ontology diagram of the present invention;
[0043] Figure 4 This is an example diagram of the zero-sample traditional folk triple extraction framework of the present invention;
[0044] Figure 5 A flow chart for the dual-stage search enhancement generation based on TFKG of the present invention;
[0045] Figure 6 Compute process graph for the embedding model;
[0046] Figure 7 Diagram of the calculation process of the reordering model. DETAILED DESCRIPTION
[0047] In order to explain the technical problems, technical solutions, and related steps to be solved by the present invention in more detail, the exemplary embodiments of the present invention will be described using the accompanying drawings. Although the accompanying drawings show exemplary embodiments of the present invention, it should be understood that the present invention should not be limited by the embodiments described herein, but can be implemented in various forms. At the same time, these embodiments are provided to convey the scope of the present invention to relevant persons in the art in more detail.
[0048] Reference Figure 1 to Figure 7 , a traditional folk custom intelligent question-answering method based on knowledge graph enhancement, which uses a crawler to crawl traditional folk custom data information from the URL of the subject website according to the traditional folk custom directory, and extracts triples driven by the traditional folk custom ontology TFOnto and the zero-sample traditional folk custom triple extraction framework ZFTE to build a traditional folk custom knowledge graph TFKG, and then based on the two-stage retrieval enhancement generation framework TFKG_RAG of TFKG, it provides user query-related data for the large language model to perform folk custom field question-answering;
[0049] Figure 1 This is the overall architecture diagram of an embodiment of the present invention. The ZFTE framework uses parameterized knowledge in the large language model to construct a traditional folk knowledge graph. TFKG-RAG uses formalized knowledge in the traditional folk knowledge graph to provide folk domain knowledge for the large language model. The steps are as follows:
[0050] Step 1: Construct a traditional folk knowledge graph: Figure 2The flowchart of the traditional folk custom knowledge graph construction of the present invention is as follows: first, manually collect traditional folk custom catalog information on the official websites of various provinces, then crawl the collected traditional folk custom catalog related data in a given subject website through a crawler, build the traditional folk custom ontology TFOnto based on the CIDOC CRM conceptual model, use TFOnto to drive the ZFTE framework to extract the triples corresponding to the predefined relationships in the ontology from the crawled data, and finally label the extracted triples and write them into the neo4j graph database to build the traditional folk custom knowledge graph;
[0051] In step 1, we manually collected traditional folklore catalog information from the official websites of various provinces, including 595 national folklore items, 2241 provincial folklore items, and 3611 municipal folklore items. For folklore-related information, we selected encyclopedias, authoritative websites, CNKI document websites, etc. as data sources. Specifically, due to the regionality of folklore, there are folklore duplicates in different regions. First, we added regional information to all folklore obtained from the official websites of various provinces, and then compiled the unique name into a query to obtain its information through the crawler. If there are still multiple data entries with the same name, we screened the data with the most complete content and the most authoritative source through expert review, and finally obtained 2911 traditional folklore data information. The crawler program uses the requests package provided in the python language to make requests, and obtains traditional folklore-related data information by requesting the subject website given by the user.
[0052] Figure 2It is the traditional folk ontology TFOnto of the embodiment of the present invention. The classes in TFOnto mainly include CRM: E1Entity, E53 Place, E21 Person, E22 Man-Made Object, E7 Activity, E89 Propositional Object, E52 Time-Span, E41 Appellation, E42 Identifier, E74 Group, and E55 Type. The present invention takes folk customs as the top-level structure, and each folk custom belongs to the scope of CRM:E1 Entity, for example, "Sanmen Winter Festival" can be regarded as its instance; Place is used to describe the reporting area or unit location of the folk custom (such as Sanmen County Cultural Center), popular area (such as Sanmen County, Zhejiang Province) or regional information (such as Zhejiang Province); Person represents the inheritor of the folk custom, such as <Erxianban Sacrifice Altar, has current or former curator, Chen Suzhen>, or the belief / commemoration figure of the folk custom, such as <Dragon Boat Festival, refers to, Qu Yuan>; Man-Made Object refers to items specially created by human activities, which are used to represent sacrificial items and food in folk customs; Activity represents activities held during folk customs (such as dragon boat racing); Propositional Object describes abstract information such as concepts, beliefs, knowledge, etc., which are used to express meanings, such as <Fujian and Taiwan send the king's boat, has note, exorcism, disaster avoidance, blessing>; Time-Span is used to indicate the origin time and festival time of folk customs; Appellation refers to all types of names, labels and titles, used to indicate the alias of folk customs; Identifier is used to indicate the batch and number of folk customs (such as X-148, X-89). Group indicates the ethnic group to which the folk custom belongs; Type refers to various types, categories, classifications and types, indicating the level type of folk customs (such as national level).
[0053] Figure 3 This is an example diagram of the zero-sample traditional folk triple extraction framework in the present invention. When performing triple extraction tasks, extraction is performed according to the relationships defined in TFOnto. ZFTE designs the triple extraction task as a chain extraction mode, which is divided into two stages. Stage one is responsible for identifying relationships in the text and filtering out non-existent element types to reduce the search space and computational complexity, which is conducive to the extraction of triples; stage two is responsible for extracting the tail entity corresponding to the relationship identified in stage one.
[0054] Phase 1: This phase only includes relationship recognition. In order to identify the relationship type presented in the sentence, the folk entity "Sanmen Winter Festival", the relationship "folk level, popular area, event, folk number" in the folk ontology and the folk text "Sanmen Winter Festival, popular in Sanmen County, Taizhou City, Zhejiang Province, one of the national intangible cultural heritages. A grand and solemn folk activity of worshiping the winter and ancestors is held on the winter solstice." are combined as the input of the large language model. Since it is difficult to predict all the relationships in the folk ontology at one time and it is not easy to expand, the framework adopts a polling method to segment the relationships in the ontology and identify a fixed number of relationships each time. If the ontology is set too long, it will be segmented into multiple groups and input into the large language model in turn. The present invention is set to query 4 types of relationships each time. In order to alleviate the deviation of the large language model in understanding relationships in the folk field, each relationship has a customized relationship interpretation instruction in the format of {relationship: relationship detailed definition, specific instance}, and the specific example is {"folk level": "Indicates the level of a certain folk activity in the cultural heritage system, such as <provincial level, municipal level>"}. To facilitate answer extraction, the system is required to reply in tuple form. If the sentence does not contain any relation type, the answer is "None". In the example, three relations "(folk custom level, popular area, held event)" are finally returned in tuple form.
[0055] Phase II: This phase includes tail entity recognition. In Phase I, the relation types contained in the folk text were identified, but the corresponding entities have not yet been obtained. The task template of the second phase is designed as a slot filling problem. First, the folk entity entity, folk text sentence, the relation type identified in Phase I and its corresponding relation interpretation instructions and the head and tail entity types are used as the input of the large language model using a template specific to the Phase II task to identify the tail entity. Since there may be multiple relations provided in Phase I, Phase II usually requires multiple rounds of question and answer. For complex folk texts, the length of the chain of complex object value extraction in entity relation triple extraction is greater than or equal to 1, that is, the number of tail entities is greater than or equal to 1. The tail entity extraction of Phase II depends on the relation identification of Phase I, so the task template of Phase II is called a chain template. Similarly, in order to facilitate the extraction of answers, the system is required to reply in the form of tuples. If the sentence does not contain any relation type, the answer is "none". Finally, the tail entity extracted in each round is combined into a triple with the folk ontology and relation type. In the example, the tail entity with the relation "folk level" of "Sanmen Winter Festival" identified as "national level" is "national level".
[0056] The zero-shot traditional folk triple extraction framework is expressed by the formula:
[0057]
[0058] Among them, ZFTE is the triple extraction task, R is the final extracted triple result, R1 and R2 are the return results of the large language model in stage one and stage two respectively, s is the folk entity, p is the predefined relationship list after segmentation, n represents the relationship interpretation instruction, p1...p m is the m relations in the relation list extracted in stage 1, o is the entity with p relations to s, d is the description information of the folk entity, q1 is the prompt question in stage 1, This is the prompt question for stage 2;
[0059] After the above-mentioned TFOnto drives ZFTE to perform the triple extraction task on the traditional folk text, the extracted triples are labeled accordingly and written into the neo4j database to construct the traditional folk knowledge graph TFKG, which contains a total of 29,983 relationships and 17,974 nodes.
[0060] Step 2: Generate query-related data for the large language model based on the two-stage retrieval enhancement of TFKG: Figure 5 The present invention is a two-stage retrieval enhancement generation flow chart based on TFKG. The flow involves entity recognition, entity vector retrieval stage and knowledge block reordering stage. First, the user inputs a query related to the folklore field, then entity recognition is performed on the query to identify the folklore entity in the query, similar entity retrieval is performed on the identified entity in the vector database in the entity vector retrieval stage, relevant triple information of the retrieved entity is queried in TFKG, the triple is converted into a folklore knowledge block, the folklore knowledge block is reordered in the knowledge block reordering stage, and the knowledge block most relevant to the user query is returned to the large language model for folklore knowledge question and answer. Since the performance of the reordering affects the question and answer effect of the large language model, the reordering is fine-tuned using a comparative learning method to enhance the question and answer performance of the large language model.
[0061] In step 2, according to Figure 5 As shown in the flowchart, the user first enters the query "What level of intangible cultural heritage is the Chinese folk custom "Sanmen Winter Festival"?", and then performs folk entity recognition on the query to identify the "Sanmen Winter Festival" entity. The folk entity recognition method mainly uses the zero-sample prompt method on the large language model. Specifically, the system prompt is designed to extract folk entities from the input text and return them in JSON format. The folk entity recognition template is: "You are an expert in extracting Chinese folk entities from sentences and report them in JSON format in the following format: {"folk": <extracted entity list>} Please report only folk entities. Do not report other entities."
[0062] In the entity vector retrieval stage, the embeddings of all folk custom nodes in TFKG are pre-computed using the "bge-large-zh-v1.5" sentence embedding model. This process converts the names of all folk custom nodes into a 1024-dimensional dense vector space, making it suitable for semantic search. These folk custom node embeddings are stored in the "Chroma" vector database. During retrieval, the folk custom name with the highest vector similarity to the entity identified in the user query is selected for subsequent context retrieval. The characteristic of this retrieval process is that it can quickly retrieve similar entities among a large number of entities. The embedding model retrieval process is as Figure 6 shown. After vectorizing the entity, the embedding model directly calculates the similarity comparison with the entities that have been pre-vectorized in the vector database and selects the entity with the highest similarity. If the zero-shot prompting method for folk custom entity recognition fails to recognize the folk custom entity in the user query, five folk custom entities with the highest vector similarity to the entire user query will be selected from the vector database.
[0063] Triples (subject, predicate, object) related to the retrieved folk custom nodes are queried from TFKG and then converted into natural language to be compatible with the input of LLMs. For example, the triple <Sanmen Winter Solstice Sacrifice, has type, National Level> can be converted to "Sanmen Winter Solstice Sacrifice has type National Level". The natural language statement converted from such a triple is called a knowledge chunk.
[0064] The knowledge chunk re-ranking stage is as follows:
[0065] The relevant knowledge chunks obtained in the entity vector retrieval stage are not all relevant to the user query, and the retrieval is random. Therefore, it is not suitable to input all the text into the large language model. Next, it is necessary to filter and extract the folk custom knowledge chunks by selecting the most relevant content required by the user query. Figure 7 is the computational process diagram of the re-ranking model. The re-ranking model will utilize a more complex decision function to obtain a more refined correlation relationship and calculate scores one by one within a small range, making the retrieved similar texts more in line with the query. First, the re-ranking model calculates the correlation scores between the user query and all the extracted folk custom knowledge chunks. Next, only the knowledge chunks with higher scores compared to the input prompt are selected. For knowledge chunk selection, the cosine similarity of the prompt knowledge chunk should meet two conditions: (i) greater than 75% of the similarity distribution of all knowledge chunks related to the selected folk custom node, and (ii) having a similarity value of at least 0.5.
[0066] The re-ranking model fine-tuning method is as follows:
[0067] The reranking model selected in this embodiment is bge-reranker-large, which is pre-trained on a mixed multilingual dataset; it is fine-tuned using contrastive learning, and the format of the fine-tuning dataset is set to {"query":str, "pos": List[str], "neg": List[str]}, where query corresponds to the question queried by the user, pos is a list of positively related samples, and neg is a list of negatively related samples. One of the key factors in contrastive learning is negative samples. According to this data format, a folklore field fine-tuning dataset containing 200 data was produced, and the original model was fine-tuned to distinguish between positive and negative samples in folklore field questions and answers, in the hope of assigning higher scores to the positive samples of the query. The deep learning framework used for fine-tuning is PyTorch 2.1.2, and the Adam optimizer is used when fine-tuning the model, with a learning rate of 6e-5. The training cycle is set to 5, the batch size is 1, and the data type is fp16. The fine-tuning process aims to minimize the cross-encoder loss, and the loss function is set as follows:
[0068]
[0069] In the above formula, p is the query text, q is the positive sample, q′∈Q′ is the negative sample, τ is the temperature, <e p ,e q > represents the inner product of the embedding vectors of p and q.
[0070] After TFKG retrieves the relevant information of the question, the user query is input into the large language model together. The large language model used in the present invention is LLaMA3-8b-instruct, which has 8 billion parameters and a token size of 8000. It is deployed in GeForce RTX 4090, i7-10700F CPU and RAM is 64GB, and the operating system is Windows 10 server. The knowledge block capacity size is set to 150, the minimum similarity of the knowledge block is set to 0.5, and the percentile threshold for calculating the similarity value is set to 75%. LLaMA3-8b-instruct will answer the user query in combination with the folklore related information provided, which greatly alleviates the factual illusion problem of the large language model in the field of traditional folklore, and enhances the accuracy and reliability of the large language model in the field of folklore. The above whole process is a traditional folklore intelligent question-answering method based on knowledge graph enhancement proposed by the present invention.
[0071] A traditional folk custom intelligent question-answering system based on knowledge graph enhancement, including the following two modules:
[0072] The traditional folklore knowledge graph construction module is used to crawl the corresponding traditional folklore data according to the traditional folklore catalog. TFOnto drives the ZFTE framework to extract triples from the crawled traditional folklore data and use the triples to build the traditional folklore knowledge graph.
[0073] A two-stage retrieval enhancement generation module based on TFKG is used to retrieve relevant data in the traditional folk knowledge graph according to user queries, and input the queries and related data into the large language model for question answering.
[0074] Although the specific implementation method steps of the present invention are described above so that those skilled in the art can understand the present invention, it should be understood that the present invention is not limited to the scope of the specific embodiments, and for those skilled in the art, the present invention may have various changes and variations. Any modifications, equivalent substitutions, improvements, etc. made within the spirit and principles of the present invention should be included in the protection scope of the present invention. Therefore, the protection scope of this application should be based on the protection scope of the claims.
Claims
1. A traditional folk custom intelligent question-answering method based on knowledge graph enhancement, characterized in that: First, we collect traditional folk catalog information from the official websites of various provinces, then use crawlers to crawl data related to the names of traditional folk catalogs on relevant websites, use TFOnto to drive the ZFTE framework to extract triples from the crawled traditional folk data, and write the extracted triples into the graph database to construct the traditional folk knowledge graph TFKG; when users query questions related to the folklore field, we use the TFKG-based two-stage retrieval enhancement generation module to retrieve data information related to the user's query in TFKG, and input the user's insert and related data into the large language model for question and answer.
2. The traditional folk custom intelligent question-answering method based on knowledge graph enhancement as claimed in claim 1, characterized in that: The steps of the method are as follows: Step 1) Constructing the traditional folklore knowledge graph: first manually collect traditional folklore catalog information from the official websites of each province, then crawl the collected traditional folklore catalog related data from the given subject website through a crawler, build the traditional folklore ontology TFOnto based on the CIDOCCRM conceptual model, use TFOnto to drive the ZFTE framework to extract the triples corresponding to the predefined relationships in the ontology from the crawled data, and finally write the extracted triples into the graph database to construct the traditional folklore knowledge graph; Step 2) The two-stage retrieval enhancement generation based on TFKG provides query-related data for the large language model: This step involves entity recognition, entity vector retrieval stage and knowledge block re-ranking stage; first, the user inputs a query related to the folklore field, then entity recognition is performed on the query to identify the folklore entities in the query, similar entities are retrieved for the identified entities in the vector database in the entity vector retrieval stage, relevant triple information of the retrieved entities is queried in TFKG, the triples are converted into folklore knowledge blocks, the folklore knowledge blocks are re-ranked in the knowledge block re-ranking stage, and the knowledge blocks most relevant to the user query are returned to the large language model for folklore knowledge question and answering; since the performance of the re-ranking affects the question and answer effect of the large language model, the re-ranking is fine-tuned using contrastive learning to enhance the question and answer performance of the large language model.
3. The traditional folk custom intelligent question-answering method based on knowledge graph enhancement as claimed in claim 2, characterized in that: In step 1), the traditional folklore ontology TFOnto is constructed as follows: The classes in TFOnto include CRM:E1 Entity, E53 Place, E21 Person, E22 Man-Made Object, E7Activity, E89 Propositional Object, E52 Time-Span, E41 Appellation, E42Identifier, E74 Group, and E55 Type. Folklore is used as the top-level structure. Each folklore belongs to the scope of CRM:E1 Entity. Place is used to describe the reporting area or unit location, popular area or regional information of the folklore; Person represents the inheritor of the folklore or the belief / commemorative figure of the folklore; Man-Made Object refers to objects specially created by human activities, which are used to represent sacrificial objects and food in folklore; Activity represents activities held during folklore; PropositionalObject describes concepts, beliefs or knowledge, which are used to express meaning; Time-Span is used to represent the origin time and festival time of folklore; Appellation refers to all types of names, tags and titles, which are used to represent the alias of folklore; Identifier is used to represent the batch and number of folklore; Group represents the ethnic group to which the folklore belongs; Type refers to various types, categories, classifications and kinds, indicating the level type of folklore; The zero-shot traditional folk triple extraction framework ZFTE is as follows: The zero-shot traditional folk triple extraction framework designs the triple extraction task as a chain extraction mode, which is divided into two stages. Stage one is responsible for identifying the relationship in the text and filtering out the non-existent element types to reduce the search space and computational complexity, which is conducive to the extraction of triples; stage two is responsible for extracting the tail entity corresponding to the relationship identified in stage one; Phase 1: This phase only includes relation recognition. In order to identify the type of relation presented in the sentence, we first use a template specific to the phase 1 task to combine the folk entity, the relation in the folk ontology, and the folk text sentence as the input of the large language model. Since it is difficult to predict all the relations in the folk ontology at one time and it is not easy to expand, the framework adopts a polling method to segment the relations in the ontology and identify a fixed number of relations each time. If the ontology is too long, it will be segmented into multiple groups and input into the large language model in turn, and it is set to ask 4 types of relations each time. In order to alleviate the deviation of the large language model in understanding relations in the folk field, each relation has a customized relation interpretation instruction in the format of {relation: detailed definition of the relation, specific instance}. To facilitate the extraction of answers, the system is required to reply in the form of tuples. If the sentence does not contain any relation type, the answer is "none". Phase II: This phase includes tail entity recognition. In Phase I, the relation type contained in the folk text was identified, but the corresponding entity has not been obtained. The task template of the second phase is designed as a slot filling problem. First, the folk entity entity, folk text sentence, relation type identified in Phase I and its corresponding relation interpretation instruction and head and tail entity types are used as the input of the large language model to identify the tail entity using a template specific to the Phase II task. Since there may be multiple relations provided in Phase I, Phase II requires multiple rounds of question and answer. For complex folk texts, the chain length of the complex object value extraction in the entity relation triple extraction is greater than or equal to 1, that is, the number of tail entities is greater than or equal to 1. The tail entity extraction in Phase II depends on the relation identification in Phase I, so the task template of Phase II is called a chain template. Similarly, in order to facilitate the extraction of answers, the system is required to reply in the form of tuples. If the sentence does not contain any relation type, the answer is "none". Finally, the tail entity extracted in each round is combined into a triple with the folk ontology and relation type. The zero-shot traditional folk triple extraction framework is expressed by the formula: Among them, ZFTE is the triple extraction task, R is the final extracted triple result, R1 and R2 are the return results of the large language model in stage one and stage two respectively, s is the folk entity, p is the predefined relationship list after segmentation, n represents the relationship interpretation instruction, p1...p m is the m relations in the relation list extracted in stage 1, o is the entity with p relations to s, d is the description information of the folk entity, q1 is the prompt question in stage 1, This is the prompt question for stage 2; After ZFTE, driven by TFOnto, performs triple extraction on traditional folk texts, the extracted triples are written into the graph database to construct the traditional folk knowledge graph TFKG.
4. The traditional folk custom intelligent question-answering method based on knowledge graph enhancement as claimed in claim 2 or 3, characterized in that: In the step 2), the folk entity recognition method uses a zero-sample prompt method on a large language model, and the system prompt is designed to extract folk entities from the input text and return them in JSON format.
5. The traditional folk custom intelligent question-answering method based on knowledge graph enhancement as claimed in claim 2 or 3, characterized in that: The entity vector retrieval stages are as follows: The embeddings of all folklore nodes in TFKG are pre-calculated using the sentence embedding model. This process converts the names of all folklore nodes into dense vector space, making them suitable for semantic search. These folklore node embeddings are stored in the vector database. When searching, the folklore names with the highest vector similarity to the entities identified in the user query are selected for subsequent contextual retrieval. The retrieval process is characterized by the ability to quickly retrieve similar entities from a large number of entities. If the zero-shot hint method for folklore entity recognition fails to identify the folklore entity in the user query, the five folklore entities with the highest vector similarity to the entire user query are selected from the vector database. The triples (subject, predicate, object) related to the retrieved folk nodes are queried from TFKG and then converted into natural language to make it compatible with the input of LLMs. The natural language sentences converted from triples are called knowledge blocks.
6. The traditional folk custom intelligent question-answering method based on knowledge graph enhancement as claimed in claim 2 or 3, characterized in that: The knowledge block reordering stage is as follows: The relevant knowledge blocks obtained in the entity vector retrieval stage are not all related to the user query, and the retrieval is random, so it is not suitable to input all the texts into the large language model; next, it is necessary to filter the extracted folk knowledge blocks by selecting the most relevant content required by the user query; the retrieval ranking model will use more complex judgment functions to obtain more detailed correlation relationships and calculate the scores one by one within a small range, so that the retrieved similar texts are more consistent with the query. First, the re-ranking model is used to calculate the correlation scores between the user query and all the extracted folk knowledge blocks; Next, only knowledge chunks with higher scores to the input prompt are selected. For knowledge chunk selection, the cosine similarity of the prompt knowledge chunk should satisfy two conditions: (i) be greater than 75% of the similarity distribution containing all knowledge chunks related to the selected folk node, and (ii) have a similarity value of at least 0.
5.
7. The traditional folk custom intelligent question-answering method based on knowledge graph enhancement as claimed in claim 6, characterized in that: The reordering model fine-tuning method is as follows: The reranking model is bge-reranker-large, which is pre-trained on a mixed multilingual dataset and fine-tuned using contrastive learning. The format of the fine-tuning dataset is set to {"query":str,"pos":List[str],"neg":List[str]}, where query corresponds to the user's query, pos is a list of positively related samples, and neg is a list of negatively related samples. One of the key factors in contrastive learning is negative samples. The original model is fine-tuned to distinguish between positive and negative samples in folklore question-answering, hoping to assign higher scores to the positive samples of the query. The fine-tuning process aims to minimize the cross-encoder loss, and the loss function is set as follows: In the above formula, p is the query text, q is the positive sample, q′∈Q′ is the negative sample, τ is the temperature, <e p ,e q > represents the inner product of the embedding vectors of p and q; After TFKG retrieves query-related information, it will input the user query into the big language model. The big language model will answer the user query based on the folklore-related information provided, greatly alleviating the factual illusion problem of the big language model in the field of traditional folklore.
8. A system for implementing the traditional folk custom intelligent question-answering method based on knowledge graph enhancement as claimed in claim 1, characterized in that: The system includes the following two modules: The traditional folklore knowledge graph construction module is used to crawl the corresponding traditional folklore data according to the traditional folklore catalog. TFOnto drives the ZFTE framework to extract triples from the crawled traditional folklore data and use the triples to build the traditional folklore knowledge graph. A two-stage retrieval enhancement generation module based on TFKG is used to retrieve relevant data in the traditional folk knowledge graph according to user queries, and input the queries and related data into the large language model for question answering.
Citation Information
Patent Citations
Question-answering system based on domain knowledge graph and construction method thereof
CN110555153A
Liao dynasty historical culture field knowledge graph and construction method of intelligent question-answering system thereof
CN112417100A
Question and answer method and device for knowledge in field of literature and blog, equipment and medium
CN117216194A
Position type theme knowledge graph construction method with entity ambiguity intelligent identification function
CN117408339A
Construction industry safety question and answer method and equipment based on large language model technology
CN118332092A
Cited By
Large Language Model (LLM) Token Truncation
US20260170265A1
Large language model (LLM) token truncation
WO2026129066A1
