Entity alignment method and device, equipment and storage medium
By generating task prompt text using a large language model, the high cost and low accuracy problems caused by reliance on manual rules in existing technologies are solved, achieving efficient and accurate entity alignment.
Patent Information
- Application Number
- CN202410591307.7
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-05-13
- Publication Date
- 2025-11-21
AI Technical Summary
Existing entity alignment methods rely on manually defined alignment rules, which leads to high labor costs and difficulty in handling the diversity and complexity of entities, thus affecting accuracy.
A large language model is used to generate task prompt text. The entity that matches the target entity is selected from the candidate entities in the form of multiple choice questions. The semantic understanding and inference capabilities of the language model are used to perform entity alignment.
It improves the accuracy of entity alignment, reduces labor costs, and is able to handle complex and diverse entity alignment tasks.
Smart Images

Figure CN120994839A_ABST
Abstract
Description
Technical Field
[0001] This application relates to the field of Internet technology, specifically to the field of computer technology, and in particular to a method, apparatus, device, and storage medium for entity alignment. Background Technology
[0002] With the development of computer technology, entity alignment has been widely applied. Entity alignment is a technique aimed at determining whether entities in two or more different knowledge graphs refer to the same object in the real world. In other words, the goal of entity alignment is to identify entities with the same real-world identifier across various knowledge graphs, which is crucial for integrating information from multiple knowledge graphs. Currently, it typically relies on manually defined alignment rules to identify and align entities in different knowledge graphs. While such entity alignment methods are simple and intuitive, they require significant human resources and struggle to handle the diversity and complexity of entities, thus affecting the accuracy of entity alignment. Summary of the Invention
[0003] This application provides a method, apparatus, device, and storage medium for entity alignment, which can improve the accuracy of entity alignment and reduce labor costs.
[0004] On one hand, embodiments of this application provide an entity alignment method, the method comprising:
[0005] Select one entity from the first knowledge graph as the target entity, and select K entities from the second knowledge graph as candidate entities, where K is a positive integer;
[0006] Obtain the entity information of the target entity, and obtain the entity information of each of the K candidate entities;
[0007] Using the entity information of the target entity and the entity information of the K candidate entities, a task prompt text for the language model is generated; the task prompt text is used to prompt: based on the entity information of the target entity and the entity information of the K candidate entities, select a candidate entity that matches the target entity from the K candidate entities;
[0008] The language model is invoked to perform entity selection processing based on the task prompt text, and the candidate entities selected by the language model are aligned with the target entity.
[0009] On the other hand, embodiments of this application provide a solid alignment device, the device comprising:
[0010] The acquisition unit is used to select one entity from the first knowledge graph as the target entity and select K entities from the second knowledge graph as candidate entities, where K is a positive integer;
[0011] The acquisition unit is further configured to acquire entity information of the target entity, and acquire entity information of each of the K candidate entities;
[0012] An alignment unit is used to generate task prompt text for a language model using the entity information of the target entity and the entity information of the K candidate entities; the task prompt text is used to prompt: based on the entity information of the target entity and the entity information of the K candidate entities, select a candidate entity that matches the target entity from the K candidate entities;
[0013] The alignment unit is further configured to invoke the language model to perform entity selection processing based on the task prompt text, and align the candidate entities selected by the language model with the target entity.
[0014] In another aspect, embodiments of this application provide a computer device, the computer device including an input interface and an output interface, the computer device further including:
[0015] Processor and computer storage media;
[0016] The processor is adapted to implement one or more instructions, and the computer storage medium stores one or more instructions, which are adapted to be loaded by the processor and executed in the following steps:
[0017] Select one entity from the first knowledge graph as the target entity, and select K entities from the second knowledge graph as candidate entities, where K is a positive integer;
[0018] Obtain the entity information of the target entity, and obtain the entity information of each of the K candidate entities;
[0019] Using the entity information of the target entity and the entity information of the K candidate entities, a task prompt text for the language model is generated; the task prompt text is used to prompt: based on the entity information of the target entity and the entity information of the K candidate entities, select a candidate entity that matches the target entity from the K candidate entities;
[0020] The language model is invoked to perform entity selection processing based on the task prompt text, and the candidate entities selected by the language model are aligned with the target entity.
[0021] In another aspect, embodiments of this application provide a computer storage medium storing one or more instructions adapted for loading and execution by a processor of the aforementioned entity alignment method.
[0022] In another aspect, embodiments of this application provide a computer program product comprising one or more instructions; when one or more instructions in the computer program product are executed by a processor, they implement the entity alignment method mentioned above.
[0023] This application embodiment selects one entity from a first knowledge graph as the target entity and K entities from a second knowledge graph as candidate entities. Using the entity information of the target entity and the entity information of the K candidate entities, a task prompt text for a language model is generated. This task prompt text is then input into the language model for inference. The language model, based on the entity information of the target entity and the K candidate entities, selects the candidate entity that best matches the target entity from the K candidate entities, transforming the entity alignment task into a multiple-choice question. This allows the language model to leverage its semantic understanding and inference capabilities to handle the diversity and complexity of entities, determine the candidate entity that best matches the target entity semantically (i.e., the candidate entity selected by the language model), and align the most semantically matching candidate entity with the target entity, improving the accuracy of entity alignment. Furthermore, since the entire process does not rely on manually written alignment rules, it reduces labor costs. Attached Figure Description
[0024] To more clearly illustrate the technical solutions of the embodiments of this application, the drawings used in the description of the embodiments will be briefly introduced below. Obviously, the drawings described below are some embodiments of this application. For those skilled in the art, other drawings can be obtained based on these drawings without creative effort.
[0025] Figure 1a This is a schematic diagram of a knowledge graph provided in an embodiment of this application;
[0026] Figure 1b This is a schematic diagram illustrating the principle of an entity alignment scheme provided in an embodiment of this application;
[0027] Figure 1c This is a schematic diagram of a knowledge retrieval scenario provided in an embodiment of this application;
[0028] Figure 2 This is a flowchart illustrating an entity alignment method provided in an embodiment of this application;
[0029] Figure 3a This is a schematic diagram illustrating the alignment of two entities based on similar structures, provided in an embodiment of this application.
[0030] Figure 3bThis is a schematic diagram illustrating the alignment of two entities based on entity attributes, provided in an embodiment of this application.
[0031] Figure 4 This is a flowchart illustrating an entity alignment method provided in another embodiment of this application;
[0032] Figure 5 This is a flowchart illustrating an unsupervised entity alignment method provided in an embodiment of this application;
[0033] Figure 6 This is a schematic diagram of the structure of a solid alignment device provided in an embodiment of this application;
[0034] Figure 7 This is a schematic diagram of the structure of a computer device provided in an embodiment of this application. Detailed Implementation
[0035] The technical solutions in the embodiments of this application will be clearly and completely described below with reference to the accompanying drawings.
[0036] In the embodiments of this application, a knowledge graph (KG) can be understood as a relational network obtained by connecting different kinds of information together, which is an effective way to represent relations. A knowledge graph can be defined as G = (E, R, T, A), where: ① E represents the entity set, which may include at least one entity. An entity refers to a concept used to represent objects in the real world, such as people, places, products, diseases, movies, TV shows, etc.; ② R represents the relation set, which may include the association between any two entities; ③ T represents the relation triple set, which may include at least one relation triple of each entity. The relation triple of any entity (let's say the first entity) can be represented as (h, r, t), where h represents the entity name of any entity (i.e., the first entity), r represents the association between any entity (i.e., the first entity) and another entity (let's say the second entity), and r represents the entity name of the other entity (i.e., the second entity); ④ A represents the attribute triple set, which may include at least one attribute triple of each entity. The attribute triple of any entity (let's say the first entity) can be represented as (h, a, v), where a represents the entity attribute of any entity (i.e., the first entity), and v represents the attribute value of the corresponding entity attribute. It's worth noting that, from a visualization perspective, knowledge graphs are typically presented as a network consisting of multiple nodes and edges; a node represents an entity, an edge represents a relationship, and the nodes corresponding to two entities with a relationship are connected by at least one edge, such as... Figure 1a As shown.
[0037] To improve the accuracy of entity alignment between knowledge graphs and reduce the human resource costs required for entity alignment, this application proposes an entity alignment scheme based on a large language model. A large language model (LLM), also known as a large-scale language model or language model, refers to a language model (a type of deep learning model) with a large scale (i.e., a large number of parameters, such as hundreds of billions or more). It can be pre-trained on large-scale text data based on the Transformer architecture (a model structure for data processing based on attention mechanisms) to learn and capture complex patterns and structures of language, thereby learning rich language knowledge and patterns to achieve semantic understanding and inference capabilities. This results in the generation of coherent and logical text, demonstrating powerful capabilities and flexibility in various natural language processing (NLP) tasks. In other words, a large language model is a language model that is unsupervised pre-trained on a large corpus of text (i.e., massive text data). After pre-training, a large language model can predict masked or subsequent tokens based on context, thereby capturing semantic knowledge of the language and generating general representations of words. After pre-training, the large language model can be fine-tuned through supervised learning and reinforcement learning optimization using human feedback, enabling it to perform complex tasks and generate content that aligns with human values. Furthermore, research has found that when the parameter size of a large language model exceeds a certain threshold, it exhibits novel capabilities not observed in smaller pre-trained language models, such as logical reasoning, thought chains, and mathematical reasoning. Therefore, large language models have been widely applied to various downstream applications of NLP.
[0038] When using large language models to solve various natural language processing tasks (NLP), Prompts play a crucial role; in the fields of programming and natural language processing, a Prompt is the input text or question provided to the large language model to guide it to generate corresponding answers or complete specific tasks. Specifically, a Prompt can be a short question, a description, a set of instructions, and the context for interacting with the large language model. For example, when using a large language model for conversation or text generation, the user can provide a Prompt as a starting point to guide the large language model to generate appropriate answers or task execution results; in this case, the Prompt can include background information of the question, specific instructions or task descriptions, or the context of the conversation, and the large language model will understand the user's intention based on the Prompt and generate corresponding answers or text. For example, given the instruction "Translate the following English sentence into Chinese: 'Hello, how are you?'", the large language model may generate "你好,你好吗?" as the output. It can be seen that the design of Prompts is very important for obtaining the expected model output, and reasonable selection and design of Prompts can help the large language model better understand the user's needs and generate more accurate and useful answers.
[0039] Among these, NLP, mentioned above, is an important direction in computer science and artificial intelligence (AI). It studies various theories and methods to enable effective communication between humans and computers using natural language. Natural language processing involves natural language, that is, the language people use in daily life, and is closely related to linguistics research; it also involves computer science and mathematics. AI technology refers to the theories, methods, technologies, and application systems that use digital computers or machines controlled by digital computers to simulate, extend, and expand human intelligence, perceive the environment, acquire knowledge, and use that knowledge to obtain optimal results. In other words, artificial intelligence is a comprehensive technology within computer science; it primarily aims to understand the essence of intelligence and produce a new type of intelligent machine that can react in a way similar to human intelligence, enabling intelligent machines to possess multiple functions such as perception, reasoning, and decision-making. Specifically, AI technology mainly includes several major directions such as natural language processing technology and machine learning (ML) / deep learning. Natural language processing technology typically includes text processing, semantic understanding, machine translation, robot question answering, and knowledge graphs. Machine learning is a multidisciplinary field involving probability theory, statistics, approximation theory, convex analysis, and algorithm complexity theory, among others. It specifically studies how computers can simulate or implement human learning behavior to acquire new knowledge or skills and reorganize existing knowledge structures to continuously improve their performance. Machine learning is the core of AI and the fundamental way to endow computers with intelligence; its applications span all areas of artificial intelligence. Deep learning, on the other hand, is a technique that utilizes deep neural network systems for machine learning.
[0040] Based on the above description of large language models, the following will combine... Figure 1bThe general principle of the entity alignment scheme based on a large language model proposed in this application is explained. Specifically, considering that for a given first knowledge graph G1 = (E1, R1, T1, A1) and second knowledge graph G2 = (E2, R2, T2, A2) to be aligned, the goal of entity alignment is to find an entity e2 ∈ E2 in the second knowledge graph G2 that represents the same object for each entity e1 ∈ E1 in the first knowledge graph G1; therefore, when performing entity alignment between the first knowledge graph G1 and the second knowledge graph G2, for each entity e1 in the first knowledge graph G1, multiple entities can be selected from the second knowledge graph as candidate entities, and the entity information of entity e1 and the entity information of each selected candidate entity are used to generate a choice question Prompt for the large language model. This choice question Prompt is used to prompt: based on the entity information of entity e1 and the entity information of each candidate entity, select the candidate entity that matches entity e1 from multiple candidate entities. Furthermore, the generated multiple-choice prompt is input into the large language model for reasoning. The large language model can then select a candidate entity that matches entity e1 from multiple candidate entities based on the entity information of entity e1 and the entity information of each candidate entity, according to the prompt. The candidate entity selected by the large language model is regarded as entity e2 in the second knowledge graph G2 that represents the same object as entity e1, thereby aligning entity e2 with entity e1.
[0041] In practical applications, the aforementioned entity alignment scheme based on a large language model can be executed by a single computer device, which can be a terminal or a server; alternatively, it can be executed jointly by a terminal and a server, without limitation. The terminal can be a smartphone, computer (such as a tablet, laptop, or desktop computer), smart wearable device (such as a smartwatch or smart glasses), smart voice interaction device, smart home appliance (such as a smart TV), vehicle terminal, or aircraft, etc.; the server can be an independent physical server, a server cluster or distributed system composed of multiple physical servers, or a cloud server providing basic cloud computing services such as cloud services, cloud databases, cloud computing, cloud functions, cloud storage, network services, cloud communication, middleware services, domain name services, security services, CDN (Content Delivery Network), and big data and artificial intelligence platforms, etc. Furthermore, the terminal and server can be located within or outside the blockchain network, without limitation; even further, the terminal and server can upload any data stored internally to the blockchain network for storage to prevent tampering and improve data security.
[0042] As described above, the entity alignment scheme based on a large language model proposed in this application can transform the entity alignment task into a multiple-choice question, leveraging the semantic understanding and inference capabilities of the large language model to handle the diversity and complexity of entities. This allows for a more accurate determination of the entity e2 in the second knowledge graph that best matches the semantics of entity e1 in the first knowledge graph, thereby improving the accuracy of entity alignment. Furthermore, since the entire process does not rely on manually written alignment rules, it reduces labor costs. Therefore, the entity alignment scheme based on a large language model proposed in this application can effectively align entities with the same meaning (i.e., referring to the same object) from multiple knowledge graphs from different data sources and business lines. This facilitates the fusion of multiple knowledge graphs into a richer and larger-scale knowledge graph, which is of great significance for improving the performance of knowledge graphs in downstream task applications.
[0043] The application areas of downstream tasks mentioned here can include, but are not limited to, knowledge question answering, knowledge reasoning, and knowledge retrieval. For example, in the domain of knowledge question answering, entity alignment can help the system more accurately understand the questions posed by users and obtain relevant answers from the fused knowledge graph; in knowledge reasoning, entity alignment can provide a more comprehensive knowledge background, thereby supporting the system to perform deeper reasoning and logical inference; in the domain of knowledge retrieval, entity alignment can improve the accuracy and relevance of retrieval results, enabling users to find the knowledge they need more quickly. For an example in the domain of knowledge retrieval, see [link to relevant documentation]. Figure 1c As shown, by aligning the entity "pneumonia" in knowledge graph 1 (represented by KG1) with other entities in other knowledge graphs such as "double pneumonia<disease>", "double lower pneumonia<disease>", "varicella pneumonia<disease>", and "chronic pneumonia<disease>", a more comprehensive relationship network can be established. This allows for the retrieval of pneumonia-related knowledge based on this more comprehensive relationship network after a user inputs the entity "pneumonia". Therefore, the entity alignment scheme based on a large language model proposed in this application can support data analysis and decision-making. By aligning entities in knowledge graphs from different data sources, a more comprehensive data association and relationship network can be established, providing a more accurate foundation for analysis and prediction in fields such as data mining and machine learning.
[0044] Based on the above description, this application proposes an entity alignment method. This entity alignment method can be executed by the aforementioned computer device (i.e., terminal or server), or by both the terminal and server. For ease of explanation, this application uses the execution of the entity alignment method by a computer device as an example. Please refer to... Figure 2 As shown, the entity alignment method may include the following steps S201-S204:
[0045] S201: Select one entity from the first knowledge graph as the target entity, and select K entities from the second knowledge graph as candidate entities, where K is a positive integer.
[0046] In this embodiment, the first knowledge graph and the second knowledge graph are any two knowledge graphs that need to be aligned for entities. It should be noted that the "first" in the first knowledge graph and the "second" in the second knowledge graph are only used to distinguish between the two different knowledge graphs and have no special meaning. Furthermore, this embodiment does not limit the business domain of either the first or second knowledge graph, and the business domains of the first and second knowledge graphs can be the same or different. For example, the business domains mentioned here can be, for instance, the medical field, the film and television drama field, the artificial intelligence field, etc. In the medical field, entities in the knowledge graph can be, for example, diseases, people, medicines, medical locations, etc.; in the film and television drama field, entities in the knowledge graph can be, for example, films and television dramas, ending theme songs, opening theme songs, actors, etc.; in the artificial intelligence field, entities in the knowledge graph can be, for example, artificial intelligence technology, artificial intelligence products, companies (enterprises), etc.
[0047] In a specific implementation, when a computer device selects an entity as a target entity from the first knowledge graph, it can randomly select an entity as the target entity from the first knowledge graph, or start traversing from a certain entity in the first knowledge graph and take the currently traversed entity as the target entity. The embodiments of this application do not limit the selection method of the target entity.
[0048] Furthermore, when selecting K entities as candidate entities from the second knowledge graph, the computer device can select all entities from the second knowledge graph. In this case, the value of K is equal to the total number of entities in the second knowledge graph. Alternatively, considering that the second knowledge graph may contain a large number of entities (e.g., tens of thousands or even millions), while the length of the input text for a large language model (hereinafter referred to as the language model) is usually limited (e.g., 2048 / 4096 tokens, where a token can be understood as the smallest unit in the text, which can be a character, word, or punctuation mark), it may not be possible to input all entities from the second knowledge graph into the language model. Based on this, the computer device can also select a subset of entities from the second knowledge graph as candidate entities. In this case, the value of K is less than the total number of entities in the second knowledge graph.
[0049] Furthermore, when selecting entities from the second knowledge graph as candidate entities, the computer device can randomly select K entities from the second knowledge graph. Alternatively, a vector representation model (or representation learning model) can be used to embed the target entity and all entities in the second knowledge graph into a low-dimensional vector space, obtaining the entity feature vector of the target entity and the entity feature vector of each entity in the second knowledge graph. Then, based on the similarity between the entity feature vector of the target entity and the entity feature vector of each entity in the second knowledge graph, the top K entities most likely to match the target entity (i.e., the K entities with the highest entity feature vector similarity (e.g., 3-10)) can be recalled as candidate entities. This can significantly reduce the number of entities that need to be input into the language model, and can also filter out a large amount of noise (i.e., entities in the second knowledge graph that do not match the target entity) in advance, reducing the reasoning difficulty of the language model when selecting entities in the subsequent process. Specifically, the computer device can invoke a vector representation model to generate the entity feature vector of the target entity, as well as the entity feature vector of each entity in the second knowledge graph; calculate the entity feature vector similarity between the entity feature vector of the target entity and the entity feature vector of each entity in the second knowledge graph, and then select K entities from the second knowledge graph as candidate entities according to the calculated entity feature vector similarity from high to low. In this case, the selected K candidate entities can be represented as {e 2,1 e 2,2 , ..., e 2,K}∈E2. It is understood that the embodiments of this application do not limit the calculation method of entity feature vector similarity. For example, vector similarity algorithms such as cosine similarity algorithm and Euclidean distance algorithm can be used to calculate the entity feature vector similarity between two entity feature vectors.
[0050] The vector representation model mentioned above refers to a model that can encode and generate entity feature vectors for any entity in a knowledge graph, such as the GCN-Align model. The GCN-Align model generates entity feature vectors by encoding the structural information of a knowledge graph. It utilizes Graph Convolutional Networks (GCNs) to map two knowledge graphs into the same space for encoding. An L-layer GCN encoder continuously fuses the neighboring entities of any entity (e.g., entity a) (i.e., another entity in the knowledge graph connected to any entity a via an edge), thereby using the neighboring entities to represent the semantic features of any entity a, and thus generating the entity feature vector of any entity a. Here, L is a positive integer, and the (l+1)th layer (l∈[1,L]) of the GCN encoder can be defined as follows: 1.1
[0051]
[0052] In formula 1.1 above, [·] + ReLU represents an activation function. (That is, the adjacency matrix M of the two knowledge graphs plus the diagonal matrix I) N (results) Representation matrix The degree matrix, W (l) This represents the trainable parameter matrix in the l-th layer of the GCN. It means The algorithm for the inverse matrix of the square root, H (l) H represents the entity structure features of each entity output by the l-th layer GCN. (l+1) This represents the entity structure features of each entity output by the (l+1)th layer GCN. In this embodiment, the output of the last layer (i.e., the Lth layer) of the GCN can be used as the entity feature vector for each entity. Therefore, the entity feature vector generated by the GCN-Align model can effectively utilize its surrounding neighboring entities to express its own vector representation, thereby modeling the structural information of the knowledge graph and improving the accuracy of entity feature information.
[0053] It should be noted that the above is merely an illustrative example of one specific implementation of the vector representation model and is not intended to limit it. In other words, the embodiments of this application are not limited to using the GCN-Align model as the vector representation model, and other models with better performance can also be used as the vector representation model, such as TransE (a distributed vector representation method based on entities and relations), GAT (Graph, Attention Networks, a model that uses the attention mechanism to learn the weights of neighboring nodes and obtains the node's own expression by weighted summation of neighboring nodes), TransH (an algorithm for embedding learning in knowledge graphs), MCLEA (an entity alignment model based on multimodal contrastive learning), and so on.
[0054] S202, obtain the entity information of the target entity, and obtain the entity information of each of the K candidate entities.
[0055] Considering that the two aligned entities usually have similar structures (relational triples), such as Figure 3a As shown; furthermore, entity attributes are usually considered as characteristics of the entity itself. If the entity attributes of two entities are highly similar (e.g., Figure 3bAs shown in the diagram, these two entities are highly likely to be aligned. Based on this, in order for the subsequent language model to perceive and fully utilize the structured information of the target entity and each candidate entity in the corresponding knowledge graph when selecting candidate entities that match the target entity from multiple candidate entities, the computer device can extract the structured information of the target entity from the first knowledge graph and the structured information of each candidate entity from the second knowledge graph as contextual information for the language model. This allows the language model to subsequently select entities based on this contextual information, thereby helping the language model better utilize potential graph knowledge for entity selection and improving the accuracy of entity selection. The structured information mentioned here may include at least one of the following: relation triples and attribute triples. It should be noted that the relation triples mentioned here can be specifically one-hop relation triples, which are constructed using the entity names of two entities directly connected by an edge, and the association relationship between the two entities. Alternatively, the relation triples mentioned here can also be multi-hop relation triples, which are constructed using the entity names of two entities indirectly connected by at least two edges, and the association relationship between the two entities.
[0056] Based on this, when acquiring entity information of a target entity, the computer device can obtain the structured information of the target entity from the first knowledge graph, and then construct the entity information of the target entity using the entity name and the structured information of the target entity. Specifically, the structured information of the target entity may include at least one of the following: a relation triplet of the target entity and an attribute triplet of the target entity; wherein, the relation triplet of the target entity includes the following elements: the entity name of the target entity, the entity name of another entity that has an association relationship with the target entity, and the corresponding association relationship; the attribute triplet of the target entity includes the following elements: the entity name of the target entity, the entity attributes that the target entity has, and the attribute values of the corresponding entity attributes. For example, a relation triplet of the target entity can be represented as (h1, r1, t1), and an attribute triplet of the target entity can be represented as (h1, a1, v1); wherein, (h1, r1, t1) ∈ T1, (h1, a1, v1) ∈ A1.
[0057] Furthermore, when constructing entity information of a target entity using its entity name and structured information, the computer device can directly summarize the entity name and structured information to obtain the entity information. Alternatively, considering that the entity information is used to construct task prompt text for a language model, and that the task prompt text needs to be input into the language model for reasoning, and that the language model processes data in text format, it may not be able to properly recognize triple-form data. Therefore, to ensure that the language model can fully recognize and understand the task prompt text constructed based on the entity information of the target entity, thereby improving the accuracy of entity selection, when constructing entity information using the entity name and structured information of the target entity, the computer device can linearize each triple in the structured information of the target entity into natural language text. Then, it can use the entity name and the natural language text corresponding to each triple of the target entity to construct the entity information, such as summarizing the entity name and the natural language text corresponding to each triple of the target entity to obtain the entity information.
[0058] Similarly, when a computer device obtains entity information for each of the K candidate entities, it can retrieve the structured information of each candidate entity from the second knowledge graph. This allows it to construct the entity information of each candidate entity using its entity name and corresponding structured information. Specifically, the structured information of a candidate entity may include at least one of the following: a relation triplet and an attribute triplet. The relation triplet includes the following elements: the entity name of the candidate entity, the entity name of another entity associated with the candidate entity, and the corresponding association. The attribute triplet includes the following elements: the entity name of the candidate entity, the entity attributes possessed by the candidate entity, and the attribute values of the corresponding entity attributes. For example, a relation triplet for the kth candidate entity can be represented as (h... 2,k r 2,k , t 2,k The attribute triple of the k-th candidate entity can be represented as (h) 2,k a 2,k v 2,k ); where k∈[1,K], (h 2,k r 2,k , t 2,k )∈T2,(h 2,k a 2,k v 2,k)∈A2. Furthermore, when constructing entity information of a candidate entity using the entity name of any candidate entity and the structured information of the corresponding candidate entity, the computer device can directly summarize the entity name of any candidate entity and the structured information of the corresponding candidate entity to obtain the entity information of the corresponding candidate entity; or, it can linearize each triple in the structured information of any candidate entity into natural language text, thereby constructing entity information of the corresponding candidate entity using the entity name of any candidate entity and the natural language text corresponding to each triple of the corresponding candidate entity.
[0059] One way to linearize any triple into natural language text is to concatenate the elements of the triple. Specifically, the elements of the triple can be concatenated sequentially to obtain the natural language text. For example, for a relation triple (neuritis, hyponym, peripheral neuritis), concatenating the elements sequentially yields the natural language text "neuritis hyponym peripheral neuritis". Alternatively, to improve the readability and fluency of the natural language text obtained by linearizing the triples, allowing the language model to more accurately understand the text before selecting entities and thus improving the accuracy of entity selection, the computer device can also acquire a text template based on natural language. This template may include three fill fields and at least one character connecting the fill fields. Each fill field is used to fill one element of the triple. Therefore, the elements of the triple can be sequentially filled into the fill fields of the text template to concatenate the elements of the triple into a natural language text.
[0060] For example, the text template could be "x's y is z"; where x represents the padding field used to fill the first element of the triple, y represents the padding field used to fill the second element of the triple, and z represents the padding field used to fill the third element of the triple. In this case, any relation triple (h, r, t) can be linearized into the natural language text "h's r is t". If we assume that h is neuritis, r is a hyponym, and t is peripheral neuritis, then the natural language text obtained by linearizing the relation triple (neuritis, hyponym, peripheral neuritis) could be "the hyponym of neuritis is peripheral neuritis". Similarly, any attribute triple (h, a, v) can be linearized into the natural language text "h's a is v". If we assume that h is movie 1, a is the release date, and v is 2024.5, then the natural language text obtained by linearizing the attribute triple (movie 1, release date, 2024.5) can be "movie 1's release date is 2024.5".
[0061] S203: Using the entity information of the target entity and the entity information of K candidate entities, generate task prompt text for the language model.
[0062] In its implementation, the computer device can obtain a preset task prompt template, which may include instruction text, input fields, and output fields. The instruction text can be used to instruct the selection of a candidate entity that matches the target entity from the K candidate entities, based on the entity information of the target entity and the entity information of K candidate entities. The input fields can be used to fill in the entity information of the target entity and the K candidate entities. The output field can be used to output the entity name of the candidate entity selected by the language model. After obtaining the task prompt template, the computer device can fill the input fields of the task prompt template with the entity information of the target entity and the K candidate entities, thereby obtaining the task prompt text of the language model. This task prompt text can be used to prompt: based on the entity information of the target entity and the entity information of K candidate entities, select a candidate entity that matches the target entity from the K candidate entities.
[0063] As mentioned above, the entity information of any entity includes multiple types of information, such as the entity name, the entity's relation triples or the natural language text corresponding to the relation triples, and the entity's attribute triples or the natural language text corresponding to the attribute triples. Based on this, in order for the language model to better distinguish the different types of information in each entity, when the computer device fills the entity information of the target entity and the entity information of K candidate entities into the input fields of the task prompt template, it can obtain an information template. This information template includes an entity name field, a relation triple field, and an attribute triple field. The entity name field is used to fill in the entity name, the relation triple field is used to fill in the relation triples or the natural language text corresponding to the relation triples, and the attribute triple field is used to fill in the attribute triples or the natural language text corresponding to the attribute triples. Once the information template is obtained, the computer device can fill each piece of information from the entity information of the target entity into the information template to obtain the information text segment of the target entity, and fill each piece of information from the entity information of each candidate entity into the information template to obtain the information text segment of each candidate entity. Thus, the information text segment of the target entity and the information text segments of the K candidate entities are filled into the input field of the task prompt template.
[0064] It should be noted that any entity can have one or more relation triples. When an entity has multiple relation triples, the linearized natural language text corresponding to each relation triple can be concatenated, and the concatenated text can be filled into the relation triple field. For example, if the target entity has two relation triples: (h1, r1, t1) and (h2, r2, t2), then we have two natural language texts: "h1's r1 is t1" and "h2's r2 is t2". These two natural language texts can be concatenated to obtain the concatenated text "h1's r1 is t1, h2's r2 is t2", which can be represented as (h1, r1, t1), (h2, r2, t2) → h1's r1 is t1, h2's r2 is t2. This concatenated text can then be filled into the relation triple. Similarly, when an entity has multiple attribute triples, a similar operation can be performed.
[0065] It should also be noted that the specific form of the instruction text in the task prompt template mentioned above is not limited in this application embodiment. Its specific form can be set according to the actual scenario or business requirements of entity alignment. Based on the above description, the following examples illustrate the instruction text in the task prompt template mentioned above and the task prompt text generated based on the task prompt template in different actual scenarios of entity alignment:
[0066] (1) In a one-to-one entity alignment scenario (i.e., an entity in the first knowledge graph aligns with an entity in the second knowledge graph), the instruction text in the task prompt template could be, for example, "Please combine the provided entity information about relation triples and attribute triples to select the candidate entity that best matches the target entity from the given candidate entities. Only the entity name of the candidate entity needs to be output." In this case, the task prompt text obtained by filling the target entity's entity information and the entity information of K candidate entities into the task prompt template can be as follows:
[0067] "Based on the provided auxiliary information about relation triples and attribute triples, select the candidate entity that best matches the target entity "e1" from the given candidate entities. You only need to output the name of the candidate entity."
[0068] Target entity: e1
[0069] Target entity relation triple: h 1,1 r 1,1 It is t 1,1 h 1,2 r 1,2 It is t 1,2 , ..., h 1,i r 1,i It is t1,i ...
[0070] Target entity attribute triple: h 1,1 a 1,1 It is v 1,1 h 1,2 a 1,2 It is v 1,2 , ..., h 1,i a 1,i It is v 1,i ...
[0071] Candidate Entity 1: e 2,1
[0072] Candidate Entity 1 Relation Triple: h 2,1,1 r 2,1,1 It is t 2,1,1 h 2,1,2 r 2,1,2 It is t 2,1,2 , ..., h 2,1,i r 2,1,i It is t 2,1,i ...
[0073] Candidate Entity 1 Attribute Triple: h 2,1,1 a 2,1,1 It is v 2,1,1 h 2,1,2 a 2,1,2 It is v 2,1,2 , ..., h 2,1,i a 2,1,i It is v 2,1,i ...
[0074] ………
[0075] Candidate entity k: e 2,k
[0076] Candidate entity k relation triple: h 2,k,1 r 2,k,1 It is t 2,k,1 h 2,k,2 r 2,k,2 It is t 2,k,2 , ..., h 2,k,i r 2,k,i It is t 2,k,i ...
[0077] Candidate entity k-attribute triple: h 2,k,1 a 2,k,1 It is v 2,k,1 h 2,k,2 a 2,k,2 It is v 2,k,2 , ..., h 2,k,i a 2,k,i It is v2,k,i ...
[0078] ………
[0079] Answer (i.e., output field): "
[0080] Where e1 represents the entity name of the target entity, "h 1,1 r 1,1 It is t 1,1 " and "h 1,1 a 1,1 It is v 1,1 "represents the first one-hop relation triplet (h) for the target entity" 1,1 r 1,1 , t 1,1 ) and the first attribute triple (h 1,1 a 1,1 v 1,1 The natural language text obtained by linearizing ) "h 1,2 r 1,2 It is t 1,2 " and "h 1,2 a 1,2 It is v 1,2 "represents the second one-hop relation triple (h) for the target entity" 1,2 r 1,2 , t 1,2 ) and the second attribute triple (h 1,2 a 1,2 v 1,2 The natural language text obtained by linearizing ) "h 1,i r 1,i It is t 1,i " and "h 1,i a 1,i It is v 1,i "represent the i-th one-hop relation triple (h) for the target entity" 1,i r 1,i , t 1,i ) and the i-th attribute triple (h 1,i a 1,i v 1,i The natural language text obtained by linearizing (e). And so on, e 2,k The entity name representing candidate entity k (i.e., the kth candidate entity), "h" 2,k,i r 2,k,i It is t 2,k,i " represents the i-th one-hop relation triple (h) of candidate entity k 2,k,i r 2,k,i , t 2,k,i The corresponding natural language text; "h 2,k,i a2,k,i It is v 2,k,i " represents the i-th attribute triple (h) of candidate entity k 2,k,i a 2,k,i v 2,k,i The corresponding natural language text.
[0081] Based on this, assume that the target entity's entity name e1 specifically takes the value Hu(film), which has three one-hop relation triples: (Hu(film), director, Ang), (Hu(film), producer, Avi), and (Hu(film), writer, Jam), and it has four attribute triples: (Hu(film), bucket, 1.37e8), (Hu(film), tilt, H(en)), (Hu(film), runtime, 8280.0), and (Hu(film), released, 2023-06-17); assume that the candidate entity 1's entity name e 2,1 The specific value is 'hu', which has three one-hop relation triples: (hu, directed_by, Ang), (hu, produced_by, Avi), and (hu, actor, Era), which has two attribute triples: (hu, bucket, 137000000) and (hu, release_date, 2003.5). Therefore, the specific form of the generated task prompt text in this case can be exemplarily shown below:
[0082] "Based on the provided auxiliary information about relation triples and attribute triples, select the candidate entity that best matches the target entity "Hu(film)" from the given candidate entities. You only need to output the name of the candidate entity."
[0083] Target entity: Hu(film)
[0084] The target entity relation triple is: Hu(film)'s director is Ang, Hu(film)'s producer is Avi, and Hu(film)'s writer is Jam.
[0085] Target entity attribute triples: Hu(film)'s bucket is 1.37e8, Hu(film)'s title is H(en), Hu(film)'s runtime is 8280.0, Hu(film)'s release date is 2023-06-17. Candidate entity 1: hu
[0086] Candidate Entity 1 relation triple: hu's directed_by is Ang, hu's produced_by is Avi, and hu's actor is Era.
[0087] Candidate entity 1 attribute triples: hu's bucket is 137000000, and hu's release_date is 2003.5.
[0088] ………
[0089] Answer (i.e., output field): "
[0090] (2) In a one-to-many entity alignment scenario (i.e., where one entity in the first knowledge graph can align with multiple entities in the second knowledge graph), the instruction text in the task prompt template could be, for example, "Please combine the provided entity-related relation triples and attribute triples to select candidate entities that match the target entity from the given candidate entities. Note that there can be multiple matched entities; simply output the entity names of the candidate entities." In this case, the task prompt text obtained by filling the target entity's entity information and the entity information of K candidate entities into the task prompt template can be as follows:
[0091] "Based on the provided auxiliary information about relation triples and attribute triples, select the candidate entities that match the target entity from the given candidate entities. Note that there can be multiple matched entities; you only need to output the entity names of the candidate entities."
[0092] Target entity: e1
[0093] Target entity relation triple: h 1,1 r 1,1 It is t 1,1 h 1,2 r 1,2 It is t 1,2 , ..., h 1,i r 1,i It is t 1,i ...
[0094] Target entity attribute triple: h 1,1 a 1,1 It is v 1,1 h 1,2 a 1,2 It is v 1,2 , ..., h 1,i a 1,i It is v 1,i ...
[0095] Candidate Entity 1: e 2,1
[0096] Candidate Entity 1 Relation Triple: h 2,1,1 r 2,1,1 It is t 2,1,1 h 2,1,2 r 2,1,2 It is t 2,1,2 , ..., h 2,1,i r 2,1,i It is t 2,1,i ...
[0097] Candidate Entity 1 Attribute Triple: h 2,1,1 a 2,1,1 It is v 2,1,1 h 2,1,2 a 2,1,2 It is v 2,1,2 , ..., h 2,1,i a 2,1,i It is v 2,1,i ...
[0098] ………
[0099] Candidate entity k: e 2,k
[0100] Candidate entity k relation triple: h 2,k,1 r 2,k,1 It is t 2,k,1 h 2,k,2 r 2,k,2 It is t 2,k,2 , ..., h 2,k,i r 2,k,i It is t 2,k,i ...
[0101] Candidate entity k-attribute triple: h 2,k,1 a 2,k,1 It is v 2,k,1 h 2,k,2 a 2,k,2 It is v 2,k,2 , ..., h 2,k,i a 2,k,i It is v 2,k,i ...
[0102] ………
[0103] Answer (i.e., output field): "
[0104] Therefore, for the special case of one-to-many, the embodiments of this application can achieve one-to-many entity alignment by simply extending the instruction text used in the one-to-one entity alignment scenario, without retraining the model or labeling data. This can improve the flexibility and applicability of the entity alignment method.
[0105] S204, invoke the language model to perform entity selection processing based on the task prompt text, and align the candidate entities selected by the language model with the target entity.
[0106] In practical implementation, the computer device can input task prompt text into a language model. The language model, based on the prompt text and its reasoning capabilities, selects an entity from the target entity and K candidate entities, choosing the candidate entity that matches the target entity. The selected candidate entity's name is then output. The computer device can determine the selected candidate entity based on the language model's output data (i.e., the entity name), thus aligning the selected candidate entity with the target entity. This alignment relationship indicates that the candidate entity and the target entity correspond to the same object in the real world.
[0107] This application embodiment selects one entity from a first knowledge graph as the target entity and K entities from a second knowledge graph as candidate entities. Using the entity information of the target entity and the entity information of the K candidate entities, a task prompt text for a language model is generated. This task prompt text is then input into the language model for inference. The language model, based on the entity information of the target entity and the K candidate entities, selects the candidate entity that best matches the target entity from the K candidate entities, transforming the entity alignment task into a multiple-choice question. This allows the language model to leverage its semantic understanding and inference capabilities to handle the diversity and complexity of entities, determine the candidate entity that best matches the target entity semantically (i.e., the candidate entity selected by the language model), and align the most semantically matching candidate entity with the target entity, improving the accuracy of entity alignment. Furthermore, since the entire process does not rely on manually written alignment rules, it reduces labor costs.
[0108] Based on the above Figure 2 The description of the method embodiments shown in this application provides another entity alignment method. In this application, the implementation of this entity alignment method by a computer device is still used as an example for illustration. Please refer to... Figure 4 As shown, the entity alignment method may include the following steps S401-S405:
[0109] S401, Select an entity from the first knowledge graph as the target entity.
[0110] S402, invoke the vector representation model to generate the entity feature vector of the target entity, and the entity feature vector of each entity in the second knowledge graph.
[0111] The vector representation model mentioned here can be the aforementioned GCN-Align model, TransE model, GAT, TransH model, or MCLEA model. When the vector representation model is the GCN-Align model, based on the aforementioned description of the GCN-Align model, when the computer device executes step S402, it can call the vector representation model to map the first knowledge graph and the second knowledge graph into the same space for encoding, thereby outputting the entity feature vectors of each entity in each knowledge graph in the first and second knowledge graphs, thus obtaining the entity feature vector of the target entity and the entity feature vector of each entity in the second knowledge graph.
[0112] Optionally, before calling the vector representation model, the computer device can also train the vector representation model to improve its performance. This allows the vector representation model to generate the entity feature vector of the target entity and the entity feature vector of each entity in the second knowledge graph more accurately when the computer device executes step S402, thus improving the accuracy of the entity feature vector. In one specific embodiment, the computer device can acquire a large amount of labeled data, including manually aligned entities, and use the acquired labeled data to perform supervised training on the vector representation model. In another embodiment, research has found that name similarity between entities can serve as a good pseudo-alignment supervision signal (the entities corresponding to two highly similar entity names are likely aligned entities). Based on this, this application proposes a method to use name similarity between entities as a heuristic technique to construct a pseudo-alignment training dataset, and then use this training dataset to train the vector representation model, thereby solving the problem that the vector representation model requires a large amount of labeled data to drive training, thus saving labor costs.
[0113] Specifically, the process by which a computer device constructs a pseudo-aligned training dataset and uses this training dataset to train a vector representation model may include the following steps s11-s15:
[0114] s11, traverse each entity in the first knowledge graph, and take the currently traversed entity as the current entity.
[0115] s12, based on the entity name of the current entity and the entity name of each entity in the second knowledge graph, calculate the name similarity between the current entity and each entity in the second knowledge graph.
[0116] In practical implementation, the computer device can represent the entity name of the current entity as a vector, obtaining the name vector of the current entity, and represent the entity name of each entity in the second knowledge graph as a vector, obtaining the name vector of each entity in the second knowledge graph. For any entity in the second knowledge graph (represented by entity e2), a vector similarity algorithm (such as cosine similarity algorithm, Euclidean distance algorithm, etc.) can be used to calculate the vector similarity between the name vector of the current entity and the name vector of entity e2, and then use the calculated vector similarity as the name similarity between the current entity and entity e2.
[0117] One method for representing entity names into vectors and obtaining the corresponding entity name vectors is as follows: The entity name is segmented into multiple words, and a word vector generation algorithm is used to generate a word vector for each word. The average of the word vectors for each word is then used as the corresponding entity name vector. This method of generating name vectors provides richer semantic information and semantic relationships, thereby improving the accuracy of name similarity. It should be noted that the word vector generation algorithm in this application is not limited. For example, it can be GloVe (a word embedding algorithm combining matrix factorization and shallow window methods), word2vec (a method for converting words into computable structured vectors), and so on.
[0118] s13, select M entities from the second knowledge graph in descending order of calculated name similarity, and use the M entities to generate M pseudo-alignment training pairs with the current entity.
[0119] A pseudo-alignment training pair consists of the current entity and one of the M entities, where M is a positive integer. For example, if the current entity is entity Q, and three entities are selected from the second knowledge graph, namely entity a, entity b, and entity c, then three pseudo-alignment training pairs can be generated, namely: (entity Q, entity a), (entity Q, entity b), and (entity Q, entity c).
[0120] s14, after all entities in the first knowledge graph have been traversed, the training dataset for constructing the vector representation model is built using multiple generated pseudo-aligned training pairs.
[0121] In one specific implementation, the computer device can summarize the generated multiple pseudo-aligned training pairs to obtain the training dataset for the vector representation model.
[0122] In another specific implementation, considering that some pseudo-aligned training pairs may have low name similarity, where the name similarity of any pseudo-aligned training pair refers to the name similarity between the two entities in the corresponding pseudo-aligned training pair, these pseudo-aligned training pairs with low name similarity are equivalent to noise. They can easily mislead the vector representation model during model training, thus affecting its performance. Therefore, to reduce the impact of noise, the computer device can retain pseudo-aligned training pairs with name similarity greater than a similarity threshold (e.g., 0.9, 0.85, etc.) for model training. In this case, the computer device can select pseudo-aligned training pairs with name similarity greater than the similarity threshold from the generated multiple pseudo-aligned training pairs, and use the selected pseudo-aligned training pairs to construct the training dataset for the vector representation model.
[0123] Furthermore, when constructing the training dataset for the vector representation model using the selected pseudo-aligned training pairs, the computer device can directly summarize the selected pseudo-aligned training pairs to obtain the training dataset for the vector representation model. Optionally, considering that multiple entities in the first knowledge graph may form a pseudo-aligned training pair with a single entity in the second knowledge graph (that is, the entity with the highest name similarity among multiple entities in the first knowledge graph is the same entity in the second knowledge graph), to avoid this situation, this embodiment of the application can retain the pseudo-aligned training pair with the highest name similarity for model training. For example, the name similarity of the pseudo-aligned training pair (e1, e2) is 0.92, and the name similarity of the pseudo-aligned training pair (e3, e2) is 0.95. Here, e1 and e3 are both entities in the first knowledge graph (i.e., e1∈E1, e3∈E1), while e2 is an entity in the second knowledge graph (i.e., e2∈E2). Since both (e1, e2) and (e3, e2) contain the entity e2, and the name similarity of (e1, e2) is less than that of (e3, e2), (e3, e2) can be retained.
[0124] In this scenario, when the computer device constructs the training dataset for the vector representation model using the selected pseudo-aligned training pairs, it can iterate through each of the selected pseudo-aligned training pairs. If the currently iterated pseudo-aligned training pair does not contain the same entity as any other selected pseudo-aligned training pair, then the currently iterated pseudo-aligned training pair is retained. If the currently iterated pseudo-aligned training pair contains the same entity as at least one other selected pseudo-aligned training pair, then the pseudo-aligned training pair with the highest name similarity is retained among the currently iterated pseudo-aligned training pair and at least one other pseudo-aligned training pair. After all the selected pseudo-aligned training pairs have been iterated through, the retained pseudo-aligned training pairs are summarized to obtain the training dataset for the vector representation model.
[0125] It should be noted that the above are merely illustrative examples of several ways to construct the training dataset for the vector representation model, and are not exhaustive. For example, in other embodiments, the computer device may not filter the generated multiple pseudo-aligned training pairs based on a similarity threshold or the relationship between the name similarity of each pseudo-aligned training pair. Instead, it may directly traverse the generated multiple pseudo-aligned training pairs. If the currently traversed pseudo-aligned training pair does not contain the same entity as any of the other filtered pseudo-aligned training pairs, then the currently traversed pseudo-aligned training pair is retained. If the currently traversed pseudo-aligned training pair contains the same entity as at least one of the other filtered pseudo-aligned training pairs, then the pseudo-aligned training pair with the highest name similarity is retained among the currently traversed pseudo-aligned training pair and at least one other pseudo-aligned training pair. After all the filtered pseudo-aligned training pairs have been traversed, the retained pseudo-aligned training pairs are summarized to obtain the training dataset for the vector representation model.
[0126] s15 uses a training dataset to train the vector representation model, which includes at least one pseudo-aligned training pair.
[0127] In one specific implementation, the computer device can traverse all pseudo-aligned training pairs in the training dataset, determine the j-th pseudo-aligned training pair currently being traversed, and perform entity replacement on one of the entities in the j-th pseudo-aligned training pair to obtain the negative sample corresponding to the j-th pseudo-aligned training pair; where j is a positive integer less than the number of pseudo-aligned training pairs in the training dataset. After all pseudo-aligned training pairs have been traversed, the computer device can use all pseudo-aligned training pairs and corresponding negative samples in the training dataset to perform unsupervised training on the vector representation model.
[0128] One specific implementation of replacing one entity in the j-th pseudo-alignment training pair to obtain the negative sample corresponding to the j-th pseudo-alignment training pair can be: replacing one entity in the j-th pseudo-alignment training pair with a preset entity to obtain the negative sample corresponding to the j-th pseudo-alignment training pair. Alternatively, the computer device can select an entity as a reference entity from a first knowledge graph or a second knowledge graph and replace one entity in the j-th pseudo-alignment training pair with the reference entity to obtain the negative sample corresponding to the j-th pseudo-alignment training pair. The replaced entity and the reference entity belong to the same knowledge graph; optionally, the replaced entity and the reference entity can also belong to different knowledge graphs. Since the two entities in the pseudo-aligned training pair originate from the first knowledge graph and the second knowledge graph, respectively, by selecting entities from the first or second knowledge graph to replace them and generate negative samples, both the pseudo-aligned training pair and the negative samples can originate from the first and second knowledge graphs. This allows the language model to consistently and accurately distinguish between the pseudo-aligned training pair and the negative samples based on the knowledge from the first and second knowledge graphs when training the model using the pseudo-aligned training pair and the negative samples, thereby improving the training effect of the language model.
[0129] Furthermore, the specific implementation method for unsupervised training of the vector representation model using each pseudo-aligned training pair and corresponding negative sample in the training dataset can be as follows: call the vector representation model to generate entity feature vectors of each entity in each pseudo-aligned training pair in the training dataset, and entity feature vectors of each entity in each negative sample; calculate the vector similarity between the entity feature vectors of two entities in each pseudo-aligned training pair, and the vector similarity between the entity feature vectors of two entities in each negative sample; call the loss function to calculate the loss value based on the vector similarity corresponding to each pseudo-aligned training pair and the vector similarity corresponding to the corresponding negative sample, and obtain the model loss value of the vector representation model, thereby optimizing the model parameters of the vector representation model based on the model loss value.
[0130] The aforementioned loss function includes a first hyperparameter (denoted by γ1) and a second hyperparameter (denoted by γ2). The first and second hyperparameters control the distance between the pseudo-aligned training pairs (equivalent to positive samples) and their corresponding negative samples. In this case, the optimization objective of the loss function can be to make the vector similarity corresponding to the pseudo-aligned training pairs greater than the first hyperparameter, and to make the vector similarity corresponding to the negative samples less than the second hyperparameter. Optionally, the loss function may also include a third hyperparameter (denoted by α) to balance the ratio of pseudo-aligned training pairs to negative samples. For example, the loss function can be seen in Equation 1.2 below:
[0131]
[0132] In formula 1.2 above, Represents the model loss value, (e ji e j2 Let ) represent the j-th pseudo-aligned training pair, and S represent the training dataset. and Let each represent a different entity (e) in the j-th pseudo-aligned training pair. ji and e j2 The entity feature vector, express and Vector similarity between them. (e′) i1 ,e′ i2 Let S' represent the negative sample corresponding to the j-th pseudo-aligned training pair, and let S' represent the set of all negative samples. and Let e' and e' represent the two entities (e'') in the negative sample corresponding to the j-th pseudo-alignment training pair. j1 and e′ i2 The entity feature vector, express and Vector similarity between them. [x] + =max(0, x), where x represents or
[0133] Based on the above description of the loss function shown in Formula 1.2, the computer device calls the loss function to calculate the loss value based on the vector similarity corresponding to each pseudo-aligned training pair and the vector similarity corresponding to the corresponding negative sample. The specific way to obtain the model loss value is as follows: Each pseudo-aligned training pair is polled in turn, and the difference between the vector similarity corresponding to the currently polled pseudo-aligned training pair and the first hyperparameter (i.e., γ1) is calculated to obtain the first difference. The maximum value between the first difference and zero is taken as the first loss value. After each pseudo-aligned training pair has been polled, each first loss value is... The first summation result is obtained by summing the results. Then, the negative samples corresponding to each pseudo-aligned training pair are queried in turn. The difference between the second hyperparameter (i.e., γ2) and the vector similarity corresponding to the currently queried negative sample is calculated to obtain the second difference. The maximum value between the second difference and zero is taken as the second loss value. After each negative sample has been queried, the second loss values are summed to obtain the second summation result. The second summation result is scaled (i.e., multiplied) using the third hyperparameter (i.e., α) to obtain the scaled result. The scaled result and the first summation result are then summed to obtain the model loss value.
[0134] It should be noted that the above is merely an illustrative description of one specific implementation of the loss function and is not intended to limit it. For example, in other embodiments, the optimization objective of the loss function may also be to increase the difference between the vector similarity corresponding to the pseudo-aligned training pair and the vector similarity corresponding to the corresponding negative sample. In this case, the computer device calls the loss function to calculate the loss value based on the vector similarity corresponding to each pseudo-aligned training pair and the vector similarity corresponding to the corresponding negative sample. The specific way to obtain the model loss value may be: polling each pseudo-aligned training pair, calculating the difference between the vector similarity corresponding to the currently polled pseudo-aligned training pair and the vector similarity corresponding to the corresponding negative sample, and obtaining the training loss value; after each pseudo-aligned training pair has been polled, summing the obtained training loss values to obtain the model loss value.
[0135] S403, calculate the entity feature vector similarity between the entity feature vector of the target entity and the entity feature vector of each entity in the second knowledge graph; and select K entities from the second knowledge graph as candidate entities according to the calculated entity feature vector similarity from high to low.
[0136] S404, obtain the entity information of the target entity and the entity information of each of the K candidate entities; and use the entity information of the target entity and the entity information of the K candidate entities to generate the task prompt text for the language model.
[0137] S405, invoke the language model to perform entity selection processing based on the task prompt text, and align the candidate entities selected by the language model with the target entity.
[0138] In specific implementation, the detailed methods for steps S403-S405 can be found in the foregoing. Figure 2 The relevant descriptions in the method embodiments shown will not be repeated here. In addition, it should be noted that since the language model is a pre-trained model, it has semantic understanding and reasoning capabilities. Therefore, it is not necessary to train or fine-tune the language model before executing step S405. Of course, in order to enable the language model to perform entity selection processing more accurately, the language model can also be fine-tuned before executing step S405.
[0139] For example, the aforementioned pseudo-alignment training can be used to optimize the language model and fine-tune its parameters. Specifically, the first entity in the pseudo-alignment training pair can be used as the sample entity, and the second entity and at least one other entity in the pair can be used as candidate entities. Using the entity information of the sample entity and each candidate entity, a sample task prompt text is generated. This prompt text prompts the selection of a candidate entity that matches the sample entity from multiple candidate entities, based on the entity information of the sample entity and each candidate entity. Then, the language model can be invoked to perform entity selection based on the sample task prompt text, and the model parameters can be optimized based on the difference between the candidate entity selected by the language model and the second entity in the pseudo-alignment training pair. Thus, this method achieves unsupervised fine-tuning of the language model without requiring a large amount of labeled data, thereby reducing labor costs.
[0140] This application embodiment selects one entity from a first knowledge graph as the target entity and K entities from a second knowledge graph as candidate entities. Using the entity information of the target entity and the entity information of the K candidate entities, a task prompt text for a language model is generated. This task prompt text is then input into the language model for inference. The language model, based on the entity information of the target entity and the K candidate entities, selects the candidate entity that best matches the target entity from the K candidate entities, transforming the entity alignment task into a multiple-choice question. This allows the language model to leverage its semantic understanding and inference capabilities to handle the diversity and complexity of entities, determine the candidate entity that best matches the target entity semantically (i.e., the candidate entity selected by the language model), and align the most semantically matching candidate entity with the target entity, improving the accuracy of entity alignment. Furthermore, since the entire process does not rely on manually written alignment rules, it reduces labor costs.
[0141] Based on the above description, this application also proposes an unsupervised entity alignment method that does not require labeled data. The general principle of this method is as follows: Entity alignment is set as a multiple-choice problem, with the goal of integrating the knowledge of knowledge graphs and language models (LLMs) to leverage the inherent reasoning capabilities of language models to solve the entity alignment problem. Since the number of candidate entities is large and the text length of the LLM input is limited, a vector representation model can be trained by calculating the name similarity between entities and constructing a batch of pseudo-labeled data (i.e., the aforementioned training dataset). The aim is to map entities and relations to a low-dimensional vector space, learn the entity feature vectors of each entity, and calculate the similarity of the entity feature vectors between each entity in the first knowledge graph and each entity in the second knowledge graph. Based on the calculated similarity of the entity feature vectors, the Top K candidate entities corresponding to each entity in the first knowledge graph are recalled from the second knowledge graph, reducing the size of the candidate set. For each entity in the first knowledge graph, the entity information of its corresponding candidate entities (such as entity name, relation triples, attribute triples) is used as options. This transforms the entity alignment task into a multiple-choice question, which is then input into the language model for reasoning. By leveraging the semantic understanding and inference capabilities of the LLM, the candidate option that best matches the semantic association is selected as the predicted alignment result.
[0142] Note: The unsupervised entity alignment method proposed in this application does not require any alignment training data. Instead, the pseudo-labeled data used is a heuristic cold-start technique based on name similarity, which is mainly used to train a representation learning model to embed entities in the graph into a low-dimensional vector space. Furthermore, the language model used does not require training or fine-tuning. Of course, it can be further fine-tuned using pseudo-labeled data to improve the performance of the language model.
[0143] Based on the principles of the above methods, the following will combine... Figure 5 The flowchart shown illustrates the implementation process of the unsupervised entity alignment method proposed in this application embodiment. Specifically, the implementation process can roughly include the following steps:
[0144] Step 1: Construct pseudo-alignment training pairs based on the first and second knowledge graphs. Specifically, one or more pseudo-alignment training pairs can be generated based on the name similarity between each entity in the first knowledge graph and each entity in the second knowledge graph. For details, please refer to the relevant descriptions in the foregoing embodiments, which will not be repeated here. For example, suppose the first knowledge graph includes entities A, B, and C; and the second knowledge graph includes entities D, E, F, and G. Then, the final constructed and retained pseudo-alignment training pairs can include (entity A, entity D) and (entity C, entity F).
[0145] Step 2: Train the vector representation model using the constructed pseudo-aligned training pairs to obtain a vector representation model that can map entities and relations in the knowledge graph to a low-dimensional vector space for vector encoding. For example, use the pseudo-aligned training pairs (entity A, entity D) and (entity C, entity F) to train the vector representation model. The specific training method can be found in the relevant description of the aforementioned embodiments, and will not be repeated here.
[0146] Step 3: After the vector representation model is trained, the vector representation model is called to embed the first knowledge graph and the second knowledge graph into a low-dimensional vector space to obtain the entity feature vectors of each entity in the first knowledge graph (such as the entity feature vector of entity A, entity feature vector of entity B, entity feature vector of entity C), and to generate the entity feature vectors of each entity in the second knowledge graph (such as the entity feature vector of entity D, entity feature vector of entity E, entity feature vector of entity F, entity feature vector of entity G).
[0147] Step 4: Take any entity in the first knowledge graph as the target entity. Based on the similarity between the entity feature vectors of the target entity and the entity feature vectors of each entity in the second knowledge graph, recall K entities from the second knowledge graph as candidate entities, such as recalling entities E, F and G as candidate entities.
[0148] Step 5: Use the entity information of the target entity (such as relation triples and attribute triples) and the entity information of each candidate entity (such as relation triples and attribute triples) to generate task prompt text.
[0149] Step 6: Input the task prompt text into the language model, so that the language model can perform entity selection processing based on the task prompt text, and align the candidate entities selected by the language model with the target entity.
[0150] Based on the above description, the unsupervised entity alignment method proposed in this application can have at least the following beneficial effects: ① It can automatically discover and align semantically related entities without relying on labeled alignment training data, thereby reducing the workload of manually labeling alignment data. ② By using language models for reasoning, the semantic understanding and inference capabilities of language models can be utilized to more accurately select the candidate that best matches the semantic relationship as the alignment result, improving alignment accuracy. ③ It can be applied to entity alignment tasks in different domains and knowledge graphs, and can be customized and optimized according to different application scenarios, improving the scalability and adaptability of the method.
[0151] Based on the description of the above method embodiments, this application also discloses an entity alignment device; the entity alignment device may be a computer program (including one or more instructions) running on a computer device, and the entity alignment device may execute each step in the above method flows. Please refer to... Figure 6 The entity alignment device can operate the following units:
[0152] The acquisition unit 601 is used to select one entity from the first knowledge graph as the target entity and select K entities from the second knowledge graph as candidate entities, where K is a positive integer;
[0153] The acquisition unit 601 is further configured to acquire entity information of the target entity and entity information of each of the K candidate entities;
[0154] Alignment unit 602 is used to generate task prompt text for a language model using the entity information of the target entity and the entity information of the K candidate entities; the task prompt text is used to prompt: based on the entity information of the target entity and the entity information of the K candidate entities, select a candidate entity that matches the target entity from the K candidate entities;
[0155] The alignment unit 602 is further configured to call the language model to perform entity selection processing based on the task prompt text, and align the candidate entities selected by the language model with the target entity.
[0156] In one embodiment, when acquiring entity information of the target entity, the acquisition unit 601 may specifically be used for:
[0157] The structured information of the target entity is obtained from the first knowledge graph. The structured information includes at least one of the following triples: relation triples and attribute triples. The relation triple of the target entity includes the following elements: the entity name of the target entity, the entity name of another entity that has an association relationship with the target entity, and the corresponding association relationship. The attribute triple of the target entity includes the following elements: the entity name of the target entity, the entity attributes that the target entity has, and the attribute values of the corresponding entity attributes.
[0158] The entity information of the target entity is constructed using the entity name and the structured information of the target entity.
[0159] In another embodiment, when the acquisition unit 601 constructs the entity information of the target entity using the entity name and the structured information of the target entity, it may specifically be used for:
[0160] Each triple in the structured information of the target entity is linearized into natural language text; wherein, the method of linearizing any triple into natural language text includes: concatenating the elements in the corresponding triple to obtain natural language text;
[0161] The entity information of the target entity is constructed using the entity name of the target entity and the natural language text corresponding to each triple of the target entity.
[0162] In another implementation, when the acquisition unit 601 selects K entities as candidate entities from the second knowledge graph, it may specifically be used for:
[0163] The vector representation model is invoked to generate the entity feature vector of the target entity, as well as the entity feature vector of each entity in the second knowledge graph;
[0164] Calculate the entity feature vector similarity between the entity feature vector of the target entity and the entity feature vector of each entity in the second knowledge graph;
[0165] Based on the calculated entity feature vector similarity from high to low, K entities are selected as candidate entities from the second knowledge graph.
[0166] In another implementation, the alignment unit 602 may also be used to:
[0167] Traverse each entity in the first knowledge graph and take the currently traversed entity as the current entity;
[0168] Based on the entity name of the current entity and the entity name of each entity in the second knowledge graph, calculate the name similarity between the current entity and each entity in the second knowledge graph;
[0169] According to the calculated name similarity from high to low, select M entities from the second knowledge graph; and use the M entities and the current entity to generate M pseudo-alignment training pairs. Each pseudo-alignment training pair includes the current entity and one of the M entities, where M is a positive integer.
[0170] After all entities in the first knowledge graph have been traversed, a training dataset for constructing a vector representation model is constructed using multiple generated pseudo-alignment training pairs; and the vector representation model is trained using the training dataset.
[0171] In another implementation, the alignment unit 602, when used to construct a training dataset for a vector representation model using multiple generated pseudo-aligned training pairs, may specifically be used to:
[0172] From the generated multiple pseudo-alignment training pairs, select the pseudo-alignment training pairs corresponding to each name similarity greater than the similarity threshold; the name similarity corresponding to any pseudo-alignment training pair refers to the name similarity between the two entities in the corresponding pseudo-alignment training pair.
[0173] The selected pseudo-aligned training pairs are used to construct the training dataset for the vector representation model.
[0174] In another implementation, the alignment unit 602, when used to construct the training dataset for the vector representation model using the selected pseudo-aligned training pairs, can specifically be used for:
[0175] Iterate through each of the selected pseudo-aligned training pairs;
[0176] If the currently traversed pseudo-aligned training pair does not contain the same entity as any of the other selected pseudo-aligned training pairs, then the currently traversed pseudo-aligned training pair is retained.
[0177] If the currently traversed pseudo-aligned training pair contains the same entity as at least one other pseudo-aligned training pair that has been selected, then among the currently traversed pseudo-aligned training pair and at least one other pseudo-aligned training pair, the pseudo-aligned training pair corresponding to the maximum name similarity is retained.
[0178] After all the selected pseudo-aligned training pairs have been traversed, the remaining pseudo-aligned training pairs are summarized to obtain the training dataset for the vector representation model.
[0179] In another embodiment, the training dataset includes at least one pseudo-aligned training pair; correspondingly, the alignment unit 602, when used to train the vector representation model using the training dataset, may specifically be used for:
[0180] Iterate through each pseudo-aligned training pair in the training dataset and determine the j-th pseudo-aligned training pair currently being iterated, where j is a positive integer and less than the number of pseudo-aligned training pairs in the training dataset.
[0181] Entity replacement is performed on one of the entities in the j-th pseudo-alignment training pair to obtain the negative sample corresponding to the j-th pseudo-alignment training pair;
[0182] The vector representation model is trained unsupervised using each pseudo-aligned training pair and corresponding negative samples from the training dataset.
[0183] In another embodiment, when the alignment unit 602 performs entity replacement on one of the entities in the j-th pseudo-alignment training pair to obtain the negative sample corresponding to the j-th pseudo-alignment training pair, it can be specifically used for:
[0184] Select an entity as a reference entity from the first knowledge graph or the second knowledge graph;
[0185] The reference entity is used to replace one of the entities in the j-th pseudo-aligned training pair to obtain the negative sample corresponding to the j-th pseudo-aligned training pair; wherein the replaced entity and the reference entity belong to the same knowledge graph.
[0186] In another implementation, the alignment unit 602, when used to perform unsupervised training of the vector representation model using each pseudo-aligned training pair and corresponding negative samples in the training dataset, may specifically be used to:
[0187] The vector representation model is invoked to generate entity feature vectors for each entity in each pseudo-aligned training pair in the training dataset, as well as entity feature vectors for each entity in each negative sample.
[0188] Calculate the vector similarity between the entity feature vectors of the two entities in each pseudo-aligned training pair, and the vector similarity between the entity feature vectors of the two entities in each negative sample;
[0189] The loss function is called to calculate the loss value based on the vector similarity of each pseudo-aligned training pair and the vector similarity of the corresponding negative sample, so as to obtain the model loss value of the vector representation model.
[0190] Based on the model loss value, optimize the model parameters of the vector representation model.
[0191] In another embodiment, the loss function includes a first hyperparameter and a second hyperparameter, which are used to control the distance between the pseudo-aligned training pair and the corresponding negative sample;
[0192] The optimization objective of the loss function is to make the vector similarity of the pseudo-aligned training pairs greater than the first hyperparameter, and to make the vector similarity of the corresponding negative samples less than the second hyperparameter.
[0193] According to another embodiment of this application, Figure 6The units in the entity alignment device shown can be individually or entirely merged into one or more other units, or some of the units can be further divided into multiple functionally smaller units. This achieves the same operation without affecting the technical effects of the embodiments of this application. The above units are based on logical function division. In practical applications, the function of one unit can be implemented by multiple units, or the function of multiple units can be implemented by one unit. In other embodiments of this application, the entity alignment device may also include other units. In practical applications, these functions can also be implemented with the assistance of other units, and can be implemented collaboratively by multiple units.
[0194] According to another embodiment of this application, a computer program (including one or more instructions) capable of performing the steps involved in the above method embodiments can be run on a general-purpose computing device, such as a computer, which includes processing elements and storage elements such as a central processing unit (CPU), random access memory (RAM), and read-only memory (ROM), to construct a system such as... Figure 6 The entity alignment apparatus shown herein, and the various methods proposed in the embodiments of this application, are used to implement the computer program. The computer program may be recorded on, for example, a computer-readable storage medium, loaded onto the aforementioned computing device via the computer-readable storage medium, and run therein.
[0195] It is worth noting that, in the embodiments of this application, the terms "module" or "unit" refer to a computer program or part of a computer program with a predetermined function, which works together with other related parts to achieve a predetermined goal, and can be implemented wholly or partially using software, hardware (such as processing circuitry or memory), or a combination thereof. Similarly, a processor (or multiple processors or memory) can be used to implement one or more modules or units. Furthermore, each module or unit can contain a portion of the overall module or unit's functionality.
[0196] This application embodiment selects one entity from a first knowledge graph as the target entity and K entities from a second knowledge graph as candidate entities. Using the entity information of the target entity and the entity information of the K candidate entities, a task prompt text for a language model is generated. This task prompt text is then input into the language model for inference. The language model, based on the entity information of the target entity and the K candidate entities, selects the candidate entity that best matches the target entity from the K candidate entities, transforming the entity alignment task into a multiple-choice question. This allows the language model to leverage its semantic understanding and inference capabilities to handle the diversity and complexity of entities, determine the candidate entity that best matches the target entity semantically (i.e., the candidate entity selected by the language model), and align the most semantically matching candidate entity with the target entity, improving the accuracy of entity alignment. Furthermore, since the entire process does not rely on manually written alignment rules, it reduces labor costs.
[0197] Based on the description of the above method and apparatus embodiments, this application also provides a computer device. Please refer to... Figure 7 The computer device includes at least a processor 701, an input interface 702, an output interface 703, and a computer storage medium 704. The processor 701, input interface 702, output interface 703, and computer storage medium 704 within the computer device can be connected via a bus or other means. The computer storage medium 704 can be stored in the computer device's memory. The computer storage medium 704 is used to store a computer program, which includes one or more instructions. The processor 701 is used to execute one or more instructions from the computer program stored in the computer storage medium 704. The processor 701 (or CPU (Central Processing Unit)) is the computing and control core of the computer device, adapted to implement one or more instructions, specifically adapted to load and execute one or more instructions to achieve a corresponding method flow or function.
[0198] In one embodiment, the processor 701 described in this application can be used to perform a series of entity alignment processes between any two knowledge graphs, specifically including: selecting an entity from a first knowledge graph as a target entity, and selecting K entities from a second knowledge graph as candidate entities, where K is a positive integer; obtaining entity information of the target entity, and obtaining entity information of each of the K candidate entities; using the entity information of the target entity and the entity information of the K candidate entities to generate a task prompt text for a language model; the task prompt text is used to prompt: based on the entity information of the target entity and the entity information of the K candidate entities, select a candidate entity that matches the target entity from the K candidate entities; call the language model to perform entity selection processing according to the task prompt text, and align the candidate entity selected by the language model with the target entity, etc.
[0199] This application embodiment also provides a computer storage medium (Memory), which is a memory device in a computer device used to store computer programs and data. It is understood that the computer storage medium here can include both the built-in storage medium in the computer device and extended storage media supported by the computer device. The computer storage medium provides storage space that stores the operating system of the computer device. Furthermore, the storage space also stores a computer program, which includes one or more instructions suitable for loading and execution by the processor 701. These instructions can be one or more program codes. It should be noted that the computer storage medium here can be high-speed RAM or non-volatile memory, such as at least one disk storage device; optionally, it can also be at least one computer storage medium located remotely from the aforementioned processor.
[0200] In one embodiment, a processor may load and execute one or more instructions stored in a computer storage medium to implement the corresponding steps in the above method embodiments; specifically, one or more instructions in the computer storage medium may be loaded and executed by the processor in the following steps:
[0201] Select one entity from the first knowledge graph as the target entity, and select K entities from the second knowledge graph as candidate entities, where K is a positive integer;
[0202] Obtain the entity information of the target entity, and obtain the entity information of each of the K candidate entities;
[0203] Using the entity information of the target entity and the entity information of the K candidate entities, a task prompt text for the language model is generated; the task prompt text is used to prompt: based on the entity information of the target entity and the entity information of the K candidate entities, select a candidate entity that matches the target entity from the K candidate entities;
[0204] The language model is invoked to perform entity selection processing based on the task prompt text, and the candidate entities selected by the language model are aligned with the target entity.
[0205] In one implementation, when acquiring entity information of the target entity, the one or more instructions may be loaded and executed by the processor:
[0206] The structured information of the target entity is obtained from the first knowledge graph. The structured information includes at least one of the following triples: relation triples and attribute triples. The relation triple of the target entity includes the following elements: the entity name of the target entity, the entity name of another entity that has an association relationship with the target entity, and the corresponding association relationship. The attribute triple of the target entity includes the following elements: the entity name of the target entity, the entity attributes that the target entity has, and the attribute values of the corresponding entity attributes.
[0207] The entity information of the target entity is constructed using the entity name and the structured information of the target entity.
[0208] In another implementation, when constructing the entity information of the target entity using the entity name and the structured information of the target entity, the one or more instructions can be loaded and executed by the processor:
[0209] Each triple in the structured information of the target entity is linearized into natural language text; wherein, the method of linearizing any triple into natural language text includes: concatenating the elements in the corresponding triple to obtain natural language text;
[0210] The entity information of the target entity is constructed using the entity name of the target entity and the natural language text corresponding to each triple of the target entity.
[0211] In another implementation, when selecting K entities as candidate entities from the second knowledge graph, the one or more instructions can be loaded and executed by the processor:
[0212] The vector representation model is invoked to generate the entity feature vector of the target entity, as well as the entity feature vector of each entity in the second knowledge graph;
[0213] Calculate the entity feature vector similarity between the entity feature vector of the target entity and the entity feature vector of each entity in the second knowledge graph;
[0214] Based on the calculated entity feature vector similarity from high to low, K entities are selected as candidate entities from the second knowledge graph.
[0215] In another implementation, the one or more instructions may be loaded and executed by the processor before the vector representation model is invoked:
[0216] Traverse each entity in the first knowledge graph and take the currently traversed entity as the current entity;
[0217] Based on the entity name of the current entity and the entity name of each entity in the second knowledge graph, calculate the name similarity between the current entity and each entity in the second knowledge graph;
[0218] According to the calculated name similarity from high to low, select M entities from the second knowledge graph; and use the M entities and the current entity to generate M pseudo-alignment training pairs. Each pseudo-alignment training pair includes the current entity and one of the M entities, where M is a positive integer.
[0219] After all entities in the first knowledge graph have been traversed, a training dataset for constructing a vector representation model is constructed using multiple generated pseudo-alignment training pairs; and the vector representation model is trained using the training dataset.
[0220] In another implementation, when constructing a training dataset for a vector representation model using multiple generated pseudo-aligned training pairs, the one or more instructions can be loaded and executed by the processor:
[0221] From the generated multiple pseudo-alignment training pairs, select the pseudo-alignment training pairs corresponding to each name similarity greater than the similarity threshold; the name similarity corresponding to any pseudo-alignment training pair refers to the name similarity between the two entities in the corresponding pseudo-alignment training pair.
[0222] The selected pseudo-aligned training pairs are used to construct the training dataset for the vector representation model.
[0223] In another implementation, when constructing the training dataset for the vector representation model using the selected pseudo-aligned training pairs, the one or more instructions can be loaded and executed by the processor:
[0224] Iterate through each of the selected pseudo-aligned training pairs;
[0225] If the currently traversed pseudo-aligned training pair does not contain the same entity as any of the other selected pseudo-aligned training pairs, then the currently traversed pseudo-aligned training pair is retained.
[0226] If the currently traversed pseudo-aligned training pair contains the same entity as at least one other pseudo-aligned training pair that has been selected, then among the currently traversed pseudo-aligned training pair and at least one other pseudo-aligned training pair, the pseudo-aligned training pair corresponding to the maximum name similarity is retained.
[0227] After all the selected pseudo-aligned training pairs have been traversed, the remaining pseudo-aligned training pairs are summarized to obtain the training dataset for the vector representation model.
[0228] In another implementation, the training dataset includes at least one pseudo-aligned training pair; correspondingly, when training the vector representation model using the training dataset, the one or more instructions can be loaded and executed by the processor:
[0229] Iterate through each pseudo-aligned training pair in the training dataset and determine the j-th pseudo-aligned training pair currently being iterated, where j is a positive integer and less than the number of pseudo-aligned training pairs in the training dataset.
[0230] Entity replacement is performed on one of the entities in the j-th pseudo-alignment training pair to obtain the negative sample corresponding to the j-th pseudo-alignment training pair;
[0231] The vector representation model is trained unsupervised using each pseudo-aligned training pair and corresponding negative samples from the training dataset.
[0232] In another implementation, when entity replacement is performed on one of the entities in the j-th pseudo-aligned training pair to obtain the negative sample corresponding to the j-th pseudo-aligned training pair, the one or more instructions can be loaded and executed by the processor:
[0233] Select an entity as a reference entity from the first knowledge graph or the second knowledge graph;
[0234] The reference entity is used to replace one of the entities in the j-th pseudo-aligned training pair to obtain the negative sample corresponding to the j-th pseudo-aligned training pair; wherein the replaced entity and the reference entity belong to the same knowledge graph.
[0235] In another implementation, when the vector representation model is trained unsupervised using each pseudo-aligned training pair and corresponding negative samples in the training dataset, the one or more instructions can be loaded and executed by the processor:
[0236] The vector representation model is invoked to generate entity feature vectors for each entity in each pseudo-aligned training pair in the training dataset, as well as entity feature vectors for each entity in each negative sample.
[0237] Calculate the vector similarity between the entity feature vectors of the two entities in each pseudo-aligned training pair, and the vector similarity between the entity feature vectors of the two entities in each negative sample;
[0238] The loss function is called to calculate the loss value based on the vector similarity of each pseudo-aligned training pair and the vector similarity of the corresponding negative sample, so as to obtain the model loss value of the vector representation model.
[0239] Based on the model loss value, optimize the model parameters of the vector representation model.
[0240] In another embodiment, the loss function includes a first hyperparameter and a second hyperparameter, which are used to control the distance between the pseudo-aligned training pair and the corresponding negative sample;
[0241] The optimization objective of the loss function is to make the vector similarity of the pseudo-aligned training pairs greater than the first hyperparameter, and to make the vector similarity of the corresponding negative samples less than the second hyperparameter.
[0242] This application embodiment selects one entity from a first knowledge graph as the target entity and K entities from a second knowledge graph as candidate entities. Using the entity information of the target entity and the entity information of the K candidate entities, a task prompt text for a language model is generated. This task prompt text is then input into the language model for inference. The language model, based on the entity information of the target entity and the K candidate entities, selects the candidate entity that best matches the target entity from the K candidate entities, transforming the entity alignment task into a multiple-choice question. This allows the language model to leverage its semantic understanding and inference capabilities to handle the diversity and complexity of entities, determine the candidate entity that best matches the target entity semantically (i.e., the candidate entity selected by the language model), and align the most semantically matching candidate entity with the target entity, improving the accuracy of entity alignment. Furthermore, since the entire process does not rely on manually written alignment rules, it reduces labor costs.
[0243] It should be noted that, according to one aspect of this application, a computer program product or computer program is also provided, comprising one or more instructions stored in a computer storage medium. A processor of a computer device reads one or more instructions from the computer storage medium and executes the one or more instructions, causing the computer device to perform the methods provided in various optional embodiments of the above-described method. It should be understood that the above-disclosed embodiments are merely preferred embodiments of this application and should not be construed as limiting the scope of this application. Therefore, equivalent variations made according to the claims of this application are still within the scope of this application.
Claims
1. A method for aligning entities, characterized in that, include: Select one entity from the first knowledge graph as the target entity, and select K entities from the second knowledge graph as candidate entities, where K is a positive integer; Obtain the entity information of the target entity, and obtain the entity information of each of the K candidate entities; Using the entity information of the target entity and the entity information of the K candidate entities, a task prompt text for the language model is generated; The task prompt text is used to prompt: Based on the entity information of the target entity and the entity information of the K candidate entities, select a candidate entity that matches the target entity from the K candidate entities; The language model is invoked to perform entity selection processing based on the task prompt text, and the candidate entities selected by the language model are aligned with the target entity.
2. The method as described in claim 1, characterized in that, The step of obtaining the entity information of the target entity includes: The structured information of the target entity is obtained from the first knowledge graph. The structured information includes at least one of the following triples: relation triples and attribute triples. The relation triple of the target entity includes the following elements: the entity name of the target entity, the entity name of another entity that has an association relationship with the target entity, and the corresponding association relationship. The attribute triple of the target entity includes the following elements: the entity name of the target entity, the entity attributes that the target entity has, and the attribute values of the corresponding entity attributes. The entity information of the target entity is constructed using the entity name and the structured information of the target entity.
3. The method as described in claim 2, characterized in that, The step of constructing the entity information of the target entity using the entity name and the structured information of the target entity includes: Each triple in the structured information of the target entity is linearized into natural language text; wherein, the method of linearizing any triple into natural language text includes: concatenating the elements in the corresponding triple to obtain natural language text; The entity information of the target entity is constructed using the entity name of the target entity and the natural language text corresponding to each triple of the target entity.
4. The method according to any one of claims 1-3, characterized in that, The step of selecting K entities as candidate entities from the second knowledge graph includes: The vector representation model is invoked to generate the entity feature vector of the target entity, as well as the entity feature vector of each entity in the second knowledge graph; Calculate the entity feature vector similarity between the entity feature vector of the target entity and the entity feature vector of each entity in the second knowledge graph; Based on the calculated entity feature vector similarity from high to low, K entities are selected as candidate entities from the second knowledge graph.
5. The method as described in claim 4, characterized in that, Before invoking the vector representation model, the method further includes: Traverse each entity in the first knowledge graph and take the currently traversed entity as the current entity; Based on the entity name of the current entity and the entity name of each entity in the second knowledge graph, calculate the name similarity between the current entity and each entity in the second knowledge graph; According to the calculated name similarity from high to low, select M entities from the second knowledge graph; and use the M entities and the current entity to generate M pseudo-alignment training pairs. Each pseudo-alignment training pair includes the current entity and one of the M entities, where M is a positive integer. After all entities in the first knowledge graph have been traversed, a training dataset for constructing a vector representation model is constructed using multiple generated pseudo-alignment training pairs; and the vector representation model is trained using the training dataset.
6. The method as described in claim 5, characterized in that, The training dataset for constructing the vector representation model using multiple generated pseudo-aligned training pairs includes: From the generated multiple pseudo-alignment training pairs, select the pseudo-alignment training pairs corresponding to each name similarity greater than the similarity threshold; the name similarity corresponding to any pseudo-alignment training pair refers to the name similarity between the two entities in the corresponding pseudo-alignment training pair. The selected pseudo-aligned training pairs are used to construct the training dataset for the vector representation model.
7. The method as described in claim 6, characterized in that, The training dataset for constructing the vector representation model using the selected pseudo-aligned training pairs includes: Iterate through each of the selected pseudo-aligned training pairs; If the currently traversed pseudo-aligned training pair does not contain the same entity as any of the other selected pseudo-aligned training pairs, then the currently traversed pseudo-aligned training pair is retained. If the currently traversed pseudo-aligned training pair contains the same entity as at least one other pseudo-aligned training pair that has been selected, then among the currently traversed pseudo-aligned training pair and at least one other pseudo-aligned training pair, the pseudo-aligned training pair corresponding to the maximum name similarity is retained. After all the selected pseudo-aligned training pairs have been traversed, the remaining pseudo-aligned training pairs are summarized to obtain the training dataset for the vector representation model.
8. The method as described in claim 5, characterized in that, The training dataset includes at least one pseudo-aligned training pair, and the step of training the vector representation model using the training dataset includes: Iterate through each pseudo-aligned training pair in the training dataset and determine the j-th pseudo-aligned training pair currently being iterated, where j is a positive integer and less than the number of pseudo-aligned training pairs in the training dataset. Entity replacement is performed on one of the entities in the j-th pseudo-alignment training pair to obtain the negative sample corresponding to the j-th pseudo-alignment training pair; The vector representation model is trained unsupervised using each pseudo-aligned training pair and corresponding negative samples from the training dataset.
9. The method as described in claim 8, characterized in that, The step of replacing one entity in the j-th pseudo-alignment training pair to obtain the negative sample corresponding to the j-th pseudo-alignment training pair includes: Select an entity as a reference entity from the first knowledge graph or the second knowledge graph; The reference entity is used to replace one of the entities in the j-th pseudo-aligned training pair to obtain the negative sample corresponding to the j-th pseudo-aligned training pair; wherein the replaced entity and the reference entity belong to the same knowledge graph.
10. The method as described in claim 8, characterized in that, The step of using each pseudo-aligned training pair and corresponding negative sample in the training dataset to perform unsupervised training on the vector representation model includes: The vector representation model is invoked to generate entity feature vectors for each entity in each pseudo-aligned training pair in the training dataset, as well as entity feature vectors for each entity in each negative sample. Calculate the vector similarity between the entity feature vectors of the two entities in each pseudo-aligned training pair, and the vector similarity between the entity feature vectors of the two entities in each negative sample; The loss function is called to calculate the loss value based on the vector similarity of each pseudo-aligned training pair and the vector similarity of the corresponding negative sample, so as to obtain the model loss value of the vector representation model. Based on the model loss value, optimize the model parameters of the vector representation model.
11. The method as described in claim 10, characterized in that, The loss function includes a first hyperparameter and a second hyperparameter, which are used to control the distance between the pseudo-aligned training pair and the corresponding negative sample; The optimization objective of the loss function is to make the vector similarity of the pseudo-aligned training pairs greater than the first hyperparameter, and to make the vector similarity of the corresponding negative samples less than the second hyperparameter.
12. A solid alignment device, characterized in that, include: The acquisition unit is used to select one entity from the first knowledge graph as the target entity and select K entities from the second knowledge graph as candidate entities, where K is a positive integer; The acquisition unit is further configured to acquire entity information of the target entity, and acquire entity information of each of the K candidate entities; An alignment unit is used to generate task prompt text for a language model by using the entity information of the target entity and the entity information of the K candidate entities. The task prompt text is used to prompt: Based on the entity information of the target entity and the entity information of the K candidate entities, select a candidate entity that matches the target entity from the K candidate entities; The alignment unit is further configured to invoke the language model to perform entity selection processing based on the task prompt text, and align the candidate entities selected by the language model with the target entity.
13. A computer device, comprising an input interface and an output interface, characterized in that, Also includes: Processor and computer storage media; The processor is adapted to implement one or more instructions, the computer storage medium stores one or more instructions, and the one or more instructions are adapted to be loaded by the processor and executed as the entity alignment method as described in any one of claims 1-11.
14. A computer storage medium, characterized in that, The computer storage medium stores one or more instructions, which are adapted to be loaded by a processor and executed as the entity alignment method as described in any one of claims 1-11.
15. A computer program product, characterized in that, The computer program product includes one or more instructions; when one or more instructions in the computer program are executed by a processor, they implement the entity alignment method as described in any one of claims 1-11.