Adaptive text generation method and system based on knowledge graph

By combining the search tree and user query vectors, the knowledge graph query path is optimized, solving the problems of low efficiency and accuracy in existing technologies, and realizing efficient and accurate knowledge graph query and information display.

CN117932088BActive Publication Date: 2026-07-21HEFEI UNIV OF TECH
View PDF 2 Cites 0 Cited by

Patent Information

Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
HEFEI UNIV OF TECH
Filing Date
2024-01-26
Publication Date
2026-07-21

AI Technical Summary

Technical Problem

Existing technologies have low efficiency and accuracy when using knowledge graphs for complex queries. Traditional search algorithms cannot meet the needs of efficient querying of graph structure data, especially when the query speed drops significantly under large-scale data.

Method used

We construct an adaptive text generation method based on knowledge graphs. By obtaining the search tree and user query vector, we gradually query to the leaf node, generate query answers using a structured data text generation model, and optimize the query path and result generation by combining graph attention network and deep learning techniques.

Benefits of technology

It improves the efficiency and accuracy of knowledge graph queries, enabling quick location of the most relevant information to the user's query, generating easy-to-understand natural language text descriptions, and meeting the needs of complex queries.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN117932088B_ABST
    Figure CN117932088B_ABST
Patent Text Reader

Abstract

The application relates to a knowledge graph-based adaptive text generation method and system, which comprises the following steps: acquiring a knowledge graph to be queried and a pre-constructed search tree; extracting a user query vector representing semantic features and structural features of the knowledge graph to be queried from the knowledge graph; starting from a root node of the search tree, gradually querying from the root node to a leaf node based on the distance between the tree query vector and the user query vector, and saving a query path from the root node to the leaf node; selecting a suitable target tree node from the query path, acquiring a corresponding subgraph in the total knowledge graph based on the target tree node, inputting the corresponding subgraph into a structured data text generation model, generating a text description corresponding to the target tree node as a query answer of the knowledge graph to be queried. The application solves the problem of low efficiency and accuracy in complex queries using a knowledge graph in the prior art.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] This invention relates to the field of knowledge graphs, and in particular to an adaptive text generation method and system based on knowledge graphs. Background Technology

[0002] Knowledge graphs are widely used in various fields to store and represent complex information relationships. However, compared with traditional tree-structured data structures, the search efficiency of graph-structured data faces significant challenges. Traditional search algorithms are relatively inefficient when processing graph-structured data, especially when the data volume is large, the query speed drops significantly, which restricts the development of knowledge graphs in practical applications.

[0003] Furthermore, information in knowledge graphs often requires complex queries, including subgraph searches—that is, finding subgraph structures containing specific entities and relationships. However, traditional search algorithms cannot meet this need, leading to inefficiency and limited applications. Therefore, there is a need to provide an adaptive text generation method and system based on knowledge graphs. Summary of the Invention

[0004] This invention provides an adaptive text generation method based on knowledge graphs. This addresses the problems of low efficiency and accuracy in existing technologies when using knowledge graphs for complex queries.

[0005] This invention provides an adaptive text generation method based on a knowledge graph, comprising: acquiring a knowledge graph to be queried and a pre-constructed search tree; wherein the search tree is composed of a pre-acquired total knowledge graph, the search tree contains multiple tree nodes, each tree node corresponds to a tree query vector, and the tree node includes at least a root node and a leaf node; extracting a user query vector representing its semantic and structural features from the knowledge graph to be queried; starting from the root node of the search tree, querying from the root node to the leaf node step by step based on the distance between the tree query vector and the user query vector, and saving the query path from the root node to the leaf node; selecting a suitable target tree node from the query path, acquiring the corresponding subgraph in the total knowledge graph based on the target tree node, inputting the corresponding subgraph into a structured data text generation model, and generating a text description corresponding to the target tree node as the query answer for the knowledge graph to be queried.

[0006] In one embodiment of the present invention, the process of constructing the search tree includes: calculating the relevance score of each node in the total knowledge graph to the topic represented by the total knowledge graph; dividing each node in the total knowledge graph into multiple central nodes and multiple edge nodes based on the relevance score to the topic; generating multiple tree node clusters based on the positional relationship between each central node and each edge node in the total knowledge graph, and obtaining the tree query vector of each tree node cluster based on a graph attention network; and gradually merging multiple tree node clusters into parent nodes and hierarchical structures, using each tree node cluster as a leaf node, to finally generate the search tree.

[0007] In one embodiment of the present invention, the step of generating multiple tree node clusters based on the positional relationship between each central node and each edge node in the total knowledge graph, and obtaining a tree query vector for each tree node cluster based on a graph attention network, includes: taking each central node and the edge nodes within a preset step as a tree node cluster; inputting each tree node cluster into a graph attention network, extracting the semantic features and structural features of each tree node cluster, and generating a tree query vector for the tree node cluster based on the semantic features and structural features.

