A Question Answering Generation Method Based on Knowledge Graph

Through a bidirectional semantic encoder and hierarchical knowledge fusion network, the hierarchical question-and-answer path is constructed, which solves the problems of knowledge extraction and semantic alignment in the knowledge graph question-and-answer system, realizes the generation of high-quality question-and-answer pairs, and improves the practicality and scalability of the system.

CN119807349BActive Publication Date: 2025-08-05NANJING XINZHI ART TESTING TECH CO LTD
View PDF 2 Cites 0 Cited by

Patent Information

Application Number
CN202411790033.0
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2024-12-06
Publication Date
2025-08-05
Estimated Expiration
2044-12-06

AI Technical Summary

Technical Problem

The existing knowledge graph Q&A system has problems of low accuracy and poor results in knowledge extraction, semantic alignment and Q&A path construction, and it is difficult to deal with complex multi-round dialogue and deep semantic understanding, resulting in the quality of the generated Q&A.

Method used

The bidirectional semantic encoder is used to extract entity words and relational words, build basic knowledge structures through a triple-component decompositioner, use a hierarchical knowledge fusion network for semantic alignment, build a hierarchical question-and-answer path based on a dynamic weight allocator, and generate a Q&A data set through an attention model.

Benefits of technology

It improves the accuracy of knowledge extraction, realizes accurate knowledge alignment and high-quality Q&A pair generation, and improves the practicality and scalability of the Q&A system.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN119807349B_ABST
    Figure CN119807349B_ABST
Patent Text Reader

Abstract

The present invention discloses a question-answer generation method based on a knowledge graph, which relates to the technical fields of artificial intelligence and natural language processing. The method includes processing an input text corpus by using a bidirectional semantic encoder to extract entity words and relationship words, forming a first semantic vector, and converting it into a basic knowledge structure through a triple decomposer; using a hierarchical knowledge fusion network to align the basic knowledge structure with the deep semantic information in a preset knowledge graph to generate a multi-dimensional knowledge feature matrix, using a dynamic weight allocator to calculate the association strength between knowledge nodes, and constructing a hierarchical question-answer path in the order from high to low of the association strength; inputting the hierarchical question-answer path into a constructed attention model to generate a question-answer pair data set according to a question-answer template library. The present invention not only improves the accuracy of knowledge extraction and the effect of knowledge fusion, but also optimizes the construction process of the question-answer path, forming a question-answer pair data set with a complete structure.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present invention relates to the technical fields of artificial intelligence and natural language processing, and particularly to a question-answer generation method based on a knowledge graph. Background Art

[0002] As a structured knowledge representation method, the knowledge graph can effectively organize and manage large-scale knowledge information, providing important knowledge support for intelligent question-answer systems. Traditional knowledge graph question-answer systems mainly construct question-answer pairs using methods such as template matching, semantic parsing, and deep learning. These methods perform well in dealing with simple question-answer scenarios, but still face many challenges in dealing with complex multi-turn conversations and deep semantic understanding. Especially in key links such as knowledge extraction, semantic alignment, and question-answer path construction, existing technologies often have difficulty accurately capturing entity relationships and deep semantic information in text, resulting in less-than-ideal quality of generated question-answer pairs.

[0003] Currently, the existing knowledge graph question-answer technologies have the following problems in knowledge representation and question-answer generation: First, traditional knowledge extraction methods often use one-way encoding or simple feature extraction methods, unable to fully utilize the context information and semantic features of text; second, in the process of knowledge fusion, there is a lack of effective semantic alignment mechanisms, making it difficult to accurately identify and match knowledge entities from different sources; third, the construction of question-answer paths usually uses static rules or fixed templates, making it difficult to adapt to dynamically changing knowledge structures and user needs; finally, the hierarchical nature and relevance of knowledge are not fully considered in the generation process of question-answer pairs, resulting in the generated question-answer content lacking systematicness and coherence. These problems seriously affect the practicality and scalability of knowledge graph question-answer systems.

[0004] These problems existing in the prior art urgently need to be solved by a new knowledge graph question-answer generation method. A question-answer generation method based on a knowledge graph proposed by the present invention aims to solve problems such as low precision of knowledge extraction, poor semantic alignment effect, unreasonable construction of question-answer paths, and low quality of generated question-answer pairs in the prior art; by introducing technical means such as bidirectional semantic encoding, hierarchical knowledge fusion, and dynamic weight allocation, it realizes the efficient extraction, accurate alignment, and reasonable organization of knowledge. Summary of the Invention

[0005] In view of the problems existing in the existing knowledge graph question-answer generation methods in aspects such as knowledge extraction, semantic alignment, path construction, and question-answer generation, the present invention is proposed.

[0006] Therefore, the problem to be solved by the present invention is how to improve the accuracy of knowledge extraction, achieve accurate alignment of knowledge, construct a reasonable hierarchical question-answer path, and generate a high-quality question-answer pair dataset.

[0007] In order to solve the above technical problems, the present invention provides the following technical solutions:

[0008] In the first aspect, an embodiment of the present invention provides a question and answer generation method based on a knowledge graph, which includes: using a bidirectional semantic encoder to process an input text corpus, extracting entity words and relationship words, forming a first semantic vector, and converting the first semantic vector into a basic knowledge structure through a triple decomposer; using a hierarchical knowledge fusion network to align the basic knowledge structure with the deep semantic information in a preset knowledge graph to generate a multidimensional knowledge feature matrix; based on the multidimensional knowledge feature matrix, using a dynamic weight allocator to calculate the association strength between knowledge nodes, and constructing a hierarchical question and answer path in order of association strength from high to low; inputting the hierarchical question and answer path into the constructed attention model, and generating a question and answer pair dataset based on the question and answer template library.

