Knowledge representation learning model training, link prediction and triple evaluation method
By building a knowledge representation learning model containing rotating translation and relational mapping attributes, the shortcomings of existing models in dealing with complex relationships and dynamic knowledge graphs are solved, and more efficient and accurate entity relationship representation and link prediction are achieved.
Patent Information
- Application Number
- CN202510511775.3
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2025-04-22
- Publication Date
- 2025-08-12
AI Technical Summary
The existing knowledge representation learning model is difficult to effectively distinguish entities with similar attributes when dealing with large, complex and dynamic knowledge graphs, dealing with complex relationship types and adapting to real-time update requirements, resulting in inefficiency and insufficient accuracy.
By constructing an initial learning model, a vector representation containing entity embedding vectors, rotation angles and relationship mapping properties is generated. The model is trained using positive and negative samples, allowing entities to rotate map on the relational hyperplane, quantify the number of entity associations, and improve the model's representation flexibility and learning ability.
It improves the accuracy and generalization ability of the model when dealing with complex relationships, can better understand the relationship properties between entities, adapt to the dynamic changes of the knowledge graph, and enhances the performance of the model on unseen data.
Smart Images

Figure CN120471149A_ABST
Abstract
Description
Technical Field
[0001] The present application relates to the field of machine learning technology, and more specifically, to a knowledge representation learning model training, link prediction, and triple evaluation method. Background Art
[0002] In recent years, knowledge representation learning methods have attracted widespread attention from researchers due to their ability to efficiently represent entities and relations in low-dimensional continuous vector spaces. Among them, translation-based methods (such as TransE, TransH, TransR, etc.) simulate actual relationships by assuming that entities "move" in relationships, greatly simplifying the complexity of traditional representations and providing powerful tools for tasks such as link prediction and relational reasoning in knowledge graphs. However, as the scale of knowledge graphs continues to expand, traditional symbolic logic-based representation methods have gradually exposed problems such as low efficiency and lack of flexibility, especially when dealing with large, complex, and dynamic knowledge graphs. In addition, this series of models still have limitations in handling complex one-to-many or many-to-one relationship mappings, capturing subtle differences between entities, and updating dynamic changes in knowledge graphs.
[0003] On the one hand, the diversity of entities and the complexity of relationships require knowledge representation learning models to possess stronger expressive capabilities. Existing models often struggle to effectively distinguish entities with similar attributes or accurately model complex relationships, such as asymmetric and inverse relationships. On the other hand, the dynamic nature of data requires models to quickly respond to the addition of new samples to maintain the timeliness and accuracy of representation. However, the fixed structure of existing models makes it difficult to adapt to the real-time updates required by large-scale knowledge graphs.
[0004] To address the above-mentioned problems, no effective solutions have been proposed so far. Summary of the Invention
[0005] The embodiments of the present application provide a method for knowledge representation learning model training, link prediction, and triple evaluation to at least solve the technical problem that related knowledge representation learning models are difficult to meet requirements when processing complex relationships.
[0006] According to one aspect of an embodiment of the present application, a knowledge representation learning model training method is provided, comprising: obtaining structured data of a target domain, and extracting multiple triplets from the structured data, wherein each triplet includes: a head entity, a relationship, and a tail entity; for each triplet, taking the triplet as a positive sample, and constructing a negative sample corresponding to the positive sample; constructing an initial learning model, wherein the initial learning model is used to generate a vector representation corresponding to the input triplet, the vector representation including: a first embedding vector and a first angle corresponding to the target head entity in the input triplet, a second embedding vector and a second angle corresponding to the target relationship, a third embedding vector and a third angle corresponding to the target tail entity, and a relationship mapping attribute, wherein the first embedding vector is rotated by the first angle to obtain a vector mapping the target head entity to the hyperplane corresponding to the target relationship, the second embedding vector is rotated by the second angle to obtain a vector mapping the target relationship to the hyperplane, and the third embedding vector is rotated by the third angle to obtain a vector mapping the target tail entity to the hyperplane, and the relationship mapping attribute is used to reflect the number of tail entities associated with the target head entity and the number of head entities associated with the target tail entity; and the initial learning model is trained using multiple positive and negative samples to obtain a knowledge representation learning model for the target domain.
[0007] Optionally, after extracting multiple triples from the structured data, the above method also includes: for each head entity in the multiple triples, counting the first number of tail entities associated with the head entity; for each tail entity in the multiple triples, counting the second number of head entities associated with the tail entity.
[0008] Optionally, for each triple, the triple is used as a positive sample, and a negative sample corresponding to the positive sample is constructed, including: performing hierarchical clustering on multiple head entities in multiple triples to obtain multiple first clusters, and performing hierarchical clustering on multiple tail entities in multiple triples to obtain multiple second clusters; for each triple, the triple is used as a positive sample; and using a probabilistic method to determine whether to replace the first head entity or the first tail entity in the triple, wherein the probability of replacing the first head entity is: The probability of replacing the first tail entity is: In the formula, num h The first number of tail entities associated with the first head entity, num tis the second number of head entities associated with the first tail entity; in the case of replacing the first head entity, the semantic similarities between the other head entities in the cluster to which the first head entity belongs and the first head entity are determined respectively, and the first head entity in the triplet is replaced with the other head entities with the largest semantic similarity to obtain a negative sample corresponding to the positive sample; in the case of replacing the first tail entity, the semantic similarities between the other tail entities in the cluster to which the first tail entity belongs and the first tail entity are determined respectively, and the first tail entity in the triplet is replaced with the other tail entities with the largest semantic similarity to obtain a negative sample corresponding to the positive sample.
[0009] Optionally, the initial learning model is trained using multiple positive samples and negative samples to obtain a knowledge representation learning model of the target domain, including: in each training batch, the positive samples and negative samples corresponding to the training batch are input into the initial learning model in sequence to obtain the vector representations corresponding to the positive samples and negative samples; for each positive sample or negative sample, the relationship score corresponding to the positive sample or negative sample is determined based on the first embedding vector, first angle, second embedding vector, second angle, third embedding vector, third angle and relationship mapping attributes in the vector representation corresponding to the positive sample or negative sample; a target loss function is constructed based on the relationship scores corresponding to the positive samples and negative samples; and the model parameters of the initial learning model are adjusted based on the target loss function.
[0010] Optionally, determining a relationship score corresponding to the positive sample or the negative sample based on a first embedding vector, a first angle, a second embedding vector, a second angle, a third embedding vector, a third angle, and a relationship mapping attribute in a vector representation corresponding to the positive sample or the negative sample includes: determining a relationship score corresponding to the input sample according to the following formula:
[0011] f r (h,t)=w r ·‖h * cosθ h +r * cosθ r +t * cosθ t ‖ L1 / L2
[0012] In the formula, h, r, and t represent the target head entity, target relation, and target tail entity in the triplet corresponding to the input sample, respectively. r (h, t) represents the relationship score of the input sample, w r represents a relational mapping attribute, and num h The first number of tail entities associated with the target head entity, num t The second number of head entities associated with the target tail entity, h * and θh They represent the first embedding vector and the first angle corresponding to the target head entity, r * and θ r Represent the second embedding vector and the second angle corresponding to the target relationship, t * and θ t Represent the third embedding vector and third angle corresponding to the target tail entity, ‖*‖ L1 / L2 Indicates taking L1 or L2 norm.
[0013] Optionally, constructing a target loss function based on the relationship scores corresponding to each positive sample and negative sample includes: determining the target loss function according to the following formula:
[0014]
[0015] Where L represents the target loss function, (h, r, t) represents the positive sample, S represents the set of positive samples in the current training batch, and f r (h, t) represents the relationship score corresponding to the positive sample, (h′, r′, t′) represents the negative sample, S′ represents the set of negative samples in the current training batch, and f r′ (h′, t′) represents the relationship score corresponding to the negative sample, and λ is a preset coefficient used to control the difference in the relationship score between positive and negative samples.
[0016] Optionally, the above method also includes: periodically obtaining updated structured data in the target field, and using the updated structured data to generate multiple new positive samples and negative samples; using multiple new positive samples and negative samples to train the knowledge representation learning model again, and updating the model parameters of the knowledge representation learning model.
[0017] According to another aspect of an embodiment of the present application, a link prediction method is also provided, including: obtaining an input first entity and a first relationship, and determining multiple candidate second entities; for each second entity, forming a candidate triple with the second entity, the first entity, and the first relationship; analyzing the candidate triple using a knowledge representation learning model to obtain a vector representation corresponding to the candidate triple, and determining a relationship score corresponding to the candidate triple based on the vector representation, wherein the knowledge representation learning model is trained by the above-mentioned knowledge representation learning model training method; determining the second entity with the highest corresponding relationship score as the target entity matching the first entity and the first relationship.
[0018] According to another aspect of an embodiment of the present application, a triple evaluation method is also provided, including: obtaining a triple to be evaluated; analyzing the triple using a knowledge representation learning model to obtain a vector representation corresponding to the triple, and determining a relationship score corresponding to the triple based on the vector representation, wherein the knowledge representation learning model is trained by the above-mentioned knowledge representation learning model training method; and determining a matching status between the triple and the target domain based on the relationship score.
[0019] According to another aspect of the embodiment of the present application, a knowledge representation learning model training device is also provided, including: an acquisition module for acquiring structured data of a target domain and extracting multiple triples from the structured data, wherein each triple includes: a head entity, a relationship, and a tail entity; a sample generation module for treating each triple as a positive sample and constructing a negative sample corresponding to the positive sample; a model construction module for constructing an initial learning model, wherein the initial learning model is used to generate a vector representation corresponding to the input triple, and the vector representation includes: a first embedding vector and a first angle corresponding to the target head entity in the input triple, and a vector representation corresponding to the target relationship. The second embedding vector and the second angle, the third embedding vector and the third angle corresponding to the target tail entity, and the relationship mapping attribute. After the first embedding vector is rotated by the first angle, the target head entity is mapped to the vector on the hyperplane corresponding to the target relationship. After the second embedding vector is rotated by the second angle, the target relationship is mapped to the vector on the hyperplane. After the third embedding vector is rotated by the third angle, the target tail entity is mapped to the vector on the hyperplane. The relationship mapping attribute is used to reflect the number of tail entities associated with the target head entity and the number of head entities associated with the target tail entity; a model training module is used to train the initial learning model using multiple positive samples and negative samples to obtain a knowledge representation learning model for the target domain.
[0020] According to another aspect of an embodiment of the present application, a computer program product is also provided, which includes: a computer program, wherein when the computer program is executed by a processor, it implements the above-mentioned knowledge representation learning model training method, or the above-mentioned link prediction method, or the above-mentioned triple evaluation method.
[0021] According to another aspect of an embodiment of the present application, an electronic device is also provided, which includes: a memory and a processor, wherein a computer program is stored in the memory, and the processor is configured to execute the above-mentioned knowledge representation learning model training method, or the above-mentioned link prediction method, or the above-mentioned triple evaluation method through the computer program.
[0022] In an embodiment of the present application, by extracting a set of triples from structured data and dividing them into positive and negative samples, it is beneficial to improve the generalization ability of the model; then, an initial learning model is constructed, which can convert the input triples into vector representations. In the vector representation, the head entity, the relationship, and the tail entity each correspond to a specific embedding vector and angle, as well as a relationship mapping attribute. Rotation translation is introduced into the model, allowing entities to be rotated and mapped on the relationship hyperplane, breaking the limitations of traditional vector addition and improving the representation flexibility and learning ability of the model. In addition, the introduced relationship mapping attribute quantifies the number of entity associations, so that the model can better understand the nature of the relationship between entities and help to handle complex one-to-many and many-to-one relationships. Finally, the initial learning model is trained using multiple positive and negative samples to obtain a knowledge representation learning model for the target domain. The training of positive and negative samples can enable the model to learn more accurate entity and relationship representations, and the model can better generalize to unseen data, thereby improving the accuracy of the model in processing knowledge representation-related tasks, thereby solving the technical problem that the relevant knowledge representation learning model is difficult to meet the requirements when processing complex relationships. BRIEF DESCRIPTION OF THE DRAWINGS
[0023] The drawings described herein are used to provide a further understanding of the present application and constitute a part of the present application. The illustrative embodiments of the present application and their descriptions are used to explain the present application and do not constitute an improper limitation on the present application. In the drawings:
[0024] Figure 1 is a flowchart of an optional knowledge representation learning model training method according to an embodiment of the present application;
[0025] Figure 2 This is an optional knowledge representation learning model processing logic diagram according to an embodiment of the present application;
[0026] Figure 3 is a flowchart of an optional link prediction method according to an embodiment of the present application;
[0027] Figure 4 is a flow chart of an optional triplet evaluation method according to an embodiment of the present application;
[0028] Figure 5 is a schematic structural diagram of an optional knowledge representation learning model training device according to an embodiment of the present application;
[0029] Figure 6 This is a schematic diagram of an optional electronic device structure according to an embodiment of the present application. DETAILED DESCRIPTION
[0030] In order to enable those skilled in the art to better understand the present invention, the following will clearly and completely describe the technical solutions in the embodiments of the present invention in conjunction with the drawings in the embodiments of the present invention. Obviously, the described embodiments are only part of the embodiments of the present invention, not all of the embodiments. Based on the embodiments in the present invention, all other embodiments obtained by ordinary technicians in this field without making creative efforts should fall within the scope of protection of this application.
[0031] It should be noted that the terms "first", "second", etc. in the specification, claims, and drawings of the present application are used to distinguish similar objects and are not necessarily used to describe a specific order or sequential order. It should be understood that the data used in this way can be interchangeable where appropriate, so that the embodiments of the present application described herein can be implemented in an order other than those illustrated or described herein. In addition, the terms "including" and "having" and any variations thereof are intended to cover non-exclusive inclusions, for example, a process, method, system, product, or device comprising a series of steps or units is not necessarily limited to those steps or units clearly listed, but may include other steps or units that are not clearly listed or inherent to these processes, methods, products, or devices.
[0032] In order to better understand the embodiments of the present application, some nouns or terms that appear in the description of the embodiments of the present application are first translated and explained as follows:
[0033] TransH model: is a knowledge graph embedding learning model that aims to address the limitations of the TransE model in dealing with the diversity of relationships between entities. The TransE model assumes that all entity relationships can be represented by simple vector addition in a unified vector space, that is, for a triple ((h, r, t)), its mathematical representation is h+r=t. However, the TransE model ignores the differences in the roles of entities in different relationships, resulting in inaccurate representations of one-to-many, many-to-one, or symmetric relationships. The TransH model improves this by introducing hyperplanes and projection mechanisms. TransH defines a hyperplane for each relationship, and in the context of relationship r, the head entity h and the tail entity t are projected onto the hyperplane to capture the changes in the roles of entities in different relationships.
[0034] Example 1
[0035] According to an embodiment of the present application, a knowledge representation learning model training method is provided. It should be noted that the steps shown in the flowchart of the accompanying drawings can be executed in a computer system such as a set of computer-executable instructions, and although a logical order is shown in the flowchart, in some cases, the steps shown or described can be executed in an order different from that shown here.
[0036] Figure 1 This is a flow chart of a knowledge representation learning model training method provided in accordance with an embodiment of the present application. Figure 1 As shown, the method includes the following steps:
[0037] Step S102: acquiring structured data of the target domain, and extracting a plurality of triples from the structured data, wherein each triple includes: a head entity, a relationship, and a tail entity.
[0038] Figure 2 The schematic diagram of knowledge representation learning model processing logic is shown as follows: Figure 2 As shown in (a), each triple can be represented as (h, r, t), where h is the head entity, r represents the relationship, and t is the tail entity.
[0039] Step S104: for each triplet, take the triplet as a positive sample and construct a negative sample corresponding to the positive sample.
[0040] Step S106, constructing an initial learning model, wherein the initial learning model is used to generate a vector representation corresponding to the input triple, the vector representation including: a first embedding vector and a first angle corresponding to the target head entity in the input triple, a second embedding vector and a second angle corresponding to the target relationship, a third embedding vector and a third angle corresponding to the target tail entity, and a relationship mapping attribute, wherein the first embedding vector is rotated by the first angle to obtain a vector on the hyperplane corresponding to the target relationship mapped to the target head entity, the second embedding vector is rotated by the second angle to obtain a vector on the hyperplane mapped to the target relationship, and the third embedding vector is rotated by the third angle to obtain a vector on the hyperplane mapped to the target tail entity, and the relationship mapping attribute is used to reflect the number of tail entities associated with the target head entity and the number of head entities associated with the target tail entity.
[0041] like Figure 2 As shown in (b), in the traditional TransH model, for each relation r, TransH defines a hyperplane, which is represented by a normal vector and a translation vector. The head entity h and the tail entity t are first projected onto the hyperplane of the relation r to obtain the projection vector h ⊥ and t ⊥ .
[0042] In order to reduce the constraint that head entity + relation = tail entity and make the translation rules more flexible, the translation rules are improved on the basis of the traditional TransH model, and the rotation translation rule is added. The initial learning model is introduced, which is used to generate the vector representation corresponding to the triple. Among them, the vector representation corresponding to the triple includes: the first embedding vector h corresponding to the head entity h * and the first angle θ h , the second embedding vector r corresponding to the relation r* and the second angle θ r , the third embedding vector t corresponding to the tail entity t * and the third angle θ t In order to further enhance the model’s ability to handle complex relationships, the vector representation corresponding to the triple also includes the relationship mapping attribute w corresponding to the tail entity t r , the relationship mapping attribute is used to reflect the number of tail entities associated with the target head entity num h and the number of head entities num associated with the target tail entity t .
[0043] Figure 2 (c) shows: where the first embedding vector h * Rotate the first angle θ h Then we get the vector on the hyperplane corresponding to the target relationship mapped to the target head entity, and the second embedding vector r * Rotate the second angle θ r Then we get the vector of the target relationship mapped to the hyperplane, and the third embedding vector t * Rotate the third angle θ t Then we get the vector of the target tail entity mapped to the hyperplane.
[0044] Step S108: train the initial learning model using multiple positive samples and negative samples to obtain a knowledge representation learning model for the target domain.
[0045] In the above steps, the triples are converted into the vector representation corresponding to the triples, and the relationship mapping attribute is added in the vector representation process to enhance the learning ability of the model. Then, based on the translation rules, rotation translation is introduced to reduce the constraint that head entity + relationship = tail entity, thereby making the model perform better in knowledge representation learning, and solving the technical problem that related knowledge representation learning models are difficult to meet the requirements when dealing with complex relationships.
[0046] The following describes the various steps of the knowledge representation learning model training method in combination with the specific implementation process.
[0047] As an optional implementation, in order to obtain relationship mapping attributes, after extracting multiple triples from structured data, for each head entity in the multiple triples, the first number of tail entities associated with the head entity is counted; for each tail entity in the multiple triples, the second number of head entities associated with the tail entity is counted.
[0048] For each head entity, the first number of tail entities associated with the head entity is marked as num h For each tail entity, the second number of head entities associated with the tail entity can be marked as num t. Further, for the num obtained by statistics t and num t We can further obtain the statistical relationship mapping attributes, which can be expressed as That is, the mapping relationship attribute is represented by num t with num t The sum is determined by taking the reciprocal of the logarithm.
[0049] As an optional implementation, for each triple, the triple is regarded as a positive sample, and a negative sample corresponding to the positive sample can be constructed in the following manner: hierarchical clustering is performed on multiple head entities in multiple triples to obtain multiple first clusters, and hierarchical clustering is performed on multiple tail entities in multiple triples to obtain multiple second clusters; for each triple, the triple is regarded as a positive sample; and a probability method is used to determine whether to replace the first head entity or the first tail entity in the triple, wherein the probability of replacing the first head entity is: The probability of replacing the first tail entity is: In the formula, num h The first number of tail entities associated with the first head entity, num t is the second number of head entities associated with the first tail entity; in the case of replacing the first head entity, the semantic similarities between the other head entities in the cluster to which the first head entity belongs and the first head entity are determined respectively, and the first head entity in the triplet is replaced with the other head entities with the largest semantic similarity to obtain a negative sample corresponding to the positive sample; in the case of replacing the first tail entity, the semantic similarities between the other tail entities in the cluster to which the first tail entity belongs and the first tail entity are determined respectively, and the first tail entity in the triplet is replaced with the other tail entities with the largest semantic similarity to obtain a negative sample corresponding to the positive sample.
[0050] In the above process, we focus on how to select appropriate entities based on hierarchical clustering through probabilistic methods and semantic similarity to enhance the effectiveness of model training. Specifically, generating negative samples can be achieved through the following steps:
[0051] Step S1, hierarchical clustering.
[0052] Hierarchical clustering is performed on multiple head entities in multiple triples to obtain multiple first clusters. Hierarchical clustering is an unsupervised learning method used to group data points. In this application, this method is used to group head entities in a knowledge graph into multiple clusters. The head entities within each cluster have high similarity, which facilitates the generation of negative samples later, ensuring that the replaced entities are semantically close to the original entities.
[0053] Hierarchical clustering is performed on the multiple tail entities in multiple triples to obtain multiple secondary clusters. Similar to the head entities, the tail entities are also hierarchically clustered into multiple clusters to form secondary clusters. This step ensures that the tail entities are also well grouped by similarity, providing a basis for subsequent entity replacement.
[0054] Step S2: define positive samples.
[0055] For each triple, we consider it as a positive sample; a positive sample refers to the triple used to represent the real relationship during training. In the knowledge graph, every real triple is a positive sample, which reflects the actual relationship between entities.
[0056] Step S3: Determine the probability of entity replacement.
[0057] The probability method is used to determine whether to replace the first head entity or the first tail entity in the triple. The probability of replacing the first head entity is expressed as where num h The first number of tail entities associated with the first head entity, num t The second number of head entities associated with the first tail entity. This probability calculation method takes into account the connection characteristics of entities in the network, that is, the number of other entities associated with an entity, which helps to make reasonable entity replacement decisions in one-to-many or one-to-one relationships.
[0058] Step S4: Entity replacement based on semantic similarity.
[0059] When replacing the first head entity, the semantic similarity between the first head entity and the other head entities in the cluster to which the first head entity belongs is determined, and the first head entity is replaced with the other head entity with the greatest semantic similarity to obtain a negative sample corresponding to the positive sample. In this step, the semantic similarity between entities is evaluated by calculating the distance or similarity metric between their vector representations, such as using cosine similarity or Euclidean distance. Selecting the most similar entity for replacement can ensure that the negative sample remains consistent with the positive sample to a certain extent, which helps the model learn to distinguish between real and false relationships.
[0060] When replacing the first tail entity, the semantic similarity between the first tail entity and the other tail entities in the cluster to which the first tail entity belongs is determined. The first tail entity is then replaced with the other tail entity with the greatest semantic similarity, resulting in a negative sample corresponding to the positive sample. Similarly, a strategy based on semantic similarity is also used for tail entity replacement. This ensures that even negative samples are entity replacements within a similar semantic space, thereby improving the efficiency and effectiveness of model training.
[0061] Through the above steps S1 to S4, positive samples and negative samples can be divided, and multiple positive samples and negative samples can be input into the initial learning model for training to obtain a knowledge representation learning model of the target domain. This can be specifically achieved in the following way: in each training batch, each positive sample and negative sample corresponding to the training batch is input into the initial learning model in turn to obtain a vector representation corresponding to each positive sample and negative sample; for each positive sample or negative sample, the relationship score corresponding to the positive sample or negative sample is determined based on the first embedding vector, first angle, second embedding vector, second angle, third embedding vector, third angle and relationship mapping attribute in the vector representation corresponding to the positive sample or negative sample; a target loss function is constructed based on the relationship scores corresponding to each positive sample and negative sample; and the model parameters of the initial learning model are adjusted based on the target loss function.
[0062] In each training batch, a set of positive sample triplets (h, r, t) and a set of negative sample triplets (h′, r′, t′) are selected and input into the initial learning model to obtain the vector representations corresponding to each positive sample and negative sample. The initial learning model maps each entity to the corresponding hyperplane and obtains their embedded vector representations through a rotation mechanism. The embedded vector representations include the first embedding vector, the first angle, the second embedding vector, the second angle, the third embedding vector, the third angle and the relationship mapping attributes.
[0063] Optionally, for each positive sample or negative sample, the relationship score corresponding to the positive sample or negative sample is determined based on the first embedding vector, the first angle, the second embedding vector, the second angle, the third embedding vector, the third angle, and the relationship mapping attribute in the vector representation corresponding to the positive sample or negative sample. The relationship score corresponding to the input sample can be determined by the following formula:
[0064] f r (h,t)=w r ·‖h * cosθ h +r * cosθ r +t * cosθ t ‖ L1 / L2
[0065] Among them, h, r, and t represent the target head entity, target relation, and target tail entity in the triplet corresponding to the input sample, respectively, and f r (h, t) represents the relationship score of the input sample, w r represents a relational mapping attribute, and num h The first number of tail entities associated with the target head entity, num t The second number of head entities associated with the target tail entity, h* and θ h They represent the first embedding vector and the first angle corresponding to the target head entity, r * and θ r Represent the second embedding vector and the second angle corresponding to the target relationship, t * and θ t Represent the third embedding vector and third angle corresponding to the target tail entity, ‖*‖ L1 / L2 Indicates taking L1 or L2 norm.
[0066] The above function takes into account the influence of the rotation distance between entities, the contribution of the relationship vector and the weight of the relationship mapping attributes.
[0067] For each positive sample and negative sample obtained, the relationship score is calculated respectively, and the target loss function is constructed. The target loss function can be determined in the following way:
[0068]
[0069] Among them, L represents the target loss function, (h, r, t) represents the positive sample, S represents the positive sample set in the current training batch, and f r (h, t) represents the relationship score corresponding to the positive sample, (h′, r′, t′) represents the negative sample, S′ represents the set of negative samples in the current training batch, and f r′ (h′, t′) represents the relationship score corresponding to the negative sample, and λ is a preset coefficient used to control the difference in the relationship score between positive and negative samples.
[0070] The target loss function requires that the relationship score corresponding to the positive sample be lower than the sum of the relationship score of the negative sample and the coefficient λ, thereby ensuring that the score of the positive sample is significantly higher than that of the negative sample.
[0071] In addition, the dynamics and adaptability of the knowledge representation learning model can be improved by: periodically obtaining updated structured data in the target domain, and using the updated structured data to generate multiple new positive and negative samples; using multiple new positive and negative samples to train the knowledge representation learning model again and update the model parameters of the knowledge representation learning model.
[0072] Specifically, a fixed time interval or update cycle can be set, such as daily, weekly, or monthly, and adjusted based on the frequency of real-time data updates for the target domain (e.g., the Shanghai agricultural product market). During this cycle, the latest structured data for the target domain, such as new agricultural product entities, attribute information, price changes, and sales trends, can be automatically captured and integrated through crawler technology, API calls, or data sharing protocols.
[0073] Preprocess the acquired updated data, including data cleaning, standardization, and entity alignment. Ensure the quality and consistency of the newly acquired data so that it can be seamlessly integrated with the data in the existing knowledge graph.
[0074] The updated structured data is converted into a triple format, becoming a new set of positive samples. Simultaneously, a set of negative samples corresponding to the new positive samples is generated using the negative example generation strategy described in this paper. This is done to simulate relationships that do not exist in the knowledge graph, thereby enhancing the model's generalization capabilities.
[0075] The updated positive and negative sample sets are used to retrain the knowledge representation learning model. The model will reconstruct the target loss function based on the relationship scores of the new samples and adjust the model parameters through optimization algorithms such as gradient descent.
[0076] In the above steps, first, a set of triples is extracted from structured data and divided into positive and negative samples, which helps improve the model's generalization ability. Then, an initial learning model is constructed, which can convert the input triples into vector representations. In the vector representation, the head entity, relationship, and tail entity each correspond to a specific embedding vector and angle, as well as a relationship mapping attribute. The model introduces rotation translation, allowing entities to be rotated and mapped on the relationship hyperplane, breaking the limitations of traditional vector addition and improving the model's representation flexibility and learning ability. In addition, the introduced relationship mapping attribute quantifies the number of entity associations, allowing the model to better understand the nature of the relationship between entities and facilitate the processing of complex one-to-many and many-to-one relationships. Finally, the initial learning model is trained using multiple positive and negative samples to obtain a knowledge representation learning model for the target domain. Training with positive and negative samples enables the model to learn more accurate entity and relationship representations, better generalize to unseen data, and improve the model's accuracy in processing knowledge representation-related tasks, thus solving the technical problem that related knowledge representation learning models have difficulty meeting requirements when processing complex relationships.
[0077] Example 2
[0078] According to an embodiment of the present application, a link prediction method is also provided to implement the application of the knowledge representation learning model in Example 1. Figure 3 A schematic flow chart of a link prediction method is shown. Specifically, the link prediction method includes:
[0079] Step S302: obtaining the input first entity and first relationship, and determining multiple candidate second entities;
[0080] Step S304: for each second entity, combine the second entity, the first entity, and the first relationship into a candidate triple;
[0081] Step S306: Analyze the candidate triples using the knowledge representation learning model to obtain vector representations corresponding to the candidate triples, and determine the relationship scores corresponding to the candidate triples based on the vector representations, wherein the knowledge representation learning model is trained using the above-mentioned knowledge representation learning model training method;
[0082] Step S308: Determine the second entity with the highest corresponding relationship score as the target entity that matches the first entity and the first relationship.
[0083] The following describes each step of the link prediction method in detail in conjunction with the specific implementation process.
[0084] Assume that in a knowledge question-answering system, the core entity (first entity) and relationship (first relationship) are first extracted from the user's question or sentence. For example, if the question is "Which Shanghai agricultural product brand has the highest sales?", then "Shanghai agricultural product brand" is the first entity and "highest sales" is the first relationship.
[0085] For user questions, extracting input entities and relationships can ensure that the system can accurately identify the user's query intent and provide a clear direction for subsequent matching and prediction.
[0086] Based on the input first entity and first relationship, the knowledge graph is searched for possible related entities as candidate second entities. For example, for the above question, candidate entities might be Shanghai agricultural product brands such as "Gucang", "Zhu Yu", and "Huang Mu".
[0087] For each candidate second entity, combine it with the first entity and the first relationship to form a candidate triple. For example, multiple triples might be formed, such as ("Shanghai agricultural product brand", "highest sales", "barn"), ("Shanghai agricultural product brand", "highest sales", "pearls and jade"), and so on. This step ensures that all possible entity pairings are considered, providing a comprehensive foundation for finding the most appropriate answer entity.
[0088] The trained knowledge representation learning model then performs an in-depth analysis of multiple triples, obtaining corresponding vector representations and calculating relationship scores. The scoring function takes into account factors such as the rotation angle of the entity embedding vector and relationship mapping properties. By calculating the distance or similarity between vectors, the model quantifies the degree of match between candidate entities and the questioned entity and relationship, thereby identifying the most likely answer. The introduction of rotation, translation, and relationship mapping properties into the model enables it to handle complex one-to-many and many-to-one relationships, improving the accuracy of entity matching in complex knowledge graphs.
[0089] Finally, the second entity with the highest relationship score is selected from the candidate entities as the target entity. This entity is most likely to form a correct triple with the first entity and the first relationship. For example, for the above question, the system would return "barn" as the answer if it is the brand with the highest sales. By selecting the highest-scoring entity, the credibility and quality of the answer are improved, ensuring the accuracy of the knowledge question answering system.
[0090] The above-mentioned link prediction method has demonstrated significant advantages in the knowledge question-answering scenario. The knowledge question-answering system implanted with the knowledge representation learning model can accurately interpret the user's query intention and extract key entities and relationships from complex sentences; construct multiple candidate triples and conduct a comprehensive search in the knowledge graph, but can focus on highly relevant entities, avoiding the waste of resources caused by blind search; the knowledge representation learning model conducts a detailed evaluation of the candidate triples to ensure the high quality and reliability of the matching answers, even in the face of complex relationships; and finally, it can quickly provide answers to questions, improving the immediacy of the service and user experience.
[0091] It should be noted that the training of the knowledge representation learning model in the embodiment of the present application corresponds one-to-one to the steps in the training method of the knowledge representation learning model in Example 1, and will not be repeated here.
[0092] Example 3
[0093] According to an embodiment of the present application, a triple evaluation method is also provided to implement the application of the knowledge representation learning model in Example 1. Figure 4 A schematic flow chart of a triplet evaluation method is shown. Specifically, the triplet evaluation method includes:
[0094] Step S402, obtaining a triplet to be evaluated;
[0095] Step S404: Analyze the triples using a knowledge representation learning model to obtain vector representations corresponding to the triples, and determine the relationship scores corresponding to the triples based on the vector representations, wherein the knowledge representation learning model is trained using the above-mentioned knowledge representation learning model training method;
[0096] Step S406: determining the matching status between the triple and the target domain based on the relationship score.
[0097] The following describes each step of the triple evaluation method in detail in conjunction with the specific implementation process.
[0098] Considering that in the maintenance and expansion of knowledge graphs, it is often necessary to classify newly captured or user-submitted triples to determine whether they belong to the target domain, or their authenticity and rationality in the knowledge graph.
[0099] For example, in the question-answering system of Shanghai agricultural products, the system may receive the triple "(Chongming District, main product, hairy crab)" submitted by the user, and needs to verify and confirm whether this triple data should be included in the agricultural products knowledge graph.
[0100] Submitted triples can be evaluated using a trained knowledge representation learning model. The model first generates a vector representation for each entity and relationship in the triple, including the corresponding embedding vector and rotation angle, as well as the relationship mapping attributes. It then calculates a score for the triple, which reflects the triple's plausibility within the knowledge graph. A higher score indicates a closer match between the triple and the graph. Through vector representation, the model can gain a deeper understanding of the semantics of entities and relationships, enabling refined scoring of triples. This scoring mechanism can quickly distinguish between real and fake triples, avoiding the storage and processing of large amounts of invalid or erroneous information and improving the efficiency of knowledge graph maintenance.
[0101] Based on the scoring results, the matching status of the evaluated triplet with the target domain (e.g., the Shanghai Agricultural Products Knowledge Graph) is determined. Specifically, if the score is higher than a pre-set threshold, it means that the triplet belongs to the target domain and can be included in the graph; otherwise, it is marked as not belonging to the target domain or as potential erroneous information.
[0102] By setting appropriate thresholds, we can effectively filter out information that doesn't belong to the target domain, maintaining the specificity and integrity of the knowledge graph. The model can adjust the threshold based on real-time changes in the knowledge graph, ensuring accurate classification of new information and adapting to the dynamic updating needs of the knowledge graph.
[0103] During the classification and evaluation process, the knowledge representation learning model effectively filters out triplets that do not conform to the target domain or knowledge graph rules, thereby improving the overall quality and credibility of the graph. This automated classification process reduces the burden of manual review, improves the efficiency of maintaining large-scale knowledge graphs, and enables the system to quickly adapt to data growth and changes. The classification results can provide a real-time, accurate information foundation for decision support systems, facilitating decision optimization in areas such as trend analysis and policy formulation.
[0104] It should be noted that the training of the knowledge representation learning model in the embodiment of the present application corresponds one-to-one to the steps in the training method of the knowledge representation learning model in Example 1, and will not be repeated here.
[0105] Example 4
[0106] According to an embodiment of the present application, a knowledge representation learning model training device for implementing the knowledge representation learning model training method in embodiment 1 is also provided. Figure 5As shown, the knowledge representation learning model training device at least includes: an acquisition module 51, a sample generation module 52, a model construction module 53 and a model training module 54, wherein:
[0107] An acquisition module 51 is configured to acquire structured data of a target domain and extract a plurality of triples from the structured data, wherein each triple includes: a head entity, a relationship, and a tail entity;
[0108] The sample generation module 52 takes each triple as a positive sample and constructs a negative sample corresponding to the positive sample;
[0109] A model construction module 53 is configured to construct an initial learning model, wherein the initial learning model is configured to generate a vector representation corresponding to an input triple, wherein the vector representation includes: a first embedding vector and a first angle corresponding to a target head entity in the input triple, a second embedding vector and a second angle corresponding to a target relationship, a third embedding vector and a third angle corresponding to a target tail entity, and a relationship mapping attribute, wherein the first embedding vector is rotated by a first angle to obtain a vector on a hyperplane corresponding to a target relationship mapped to the target head entity, the second embedding vector is rotated by a second angle to obtain a vector on a hyperplane mapped to the target relationship, and the third embedding vector is rotated by a third angle to obtain a vector on a hyperplane mapped to the target tail entity, and the relationship mapping attribute is configured to reflect the number of tail entities associated with the target head entity and the number of head entities associated with the target tail entity;
[0110] The model training module 54 uses multiple positive samples and negative samples to train the initial learning model to obtain a knowledge representation learning model of the target domain.
[0111] The functions of each module of the knowledge representation learning model training device are explained below in conjunction with the specific implementation process.
[0112] As an optional implementation, in order to obtain relationship mapping attributes, after the acquisition module extracts multiple triples from the structured data, for each head entity in the multiple triples, the first number of tail entities associated with the head entity is counted; for each tail entity in the multiple triples, the second number of head entities associated with the tail entity is counted.
[0113] As an optional implementation, for each triple, the triple is regarded as a positive sample, and the sample generation module can construct a negative sample corresponding to the positive sample in the following manner: hierarchically clustering multiple head entities in multiple triples to obtain multiple first clusters, and hierarchically clustering multiple tail entities in multiple triples to obtain multiple second clusters; for each triple, the triple is regarded as a positive sample; and a probability method is used to determine whether to replace the first head entity or the first tail entity in the triple, wherein the probability of replacing the first head entity is: The probability of replacing the first tail entity is: In the formula, num h The first number of tail entities associated with the first head entity, num t is the second number of head entities associated with the first tail entity; in the case of replacing the first head entity, the semantic similarities between the other head entities in the cluster to which the first head entity belongs and the first head entity are determined respectively, and the first head entity in the triplet is replaced with the other head entities with the largest semantic similarity to obtain a negative sample corresponding to the positive sample; in the case of replacing the first tail entity, the semantic similarities between the other tail entities in the cluster to which the first tail entity belongs and the first tail entity are determined respectively, and the first tail entity in the triplet is replaced with the other tail entities with the largest semantic similarity to obtain a negative sample corresponding to the positive sample.
[0114] As an optional implementation, positive samples and negative samples can be divided through the above steps S1 to S4. The model training module can input multiple positive samples and negative samples into the initial learning model for training to obtain a knowledge representation learning model of the target domain. This can be achieved in the following way: in each training batch, the positive samples and negative samples corresponding to the training batch are input into the initial learning model in turn to obtain the vector representation corresponding to each positive sample and negative sample; for each positive sample or negative sample, the relationship score corresponding to the positive sample or negative sample is determined based on the first embedding vector, first angle, second embedding vector, second angle, third embedding vector, third angle and relationship mapping attribute in the vector representation corresponding to the positive sample or negative sample; the target loss function is constructed based on the relationship scores corresponding to each positive sample and negative sample; and the model parameters of the initial learning model are adjusted based on the target loss function.
[0115] Optionally, for each positive sample or negative sample, the relationship score corresponding to the positive sample or negative sample is determined based on the first embedding vector, the first angle, the second embedding vector, the second angle, the third embedding vector, the third angle, and the relationship mapping attribute in the vector representation corresponding to the positive sample or negative sample. The relationship score corresponding to the input sample can be determined by the following formula:
[0116] f r (h,t)=w r ·‖h * cosθ h +r * cosθ r +t * cosθ t ‖ L1 / L2
[0117] Among them, h, r, and t represent the target head entity, target relation, and target tail entity in the triplet corresponding to the input sample, respectively, and f r(h, t) represents the relationship score of the input sample, w r represents a relational mapping attribute, and num h The first number of tail entities associated with the target head entity, num t The second number of head entities associated with the target tail entity, h * and θ h They represent the first embedding vector and the first angle corresponding to the target head entity, r * and θ r Represent the second embedding vector and the second angle corresponding to the target relationship, t * and θ t Represent the third embedding vector and third angle corresponding to the target tail entity, ‖*‖ L1 / L2 Indicates taking L1 or L2 norm.
[0118] Optionally, for each positive sample and negative sample obtained, the relationship score is calculated respectively, and a target loss function is constructed. The target loss function can be determined by the following method:
[0119]
[0120] Among them, L represents the target loss function, (h, r, t) represents the positive sample, S represents the positive sample set in the current training batch, and f r (h, t) represents the relationship score corresponding to the positive sample, (h′, r′, t′) represents the negative sample, S′ represents the set of negative samples in the current training batch, and f r′ (h′, t′) represents the relationship score corresponding to the negative sample, and λ is a preset coefficient used to control the difference in the relationship score between positive and negative samples.
[0121] In addition, the training device of the knowledge representation learning model can improve the dynamics and adaptability of the model in the following ways: periodically obtain updated structured data of the target field, and use the updated structured data to generate multiple new positive samples and negative samples; use multiple new positive samples and negative samples to train the knowledge representation learning model again and update the model parameters of the knowledge representation learning model.
[0122] It should be noted that the modules in the knowledge representation learning model training device in the embodiment of the present application correspond one-to-one to the implementation steps of the knowledge representation learning model training method in Example 1. Since a detailed description has been given in Example 1, some details not reflected in this embodiment can be referred to Example 1 and will not be elaborated here.
[0123] Example 5
[0124] According to an embodiment of the present application, a computer program product is also provided, which includes a computer program, wherein when the computer program is executed by a processor, it implements the knowledge representation learning model training method in Example 1, or the link prediction method in Example 2, or the triple evaluation method in Example 3.
[0125] According to an embodiment of the present application, a non-volatile storage medium is also provided, which includes a stored computer program, wherein the device where the non-volatile storage medium is located executes the knowledge representation learning model training method in Example 1, or the link prediction method in Example 2, or the triple evaluation method in Example 3 by running the computer program.
[0126] According to an embodiment of the present application, a processor is also provided, which is used to run a computer program, wherein when the computer program is running, it executes the knowledge representation learning model training method in Example 1, or the link prediction method in Example 2, or the triple evaluation method in Example 3.
[0127] According to an embodiment of the present application, an electronic device is also provided, which includes: a memory and a processor, wherein a computer program is stored in the memory, and the processor is configured to execute the knowledge representation learning model training method in Example 1, or the link prediction method in Example 2, or the triple evaluation method in Example 3 through the computer program.
[0128] Specifically, when the computer program is running, the following steps of the knowledge representation learning model training method in Example 1 are executed: structured data of the target domain is obtained, and multiple triples are extracted from the structured data, wherein each triple includes: a head entity, a relationship, and a tail entity; for each triple, the triple is used as a positive sample, and a negative sample corresponding to the positive sample is constructed; an initial learning model is constructed, wherein the initial learning model is used to generate a vector representation corresponding to the input triple, and the vector representation includes: a first embedding vector corresponding to the target head entity in the input triple, and a first angle, and a second embedding vector corresponding to the target relationship The first embedding vector is rotated by the first angle to obtain the vector on the hyperplane corresponding to the target head entity and the target relationship, the second embedding vector is rotated by the second angle to obtain the vector on the hyperplane corresponding to the target relationship, the third embedding vector is rotated by the third angle to obtain the vector on the hyperplane corresponding to the target tail entity, and the relationship mapping attribute is used to reflect the number of tail entities associated with the target head entity and the number of head entities associated with the target tail entity; the initial learning model is trained using multiple positive samples and negative samples to obtain a knowledge representation learning model for the target domain.
[0129] Specifically, when the computer program is running, the following steps of the link prediction method in Example 2 can also be implemented: obtaining the input first entity and first relationship, and determining multiple candidate second entities; for each second entity, combining the second entity, the first entity, and the first relationship into a candidate triple; using the knowledge representation learning model to analyze the candidate triple, obtain the vector representation corresponding to the candidate triple, and determine the relationship score corresponding to the candidate triple based on the vector representation, wherein the knowledge representation learning model is trained by the above-mentioned knowledge representation learning model training method; determining the second entity with the highest corresponding relationship score as the target entity that matches the first entity and the first relationship.
[0130] Specifically, when the computer program is running, the following steps of the triple evaluation method in Example 3 can also be implemented: obtaining the triple to be evaluated; using the knowledge representation learning model to analyze the triple to obtain the vector representation corresponding to the triple, and determining the relationship score corresponding to the triple based on the vector representation, wherein the knowledge representation learning model is trained by the above-mentioned knowledge representation learning model training method; determining the matching status of the triple and the target field based on the relationship score.
[0131] As an optional implementation, the electronic device may be in the form of a mobile terminal, a computer terminal or a similar computing device. Figure 6 FIG1 shows a hardware structure block diagram of an electronic device for implementing a knowledge representation learning model training method. Figure 6 As shown, the electronic device 60 may include one or more (illustrated by 602a, 602b, ..., 602n in the figure) processors 602 (the processor 602 may include but is not limited to a processing device such as a microprocessor MCU or a programmable logic device FPGA), a memory 604 for storing data, and a transmission device 606 for communication functions. In addition, it may also include: a display, an input / output interface (I / O interface), a universal serial bus (USB) port (which may be included as one of the ports of the BUS bus), a network interface, a power supply and / or a camera. It will be understood by those skilled in the art that Figure 6 The structure shown is only for illustration and does not limit the structure of the above electronic device. Figure 6 More or fewer components than shown, or with Figure 6 Different configurations shown.
[0132] It should be noted that the one or more processors 602 and / or other data processing circuits described above may generally be referred to herein as "data processing circuitry". The data processing circuitry may be embodied in whole or in part as software, hardware, firmware, or any other combination thereof. In addition, the data processing circuitry may be a single independent processing module, or may be incorporated in whole or in part into any of the other components of the electronic device 60. As described in the embodiments of the present application, the data processing circuitry serves as a processor control (e.g., selection of a variable resistor terminal path connected to an interface).
[0133] The memory 604 can be used to store software programs and modules of application software, such as the program instructions / data storage device corresponding to the knowledge representation learning model training method in the embodiment of the present application. The processor 602 executes various functional applications and data processing by running the software programs and modules stored in the memory 604, that is, implementing the vulnerability detection method of the above-mentioned application. The memory 604 may include a high-speed random access memory, and may also include a non-volatile memory, such as one or more magnetic storage devices, flash memory, or other non-volatile solid-state memory. In some instances, the memory 604 may further include a memory remotely located relative to the processor 602, and these remote memories may be connected to the electronic device 60 via a network. Examples of the above-mentioned network include, but are not limited to, the Internet, an intranet, a local area network, a mobile communication network, and a combination thereof.
[0134] The transmission device 606 is used to receive or send data via a network. Specific examples of the aforementioned network may include a wireless network provided by the communications provider of the electronic device 60. In one embodiment, the transmission device 606 includes a network interface controller (NIC), which can be connected to other network devices via a base station to enable communication with the Internet. In another embodiment, the transmission device 606 may be a radio frequency (RF) module, which is used to communicate with the Internet wirelessly.
[0135] The display may be, for example, a touch screen liquid crystal display (LCD) that enables a user to interact with a user interface of the electronic device 60 .
[0136] The serial numbers of the above embodiments are for description only and do not represent the advantages or disadvantages of the embodiments.
[0137] In the above embodiments of the present application, the description of each embodiment has its own focus. For parts that are not described in detail in a certain embodiment, please refer to the relevant description of other embodiments.
[0138] In the several embodiments provided in this application, it should be understood that the disclosed technical content can be implemented in other ways. Among them, the device embodiments described above are only exemplary. For example, the division of units can be a logical function division. In actual implementation, there may be other division methods, such as multiple units or components can be combined or integrated into another system, or some features can be ignored or not executed. Another point is that the mutual coupling or direct coupling or communication connection shown or discussed can be through some interfaces, indirect coupling or communication connection of units or modules, which can be electrical or other forms.
[0139] Units described as separate components may or may not be physically separate, and components shown as units may or may not be physical units, that is, they may be located in one place or distributed across multiple units. Some or all of the units may be selected to achieve the purpose of the present embodiment according to actual needs.
[0140] In addition, the functional units in the various embodiments of the present application may be integrated into a single processing unit, or each unit may exist physically separately, or two or more units may be integrated into a single unit. The aforementioned integrated units may be implemented in the form of hardware or software functional units.
[0141] If the integrated unit is implemented in the form of a software functional unit and sold or used as an independent product, it can be stored in a computer-readable storage medium. Based on this understanding, the technical solution of the present application is essentially or the part that contributes to the prior art or all or part of the technical solution can be embodied in the form of a software product, and the computer software product is stored in a storage medium, including a number of instructions for enabling a computer device (which can be a personal computer, server or network device, etc.) to execute all or part of the steps of the various embodiments of the present application. The aforementioned storage medium includes: U disk, read-only memory (ROM, Read-Only Memory), random access memory (RAM, Random Access Memory), mobile hard disk, magnetic disk or optical disk and other media that can store program code.
[0142] The above is only a preferred embodiment of the present application. It should be pointed out that for ordinary technicians in this technical field, several improvements and modifications can be made without departing from the principles of the present application. These improvements and modifications should also be regarded as the scope of protection of the present application.
Claims
1. A knowledge representation learning model training method, characterized in that: include: Acquire structured data of a target domain, and extract a plurality of triples from the structured data, wherein each triple includes: a head entity, a relation, and a tail entity; For each triplet, the triplet is taken as a positive sample, and a negative sample corresponding to the positive sample is constructed; Constructing an initial learning model, wherein the initial learning model is used to generate a vector representation corresponding to an input triple, the vector representation including: a first embedding vector and a first angle corresponding to a target head entity in the input triple, a second embedding vector and a second angle corresponding to a target relationship, a third embedding vector and a third angle corresponding to a target tail entity, and a relationship mapping attribute, wherein the first embedding vector is rotated by the first angle to obtain a vector on a hyperplane corresponding to the target relationship mapped to the target head entity, the second embedding vector is rotated by the second angle to obtain a vector on a hyperplane mapped to the target relationship, and the third embedding vector is rotated by the third angle to obtain a vector on a hyperplane mapped to the target tail entity, and the relationship mapping attribute is used to reflect the number of tail entities associated with the target head entity and the number of head entities associated with the target tail entity; The initial learning model is trained using multiple positive samples and negative samples to obtain a knowledge representation learning model for the target domain.
2. The method according to claim 1, characterized in that After extracting a plurality of triples from the structured data, the method further includes: For each head entity in the plurality of triples, counting a first number of tail entities associated with the head entity; For each tail entity in the plurality of triples, a second number of head entities associated with the tail entity is counted.
3. The method according to claim 2, characterized in that For each triplet, the triplet is taken as a positive sample, and a negative sample corresponding to the positive sample is constructed, including: Performing hierarchical clustering on multiple head entities in the multiple triples to obtain multiple first clusters, and performing hierarchical clustering on multiple tail entities in the multiple triples to obtain multiple second clusters; For each triplet, take the triplet as a positive sample; The probability method is used to determine whether to replace the first head entity or the first tail entity in the triple, wherein the probability of replacing the first head entity is: The probability of replacing the first tail entity is: In the formula, num h The first number of tail entities associated with the first head entity, num t a second number of head entities associated with the first tail entity; In the case of replacing the first head entity, determining the semantic similarity between the first head entity and other head entities in the cluster to which the first head entity belongs, and replacing the first head entity in the triplet with other head entities with the greatest semantic similarity to obtain a negative sample corresponding to the positive sample; In the case of replacing the first tail entity, the semantic similarities between the first tail entity and other tail entities in the cluster to which the first tail entity belongs are determined respectively, and the first tail entity in the triplet is replaced with the other tail entities with the greatest semantic similarity to obtain a negative sample corresponding to the positive sample.
4. The method according to claim 2, characterized in that The initial learning model is trained using multiple positive samples and negative samples to obtain a knowledge representation learning model for the target domain, including: In each training batch, each positive sample and each negative sample corresponding to the training batch are sequentially input into the initial learning model to obtain a vector representation corresponding to each positive sample and each negative sample; For each positive sample or negative sample, determine a relationship score corresponding to the positive sample or negative sample based on a first embedding vector, a first angle, a second embedding vector, a second angle, a third embedding vector, a third angle, and a relationship mapping attribute in the vector representation corresponding to the positive sample or negative sample; Constructing a target loss function based on the relationship scores corresponding to each positive sample and negative sample; Adjust the model parameters of the initial learning model according to the target loss function.
5. The method according to claim 4, characterized in that Determining a relationship score corresponding to the positive sample or the negative sample based on a first embedding vector, a first angle, a second embedding vector, a second angle, a third embedding vector, a third angle, and a relationship mapping attribute in a vector representation corresponding to the positive sample or the negative sample, including: The relationship score corresponding to the input sample is determined according to the following formula: f r (h,t)=w r ·‖h * ·cosθ h +r * ·cosθ r +t * ·cosθ t ‖ L1 / L2 In the formula, h, r, and t represent the target head entity, target relation, and target tail entity in the triplet corresponding to the input sample, respectively. r (h, t) represents the relationship score of the input sample, w r represents the relationship mapping attribute, and num h The first number of tail entities associated with the target head entity, num t is the second number of head entities associated with the target tail entity, h * and θ h Respectively represent the first embedding vector and the first angle corresponding to the target head entity, r * and θ r Respectively represent the second embedding vector and the second angle corresponding to the target relationship, t * and θ t Respectively represent the third embedding vector and the third angle corresponding to the target tail entity, ‖*‖ L1 / L2 Indicates taking L1 or L2 norm.
6. The method according to claim 4, characterized in that Constructing a target loss function based on the relationship scores corresponding to each positive sample and negative sample includes: The target loss function is determined according to the following formula: Where L represents the target loss function, (h, r, t) represents the positive sample, S represents the set of positive samples in the current training batch, and f r (h,t) represents the relationship score corresponding to the positive sample, (h ′ ,r ′ ,t ′ ) represents negative samples, S ′ represents the set of negative samples in the current training batch, f r′ (h ′ ,t ′ ) represents the relationship score corresponding to the negative sample, and λ is a preset coefficient used to control the difference in relationship scores between positive and negative samples.
7. The method according to claim 1, characterized in that The method further comprises: Periodically acquiring updated structured data of the target domain, and generating a plurality of new positive samples and negative samples using the updated structured data; The knowledge representation learning model is trained again using the multiple new positive samples and negative samples to update model parameters of the knowledge representation learning model.
8. A link prediction method, characterized in that: include: Obtaining an input first entity and a first relationship, and determining a plurality of candidate second entities; For each second entity, forming a candidate triple by combining the second entity, the first entity, and the first relationship; Analyzing the candidate triples using a knowledge representation learning model to obtain vector representations corresponding to the candidate triples, and determining relationship scores corresponding to the candidate triples based on the vector representations, wherein the knowledge representation learning model is trained using the knowledge representation learning model training method according to any one of claims 1 to 7; A second entity with the highest correspondence score is determined as the target entity that matches the first entity and the first relationship.
9. A triplet evaluation method, characterized in that include: Get the triple to be evaluated; Analyzing the triples using a knowledge representation learning model to obtain vector representations corresponding to the triples, and determining relationship scores corresponding to the triples based on the vector representations, wherein the knowledge representation learning model is trained using the knowledge representation learning model training method according to any one of claims 1 to 7; The matching status between the triple and the target domain is determined according to the relationship score.
10. A knowledge representation learning model training device, characterized in that: include: An acquisition module is used to acquire structured data of a target domain and extract a plurality of triples from the structured data, wherein each triple includes: a head entity, a relationship, and a tail entity; A sample generation module, configured to treat each triplet as a positive sample and construct a negative sample corresponding to the positive sample; A model construction module is used to construct an initial learning model, wherein the initial learning model is used to generate a vector representation corresponding to an input triple, the vector representation including: a first embedding vector and a first angle corresponding to a target head entity in the input triple, a second embedding vector and a second angle corresponding to a target relationship, a third embedding vector and a third angle corresponding to a target tail entity, and a relationship mapping attribute, wherein the first embedding vector is rotated by the first angle to obtain a vector mapping the target head entity to a hyperplane corresponding to the target relationship, the second embedding vector is rotated by the second angle to obtain a vector mapping the target relationship to the hyperplane, and the third embedding vector is rotated by the third angle to obtain a vector mapping the target tail entity to the hyperplane, and the relationship mapping attribute is used to reflect the number of tail entities associated with the target head entity and the number of head entities associated with the target tail entity; The model training module is used to train the initial learning model using multiple positive samples and negative samples to obtain a knowledge representation learning model for the target domain.
11. A computer program product, characterized in that include: A computer program, wherein when the computer program is executed by a processor, it implements the knowledge representation learning model training method described in any one of claims 1 to 7, or the link prediction method described in claim 8, or the triple evaluation method described in claim 9.
12. An electronic device, characterized in that: include: A memory and a processor, wherein a computer program is stored in the memory, and the processor is configured to execute the knowledge representation learning model training method described in any one of claims 1 to 7, or the link prediction method described in claim 8, or the triple evaluation method described in claim 9 through the computer program.
Citation Information
Cited By
Cross-platform business system integration method based on knowledge graph
CN121579702A
A knowledge graph-based cross-platform business system integration method
CN121579702B