Knowledge graph query construction using Steiner trees
Steiner tree approximations in knowledge graph queries address the inefficiencies of existing LLMs by optimizing node connections for accurate and efficient retrieval of semantic information.
Patent Information
- Application Number
- US18/900405
- Authority / Receiving Office
- US · United States
- Patent Type
- Patents(United States)
- Current Assignee / Owner
- Filing Date
- 2024-09-27
- Publication Date
- 2026-12-01
- Estimated Expiration
- 2044-09-27
AI Technical Summary
Existing language models (LLMs) struggle with efficiently retrieving accurate responses to natural language queries due to limitations in querying knowledge graphs, often requiring additional grounding and hallucinating responses, while existing methods for constructing knowledge graph queries do not utilize Steiner trees or their approximations, leading to suboptimal connection of queried nodes.
Utilizing Steiner tree approximations to efficiently map natural language queries onto knowledge graph nodes, forming a connected set of nodes for optimal query construction, leveraging minimum spanning tree algorithms to generate query patterns and Cypher queries in knowledge graph databases.
Enables efficient and accurate retrieval of semantic information from knowledge graphs by constructing optimal queries that connect required nodes with minimal weight, improving response accuracy and computational efficiency.
Smart Images

Figure US12817857-D00000_ABST
Abstract
Description
BACKGROUND
[0001] Knowledge graphs are well-suited for capturing relationships between entities and semantic information in a way that facilitates both human and machine-based interpretation and reasoning. Algorithms that operate on knowledge graphs may take advantage of the mathematical properties of graphs to enhance performance and capabilities.BRIEF DESCRIPTION OF DRAWINGS
[0002] FIG. 1 is a diagram illustrating an example system for knowledge graph query construction using Steiner trees, used in accordance with various aspects of the present disclosure.
[0003] FIG. 2 is a diagram illustrating an example knowledge graph comprising circle, rhombus, square, and parallelogram type nodes with relationships between nodes depicted as rectangles.
[0004] FIG. 3 is a diagram illustrating another example knowledge graph with two example candidate trees, where nodes are depicted as circles and relationships between nodes are depicted as text associated with arrows connecting the nodes.
[0005] FIG. 4 illustrates an example apparatus effective for knowledge graph query construction using Steiner trees, used in accordance with various aspects of the present disclosure.
[0006] FIG. 5 is a block diagram showing an example architecture of a natural language processing system that may be used in accordance with various embodiments described herein.
[0007] FIG. 6 depicts an example language model-based natural language processing flow, in accordance with various aspects of the present disclosure.
[0008] FIG. 7 is a block diagram illustrating an example process for knowledge graph query construction using Steiner trees, in accordance with various aspects of the present disclosure.
[0009] FIG. 8 is a block diagram illustrating an example process for constructing a Steiner tree using a minimum spanning tree (MST) approximation, in accordance with various aspects of the present disclosure.DETAILED DESCRIPTION
[0010] In the following description, reference is made to the accompanying drawings that illustrate several examples of the various technologies described herein. It is understood that other examples may be utilized and various operational changes may be made without departing from the scope of the present disclosure. The following detailed description is not to be taken in a limiting sense, and the scope of the embodiments of the present invention is defined only by the claims of the issued patent.
[0011] Described herein are systems, techniques, and interfaces that may be used for constructing knowledge graph queries using Steiner trees and / or minimum spanning tree (MST) approximations based on natural language queries. Accordingly, some examples may receive a natural language query (e.g., “what is the share price of ABCD?”) and parse the natural language query into a set of tokens. The tokens may be words, fragments of words, lemmatized words, and / or the like. The set of tokens may be identified with or otherwise mapped onto nodes in a knowledge graph database. A Steiner tree may be identified that includes the set of tokens from the query, and the Steiner tree may be interpreted into a series of subject-predicate-object triplets that are arranged to form a knowledge graph query. In some examples, the knowledge graph query may be executed to automatically retrieve the requested information, which may then be prepared and formatted to present a response to the query (e.g., using text, audio, or other media as appropriate to the nature of the query and the types of devices that receives the query and provides the response).
[0012] The use of knowledge graphs has grown as technology has developed and increased their ease of adoption and use. Knowledge graphs provide a level of semantic understanding that is unavailable or more difficult to achieve in traditional database models. Knowledge graphs also provide scalability, integration, and interoperability needed for modern database functionality.
[0013] Accordingly, there is a need to integrate more technologies to make full use of the advantages of knowledge graphs, particularly the semantic understanding capabilities. One difficult problem that is suitable for knowledge graphs to solve is searching or querying using natural language. For example, voice-activated assistant devices, search engines, and / or the like may need to quickly and efficiently retrieve answers to questions received as a sentence or natural language expression. Existing language model (LM, including, for example, so-called “large language models” (LLMs)) approaches have limitations in such general assistant applications, including hallucinating responses and requiring additional grounding (e.g., through the use of retrieval augmented generation and / or in-context learning) to provide accurate responses. Knowledge graphs may store factual knowledge be queried for grounding an LM, or may directly provide responses without the aid of an LM.
[0014] In contrast with previous techniques, example methods disclosed herein leverage fast Steiner tree approximations to efficiently find a connected set of knowledge graph nodes required to form a database query based on a set of tokens. Previous approaches to preparing queries for knowledge graphs do not use Steiner trees or Steiner tree approximations, and therefore do not achieve optimal or approximations of optimal queries that connect the queried nodes with the least-weighted relations. In particular, cases where the number of nodes to query is greater than two and less than the total number of nodes in the tree cannot be simplified to a shortest-path or minimum spanning tree problem, and the Steiner tree or its approximation must be computed. By mapping natural language queries onto Steiner tree problems, example methods disclosed herein provide a technical improvement to systems for querying knowledge graph databases.
[0015] Knowledge graphs are data structures that include entities, attributes, and the relationships connecting them and stores this information in a mathematical graph structure. Graphs are mathematical structures that include nodes (also called vertices) connected by edges (which may include numerical weights). Various examples described herein may perform a subtask of automatic query generation which involves finding a path between entity nodes and datapoint nodes in a knowledge graph. As an illustrative example, an entity node may be a named entity like “George Washington” and a datapoint node could be any data associated with Washington such as “number of terms as President.” In various examples, a knowledge graph may store data in triplet form (e.g., subject-predicate-object). A path in such a graph may be joined between triplets. For example, a triplet may be (“Barack Obama”, “was president of”, “United States”) and a path connecting triplets may be (“Barack Obama”, “was president of”, “United States”)->(“United States”, “is located in”, “North America”). Algorithmically finding all triplet patterns and / or paths in a graph which produces a joining of a given entity and datapoint is a hitherto unsolved problem in the field. Finding such patterns in a graph provides a computationally efficient method of retrieving semantic information that is not possible with existing methods.
[0016] An example solution disclosed herein involves finding a minimum-weight tree that spans a given subset of nodes in a weighted graph. As described herein, it has been determined that this minimum-weight tree problem is connected to the Steiner tree problem. From this connection, various examples, may use approximation algorithms used for Steiner trees to find the triplet patterns to join to obtain a datapoint for a given entity.
[0017] Example methods disclosed herein use Steiner tree algorithms, including but not limited to minimum spanning tree (MST) to solve a path finding problem. These Steiner tree approximation solutions aid in algorithmically producing query patterns (e.g., match patterns) to join a given entity and datapoints in a knowledge graph to generate a complete query.
[0018] In the context of graph theory, the Steiner tree problem takes as input an undirected graph with non-negative weights for each edge and a subset of vertices of the graph, called terminals. Given these inputs, the Steiner tree is a tree of minimum weighted tree that includes all of the terminals, and potentially additional points called the Steiner points. Finding the Steiner tree is NP-hard, and the Steiner tree problem can be thought of as a generalization of a shortest path problem (a case where there are only two terminals) and the minimum spanning tree (MST) problem (when every vertex of the graph is a terminal), both of which are solvable in polynomial time.
[0019] The MST of a graph a subset of the graph's edges with the minimum possible total edge weight, while connecting all edges without any cycles. As stated above, finding the MST is a special case of the Steiner tree problem. Many algorithmic solutions exist to finding the MST for a graph, which are generally polynomial time or close to polynomial time, though faster solutions may exist for special cases.
[0020] Finding the MST may also be used in various algorithms for approximate solutions to the Steiner tree problem. For example, one Steiner tree approximation algorithm requires finding the MST of a subgraph of the metric closure of a graph induced by the terminals. This approximation produced a tree with weight within a factor of 2-2 / t of the optimal Steiner tree, where t is the number of leaves in the optimal Steiner tree. MST approximations to the Steiner tree problem provide a practical solution for cases where an exact Steiner tree is not required, and computational efficiency is a more important consideration.
[0021] As mentioned previously, various example methods disclosed herein utilize knowledge graphs to store semantic information. Knowledge graphs are data structures that include entities, attributes, and the relationships connecting them. As the name implies, a knowledge graph stores entities and relationships using a mathematical graph structure. The graph structure is flexible and allows the presentation of a diverse array of data in a way that is both human-readable and machine-readable. Knowledge graphs allow the incorporation of semantic information to improve how data is represented in the database. Knowledge graphs may include ontologies and schema that further define relationships between entities and enable advanced operations and queries over the stored data.
[0022] One popular graph database management system is Neo4j, which is capable of storing data as nodes, relationships, and properties. Neo4j supports the Cypher query language to allow users to query and manipulate data within a knowledge graph. Cypher supports complex queries, including pattern matching, filtering, and aggregation, and also tasks like finding paths, detecting patterns, and analyzing structures.
[0023] The Cypher query language bears similarities to SQL, and uses a visual way of matching patterns and relationships. For example, nodes are represented with parentheses around the node information. Relationships are represented with an arrow between nodes, which may include the relationship type indicated in square brackets. Cypher includes a variety of keywords for performing various operations, specifying patterns, applying filters, and / or the like. Example keywords include “RETURN”, “MATCH”, and “WHERE.” The “MATCH” keyword in particular is used for matching patterns. The “MATCH” keyword is followed by a search pattern for finding nodes, relationships, or combinations thereof. “WHERE” may be used to add constraints or filters on patterns, and “RETURN” provides a format for results to be returned from the query.
[0024] FIG. 1 is a diagram illustrating an example system 100 for knowledge graph query construction using Steiner trees. The example system 100 may include an NL agent 102 which provides an interface to a user 140 and a Steiner tree query system 130 which performs back-end processing. The NL agent 102 and / or Steiner tree query system 130 may be physically implemented as separate devices, on the same physical device (e.g., an apparatus 400), or as a combination of user devices, cloud services, and / or the like. A natural language agent may send and receive queries to interact with a user with natural language. An NL query may be received and processed by query processor 104, which may perform steps including tokenizing, filtering, lemmatizing, and / or the like, to produce a tokenized query. The graph data association 106 may be performed by matching tokens from the tokenized query to nodes (e.g., classes) from a knowledge graph 150 to form a set of identified graph nodes. The identified graph nodes may be treated as terminal nodes in a Steiner tree problem, and Steiner tree approximation circuitry 408 (described below in connection with FIG. 4 as a component of apparatus 400) may perform a fast approximation or exact calculation to find a Steiner tree or approximate Steiner tree that includes the terminal nodes (identified graph nodes). The Steiner tree may be used for query / response formulation 110 by algorithmically constructing fragments of database queries from connected nodes in the Steiner tree, and assembling the fragments into a complete knowledge graph database query. The query may be used to query the knowledge graph 150 and receive a query response, which query / response formulation 110 may subsequently parse and present as a natural language query response. Finally, NL agent 102 may receive the NL query response and use the query response to complete the interaction with the user.
[0025] FIG. 2 is a diagram illustrating an example knowledge graph comprising circle, rhombus, square, and parallelogram type nodes with relationships between nodes depicted as rectangles. Additionally, certain nodes are shown with associated name data. The circle or “N” type node shown is node NO 202. Rhombus or “P” type nodes shown are node P0204, node P1206, and node P2208. The square or “B” type nodes shown are node B0210 and node B1212. Finally, the parallelogram or “A” type nodes shown are node A0214, node A1216, and node A2218.
[0026] Relations between nodes are shown as rectangles with additional border lines. “NP” type relations connect “N” and “P” type nodes, and include relation NP 254, relation NP 256, and relation NP 258. “NB” type relations connect “N” and “B” type nodes, and include relation NB 260 and relation NB 262. “BA” type relations connect “B” and “A” type nodes, and include relation BA 264, relation BA 266, and relation BA 268.
[0027] A selection of nodes are shown with associated data of the “name” type. Node P0204 has attached data name: Alpha 284, and node A0214 has attached data name: Beta 294.
[0028] To represent all triplets in the graph, a listing would appear as:
[0029] Node N0→[relation NP]=→Node P0 {name: “Alpha”}
[0030] Node N0→[relation NP]=→P1
[0031] Node N0→[relation NP]=→P2
[0032] Node N0→[relation NB]=→B0
[0033] Node N0→[relation NB]=→B1
[0034] Node B0→[relation BA]→Node A0 {name: “Beta”}
[0035] Node B0→[relation BA]=→A1
[0036] Node B0→[relation BA]→A2 Additionally, the unique triplet patterns may be selected based only on types as:
[0037] Type N→[relation NP]=→Node P
[0038] Type N→[relation NB]→Node B
[0039] Type B→[relation BA]→Node A
[0040] Given the understanding of the graph as shown above, the task is to find the minimum set of triplet patterns which, when joined, results in a query for the required data from the database. For example, in the above subgraph, all data rows of Node A0 with the name “Beta” which are connected with P0 with name “Alpha” could be required for a query. In the form of a Cypher query, the corresponding “MATCH”, “WHERE”, and “RETURN” statements could be written as:
[0041] MATCH (:N)-[relation_np]->(p:P)
[0042] MATCH (:N)-[relation_np]->(:B)
[0043] MATCH (:B)-[relation_np]->(a:A)
[0044] WHERE p.name=“Alpha” and a.name=“Beta” RETURN p, a
[0045] To generate MATCH patterns such as the example above, a tree may be built which has connected paths from nodes of type “P” with the property “name: Alpha” to nodes of type “A” with the property “name: Beta”.
[0046] Stated another way, a shortest path tree that connects the required nodes may be found. This is a Steiner tree problem in literature, and solving it is an NP-Hard problem. Hence, an approximating method referred to as MST (Minimum Spanning Tree) may be used. Using a Minimum Spanning tree or Steiner tree to find the MATCH patterns in a knowledge graph has not been explored in public knowledge of literature or industry.
[0047] For using the MST a list of all possible triplet patterns in the graph is provided and any MST algorithm known in the art is used to find the shortest tree. The shortest tree is then used to build MATCH statements to help write the cypher query.
[0048] For example, in the above shared example where all possible triplets in a given graph are (as shown previously):
[0049] Type N→[relation NP]→Node P
[0050] Type N→[relation NB]=→Node B
[0051] Type B→[relation BA]=→Node A
[0052] The following example method may be used to apply MST on finding MATCH patterns. (1) Find the nodes in the graph which needs to be connected (in example it will be P and A). (2) Run an MST algorithm to join the identified nodes in step (1). (3) Rewrite the found triplets in the form of “MATCH” statements. Following these steps for the example above results in the statements:
[0053] MATCH (:N)-[relation_np]->(p: P)
[0054] MATCH (:N)-[relation_np]->(: B)
[0055] MATCH (:B)-[relation_np]->(a: A)
[0056] The “MATCH” statements may be combined with additional statements (e.g., “WHERE” and “RETURN” statements) to form a complete query. For example, an algorithmic or programmatic process may automatically generate the “MATCH” statements shown above, and the set of “MATCH” statements may be included in a language model query (facilitated, for example, using LM orchestrator 630, which may invoke LM prompt generation 650 described below) that instructs the language model (e.g., LM 660) to prepare a complete knowledge graph query (e.g., a Cypher query) based on the provided “MATCH” statements, further provided the context of the original natural language query. The language model may provide a response to the query, which may be parsed and interpreted to construct the knowledge graph query which includes the original “MATCH” statements combined with additional statements (e.g., “WHERE” and “RETURN”).
[0057] FIG. 3 is a diagram illustrating another example knowledge graph with two example candidate trees, where nodes are depicted as circles and relationships between nodes are depicted as text associated with arrows connecting the nodes. An example method is shown demonstrating how a Steiner tree helps to construct a correct Cypher query. Furthermore, while using a Steiner tree, an edge may be selected and / or dropped from the final tree by assigning appropriate weights to edges participating in the input function.
[0058] The diagram of FIG. 3 represents a subgraph of a larger knowledge graph that includes, among other information, details relevant to retrieving a stock price for a company listed on an index. Any example natural language query considered in connection with FIG. 3 may be “what is the share price of ABCD?” The nodes depicted in FIG. 3 include stock listing 302, security exchange 304, identifier 306, stock 308, company 310, geographic entity 312, time series 314, interval granularity type 316, observation event 318, geographic entity type 320, class 322, quantity data point 324, data point type 326, unit or scale type 328, index 330, and index listing 332. Relations between nodes include exchange listed on 352, intra day time series 354, identifier 356, stock listing 358, identifier 360, issuer 362, identifier 364, identifier 366, end of day time series 368, issuer 370, located in 372, interval granularity 374, observation 376, data point 378, geographic entity type 380, intra day time series 382, data point type range 384, data point type 386, unit of scale 388, observation 390, and index listing 392. The node geographic entity 312 also has a self-referencing relation, located in 394. Solid light arrows connecting nodes represent relations not included in either example tree A or example tree B, solid heavy arrows represent relations included in tree A, light dashed arrows represent relations included in tree B, and heavy dashed arrows represent relations included in both trees A and B.
[0059] Returning to the example query, “what is the share price of ABCD?” an example method may determine that answering the query requires data from the company 310 node and the data point type 326 node. The goal in answering the query is then to construct a tree with the least possible weight that connects company 310 and data point type 326 as triplets in a set of “MATCH” patterns for a Cypher query. As shown in FIG. 3, company 310 is connected to stock 308 via issuer 370 and also to geographic entity 312 via located in 372. Geographic entity 312 has its own observation 390 and data points. If one optimizes assuming unit weight for each edge of the graph, tree B (shown as a dashed line) will be preferred.
[0060] As for responding to the original query, tree B does not provide the correct information, however. Tree B yields only data points which are associated with the company 310 and its geographic location (via geographic entity 312), but will not contain information about the share price (e.g., stock 308 and stock listing 302). To resolve this problem, a larger weight (e.g., weight=200) may be assigned to the edge corresponding to
[0061] (:GeographicEntity)->[:locatedIn]→(:GeographicEntity)
[0062] which is shown as located in 394 on FIG. 3. With a large weight associated to located in 394, the Steiner tree algorithm will omit tree B and choose another path that may have a larger number of hops but lower total weight, which is tree A in this example. While this example illustrates how adding large weights may help avoid disfavored tree choices, lower weights may also be used to cause an edge to be explicitly selected.
[0063] FIG. 4 is a diagram illustrating an example apparatus for generating artwork based on music metadata, visual data, and / or audio data that may be used in accordance with various aspects of the present disclosure. Various example methods (described previously with reference to FIG. 1) may be performed by one or more computing devices, shown as apparatus 400 in FIG. 4. The apparatus 400 may be configured to execute various operations described above in connection with FIG. 2 and below in connection with FIG. 5. As illustrated in FIG. 4, the apparatus 400 may include processor 402, memory 404, and communications hardware 406, each of which will be described in greater detail below.
[0064] The processor 402 (and / or co-processor or any other processor assisting or otherwise associated with the processor) may be in communication with the memory 404 via a bus for passing information amongst components of the apparatus. The processor 402 may be implemented in a number of different ways and may, for example, include one or more processing devices configured to perform independently. Furthermore, the processor may include one or more processors configured in tandem via a bus to enable independent execution of software instructions, pipelining, and / or multithreading. The use of the term “processor” may be understood to include a single core processor, a multi-core processor, multiple processors of the apparatus 400, remote or “cloud” processors, or any combination thereof.
[0065] The processor 402 may be configured to execute software instructions stored in the memory 404 or otherwise accessible to the processor. In some cases, the processor may be configured to execute hard-coded functionality. As such, whether configured by hardware or software methods, or by a combination of hardware with software, the processor 402 represents an entity (e.g., physically embodied in circuitry) capable of performing operations according to various examples of the present invention while configured accordingly. Alternatively, as another example, when the processor 402 is embodied as an executor of software instructions, the software instructions may specifically configure the processor 402 to perform the algorithms and / or operations described herein when the software instructions are executed.
[0066] Memory 404 is non-transitory and may include, for example, one or more volatile and / or non-volatile memories. For example, the memory 404 may be an electronic storage device (e.g., a computer readable storage medium). The memory 404 may be configured to store information, data, content, applications, software instructions, or the like, for enabling the apparatus 400 to carry out various functions in accordance with various examples disclosed herein.
[0067] The communications hardware 406 may be any means such as a device or circuitry embodied in either hardware or a combination of hardware and software that is configured to receive and / or transmit data from / to a network and / or any other device, circuitry, or module in communication with the apparatus 400. In this regard, the communications hardware 406 may include a network interface for enabling communications with a wired or wireless communication network. For example, the communications hardware 406 may include one or more network interface cards, antennas, buses, switches, routers, modems, and supporting hardware and / or software, or any other device suitable for enabling communications via a network. Furthermore, the communications hardware 406 may include the processing circuitry for causing transmission of such signals to a network or for handling receipt of signals received from a network.
[0068] The communications hardware 406 may further be configured to provide output to a user and, in various examples, to receive an indication of user input. In this regard, the communications hardware 406 may comprise a user interface, such as a display and audio speakers. In various examples, the communications hardware 406 may include a keyboard, a mouse, a touch screen, touch areas, soft keys, a microphone, a speaker, and / or other input / output mechanisms. The communications hardware 406 may utilize the processor 402 to control one or more functions of one or more of these user interface elements through software instructions (e.g., application software and / or system software, such as firmware) stored on a memory (e.g., memory 404) accessible to the processor 402.
[0069] In addition, the apparatus 400 may comprise a Steiner tree approximation circuitry 408 that produces a Steiner tree or approximation of a Steiner tree when provided with a graph. The Steiner tree approximation circuitry 408 may utilize processor 402, memory 404, or any other hardware component included in the apparatus 400 to perform these operations, as described in connection with FIGS. 5-5 below. The Steiner tree approximation circuitry 408 may additionally or alternatively include specialized hardware for determining a Steiner tree based on a set of nodes, edges, and weights, and the specialized hardware may be optimized for efficient computation of Steiner trees and / or approximations thereof. In some examples, the Steiner tree approximation circuitry 408 may be configured to perform the operations described below in connection with FIG. 6 to utilize an MST to approximate a Steiner tree.
[0070] In addition, the apparatus 400 may comprise a natural language processing system 520 that performs tokenization and other processing of natural language queries, invokes Steiner tree approximation circuitry 408 and other circuitry to prepare a query, queries a knowledge graph 150, and may also prepare a natural language response that is responsive to the original query, based on data retrieved from knowledge graph 150. The natural language processing system 520 is described in further detail below in connection with FIG. 5.
[0071] In addition, the apparatus 400 may comprise a LM orchestrator 630 that interfaces with a language model for performing various functions. For example, the LM orchestrator 630 may receive an initial natural language query, process the query, and redirect the query or a processed derivative of the query to the query processor 104 for processing in the context of the Steiner tree approximation methods disclosed herein. In another example, the response formulation 110 of example methods disclosed herein may construct a syntactically coherent and complete database query using an input to orchestrator 630 based on data retrieved from knowledge graph 150.
[0072] It will be understood that any methods disclosed herein that may be performed by apparatus 400 may include one or more dedicated processors, specially configured field programmable gate array (FPGA), or application specific interface circuit (ASIC) to perform their corresponding functions, and may accordingly leverage processor 402 executing software stored in a memory (e.g., memory 404), or communications hardware 406 for enabling any functions not performed by special-purpose hardware. In various examples, however, it will be understood that apparatus 400 comprises particular machinery designed for performing the functions described herein in connection with processor 402, memory 404, and / or communications hardware 406.
[0073] In various examples, various components of the apparatus 400 may be hosted remotely (e.g., by one or more cloud servers) and thus need not physically reside on the corresponding apparatus 400. For instance, some components of the apparatus 400 may not be physically proximate to the other components of apparatus 400. Similarly, some or all of the functionality described herein may be provided by third party circuitry. For example, a given apparatus 400 may access one or more third party circuitries in place of local circuitries for performing certain functions.
[0074] As will be appreciated based on this disclosure, various examples contemplated herein may be implemented by an apparatus 400. Furthermore, some examples may take the form of a computer program product comprising software instructions stored on at least one non-transitory computer-readable storage medium (e.g., memory 404). Any suitable non-transitory computer-readable storage medium may be utilized in such example systems, some examples of which are non-transitory hard disks, CD-ROMs, DVDs, flash memory, optical storage devices, and magnetic storage devices. It should be appreciated, with respect to certain devices embodied by apparatus 400 as described in FIG. 4, that loading the software instructions onto a computing device or apparatus produces a special-purpose machine comprising the means for implementing various functions described herein.
[0075] FIG. 5 is a block diagram showing an example architecture of a natural language processing system 520 that may be used in accordance with various embodiments described herein. In various examples situations, a natural language processing device 502 (e.g., a speech processing-enabled device such as a device including the NL agent 102) may receive audio data 504 and may send the audio data 504 to the natural language processing system 520 for processing. As described above, the device 502 may capture audio using the microphone 470, and send audio data 504 (e.g., representing a spoken user request), corresponding to the captured audio, to the natural language processing system 520. The device 502 may include a wakeword detection component that detects when input audio includes a spoken wakeword, and when the wakeword is detected, the audio data 504 is sent by the device 502 to the natural language processing system 520. The natural language processing system 520 may employ language models (such as LM 660 descried in reference to FIG. 6) and / or other natural language processing components (such as natural language understanding component 560).
[0076] Upon receipt by the natural language processing system 520, the audio data 504 may be sent to an orchestrator 630 (e.g., a language model orchestrator). The orchestrator 630 may include memory and logic that enables the orchestrator 630 to send various pieces and forms of data to various components of the system.
[0077] The orchestrator 630 may send the audio data 504 to a natural language processing component 540. An ASR component 550 of the natural language processing component 540 transcribes the audio data 504 into one or more hypotheses representing speech contained in the audio data 504. The natural language processing component 540 interprets the speech in the audio data based on a similarity between the characteristics of the audio data corresponding to the speech and pre-established language models. For example, the natural language processing component 540 may compare the audio data 504 with models for sounds (e.g., subword units such as phonemes) and sequences of sounds to identify words that match the sequence of sounds in the speech represented in the audio data 504. The natural language processing component 540 may send text data generated thereby to an NLU component 560 of the natural language processing component 540. The text data output by the natural language processing component 540 may include a top scoring hypothesis of the speech represented in the audio data 504 or may include an N-best list including a group of hypotheses of the speech represented in the audio data 504, and potentially respective scores ASR processing confidence scores.
[0078] The NLU component 560 attempts to make a semantic interpretation of the phrases or statements represented in the text data input therein. That is, the NLU component 560 determines one or more meanings associated with the phrases or statements represented in the text data based on individual words represented in the text data. The NLU component 560 interprets a text string to derive an intent of the user (e.g., an action that the user desires be performed) as well as pertinent pieces of information in the text data that allow a device (e.g., the natural language processing system 520) to complete the intent. For example, if the text data corresponds to “What is the name of the new album by {Musical_Artist}”, the NLU component 560 may determine the user intended to make a knowledge-based query about music library data.
[0079] In various examples, the orchestrator 630 may instead pass the audio data 504 and / or a transcription of the audio data 504 (e.g., generated by ASR component 550) to LM 660 for processing, as described in further detail below in reference to FIG. 6. The natural language processing system 520 (and / or orchestrator 630) may send a structured data representation of query data to the query processor 104, which may tokenize and process a natural language query as described in connection with FIG. 1 and elsewhere.
[0080] Upon receiving a user query (e.g., included in audio data 504), the LM 660 may, in some examples, perform retrieval actions, including retrieval augmented generation (RAG) to provide factual grounding for responses to queries. Accordingly, the LM 660 may pass a natural language query to the query processor 104, which may in turn provide a response to the query grounded using knowledge graph 150.
[0081] The natural language processing system 520 may include a non-transitory computer-readable memory storage 570 (which may be identified with or provided by physical components of, e.g., memory 404), storing various instructions for operation of the natural language processing system 520. In some examples, the natural language processing system 520 may include one or more skills 590. Skills 590 may be application-specific programs that may be accessible by the orchestrator 630 and / or the LM 660. In various examples, application programming interfaces (APIs) of the skills 590 may be exposed to the orchestrator 630 and / or the LM 660 (along with API definitions) so that the LM 660 and / or the orchestrator 630 is able to understand the specific functionality of a given skill along with the specific arguments and expected responses associated with the skill. The natural language processing system 520 may also include a TTS component 580 that synthesizes speech (e.g., generates audio data) corresponding to text data input therein. The TTS component 580 may perform speech synthesis using one or more different methods. In one method of synthesis called unit selection, the TTS component 580 matches text data against one or more databases of recorded speech. Matching units are selected and concatenated together to form audio data. In another method of synthesis called parametric synthesis, the TTS component 580 varies parameters such as frequency, volume, and noise to create an artificial speech waveform output. Parametric synthesis uses a computerized voice generator, sometimes called a vocoder.
[0082] The various components of the natural language processing system 520 and the device 502 described herein may be implemented in software, hardware, firmware, or some combination thereof.
[0083] The natural language processing system 520 may reside on apparatus 400, in a cloud computing environment, or some combination thereof. For example, the device 502 may include computing equipment, some portion of which is configured with some or all of the components or functionality of natural language processing system 520 and another portion of which is configured with some or all of the components or functionality of computing device(s) used in natural language processing system 520. The apparatus 400 may then perform a variety of functions on its own (such as when remote communications are unavailable), and / or may communicate (when capable) with computing device(s) and / or the natural language processing system 220 to perform other functions. Alternatively, all of the functionalities may reside on the apparatus 400 or remotely.
[0084] FIG. 6 depicts an example LM-based natural language processing flow (which may be an example LM architecture in accordance with various aspects of the present disclosure. The example architecture in FIG. 6 includes an LM orchestrator 630 (shown previously in FIG. 4 in connection with apparatus 400) and various other components for performing various actions such as completing knowledge graph database queries, invoking the Steiner tree approximation circuitry 408 for RAG, and / or the like. The architecture may further include an action plan execution component 680 and an API provider component 690. With reference to FIG. 6, the LM orchestrator 630 may include a preliminary action plan generation component 640, a LM prompt generation component 650, an LM 660, and an action plan generation component 670. In various examples, the LM 660 may be a generative model.
[0085] In some examples, the LM 660 may be a transformer-based seq2seq model involving an encoder-decoder architecture. In some such embodiments, the LM 660 may be a multilingual (approximately) 20 billion parameter seq2seq model that is pre-trained on a combination of denoising and Causal Language Model (CLM) tasks in various languages (e.g., English, French, German, Arabic, Hindi, Italian, Japanese, Spanish, etc.), and the LM 660 may be pre-trained for approximately 1 trillion tokens. Being trained on CLM tasks, the LM 660 may be capable of in-context learning. An example of such a LM is Alexa Teacher Model (Alexa™).
[0086] In various examples, the input to the LM 660 may be in the form of a prompt. A prompt may be a natural language input, for example, an instruction, for the LM 660 to generate an output according to the prompt (e.g., one or more questions for input event data). The output generated by the LM 660 may be a natural language output responsive to the prompt. The prompt and the output may be text in a particular spoken language.
[0087] The LM 660 may be configured using various learning techniques. For example, in some embodiments, the LM 660 may be configured (e.g., “fine-tuned”) using few-shot learning. In few-shot learning, the model learns how to learn to solve the given problem. In this approach, the model is provided with a limited number of examples (i.e., “few shots”) from the new task, and the model uses this information to adapt and perform well on that task. Few-shot learning may require fewer amount of training data than implementing other fine-tuning techniques. For further example, in some embodiments, the LM 660 may be configured using one-shot learning, which is similar to few-shot learning, except the model is provided with a single example. As another example, in some embodiments, the LM 660 may be configured using zero-shot learning. In zero-shot learning, the model solves the given problem without examples of how to solve the specific / similar problem and just based on the model's training dataset. In this approach, the model is provided with data sampled from a class not observed during training, and the model learns to classify the data.
[0088] The LM orchestrator 630 may be configured for generating the prompt to be used by the LM 660 to determine an action responsive to a user query and / or to input event data. As shown in FIG. 6, the LM orchestrator 630 receives (at step 1) input data 627 (which may be a user query or other instructions, as described above in reference to FIG. 1). In some instances, the input data 627 may correspond to a text or tokenized representation of a user input. For example, prior to the LM orchestrator 630 receiving the input data 627, another component (e.g., an ASR component) may receive audio data representing the input. The ASR component may perform ASR processing on the audio data to determine ASR output data corresponding to the user input. As previously described, an ASR component may determine ASR data that includes an ASR N-best list including multiple ASR hypotheses and corresponding confidence scores representing what the user may have said. The ASR hypotheses may include text data, token data, etc. as representing the input utterance. The confidence score of each ASR hypothesis may indicate the ASR component's level of confidence that the corresponding hypothesis represents what the user said. The ASR component may also determine token scores corresponding to each token / word of the ASR hypothesis, where the token score indicates the ASR component's level of confidence that the respective token / word was spoken by the user. The token scores may be identified as an entity score when the corresponding token relates to an entity. In some instances, the input data 627 may include a top scoring ASR hypothesis of the ASR data.
[0089] As illustrated in FIG. 6, the input data 627 may be received at the preliminary action plan generation component 640 and the LM prompt generation component 650 of the LM orchestrator 630. The preliminary action plan generation component 640 processes the input data 627 to generate prompt generation action plan data 645 corresponding to an instruction(s) (e.g., a request(s)) for one or more portions of data usable to generate a language model prompt for determining an action responsive to the user input). In some examples, the one or more portions of data may be data that is determined to be relevant for processing of the input. The one or more portions of data may represent one or more actions (e.g., API definitions), one or more exemplars corresponding to the actions (e.g., example model outputs including an appropriate use of the API), one or more device states corresponding to one or more devices associated with the user input, and / or one or more other contexts associated with the user input. For example, if the input data 627 represents an event related to a particular entity then the preliminary action plan generation component 640 may determine prompt generation action plan data 645 representing instructions for one or more actions (e.g., API definitions) related to retrieving information from a data store (e.g., knowledge graph 150) related to the entity.
[0090] In some examples, the prompt generation action plan data 645 may include one or more executable API calls usable for retrieving the one or more portions of data from the corresponding component. For example, instructions included in the prompt generation action plan data 645 may include “FETCH_API,”“FETCH_EXEMPLAR,”
[0091] “FETCH_DEVICE_STATE,”“FETCH_CONTEXT,” etc., along with optional API arguments / inputs. In some embodiments, the prompt generation action plan data 645 may also include the input data 627. The prompt generation action plan data 645 may be sent (at step 2) to the action plan execution component 680.
[0092] In some examples, the preliminary action plan generation component 640 may implement one or more machine learning (ML) models. A first ML model(s) may be configured to take as input the input data 627 and generate a representation of the user's request. For example, the preliminary action plan generation component 640 may include the NL agent 102. For example, the ML model may be a text summarization model or a text rewrite model. A second ML model (or the first ML model) may be configured to take as input the input event data or query data and may determine one or more portions of data relevant for processing of the input. For example, the second ML model may be a classifier trained to classify the request (or the input data 627) to determine data (or types of data) relevant to the processing of the input (e.g., one or more related actions (e.g., API definitions), one or more exemplars corresponding to the one or more related actions, one or more device states corresponding to one or more related devices, one or more related contexts, etc.)
[0093] In other embodiments, the preliminary action plan generation component 640 may be an LM, similar to the LM 660. In such embodiments, the architecture may include a further component configured to generate a prompt to be provided to the LM (e.g., similar to the LM prompt generation component 650) or the prompt may be generated by the LM prompt generation component 650. In various examples, the LM prompt generation component 650 may use the various techniques described herein to generate the prompt. For example, the LM prompt generation component 650 may include natural language instructions and / or code configured to cause the LM 660 to explore multiple different strategies in a decision tree for the current input task. Additionally, using planning (e.g., CoT prompting) the LM prompt generation component 650 may generate a prompt to cause the LM 660 to divide the current task into multiple sub-tasks, with thoughts, actions, and observations. The LM may process the prompt and generate model output data representing the one or more portions of data (or types of data). The preliminary action plan generation component 640 may process the model output data to determine the prompt generation action plan data 645.
[0094] The action plan execution component 680 may process the prompt generation action plan data 645 to execute the one or more instructions to retrieve / receive data corresponding to the input and that may be used to generate the language model prompt. As shown in FIG. 6, the action plan execution component 680 processes the prompt generation action plan data 645 to generate action data 685 representing an action included in the prompt generation action plan data 645 (e.g., a single instruction, such as FETCH_CONTEXT). For example, in the situation where the action is represented by an API call, the action data 685 may represent the action plan execution component 680 executing the API call included in the prompt generation action plan data 645. The action data 685 may be sent (at step 3) to the API provider component 690. In the situation where the prompt generation action plan data 645 includes more than one instruction, the action plan execution component 680 may generate more than one instance of action data 685 (e.g., one instance for each instruction included in the prompt generation action plan data 645) and send each instance to the API provider component 690.
[0095] The API provider component 690 may process the (one or more instances of the) action data 685 and cause the retrieval of the (one or more portions of) data associated with the action data 685. The API provider component 690 may include a knowledge provider component. The knowledge provider component may include an API retrieval component, an exemplar retrieval component, a device state retrieval component, and an “other” context retrieval component. The knowledge provider component may provide the action data 685 to the component(s) configured to determine the data corresponding to the request(s) represented by the action data 685.
[0096] For example, the API retrieval component (not shown) may process the action data 685 to generate API data 692 representing one or more APIs that correspond to an action performable with respect to the input. For example, if the user input corresponds to “turn on the kitchen light,” the API retrieval component may determine an API usable to control a device and include an API definition corresponding to the API in the API data 692. In some examples, the API definition may include one or more API call frameworks for instructing / requesting that the API perform an action (e.g., turn_on_device (device: [device name]), turn_off_device (device: [device name]), set_device_temperature (device: [device name]); temperature: [temperature], set_device_volume (device: [device name]; volume: [volume value]), etc.). In some examples, the API definition may include a natural language description of the functionality of the API (e.g., a natural language description of the actions performable by the API / API call framework). For example, for the abovementioned API determined to be associated with the user input of “turn on the kitchen light,” the API definition may further include a natural language description of “used to power on a device.” In some embodiments, the one or more API definitions may be included in the API data 692 based on them being semantically similar to the user input. For example, the API retrieval component may be capable of comparing (e.g., using cosine similarity) (an encoded representation of) the user input to (an encoded representation of) the API definition to determine a semantic similarity between the user input and the API definition (e.g., a semantic similarity between the user input and the natural language description of the functionality of the API included in the API definition). If the API definition is determined to be semantically similar to the user input, then the corresponding API definition may be included in the API data 692. In some embodiments, the API retrieval component may include the top-n identified API definitions in the API data 692. The API data 692 may be sent (at step 4) to the action plan execution component 680 as shown in FIG. 6.
[0097] For further example, the exemplar retrieval component may process the action data 685 to generate exemplar data 694 representing one or more exemplars associated with one or more APIs (e.g., the API represented by the API data 692). As used herein, an “exemplar” associated with an API corresponds to an example use of the API (e.g., an example language model output including use of the API (e.g., via a corresponding API call) with respect to a user input, where the user input is similar to the current user input. For example, for an API associated with the API call framework “turn_on_device (device: [device name]),” and the current user input “please turn on the kitchen lights” the exemplar retrieval component may select an exemplar including the example user input of “please turn on the lights” and the API call of “turn_on_device (device=” lights”).” In some embodiments, an exemplar represented in the exemplar data 694 may include an example user input, a natural language description of an action associated with the example user input, an executable API call associated with the example user input and the action associated with the example user input, an example result of the API call, a natural language description of an action to be performed in response to the example result of the API call, and / or an output responsive to the user input. For example, for an API associated with the API call frameworks “Routine.create_turn_on_action (device: str)” and “Routine.create_time_trigger (hour: [hour value])” and the current user input “please turn on the kitchen light every day at 7 am,” the exemplar retrieval component may select an exemplar related to creating a routine for device control.
[0098] Although not illustrated in FIG. 6, in some embodiments, the API provider component 690 and / or a knowledge provider component may provide the exemplar retrieval component with the action data 685 and a list of API call(s) to which the determined exemplars are to be associated (e.g., the API call(s) included in the API data 692). In some embodiments, the one or more exemplars may be included in the exemplar data 694 based on them being semantically similar to the user input. For example, the exemplar retrieval component may be capable of comparing (e.g., using cosine similarity) the current user input to the example user input included in an exemplar to determine a semantic similarity between the current user input and the example user input. If the example user input is determined to be semantically similar to the current user input, then the corresponding exemplar may be included in the exemplar data 694. In some embodiments, the exemplar retrieval component may include the top-n identified exemplars in the exemplar data 694. The exemplar data 694 may be sent (at step 4) to the action plan execution component 680 as shown in FIG. 6.
[0099] As a further example, a context retrieval component (not shown) may process the action data 685 to generate other context data 648 (apart from the device state data 696, the API data 692, the exemplar data 694, etc.) representing one or more contexts associated with / relevant to the user input. For example, the other context data 648 may represent user profile information (age, gender, associated devices, user preferences, etc.), visual context (e.g., content being displayed by devices associated with the user profile, content being displayed by the user device that captured the user input, etc.), knowledge context (e.g., one or more previous user inputs and / or system generated responses, etc.), time of day, geographic / device location, weather information, etc. In some embodiments, the context data 648 may include the top-n identified context. The other context data 648 may be sent (at step 4) to the action plan execution component 680 as shown in FIG. 6.
[0100] In some examples, the knowledge provider component may be configured to cause one or more of the API retrieval components, the exemplar retrieval component, the device state retrieval component, and the other context retrieval component to process based on the data output by one or more of the components of the knowledge provider component. For example, if the output of the API retrieval component (e.g., the API data 692) indicates that a related API definition was identified, then the knowledge provider component (or another component) may cause the exemplar retrieval component to process to determine one or more exemplars related to the identified API definitions. For further example, if the output of the API retrieval component (e.g., the API data 692) indicates that a particular API definition was identified (e.g., an API definition for controlling a device), then the knowledge provider component may cause the exemplar retrieval component to process as described above, and may further cause the device state retrieval component and / or the other context retrieval component to process to determine device states for one or more related devices and / or other contextual information based on the identified API definition being associated with controlling a device. In some embodiments, the knowledge provider component may determine to cause the components to process based on instruction(s) included in the action data (e.g., based on a determination made by preliminary action plan generation component 640, as discussed above).
[0101] The action plan execution component 680 may send (step 5) the data received from the API provider component 690 (e.g., the API data 692, the exemplar data 694, the device state data 696, and the other context data 648) to the LM prompt generation component 650. The LM prompt generation component 650 may be configured to generate prompt data 655 (e.g., using the input data 627, the API data 692, the exemplar data 694, the device state data 696, and / or the other context data 648) to be used by the LM 660.
[0102] In some examples, the LM prompt generation component 650 may generate the prompt data 655 representing a prompt for input to the LM 660. In some embodiments, such prompt data 655 may be generated based on combining the input data 627, the API data 692, the exemplar data 694, the device state data 696, and the other context data 648. The prompt data 655 may be an instruction to determine an action(s) responsive to the input data 627 given the other information (e.g., the API data 692, the exemplar data 694, the device state data 696, the other context data 648) included in the prompt data 655. In some embodiments, the LM prompt generation component 650 may also include in the prompt data 655 a sample processing format to be used by the LM 660 when processing the prompt and generating the response. In some embodiments, the prompt data 655 may be generated according to a template format.
[0103] In some examples, the template format may instruct the LM 660 as to how it should process to determine the action responsive to the user input and / or how it should generate the output including the action response to the user input. For example, as shown in the example above, the format may include the label “User:” labelling the following string of characters / tokens as the user input. For further example, the format may include the label “Thought:” instructing the LM 660 to generate an output representing the determined interpretation of the user input by the LM 660 (e.g., the user is requesting [intent of the user input], the user is trying to [intent of the user Input], etc.) As another example, the format may include the label “Observation:” labeling the following string of characters / tokens as the result of performance of an action determined by the LM 660 / the LM 660's interpretation of the result of the performance of the action determined by the LM 660. As a further example, the format may include a label of “Response:” instructing the LM 660 to generate a response (e.g., a natural language output for a user) to the prompt.
[0104] In some embodiments, the LM prompt generation component 650 may also include in the prompt data an instruction to output a response that satisfies certain conditions. Such conditions may relate to generating a response that is unbiased (toward protected classes, such as gender, race, age, etc.), non-harmful, profanity-free, etc. For example, the prompt data may include “Please generate a polite, respectful, and safe response and one that does not violate protected class policy.” The LM prompt generation component 650 may be configured to provide prompts to enable the self-inspired reasoning described herein. For example, the LM prompt generation component 650 may generate prompts instructing the LM 660 to consider several alternative approaches and / or lines of reasoning in order to respond to the input data 627. Additionally, the prompt generation component 650 may be configured to generate prompts causing the LM 660 to backtrack after generating intermediate output to consider other branches of reasoning and may also instruct the LM 660 to aggregate information from different lines of reasoning prior to the next planning step.
[0105] The LM 660 processes the prompt data 655 to generate model output data 665 representing an action responsive to the user input. For example, based on processing the example prompt data provided above, the LM 660 may output model output data 665: {“Thought: the user is trying to turn on the living room light; Action: turn_on_device (device=” living room light”),”} or the like. The model output data 665 is sent (at step 7) to the action plan generation component 670. The action plan generation component 670 may parse the model output data 665 to determine action plan data representing the action generated by the LM 660. For example, for the model output data 665: “Action: turn_on_device (device=” living room light”),” the corresponding action plan data may correspond to “turn_on_device (device=” living room light “)” (e.g., corresponding to the action generated by the LM 660, without the label of “Action”). In some embodiments, the action plan generation component 670 may determine an API call corresponding to the “Action” data included in the model output data 665. For example, in some embodiments, the action plan generation component 670 may fill in the arguments / inputs, if any, for the API call, which may be included in the action plan data. For further example, in some embodiments, the action plan execution component 680 may fill in the arguments / inputs, if any, for the API call.
[0106] FIG. 7 is a block diagram illustrating an example process for knowledge graph query construction using Steiner trees. Example flowcharts are illustrated that contain example operations implemented by various examples described herein. The operations illustrated in FIG. 7 may, for example, be performed by a system embodied by an apparatus 400, which is shown and described in connection with FIG. 4. To perform the operations described below, the apparatus 400 may utilize one or more of processor 402, memory 404, communications hardware 406, and / or specialized hardware or circuitry for performing the operations described below. It will be understood that user interaction with the apparatus 400 may occur directly via communications hardware 406, or may instead be facilitated by a separate user device, and which may have similar or equivalent physical componentry facilitating such user interaction.
[0107] As shown by operation 710, apparatus 400 includes means, such as communications hardware 406, and / or the like, for receiving a knowledge graph comprising a plurality of graph nodes. In some examples, sets of three graph nodes may be arranged as subject-predicate-object triplets. For example, as shown in FIG. 2, graph nodes may represent each of the subject, object, and predicate of the subject-predicate-object triplet structure. Communications hardware 406 may receive the knowledge graph in any format known in the art, including various formats readable using Neo4j and / or other software for managing graph databases. In other words, the knowledge graph may include a graph (or graph database) and an associated ontology (or taxonomy), which may provide a schema for interpreting data of the graph or graph database. In some examples, the subject-predicate-object triplet may be stored as a fragment of a database query. For example, in the case of Cypher queries, subject-predicate-object triplets may be represented in the form “Type N→[relation NP]→Node P” based on the example of FIG. 2.
[0108] In some examples, one or more of the plurality of graph nodes is associated with a respective key-value pair. The key-value pair may allow graph nodes to store metadata, properties or other data associated with the node. For example, node P0204 from FIG. 2 has an associated key-value pair name: Alpha 284, where the key is “name” and the value is “Alpha.” Key-value pairs may additionally store identifiers, attributes, status labels, and / or the like, while more complex information may typically be stored as relational information involving additional graph nodes.
[0109] As shown by operation 720, apparatus 400 includes means, such as communications hardware 406, and / or the like, for receiving a parsed query comprising a first data entry and second data entry. For example, as described in connection with FIG. 3, a natural language query may be received such as “what is the share price of ABCD?” which may be processed by, for example, a natural language model as an initial step for interpreting the query. In some examples, the natural language model may produce a series of tokens (e.g., a first token corresponding to the first data entry and a second token corresponding to the second data entry), and each token may be subsequently checked for associations to one or more nodes in the knowledge graph. Tokens may be filtered or adjusted to remove natural language tokens that may not influence a knowledge graph search (e.g., articles, punctuation), and other adjustments may be made to tokens (e.g., fixing spelling mistakes, adjusting references to other words in the query).
[0110] As shown by operation 730, apparatus 400 includes means, such as processor 402, memory 404, and / or the like, for determining a first graph node among the plurality of graph nodes that corresponds to the first data entry, and, as shown by operation 740, for determining a second graph node among the plurality of graph nodes that corresponds to the second data entry. In the example of FIG. 3 (with the query “what is the share price of ABCD?”), a determination may be made that the share price query relates to the nodes called “company” (company 310) and “DataPointType” (data point type 326). Various algorithms and / or machine learning models may be employed to associate a particular token to a knowledge graph node (e.g., the first graph node and / or the second graph node). In some examples, a lookup table of cached associations between tokens and nodes may be used to provide associations to the graph nodes. The tokens (e.g., first data entry and second data entry) may be associated with information in the nodes themselves, metadata or other identifiers associated with the nodes (e.g., the key-value pairs associated with the nodes) and / or the like. In some examples, semantic information about the context of the first data entry and the second data entry as tokens or words within a larger sentence or query may be used. For example, contextual information derived from an attention layer of a transformer or other machine learning model may provide information useful for identifying a likely node of the knowledge graph to associate with the first data entry and second data entry.
[0111] In some examples, a subgraph including the first graph node and the second graph node may be constructed for use in subsequent operations. For example, a heuristic or other approach may prune the full knowledge graph by removing parts of the knowledge graph that are unlikely to be useful in finding a Steiner graph or path connecting the first graph node and the second graph node.
[0112] As shown by operation 750, apparatus 400 includes means, such as processor 402, memory 404, Steiner tree approximation circuitry 408, and / or the like, for determining a Steiner tree comprising the first graph node and the second graph node. The Steiner tree may be constructed using any Steiner tree method or approximation known in the art. For one example of using an MST to approximate the Steiner tree, an example implementation is given below in connection with FIG. 6. It will be understood that a Steiner tree found in operation 750 may be an exact Steiner tree or an approximate Steiner tree using an approximation, heuristic, or other means.
[0113] As shown by operation 760, apparatus 400 includes means, such as processor 402, memory 404, and / or the like, for extracting a set of resultant subject-predicate-object triplets from the Steiner tree, wherein the set of resultant subject-predicate-object triplets comprises an indication of the first graph node and an indication of the second graph node. As described in connection with operation 510, subject-predicate-object triplets may be stored as fragments of query statements, such as ‘Type N→[relation NP]→Node P” based on the example of FIG. 2. In some examples, the triplets may be stored as graph nodes or references to graph nodes in a mathematical graph, or any other representation of graph data known in the art. The subject-predicate-object triplets may be extracted based on every possible triplet found in the Steiner tree, or in some examples, post-processing may be performed to confirm that the set of triplets provides information responsive to the initial natural language query.
[0114] As shown by operation 770, apparatus 400 includes means, such as processor 402, memory 404, and / or the like, for translating the set of resultant subject-predicate-object triplets to a corresponding set of “MATCH” statements. In some examples, processor 402 may translate the triplets to statements used in various other forms of query (e.g., queries other than Cypher). In examples where Cypher is used, the processor 402 may translate the set of resultant triplets to a series of “MATCH” statements such as the statements described above in connection with FIG. 2. The “MATCH” statements (or other query fragments in the case of other query formats) may indicate each of the nodes and relations between nodes included in the Steiner tree connecting the first graph node and the second graph node.
[0115] As shown by operation 780, apparatus 400 includes means, such as processor 402, memory 404, and / or the like, for preparing a Cypher query comprising the set of “MATCH” statements (or any other format of database query, in some examples, which may comprise query fragments prepared in operation 770). For example, one or more “MATCH” statements may be combined with other statements (e.g., statements with “WHERE” and / or “RETURN”) keywords to form a full Cypher query. The Cypher query may be passed as a plain text query to subsequent operations. For example, the query may be presented to a user for manual entry in a database management system, or may be automatically used to query a knowledge graph and / or database. Automatically querying the knowledge graph with the query prepared in operation 780 may cause a response received as described in operation 790.
[0116] As shown by operation 790, apparatus 400 includes means, such as processor 402, memory 404, communications hardware 406, and / or the like, for receiving response data representing a response to the parsed query by querying the knowledge graph using the Cypher query. As described above, a text query (e.g., the Cypher query) may be automatically executed to query a database (e.g., the knowledge graph) to retrieve data which may be responsive to an original natural language query and / or a parsed query received by communications hardware 406. In some examples, the response to the query may be further format and interpreted by additional algorithms and / or machine learning models to prepare a response suitable for presentation to a user. For example, the query response may be embedded into a prompt passed to a language model or provided via an interface to a language model using retrieval augmented generation to provide factual grounding for a natural language response to be presented to a user (e.g., via RAG using LM orchestrator 630).
[0117] In some examples, the apparatus 400 may include means for receiving feedback indicating the knowledge graph query does not produce a result responsive to an initial query. For example, feedback mechanisms, which may include user feedback and / or automated (e.g., based on machine learning) feedback may provide a feedback score rating the query produced, for example, in operation 780 (e.g., a cypher query or text query). The rating may be based on the query itself or the data retrieved by executing the query to retrieve data from a corresponding knowledge graph. The rating may express the degree to which the constructed query (e.g., the Cypher query, text query) is responsive to the original query provided by a user (e.g., the natural language query. For example, as described in connection with FIG. 3, a query that includes geographical data is not responsive to the natural language query “what is the share price of ABCD?”, which relates to pricing information for a stock. A Cypher query built around geographic data is unlikely to return information relevant to the natural language query of the user.
[0118] In some embodiments, the apparatus 400 may include means for determining a new weight to apply to a selected edge of the knowledge graph based on the Steiner tree (e.g., in the instance in which feedback indicates the query is not responsive to the original natural language query. As shown in connection with FIG. 3, the “Tree B” query is determined to not be responsive to the original natural language query, so one or more weights of edges associated with tree B may be increased. The determination of which edge or edges to increase may be made algorithmically (e.g., choosing an edge that is present in tree B but not tree A, choosing an edge that is present in the Steiner tree but not in close alternatives with total weight within a small threshold of the Steiner tree), using a machine learning model, and / or using an expert human-in-the-loop to determine an edge / relationship that is suitable for having increase weight.
[0119] Once an edge (or relationship) is identified, the apparatus 400 may modify an old weight of the knowledge graph to be the new weight to produce an updated knowledge graph. The updated knowledge graph may replace the knowledge graph, or the updated knowledge graph may be stored separately as a branch or modification of the original knowledge graph (e.g., using a versioning system or the like).
[0120] Turning now to FIG. 8, example operations are shown for determining a Steiner tree comprising the first graph node and the second graph node. It will be understood that the operations described in FIG. 8 represent one example out of many possible techniques for finding a Steiner tree or approximate Steiner tree. Any method known in the art for finding the Steiner tree or approximate Steiner tree may be used in conjunction with the methods described herein. As shown by operation 810, apparatus 400 may include means, such as processor 402, memory 404, Steiner tree approximation circuitry 408, and / or the like, for constructing a first distance graph comprising the first graph node and the second graph node. The distance graph is a graph in which any two nodes from the original graph are connected by an edge whose weight is equal to the combined weight of the shortest path between the two nodes. The distance graph may be considered to be the knowledge graph moved into a metric space. In this example, the first distance graph may be computed for only the terminal vertices (e.g., the first graph node and the second graph node).
[0121] As shown by operation 820, apparatus 400 may include means, such as processor 402, memory 404, Steiner tree approximation circuitry 408, and / or the like, for determining a first minimum spanning tree (MST) of the first distance graph. The MST may be found using any MST algorithm known in the art. As described previously, the MST is the tree of least total weight that includes all nodes of the original graph (e.g., the first distance graph).
[0122] As shown by operation 830, apparatus 400 may include means, such as processor 402, memory 404, and / or the like, for constructing a first subgraph by replacing each edge of the first MST with a corresponding shortest path of the knowledge graph. Since the first MST is a MST of the distance graph, edges in the MST may represent weighted distances over the original knowledge graph. Accordingly, one may replace edges in the first MST with the corresponding paths of the original knowledge graph and thereby map the first MST back onto the original knowledge graph, producing a first subgraph of the knowledge graph. In this example, the first subgraph is in the original space of the knowledge graph, not the metric space.
[0123] As shown by operation 840, apparatus 400 may include means, such as processor 402, memory 404, and / or the like, for determining a second MST of the first subgraph. The second MST may be derived, as above, using any MST algorithm applied to the first subgraph.
[0124] As shown by operation 850, apparatus 400 may include means, such as processor 402, memory 404, and / or the like, for removing one or more edges from the second MST to produce an approximated Steiner tree, wherein the Steiner tree is the approximated Steiner tree. in particular, nodes with only a single edge that are not terminal vertices may be removed with their associated single edges.
[0125] It should be emphasized that the above-described embodiments of the present disclosure are merely possible examples of implementations set forth for a clear understanding of the principles of the disclosure. Many variations and modifications may be made to the above-described example(s) without departing substantially from the spirit and principles of the disclosure. All such modifications and variations are intended to be included herein within the scope of this disclosure and protected by the following claims.
Claims
1. A computer-implemented method comprising:receiving a knowledge graph comprising a plurality of graph nodes, wherein a set of two graph nodes and their connection are arranged as a subject-predicate-object triplet, wherein one or more of the plurality of graph nodes is associated with a respective key-value pair;receiving a natural language query comprising an indication of a set of data entries;parsing the natural language query to produce a set of filtered tokens;selecting the set of data entries from the set of filtered tokens;determining a set of graph nodes among the plurality of graph nodes that corresponds to respective data entries from the set of data entries;determining a Steiner tree comprising the set of graph nodes;extracting a set of resultant subject-predicate-object triplets from the Steiner tree, wherein the set of resultant subject-predicate-object triplets comprises an indication of each graph node from the set of graph nodes;generating, based on a first subject-predicate-object triplet from the set of resultant subject-predicate-object triplets, a match statement comprising a subject, a predicate, and an object from the first subject-predicate-object triplet;generating an additional statement based on the match statement, wherein the additional statement is a where statement or a return statement;preparing a Cypher query comprising the match statement and the additional statement;receiving response data representing a response to the natural language query by querying the knowledge graph using the Cypher query; andpreparing, by a language model, a natural language query response responsive to the natural language query, wherein the response data is provided as an input to the language model.
2. The computer-implemented method of claim 1 comprising:constructing a first distance graph comprising the set of graph nodes;determining a first minimum spanning tree (MST) of the first distance graph;constructing a first subgraph by replacing each edge of the first MST with a corresponding shortest path of the knowledge graph;determining a second MST of the first subgraph; andremoving one or more edges from the second MST to produce an approximated Steiner tree, wherein the Steiner tree is the approximated Steiner tree.
3. The computer-implemented method of claim 1, wherein each edge of the knowledge graph has a corresponding non-negative weight, wherein a sum of weights associated with the Steiner tree is a minimum total weight such that the Steiner tree comprises a first graph node of the set of two graph nodes and a second graph node of the set of two graph nodes.
4. The computer-implemented method of claim 1, comprising:determining a parsed query based on the natural language query;providing the Cypher query to a graph database; andcausing display of the response data.
5. A method comprising:receiving an indication of a first graph node and second graph node belonging to a knowledge graph, wherein the knowledge graph comprises a plurality of graph nodes, wherein a pair of graph nodes and their connecting edge are arranged as a subject predicate object triplet;determining a Steiner tree comprising the first graph node and the second graph node;determining a set of resultant subject-predicate-object triplets from the Steiner tree, wherein each resultant subject-predicate-object triplet from the set of resultant subject-predicate-object triplets corresponds to a respective edge of the Steiner tree;generating a query statement based at least in part on the set of resultant subject-predicate-object triplets;generating an additional statement based on the query statement, wherein the additional statement is a where statement or a return statement, wherein the additional statement references at least one variable of the query statement;generating, by combining the additional statement with the query statement, a knowledge graph query; andreceiving response data by querying the knowledge graph using the knowledge graph query.
6. The method of claim 5 comprising:constructing a first distance graph comprising the first graph node and the second graph node;determining a first minimum spanning tree (MST) of the first distance graph;constructing a first subgraph by replacing each edge of the first MST with a corresponding shortest path of the knowledge graph;determining a second MST of the first subgraph; andremoving one or more edges from the second MST to produce an approximated Steiner tree, wherein the Steiner tree is the approximated Steiner tree.
7. The method of claim 5, comprising:receiving a natural language query; andparsing the natural language query to produce a parsed query comprising an indication of the first graph node and an indication of the second graph node,wherein querying the knowledge graph with the knowledge graph query produces a response to the natural language query.
8. The method of claim 7, wherein the parsed query comprises a first data entry and a second data entry, the method comprising:identifying the first graph node corresponding to the first data entry and the second graph node corresponding to the second data entry.
9. The method of claim 5, comprising:providing the knowledge graph query to a graph database; andcausing display of the response data.
10. The method of claim 5, wherein each edge of the knowledge graph has a corresponding non-negative weight, wherein a sum of weights associated with the Steiner tree is a minimum total weight such that the Steiner tree comprises the first graph node and the second graph node.
11. The method of claim 10, comprising:receiving feedback indicating the knowledge graph query does not produce a result responsive to an initial query;determining a new weight to apply to a selected edge of the knowledge graph based on the Steiner tree; andmodifying an old weight of the knowledge graph to be the new weight to produce an updated knowledge graph.
12. The method of claim 5, wherein the knowledge graph query is a Cypher query, the method comprising:preparing a set of Cypher match statements corresponding to the set of resultant subject-predicate-object triplets, wherein the query statement comprises the set of cypher match statements.
13. An electronic device comprising:one or more processors; andone or more computer readable media storing processor executable instructions which, when executed using the one or more processors, cause the electronic device to perform operations comprising:receiving a knowledge graph comprising a plurality of graph nodes, wherein a pair of graph nodes and their connection are arranged as a subject-predicate-object triplet;receiving an indication of a first graph node and second graph node;determining a Steiner tree comprising the first graph node and the second graph node;determining a set of resultant subject-predicate-object triplets from the Steiner tree, wherein each resultant subject-predicate-object triplet from the set of resultant subject-predicate-object triplets corresponds to a respective edge of the Steiner tree;generating a query statement based at least in part on the set of resultant subject-predicate-object triplets;generating an additional statement based on the query statement, wherein the additional statement is a where statement or a return statement, wherein the additional statement references at least one variable of the query statement;generating, by combining the additional statement with the query statement, a knowledge graph query; andreceiving response data by querying the knowledge graph using the knowledge graph query.
14. The electronic device of claim 13, wherein the one or more computer readable media store additional processor executable instructions which, when executed using the one or more processors, cause the electronic device to perform further operations comprising:constructing a first distance graph comprising the first graph node and the second graph node;determining a first minimum spanning tree (MST) of the first distance graph;constructing a first subgraph by replacing each edge of the first MST with a corresponding shortest path of the knowledge graph;determining a second MST of the first subgraph; andremoving one or more edges from the second MST to produce an approximated Steiner tree, wherein the Steiner tree is the approximated Steiner tree.
15. The electronic device of claim 13, wherein the one or more computer readable media store additional processor executable instructions which, when executed using the one or more processors, cause the electronic device to perform further operations comprising:receiving a natural language query; andparsing the natural language query to produce a parsed query comprising an indication of the first graph node and an indication of the second graph node,wherein querying the knowledge graph with the knowledge graph query produces a response to the natural language query.
16. The electronic device of claim 15, wherein the parsed query comprises a first data entry and a second data entry, wherein the one or more computer readable media store additional processor executable instructions which, when executed using the one or more processors, cause the electronic device to perform further operations comprising:identifying the first graph node corresponding to the first data entry and the second graph node corresponding to the second data entry.
17. The electronic device of claim 13, wherein the one or more computer readable media store additional processor executable instructions which, when executed using the one or more processors, cause the electronic device to perform further operations comprising:providing the knowledge graph query to a graph database; andcausing display of the response data.
18. The electronic device of claim 13, wherein each edge of the knowledge graph has a corresponding non-negative weight, wherein a sum of weights associated with the Steiner tree is a minimum total weight such that the Steiner tree comprises the first graph node and the second graph node.
19. The electronic device of claim 18, wherein the one or more computer readable media store additional processor executable instructions which, when executed using the one or more processors, cause the electronic device to perform further operations comprising:receiving feedback indicating the knowledge graph query does not produce a result responsive to an initial query;determining a new weight to apply to a selected edge of the knowledge graph based on the Steiner tree; andmodifying an old weight of the knowledge graph to be the new weight to produce an updated knowledge graph.
20. The electronic device of claim 13, wherein the knowledge graph query is a Cypher query, wherein the one or more computer readable media store additional processor executable instructions which, when executed using the one or more processors, cause the electronic device to perform further operations comprising:preparing a set of Cypher match statements corresponding to the set of resultant subject-predicate-object triplets, wherein the query statement comprises the set of cypher match statements.
Citation Information
Patent Citations
Methods, apparatus and systems for annotation of text documents
US12014135B2
Data storage and retrieval system including a knowledge graph employing multiple subgraphs and a linking layer including multiple linking nodes, and methods, apparatus and systems for constructing and using same
US12131262B2
Systems for natural language processing of sentence based queries
US20100005081A1
Method and device for parsing question in knowledge base
US20170199928A1
Multi-dimensional knowledge index and application thereof
US20200012733A1