[0008] In one embodiment of the present invention, the step of using each tree node cluster as a leaf node, gradually merging multiple tree node clusters to form a parent node and a hierarchical structure, and finally generating a search tree includes:

[0009] In one embodiment of the present invention, S41, according to a preset addition strategy, adjust the preset step size, regenerate multiple tree node clusters, and obtain the tree query vector of each tree node cluster; S42, determine whether each tree node cluster contains the same node; S43, if yes, merge the tree node clusters containing the same node into one tree node cluster, and use the merged tree node cluster as the parent node of each tree node cluster before merging; S44, if no, repeat steps S41 to S42 until all nodes in the total knowledge graph have corresponding tree node clusters, and construct the search tree based on the hierarchical structure of each tree node cluster.

[0010] In one embodiment of the present invention, the step of querying from the root node of the search tree to the leaf node step by step based on the distance between the tree query vector and the user query vector, and saving the query path from the root node to the leaf node, includes: S31, taking the root node of the search tree as the current node; S32, calculating the distance between each non-leaf node and / or leaf node corresponding to the current node and the user query vector; wherein, non-leaf nodes and leaf nodes are tree nodes; S33, selecting the tree node with the shortest distance and determining whether the tree node is a leaf node; S34, if not, taking the tree node with the shortest distance as the current node and executing steps S32 and S33 again; S35, if yes, saving the query path from the root node to the leaf node.

[0011] In one embodiment of the present invention, the step of selecting a suitable target tree node from the query path, obtaining the corresponding subgraph in the total knowledge graph based on the target tree node, and inputting the corresponding subgraph into a structured data text generation model to generate a text description corresponding to the target tree node as the query answer for the knowledge graph to be queried includes: selecting a target tree node from each tree node of the query path according to its distance from the user query vector, and obtaining the subgraph corresponding to the target tree node; converting the subgraph corresponding to the target tree node into an input sequence; and inputting the input sequence into the structured data text generation model to generate a text description corresponding to the target tree node as the query answer for the knowledge graph to be queried.

[0012] In one embodiment of the present invention, converting the subgraph corresponding to the target tree node into an input sequence includes: extracting triple information of the subgraph from the subgraph; wherein the triple information represents the relationship between the nodes in the subgraph; converting the triple information into a node sequence, and adding identifiers representing the type of each node to the node sequence to form an input sequence.

[0013] In one embodiment of the present invention, the step of inputting the input sequence into the structured data text generation model to generate a text description corresponding to the target tree node as the query answer of the knowledge graph to be queried includes: inputting the input sequence into the structured text generation model to generate a text description corresponding to the target tree node; determining whether the length of the text description meets a preset target length; if yes, then using the text description as the query answer of the knowledge graph to be queried; if no, then reselecting a target tree node from each tree node of the query path to generate a text description until the length of the text description meets the preset target length.

[0014] In another aspect of the present invention, an adaptive text generation system based on a knowledge graph is also provided. The system includes: a data acquisition module for acquiring a knowledge graph to be queried and a pre-constructed search tree; wherein the search tree is composed of a pre-acquired total knowledge graph, the search tree contains multiple tree nodes, each tree node corresponds to a tree query vector, and the tree node includes at least a root node and leaf nodes; a user query vector acquisition module for extracting user query vectors representing the semantic and structural features of the knowledge graph to be queried; a query path acquisition module for querying from the root node of the search tree, based on the distance between the tree query vector and the user query vector, from the root node to the leaf node, and storing the query path from the root node to the leaf node; and a text generation module for selecting a suitable target tree node from the query path, acquiring the corresponding subgraph in the total knowledge graph based on the target tree node, inputting the corresponding subgraph into a structured data text generation model, and generating a text description corresponding to the target tree node as the query answer for the knowledge graph to be queried.

[0015] This invention proposes an adaptive text generation method and system based on knowledge graphs. By using search trees and query vectors, the most relevant parts of the knowledge graph to the user's query can be quickly located, improving query efficiency. Analyzing the positional relationships of nodes in the knowledge graph to be queried generates a user query vector, which helps in understanding and parsing the knowledge graph structure and more comprehensively represents the user's query intent. The distance between the user query vector and the tree query vector is used to select the query path, accurately matching the content of the user's query with relevant information in the knowledge graph, making the final generated text more closely aligned with the user's needs. By combining efficient information retrieval, accurate query matching, and easy-to-understand information presentation, the ability to extract and convey information from complex knowledge graphs is greatly improved, solving the problem of low efficiency and accuracy in existing technologies when using knowledge graphs for complex queries. Attached Figure Description

[0016] Figure 1 A flowchart illustrating an adaptive text generation method based on knowledge graphs provided in an embodiment of the present invention;

[0017] Figure 2 The diagram shows a flowchart of constructing a search tree in one embodiment of the present invention.

[0018] Figure 3 The diagram shows a flowchart of obtaining a tree node cluster in one embodiment of the present invention.