[0009] As a preferred solution of the question-answer generation method based on knowledge graph described in the present invention, wherein: the attention model includes an encoder and a decoder; the encoder performs multi-level feature extraction on the input hierarchical question-answer path, and calculates the attention weight score of each knowledge node in the path through the self-attention mechanism to identify key knowledge nodes; the decoder matches the key knowledge nodes with the corresponding question-answer templates according to the question-answer templates pre-stored in the question-answer template library; the method for generating the question-answer pair data set is to dynamically integrate the semantic information of the key knowledge nodes into the structure of the question-answer pattern through the cross-attention mechanism to generate question-answer pairs, wherein the question-answer pairs include question text, answer text and corresponding knowledge path information; based on the question-answer pairs, rule filtering and semantic similarity calculation are used for screening; the screened question-answer pairs are organized according to the hierarchical relationship of the knowledge nodes to form a structured question-answer pair data set.

[0010] As a preferred solution of the question-answer generation method based on knowledge graph described in the present invention, wherein: the method for constructing the hierarchical question-answer path is that the dynamic weight allocator includes a feature aggregation unit and a weight calculation unit; the feature aggregation unit performs weighted summation on the attribute features of the nodes in the multidimensional knowledge feature matrix to generate a node representation vector; the weight calculation unit calculates the association strength of the node pairs based on the node representation vector and filters the node pairs; the node pairs that pass the screening are sorted from high to low according to the association strength value, and the node pairs are divided into different levels based on the sorting results; within each level, a directed connection path is constructed based on the semantic dependency and relationship topology features of the node pairs; the directed connection paths of each level are connected in series in sequence to form a hierarchical question-answer path, in which the high-level nodes are used as core knowledge points and the low-level nodes are used as extended knowledge points.

[0011] As a preferred solution of the knowledge graph-based question and answer generation method described in the present invention, wherein: the specific formula for the association strength is as follows:

[0012]

[0013] Wherein, R ij is the association strength value between node i and node j, v i and v j are the representation vectors of node i and node j respectively, T is the transpose of the representation vector v i , M is the feature transformation matrix, β, ε and γ are adjustment coefficients, d is the feature dimension, w k is the weight coefficient of the k-th dimension feature, x ik and x jk are the feature values of node i and node j in the k-th dimension respectively.

[0014] As a preferred solution of the knowledge graph-based question and answer generation method described in the present invention, wherein: based on the multi-dimensional knowledge feature matrix, a dynamic weight allocator is used to calculate the association strength between knowledge nodes, and a hierarchical question and answer path is constructed in the order of decreasing association strength, including: the hierarchical knowledge fusion network includes an entity alignment unit and a relationship mapping unit; the semantic similarity between the entity in the basic knowledge structure and the entity in the preset knowledge graph is calculated through the entity alignment unit to judge whether this entity pair meets the matching condition; the relationship words in the basic knowledge structure and the relationships in the preset knowledge graph are semantically mapped through the relationship mapping unit by using the multi-head attention mechanism to extract the corresponding relationships between the relationships; an alignment matrix is constructed based on the entity alignment result of the entity alignment unit and the mapping result of the relationship mapping unit; the entity attribute features related to the alignment matrix are extracted from the preset knowledge graph, and at the same time, the relationship topology features between entities are extracted; the entity attribute features and the relationship topology features are combined to form a multi-dimensional knowledge feature matrix, where the rows of the multi-dimensional knowledge feature matrix represent different entity nodes, and the columns represent the corresponding attribute dimensions and topology features.

[0015] As a preferred solution of the knowledge graph-based question and answer generation method described in the present invention, wherein: the specific formula for the semantic similarity is as follows:

[0016]

[0017] Wherein, Sim(e1, e2) is the semantic similarity value between the entity in the basic knowledge structure and the entity in the preset knowledge graph, α is the weight coefficient of the semantic similarity, v1 is the vectorized semantic representation of the entity in the basic knowledge structure, v2 is the vectorized semantic representation of the entity in the preset knowledge graph, n is the number of entity attributes, is the i-th attribute of the entity in the basic knowledge structure, is the i-th attribute of the entity in the preset knowledge graph, is the similarity score of the i-th attribute, e1 is the entity in the basic knowledge structure, and e2 is the entity in the preset knowledge graph.

[0018] When the semantic similarity is greater than or equal to the first preset threshold, the entity pair is matched; when the semantic similarity is less than the first preset threshold, the entity pair is temporarily stored in the buffer to be processed, and the semantic representation of the entity is extended, and the semantic similarity of the extended entity is recalculated; if the semantic similarity of the extended entity is still less than the first preset threshold, the entity pair is marked as an unmatched state, and a zero value is filled in the corresponding position in the alignment matrix; if the semantic similarity of the extended entity is still greater than or equal to the first preset threshold, the entity pair is matched.

