Link prediction method, electronic equipment and computer readable storage medium
By using machine learning models based on time-series knowledge graphs in link prediction, the problem of poor link prediction results caused by static knowledge graphs is solved, and more accurate and timely link prediction is achieved.
Patent Information
- Application Number
- CN202411436663.8
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-10-14
- Publication Date
- 2025-03-25
AI Technical Summary
When conducting link prediction, the prior art is based on a static knowledge graph, resulting in poor prediction results.
A machine learning model based on a timing knowledge graph is used for link prediction, which includes an encoded part and a decoded part, and predicts by obtaining the timing coded vector of an entity object.
By introducing time information, a denser timing knowledge graph is built, which improves the accuracy and timeliness of link prediction, and solves the problem of poor prediction results caused by static knowledge graphs.
Smart Images

Figure CN119691295A_ABST
Abstract
Description
Technical Field
[0001] The present application belongs to the field of computers, and specifically relates to a link prediction method, an electronic device, and a computer-readable storage medium. Background Art
[0002] Knowledge Graph (KG), as an emerging type of auxiliary information, can provide a potential source of auxiliary information for link prediction and has the potential to be applied in many link prediction scenarios, such as movie recommendation, news recommendation, product recommendation, or scenic spot recommendation.
[0003] At present, in the process of link prediction, related technologies usually perform link prediction based on static knowledge graphs, which leads to the problem of poor link prediction results. Summary of the invention
[0004] The embodiments of the present application provide a link prediction method, an electronic device, and a computer-readable storage medium, which can solve the problem of poor link prediction results in related technologies.
[0005] In a first aspect, an embodiment of the present application provides a link prediction method, comprising: Obtaining a first entity object for link prediction; Inputting the first entity object into a prediction model to perform link prediction processing to obtain a link prediction result; Among them, the prediction model is a machine learning model obtained based on the temporal knowledge graph, and includes an encoding part and a decoding part. During the link prediction processing, the encoding part is used to obtain the first temporal coding vector of the first entity object, and the decoding part is used to obtain the link prediction result based on the first temporal coding vector.
[0006] In a second aspect, an embodiment of the present application provides an electronic device, which includes a processor and a memory, wherein the memory stores programs or instructions that can be run on the processor, and when the program or instructions are executed by the processor, the steps of the method described in the first aspect are implemented.
[0007] In a third aspect, an embodiment of the present application provides a computer-readable storage medium, on which a program or instruction is stored, and when the program or instruction is executed, the steps of the method described in the first aspect are implemented.
[0008] At least one of the above technical solutions provided in the embodiments of the present application can achieve the following technical effects: In an embodiment of the present application, a first entity object for link prediction is obtained; the first entity object is input into a prediction model for link prediction processing to obtain a link prediction result; wherein the prediction model is a machine learning model obtained based on a temporal knowledge graph, and includes an encoding part and a decoding part. During the link prediction processing, the encoding part is used to obtain a first temporal coding vector of the first entity object, and the decoding part is used to obtain the link prediction result based on the first temporal coding vector. In this way, the first entity object for link prediction is input into the prediction model to obtain a link prediction result, wherein the prediction model is a machine learning model obtained based on a temporal knowledge graph. Compared with the use of a static knowledge graph for link prediction in related technologies, this method uses a temporal knowledge graph to introduce time information into the knowledge graph, and can combine time information to predict the relationship between entities, thereby achieving more accurate link prediction, solving the problem of poor link prediction results in related technologies. BRIEF DESCRIPTION OF THE DRAWINGS
[0009] In order to more clearly illustrate the technical solutions of the embodiments of the present invention, the drawings required for use in the embodiments are briefly introduced below. It should be understood that the following drawings only show certain embodiments of the present invention and therefore should not be regarded as limiting the scope. For ordinary technicians in this field, other related drawings can be obtained based on these drawings without creative work.
[0010] Figure 1 is a flow chart of a link prediction method provided by an embodiment of the present application; Figure 2 is a flow chart of a method for obtaining a prediction model provided in an embodiment of the present application; Figure 3 It is a general concept diagram of a method for obtaining a prediction model provided in an embodiment of the present application; Figure 4 is a flowchart of another method for obtaining a prediction model provided in an embodiment of the present application; Figure 5 is a flowchart of another method for obtaining a prediction model provided in an embodiment of the present application; Figure 6 is a specific flow chart of a link prediction method provided by an embodiment of the present application; Figure 7 is a schematic diagram of a link prediction method provided in an embodiment of the present application; Figure 8 is a structural block diagram of a link prediction device provided in an embodiment of the present application; Fig. 9 It is a structural block diagram of an electronic device provided in an embodiment of the present application. DETAILED DESCRIPTION
[0011] The following will be combined with the drawings in the embodiments of the present application to clearly describe the technical solutions in the embodiments of the present application. Obviously, the described embodiments are part of the embodiments of the present application, not all of the embodiments. Based on the embodiments in the present application, all other embodiments obtained by ordinary technicians in this field without creative work are within the scope of protection of this application.
[0012] The terms "first", "second", etc. in the specification and claims of the present application are used to distinguish similar objects, and are not used to describe a specific order or sequence. It should be understood that the data used in this way can be interchangeable under appropriate circumstances, so that the embodiments of the present application can be implemented in an order other than those illustrated or described here, and the objects distinguished by "first", "second", etc. are generally of one type, and the number of objects is not limited. For example, the first object can be one or more. In addition, "and / or" in the specification and claims represents at least one of the connected objects, and the character " / " generally indicates that the objects associated with each other are in an "or" relationship.
[0013] Therefore, the following detailed description of the embodiments of the present invention provided in the accompanying drawings is not intended to limit the scope of the invention claimed for protection, but merely represents selected embodiments of the present invention. Based on the embodiments of the present invention, all other embodiments obtained by ordinary technicians in this field without creative work are within the scope of protection of the present invention.
[0014] Related technologies usually use static time series knowledge graphs, which are prone to data sparsity problems and have certain difficulties in processing the dynamic evolution of nodes and edges. In response to the above problems, the embodiment of the present application introduces time information into the knowledge graph to construct a time series knowledge graph, which can provide structured information for the reasoning process of the subsequent prediction model. At the same time, by integrating time information into the knowledge graph, a denser time series knowledge graph can be obtained to fill the gaps in data missing and improve the accuracy of link prediction. In addition, by encoding the time series information of nodes and edges, the evolution trends of nodes and edges can be better captured, making the results of link prediction more timely and improving the practicality of link prediction.
[0015] The link prediction method provided in the embodiment of the present application is applied to the link prediction scenario based on the time series knowledge graph. In particular, a trained prediction model based on the time series knowledge graph can be first obtained, and a first entity object for link prediction can be obtained. The first entity object can be input into the prediction model for link prediction to obtain a link prediction result.
[0016] In the link prediction method provided in this application, a bidirectional long short-term memory neural network (BiLSTM) model can be used to encode the temporal knowledge graph, capturing the time dependency of nodes in the temporal knowledge graph from both forward learning and reverse learning directions, which can more accurately identify and understand complex user behavior patterns and improve the performance of link prediction based on the temporal knowledge graph.
[0017] In the process of link prediction, the second time series encoding vector can be decoded by combining the ConvTrans decoder with the attention mechanism to obtain the link prediction result. This method can capture the local and global time series characteristics of the node at the same time, and the attention mechanism can apply different weights to different timestamps, so that the model pays attention to more important timestamps and improves the accuracy of link prediction results.
[0018] In the process of link prediction based on the time series knowledge graph, the time series knowledge graph can be obtained after data division through a sliding time window, and the window size of the sliding time window can be adaptively adjusted as the data changes. The adaptively adjusted sliding time window can realize dynamic prediction of the time series knowledge graph, and better capture and utilize the changes of the time series knowledge graph in the time dimension.
[0019] The link prediction method provided in the embodiment of the present application can be performed by a target device, wherein the target device can be one electronic device or multiple electronic devices. In the case where the link prediction method provided in the embodiment of the present application is performed by one electronic device, the electronic device can be a professional server equipped with a high-performance graphics processing unit (Graphic Processing Unit, GPU), a multi-core CPU, a large-capacity random access memory (random access memory, RAM) and a fast solid-state hard disk, the large-capacity RAM is, for example, tens of GB or even higher, and the professional server can be a separate physical machine, or it can be a virtual instance provided by a cloud service provider (such as AWS, Azure or GCP) to provide the necessary computing power to process complex deep learning models and large-scale data sets, ensuring the efficiency and speed of model training and reasoning processes. In the case where the link prediction method provided in the embodiment of the present application is performed by multiple electronic devices, these multiple electronic devices can form a service cluster, which cooperate with each other to complete each step. The service cluster can be a server cluster composed of multiple servers, and may include a cloud server capable of cloud computing.
[0020] The link prediction method provided by the embodiment of the present application is described in detail below through specific embodiments and their application scenarios in conjunction with the accompanying drawings.
[0021] See also Figure 1 , Figure 1 is a flow chart of a link prediction method provided by an embodiment of the present application. Figure 1 As shown, the method comprises the following steps: Step 110: Obtain a first entity object for link prediction.
[0022] In the embodiment of the present application, link prediction technology is a technology for predicting missing facts based on existing entities in the knowledge graph, and is a technology for solving the task of incomplete knowledge graph. In other words, the first entity object used for link prediction is the entity object for the task of predicting missing facts.
[0023] The first entity object may be a single entity or an entity pair (two entities). For example, the first entity object may be a single entity "user A" or an entity pair ("user A", "product B").
[0024] Step 120: Input the first entity object into the prediction model for link prediction processing to obtain a link prediction result; wherein the prediction model is a machine learning model obtained based on a temporal knowledge graph, and includes an encoding part and a decoding part. During the link prediction processing, the encoding part is used to obtain a first temporal coding vector of the first entity object, and the decoding part is used to obtain the link prediction result based on the first temporal coding vector.
[0025] In the embodiment of the present application, the prediction model is a trained machine learning model. During the training process of the prediction model, a time series knowledge graph can be constructed based on historical data, and the time series knowledge graph can be used to learn the representation of nodes and the relationship between nodes. The representation of nodes and the representation of the relationship between nodes include time information. The time series knowledge graph constructed in the training phase can provide structured information for the prediction model and can be applied to the subsequent reasoning and prediction process.
[0026] In an embodiment of the present application, after the first entity object is input into the prediction model, the first temporal coding vector of the first entity object can be obtained based on the coding part of the prediction model, and the first temporal coding vector can be the first temporal coding vector of the entity pair. The first entity object can be a single entity or an entity pair. In the case where the first entity object is a single entity, another entity that is connected to the single entity in the historical time period can be further determined based on the temporal knowledge graph constructed during the training process. It can be considered that the single entity and the other entity may be connected in the future to determine the entity pair formed by the single entity and the other entity, and determine the first temporal coding vector of the entity pair. In the case where the first entity object is an entity pair, the entity pair can be directly used to determine the first temporal coding vector of the entity pair.
[0027] After determining the first temporal coding vector of the first entity object, a link prediction result of the first entity object can be determined based on the decoding part of the prediction model. The processing result of the link prediction may include other entity objects, and the other entity objects are entity objects that the first entity object may be linked to. The decoding part of the prediction model can further determine the link prediction result of the first temporal coding vector based on the first temporal coding vector determined in the encoding part of the first entity object. The first temporal coding vector is a vector obtained by encoding an entity pair including the first entity object, and the link prediction result can be used to indicate the degree of association between the entity pairs.
[0028] In one embodiment of the present application, the temporal knowledge graph is a temporal knowledge graph oriented to a recommendation field, and the link prediction result is a recommendation result oriented to the first entity object.
[0029] In an embodiment of the present application, the first entity object may include a user, the temporal knowledge graph may be used to implement user-oriented recommendations, and the link prediction result is a recommendation result for the user. In fact, the recommendation result of the first entity object may be determined by predicting the degree of association between entity pairs. Specifically, in the case where the first entity object is a single entity, the recommendation result of the first entity object may include other entities with a high degree of association with the single entity. For example, if the first entity is user A, it may be determined that other entities "product B" with a high degree of association with user A, and product B may be recommended to user A.
[0030] In the case where the first entity is an entity pair, the most likely relationship between the entity pair can be predicted first, and other entities related to the entity pair can be recommended based on the relationship. For example, if the first entity is ("user A", "product B"), the relationship between the entity pair can be determined as "user A likes product B", and then products or services similar to product B can be recommended to user A based on the relationship, or other users related to product B can be recommended.
[0031] In the embodiment of the present application, by making user recommendations through a temporal knowledge graph, the temporal behavior model between users and items can be mined, which is more helpful in understanding the evolution of user behavior and the changes in the associations between items. In addition, the form of the knowledge graph can provide a deeper level of understanding and explainability for the recommendation system.
[0032] In an embodiment of the present application, a first entity object for link prediction is obtained; the first entity object is input into a prediction model for link prediction processing to obtain a link prediction result; wherein the prediction model is a machine learning model obtained based on a temporal knowledge graph, and includes an encoding part and a decoding part. During the link prediction processing, the encoding part is used to obtain a first temporal coding vector of the first entity object, and the decoding part is used to obtain the link prediction result based on the first temporal coding vector. In this way, the first entity object for link prediction is input into the prediction model to obtain a link prediction result, wherein the prediction model is a machine learning model obtained based on a temporal knowledge graph. Compared with the use of a static knowledge graph for link prediction in related technologies, this method uses a temporal knowledge graph to introduce time information into the knowledge graph, and can combine time information to predict the relationship between entities, thereby achieving more accurate link prediction, solving the problem of poor link prediction results in related technologies.
[0033] See also Figure 2 and Figure 3 , Figure 2 is a flowchart of a method for obtaining a prediction model provided in an embodiment of the present application, Figure 3 FIG. 1 is a general conceptual diagram of a method for obtaining a prediction model provided in an embodiment of the present application. Figure 2 As shown, the method comprises the following steps: Step 210: Based on the temporal knowledge graph, obtain a second temporal coding vector, wherein the second temporal coding vector includes an entity embedding vector, a relationship embedding vector and a timestamp embedding vector; the entity embedding vector is a vector representation of a node, including feature information of the node; the relationship embedding vector is a vector representation of an edge, used to represent the attributes of the relationship between nodes; the timestamp embedding vector is a vector representation of time information, and the time information provides the time context for the occurrence of an event.
[0034] In an embodiment of the present application, a time series knowledge graph may be first obtained, wherein the time series knowledge graph includes nodes and edges, and both the nodes and the edges contain time information.
[0035] In an embodiment of the present application, the temporal knowledge graph is constructed based on entity data within a historical time period. The entity is a node in the temporal knowledge graph, such as a target user, an item, an advertisement, or a scenic spot. In the temporal knowledge graph, an edge between two entities is used to indicate that there is a relationship between the two entities (such as a purchase relationship, a click relationship, or a similarity, etc.). For example, the two entities may be "Dream of Red Mansions" and "Cao Xueqin", and the relationship between the two entities is writing.
[0036] Since the relationship between entities may be related to time information, for example, user A purchased item C at time B. In this case, by introducing time information into the knowledge graph, the time evolution trend of nodes and edges can be better captured, and the timeliness between entity data can be better reflected to improve the accuracy of link prediction.
[0037] In an embodiment of the present application, the constructed time series knowledge graph can be directly obtained, or the time series knowledge graph can be obtained in the following way.
[0038] Exemplarily, in one embodiment of the present application, the process of acquiring the time series knowledge graph includes: acquiring first data within a target time period; for each sliding time window within the target time period, acquiring second data located within the sliding time window from the first data; based on the second data, acquiring the time series knowledge graph corresponding to the sliding time window; wherein the sliding time window is an adaptive window, and the window size of the sliding time window is adjusted as the target data that meets the target condition in the second data changes.
[0039] In an embodiment of the present application, the first data may be four-tuple data obtained after preprocessing, and the four-tuple data includes a head entity, a relationship, a tail entity and a timestamp. The head entity can be used to represent an entity, the tail entity can be an entity or numerical data, the relationship is the relationship between the head entity and the tail entity, and the timestamp is the timestamp information of the relationship between the head entity and the tail entity, for example (item S, sold, 100000, 2024 / 3 / 20-2024 / 4 / 19).
[0040] In an embodiment of the present application, the first data within a historical target time period (e.g., a historical week or a historical month) can be obtained. For example, the product purchase data of multiple shopping websites can be crawled through a crawler framework (e.g., the Apache Nutch crawler framework or other suitable web crawler tools) to build a data set containing rich entity data. If there are missing data in the data set, it can be processed in the following ways: using statistical methods or machine learning models to predict or interpolate missing data; in a time series knowledge graph, existing entities and relationships can be used to infer missing data; directly using data with missing information for link prediction. In practical applications, the above strategies can be combined to deal with the problem of missing data.
[0041] In an embodiment of the present application, the first data may be divided according to a sliding time window to obtain second data within the sliding time window. The sliding time window is to divide the first data into continuous time periods of fixed length and slide at a fixed step size. For example, a daily, weekly or shorter time window may be defined. The data within a sliding time window is regarded as a snapshot, which may reflect the data status within the sliding time window.
[0042] In the process of determining the window size of the sliding time window, the window size of the sliding time window can be adaptively adjusted according to the state of the target data that meets the target condition in the second data. Specifically, when it is determined that there is target data in the second data that meets the target condition (for example, the target data changes too frequently or is too active), the sliding window size can be dynamically adjusted according to the activity level or change frequency of the target data so as to capture the change trend or characteristics of the target data.
[0043] Specifically, the state of the target data may include an active state and an inactive state, wherein the active state is used to indicate that the data or event is in a time period with a high frequency of occurrence and a fast change. In this case, the window size may be shortened so that the data can be updated or analyzed more frequently to capture real-time changes. The inactive state is used to indicate that the data or event is in a time period with a slow and stable change. In this case, because the data does not need to be updated frequently, the window size of the sliding time window can be increased, and a longer time window can be more fully utilized to analyze and predict long-term trends or patterns.
[0044] For example, when analyzing the trading data of a certain market, the trading time is usually a specific time period every day, such as a few hours before the market opens or when some news is released. The trading data in these time periods can be considered to be active. In contrast, the trading data in the time period with low trading volume and small price fluctuations can be considered to be inactive. In other words, the idea of adaptively adjusting the sliding time window size is to dynamically adjust the sliding time window size of the data according to the activity of the data, so that effective analysis and prediction can be performed under different data change states.
[0045] In one embodiment of the present application, the window size of the sliding time window can be dynamically adjusted according to the specific characteristics of the target data and business requirements. For example, for highly seasonal products, a longer sliding time window may be required to smooth seasonal fluctuations.
[0046] After the first data is divided based on the sliding time window, a time series knowledge graph can be constructed for the second data in the sliding time window to construct a series of time series knowledge graphs. Each node and edge of the time series knowledge graph has timestamp information, and the timestamp information is used to indicate the generation or update time of the node or edge in the current sliding time window.
[0047] In an embodiment of the present application, the constructed temporal knowledge graph can be an undirected graph or a directed graph. Whether to construct an undirected graph or a directed graph can be determined based on specific application scenarios and requirements. In an undirected graph, the edge has no direction, indicating that the relationship between entities is bidirectional or does not distinguish directions. In a directed graph, the edge has a direction, indicating that the relationship is from one node to another. In practical applications, if the relationship between entities is bidirectional or has no fixed direction, such as the similarity between two commodities, an undirected temporal knowledge graph can be constructed. Correspondingly, if the relationship between entities has a clear direction, such as a user's evaluation, purchase or browsing of a commodity, a directed temporal knowledge graph can be constructed.
[0048] In an embodiment of the present application, the entity embedding vector, relationship embedding vector and timestamp embedding vector can be obtained through a machine learning model to represent the position of the entity in the vector space. This position is determined based on the attributes of the entity and the relationship between the entity in the temporal knowledge graph, so as to facilitate subsequent more efficient calculations, such as link prediction, classification or clustering.
[0049] The entity embedding vector is a vector representation of a node (which can be a head entity or a tail entity), including the intrinsic attributes of the node (such as the user's age, gender, historical behavior, etc. or the price and category of the product, etc.) and the location information in the time series knowledge graph. The relationship embedding vector is a vector representation of an edge, which is used to represent the attributes of the relationship between entities, such as "purchase" or "evaluation". The relationship embedding vector includes the type, direction and attributes of the edge (such as the frequency of transactions, the average score of evaluations, etc.). The timestamp embedding vector is a continuous vector representation of time information. The timestamp embedding vector includes time information, such as the specific time point when the event occurs, the sequentiality of time, etc.
[0050] Step 220: Based on the second temporal coding vector, obtain a processing result for link prediction.
[0051] In an embodiment of the present application, the processing result of the link prediction may include a recommendation data result. That is, the processing result of the link prediction may include other entity objects, and the other entity objects are entity objects that the first entity object may link to. For example, in the case of implementing target user recommendations, the temporal knowledge graph is constructed based on the historical data of the target user, and the result of the link prediction may be the future recommendation data of the target user.
[0052] In the embodiment of the present application, by obtaining the processing results for link prediction, the temporal behavior patterns between entities (such as users and items) can be mined, which helps to understand the evolution of user behavior and the changes in associations between items, thereby providing a deeper level of understanding and interpretability for the recommendation system. The temporal behavior patterns can be, for example, the behavioral trends and laws between users and items, and can include at least one of the patterns of behavioral trends, behavioral evolution, association rules, time sensitivity, and contextual influence.
[0053] Among them, the behavioral trend may be, for example, seasonal purchasing behavior (users may buy certain items at a specific time), the behavioral evolution may be, for example, changes in user interests (over time, it can be observed that user interests and preferences may change), the association rules may be, for example, purchasing patterns (after purchasing a product, users may purchase related accessories or services in the future), the time sensitivity may be, for example, instant behavior (user behavior may be affected by instant promotional activities or events), and the contextual influence may be, for example, the influence of external factors (news time, popular trends may affect user behavior).
[0054] In the embodiment of the present application, by performing link prediction through the time series knowledge graph, the time series behavior pattern can be analyzed and applied to the recommendation system to achieve personalized recommendations that are more in line with the user's current status and potential needs. For example, if it is observed that the user buys fitness-related items at the beginning of each year, then recommending fitness equipment or health food to the user at this time point may be more in line with the user's current needs, or if it is observed that the user has recently frequently browsed baby products, then recommending baby-related products may be more in line with the user's current needs.
[0055] In the embodiments of the present application, Figure 3 As shown, an embodiment of the present application provides a temporal knowledge graph link prediction method for recommendation systems (TKGLP-RS) for recommendation fields. The method may include three parts: temporal knowledge graph acquisition in the recommendation field, temporal knowledge graph encoding in the recommendation field, and temporal knowledge graph link prediction in the recommendation field.
[0056] Among them, the acquisition part of the time series knowledge graph in the recommendation field: construct the time series knowledge graph; the encoding part of the time series knowledge graph in the recommendation field: the BiLSTM model can be used to encode the time series knowledge graph and convert the time series knowledge graph into a second time series encoding vector; the link prediction part of the time series knowledge graph in the recommendation field: the ConvTrans decoder and the attention mechanism can be used to extract local and global features in the second time series encoding vector. The TKGLP-RS method can effectively model the time series of recommendation data, and by embedding time information, it improves the expression ability of the time series relationship in the time series knowledge graph and the accuracy of link prediction.
[0057] In one embodiment of the present application, in the process of link prediction based on the time-series knowledge graph, the time-series knowledge graph can be updated according to real-time data to obtain the latest link prediction results. The frequency of updating the time-series knowledge graph can be adjusted according to actual conditions and needs, such as the speed of change of user behavior, the update speed of the item library, the performance of the recommendation system, business needs or event-driven updates. Common update frequencies may include real-time updates (for highly dynamic environments, such as the stock market or news field), daily updates (for scenarios such as daily shopping), and weekly / monthly updates (for areas that do not change frequently, such as book recommendations).
[0058] In an embodiment of the present application, by continuously updating the time-series knowledge graph to obtain real-time link prediction results, changes in the relationship between users and items can be reflected in a timely manner, thereby achieving real-time adjustment and optimization of the link prediction results.
[0059] In one embodiment of the present application, the temporal knowledge graph may be obtained by fusing knowledge graphs based on different industries, fields or categories, that is, data sets from different industries, fields or categories may be merged into a unified knowledge graph. Cross-domain recommendations may be achieved through the fused temporal knowledge graph. For example, user A likes to watch historical movies on a movie recommendation platform and likes to read history books on a book recommendation platform. By fusing the temporal knowledge graph of the movie recommendation platform and the temporal knowledge graph of the book recommendation platform, user A's interest in historical content may be observed through link prediction, and historical-themed games, travel destinations with historical themes or history-related educational courses may be recommended to user A to achieve cross-domain personalized recommendations.
[0060] It is important to note that this process is not just about putting data together, but also about ensuring that data from different sources are semantically compatible and can be associated with each other to form meaningful links and relationships. Such integration can increase the diversity and richness of the knowledge graph and provide support for cross-domain recommendations.
[0061] In the process of integrating knowledge graphs from different fields, compatibility can be processed from the aspects of entity unification, relationship fusion, temporal information integration, semantic consistency and data quality management. Specifically, knowledge graphs from different fields may contain the same entities (such as the same user, company or product) but use different representations. Entity unification refers to identifying and unifying these entities to ensure that they are unique in the fused temporal knowledge graph.
[0062] The relationships between entities in graphs from different fields may be different. The fusion process needs to unify these relationships, and may need to create new relationship types or transform existing relationships to ensure relationship consistency and understandability in the new temporal knowledge graph. The temporal knowledge graph not only records the relationships between entities, but also records how these relationships change over time. When fusion occurs across domains, this temporal information can be retained to support temporal analysis of user behavior. In addition, ensure that data from different fields are semantically consistent, such as term standardization or concept alignment. During the fusion process, data conflicts and data quality issues can be handled, such as removing duplicate information and resolving inconsistent data points.
[0063] In the embodiment of the present application, by integrating time-series knowledge graphs from different fields, cross-domain recommendations can be achieved, which can provide users with more diverse and rich recommendation services and increase the diversity of recommendation data. At the same time, by analyzing the behavior of users in multiple fields, the preferences of target users can be observed more accurately, improving the accuracy of link prediction results.
[0064] In an embodiment of the present application, based on the time series knowledge graph, a second time series coding vector including an entity embedding vector, a relationship embedding vector and a timestamp embedding vector is obtained, so as to perform link prediction based on the second time series coding vector and obtain a processing result for link prediction. The time series knowledge graph is used to learn the representation of nodes and the relationships between nodes, and the time series knowledge graph constructed in the training phase can provide structured information for the reasoning process of the prediction model.
[0065] This application embodiment provides a specific method for obtaining a time-series coding vector. Figure 4 , Figure 4 FIG. 1 is a flowchart of another method for obtaining a prediction model provided in an embodiment of the present application. Figure 4 As shown, the method comprises the following steps: Step 410: Based on the temporal knowledge graph, determine a node feature matrix and an adjacency matrix, wherein the node feature matrix is used to represent the attribute information of each node in the temporal knowledge graph, and the adjacency matrix is used to represent the connection relationship between the nodes in the temporal knowledge graph.
[0066] In the embodiment of the present application, before determining the node feature matrix and the adjacency matrix, a unique identifier, such as 0, 1, 2, etc., may be assigned to each node in the temporal knowledge graph (including the head entity and the tail entity). Based on the temporal knowledge graph, the method for determining the node feature matrix may refer to the following method: First, extract relevant features from the data (quadruple data) corresponding to the time series knowledge graph according to the type of node (user, item, etc.). Specifically, for user nodes, features can be the user's purchase history, browsing history, user statistics, etc. For item nodes, features can be the item's category, price, sales volume, rating, historical sales trend, etc. In addition, node features can also include other external factors that affect trends, as well as time features, such as encoding weeks, months, and holidays to capture the periodicity and seasonality of time.
[0067] Then, the extracted features are converted into numerical form to obtain the feature vector of the node. Among them, for categorical feature data, one-hot encoding can be used for feature conversion; for numerical feature data, normalization or standardization can be used for processing. The feature conversion is the process of converting feature data into a format that the model can understand. In the time series knowledge graph, this usually means converting time series data (such as clicks or sales) into features that help show data trends and patterns. Based on the feature vector of each node, a node feature matrix is constructed. For example, there are N nodes, each with F features, then the shape of the node feature matrix X is N*F.
[0068] In one embodiment of the present application, the node feature matrix includes a target element, and the target element is obtained based on averaging specified statistical values of the same node in the temporal knowledge graph at different unit times.
[0069] In an embodiment of the present application, the target element may be a sliding average, the sliding average of a node may be the average of specified statistical values of the node at different unit times within a sliding time window, and the specified statistical value may be numerical data in the data (quadruple data) of the above-mentioned time series knowledge graph, such as number of clicks, sales volume, etc.
[0070] In practical applications, the four-tuple data may not necessarily contain numerical data. In the case where the four-tuple data contains numerical data, the numerical data may be directly extracted from the four-tuple data. In the case where the four-tuple data does not contain numerical data, the four-tuple data may be first digitized to convert the four-tuple data into numerical form, such as counting the number of occurrences of an event, or defining a complex numerical code, which may be digitized based on the type, frequency or other attributes of the event.
[0071] After obtaining the specified statistical value, the sliding average value can be calculated by the following formula:
[0072] in, is the specified statistical value of timestamp i, N is the window size of the sliding time window, is the sliding average of timestamp t, that is, the average of the data in the first N time units of timestamp i. It should be noted that when calculating the sliding average using the above formula, The specified statistical value within the current sliding time window.
[0073] In an embodiment of the present application, after determining the sliding average of the node, operations such as entity attribute update, relationship weight adjustment, and trend analysis can be performed based on the sliding average. Specifically, the entity attributes can be updated according to the change of the sliding average. For example, the popularity or activity of a product can be adjusted according to the sliding average of its sales. At the same time, the relationship weights between entities can be adjusted according to the change of the sliding average. For example, if the sliding averages of the sales of two products show a correlation, it may indicate that there is some kind of association between them (such as being frequently purchased together), so the relationship weights between them should be adjusted accordingly. In addition, the trend of changes in the sliding average over time can be analyzed to identify long-term growth or decline trends, or cyclical changes. These steps ensure that the time series knowledge graph is not only accurate when it is created, but also that it can adapt to changes and remain updated and relevant over time and as data accumulates.
[0074] In the embodiment of the present application, the sliding average can be used as a feature in the node feature matrix. In addition, other statistics such as standard deviation and median can also be included. The introduction of the sliding average helps to smooth the time series data, remove noise and capture long-term trends, and provide a more stable and reliable data basis for the recommendation system.
[0075] In the embodiment of the present application, based on the temporal knowledge graph, the method of determining the adjacency matrix is as follows: for a temporal knowledge graph with N nodes, the adjacency matrix A of the temporal knowledge graph is an N×N square matrix, where It is used to indicate whether there is an edge between node i and node j. Specifically, first determine the edge relationship in the temporal knowledge graph, that is, according to the data structure of the graph, determine which nodes have edges. If there is an edge between node i and node j, then determine Otherwise, determine .
[0076] Step 420: Normalize the time information in the time series knowledge graph to obtain a target time series.
[0077] In an embodiment of the present application, in order to standardize the time information to a fixed range to improve the stability and prediction effect of the model, the time information in the time series knowledge graph can be normalized. The normalization process includes: obtaining the timestamp information of the nodes and edges to form a timestamp sequence, and then normalizing the timestamp sequence to the range of [0,1] by adopting the Min-Max normalization method. Specifically, Min-Max normalization can be performed by the following formula:
[0078] Among them, t is the timestamp before normalization processing, is the maximum value of the timestamp sequence, is the minimum value of the timestamp sequence, The timestamp after normalization.
[0079] Step 430: Input the target time series, the node feature matrix and the adjacency matrix into a time recurrent neural network to obtain a second time series encoding vector.
[0080] In an embodiment of the present application, the target time series, the node feature matrix and the adjacency matrix are input into a time recurrent neural network, and the time recurrent neural network encodes the target time series, the node feature matrix and the adjacency matrix to obtain an entity embedding vector, a relationship embedding vector and a timestamp embedding vector, and the entity embedding vector is obtained by learning the features in the node feature matrix.
[0081] In one embodiment of the present application, the time recurrent neural network includes a BiLSTM, and the BiLSTM includes a first LSTM for forward learning and a second LSTM for reverse learning. Step 430 inputs the target time series, the node feature matrix, and the adjacency matrix into the time recurrent neural network to obtain a second temporal coding vector, including: inputting the target time series, the node feature matrix, and the adjacency matrix into the first LSTM and the second LSTM; processing the target time series, the node feature matrix, and the adjacency matrix by the first LSTM to obtain a first processing result, and the first processing result is a result obtained by processing in the direction from the beginning to the end of the target time series. Processing the target time series, the node feature matrix, and the adjacency matrix by the second LSTM to obtain a second processing result, and the second processing result is a result obtained by processing in the direction from the end to the beginning of the target time series. Based on the first processing result and the second processing result, a second temporal coding vector is obtained.
[0082] In the embodiment of the present application, the BiLSTM model includes an input layer, a BiLSTM layer and an output layer, wherein the BiLSTM layer includes a first LSTM for forward learning and a second LSTM for reverse learning. The input layer is used to take the node feature matrix, the adjacency matrix and the target time series as the input of the BiLSTM model, the BiLSTM layer is used to capture the timing information of the nodes and edges, and the output layer is used to convert the output of the BiLSTM layer into a second timing encoding vector. , that is, the entity embedding vector is obtained by encoding , relation embedding vector and timestamp embedding vector , the second temporal coding vector is the basis for subsequent link prediction.
[0083] In the process of capturing the time series information of nodes and edges through the BiLSTM layer, the first LSTM (forward LSTM) and the second LSTM (backward LSTM) simultaneously process the information in two directions to obtain the first processing result and the second processing result, and the first processing result and the second processing result are spliced to obtain the second time series encoding vector. Among them, the first processing result is the result obtained by processing from the beginning to the end of the target time series, and the second processing result is the result obtained by processing from the end to the beginning of the target time series. In this way, the model can more fully consider the future change trend when learning time series information, thereby improving the prediction ability of future information. By applying bidirectional LSTM in the context of the time series knowledge graph, the capture of the time series information of nodes and edges is also enhanced, and the sensitivity of the recommendation system to future time series changes is improved.
[0084] Step 440: Based on the second temporal coding vector, obtain a processing result for link prediction.
[0085] In the embodiment of the present application, the above steps 410 to 430 specifically describe the process of the prediction model obtaining the second temporal coding vector based on the temporal knowledge graph during the training phase. In fact, the prediction model will also obtain the first temporal coding vector based on the entity pair containing the first entity object during the reasoning phase. It should be understood that the process of the prediction model obtaining the first temporal coding vector of the entity pair during the reasoning phase can refer to the process of obtaining the second temporal coding vector of the temporal knowledge graph described above.
[0086] In an embodiment of the present application, the prediction model may include a decoding part (decoder), and the second temporal coding vector may be input into the decoder, and the second temporal coding vector may be converted into a processing result for link prediction by the decoder. The decoder may be a ConvTrans decoder, and the local and global features in the second temporal coding vector may be extracted by using the decoder to realize link prediction of the temporal knowledge graph.
[0087] Specifically, the processing result for link prediction may include the degree of link between entity pairs at a specified timestamp, that is, the degree of association or connection strength between two entities. There may be various relationships between entities in the temporal knowledge graph, such as temporal causal relationships, attribute relationships, behavioral relationships, etc., and the degree of link between entities reflects the closeness of the relationship between entities or the strength of the correlation. Among them, the degree of link between the entities can be used to generate recommendation data. When generating recommendation data, recommendation data can be generated through two specific scenarios. One is a scenario with a single entity input, and the other is a scenario with dual entity input.
[0088] For the first scenario, the first entity object is a single entity. The first entity object is input into the prediction model. According to the degree of connection between other entities and the first entity object, an entity with a higher degree of connection can be selected from other entities as the final recommendation data of the first entity object.
[0089] In this scenario, when generating recommendation data for the target user, for each possible prediction entity, the model will calculate the degree of link between the prediction entity and the target user, and the degree of link is used to indicate the relevance of the prediction entity to the target user or the probability of the relationship occurring. All prediction entities are sorted according to the degree of link, and the prediction entities with high link degrees can be considered as entities that the target user is interested in. Therefore, the top N prediction entities with the highest link degrees can be selected as the final recommended entities, where N is a positive integer and can be adjusted according to the application scenario and user needs, so as to provide a personalized recommendation list for the target user.
[0090] For example, the first entity object is user A. By inputting "user A" into the prediction model, another entity object "product B" associated with user A can be obtained, that is, product B is the recommendation data for user A.
[0091] For the second scenario, the first entity object may be two entities (entity pair). The entity pair is input into the prediction model. The prediction model may first predict the relationship between the entity pair and then generate recommendation data for the two entities based on the relationship.
[0092] In this scenario, when predicting the relationship between entity pairs, there may be multiple possible relationships between the entity pairs, and each of the multiple possible relationships may correspond to a degree of linkage, which is used to indicate the confidence that the relationship exists between the entity pairs within a given timestamp. The multiple possible relationships are sorted according to the degree of linkage. The higher the degree of linkage corresponding to a certain relationship, the higher the probability that the entity pairs have the relationship. The relationship with the highest degree of linkage can be considered to be the relationship between the entity pairs within a given timestamp. In addition, a confidence threshold can be set in advance. When the degree of linkage between a certain relationship between entity pairs is greater than the confidence threshold, the relationship can be regarded as a predicted relationship, which helps to filter out predicted relationships with insufficient confidence, thereby improving the quality of the prediction results.
[0093] At the same time, the final prediction relationship can be determined from multiple prediction relationships according to actual needs. Specifically, if the most likely single relationship between entity pairs needs to be predicted, the prediction relationship with the highest degree of connection can be selected as the final prediction relationship. If multiple possible relationships between entity pairs need to be predicted, all prediction relationships with a degree of connection greater than the confidence threshold can be selected as the final prediction relationship.
[0094] After predicting the relationship between the entity pair, recommendation data of the two entities can be generated based on the relationship. For example, the entity pair can be (user A and product B), and the prediction model can first predict that the relationship between the entity "user A" and the entity "product B" is "like", that is, user A likes product B. Based on this relationship, products or services similar to product B can be generated, and the similar products or services can be recommended to users, or other users related to product B can be recommended.
[0095] In the embodiment of the present application, the model can quantify and evaluate the association between entities based on the historical time-series knowledge graph and the current time-series knowledge graph of the time-series knowledge graph, and provide a numerical measure for the degree of association between entities. The numerical measure helps to understand the relationship pattern between entities to generate recommendation data or predict future associations, and can better understand the evolution of user behavior and preferences, so as to make more accurate recommendations.
[0096] In an embodiment of the present application, based on the time series knowledge graph, a node feature matrix and an adjacency matrix are determined, the node feature matrix is used to represent the attribute information of each node in the time series knowledge graph, and the adjacency matrix is used to represent the connection relationship between nodes in the time series knowledge graph; the time information is normalized to obtain a target time series; the target time series, the node feature matrix and the adjacency matrix are input into a time recurrent neural network to obtain a second time series encoding vector. In this way, node features of different timestamps are extracted from the time series knowledge graph, thereby capturing dynamic changes in the time series knowledge graph to improve the accuracy of link prediction.
[0097] The present application embodiment provides a specific implementation method of the decoding process of the prediction model, see Figure 5 , Figure 5 FIG. 1 is a flowchart of another method for obtaining a prediction model provided in an embodiment of the present application. Figure 5 As shown, the method comprises the following steps: Step 510: Based on the temporal knowledge graph, obtain a second temporal coding vector, wherein the second temporal coding vector includes an entity embedding vector, a relationship embedding vector and a timestamp embedding vector; the entity embedding vector is a vector representation of a node, including feature information of the node; the relationship embedding vector is a vector representation of an edge, used to represent the attributes of the relationship between nodes; the timestamp embedding vector is a vector representation of time information, and the time information provides the time context for the occurrence of an event.
[0098] In the embodiment of the present application, the prediction model includes an encoding part and a decoding part. The encoding part can refer to the specific description of the above steps 410 to 430, and the following steps 520 to 540 will expand the description of the decoding part of the prediction model.
[0099] Step 520: Perform feature extraction on the second temporal coding vector to obtain a first feature graph, where the first feature graph contains local features of the node.
[0100] In an embodiment of the present application, the decoding part of the prediction model may include a convolutional layer and a fully connected layer. Among them, the convolutional layer can be used to extract local features and capture complex relationships between nodes, which is very important for local structural information at a specific time point in the temporal knowledge graph. The decoding part can also be combined with an attention mechanism, which is used to aggregate information of different timestamps to capture dynamic changes in the temporal knowledge graph. The convolution output of the latest temporal knowledge graph and all historical temporal knowledge graphs can be weighted and integrated to provide accurate distributed embedding for entity learning, ensuring that important changes in timing can be captured. Through the combination of convolutional layers and attention mechanisms, complex relationships and dynamic changes in temporal knowledge graphs can be captured more comprehensively. Among them, the idea of the distributed embedding is to map entities to points in a low-dimensional vector space, similar entities are closer in the vector space, and dissimilar entities are farther apart in the vector.
[0101] Specifically, the second temporal coding vector is input into the convolution layer, and the second temporal coding vector is convolved by the convolution kernel to extract local features to generate a first feature map, where the first feature map is a feature matrix after the convolution operation, and the feature matrix includes local features of the node and the neighboring nodes of the node, wherein the output of the convolution layer is shown in the following formula:
[0102] in, is the entity embedding vector at timestamp t, is the relation embedding vector of timestamp t, is the timestamp embedding vector, is the convolution output at timestamp t.
[0103] Step 530: Perform weighted processing on the first feature map through an attention mechanism to obtain a second feature map.
[0104] In the embodiment of the present application, considering that the latest historical timestamp has the greatest influence on the prediction, the convolution output of timestamp t-1 can be Apply learnable attention to the convolution outputs of all historical timestamps. That is, the attention mechanism can assign different attention weights according to the importance of the current timestamp, so that the model can pay more attention to the timestamps that are helpful for link prediction. Through the attention weights, the convolution outputs of different timestamps are weighted and summed to capture important information in the time dimension. Specifically, the expression of the attention mechanism is as follows:
[0105]
[0106]
[0107]
[0108] in, is the second feature map, Q is the query matrix, K is the key matrix, V is the value matrix, is a specific scaling factor that can be set to the dimension of the key matrix K to prevent the gradient from disappearing. , as well as are all learning parameters, which are used to assign a learnable attention weight to each historical timestamp.
[0109] Step 540: Based on the first feature graph and the second feature graph, obtain a processing result for link prediction.
[0110] In an embodiment of the present application, the first feature map output by the convolution layer and the second feature map obtained by the attention mechanism are input into the fully connected layer, and the fully connected layer linearly transforms the input through the weight matrix and the bias vector, and adds an activation function to obtain the result for link prediction. This method combines the advantages of the convolution layer and the attention mechanism. The convolution layer is good at extracting features from the local graph structure, and the attention mechanism can effectively integrate and weight features at different times, thereby capturing important dynamic changes in the time series. The combination of the two allows the model to more accurately capture the complex relationships and changes in the time series knowledge graph when performing link prediction, making the link prediction effect better.
[0111] In one embodiment of the present application, the number of the second temporal coding vectors is n groups, the number of the first feature graphs is n, the n first feature graphs are obtained based on the n groups of second temporal coding vectors, and n is a positive integer greater than 1. The obtaining of a processing result for link prediction based on the first feature graph and the second feature graph includes: performing a sum operation on the n first feature graphs to obtain a sum result; and obtaining a processing result for link prediction based on the sum result and the second feature graph.
[0112] In the embodiment of the present application, the n groups of second temporal coding vectors are the second temporal coding vectors of the historical timestamp t-1, and the n first feature graphs are the convolution outputs of the historical timestamp t-1. By summing the convolution outputs of the historical timestamp t-1 to obtain the summation result, entity information within a period of time can be accumulated and important features can be extracted from it. Matrix multiplication can be performed on the summation result and the second feature graph to obtain a result matrix, which can be referred to the following formula:
[0113] Among them, S is the result matrix, z is the second feature map, To sum the results, mm() is used to represent matrix multiplication. After the result matrix is obtained, each element in the result matrix is averaged, so as to convert the result matrix into a numerical value (the degree of link between entities), that is, the processing result of link prediction.
[0114] The embodiment of the present application specifically describes the decoding process in the prediction model training phase. In fact, the reasoning phase of the prediction model also includes the process of decoding the first temporal coding vector of the entity pair to obtain the link prediction result. It should be noted that the decoding process in the reasoning phase of the prediction model is consistent with the decoding process in the training phase, and the decoding process in the training phase can be referred to, which will not be described here.
[0115] In an embodiment of the present application, in the process of the above-mentioned TKGLP-RS, link prediction based on the time series knowledge graph can be realized through a link prediction model, and the link prediction model includes a BiLSTM model and a ConvTrans decoder. In the process of training the link prediction model, a grid search can be used to tune hyperparameters to determine the optimal hyperparameter combination of the link prediction model to be trained. Among them, the principle of the grid search is to establish a grid by all possible combinations of hyperparameters to be adjusted, and perform model training and evaluation on each grid, and use the hyperparameter combination with the best evaluation performance as the best hyperparameter group, and apply the best hyperparameter group to the link prediction model to be trained to obtain a trained link prediction model. Among them, the evaluation indicators may include indicators such as accuracy and recall.
[0116] Specifically, a training set is obtained, for example, six months of historical user behavior data can be obtained. Based on the training set, a time series knowledge graph is constructed, and the BiLSTM model is used for encoding, and link prediction is performed through the ConvTrans decoder and the attention mechanism. The loss function is calculated based on the link prediction results of the training set and the true value of the identification of the training set to adjust the hyperparameter group of the link prediction model to be trained and optimize the model performance. The loss function can refer to the following formula:
[0117] Wherein, T is the number of timestamps in the training set, that is, the number of timestamps involved in the training process of the link prediction model to be trained; Used to indicate the number of entities involved in the model; is an indicator function used to indicate whether there is a relationship between the ith entity and entity e at timestamp t+1. Specifically, if there is a relationship between the ith entity and entity e at timestamp t+1, the value can be determined to be 1, otherwise the value is determined to be 0. is the probability score corresponding to the ith entity, that is, the link degree corresponding to the ith entity. L is the loss function of the link prediction model to be trained, which is used to represent the overall loss obtained by accumulating and summing the losses of all timestamps and all entities.
[0118] In an embodiment of the present application, the link prediction model to be trained is evaluated using a training set until the evaluation result of the link prediction model to be trained meets the expected requirements, thereby completing the training of the link prediction model to be trained.
[0119] In an embodiment of the present application, after obtaining the second temporal coding vector, feature extraction is performed on the second temporal coding vector to obtain a first feature graph, which contains local features of the node; the first feature graph is weighted by the attention mechanism to obtain a second feature graph; based on the first feature graph and the second feature graph, a processing result for link prediction is obtained. In this way, the second temporal coding vector is decoded to capture the local features of the node and the neighboring nodes. At the same time, the attention mechanism can be introduced to apply different weights to the node features of different timestamps, so that the model can pay more attention to timestamps that are beneficial to link prediction.
[0120] See also Figure 6 and Figure 7 , Figure 6 is a specific flow chart of a link prediction method provided by an embodiment of the present application, Figure 7 is a schematic diagram of a link prediction method provided by an embodiment of the present application. Figure 6 As shown, the method comprises the following steps: The link prediction method provided in the embodiment of the present application includes a training process and a reasoning process of a prediction model. Specifically, the following steps 610 to 660 are used to describe the training process of the prediction model, that is, the process of obtaining the prediction model; the following steps 670 to 680 are used to describe the reasoning process of the prediction model, that is, the process of using the prediction model to obtain the link prediction result. Wherein, the prediction model is a machine learning model obtained based on a temporal knowledge graph, and includes an encoding part and a decoding part. In the process of link prediction processing, the encoding part is used to obtain the first temporal encoding vector of the first entity object, and the decoding part is used to obtain the link prediction result based on the first temporal encoding vector.
[0121] Step 610: Based on the temporal knowledge graph, determine a node feature matrix and an adjacency matrix, wherein the node feature matrix is used to represent the attribute information of each node in the temporal knowledge graph, and the adjacency matrix is used to represent the connection relationship between the nodes in the temporal knowledge graph.
[0122] Among them, the node feature matrix includes a target element, and the target element is obtained based on averaging the specified statistical values of the same node in the time series knowledge graph at different unit times.
[0123] Step 620: Normalize the time information in the time series knowledge graph to obtain a target time series.
[0124] Step 630: Input the target time series, the node feature matrix and the adjacency matrix into a time recurrent neural network to obtain a second time series encoding vector.
[0125] In an embodiment of the present application, the second temporal encoding vector includes an entity embedding vector, a relationship embedding vector and a timestamp embedding vector; the entity embedding vector is a vector representation of a node, including feature information of the node; the relationship embedding vector is a vector representation of an edge, used to represent the attributes of the relationship between nodes; the timestamp embedding vector is a vector representation of time information, and the time information provides the time context for the occurrence of an event.
[0126] In the embodiments of the present application, Figure 7As shown, by determining the target time series, node feature matrix and adjacency matrix of the time series knowledge graph, the time series knowledge graph can be encoded into a vector through the BiLSTM model. The time recurrent neural network includes BiLSTM, and the BiLSTM includes a first LSTM for forward learning and a second LSTM for reverse learning. In step 630, the target time series, the node feature matrix and the adjacency matrix are input into the time recurrent neural network to obtain a second time series encoding vector, including: inputting the target time series, the node feature matrix and the adjacency matrix into the first LSTM and the second LSTM; processing the target time series, the node feature matrix and the adjacency matrix by the first LSTM to obtain a first processing result, the first processing result is a result obtained by processing in the direction from the beginning to the end of the target time series; processing the target time series, the node feature matrix and the adjacency matrix by the second LSTM to obtain a second processing result, the second processing result is a result obtained by processing in the direction from the end to the beginning of the target time series; based on the first processing result and the second processing result, a second time series encoding vector is obtained.
[0127] Step 640: Perform feature extraction on the second temporal coding vector to obtain a first feature graph, where the first feature graph contains local features of the node.
[0128] Step 650: Perform weighted processing on the first feature map through an attention mechanism to obtain a second feature map.
[0129] Step 660: Based on the first feature graph and the second feature graph, obtain a processing result for link prediction.
[0130] In an embodiment of the present application, the processing result for link prediction can be used to train the prediction model to be trained, adjust the parameters of the prediction model, and obtain a trained prediction model for link prediction of the first entity object in subsequent steps 670 to 680.
[0131] like Figure 7 As shown, the second temporal encoding vector can be decoded using the ConvTrans decoder and the attention mechanism to obtain the processing result of the link prediction of the temporal knowledge graph.
[0132] In the embodiment of the present application, the number of the second temporal coding vectors is n groups, the number of the first feature graphs is n, and the n first feature graphs are obtained based on the n groups of second temporal coding vectors, where n is a positive integer greater than 1. The step 660 of obtaining a processing result for link prediction based on the first feature graph and the second feature graph includes: performing a sum operation on the n first feature graphs to obtain a sum result; and obtaining a processing result for link prediction based on the sum result and the second feature graph.
[0133] Step 670: Obtain a first entity object for link prediction.
[0134] Step 680: Input the first entity object into the prediction model to perform link prediction processing to obtain a link prediction result.
[0135] In an embodiment of the present application, the temporal knowledge graph is a temporal knowledge graph oriented to a recommendation field, and the link prediction result is a recommendation result oriented to the first entity object.
[0136] The prediction model is a trained machine learning model based on a temporal knowledge graph, and includes an encoding part and a decoding part. During the link prediction process, the encoding part is used to obtain the first temporal encoding vector of the first entity object, and the decoding part is used to obtain the link prediction result based on the first temporal encoding vector. The encoding process and decoding process of the prediction model in the inference stage can refer to the encoding process and decoding process in the training stage.
[0137] The first temporal encoding vector includes a target entity embedding vector, a target relationship embedding vector and a target timestamp embedding vector. The target entity embedding vector is a vector representation of an entity pair including a first entity object, and includes feature information of a node pair. The target relationship embedding vector is a vector representation of an edge between entity pairs, and is used to represent the attributes of the relationship between node pairs. The target timestamp embedding vector is a vector representation of time information, and the time information provides a time context for an event to occur.
[0138] In an embodiment of the present application, a first entity object for link prediction is obtained; the first entity object is input into a prediction model for link prediction processing to obtain a link prediction result; wherein the prediction model is a machine learning model obtained based on a temporal knowledge graph, and includes an encoding part and a decoding part. During the link prediction processing, the encoding part is used to obtain a first temporal coding vector of the first entity object, and the decoding part is used to obtain the link prediction result based on the first temporal coding vector. In this way, the first entity object for link prediction is input into the prediction model to obtain a link prediction result, wherein the prediction model is a machine learning model obtained based on a temporal knowledge graph. Compared with the use of a static knowledge graph for link prediction in related technologies, this method uses a temporal knowledge graph to introduce time information into the knowledge graph, and can combine time information to predict the relationship between entities, thereby achieving more accurate link prediction, solving the problem of poor link prediction results in related technologies.
[0139] It is important to understand that Figures 1 to 6 The explanations of the same or corresponding steps in the above may refer to each other. For example, Figure 2 The explanation of step 210 and step 220 in Figure 5 Step 510 and step 520 in .
[0140] At the same time, it should be understood that a link prediction method provided in an embodiment of the present application may have the following beneficial effects: First, the link prediction method of the temporal knowledge graph can capture the temporal relationship between users and items, thereby improving the accuracy and prediction effect of personalized recommendations. By predicting the connection relationships that may be generated in the future, the evolution of user behavior and preferences can be better understood, thereby achieving more accurate recommendations. Second, by analyzing the link prediction results in the temporal knowledge graph, the potential temporal behavior patterns between users and items can be mined. This helps to understand the evolution of user behavior and the changes in the associations between items, thereby providing a deeper understanding and interpretation capability for the recommendation system. Third, the temporal knowledge graph link prediction method can help alleviate the cold start problem in the recommendation system. By analyzing the existing temporal knowledge graph data, new users and new items can be more accurately predicted and recommended, thereby improving the effect of the recommendation system in the cold start phase. Fourth, the temporal knowledge graph link prediction method can achieve dynamic optimization of recommendation results. By continuously updating the knowledge graph and prediction results, the recommendation system can timely reflect the changes in the relationship between users and items, thereby achieving real-time adjustment and optimization of the recommendation results. Fifth, the temporal knowledge graph link prediction method can support cross-domain recommendations. By fusing temporal knowledge graphs from different fields and analyzing the temporal relationship of the fused temporal knowledge graphs, cross-domain recommendations can be achieved, providing users with more diverse and rich recommendation services.
[0141] See also Figure 8 , Figure 8 is a structural block diagram of a link prediction device provided by an embodiment of the present application. Figure 8 As shown, an embodiment of the present application provides a link prediction device 800 , and the link prediction device 800 includes: an acquisition module 810 and a prediction module 820 .
[0142] The acquisition module 810 is used to acquire a first entity object for link prediction; The prediction module 820 is used to input the first entity object into the prediction model for link prediction processing to obtain a link prediction result; wherein the prediction model is a machine learning model obtained based on a temporal knowledge graph, and includes an encoding part and a decoding part. During the link prediction processing, the encoding part is used to obtain a first temporal coding vector of the first entity object, and the decoding part is used to obtain the link prediction result based on the first temporal coding vector.
[0143] In an embodiment of the present application, a first entity object for link prediction is obtained; the first entity object is input into a prediction model for link prediction processing to obtain a link prediction result; wherein the prediction model is a machine learning model obtained based on a temporal knowledge graph, and includes an encoding part and a decoding part. During the link prediction processing, the encoding part is used to obtain a first temporal coding vector of the first entity object, and the decoding part is used to obtain the link prediction result based on the first temporal coding vector. In this way, the first entity object for link prediction is input into the prediction model to obtain a link prediction result, wherein the prediction model is a machine learning model obtained based on a temporal knowledge graph. Compared with the use of a static knowledge graph for link prediction in related technologies, this method uses a temporal knowledge graph to introduce time information into the knowledge graph, and can combine time information to predict the relationship between entities, thereby achieving more accurate link prediction, solving the problem of poor link prediction results in related technologies.
[0144] The link prediction device provided in the embodiment of the present application can implement each process implemented in the above method embodiment, and will not be described again here to avoid repetition.
[0145] like Fig. 9As shown, an embodiment of the present application also provides an electronic device 900. The electronic device 900 includes: a processor 910 and a memory 920, and the memory 920 stores programs or instructions, and the programs or instructions implement the steps of any one of the methods described above when executed by the processor 910. For example, when the program is executed by the processor 910, the following process is implemented: obtaining a first entity object for link prediction; inputting the first entity object into a prediction model for link prediction processing to obtain a link prediction result; wherein the prediction model is a machine learning model obtained based on a temporal knowledge graph, and includes an encoding part and a decoding part, and during the link prediction processing, the encoding part is used to obtain a first temporal coding vector of the first entity object, and the decoding part is used to obtain the link prediction result based on the first temporal coding vector. In this way, the first entity object used for link prediction is input into the prediction model to obtain a link prediction result, wherein the prediction model is a machine learning model obtained based on a temporal knowledge graph. Compared with the use of a static knowledge graph for link prediction in related technologies, this method uses a temporal knowledge graph to introduce time information into the knowledge graph, and can combine time information to predict the relationship between entities, thereby achieving more accurate link prediction and solving the problem of poor link prediction results in related technologies.
[0146] An embodiment of the present application also provides a readable storage medium, on which a program or instruction is stored. When the program or instruction is executed by a processor, the steps of each embodiment of the link prediction method are implemented and the same technical effect can be achieved. To avoid repetition, it will not be repeated here.
[0147] The processor is the processor in the electronic device described in the above embodiment. The readable storage medium includes a computer readable storage medium, such as a computer read-only memory ROM, a random access memory RAM, a magnetic disk or an optical disk.
[0148] An embodiment of the present application further provides a chip, which includes a processor and a communication interface, wherein the communication interface is coupled to the processor, and the processor is used to run programs or instructions to implement the various processes of the above-mentioned method embodiment, and can achieve the same technical effect. To avoid repetition, it will not be repeated here.
[0149] An embodiment of the present application provides a computer program product, which is stored in a storage medium. The program product is executed by at least one processor to implement the various processes of the above-mentioned method embodiment and can achieve the same technical effect. To avoid repetition, it will not be repeated here.
[0150] It should be noted that, in this article, the term "comprises", "includes" or any other variant thereof is intended to cover non-exclusive inclusion, so that the process, method, article or device including a series of elements includes not only those elements, but also includes other elements not explicitly listed, or also includes elements inherent to such process, method, article or device. In the absence of further restrictions, the elements defined by the sentence "including one..." do not exclude the presence of other identical elements in the process, method, article or device including the element. In addition, it should be pointed out that the scope of the method and device in the embodiment of the present application is not limited to performing functions in the order shown or discussed, and may also include performing functions in a substantially simultaneous manner or in reverse order according to the functions involved, for example, the described method may be performed in an order different from that described, and various steps may also be added, omitted, or combined. In addition, the features described with reference to certain examples may be combined in other examples.
[0151] Through the description of the above implementation methods, those skilled in the art can clearly understand that the above-mentioned embodiment methods can be implemented by means of software plus a necessary general hardware platform, and of course by hardware, but in many cases the former is a better implementation method. Based on such an understanding, the technical solution of the present application, or the part that contributes to the prior art, can be embodied in the form of a computer software product, which is stored in a storage medium (such as ROM / RAM, a magnetic disk, or an optical disk), and includes a number of instructions for enabling a terminal (which can be a mobile phone, a computer, a server, or a network device, etc.) to execute the methods described in each embodiment of the present application.
[0152] The embodiments of the present application are described above in conjunction with the accompanying drawings, but the present application is not limited to the above-mentioned specific implementation methods. The above-mentioned specific implementation methods are merely illustrative and not restrictive. Under the guidance of the present application, ordinary technicians in this field can also make many forms without departing from the purpose of the present application and the scope of protection of the claims, all of which are within the protection of the present application.
Claims
1. A link prediction method, characterized in that: include: Obtaining a first entity object for link prediction; Inputting the first entity object into a prediction model to perform link prediction processing to obtain a link prediction result; Among them, the prediction model is a machine learning model obtained based on the temporal knowledge graph, and includes an encoding part and a decoding part. During the link prediction processing, the encoding part is used to obtain the first temporal coding vector of the first entity object, and the decoding part is used to obtain the link prediction result based on the first temporal coding vector.
2. The method according to claim 1, characterized in that The process of obtaining the prediction model includes: Based on the time series knowledge graph, a second time series coding vector is obtained, wherein the second time series coding vector includes an entity embedding vector, a relationship embedding vector and a timestamp embedding vector; the entity embedding vector is a vector representation of a node, including feature information of the node; the relationship embedding vector is a vector representation of an edge, used to represent the attributes of the relationship between nodes; the timestamp embedding vector is a vector representation of time information, and the time information provides a time context for the occurrence of an event; Based on the second temporal coding vector, a processing result for link prediction is obtained.
3. The method according to claim 2, characterized in that The obtaining of a second temporal coding vector based on the temporal knowledge graph includes: Based on the time series knowledge graph, determine a node feature matrix and an adjacency matrix, wherein the node feature matrix is used to represent the attribute information of each node in the time series knowledge graph, and the adjacency matrix is used to represent the connection relationship between the nodes in the time series knowledge graph; Normalizing the time information in the time series knowledge graph to obtain a target time series; The target time series, the node feature matrix and the adjacency matrix are input into a time recurrent neural network to obtain a second time series encoding vector.
4. The method according to claim 3, characterized in that The time recurrent neural network includes a bidirectional long short-term memory neural network, and the bidirectional long short-term memory neural network includes a first long short-term memory neural network for forward learning and a second long short-term memory neural network for reverse learning; The step of inputting the target time series, the node feature matrix and the adjacency matrix into a time recurrent neural network to obtain a second time series encoding vector comprises: Inputting the target time series, the node feature matrix and the adjacency matrix into the first long short-term memory neural network and the second long short-term memory neural network; The target time series, the node feature matrix and the adjacency matrix are processed by the first long short-term memory neural network to obtain a first processing result; the first processing result is a result obtained by processing in a direction from the beginning to the end of the target time series; The target time series, the node feature matrix and the adjacency matrix are processed by the second long short-term memory neural network to obtain a second processing result; the second processing result is a result obtained by processing in a direction from the end to the beginning of the target time series; Based on the first processing result and the second processing result, a second temporal coding vector is obtained.
5. The method according to claim 2, characterized in that: The obtaining a processing result for link prediction based on the second temporal coding vector includes: Performing feature extraction on the second temporal coding vector to obtain a first feature graph, where the first feature graph includes local features of the node; Performing weighted processing on the first feature map through an attention mechanism to obtain a second feature map; Based on the first feature map and the second feature map, a processing result for link prediction is obtained.
6. The method according to claim 5, characterized in that The number of the second temporal coding vectors is n groups, the number of the first feature graphs is n, the n first feature graphs are obtained based on the n groups of second temporal coding vectors, and n is a positive integer greater than 1; The obtaining a processing result for link prediction based on the first feature graph and the second feature graph includes: Perform a sum operation on the n first feature maps to obtain a sum result; Based on the summation result and the second feature map, a processing result for link prediction is obtained.
7. The method according to claim 3, characterized in that The node feature matrix includes a target element, and the target element is obtained based on averaging specified statistical values of the same node in the temporal knowledge graph at different unit times.
8. The method according to any one of claims 1 to 7, characterized in that: The temporal knowledge graph is a temporal knowledge graph oriented to a recommendation field, and the link prediction result is a recommendation result oriented to the first entity object.
9. An electronic device, characterized in that: The method comprises a processor and a memory, wherein the memory stores a program or instruction running on the processor, and when the program or instruction is executed by the processor, the steps of the method according to any one of claims 1 to 8 are implemented.
10. A computer-readable storage medium, characterized in that: The medium stores a program or an instruction, and when the program or the instruction is executed, the steps of the method according to any one of claims 1 to 8 are implemented.