Sequence prediction method and device based on large language model and time knowledge graph
By constructing a temporal knowledge graph and using temporal random walks and a large language model to generate prompt templates, the problem of insufficient generalization ability of the temporal knowledge graph in complex scenarios is solved, and more accurate prediction of future events is achieved.
Patent Information
- Application Number
- CN202510704210.7
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2025-05-28
- Publication Date
- 2025-09-19
AI Technical Summary
Existing temporal knowledge graph methods lack cross-domain and cross-time generalization capabilities when processing complex temporal relationship data. Especially in scenarios such as property insurance and intelligent diagnosis and treatment, traditional methods ignore the semantic information of events, resulting in insufficient prediction performance.
By constructing a temporal knowledge graph and applying the transition distribution formula of temporal random walk to generate paths with time information, the paths are analyzed to obtain temporal patterns and converted into temporal logic rules, and combined with a large language model to generate prompt templates to predict future events.
The cross-domain and cross-time generalization capabilities of the temporal knowledge graph are improved, and the generated results are more accurate and suitable for prediction tasks in different data sets and fields.
Smart Images

Figure CN120670600A_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to the field of knowledge graph technology, and in particular to a sequence prediction method, device, equipment and medium based on a large language model and a temporal knowledge graph. Background Art
[0002] A temporal knowledge graph (tKG) is a directed graph containing multiple relationships, with edges between nodes carrying timestamps, representing world knowledge that changes over time. The main goal of the tKG task is to predict future events based on given past historical events. For example, when predicting a certain entity relationship at a given point in time, traditional methods usually embed time quadruple into the latent space through an embedding model, or make predictions by mining temporal logic rules in the graph structure. However, this method has significant limitations when processing complex temporal relationship data. For example, in property insurance scenarios such as online auto insurance, its temporal knowledge graph includes multiple nodes such as the insurance application node, the seat allocation and docking personnel node, the interim report submission node, and the review node. For example, in intelligent diagnosis and treatment or remote consultation application scenarios, it includes nodes such as patient onset, patient treatment, and patient recovery. Treatment may include multiple treatments, and each treatment can be further subdivided according to medication or symptoms until recovery. In the above scenarios, the temporal knowledge graphs to be dealt with are often graph structures with complex data scales. Traditional methods often ignore the semantic information of events in tKG, only focus on implicit structural representation, and lack the ability to generalize across domains and time. Summary of the Invention
[0003] The present invention provides a sequence prediction method, device, computer equipment and medium based on a large language model and a temporal knowledge graph to solve the technical problem that the existing temporal knowledge graph method exhibits insufficient performance when faced with complex temporal relationship data, and to improve the cross-domain and cross-time generalization capabilities of the temporal knowledge graph.
[0004] First, an event prediction method based on a temporal knowledge graph and a large language model is provided, including:
[0005] Obtain interrelated historical events that occurred within a preset time period, and create a time knowledge graph based on the timestamp of each historical event and the correlation between the historical events. The time knowledge graph is a directed graph, the nodes of the directed graph are used to represent the historical events, and the edges of the directed graph are used to represent the relationship between adjacent historical events and the time intervals between their occurrence;
[0006] Applying the transition distribution formula of time random walk to walk in the directed graph to generate a path with time information;
[0007] Analyze the paths with time information to obtain time patterns with an occurrence frequency greater than or equal to a preset time threshold, and convert the time patterns with an occurrence frequency greater than or equal to the preset time threshold into time logic rules and store them to obtain a time logic rule library;
[0008] According to the current event, a time logic rule is selected from the time logic rule library to generate a large language model to generate a prompt template, and the prompt template generated by the large language model is used to predict possible events in the future.
[0009] In a second aspect, an event prediction device based on a temporal knowledge graph and a large language model is provided, comprising:
[0010] A graph creation module is used to obtain interrelated historical events that occurred within a preset time period, and create a time knowledge graph based on the timestamp of each historical event and the correlation between the historical events. The time knowledge graph is a directed graph, the nodes of the directed graph are used to represent the historical events, and the edges of the directed graph are used to represent the relationship between adjacent historical events and the time intervals between their occurrence;
[0011] A path generation module, configured to apply a transition distribution formula of a temporal random walk to walk in the directed graph and generate a path with time information;
[0012] a rule generation module configured to analyze the paths with time information to obtain time patterns with an occurrence frequency greater than or equal to a preset time threshold, convert the time patterns with an occurrence frequency greater than or equal to the preset time threshold into time logic rules, store the rules, and obtain a time logic rule library;
[0013] The event prediction module is used to select time logic rules from the time logic rule library according to the current event to generate a large language model to generate a prompt template, and predict possible future events based on the prompt template generated by the large language model.
[0014] In a third aspect, a computer device is provided, comprising a memory, a processor, and a computer program stored in the memory and executable on the processor. When the processor executes the computer program, the steps of the above-mentioned event prediction method based on the temporal knowledge graph and the large language model are implemented.
[0015] In a fourth aspect, a computer-readable storage medium is provided, which stores a computer program. When the computer program is executed by a processor, it implements the steps of the above-mentioned event prediction method based on time knowledge graph and large language model.
[0016] In the scheme implemented by the above-mentioned event prediction method, device, computer equipment and storage medium based on time knowledge graph and large language model, a time knowledge graph is created based on the timestamp of each historical event and the correlation between historical events; the transition distribution formula of time random walk is applied to walk in the directed graph of the time knowledge graph to generate a path with time information; the path with time information is analyzed to obtain a time pattern with an occurrence frequency greater than or equal to a preset time threshold, and the time pattern with an occurrence frequency greater than or equal to the preset time threshold is converted into a time logic rule and stored to obtain a time logic rule library; according to the current event, a time logic rule is selected from the time logic rule library to generate a large language model to generate a prompt template, and the prompt template generated by the large language model is used to predict possible future events. In the present invention, prediction is not performed directly through the constructed time knowledge graph. Instead, the time logic rules are first extracted from the time knowledge graph through the transition distribution formula of time random walk, and a time logic rule library is constructed. Then, even when facing different data sets or different fields, the time logic rules are equally applicable. According to the current event, the time logic rules are selected from the time logic rule library to generate a large language model to generate a prompt template, and the prompt template generated by the large language model is used to predict possible future events. The prompt template generated by the large language model includes not only the semantic information of the current event, but also the structural information of the extracted time logic rules, thereby improving its generalization ability across fields and time, and the results obtained are more accurate. BRIEF DESCRIPTION OF THE DRAWINGS
[0017] In order to more clearly illustrate the technical solutions of the embodiments of the present invention, the following briefly introduces the drawings required for use in the description of the embodiments of the present invention. Obviously, the drawings described below are only some embodiments of the present invention. For ordinary technicians in this field, other drawings can be obtained based on these drawings without paying any creative labor.
[0018] Figure 1 This is a flow chart of an event prediction method based on a temporal knowledge graph and a large language model in one embodiment of the present invention;
[0019] Figure 2 yes Figure 1 A schematic flow chart of a specific implementation of step S20;
[0020] Figure 3 yes Figure 1 Another specific implementation flow diagram of step S20;
[0021] Figure 4 is a flow chart of an event prediction method based on a temporal knowledge graph and a large language model in another embodiment of the present invention;
[0022] Figure 5 yes Figure 1 A schematic flow chart of a specific implementation of step S40;
[0023] Figure 6 yes Figure 1 Another specific implementation flow diagram of step S40;
[0024] Figure 7 1 is a schematic diagram of the structure of an event prediction device based on a temporal knowledge graph and a large language model in one embodiment of the present invention;
[0025] Figure 8 It is a structural diagram of a computer device in one embodiment of the present invention. DETAILED DESCRIPTION
[0026] The following will clearly and completely describe the technical solutions in the embodiments of the present invention in conjunction with the accompanying drawings. Obviously, the described embodiments are only part of the embodiments of the present invention, not all of them. All other embodiments obtained by ordinary technicians in this field based on the embodiments of the present invention without making any creative efforts shall fall within the scope of protection of the present invention.
[0027] The event prediction method based on the time knowledge graph and the large language model involved in the embodiments of the present application is mainly applied to computer devices. The event prediction device based on the time knowledge graph and the large language model can be a PC, a portable computer, a mobile terminal, or other device with display and processing functions.
[0028] The following describes some embodiments of the present application in detail with reference to the accompanying drawings. In the absence of conflict, the following embodiments and features therein may be combined with each other.
[0029] Reference Figure 1 , Figure 1 A flowchart of an event prediction method based on a temporal knowledge graph and a large language model provided in this application.
[0030] like Figure 1 As shown, an embodiment of the present application provides an event prediction method based on a time knowledge graph and a large language model. The event prediction method based on a time knowledge graph and a large language model includes steps S10 to S40.
[0031] In this embodiment, the event prediction method based on the time knowledge graph and the large language model includes the following steps:
[0032] Step S10: Obtain interrelated historical events that occurred within a preset time period, and create a time knowledge graph based on the timestamp of each historical event and the correlation between the historical events. The time knowledge graph is a directed graph, and the nodes of the directed graph are used to represent the historical events, and the edges of the directed graph are used to represent the relationship between adjacent historical events and the time intervals between their occurrence.
[0033] Among them, the temporal knowledge graph is an extension of the traditional knowledge graph. It introduces the time dimension based on the entity-relationship triple (head entity, relationship, tail entity), forming a four-tuple: (head entity, relationship, tail entity, time) or a five-tuple (if the event has a time range): (head entity, relationship, tail entity, start time, end time). It can be used to record the dynamic evolution of knowledge over time, support the tracing of historical events and the reasoning of future trends.
[0034] Among them, historical events can be events that have already occurred. The time knowledge graph in this application can be used, for example, for intelligent diagnosis and treatment or remote consultation, and historical events can be used to record the time process of the patient from diagnosis to medication to recovery. For example, the time when the patient first became ill, the time when the patient first received treatment, the symptoms and medications the patient had, the time when the patient returned for a visit, the symptoms and medications the patient had, and the time when the patient recovered can constitute a series of historical events, and there is a causal relationship between these historical events. Historical events can be divided into several categories: onset, treatment, and recovery, among which treatment can be divided into the first treatment, the second treatment...the Nth treatment, and each treatment can be further subdivided according to medication or symptoms until recovery. The time corresponding to each historical event is its timestamp, and the relationship can be causal. A directed edge points from the historical event corresponding to the cause to the historical event corresponding to the effect, and the length of the directed edge can be the time span of the two historical events.
[0035] It should be noted that the examples here are just smart diagnosis and treatment or remote consultation, and the application scenarios are not limited to the above specific embodiments. Of course, in addition to causal relationships, the correlation can also include temporal relationships, dependency relationships, concurrency relationships, periodic relationships, etc. The specific correlation is selected according to the application scenario.
[0036] Step S20: applying the transition distribution formula of temporal random walk to walk in the directed graph to generate a path with time information.
[0037] A time-random walk (TWR) is a stochastic process model that describes the evolution of time series data over time. Its core concept is that the future state depends only on the current state, and the increments at each step are independent of each other. The transition distribution formula for a TWR describes the probability of state transitions between adjacent time points.
[0038] Among them, such as Figure 2 As shown, in step S20, that is, applying the transition distribution formula of the time random walk to walk in the directed graph to generate a path with time information, the following steps are included:
[0039] Step S21: randomly selecting a node from the directed graph as the initial walk starting point;
[0040] Step S22: taking the initial wandering starting point as the current wandering node;
[0041] Step S23: traversing and calculating the transition probabilities of all next wandering nodes of the current wandering node according to the transition distribution formula of time random walk;
[0042] In a specific embodiment provided by the present application, before applying the transition distribution formula of the temporal random walk to walk in the directed graph and generating a path with time information, the method further includes:
[0043] Determining a current wandering node in the directed graph;
[0044] Determine all next wandering nodes of the current wandering node;
[0045] Select one of the next wandering nodes from all the next wandering nodes;
[0046] A transition distribution formula of the temporal random walk is determined according to one of the currently selected next walk nodes and other next walk nodes except the currently selected one of the next walk nodes.
[0047] Specifically, the transition distribution formula of the temporal random walk is:
[0048]
[0049] Among them, e and t are one of the currently selected next wandering nodes and timestamps, respectively, and u is one of the currently selected next wandering nodes and the historical event corresponding to the timestamp. and t u is any next wandering node and timestamp.
[0050] Step S24: Determine whether the preset path length has been reached or whether the path cannot be continued;
[0051] If not, proceed to step S25;
[0052] If yes, proceed to step S26;
[0053] Step S25: determining a target wandering node according to the transition probability of the next wandering node, taking the target wandering node as the current wandering node, and executing the step of traversing and calculating the transition probabilities of all next wandering nodes of the current wandering node according to the transition distribution formula of the time random walk;
[0054] Step S26: Generate a path with time information.
[0055] The initial walk starting point can be a node with an in-degree of 0 or a node with the largest out-degree. The node with an in-degree of 0 is usually used as the initial walk starting point because no other node directly points to it through an edge. The node with the largest out-degree can generate the most paths because it has the largest number of edges pointing to other nodes. Starting from the node with the largest out-degree can prevent the path from being interrupted before reaching the node with the largest out-degree due to reaching the preset path length, thereby resulting in too few paths with time information.
[0056] The preset path length may include 3 nodes, 5 nodes, or 7 nodes, depending on the actual application scenario and is not limited here. Specifically, the target wandering node is determined based on the transition probability of the next wandering node, and the next wandering node with a transition probability greater than or equal to a preset threshold may be used as the target wandering node.
[0057] As can be seen, the above solution provides a method for generating paths with time information. This path generation process utilizes a temporal random walk transition distribution formula. This formula ensures that the retrieved historical facts are closer in time to the current query, making the generative prediction more consistent with temporal logic. Furthermore, this solution also sets a preset path length to prevent the generated path from being too long, introducing excessive randomness and resulting in inaccurate temporal logic rules. This improves the accuracy of temporal logic rules.
[0058] Furthermore, if Figure 3 As shown, before executing step S23, that is, before traversing and calculating the transfer probabilities of all next wandering nodes of the current wandering node according to the transition distribution formula of the time random walk, the method further includes the following steps:
[0059] Step S27: Obtain the transition distribution formula of the temporal random walk, which is:
[0060]
[0061] Among them, e and t are one of the currently selected next wandering nodes and timestamps, respectively, and u is one of the currently selected next wandering nodes and the historical event corresponding to the timestamp. and tu is any next wandering node and timestamp.
[0062] Step S28: updating the transition distribution formula of the time random walk according to the time sensitivity coefficient and the typical time interval to obtain a new transition distribution formula of the time random walk. The new transition distribution formula of the time random walk is:
[0063]
[0064] The time sensitivity coefficient α is used to control the sensitivity of the transition distribution formula of the temporal random walk to time, and the typical time interval Δ is used to characterize the expected reasonable time span between two adjacent historical events.
[0065] It can be seen that in this scheme, the transition distribution formula of the above-mentioned time random walk is further revised by the time sensitivity coefficient α and the typical time interval Δ, and the exponential decay function is used to A penalty is imposed on edges whose time interval deviates from the expected value Δ. The denominator sums the weights of all candidate edges at the current node to ensure that the total transition probability is 1. Therefore, the expected results can be corrected by further adjusting the time sensitivity coefficient α and the typical time interval Δ to make them more consistent with the actual results, thereby improving the accuracy of the results.
[0066] Step S30: Analyze the path with time information to obtain a time pattern with an occurrence frequency greater than or equal to a preset time threshold, and convert the time pattern with an occurrence frequency greater than or equal to the preset time threshold into a time logic rule and store it to obtain a time logic rule library.
[0067] Temporal patterns refer to recurring, structured patterns with specific temporal regularities in time series data, describing the dynamic characteristics of events over time. In temporal knowledge graphs (tKGs) and time series analysis, temporal patterns help reveal dynamic characteristics such as sequentiality, periodicity, and dependencies between events, forming the foundation for time series reasoning and prediction.
[0068] Furthermore, if Figure 4 As shown, each of the time logic rules includes a premise, a conclusion, and a constraint time. Before executing step S30, that is, converting the time pattern with an occurrence frequency greater than or equal to a preset time threshold into a time logic rule and storing it, the method further includes the following steps:
[0069] Step S50: Filter out time logic rules whose constraint time is greater than or equal to the maximum allowed time span, and filter out time logic rules whose confidence is less than or equal to a preset confidence, wherein the confidence is determined based on the ratio of the number of simultaneous occurrences of time logic rules with the same premise and conclusion to the number of separate occurrences of time logic rules with the same premise.
[0070] It can be seen that in the present invention, the time logic rules are further screened by the maximum time span and confidence level, the credibility of the rules is evaluated, low-quality rules are filtered out, and the redundancy of the time logic rule base is prevented.
[0071] Step S40: selecting a temporal logic rule from the temporal logic rule library according to the current event to generate a large language model to generate a prompt template, and predicting possible future events based on the prompt template generated by the large language model.
[0072] Among them, such as Figure 5 As shown, executing step S40, i.e. selecting a time logic rule from the time logic rule library according to the current event and the evolution time of the current event to generate a large language model to generate a prompt template, includes the following steps:
[0073] Step S411: extracting keywords from the current event as search index words and searching the time logic rule library to obtain all time logic rules containing the keywords;
[0074] Step S421: taking all the time logic rules containing the keywords as rule description information and the current event as context information, a large language model is generated to generate a prompt template.
[0075] Furthermore, if Figure 6 As shown, executing step S40, i.e. selecting a time logic rule from the time logic rule library according to the current event and the evolution time of the current event to generate a large language model to generate a prompt template, includes the following steps:
[0076] Step S412: extracting keywords from the current event as search index words and searching the time logic rule library to obtain all time logic rules containing the keywords;
[0077] Step S422: Expanding the evolution time of the current event to obtain an evolution time interval, and screening all time logic rules containing the keyword according to the evolution time interval to obtain a target time logic rule;
[0078] Step S423: Using the target time logic rule as rule description information and the current event as context information, a large language model is generated to generate a prompt template.
[0079] A large language model typically generates a prompt template consisting of four parts: 1. Instructions, which clarify the task requirements, for example: "Predict the future events of the subject based on the following historical rules:"; 2. Rule descriptions, which convert formal rules into natural language, for example: "Rule 1: An employee may be promoted one year after joining the company," "Rule 2: An employee may leave the company three years after joining the company"; 3. Event context, which inserts current event information, for example: "It is known that Zhang San joined Company A in 2023"; and 4. Generation instructions, which specify the output format and constraints, for example: "Please list the possible events that may occur to Zhang San between 2023 and 2025 in chronological order, and explain the rules used."
[0080] It can be seen that in the above scheme, by taking the target time logic rule as the rule description information and the current event as the context information, a method for generating a prompt template using a large language model is provided, so that the prompt template generated by the large language model not only includes the semantic information of the current event, but also includes the structural information of the extracted time logic rule, thereby improving its generalization ability across domains and time, and the results obtained are more accurate.
[0081] It can be seen that in the above scheme, prediction is not made directly through the constructed time knowledge graph. Instead, the time logic rules are first extracted from the time knowledge graph through the transition distribution formula of time random walk, and a time logic rule library is constructed. Then, even when facing different data sets or different fields, the time logic rules are equally applicable; the time logic rules are selected from the time logic rule library according to the current event to generate a large language model to generate a prompt template, and the prompt template generated by the large language model is used to predict possible future events. The prompt template generated by the large language model includes not only the semantic information of the current event, but also the structural information of the extracted time logic rules, thereby improving its generalization ability across fields and time, and the results obtained are more accurate.
[0082] It should be understood that the size of the serial numbers of the steps in the above embodiments does not mean the order of execution. The execution order of each process should be determined by its function and internal logic, and should not constitute any limitation on the implementation process of the embodiments of the present invention.
[0083] In one embodiment, an event prediction device based on a time knowledge graph and a large language model is provided. The event prediction device based on a time knowledge graph and a large language model corresponds one-to-one to the event prediction processing method based on a time knowledge graph and a large language model in the above embodiment. Figure 7 As shown, the event prediction device based on the time knowledge graph and the large language model includes a graph creation module 101, a path generation module 102, a rule generation module 103 and an event prediction module 104. The functional modules are described in detail as follows:
[0084] A graph creation module 101 is configured to obtain interrelated historical events that occurred within a preset time period and create a time knowledge graph based on the timestamp of each historical event and the correlation between the historical events. The time knowledge graph is a directed graph, wherein the nodes of the directed graph are used to represent the historical events, and the edges of the directed graph are used to represent the relationship between adjacent historical events and the time intervals between their occurrences.
[0085] A path generation module 102 is configured to apply a temporal random walk transition distribution formula to walk in the directed graph to generate a path with time information;
[0086] A rule generation module 103 is configured to analyze the paths with time information to obtain time patterns with an occurrence frequency greater than or equal to a preset time threshold, convert the time patterns with an occurrence frequency greater than or equal to the preset time threshold into time logic rules, store the rules, and obtain a time logic rule library;
[0087] The event prediction module 104 is used to select a time logic rule from the time logic rule library according to the current event to generate a large language model to generate a prompt template, and predict possible future events based on the prompt template generated by the large language model.
[0088] In one embodiment, in applying the temporal random walk transition distribution formula to walk in the directed graph to generate a path with time information, the path generation module 102 is specifically configured to:
[0089] Randomly select a node from the directed graph as the initial walk starting point;
[0090] Taking the initial walk starting point as the current walk node, and traversing and calculating the transition probabilities of all next walk nodes of the current walk node according to the transition distribution formula of time random walk;
[0091] Determine the target wandering node according to the transition probability of the next wandering node, use the target wandering node as the current wandering node, and perform the step of traversing and calculating the transition probability of all next wandering nodes of the current wandering node according to the transition distribution formula of the time random walk;
[0092] When the preset path length is reached or it is impossible to continue walking, a path with time information is generated.
[0093] In one embodiment, before applying the transition distribution formula of the temporal random walk to walk in the directed graph and generating a path with time information, the path generation module 102 is further configured to:
[0094] Determining a current wandering node in the directed graph;
[0095] Determine all next wandering nodes of the current wandering node;
[0096] Select one of the next wandering nodes from all the next wandering nodes;
[0097] A transition distribution formula of the temporal random walk is determined according to one of the currently selected next walk nodes and other next walk nodes except the currently selected one of the next walk nodes.
[0098] In one embodiment, the path generation module 102 is further configured to:
[0099] The transition distribution formula of the time random walk is updated according to the time sensitivity coefficient and the typical time interval to obtain a new transition distribution formula of the time random walk.
[0100] In one embodiment, each of the temporal logic rules includes a precondition, a conclusion, and a constraint time. Before converting the time pattern whose occurrence frequency is greater than or equal to the preset time threshold into a temporal logic rule and storing the result, the apparatus further includes:
[0101] The rule filtering module 105 is used to filter out time logic rules whose constraint time is greater than or equal to the maximum allowed time span, and to filter out time logic rules whose confidence is less than or equal to a preset confidence, wherein the confidence is determined based on the ratio of the number of simultaneous occurrences of time logic rules with the same premise and conclusion to the number of separate occurrences of time logic rules with the same premise.
[0102] In one embodiment, in the aspect of selecting a temporal logic rule from the temporal logic rule library based on the current event and the evolution time of the current event to generate a large language model and generate a prompt template, the event prediction module 104 is specifically configured to:
[0103] Extract keywords from the current event as search index words and search the time logic rule library to obtain all time logic rules containing the keywords;
[0104] All time logic rules containing the keywords are used as rule description information, and the current event is used as context information to generate a large language model generation prompt template.
[0105] In one embodiment, the event prediction module 104 is further configured to:
[0106] Expanding the evolution time of the current event to obtain an evolution time interval, and screening all time logic rules containing the keyword according to the evolution time interval to obtain a target time logic rule;
[0107] The target time logic rule is used as rule description information.
[0108] The present invention provides an event prediction device based on a temporal knowledge graph and a large language model. The device does not make predictions directly through the constructed temporal knowledge graph, but first extracts temporal logic rules from the temporal knowledge graph through the transition distribution formula of temporal random walk and constructs a temporal logic rule library. Then, even when facing different data sets or different fields, the temporal logic rules are equally applicable. The device selects temporal logic rules from the temporal logic rule library according to the current event to generate a large language model prompt template, and predicts possible future events based on the prompt template generated by the large language model. The prompt template generated by the large language model includes not only the semantic information of the current event, but also the structural information of the extracted temporal logic rules, thereby improving its generalization ability across fields and time, and the obtained results are more accurate.
[0109] For the specific limitations of the event prediction device based on the time knowledge graph and the large language model, please refer to the limitations of the event prediction method based on the time knowledge graph and the large language model above, which will not be repeated here. The various modules in the above-mentioned event prediction device based on the time knowledge graph and the large language model can be implemented in whole or in part by software, hardware and a combination thereof. The above-mentioned modules can be embedded in or independent of the processor in the computer device in the form of hardware, or can be stored in the memory of the computer device in the form of software, so that the processor can call and execute the operations corresponding to the above modules.
[0110] In one embodiment, a computer device is provided. The computer device may be a server, and its internal structure diagram may be as follows: Figure 8 As shown. The computer device includes a processor, a memory, a network interface and a database connected via a system bus. The processor of the computer device is used to provide computing and control capabilities. The memory of the computer device includes a non-volatile and / or volatile storage medium and an internal memory. The non-volatile storage medium stores an operating system, a computer program and a database. The internal memory provides an environment for the operation of the operating system and the computer program in the non-volatile storage medium. The network interface of the computer device is used to communicate with an external client via a network connection. When the computer program is executed by the processor, it implements the functions or steps of an event prediction method based on a time knowledge graph and a large language model.
[0111] In one embodiment, a computer device is provided, including a memory, a processor, and a computer program stored in the memory and executable on the processor. When the processor executes the computer program, the following steps are performed:
[0112] Obtain interrelated historical events that occurred within a preset time period, and create a time knowledge graph based on the timestamp of each historical event and the correlation between the historical events. The time knowledge graph is a directed graph, the nodes of the directed graph are used to represent the historical events, and the edges of the directed graph are used to represent the relationship between adjacent historical events and the time intervals between their occurrence;
[0113] Applying the transition distribution formula of time random walk to walk in the directed graph to generate a path with time information;
[0114] Analyze the paths with time information to obtain time patterns with an occurrence frequency greater than or equal to a preset time threshold, and convert the time patterns with an occurrence frequency greater than or equal to the preset time threshold into time logic rules and store them to obtain a time logic rule library;
[0115] According to the current event, a time logic rule is selected from the time logic rule library to generate a large language model to generate a prompt template, and the prompt template generated by the large language model is used to predict possible events in the future.
[0116] In one embodiment, a computer-readable storage medium is provided, on which a computer program is stored. When the computer program is executed by a processor, the following steps are implemented:
[0117] Obtain interrelated historical events that occurred within a preset time period, and create a time knowledge graph based on the timestamp of each historical event and the correlation between the historical events. The time knowledge graph is a directed graph, the nodes of the directed graph are used to represent the historical events, and the edges of the directed graph are used to represent the relationship between adjacent historical events and the time intervals between their occurrence;
[0118] Applying the transition distribution formula of time random walk to walk in the directed graph to generate a path with time information;
[0119] Analyze the paths with time information to obtain time patterns with an occurrence frequency greater than or equal to a preset time threshold, and convert the time patterns with an occurrence frequency greater than or equal to the preset time threshold into time logic rules and store them to obtain a time logic rule library;
[0120] According to the current event, a time logic rule is selected from the time logic rule library to generate a large language model to generate a prompt template, and the prompt template generated by the large language model is used to predict possible events in the future.
[0121] It should be noted that the above functions or steps that can be implemented by the computer-readable storage medium or computer device can refer to the relevant description in the aforementioned method embodiment. To avoid repetition, they will not be described one by one here.
[0122] Those skilled in the art will appreciate that all or part of the processes in the above-mentioned embodiments can be implemented by instructing the relevant hardware through a computer program. The computer program can be stored in a non-volatile computer-readable storage medium. When the computer program is executed, it can include the processes of the embodiments of the above-mentioned methods. Among them, any reference to memory, storage, database or other media used in the embodiments provided in this application can include non-volatile and / or volatile memory. Non-volatile memory can include read-only memory (ROM), programmable ROM (PROM), electrically programmable ROM (EPROM), electrically erasable programmable ROM (EEPROM) or flash memory. Volatile memory can include random access memory (RAM) or external cache memory. By way of illustration and not limitation, RAM is available in various forms, such as static RAM (SRAM), dynamic RAM (DRAM), synchronous DRAM (SDRAM), double data rate SDRAM (DDRSDRAM), enhanced SDRAM (ESDRAM), synchronous link (Synchlink) DRAM (SLDRAM), memory bus (Rambus) direct RAM (RDRAM), direct memory bus dynamic RAM (DRDRAM), and memory bus dynamic RAM (RDRAM).
[0123] Those skilled in the art will clearly understand that for the sake of convenience and brevity of description, only the division of the above-mentioned functional units and modules is used as an example. In actual applications, the above-mentioned functions can be distributed and completed by different functional units and modules as needed, that is, the internal structure of the device can be divided into different functional units or modules to complete all or part of the functions described above.
[0124] The embodiments described above are only used to illustrate the technical solutions of the present invention, rather than to limit the same. Although the present invention has been described in detail with reference to the aforementioned embodiments, those skilled in the art should understand that they can still modify the technical solutions described in the aforementioned embodiments, or make equivalent replacements for some of the technical features therein. These modifications or replacements do not deviate the essence of the corresponding technical solutions from the spirit and scope of the technical solutions of the various embodiments of the present invention, and should all be included in the scope of protection of the present invention.
Claims
1. An event prediction method based on temporal knowledge graph and large language model, characterized in that: include: Obtain interrelated historical events that occurred within a preset time period, and create a time knowledge graph based on the timestamp of each historical event and the correlation between the historical events. The time knowledge graph is a directed graph, the nodes of the directed graph are used to represent the historical events, and the edges of the directed graph are used to represent the relationship between adjacent historical events and the time intervals between their occurrence; Applying the transition distribution formula of time random walk to walk in the directed graph to generate a path with time information; Analyze the paths with time information to obtain time patterns with an occurrence frequency greater than or equal to a preset time threshold, and convert the time patterns with an occurrence frequency greater than or equal to the preset time threshold into time logic rules and store them to obtain a time logic rule library; According to the current event, a time logic rule is selected from the time logic rule library to generate a large language model to generate a prompt template, and the prompt template generated by the large language model is used to predict possible events in the future.
2. The event prediction method based on a temporal knowledge graph and a large language model according to claim 1, characterized in that: The transition distribution formula of the temporal random walk is applied to walk in the directed graph to generate a path with time information, including: Randomly select a node from the directed graph as the initial walk starting point; Taking the initial walk starting point as the current walk node, and traversing and calculating the transition probabilities of all next walk nodes of the current walk node according to the transition distribution formula of time random walk; Determine the target wandering node according to the transition probability of the next wandering node, use the target wandering node as the current wandering node, and perform the step of traversing and calculating the transition probability of all next wandering nodes of the current wandering node according to the transition distribution formula of the time random walk; When the preset path length is reached or it is impossible to continue walking, a path with time information is generated.
3. The event prediction method based on time knowledge graph and large language model according to claim 2, characterized in that: Before applying the transition distribution formula of the temporal random walk to walk in the directed graph to generate a path with time information, the method further includes: Determine a current wandering node and all next wandering nodes of the current wandering node in the directed graph; A transition distribution formula of the temporal random walk is determined according to one of the next wandering nodes currently selected among all the next wandering nodes and other next wandering nodes except the one of the next wandering nodes currently selected.
4. The event prediction method based on a temporal knowledge graph and a large language model according to claim 3, characterized in that: The method further comprises: The transition distribution formula of the time random walk is updated according to the time sensitivity coefficient and the typical time interval to obtain a new transition distribution formula of the time random walk.
5. The event prediction method based on time knowledge graph and large language model according to claim 1, characterized in that: Each of the time logic rules includes a premise, a conclusion, and a constraint time. Before converting the time pattern whose occurrence frequency is greater than or equal to the preset time threshold into a time logic rule and storing the result, the method further includes: Filter out time logic rules whose constraint time is greater than or equal to the maximum allowed time span, and filter out time logic rules whose confidence is less than or equal to a preset confidence, wherein the confidence is determined based on the ratio of the number of simultaneous occurrences of time logic rules with the same premise and conclusion to the number of separate occurrences of time logic rules with the same premise.
6. The event prediction method based on time knowledge graph and large language model according to claim 1, characterized in that: The step of selecting a time logic rule from the time logic rule library according to the current event and the evolution time of the current event to generate a large language model and generate a prompt template includes: Extract keywords from the current event as search index words and search the time logic rule library to obtain all time logic rules containing the keywords; All time logic rules containing the keywords are used as rule description information, and the current event is used as context information to generate a large language model generation prompt template.
7. The event prediction method based on time knowledge graph and large language model according to claim 1, characterized in that: The step of selecting a time logic rule from the time logic rule library according to the current event and the evolution time of the current event to generate a large language model and generate a prompt template includes: Extract keywords from the current event as search index words and search the time logic rule library to obtain all time logic rules containing the keywords; Expanding the evolution time of the current event to obtain an evolution time interval, and screening all time logic rules containing the keyword according to the evolution time interval to obtain a target time logic rule; The target time logic rule is used as rule description information, and the current event is used as context information to generate a large language model to generate a prompt template.
8. An event prediction device based on a temporal knowledge graph and a large language model, characterized in that: include: A graph creation module is used to obtain interrelated historical events that occurred within a preset time period, and create a time knowledge graph based on the timestamp of each historical event and the correlation between the historical events. The time knowledge graph is a directed graph, the nodes of the directed graph are used to represent the historical events, and the edges of the directed graph are used to represent the relationship between adjacent historical events and the time intervals between their occurrence; A path generation module, configured to apply a transition distribution formula of a temporal random walk to walk in the directed graph and generate a path with time information; a rule generation module configured to analyze the paths with time information to obtain time patterns with an occurrence frequency greater than or equal to a preset time threshold, convert the time patterns with an occurrence frequency greater than or equal to the preset time threshold into time logic rules, store the rules, and obtain a time logic rule library; The event prediction module is used to select time logic rules from the time logic rule library according to the current event to generate a large language model to generate a prompt template, and predict possible future events based on the prompt template generated by the large language model.
9. A computer device comprising a memory, a processor, and a computer program stored in the memory and executable on the processor, wherein: When the processor executes the computer program, the steps of the event prediction method based on the time knowledge graph and the large language model are implemented as described in any one of claims 1 to 7.
10. A computer-readable storage medium storing a computer program, characterized in that: When the computer program is executed by a processor, the steps of the event prediction method based on a temporal knowledge graph and a large language model are implemented as described in any one of claims 1 to 7.
Citation Information
Patent Citations
Time sequence knowledge graph reasoning model construction method and reasoning method
CN119849630A
Time sequence knowledge graph prediction method based on logic context learning
CN119962677A
Predicting follow-on requests to a natural language request received by a natural language processing system
US11017764B1
Method for temporal knowledge graph reasoning based on distributed attention
US20230401466A1
Hotspot prediction method and apparatus based on random walk model, and computer device
WO2021139102A1