[0019] As a preferred solution of the method for generating questions and answers based on a knowledge graph according to the present invention, wherein: a bidirectional semantic encoder is used to process the input text corpus, extract entity words and relationship words, form a first semantic vector, and convert the first semantic vector into a basic knowledge structure through a triple decomposer, including: the bidirectional semantic encoder includes a forward encoding layer and a backward encoding layer; the forward encoding layer scans the tokens in the input text corpus from left to right in sequence; the backward encoding layer scans the tokens in the input text corpus from right to left in sequence; the conversion method of the basic knowledge structure is to adaptively fuse the output results of the forward encoding layer and the backward encoding layer, determine the importance of the forward encoding layer and the backward encoding layer through a dynamic weight distribution mechanism, and at the same time introduce a multi-scale convolution operation to extract local semantic features, and combine position encoding information to enhance the sequence feature representation of the input text corpus, generate a text semantic representation; process the text semantic representation with a preset named entity recognition model to identify and label the type and boundary information of the entity word; use a dependency parser to parse the syntactic structure of the text semantic representation to extract the relationship words between the entity words; concatenate the identified entity words, the type and boundary information of the entity words, the relationship words, and the semantic features corresponding to the relationship words in the vector space through a feature concatenator to form a first semantic vector; process the first semantic vector through a triple decomposer, and divide the semantic vector into several sub-vector segments by using a sliding window mechanism; perform semantic analysis and knowledge element extraction on the several sub-vector segments to construct a basic knowledge structure.

[0020] Second aspect, an embodiment of the present invention provides a question and answer generation method system based on a knowledge graph, which includes: an extraction and transformation module, configured to process the input text corpus using a bidirectional semantic encoder, extract entity words and relationship words, form a first semantic vector, and transform the first semantic vector into a basic knowledge structure through a triple decomposer; a generation module, configured to align the basic knowledge structure with the deep semantic information in a preset knowledge graph using a hierarchical knowledge fusion network to generate a multi-dimensional knowledge feature matrix; a construction module, based on the multi-dimensional knowledge feature matrix, calculates the association strength between knowledge nodes using a dynamic weight allocator, and constructs a hierarchical question and answer path in the order of decreasing association strength; a generation module, configured to input the hierarchical question and answer path into the constructed attention model, and generate a question and answer pair dataset according to a question and answer template library.

[0021] Third aspect, an embodiment of the present invention provides a computer device, including a memory and a processor, where the memory stores a computer program, and: when the computer program instructions are executed by the processor, the steps of the question and answer generation method based on the knowledge graph as described in the first aspect of the present invention are implemented.

[0022] Fourth aspect, an embodiment of the present invention provides a computer-readable storage medium, on which a computer program is stored, and: when the computer program instructions are executed by the processor, the steps of the question and answer generation method based on the knowledge graph as described in the first aspect of the present invention are implemented.

[0023] The beneficial effects of the present invention are as follows: The present invention realizes high-precision entity and relationship extraction by using a bidirectional semantic encoder and a multi-level named entity recognition model, effectively retaining the context semantic information of the text; through the semantic alignment mechanism of the hierarchical knowledge fusion network, the deep semantic fusion of the basic knowledge structure and the preset knowledge graph is realized, improving the integrity of knowledge representation; the hierarchical question and answer path constructed based on the dynamic weight allocator ensures the rationality of knowledge connection and the gradualness of knowledge transfer; through the cooperation of the attention model and the question and answer template library, the intelligent generation of high-quality question and answer pairs is realized. Description of the Drawings

[0024] In order to more clearly illustrate the technical solutions of the embodiments of the present invention, the following will briefly introduce the drawings required for the description of the embodiments. Obviously, the following drawings are only some embodiments of the present invention. For those of ordinary skill in the art, other drawings can be obtained based on these drawings without creative efforts. Among them:

[0025] Figure 1 It is a flowchart of the question and answer generation method based on the knowledge graph for Embodiment 1.

[0026] Figure 2Semantic similarity distribution diagram of the question-answering generation method based on the knowledge graph in Embodiment 1. Detailed implementation manners

[0027] To make the above objects, features, and advantages of the present invention more obvious and understandable, the following will describe the detailed implementation manners of the present invention in conjunction with the accompanying drawings of the specification.

[0028] In the following description, many specific details are set forth to facilitate a full understanding of the present invention. However, the present invention may also be implemented in other ways different from those described herein. Those skilled in the art can make similar extensions without departing from the connotation of the present invention. Therefore, the present invention is not limited by the specific embodiments disclosed below.

[0029] Secondly, the so-called "one embodiment" or "embodiment" herein refers to a specific feature, structure, or characteristic that may be included in at least one implementation manner of the present invention. The appearances of "in one embodiment" in different places in this specification do not all refer to the same embodiment, nor are they separate or alternative embodiments that exclude each other with other embodiments.

[0030] Embodiment 1

[0031] [[ID=q17]]Refer to Figures 1 to 2 , which is the first embodiment of the present invention. This embodiment provides a question-answering generation method based on a knowledge graph, including:

[0032] S1: Use a bidirectional semantic encoder to process the input text corpus, extract entity words and relationship words, form a first semantic vector, and convert the first semantic vector into a basic knowledge structure through a triple decomposer.

[0033] Specifically, the bidirectional semantic encoder includes a forward encoding layer and a backward encoding layer; the forward encoding layer scans the tokens in the input text corpus from left to right in sequence; the specific formula of the forward encoding layer is as follows:

[0034] H f =σ(W f X + b f + η t-1 );

[0035] Among them, H f is the forward encoding output vector, W f is the forward encoding weight matrix, X is the input text sequence vector, b f is the input text sequence vector, σ is the activation function, and η t-1 is the historical information influence factor;

[0036] Furthermore, the backward encoding layer scans the tokens in the input text corpus from right to left in sequence; the specific formula of the forward encoding layer is as follows:

[0037] H b = σ(W b X + b b + ξ t+1 );