[0019] Figure 4 This is a schematic diagram of a process for obtaining corresponding text descriptions based on user needs in one embodiment of the present invention;

[0020] Figure 5 The diagram shown is a structural block diagram of an adaptive text generation system based on knowledge graphs provided in an embodiment of the present invention. Detailed Implementation

[0021] The following specific examples illustrate the implementation of the present invention. Those skilled in the art can easily understand other advantages and effects of the present invention from the content disclosed in this specification. The present invention can also be implemented or applied through other different specific embodiments, and various details in this specification can also be modified or changed based on different viewpoints and applications without departing from the spirit of the present invention. It should be noted that, unless otherwise specified, the following embodiments and features described therein can be combined with each other.

[0022] It should be noted that the illustrations provided in the following embodiments are only schematic representations of the basic concept of the present invention. Therefore, the drawings only show the components related to the present invention and are not drawn according to the actual number, shape and size of the components in the actual implementation. In the actual implementation, the form, quantity and proportion of each component can be arbitrarily changed, and the layout of the components may also be more complex.

[0023] In the following description, numerous details are explored to provide a more thorough explanation of embodiments of the invention. However, it will be apparent to those skilled in the art that embodiments of the invention may be practiced without these specific details. In other embodiments, well-known structures and devices are shown in block diagram form rather than in detail to avoid obscuring embodiments of the invention.

[0024] This invention provides an adaptive text generation method based on knowledge graphs. The user-input query is queried in a pre-generated search tree to obtain a series of related nodes, which serve as the query path. A suitable target tree node is selected from the query path, and the subgraph corresponding to that target tree node is queried from the pre-acquired overall knowledge graph. Based on the subgraph corresponding to the target tree node obtained from the query, a structured data text generation model is used to generate a text description of a specified length for the query result. This invention better utilizes knowledge graphs, promoting innovative applications in domain knowledge discovery, intelligent search, data mining, and other fields, achieving more efficient information management and retrieval. It fully leverages the potential of knowledge graphs and meets the needs of practical applications, improving the search and retrieval algorithms for graph-structured data. The improved algorithm can efficiently process large-scale graph-structured data while supporting complex query operations, including subgraph search.

[0025] Please see Figure 1 The knowledge graph-based adaptive text generation method includes the following steps:

[0026] S1. Obtain the knowledge graph to be queried and the pre-constructed search tree; wherein, the search tree is composed of the pre-obtained total knowledge graph, the search tree contains multiple tree nodes, each tree node corresponds to a tree query vector, and the tree node includes at least a root node and a leaf node;

[0027] S2. Extract user query vectors representing the semantic and structural features of the knowledge graph to be queried;

[0028] S3. Starting from the root node of the search tree, query from the root node to the leaf node step by step based on the distance between the tree query vector and the user query vector, and save the query path from the root node to the leaf node;

[0029] S4. Select a suitable target tree node from the query path, obtain the corresponding subgraph in the total knowledge graph based on the target tree node, input the corresponding subgraph into the structured data text generation model, and generate the text description corresponding to the target tree node as the query answer of the knowledge graph to be queried.

[0030] The following details the specific process for each step:

[0031] S1. Obtain the knowledge graph to be queried and the pre-constructed search tree; wherein, the search tree is composed of the pre-obtained total knowledge graph, the search tree contains multiple tree nodes, each tree node corresponds to a tree query vector, and the tree node includes at least a root node and a leaf node.

[0032] Please see Figure 1 , Figure 3 and Figure 4 The knowledge graph to be queried refers to the data used for querying, which contains relevant information about a specific topic or domain. It is understood that, in this application, the knowledge graph to be queried can be based on a user-input query text sequence X = {x1, x2, ... x...} nThis process generates a corresponding knowledge graph to be queried. Alternatively, the knowledge graph representing the user's query intent can be used as the knowledge graph to be queried; the specific method is not limited here. For example, the query statement is: "To which cuisine does Mapo Tofu belong? What other dishes in this cuisine have similar flavors?" Through natural language processing, the corresponding knowledge graph can be obtained. Using the method described in this application, the final text description corresponding to the user's request can be obtained as follows: Sichuan cuisine is famous for its unique flavor, including classic dishes such as Mapo Tofu, Kung Pao Chicken, Twice-Cooked Pork, and Sliced ​​Beef and Offal in Chili Sauce. Among them, Mapo Tofu, Kung Pao Chicken, Twice-Cooked Pork, and Sliced ​​Beef and Offal in Chili Sauce are all characterized by their spicy and numbing flavor, bringing people a rich taste and aroma. In this application, the overall knowledge graph provides a high-level knowledge framework, while the knowledge graph to be queried is a more specific and focused knowledge representation within this framework. For example, in a large medical knowledge graph, the overall knowledge graph may include information on all diseases, symptoms, treatments, and drugs. When a user queries a treatment for a specific disease, a knowledge graph to be queried is formed; this sub-graph focuses on the user's specific query content.