[0038] where, H b is the backward encoding output vector, σ is the activation function, W b is the backward encoding weight matrix, X is the input text sequence vector, b b is the backward encoding bias term, and ξ t+1 is the prediction information influence factor;

[0039] It should be noted that when the forward encoding layer and the backward encoding layer process tokens, they will consider the context information of the tokens, including the influence of the historical processed information and the future to-be-processed information, and capture semantic features.

[0040] Furthermore, the output results of the forward encoding layer and the backward encoding layer are adaptively fused. The importance of the forward encoding layer and the backward encoding layer is determined through a dynamic weight allocation mechanism. At the same time, multi-scale convolution operations are introduced to extract local semantic features, and the sequence feature representation of the input text corpus is enhanced by combining positional encoding information to generate a text semantic representation.

[0041] Specifically, the text semantic representation is processed using a preset named entity recognition model to identify and label the types and boundary information of entity words; a dependency parser is used to parse the syntactic structure of the text semantic representation to extract the relational words between entity words.

[0042] It should be noted that the preset named entity recognition model is designed with a hierarchical structure, including a token encoding layer, a feature enhancement layer, a context encoding layer, a tagging prediction layer, and a constraint optimization layer. Token encoding layer: Perform word segmentation on the input text corpus, map each token to a vector representation, and at the same time combine character-level features to extract the internal structure features of the token through a character embedding network, enhancing the processing ability for out-of-vocabulary words and rare words; Feature enhancement layer: Integrate multi-dimensional feature information of tokens, including part-of-speech tagging features, word form features (such as uppercase and lowercase and numbers), morpheme features (such as affixes and roots), and context semantic features provided by pre-trained language models; Context encoding layer: Adopt a bidirectional long short-term memory network structure to capture long-range dependencies in the sequence, introduce a residual connection mechanism during the processing to alleviate the problem of gradient disappearance in deep network training, and at the same time set up a multi-head attention module to extract the mutual association information between tokens from different perspectives; Tagging prediction layer: Construct a conditional random field decoder, fully consider the transition constraint relationship between tags, find the optimal tagging sequence path through the Viterbi algorithm, introduce a label embedding mechanism, and also represent entity type tags as vector forms to enhance the model's semantic understanding ability of entity types; Constraint optimization layer: Design a multi-task learning framework. In addition to the main sequence tagging task, an auxiliary boundary detection task and a type classification task are also introduced. Through the mutual promotion between tasks, the robustness of the model is improved, and at the same time, an entity boundary awareness mechanism is adopted to improve the accuracy of entity boundary recognition.

[0043] Furthermore, the recognized entity words, the type and boundary information of the entity words, relation words, and the semantic features corresponding to the relation words are concatenated and combined in the vector space through a feature splicer to form a first semantic vector; the first semantic vector is processed by a triple decomposer, and the semantic vector is divided into several sub-vector segments by using a sliding window mechanism; semantic analysis and knowledge element extraction are performed on the several sub-vector segments to construct a basic knowledge structure.

[0044] Even further, the sub-vector segments include a head entity, a relation word, and a tail entity.

[0045] S2: Align the basic knowledge structure and the deep semantic information in the preset knowledge graph by using a hierarchical knowledge fusion network to generate a multi-dimensional knowledge feature matrix.

[0046] Specifically, the hierarchical knowledge fusion network includes an entity alignment unit and a relation mapping unit; the method for generating the multi-dimensional knowledge feature matrix is to calculate the semantic similarity between the entities in the basic knowledge structure and the entities in the preset knowledge graph through the entity alignment unit, and judge whether this entity pair meets the matching conditions.

[0047] Furthermore, the specific formula for semantic similarity is as follows:

[0048]

[0049] Among them, Sim(e1, e2) is the semantic similarity value between the entity in the basic knowledge structure and the entity in the preset knowledge graph, α is the weight coefficient of semantic similarity, v1 is the vectorized semantic representation of the entity in the basic knowledge structure, v2 is the vectorized semantic representation of the entity in the preset knowledge graph, n is the number of entity attributes, is the i-th attribute of the entity in the basic knowledge structure, is the i-th attribute of the entity in the preset knowledge graph, is the similarity score of the i-th attribute, e1 is the entity in the basic knowledge structure, and e2 is the entity in the preset knowledge graph.

[0050] Furthermore, when the semantic similarity is greater than or equal to the first preset threshold, the entity pair is matched; when the semantic similarity is less than the first preset threshold, the entity pair is temporarily stored in the buffer to be processed, and the semantic representation of the entity is extended, and the semantic similarity of the extended entity is recalculated; if the semantic similarity of the extended entity is still less than the first preset threshold, the entity pair is marked as an unmatched state, and a zero value is filled in the corresponding position in the alignment matrix; if the semantic similarity of the extended entity is still greater than or equal to the first preset threshold, the entity pair is matched.

[0051] It should be noted that the first preset threshold is a key parameter determined based on the distribution law and empirical analysis of the semantic similarity of entity pairs; by statistically analyzing the semantic similarity of entity pairs in a large-scale labeled sample, the clustering center of the similarity distribution is obtained; secondly, comparative experiments are carried out under multiple candidate thresholds to evaluate the impact of different thresholds on the entity alignment accuracy and recall rate; the preset knowledge graph contains a structured knowledge base of entities, relationships and attributes, and represents and organizes knowledge in the form of triples, where entity nodes carry attribute information and type labels, entities are connected through semantic relationships, and each knowledge unit has a deep semantic representation and vectorized encoding.

[0052] Specifically, the relationship mapping unit uses the multi-head attention mechanism to perform semantic mapping on the relationship words in the basic knowledge structure and the relationships in the preset knowledge graph, and extracts the corresponding relationships between the relationships; based on the entity alignment results of the entity alignment unit and the mapping results of the relationship mapping unit, an alignment matrix is constructed; entity attribute features related to the alignment matrix are extracted from the preset knowledge graph, and at the same time, the relationship topological features between entities are extracted.

[0053] Furthermore, the entity attribute features include the type label, attribute value and numerical features of the entity; the relationship topological features include the directionality, relationship strength and path distance of the relationship.

[0054] Further, the entity attribute features and relationship topology features are combined to form a multi-dimensional knowledge feature matrix, where the rows of the multi-dimensional knowledge feature matrix represent different entity nodes, and the columns represent the corresponding attribute dimensions and topology features.

[0055] S3: Based on the multi-dimensional knowledge feature matrix, a dynamic weight allocator is used to calculate the association strength between knowledge nodes, and a hierarchical question-answering path is constructed in the order of decreasing association strength.

[0056] Specifically, the method for constructing the hierarchical question-answering path is that the dynamic weight allocator includes a feature aggregation unit and a weight calculation unit; the feature aggregation unit performs weighted summation on the attribute features of the nodes in the multi-dimensional knowledge feature matrix to generate node representation vectors; the weight calculation unit calculates the association strength of node pairs based on the node representation vectors and filters the node pairs.

[0057] Further, the specific formula for the association strength is as follows:

[0058]

[0059] where, R ij is the association strength value between node i and node j, v i and v j are the representation vectors of node i and node j respectively, T is the transpose of the representation vector v i , M is the feature transformation matrix, β, ε and γ are adjustment coefficients, d is the feature dimension, w k is the weight coefficient of the k-th dimension feature, x ik and x jk are the feature values of node i and node j in the k-th dimension respectively.

[0060] Further, the screening includes that when the calculated association strength value of the node pair is greater than or equal to the second preset threshold, this node pair is retained and incorporated into the subsequent construction process of the hierarchical question-answering path; when the calculated association strength value of the node pair is less than the second preset threshold, this node pair is excluded.

[0061] It should be noted that the second preset threshold is a dynamic parameter determined based on the statistical distribution and experimental verification of the association strength of knowledge nodes. By calculating the association strength of a large number of knowledge node pairs, the distribution characteristics of the association strength are obtained, and its natural segmentation point is analyzed; at the same time, comparative experiments are carried out under multiple candidate thresholds to evaluate the impact of different thresholds on the construction of the hierarchical question-answering path.

[0062] Specifically, the node pairs passing the screening are sorted in descending order according to the association strength value, and the node pairs are divided into different levels based on the sorting result; within each level, a directed connection path is constructed based on the semantic dependency relationship and relationship topological features of the node pairs; the directed connection paths of each level are concatenated in sequence to form a hierarchical Q&A path, where the nodes at the high level are used as core knowledge points and the nodes at the low level are used as extended knowledge points.

[0063] S4: Input the hierarchical Q&A path into the constructed attention model, and generate a Q&A pair dataset according to the Q&A template library.

[0064] Specifically, the attention model includes an encoder and a decoder; the encoder includes performing multi-level feature extraction on the input hierarchical Q&A path; calculating the attention weight scores of each knowledge node in the path through the self-attention mechanism, and identifying key knowledge nodes based on the attention weight scores; the decoder includes matching the key knowledge nodes with the corresponding Q&A templates according to the Q&A templates pre-stored in the Q&A template library.

[0065] Furthermore, matching the key knowledge nodes with the corresponding Q&A templates includes extracting feature vectors for the input key knowledge nodes; the feature vectors include the node type identifier, attribute features, relationship structure, and context semantic information; using a semantic similarity algorithm to calculate the matching degree between the sub-feature vectors and the Q&A templates, and selecting candidate Q&A templates based on a preset threshold; in the fine matching stage, evaluate from three dimensions of node type consistency, attribute completeness, and relationship structure matching degree, and perform weighted calculation in combination with the historical usage frequency, Q&A quality, and context applicability of the Q&A templates to obtain a comprehensive matching score; perform instantiation processing on the Q&A template with the highest score, map the specific attribute values of the knowledge nodes to the variable positions of the Q&A template, and supplement associated information from the knowledge graph if necessary; start the quality verification mechanism and evaluate according to indicators such as semantic integrity, logical consistency, and expression accuracy.

[0066] It should be noted that the Q&A template library contains various types of Q&A modes, and corresponding question templates and answer templates are set under each mode.

[0067] Furthermore, the method for generating the Q&A pair dataset is to dynamically integrate the semantic information of the key knowledge nodes into the structure of the Q&A mode through the cross-attention mechanism to generate Q&A pairs, where the Q&A pairs include question text, answer text, and corresponding knowledge path information; based on the Q&A pairs, perform screening using rule filtering and semantic similarity calculation.

[0068] Specifically, the screening includes: when the semantic similarity value between the entity in the basic knowledge structure and the entity in the preset knowledge graph is greater than or equal to the third preset threshold, it is determined that there is semantic repetition in this question-and-answer pair, and this question-and-answer pair is eliminated; when the semantic similarity value between the entity in the basic knowledge structure and the entity in the preset knowledge graph is less than the third preset threshold, this question-and-answer pair is retained.

[0069] It should be noted that the third preset threshold is a dynamic parameter value determined through semantic similarity distribution statistics and data verification experiments.