[0033] In one embodiment of the present invention, the process of constructing the search tree includes:

[0034] Calculate the relevance score between each node in the total knowledge graph and the topic represented by the total knowledge graph;

[0035] Based on the relevance score to the topic, each node in the total knowledge graph is divided into multiple central nodes and multiple edge nodes;

[0036] Based on the positional relationship between each central node and each edge node in the total knowledge graph, multiple tree node clusters are generated, and a tree query vector for each tree node cluster is obtained based on a graph attention network.

[0037] Using each tree node cluster as a leaf node, multiple tree node clusters are gradually merged to form parent nodes and hierarchical structures, ultimately generating a search tree.

[0038] Please see Figures 1 to 3 The search tree is constructed based on the selected total knowledge graph, G = {V, E}, where V represents a node in the graph. Nodes are basic elements in the knowledge graph and can represent various entities, such as people, places, and concepts. Edges representing connecting nodes indicate relationships between them, such as "belongs to" or "located in". R represents the relationship type between nodes, describing the specific relationship. The relevance of each node to the topic in the overall knowledge graph is evaluated using methods such as text similarity and graph structure analysis. Based on the relevance score, all nodes in the overall knowledge graph are divided into multiple central nodes Vc and multiple edge nodes Ve. Central nodes Vc are highly relevant to the topic, while edge nodes Ve have lower relevance. Multiple tree node clusters are formed using the positional relationships of central and edge nodes in the overall knowledge graph. Each tree node cluster can include a central node and its associated edge nodes, or multiple central nodes and their associated edge nodes. For each tree node cluster, a graph attention network is used to effectively capture the structural and semantic relationships between nodes within the cluster, generating a tree query vector for that cluster. Using tree node clusters as leaf nodes, parent nodes and hierarchical structures are formed by continuously merging tree node clusters, gradually ascending until a complete search tree is formed.

[0039] In one embodiment of the present invention, the step of generating multiple tree node clusters based on the positional relationships of each central node and each edge node in the total knowledge graph, and obtaining the tree query vector for each tree node cluster based on a graph attention network, includes:

[0040] Each central node and the edge nodes within a preset step distance are treated as a tree node cluster;

[0041] Each tree node cluster is input into a graph attention network to extract semantic and structural features of each tree node cluster, and a tree query vector for the tree node cluster is generated based on the semantic and structural features.

[0042] Please see Figures 1 to 3 After dividing the nodes in the overall knowledge graph into central nodes and edge nodes, for each central node: taking the central node Vc as the center, gather the nodes within its n-hop neighborhood to form a tree node cluster. Here, the nodes within the n-hop neighborhood, as described in this invention, are nodes connected to the central node Vc by no more than n edges. After all central nodes Vc have been processed in the above manner, several tree node clusters S = {S1, S2, ... S} are obtained. m For each tree node cluster S i Randomly number each node and extract the structural features h of each node based on a graph attention network. frame and semantic features h semantic Semantic features may include node content and attributes, while structural features involve the connections and relationship patterns between nodes. The structural features h of each node in the tree node cluster Si are then analyzed. frame and semantic features hsemantic Feature fusion is performed, and the resulting embedding vector is used as the tree node cluster S. i tree query vector h search ={h frame h semantic This query vector captures the core characteristics of the tree node cluster for subsequent query matching and navigation. As the smallest unit of the search tree, the tree node cluster stores the graph structure information of the node cluster to which the node belongs, as well as the tree query vector. The graph structure information includes structural features, semantic features, and the corresponding subgraph of the overall knowledge graph.

[0043] In one embodiment of the present invention, the step of using each tree node cluster as a leaf node, gradually merging multiple tree node clusters to form a parent node and a hierarchical structure, and finally generating a search tree, includes:

[0044] S41. According to the preset addition strategy, adjust the preset distance, regenerate multiple tree node clusters, and obtain the tree query vector of each tree node cluster;

[0045] S42. Determine whether each tree node cluster contains the same node;

[0046] S43. If so, merge the tree node clusters containing the same nodes into one tree node cluster, and use the merged tree node cluster as the parent node of each tree node cluster before the merger.

[0047] S44. If not, repeat steps S41 to S42 until all nodes in the total knowledge graph have corresponding tree node clusters, and construct the search tree based on the hierarchical structure of each tree node cluster.

[0048] To progressively construct and optimize the search tree for more efficient management and querying of the large total knowledge graph, this invention, after the initial generation of a node cluster, continues to expand the neighborhood range n (i.e., expand the n-hop neighborhood) so that each central node Vc can gather nodes from farther away, thereby enabling the newly generated tree node clusters to capture a wider range of information and relationships. As the neighborhood range increases, different tree node clusters may begin to overlap, meaning the same node may appear in multiple tree node clusters simultaneously. When this overlap occurs, these overlapping tree node clusters are merged into a larger tree node cluster, which then becomes the parent node of the original tree node cluster. For each expanded tree node cluster, its tree query vector is recalculated using a graph attention network to reflect its updated structural and semantic features. By repeatedly increasing the neighborhood range and merging tree node clusters, all nodes in the pre-selected total knowledge graph are gradually incorporated into the search tree. After multiple iterations, a complete search tree T = {S1, S2, ... S} is formed. n}, where each node cluster S i In a search tree, the node cluster S represents a single node or a group of nodes. i The search tree includes one or more central nodes and corresponding edge nodes. After the search tree is constructed, the root node at the top of the search tree is a cluster of tree nodes containing the broadest range of node information, while the leaf nodes at the bottom of the search tree correspond to the initially formed, more specific clusters of tree nodes. It should be noted that the entire construction process of the search tree is dynamic; as the neighborhood range n increases, the clusters of tree nodes continuously merge and expand, allowing the search tree to flexibly adapt to query requirements of different depths and ranges. After the search tree is constructed, structural and semantic searches of the knowledge graph are transformed into comparing the distances between embedding vectors on the tree structure, which can significantly improve the query speed for such complex queries.