[0070] Furthermore, the question-and-answer pairs that pass the screening are organized according to the hierarchical relationship of knowledge nodes to form a structured question-and-answer pair dataset.

[0071] Even further, this embodiment also provides a question-and-answer generation method system based on a knowledge graph, including: an extraction and transformation module for processing the input text corpus using a bidirectional semantic encoder to extract entity words and relationship words, forming a first semantic vector, and transforming the first semantic vector into a basic knowledge structure through a triple decomposer; a generation module for aligning the basic knowledge structure and the deep semantic information in the preset knowledge graph using a hierarchical knowledge fusion network to generate a multi-dimensional knowledge feature matrix; a construction module for calculating the association strength between knowledge nodes based on the multi-dimensional knowledge feature matrix using a dynamic weight allocator and constructing a hierarchical question-and-answer path in descending order of the association strength; a generation module for inputting the hierarchical question-and-answer path into the constructed attention model to generate a question-and-answer pair dataset according to the question-and-answer template library.

[0072] This embodiment also provides a computer device applicable to the case of the question-and-answer generation method based on a knowledge graph, including a memory and a processor; the memory is used to store computer-executable instructions, and the processor is used to execute the computer-executable instructions to implement the question-and-answer generation method based on a knowledge graph as proposed in the above embodiment.

[0073] The computer device may be a terminal, which includes a processor, a memory, a communication interface, a display screen, and an input device connected via a system bus. Among them, the processor of the computer device is used to provide computing and control capabilities. The memory of the computer device includes a non-volatile storage medium and an internal memory. The non-volatile storage medium stores an operating system and computer programs. The internal memory provides an environment for the operation of the operating system and computer programs in the non-volatile storage medium. The communication interface of the computer device is used to communicate with an external terminal in a wired or wireless manner. The wireless manner can be implemented through WIFI, a carrier network, NFC (Near Field Communication), or other technologies. The display screen of the computer device can be a liquid crystal display screen or an electronic ink display screen. The input device of the computer device can be a touch layer covering the display screen, or buttons, a trackball, or a touchpad provided on the outer shell of the computer device, or an external keyboard, touchpad, or mouse, etc.

[0074] This embodiment also provides a storage medium, on which a computer program is stored. When the program is executed by a processor, the following steps are implemented: using a bidirectional semantic encoder to process the input text corpus, extracting entity words and relationship words, forming a first semantic vector, and converting the first semantic vector into a basic knowledge structure through a triple decomposer; using a hierarchical knowledge fusion network to align the basic knowledge structure with the deep semantic information in a preset knowledge graph to generate a multi-dimensional knowledge feature matrix; based on the multi-dimensional knowledge feature matrix, using a dynamic weight allocator to calculate the association strength between knowledge nodes, and constructing a hierarchical question-answering path in the order of decreasing association strength; inputting the hierarchical question-answering path into the constructed attention model, and generating a question-answer pair data set according to the question-answer template library.

[0075] In summary, the present invention realizes high-precision entity and relationship extraction and effectively retains the context semantic information of the text by using a bidirectional semantic encoder and a multi-level named entity recognition model; realizes the deep semantic fusion of the basic knowledge structure and the preset knowledge graph through the semantic alignment mechanism of the hierarchical knowledge fusion network, improving the integrity of knowledge representation; constructs a hierarchical question-answering path based on a dynamic weight allocator to ensure the rationality of knowledge connection and the gradualness of knowledge transfer; realizes the intelligent generation of high-quality question-answer pairs through the cooperation of an attention model and a question-answer template library.

[0076] Embodiment 2

[0077] Referring to Table 1, this is the second embodiment of the present invention. This embodiment provides a method for generating questions and answers based on a knowledge graph. In order to verify the beneficial effects of the present invention, scientific demonstration is carried out through economic benefit calculation and simulation experiments.

[0078] Specifically, medical domain text corpus is selected as the test data set; a test data set is constructed using 5000 medical paper abstracts and 3000 clinical diagnosis and treatment records, and the publicly available medical knowledge graph CMeKG is selected as the preset knowledge graph. The experiment is conducted on a server configured with an Intel(R) Xeon(R) Gold 6248R CPU @ 3.00GHz, NVIDIA Tesla A100 graphics card, and 256GB of memory, with the operating system being Ubuntu20.04.

[0079] Furthermore, in the text processing stage, an improved BERT-BiLSTM bidirectional semantic encoder architecture is adopted. Both the forward layer and the backward layer of this encoder use a 3-layer BiLSTM structure, with the hidden layer dimension set to 768 and the number of attention heads to 12. To enhance the model's feature extraction ability, a multi-scale feature extraction module based on CNN is introduced, with convolutional kernels of three sizes, 3, 5, and 7 designed, and the number of feature channels uniformly configured to 256. Through a large number of experiments, it is verified that the optimal fusion weights of the forward encoding layer and the backward encoding layer are 0.6 and 0.4 respectively. In terms of sequence representation, a sinusoidal position encoding scheme matching the hidden layer dimension is adopted, effectively maintaining the sequence position information. The BiLSTM-CRF model optimized specifically for the medical domain is used in the entity recognition link, and this model achieves a 92.3% F1 score in the medical entity recognition task.

[0080] Even further, a hierarchical processing strategy is adopted in the knowledge fusion stage. The core of the knowledge fusion network is a 4-layer Graph Transformer structure, with 8 attention heads configured for each layer to capture multi-angle knowledge features. The entity alignment unit sets the similarity threshold to 0.85 to ensure the matching quality; the relationship mapping unit uses a 6-head attention mechanism for semantic mapping. When constructing the knowledge feature matrix, 20 key attribute features and 15 topological features of the entity are comprehensively considered, forming a multi-dimensional feature representation. In the construction process of the hierarchical question-answering path, the dynamic weight allocator uses a 3-layer GAT network structure, with the output dimension set to 512, achieving efficient feature aggregation. The weight calculation adopts a three-term weighting scheme, with the weight coefficients being λ1 = 0.4, λ2 = 0.3, and λ3 = 0.3. The entire knowledge network is divided into 5 levels, with each level containing an average of 200 nodes, forming a clear hierarchical structure.

[0081] Specifically, in the question-answering generation link, a symmetric Transformer architecture is adopted, with both the encoder and the decoder being 6-layer structures, configured with a 512-dimensional hidden layer and 8 attention heads. To ensure the quality and diversity of the generated question-answer pairs, a question-answer template library containing 2000 high-quality templates is pre-constructed. In the question-answer pair screening stage, the semantic similarity threshold is set to 0.8 to ensure the accuracy and practicality of the generated results.

[0082] Furthermore, as shown in Table 1, the method of the present invention significantly outperforms the traditional BERT-QA method in various performance indicators; in terms of the accuracy of question answering, the method of the present invention reaches 91.2%, showing an obvious improvement compared with 82.5% of the traditional BERT-QA method, reflecting the advantage of this method in the accuracy of question answering; the knowledge coverage rate is increased from 75.3% to 88.6%, indicating that this method can handle a wider range of question types. In terms of the semantic relevance index, the method of the present invention reaches 0.893, while the traditional method is 0.756, indicating that this method has better performance in understanding the semantics of questions and generating relevant answers. In terms of efficiency, the question generation speed is increased from 15.2 questions / second to 25.6 questions / second, and the processing efficiency is significantly improved.

[0083] Table 1 Comparison table between the present invention and the traditional method

[0084] Test metrics Traditional BERT-QA method Method of the present invention Question-answering accuracy rate (%) 82.5 91.2 Knowledge coverage rate (%) 75.3 88.6 Semantic relevance 0.756 0.893 Question generation speed (questions / second) 15.2 25.6 Depth of knowledge reasoning (layers) 2.3 4.2 Answer integrity score 0.723 0.876 Quality score of question-answer pairs 7.5 8.8

[0085] Even further, the method of the present invention reaches 4.2 layers in the depth of knowledge reasoning, far exceeding 2.3 layers of the traditional method, indicating that the system has stronger multi-level reasoning ability; the answer integrity score is increased from 0.723 to 0.876, indicating that the answers generated by this method are more complete and comprehensive; the quality score of the question-answer pair is increased from 7.5 to 8.8, comprehensively reflecting the overall improvement of this method in the quality of question answering.

[0086] It should be noted that the above embodiments are only used to illustrate the technical solutions of the present invention and not to limit them. Although the present invention has been described in detail with reference to the preferred embodiments, those of ordinary skill in the art should understand that the technical solutions of the present invention can be modified or equivalently replaced without departing from the spirit and scope of the technical solutions of the present invention, and they should all be covered within the scope of the claims of the present invention.

Claims

1. A question-answer generation method based on knowledge graph, characterized by: include, A bidirectional semantic encoder is used to process the input text corpus, extract entity words and relation words to form a first semantic vector, and the first semantic vector is converted into a basic knowledge structure through a triple decomposer; Using a hierarchical knowledge fusion network to align the basic knowledge structure with the deep semantic information in the preset knowledge graph to generate a multi-dimensional knowledge feature matrix; Based on the multi-dimensional knowledge feature matrix, a dynamic weight allocator is used to calculate the association strength between knowledge nodes, and a hierarchical question-answering path is constructed in descending order of association strength; Input the hierarchical question-answer path into the constructed attention model, and generate a question-answer pair dataset based on the question-answer template library; The attention model includes an encoder and a decoder; the encoder performs multi-level feature extraction on the input hierarchical question-answer path, and calculates the attention weight score of each knowledge node in the path through the self-attention mechanism to identify key knowledge nodes; the decoder matches the key knowledge nodes with the corresponding question-answer templates based on the question-answer templates pre-stored in the question-answer template library; the method for generating the question-answer pair dataset is as follows: Dynamically integrating the semantic information of the key knowledge nodes into the structure of the question-answer template through a cross-attention mechanism to generate a question-answer pair, wherein the question-answer pair includes a question text, an answer text, and corresponding knowledge path information; Based on the question-answer pairs, screening is performed using rule filtering and semantic similarity calculation; The screened question-answer pairs are organized according to the hierarchical relationship of knowledge nodes to form a structured question-answer pair dataset; The method for constructing the hierarchical question-answering path is: The dynamic weight allocator includes a feature aggregation unit and a weight calculation unit; the feature aggregation unit performs weighted summation on the attribute features of the nodes in the multidimensional knowledge feature matrix to generate a node representation vector; the weight calculation unit calculates the association strength of node pairs based on the node representation vector and screens the node pairs; Sort the node pairs that pass the screening by their association strength values from high to low, and divide the node pairs into different levels based on the sorting results; In each level, a directed connection path is constructed based on the semantic dependency and relationship topology features of the node pairs; The directed connection paths of each level are connected in series to form a hierarchical question-answering path, in which the high-level nodes serve as core knowledge points and the low-level nodes serve as extended knowledge points.