[0049] S2. Extract user query vectors representing the semantic and structural features from the knowledge graph to be queried.

[0050] For the query text sequence X = {x1, x2, ..., x...} that the user needs to query... n}, this query text sequence represents the user's query request, where x n This represents a word or phrase in the query statement. It generates the corresponding knowledge graph G to be queried. x In Gx, the structure and node design reflect the needs and content of the query text, and most nodes in Gx are initially empty, to be filled and refined later. A similar approach to constructing the search tree described above is used to process the knowledge graph G to be queried. x Generate G x The node clusters are analyzed. Semantic and structural features corresponding to the node clusters are extracted using a graph attention network to generate the user query vector for that node cluster. The user query vector is derived from the structural features h of the query. q frame and semantic features h q semantic This user query vector is used in the subsequent query matching process, compared with data in the pre-acquired overall knowledge graph to find the most relevant information. In this way, user query needs can be processed and understood more effectively, and accurate search results can be provided.

[0051] S3. Starting from the root node of the search tree, query from the root node to the leaf node step by step based on the distance between the tree query vector and the user query vector, and save the query path from the root node to the leaf node.

[0052] Starting from the root node of the constructed search tree, obtain the tree query vectors of each node under the root node, and calculate the distance between the tree query vector of each child node and the user query vector. Select the node with the closest distance, and perform the same query operation on the child nodes of that node until the leaf node is obtained. Save the query path P = {V} from the root node to the leaf node. root V n1 V n2 ....V tgt ....V nn} is used as a candidate intermediate result. Where, V root V is the root node. tgt V is the child node that is closest to the user's query vector. nn For V tgt The corresponding leaf node.

[0053] In one embodiment of the present invention, the step of starting from the root node of the search tree, querying stepwise from the root node to the leaf node based on the distance between the tree query vector and the user query vector, and saving the query path from the root node to the leaf node includes:

[0054] S31. Take the root node of the search tree as the current node;

[0055] S32. Calculate the distance between each non-leaf node and / or leaf node corresponding to the current node and the user query vector; wherein, the non-leaf nodes and leaf nodes are tree nodes;

[0056] S33. Select the tree node with the shortest distance and determine whether the tree node is a leaf node;

[0057] S34. If not, then take the tree node with the shortest distance as the current node and execute steps S32 and S33 again.

[0058] S35. If so, save the query path from the root node to the leaf node.

[0059] The root node of the search tree is set as the current node. For each child node of the current node (whether it is a non-leaf node or a leaf node, it is a tree node in the search tree): calculate the distance between the tree query vector corresponding to the tree node and the user query vector. Select the tree node with the shortest distance from all tree nodes of the current node, and determine whether the tree node with the shortest distance is a leaf node. If not, set the tree node with the shortest distance as the new current node, and repeat steps S32 and S33 to continue searching downwards in the search tree. If yes, save the entire query path from the root node to the leaf node. This process can effectively locate the information in the knowledge graph that is closest to the user query vector, ensuring the relevance and accuracy of the query. Moreover, this iterative approach can quickly narrow down the search scope, greatly improving query efficiency. It should be noted that the nodes in the search tree not only contain the nodes in the total knowledge graph, but also store the structural and semantic embedding vectors of these nodes to accelerate the search speed. Different comparison models can be used to search for various types of information. For example, by calculating the distance between embedding vectors, it is possible to search for similar nodes or subgraphs. More complex comparison mechanisms can also be used, such as pre-trained models to determine relevance, which can enable the input of natural language queries to find nodes or subgraphs that meet the requirements.

[0060] S4. Select a suitable target tree node from the query path, obtain the corresponding subgraph in the total knowledge graph based on the target tree node, input the corresponding subgraph into the structured data text generation model, and generate the text description corresponding to the target tree node as the query answer of the knowledge graph to be queried.