2. The question-answer generation method based on a knowledge graph according to claim 1, wherein: The specific formula of the association strength is as follows: ; in, is the association strength value between node i and node j, and are the characterization vectors of node i and node j respectively, and T is the characterization vector The transpose of is the feature transformation matrix, 、 and is the adjustment coefficient, is the feature dimension, is the weight coefficient of the k-th dimension feature, and are the eigenvalues of node i and node j in the kth dimension respectively.

3. The question-answer generation method based on a knowledge graph according to claim 2, characterized in that: Based on the multi-dimensional knowledge feature matrix, A dynamic weight allocator is used to calculate the association strength between knowledge nodes, and a hierarchical question-answering path is constructed in descending order of association strength, including: The hierarchical knowledge fusion network includes an entity alignment unit and a relationship mapping unit; The entity alignment unit calculates the semantic similarity between the entity in the basic knowledge structure and the entity in the preset knowledge graph to determine whether the entity pair meets the matching conditions; The relationship mapping unit uses a multi-head attention mechanism to perform semantic mapping on the relationship words of the basic knowledge structure and the relationships in the preset knowledge graph to extract the correspondence between the relationships; constructing an alignment matrix based on the entity alignment result of the entity alignment unit and the mapping result of the relationship mapping unit; Extracting entity attribute features related to the alignment matrix from a preset knowledge graph, and extracting relationship topology features between entities; The entity attribute features and the relationship topology features are combined to form a multidimensional knowledge feature matrix, wherein the rows of the multidimensional knowledge feature matrix represent different entity nodes, and the columns represent corresponding attribute dimensions and topology features.

4. The question-answer generation method based on a knowledge graph according to claim 3, wherein: The specific formula of the semantic similarity is as follows: ; in, The semantic similarity value between the entity in the basic knowledge structure and the entity in the preset knowledge graph, is the weight coefficient of semantic similarity, is the vectorized semantic representation of entities in the basic knowledge structure, is the vectorized semantic representation of the entity in the preset knowledge graph, n is the number of attributes of the entity, is the i-th attribute of the entity in the basic knowledge structure, is the i-th attribute of the entity in the preset knowledge graph, is the similarity score of the i-th attribute, is an entity in the basic knowledge structure, It is an entity in the preset knowledge graph; When the semantic similarity is greater than or equal to a first preset threshold, the entity pair is matched; When the semantic similarity is less than the first preset threshold, the entity pair is temporarily stored in the pending buffer area, the semantic representation of the entity is expanded, and the semantic similarity of the expanded entity is recalculated; if the semantic similarity of the expanded entity is less than the first preset threshold, the entity pair is marked as unmatched and the corresponding position in the alignment matrix is filled with zero value; if the semantic similarity of the expanded entity is greater than or equal to the first preset threshold, the entity pair is matched.

5. The question-answer generation method based on knowledge graph according to claim 4, characterized in that: A bidirectional semantic encoder is used to process the input text corpus, extract entity words and relation words, form a first semantic vector, and convert the first semantic vector into a basic knowledge structure through a triple decomposer, including: The bidirectional semantic encoder includes a forward encoding layer and a backward encoding layer; the forward encoding layer scans the word elements in the input text corpus from left to right; the backward encoding layer scans the word elements in the input text corpus from right to left; the conversion method of the basic knowledge structure is: Adaptively fusing the output results of the forward coding layer and the backward coding layer, determining the importance of the forward coding layer and the backward coding layer through a dynamic weight allocation mechanism, introducing a multi-scale convolution operation to extract local semantic features, and combining positional coding information to enhance the sequence feature representation of the input text corpus to generate a text semantic representation; The text semantic representation is processed using a preset named entity recognition model to identify and annotate the type and boundary information of entity words; Utilizing a dependency parser to parse the text semantic representation into a syntactic structure and extract relational words between entity words; The identified entity words, the type and boundary information of the entity words, the relation words, and the semantic features corresponding to the relation words are serially combined in the vector space by a feature splicer to form a first semantic vector; Processing the first semantic vector through a triple decomposer, and dividing the semantic vector into a plurality of sub-vector segments using a sliding window mechanism; Semantic analysis and knowledge element extraction are performed on the sub-vector segments to construct a basic knowledge structure.

6. A knowledge graph-based question and answer generation method system, based on the knowledge graph-based question and answer generation method according to any one of claims 1 to 5, characterized in that: include, An extraction and conversion module is used to process the input text corpus using a bidirectional semantic encoder, extract entity words and relation words to form a first semantic vector, and convert the first semantic vector into a basic knowledge structure through a triple decomposer; A generation module is used to align the basic knowledge structure with the deep semantic information in the preset knowledge graph using a hierarchical knowledge fusion network to generate a multidimensional knowledge feature matrix; A construction module, based on the multi-dimensional knowledge feature matrix, uses a dynamic weight allocator to calculate the association strength between knowledge nodes, and constructs a hierarchical question-answering path in descending order of association strength; A generation module is used to input the hierarchical question-answer path into the constructed attention model and generate a question-answer pair dataset based on the question-answer template library.

7. A computer device comprising a memory and a processor, wherein the memory stores a computer program, wherein: When the processor executes the computer program, the steps of the question and answer generation method based on the knowledge graph are implemented in any one of claims 1 to 5.

8. A computer-readable storage medium having a computer program stored thereon, characterized in that: When the computer program is executed by a processor, the steps of the question and answer generation method based on the knowledge graph are implemented in any one of claims 1 to 5.

Citation Information

Patent Citations

  • Food safety question-answer reasoning method and system and electronic equipment

    CN113849613A

  • Knowledge reasoning method based on heterogeneous knowledge fusion

    CN117235216A