[0061] Identify the final target tree node V from the saved query path. tgt The target tree node V tgt The node closest to the user's query vector represents the most relevant part of the knowledge graph to the user's query. Based on the target tree node, the corresponding subgraph in the overall knowledge graph is obtained. This extracted subgraph is then input into a structured data text generation model to generate a text description corresponding to the subgraph's content. This description serves as the query answer for the knowledge graph, providing easily understandable knowledge graph content. By converting complex graph structure data into easily understandable natural language text, the readability and acceptability of the information are improved.

[0062] In one embodiment of the present invention, the step of selecting a suitable target tree node from the query path, obtaining the corresponding subgraph in the total knowledge graph based on the target tree node, inputting the corresponding subgraph into a structured data text generation model, and generating a text description corresponding to the target tree node as the query answer for the knowledge graph to be queried includes:

[0063] From each tree node of the query path, select the target tree node based on its distance from the user query vector, and obtain the subgraph corresponding to the target tree node;

[0064] Convert the subgraph corresponding to the target tree node into an input sequence;

[0065] The input sequence is fed into the structured data text generation model to generate the text description corresponding to the target tree node, which serves as the query answer for the knowledge graph to be queried.

[0066] In each tree node of the query path, a depth-first search is used to find the search tree node with the closest vector distance. This tree node is set as the target tree node, and the subgraph corresponding to the selected target tree node is obtained. The structure of the subgraph is then transformed into an input sequence suitable for input into a structured data text generation model. The structured data text generation model interprets the graph structure data and generates a text description of the selected subgraph's content as a response to the user query.

[0067] In one embodiment of the present invention, converting the subgraph corresponding to the target tree node into an input sequence includes:

[0068] From the subgraph, extract the triple information of the subgraph; wherein the triple information represents the relationship between the nodes in the subgraph;

[0069] The triplet information is converted into a node sequence, and identifiers representing the type of each node are added to the node sequence to form an input sequence.

[0070] The triplet data of the subgraph (e.g., {s0, p0, o0}, {s1, p1, o1}, ... {s r ,p r The subgraph is transformed into a sequence of nodes, where each triple consists of a subject, a predicate, and an object, representing the relationships between nodes in the subgraph. A special token is inserted for each node type (e.g., subject, predicate, object); for example, a token can be used for the subject. <subj>Predicate usage <rel>object use <obj>As markers, the final input sequence { <subj> s i1 , <rel> p i1 , <obj> o i2 ,... <rel> p im , <obj>o im The input sequence is fed into the model to generate the corresponding text sequence {y0, y1, ... y}. t }

[0071] In one embodiment of the present invention, the step of inputting the input sequence into the structured data text generation model to generate a text description corresponding to the target tree node, as the query answer for the knowledge graph to be queried, includes:

[0072] The input sequence is fed into the structured text generation model to generate text descriptions corresponding to the target tree nodes;

[0073] Determine whether the length of the text description meets the preset target length;

[0074] If so, the text description will be used as the query answer for the knowledge graph to be queried;

[0075] If not, then select a new target tree node from each tree node of the query path to generate a text description until the length of the text description meets the preset target length.

[0076] The process involves determining whether the length of the text description generated by the structured text generation model meets the preset target length. The target length can be a fixed number of characters or words, or it can be set differently based on user needs. The specific setting depends on the application's requirements and is not limited here. If the generated text description meets the preset target length, it means the text sufficiently represents the user's query and can be used as the query answer for the knowledge graph. Conversely, if the text description length does not meet the preset target length, a new target tree node needs to be selected. By changing the position of the target tree node, the length can be adjusted by including more or less information in the text. After selecting a new target tree node, the corresponding subgraph is converted into an input sequence. The modified input sequence is then re-input into the structured text generation model to generate a new text description. This process is repeated until the length of the newly generated text description meets the preset target length. It can be understood that the target tree node V... tgt Previous candidate intermediate results have more knowledge graph nodes, enabling them to generate richer query results; conversely, those in V... tgt With fewer candidate intermediate result nodes, the generated query results are more concise. By adjusting the text length, it is possible to ensure that the information is both complete and accurate, meeting different application needs.

[0077] Please see Figure 5 The knowledge graph-based adaptive text generation system 100 includes: a data acquisition module 110, a user query vector acquisition module 120, a query path acquisition module 130, and a text generation module 140. The data acquisition module 110 acquires the knowledge graph to be queried and a pre-constructed search tree. The search tree is composed of the pre-acquired total knowledge graph and contains multiple tree nodes, each corresponding to a tree query vector. Each tree node includes at least a root node and leaf nodes. The user query vector acquisition module 120 extracts user query vectors representing the semantic and structural features of the knowledge graph to be queried. The query path acquisition module 130 starts from the root node of the search tree and queries from the root node to the leaf node based on the distance between the tree query vector and the user query vector, saving the query path from the root node to the leaf node. The text generation module 140 is used to select a suitable target tree node from the query path, obtain the corresponding subgraph in the total knowledge graph based on the target tree node, input the corresponding subgraph into the structured data text generation model, and generate the text description corresponding to the target tree node as the query answer of the knowledge graph to be queried.

[0078] Specific limitations regarding the knowledge graph-based adaptive text generation system can be found in the limitations of the knowledge graph-based adaptive text generation method described above, and will not be repeated here. Each module in the aforementioned knowledge graph-based adaptive text generation system can be implemented entirely or partially through software, hardware, or a combination thereof. These modules can be embedded in or independent of the processor in a computer device in hardware format, or stored in the memory of a computer device in software format, so that the processor can call the corresponding operations of each module.

[0079] It should be noted that, in order to highlight the innovative aspects of this invention, this embodiment does not include modules that are not closely related to solving the technical problems proposed by this invention, but this does not mean that there are no other modules in this embodiment.

[0080] In summary, this invention discloses an adaptive text generation method and system based on a knowledge graph. It uses a search tree constructed from a total knowledge graph as its foundation. Based on the search query, it searches the search tree for relevant nodes that meet the requirements. These nodes are then organized into subgraphs based on their relationships within the original knowledge graph. A deep learning model transforms the content of the subgraphs into descriptive text output. The length of the output text can be controlled by adjusting the size of the subgraphs. The method is divided into a preparation phase and an implementation phase. In the preparation phase, a search tree is constructed based on the total knowledge graph, and the information in the search tree is encoded. In the implementation phase, the system accepts the user's query, searches the constructed search tree for nodes that meet the requirements, and stores the query path. Natural language descriptions are generated based on the retrieved nodes. The length of the generated text is evaluated, the node size is adjusted, and the process is repeated until a text sequence that meets the requirements is generated. This invention, based on a search tree, can significantly improve the speed of querying the knowledge graph, and the query results are displayed in the form of a natural language text sequence, which is easy for users to understand. Therefore, this invention effectively overcomes the various shortcomings of existing technologies and has high industrial application value.

[0081] The above embodiments are merely illustrative of the principles and effects of the present invention and are not intended to limit the invention. Any person skilled in the art can modify or alter the above embodiments without departing from the spirit and scope of the present invention. Therefore, all equivalent modifications or alterations made by those skilled in the art without departing from the spirit and technical concept disclosed in the present invention should still be covered by the claims of the present invention.< / obj> < / rel> < / obj> < / rel> < / subj> < / obj> < / rel> < / subj>

Claims

1. An adaptive text generation method based on knowledge graphs, characterized in that, The method includes: Obtain the knowledge graph to be queried and the pre-constructed search tree; wherein, the search tree is composed of the pre-obtained total knowledge graph, the search tree contains multiple tree nodes, each tree node corresponds to a tree query vector, and the tree node includes at least a root node and a leaf node; Extract user query vectors representing the semantic and structural features of the knowledge graph to be queried; Starting from the root node of the search tree, the query is performed step by step from the root node to the leaf node based on the distance between the tree query vector and the user query vector, and the query path from the root node to the leaf node is saved. Select a suitable target tree node from the query path, obtain the corresponding subgraph in the total knowledge graph based on the target tree node, input the corresponding subgraph into the structured data text generation model, generate the text description corresponding to the target tree node, and use it as the query answer for the knowledge graph to be queried; The process of constructing the search tree includes: Calculate the relevance score between each node in the total knowledge graph and the topic represented by the total knowledge graph; Based on the relevance score to the topic, each node in the total knowledge graph is divided into multiple central nodes and multiple edge nodes; Based on the positional relationship between each central node and each edge node in the total knowledge graph, multiple tree node clusters are generated, and a tree query vector for each tree node cluster is obtained based on a graph attention network. Using each tree node cluster as a leaf node, multiple tree node clusters are gradually merged to form parent nodes and hierarchical structures, ultimately generating a search tree; Based on the positional relationships of each central node and each edge node in the overall knowledge graph, multiple tree node clusters are generated, and based on a graph attention network, a tree query vector for each tree node cluster is obtained, including: Each central node and the edge nodes within a preset step distance are treated as a tree node cluster; Each tree node cluster is input into a graph attention network to extract the semantic and structural features of each tree node cluster, and a tree query vector for the tree node cluster is generated based on the semantic and structural features. The process of using each tree node cluster as a leaf node, gradually merging multiple tree node clusters to form parent nodes and hierarchical structures, and finally generating a search tree includes: S41. According to the preset addition strategy, adjust the preset step size, regenerate multiple tree node clusters, and obtain the tree query vector of each tree node cluster. S42. Determine whether each tree node cluster contains the same node; S43. If so, merge the tree node clusters containing the same nodes into one tree node cluster, and use the merged tree node cluster as the parent node of each tree node cluster before the merger. S44. If not, repeat steps S41 to S42 until all nodes in the total knowledge graph have corresponding tree node clusters, and construct the search tree based on the hierarchical structure of each tree node cluster.

2. The adaptive text generation method based on knowledge graphs according to claim 1, characterized in that, The process of starting from the root node of the search tree and progressively querying from the root node to the leaf node based on the distance between the tree query vector and the user query vector, and saving the query path from the root node to the leaf node, includes: S31. Take the root node of the search tree as the current node; S32. Calculate the distance between each non-leaf node and / or leaf node corresponding to the current node and the user query vector; wherein, the non-leaf nodes and leaf nodes are tree nodes; S33. Select the tree node with the shortest distance and determine whether the tree node is a leaf node; S34. If not, then take the tree node with the shortest distance as the current node and execute steps S32 and S33 again. S35. If so, save the query path from the root node to the leaf node.

3. The adaptive text generation method based on knowledge graphs according to claim 1, characterized in that, The steps include selecting a suitable target tree node from the query path, obtaining the corresponding subgraph in the overall knowledge graph based on the target tree node, inputting the corresponding subgraph into a structured data text generation model, and generating a text description corresponding to the target tree node as the query answer for the knowledge graph to be queried, including: From each tree node of the query path, select the target tree node based on its distance from the user query vector, and obtain the subgraph corresponding to the target tree node; Convert the subgraph corresponding to the target tree node into an input sequence; The input sequence is fed into the structured data text generation model to generate the text description corresponding to the target tree node, which serves as the query answer for the knowledge graph to be queried.

4. The adaptive text generation method based on knowledge graphs according to claim 3, characterized in that, The step of converting the subgraph corresponding to the target tree node into an input sequence includes: From the subgraph, extract the triple information of the subgraph; wherein the triple information represents the relationship between the nodes in the subgraph; The triplet information is converted into a node sequence, and identifiers representing the type of each node are added to the node sequence to form an input sequence.

5. The adaptive text generation method based on knowledge graphs according to claim 3, characterized in that, The step of inputting the input sequence into the structured data text generation model to generate the text description corresponding to the target tree node, as the query answer for the knowledge graph to be queried, includes: The input sequence is fed into the structured data text generation model to generate the text description corresponding to the target tree node; Determine whether the length of the text description meets the preset target length; If so, the text description will be used as the query answer for the knowledge graph to be queried; If not, then select a new target tree node from each tree node of the query path to generate a text description until the length of the text description meets the preset target length.

6. An adaptive text generation system based on knowledge graphs, characterized in that, The system includes: The data acquisition module is used to acquire the knowledge graph to be queried and the pre-constructed search tree; wherein, the search tree is composed of the pre-acquired total knowledge graph, the search tree contains multiple tree nodes, each tree node corresponds to a tree query vector, and the tree node includes at least a root node and a leaf node; The user query vector acquisition module is used to extract user query vectors representing the semantic and structural features of the knowledge graph to be queried. The query path acquisition module is used to start from the root node of the search tree, and query from the root node to the leaf node step by step based on the distance between the tree query vector and the user query vector, and save the query path from the root node to the leaf node. The text generation module is used to select a suitable target tree node from the query path, obtain the corresponding subgraph in the total knowledge graph based on the target tree node, input the corresponding subgraph into the structured data text generation model, and generate the text description corresponding to the target tree node as the query answer of the knowledge graph to be queried. The process of constructing the search tree includes: Calculate the relevance score between each node in the total knowledge graph and the topic represented by the total knowledge graph; Based on the relevance score to the topic, each node in the total knowledge graph is divided into multiple central nodes and multiple edge nodes; Based on the positional relationship between each central node and each edge node in the total knowledge graph, multiple tree node clusters are generated, and a tree query vector for each tree node cluster is obtained based on a graph attention network. Using each tree node cluster as a leaf node, multiple tree node clusters are gradually merged to form parent nodes and hierarchical structures, ultimately generating a search tree; Based on the positional relationships of each central node and each edge node in the overall knowledge graph, multiple tree node clusters are generated, and based on a graph attention network, a tree query vector for each tree node cluster is obtained, including: Each central node and the edge nodes within a preset step distance are treated as a tree node cluster; Each tree node cluster is input into a graph attention network to extract the semantic and structural features of each tree node cluster, and a tree query vector for the tree node cluster is generated based on the semantic and structural features. The process of using each tree node cluster as a leaf node, gradually merging multiple tree node clusters to form parent nodes and hierarchical structures, and finally generating a search tree includes: S41. According to the preset addition strategy, adjust the preset step size, regenerate multiple tree node clusters, and obtain the tree query vector of each tree node cluster. S42. Determine whether each tree node cluster contains the same node; S43. If so, merge the tree node clusters containing the same nodes into one tree node cluster, and use the merged tree node cluster as the parent node of each tree node cluster before the merger. S44. If not, repeat steps S41 to S42 until all nodes in the total knowledge graph have corresponding tree node clusters, and construct the search tree based on the hierarchical structure of each tree node cluster.