Knowledge injection and training methods and systems for knowledge-enhanced pre-trained language model

By identifying and injecting important elements into the knowledge-enhanced pre-trained language model, and updating only the neuron parameters related to knowledge, the noise problem and the high consumption of computing resources during knowledge injection are solved, and the robustness and robustness of the model are improved. Training efficiency.

WO2024193382A1PCT designated stage expired Publication Date: 2024-09-26HANGZHOU ALICLOUD FEITIAN INFORMATION TECH CO LTD

Patent Information

Application Number
PCT/CN2024/081037
Authority / Receiving Office
WO · WO
Patent Type
Applications
Current Assignee / Owner
Priority Date
2023-03-20
Filing Date
2024-03-11
Publication Date
2024-09-26

AI Technical Summary

Technical Problem

Existing knowledge-enhanced pre-trained language models lack focus on knowledge injection, resulting in increased knowledge noise, reduced model performance, and high consumption of computing resources during the training process, increasing costs.

Method used

By identifying important elements in pre-trained sentences based on the domain knowledge graph, such as important entities and long-tail words, inject them into the training data of the pre-trained language model, and use the memory library to store and update the embedded representations of important elements, updating only knowledge-related neuron parameters, reducing the impact of redundant knowledge and consumption of computing resources.

Benefits of technology

It achieves focused knowledge learning, reduces knowledge noise, improves model robustness, reduces training costs and resource overhead, and improves training efficiency.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN2024081037_26092024_PF_FP
    Figure CN2024081037_26092024_PF_FP
Patent Text Reader

Abstract

Knowledge injection and training methods and systems for a knowledge enhanced pre-trained language model are disclosed. The methods comprise: on the basis of a domain knowledge graph, identifying important elements in a pre-training statement, injecting the important elements into training data of a pre-trained language model to obtain knowledge-enhanced training data, and inputting the knowledge-enhanced training data into the pre-trained language model; for each layer of a feed-forward network, on the basis of the inputted training data and a knowledge evaluation target, determining the probability of generating a correct answer to the knowledge evaluation target, then determining a knowledge attribution score in respect of each neuron according to the probability; then, from each layer, taking neurons that have knowledge attribution scores that meet a preset condition as knowledge neurons so as to generate a knowledge path comprising said knowledge neurons; and on the basis of a preset loss function, updating parameters of the knowledge path. Knowledge noise is reduced by means of learning according to the weight of the injected knowledge, robustness is high, and the knowledge path can be identified so as to reduce the amount of updated system parameters, thus reducing resource consumption.
Need to check novelty before this filing date? Find Prior Art

Description

Knowledge-enhanced pre-trained language model knowledge injection and training method and system

[0001] This application claims priority to the Chinese patent application filed with the China Patent Office on March 20, 2023, with application number 202310277777.1 and application name “Knowledge-enhanced pre-trained language model knowledge injection and training method and system”, the entire contents of which are incorporated by reference into this application. Technical Field

[0002] The present invention relates to the field of machine learning technology, and in particular to a knowledge-enhanced pre-trained language model knowledge injection and training method and system. Background Art

[0003] Pre-trained language models (PLMs) can learn sentence word representations from massive amounts of data to improve the performance of language models in downstream tasks. Although PLMs have achieved promising results and are useful in many natural language processing (NLP) tasks, they have neglected the integration of knowledge into language understanding. To better apply PLMs to knowledge-driven and semantic understanding tasks, a PLM that improves language understanding by injecting rich external knowledge, namely the Knowledge-Enhanced Pre-trained Language Model (KEPLM), was proposed. KEPLM improves the performance of PLMs by injecting external knowledge triples from the Knowledge Graph (KG). To learn from these injected knowledge triples, KEPLM designs knowledge-related pre-training tasks, forcing the model to learn the injected knowledge. Existing knowledge-enhanced pre-trained language models, such as ERNIE, K-Bert, KEPLER, and CoLAKE, all achieve knowledge learning and training by injecting triples or pre-trained knowledge into each entity in the corpus sentences.

[0004] Summary of the Invention

[0005] The inventors of this application have discovered that the current KEPLM has the following two important problems:

[0006] Previous KEPLMs lacked a focus on knowledge injection, which introduced knowledge noise and reduced model performance. Knowledge noise includes redundant and irrelevant knowledge, such as entities that appear multiple times in a sentence. This redundant knowledge can lead to repeated information. Furthermore, irrelevant knowledge involving certain entities or their corresponding subgraphs has little relevance to the semantics of the entire sentence. Therefore, irrelevant entities do not contribute to the final task evaluation metrics. The presence of knowledge noise, caused by the lack of a focus on learning knowledge triples, results in poor system robustness.

[0007] Previous KEPLMs used additional knowledge encoders to modify the model's structure, limiting its applicability. Furthermore, KEPLM designed knowledge-related tasks to force the model to learn the information contained in knowledge triples. This required updating all system parameters when updating system parameters, consuming significant computational resources and increasing the cost of training KEPLM.

[0008] Therefore, how to focus on learning knowledge triples to enhance the robustness of the model and reduce the training cost of KEPLM is a challenging task with practical application significance.

[0009] In view of the above problems, the present invention is proposed to provide a knowledge-enhanced pre-trained language model knowledge injection and training method and system that overcomes the above problems or at least partially solves the above problems.

[0010] An embodiment of the present invention provides a knowledge-enhanced pre-trained language model training method, comprising:

[0011] Based on the domain knowledge graph, identify important elements in the pre-trained sentences, including important entities detected by semantic correlation methods and / or long-tail words detected by frequency of occurrence;

[0012] The important elements are injected into the training data of the pre-trained language model to obtain knowledge-enhanced training data as input data of the model.

[0013] In some optional embodiments, identifying important elements in pre-trained sentences based on the domain knowledge graph includes:

[0014] Based on the triples in the domain knowledge graph, the entities in the pre-trained sentences are detected, and the important entities in the pre-trained sentences are detected by comparing the semantic relevance between the pre-trained sentences and the replacement sentences after the detected entities are replaced by entities; the triples include entities, relations, and entities;

[0015] According to the frequency of occurrence of words in the pre-training corpus, long-tail words in the pre-training sentences are detected.

[0016] In some optional embodiments, detecting important entities in the pre-trained sentence by comparing the semantic relevance between the pre-trained sentence and the replacement sentence after entity replacement of the detected entity includes:

[0017] Performing entity replacement on the entities in the pre-trained sentence to obtain a replacement sentence including the replaced entities;

[0018] Based on the layer normalization function, an embedded representation of the pre-trained sentence and an embedded representation of the replacement pre-sentence are obtained, and the semantic relevance between the pre-trained sentence and the replacement sentence is determined according to the embedded representation of the pre-trained sentence and the embedded representation of the replacement pre-sentence.

[0019] Entities whose semantic relevance meets the preset conditions are identified as important entities.

[0020] In some optional embodiments, the above method further includes:

[0021] Storing the detected embedding representations of important elements in a pre-established memory bank, wherein the memory bank includes an entity bank for storing embedding representations of important entities and a vocabulary bank for storing embedding representations of long-tail words; or updating the embedding representation of the important element stored in the memory bank based on the detected embedding representation of the important element;

[0022] Correspondingly, injecting the important elements into the training data of the pre-trained language model includes: injecting the embedded representation of the important elements stored in the memory bank into the training data of the pre-trained language model.

[0023] In some optional embodiments, updating the embedded representation of the important element stored in the memory based on the detected embedded representation of the important element includes:

[0024] Obtain the storage location of the embedded representation of the detected important elements in the memory bank;

[0025] The stored embedding representation of the important element at the storage location and the new embedding representation obtained after the important element is detected this time are summed to obtain an updated embedding representation of the important element.

[0026] An embodiment of the present invention provides a knowledge-enhanced pre-trained language model training method, comprising:

[0027] Inputting knowledge-enhanced training data into the knowledge-enhanced pre-trained language model; the knowledge-enhanced training data is obtained using the above-mentioned knowledge-enhanced pre-trained language model knowledge injection method;

[0028] For each layer of the feedforward network of the pre-trained language model, determining the probability of generating a correct answer to the knowledge evaluation target based on the input training data and the knowledge evaluation target, and determining the knowledge attribution score of each neuron based on the probability;

[0029] The neurons in each layer whose knowledge attribution scores meet preset conditions are used as knowledge neurons, and a knowledge path including the knowledge neurons is generated;

[0030] The parameters of the knowledge path are updated based on a preset loss function.

[0031] In some optional embodiments, determining the probability of generating a correct answer to the knowledge evaluation target based on the input training data and the knowledge evaluation target, and determining the knowledge attribution score of each neuron based on the probability includes:

[0032] A normalized exponential function is used to obtain the probability of generating the correct answer to the knowledge evaluation target corresponding to the input sequence of the training data;

[0033] For each neuron, a knowledge attribution score of the neuron is determined according to the gradient of the probability of generating a correct answer to the knowledge evaluation target.

[0034] In some optional embodiments, taking neurons in each layer whose knowledge attribution scores meet preset conditions as knowledge neurons and generating a knowledge path including the knowledge neurons includes:

[0035] The neuron with the highest knowledge attribution score in each layer is determined as the knowledge neuron of that layer, and the knowledge neurons of each layer are connected through paths to generate a knowledge path.

[0036] In some optional embodiments, updating the parameters of the knowledge path based on a preset loss function includes:

[0037] Determine a contrastive learning loss function for the embedded representations of entities included in the training sentences obtained by processing the Transformer encoder. The loss function maximizes the similarity between the predicted correct answer output by the model and the true value, and minimizes the similarity between the predicted correct answer and the fake answer corresponding to the replacement entity.

[0038] The gradient of the model parameters is calculated according to the loss function, and the gradient of the knowledge path is updated.

[0039] An embodiment of the present invention provides a knowledge-enhanced pre-trained language model knowledge injection system, comprising:

[0040] A Transformer encoder is used to identify important elements in pre-trained sentences based on the domain knowledge graph, such as important entities detected by semantic correlation methods and / or long-tail words detected by frequency of occurrence; and inject these important elements into the training data of the pre-trained language model;

[0041] Memory, used to store embedded representations of important elements.

[0042] An embodiment of the present invention provides a knowledge-enhanced pre-trained language model training system, including:

[0043] The Transformer encoder identifies important elements in pre-trained sentences based on the domain knowledge graph, wherein the important elements include important entities detected by semantic correlation methods and long-tail words detected by frequency of occurrence; the important elements are injected into the training data of the pre-trained language model, wherein a dynamic routing module is provided for inputting the knowledge-enhanced training data into the knowledge-enhanced pre-trained language model; for each layer of the feedforward network of the pre-trained language model, the probability of generating a correct answer to the knowledge evaluation target is determined based on the input training data and the knowledge evaluation target, and the knowledge attribution score of each neuron is determined based on the probability; the neurons in each layer whose knowledge attribution scores meet the preset conditions are used as knowledge neurons, and a knowledge path including the knowledge neurons is generated; the parameters of the knowledge path are updated based on a preset loss function;

[0044] Memory, used to store embedded representations of important elements.

[0045] An embodiment of the present invention provides a computer storage medium, which stores computer-executable instructions. When the computer-executable instructions are executed by a processor, the above-mentioned knowledge-enhanced pre-trained language model knowledge injection method and / or the above-mentioned knowledge-enhanced pre-trained language model training method are implemented.

[0046] An embodiment of the present invention provides an electronic device, comprising: a memory, a processor, and a computer program stored in the memory and runnable on the processor. When the processor executes the program, the above-mentioned knowledge-enhanced pre-trained language model knowledge injection method and / or the above-mentioned knowledge-enhanced pre-trained language model training method are implemented.

[0047] The beneficial effects of the above technical solutions provided by the embodiments of the present invention include at least:

[0048] The knowledge injection method for the knowledge-enhanced pre-trained language model provided in an embodiment of the present invention identifies important elements in pre-trained sentences, such as important entities and long-tail words, based on the domain knowledge graph, and injects the identified important elements into the training data of the pre-trained language model to obtain knowledge-enhanced training data as input data of the model, thereby enabling focused learning in the knowledge injection learning process, reducing knowledge noise caused by redundant knowledge and irrelevant knowledge, and improving the robustness of the system.

[0049] The knowledge-enhanced pre-trained language model training method provided by the embodiment of the present invention reduces knowledge noise and improves the robustness of the system by identifying important elements, realizes the identification of knowledge neurons in neurons through comparative learning, and updates the model parameters of the knowledge path composed of knowledge neurons without having to update all system parameters, thereby reducing the data processing volume of parameter updates, reducing resource overhead, improving the speed and efficiency of update processing, and reducing hardware costs.

[0050] Other features and advantages of the present invention will be described in the following description, and in part will become apparent from the description, or will be understood by practicing the present invention. The purposes and other advantages of the present invention can be realized and obtained by the structures particularly pointed out in the written description, claims, and drawings.

[0051] The technical solution of the present invention is further described in detail below through the accompanying drawings and embodiments. BRIEF DESCRIPTION OF THE DRAWINGS

[0052] The accompanying drawings are used to provide a further understanding of the present invention and constitute a part of the specification. Together with the embodiments of the present invention, they are used to explain the present invention and do not constitute a limitation of the present invention. In the accompanying drawings:

[0053] FIG1 is a schematic diagram of a knowledge training model for a knowledge-enhanced pre-trained language model according to an embodiment of the present invention;

[0054] FIG2 is a flow chart of a method for injecting knowledge into a knowledge-enhanced pre-trained language model according to a first embodiment of the present invention;

[0055] FIG3 is a schematic diagram showing the principle of a knowledge-enhanced pre-trained language model knowledge training method according to an embodiment of the present invention;

[0056] FIG4 is a flow chart of a knowledge training method for a knowledge-enhanced pre-trained language model according to a second embodiment of the present invention;

[0057] FIG5 is a schematic diagram of the structure of a knowledge-enhanced pre-trained language model knowledge injection device according to an embodiment of the present invention;

[0058] FIG6 is a schematic diagram of the structure of a knowledge training device for a knowledge-enhanced pre-trained language model according to an embodiment of the present invention. DETAILED DESCRIPTION

[0059] Exemplary embodiments of the present disclosure will be described in more detail below with reference to the accompanying drawings. Although exemplary embodiments of the present disclosure are shown in the accompanying drawings, it should be understood that the present disclosure can be implemented in various forms and should not be limited by the embodiments set forth herein. Rather, these embodiments are provided to enable a more thorough understanding of the present disclosure and to fully convey the scope of the present disclosure to those skilled in the art.

[0060] Since the existing KEPLM does not focus on knowledge injection and all system parameters must be updated when updating system parameters, the KEPLM system has problems such as poor robustness, large resource overhead, and high cost.

[0061] For example, the Enhanced Language Representation with Informative Entities (ERNIE) model introduces a new entity encoder to capture the semantic associations between entities and sentences. It then uses a denoising entity auto-encoder (DEA) to randomly mask some entities and subsequently predict the masked entities. However, the introduction of a new entity encoder introduces new parameters and modifies the model structure, hindering its general applicability.

[0062] A Unified Model for Knowledge Embedding and Pre-trained Language Representation (KEPLER) uses the same encoder (Transformer) to encode text and entities into a unified semantic space. For entities, the entity and its description text are fed into the Transformer, and the Transformer encoding method is used to reduce the distance between the head entity, relations, and tail entities. However, this injection of all entities does not consider the potential for noise hidden within the entities to adversely affect the model.

[0063] The Decomposable Knowledge-enhanced Pre-trained Language Model for Natural Language Understanding (DKPLM) enhances the semantic understanding capabilities of the KEPLM by detecting knowledge-aware long-tail entities as targets for knowledge injection, thereby avoiding the injection of redundant information. The embeddings of long-tail entities are replaced with "pseudo-representations" formed by related knowledge triples. A relational knowledge decoding task is designed for pre-training to force the model to truly understand the injected knowledge through relational reconstruction. However, the introduction of the relational knowledge decoding task requires the model to calculate the loss and update all model parameters, which is computationally intensive.

[0064] Therefore, in order to focus on learning entities in knowledge triples and accelerate the training of knowledge-enhanced pre-trained language models, the present invention proposes a new KEPLM training method for REALM. Referring to the differences between PLM, KEPLM and REALM shown in Figure 1, PLM usually uses masked language modeling as a pre-training object and processes the input representation through a Transformer Encoder. KEPLM utilizes external knowledge sources, such as KG, and designs knowledge perception tasks that require additional knowledge encoders. The input representation is processed by the Transformer Encoder, the input entity is processed by the knowledge encoder, and the processing results of the two are fused through a fusion module. REALM adds a memory bank to memorize the representations of important elements such as important entities and long-tail words, and adds a knowledge path recognition function to the Transformer Encoder. REALM uses a shared encoder and a knowledge-enhanced memory bank to inject factual knowledge during pre-training, and only needs to use a dynamic knowledge routing method to update some FFN parameters in the Transformer module to reduce the number of updated parameters and reduce resource consumption.

[0065] The novel KEPLM training method provided by the present invention can train KEPLM more robustly and efficiently, and is a robustly optimized BERT pretraining approach (RoBERTa). In order to reduce the introduction of excessive knowledge noise, important entities and long-tail words are detected as targets of knowledge injection by calculating semantic importance. A knowledge-augmented memory bank (KMB) is constructed to promote the learning of the representation of important entities and long-tail words, which can guide the learning of entities during the pre-training process and accelerate network convergence. In addition, in order to reduce the consumption of computing resources, the parameters in the Transformer module are selectively updated through dynamic knowledge routing (DKR). Specifically, knowledge-related tasks are used to identify knowledge paths composed of neurons (KN) that store knowledge and knowledge neurons, so that model parameters can be selectively updated to accelerate model training.

[0066] Example 1

[0067] Embodiment 1 of the present invention provides a method for injecting knowledge into a knowledge-enhanced pre-trained language model. The process is shown in FIG2 , and the principle is shown in FIG3 . The method includes the following steps:

[0068] Step S101: Based on the domain knowledge graph, identify important elements in the pre-trained sentence, where the important elements include important entities detected by semantic correlation methods and / or long-tail words detected by occurrence frequency.

[0069] Step S102: injecting important elements into the training data of the pre-trained language model to obtain knowledge-enhanced training data as input data of the model.

[0070] In the above step S101, based on the domain knowledge graph, important elements in the pre-trained sentences are identified, including the detection of important entities and long-tail words. Of course, it can also include the detection of other important elements. The important elements to be detected can be selected according to the needs of model training.

[0071] For the detection of important entities, based on the triples in the domain knowledge graph, the entities in the pre-trained sentences are detected. The important entities in the pre-trained sentences are detected through the semantic correlation between the pre-trained sentences and the replacement sentences after the detected entities are replaced by entities; the triples include entity, relationship, and entity.

[0072] Optionally, the process of detecting important entities includes: performing entity replacement on entities in pre-trained sentences to obtain replacement sentences including replaced entities; based on a layer normalization function, obtaining an embedded representation of the pre-trained sentence and an embedded representation of the replacement pre-sentence, determining the semantic relevance between the pre-trained sentence and the replacement sentence based on the embedded representation of the pre-trained sentence and the embedded representation of the replacement pre-sentence, and determining entities whose semantic relevance meets preset conditions as important entities.

[0073] For the detection of long-tail words, the long-tail words in the pre-training sentences are detected based on the frequency of occurrence of the words in the pre-training corpus.

[0074] Optionally, the detected important elements can be memorized through a set memory network and used in the subsequent model training process. That is, the above method also includes:

[0075] The embedded representation of the detected important element is stored in a pre-established memory bank, which may include an entity bank for storing the embedded representation of important entities and a vocabulary bank for storing the embedded representation of long-tail words; or the embedded representation of the important element stored in the memory bank is updated based on the embedded representation of the detected important element.

[0076] When an important element is detected for the first time from a pre-trained sentence in the pre-training corpus, its embedded representation is stored in the memory bank. When the important element is detected again, the embedded representation of the important element stored in the memory bank is updated based on the new embedded representation obtained when the important element is detected again. The new embedded representation and the stored embedded representation are added together to obtain the updated embedded representation.

[0077] When updating important elements in the memory bank, the update is performed based on the storage location of the important elements. The storage location of the detected important element's embedded representation in the memory bank is obtained; the stored embedded representation of the important element at the storage location and the new embedded representation obtained after the important element is detected are summed to obtain the updated embedded representation of the important element.

[0078] Accordingly, injecting the important elements into the training data of the pre-trained language model includes injecting the embedded representations of the important elements stored in the memory bank into the training data of the pre-trained language model.

[0079] In the above method of this embodiment, based on the domain knowledge graph, important elements in the pre-trained sentences, such as important entities and long-tail words, are identified, and the identified important elements are injected into the existing training data of the pre-trained language model to obtain knowledge-enhanced training data as the input data of the model, thereby enabling focused learning in the knowledge injection learning process, reducing knowledge noise caused by redundant knowledge and irrelevant knowledge, and improving the robustness of the system.

[0080] Example 2

[0081] A second embodiment of the present invention provides a method for training a knowledge-enhanced pre-trained language model, the process of which is shown in FIG4 and includes the following steps:

[0082] Step S201: Identify important elements in pre-trained sentences based on the domain knowledge graph.

[0083] Step S202: injecting important elements into the training data of the pre-trained language model to obtain knowledge-enhanced training data as input data of the model.

[0084] Step S203: inputting the knowledge-enhanced training data into the knowledge-enhanced pre-trained language model.

[0085] Step S204: For each layer of the feedforward network of the pre-trained language model, determine the probability of generating a correct answer to the knowledge evaluation target based on the input training data and the knowledge evaluation target, and determine the knowledge attribution score of each neuron based on the probability of generating a correct answer to the knowledge evaluation target.

[0086] For each layer of the feedforward network of the pre-trained language model, such as the input layer, intermediate layer, and output layer in FFN, the knowledge attribution score of each neuron in each layer is determined, so that the knowledge neurons in each layer can be determined based on the knowledge attribution score.

[0087] When determining the knowledge attribution score, a normalized exponential function is used to obtain the probability of generating a correct answer to the knowledge evaluation target corresponding to the input sequence of the training data; for each neuron, the knowledge attribution score of the neuron is determined based on the gradient of the probability of generating a correct answer to the knowledge evaluation target.

[0088] Step S205: Neurons in each layer whose knowledge attribution scores meet preset conditions are used as knowledge neurons, and a knowledge path including the knowledge neurons is generated.

[0089] In this step, the neuron with the highest knowledge attribution score in each layer is identified as the knowledge neuron in that layer. The knowledge neurons in each layer are connected via paths to generate a knowledge path. A neuron with the highest knowledge attribution score in a layer is identified as the knowledge neuron. Optionally, identification conditions can be set to identify neurons in each layer that meet the conditions as knowledge neurons. Connecting the knowledge neurons in each layer generates a knowledge path, allowing the parameters of the knowledge path to be updated.

[0090] Step S206: updating the parameters of the knowledge path based on a preset loss function.

[0091] For the embedded representations obtained by processing the Transformer encoder of the entities included in the training sentences, contrastive learning is used to determine the loss function of contrastive learning. The loss function maximizes the similarity between the predicted correct answer output by the model and the true value, and minimizes the similarity with the forged answer corresponding to the replaced entity; the gradient of the model parameters is calculated according to the loss function, and the gradient of the knowledge path is updated.

[0092] In this embodiment, knowledge noise is reduced and the robustness of the system is improved by identifying important elements. Knowledge neurons in neurons are identified through comparative learning, and model parameters are updated for the knowledge paths composed of knowledge neurons without having to update all system parameters. This reduces the amount of data processing for parameter updates, reduces resource overhead, improves the speed and efficiency of update processing, and also reduces hardware costs.

[0093] Example 3

[0094] The third embodiment of the present invention provides a specific process of a knowledge injection and training method for a knowledge-enhanced pre-trained language model. The method is a new framework for training KEPLM, in which two innovative mechanisms are designed to accelerate the injection of knowledge information into the PLM without the need for additional parameters: (1) A knowledge-enhanced memory network that considers the injection of important entities. (2) Through a dynamic knowledge routing method, the knowledge path related to factual knowledge is updated, which accelerates the training of the PLM and enhances the language understanding ability of the model. Experiments show that the KEPLM model achieves relatively good performance in knowledge detection tasks and knowledge-aware language understanding tasks.

[0095] As shown in FIG3 , the knowledge-enhanced pre-trained language model injection and training method provided in the third embodiment of the present invention includes three stages: an input stage, a forward propagation stage, and a backpropagation stage.

[0096] Input stage:

[0097] Important entities are detected through semantic relevance, and long-tail words are detected through frequency of occurrence. Important elements including important entities and long-tail words are injected into the input text as the input of the model to reduce the knowledge noise brought by the injection of all entities.

[0098] As shown in Figure 3, the knowledge graph includes knowledge triples, which can include entities, relationships, and entities. For example, they can be head entities, relationships, and tail entities. For the detection of important entities, take the pre-trained sentence "The Walt Disney Company, commonly known as Disney, is an American multinational mass media and entertainment conglomerate headquartered at the Walt Disney Studios complex in Burbank, California" in the pre-training corpus as an example. Based on the knowledge triples in the knowledge graph, the important entities detected are "the Walt Disney Company" and "mass media", and the long-tail words detected are "conglomerate".

[0099] An important entity refers to an entity in a pre-trained sentence that changes its meaning after being replaced by another entity. Such an entity is an important entity. If the meaning of the sentence does not change after replacement, it is not an important entity.

[0100] The detection of important entities is measured using semantic relevance SI(e). When constructing the embedding representation of entities used to replace important elements based on knowledge triples, when the important element is the head entity of the knowledge triple, the embedding representation includes the tail entity embedding representation minus the relational word embedding representation; when the important element is the tail entity of the knowledge triple, the embedding representation includes the head entity embedding representation plus the relational word embedding representation.

[0101] Semantic relevance SI(e) is expressed as follows: where h o is the representation of the original sentence, hrep is a representation of the replacement statement after the entity is replaced:

[0102] If the entity in the sentence is the head entity e in the knowledge triple h , then e h Characterized by Replace; if the entity in the sentence is the tail entity e in the knowledge triple t , then e t Characterized by Replace. Among them,

[0103] is the layer normalization function, Is the head entity e h The token is input into the sentence representation of the last layer output in PLM <cls>, A similar method can be used to obtain W r are the training parameters.

[0104] Long-tail words refer to words that appear less frequently, or rare words. The rarity of these rare words prevents the model from learning a good embedding for the word, resulting in the model being unable to understand the word when it encounters it.

[0105] If this is the first time that the important element is detected, the embedded representation of the detected important element is stored in the memory bank. If this is not the first time that the important element is detected, the embedded representation (token embedding) of the detected important element is merged with the embedded representation of the important entity stored in the memory bank, that is, the stored value (stored value) and the new value (new value) are added to obtain the replaced embedding, and the new embedded representation of the important element is stored in the memory bank.

[0106] In this embodiment, optionally, the memory library may include two libraries, one is a word library, which stores the embeddings of long-tail words, and the other is an entity library, which stores the embeddings of important entities.

[0107] The knowledge-enhanced memory network or memory bank can deepen the model's understanding of important elements. If e is a long-tail entity, the "memory" of e in the memory bank can be expressed as:

[0108] where h i ∈R d1 is the output of the Transformer encoder at position i and is used as the context representation of x, where x represents the input sequence. l and r are the starting and ending positions of entity e, and k is the size of the window to control the number of surrounding tokens, that is, to control how much information around entity e is stored in the memory network. Since entity e may appear multiple times in the pre-training corpus, the "memory" of entity e in KMB is represented as The moving average of each M(e, x) is frequently used for updating. Knowledge-enhanced memory network The value in can be updated according to the following formula, γ is a hyperparameter, which is selected as γ∈(0,1) in the implementation:

[0109] When the embedding representation of position p is an important element such as a long-tail word or an important entity, the final embedding representation of the p-th position It can be obtained by the following formula:

[0110] where ε p is the token embedding of the p-th position, It is e j The embedding of λ is used to control the reliance on the memory network.

[0111] Forward propagation phase:

[0112] In each forward propagation process, the important elements in the memory bank can be updated by formula (3), and M(e, x) in formula (3) is obtained by formula (2).

[0113] In order to make the model understand the injected knowledge, a knowledge-aware task is designed based on the masked language model task, that is, a comparative learning knowledge task. Represented as the last layer e of the Transformer encoder h The corresponding representation in and h r , if you want to predict the i-th embedding representation of the tail entity {hd i } can be generated iteratively in the following way, where δ d is the scaling factor, W d is a learnable parameter, and is initialized to

[0114] For embedded representation Use contrastive learning to force the model to capture knowledge, yes Matching function between targets. The contrastive learning loss function at the token level is as follows:

[0115] Among them, y i is the true value, such as California in the previous example, y′ i Negative examples are obtained through negative sampling, for example, randomly replacing the word "Shanghai" or "Beijing" in a replacement sentence. The loss function is used to maximize the similarity between the predicted correct answer output by the model and the true value, while minimizing the similarity with the fake answer after replacement.

[0116] The contrastive learning loss function allows positive samples to have a much higher score than negative samples by flexibly defining the positive and negative samples. The loss function is calculated during the forward propagation phase, allowing model parameters to be adjusted based on the loss function during the backward propagation phase.

[0117] To obtain knowledge paths, it is necessary to find knowledge neurons in the forward propagation. Dynamic Knowledge Routing (DKR) finds knowledge neurons and knowledge paths in FFN through knowledge attribution, and selectively updates model parameters.

[0118] In each FFN layer, the attribution score of the neuron is calculated through the knowledge evaluation task. Based on the attribution score, the knowledge neurons are screened and the knowledge path is obtained. After the forward propagation, the output of the last Transformer layer can be used to update the embedding representation of important elements stored in the knowledge-augmented memory bank.

[0119] For a given input sequence x, Defined as the probability of generating the correct answer to the knowledge assessment objective:

[0120] Where p represents the softmax function, y * Indicates the correct answer, represents the i-th neuron in the l-th FFN, for The given value of .

[0121] For the neurons in the FFN network, taking the i-th neuron in the l-th layer FFN as an example, we can use The gradient of The attribution score can be calculated by the following formula:

[0122] When α changes from 0 to 1, Indicated by The change in output probability caused by the integral gradient is used. Since continuous integrals are difficult to calculate directly, in practice, we can use formula (7) after using the Riemann approximation and set the value of m based on experience, for example, setting the value of m to 20:

[0123] The knowledge neurons of each layer can be found based on the attribution score. For example, the neurons with the highest attribution score in each layer are used as knowledge neurons. By connecting the knowledge neurons of each layer (such as the input layer, middle layer, output layer, etc.), the knowledge path can be obtained:

[0124] use Indicates the The i-th node of the input layer of the layer FFN, Indicates the The j-th node in the middle layer of the layer FFN, Indicates the The kth node of the output layer of the FFN layer. Then the knowledge path obtained by the knowledge neurons in each layer can be used It means that updating this part of the knowledge path related to knowledge can achieve the effect of updating some parameters in the network and accelerating network training.

[0125] Backpropagation phase:

[0126] In this embodiment, only some parameters of the model are updated in the back propagation stage. After the knowledge path is found in the forward propagation stage, the parameters corresponding to the knowledge path found in the forward propagation are updated to accelerate the training. When updating the parameters, the loss function can be used to calculate the loss function. Calculate the gradient w and update the gradient w belonging to the knowledge path. It can be obtained according to formula (5), or after calculating the losses of different entities according to formula (5), it can be obtained by weighted summation based on the set hyperparameters

[0127] To accelerate knowledge-enhanced language model training and enhance robustness, the knowledge-enhanced memory network utilizes key entity injection to prioritize knowledge injection. Furthermore, through a dynamic knowledge routing approach, knowledge neurons and knowledge paths are found by calculating the attribution values ​​of neurons in the network. This knowledge path, associated with factual knowledge, is updated, accelerating PLM training and enhancing the model's language comprehension capabilities. Experiments demonstrate that the REALM model achieves superior performance on knowledge detection and knowledge-aware language comprehension tasks.

[0128] Based on the same inventive concept, an embodiment of the present invention further provides a knowledge-enhanced pre-trained language model knowledge injection system, as shown in FIG1 , comprising:

[0129] The Transformer encoder is used to identify important elements in pre-trained sentences based on the domain knowledge graph. The important elements include important entities detected by semantic correlation methods and long-tail words detected by frequency of occurrence; and the important elements are injected into the training data of the pre-trained language model.

[0130] Memory, used to store embedded representations of important elements.

[0131] Based on the same inventive concept, an embodiment of the present invention further provides a knowledge-enhanced pre-trained language model training system, as shown in FIG1 , comprising:

[0132] The Transformer encoder identifies important elements in pre-trained sentences based on the domain knowledge graph, wherein the important elements include important entities detected by semantic correlation methods and long-tail words detected by frequency of occurrence; the important elements are injected into the training data of the pre-trained language model, wherein a dynamic routing module is provided for inputting the knowledge-enhanced training data into the knowledge-enhanced pre-trained language model; for each layer of the feedforward network of the pre-trained language model, the probability of generating a correct answer to the knowledge evaluation target is determined based on the input training data and the knowledge evaluation target, and the knowledge attribution score of each neuron is determined based on the probability; the neurons in each layer whose knowledge attribution scores meet the preset conditions are used as knowledge neurons, and a knowledge path including the knowledge neurons is generated; the parameters of the knowledge path are updated based on a preset loss function.

[0133] Memory, used to store embedded representations of important elements.

[0134] Based on the same inventive concept, an embodiment of the present invention further provides a knowledge-enhanced pre-trained language model injection device, which can be provided in an electronic device. The structure of the device is shown in FIG5 , and includes:

[0135] Identification module 11, for identifying important elements in pre-trained sentences based on the domain knowledge graph, wherein the important elements include important entities detected by semantic correlation method and long-tail words detected by frequency of occurrence;

[0136] The injection module 12 is used to inject the important elements into the training data of the pre-trained language model to obtain knowledge-enhanced training data as input data of the model.

[0137] Based on the same inventive concept, an embodiment of the present invention further provides a knowledge-enhanced pre-trained language model training device, which can be provided in an electronic device. The structure of the device is shown in FIG6 , and includes:

[0138] An input module 21 is used to input knowledge-enhanced training data into the knowledge-enhanced pre-trained language model;

[0139] The dynamic routing module 22 is configured to determine, for each layer of the feedforward network of the pre-trained language model, the probability of generating a correct answer to the knowledge evaluation target based on the input training data and the knowledge evaluation target, and determine the knowledge attribution score of each neuron based on the probability; and to select neurons in each layer whose knowledge attribution scores meet preset conditions as knowledge neurons, and to generate a knowledge path including the knowledge neurons;

[0140] The parameter updating module 23 is configured to update the parameters of the knowledge path based on a preset loss function.

[0141] An embodiment of the present invention also provides a computer storage medium, which stores computer-executable instructions. When the computer-executable instructions are executed by a processor, the above-mentioned knowledge-enhanced pre-trained language model knowledge injection method and / or the above-mentioned knowledge-enhanced pre-trained language model training method are implemented.

[0142] An embodiment of the present invention also provides an electronic device, comprising: a memory, a processor, and a computer program stored in the memory and runnable on the processor, wherein when the processor executes the program, the above-mentioned knowledge-enhanced pre-trained language model knowledge injection method and / or the above-mentioned knowledge-enhanced pre-trained language model training method are implemented.

[0143] Regarding the apparatus in the above embodiment, the specific manner in which each module performs operations has been described in detail in the embodiment of the method, and will not be elaborated here.

[0144] The above-mentioned method and apparatus of the embodiment of the present invention can be integrated into the open source code library of the NLP algorithm framework.

[0145] The method provided by an embodiment of the present invention is a robust knowledge injection and training acceleration algorithm for knowledge-augmented pre-trained language models, providing a model framework that enables more robust and efficient knowledge learning. Because words and entities in a corpus follow a long-tail distribution, some are often not well learned by the language model, slowing down the pre-training process. This problem is addressed by more robustly injecting knowledge triples and using a knowledge-augmented memory bank to capture useful knowledge. Furthermore, updating only a small portion of neurons in the feed-forward network (FFN) that store factual knowledge during backpropagation is a more efficient training approach. Specifically, dynamic knowledge routing is used to identify knowledge paths in the feed-forward network and selectively update some parameters during pre-training. Experimental results show that this solution reduces pre-training time by at least 50% and outperforms other knowledge-augmented pre-trained language models on knowledge probing and multiple knowledge-aware language understanding tasks.

[0146] Unless otherwise specifically stated, terms such as process, calculate, compute, determine, display, and the like may refer to the actions and / or processes of one or more processing or computing systems, or similar devices, that manipulate and convert data represented as physical (e.g., electronic) quantities within registers or memories of a processing system into other data similarly represented as physical quantities within the memories, registers, or other such information storage, transmission, or display devices of the processing system. Information and signals may be represented using any of a variety of different techniques and methods. For example, data, instructions, commands, information, signals, bits, symbols, and chips referred to throughout the above description may be represented by voltages, currents, electromagnetic waves, magnetic fields or particles, light fields or particles, or any combination thereof.

[0147] It should be understood that the specific order or hierarchy of steps in the disclosed processes is an example of an exemplary method. Based on design preferences, it should be understood that the specific order or hierarchy of steps in the process can be rearranged without departing from the scope of the present disclosure. The accompanying method claims present elements of the various steps in an exemplary order and are not intended to be limited to the specific order or hierarchy described.

[0148] In the foregoing detailed description, various features are grouped together in a single embodiment to simplify the disclosure. This method of disclosure should not be interpreted as reflecting an intention that embodiments of the claimed subject matter require more features than are expressly recited in each claim. On the contrary, as reflected in the appended claims, the invention comprises less than all the features of any individual disclosed embodiment. The appended claims are therefore hereby expressly incorporated into the detailed description, with each claim standing on its own as a separate preferred embodiment of the invention.

[0149] Those skilled in the art will also appreciate that the various illustrative logic blocks, modules, circuits, and algorithmic steps described in conjunction with the embodiments herein may be implemented as electronic hardware, computer software, or a combination thereof. In order to clearly illustrate the interchangeability between hardware and software, the various illustrative components, blocks, modules, circuits, and steps described above are generally described around their functions. Whether such functions are implemented as hardware or software depends on the specific application and the design constraints imposed on the entire system. A skilled person may implement the described functions in an adaptable manner for each specific application, but such implementation decisions should not be interpreted as departing from the scope of protection of this disclosure.

[0150] The steps of the methods or algorithms described in conjunction with the embodiments herein may be directly embodied as hardware, software modules executed by a processor, or a combination thereof. The software module may be located in a RAM memory, flash memory, ROM memory, EPROM memory, EEPROM memory, register, hard disk, removable disk, CD-ROM, or any other form of storage medium well known in the art. An exemplary storage medium is connected to the processor so that the processor can read information from the storage medium and write information to the storage medium. Of course, the storage medium may also be an integral part of the processor. The processor and storage medium may be located in an ASIC. The ASIC may be located in a user terminal. Of course, the processor and storage medium may also be present in a user terminal as discrete components.

[0151] For software implementation, the techniques described in this application can be implemented using modules (e.g., procedures, functions, etc.) that perform the functions described in this application. These software codes can be stored in a memory unit and executed by a processor. The memory unit can be implemented within the processor or external to the processor. In the latter case, it is communicatively coupled to the processor via various means, which are well known in the art.

[0152] The foregoing description includes examples of one or more embodiments. Of course, it is not possible to describe all possible combinations of components or methods for the purposes of describing the above embodiments, but one of ordinary skill in the art will recognize that the various embodiments may be further combined and arranged. Therefore, the embodiments described herein are intended to encompass all such changes, modifications and variations that fall within the scope of the appended claims. Furthermore, to the extent that the term "comprising" is used in the specification or claims, the term is intended to be encompassed in a manner similar to the term "including," as explained when "including" is used as a transitional word in the claims. Furthermore, any use of the term "or" in the specification of the claims is intended to mean a "non-exclusive or."< / cls>

Claims

1. A knowledge enhancement pre-trained language model knowledge injection method, characterized in that: include: Based on the domain knowledge graph, identify important elements in the pre-trained sentences, wherein the important elements include important entities detected by semantic correlation methods and / or long-tail words detected by occurrence frequency; The important elements are injected into the training data of the pre-trained language model to obtain knowledge-enhanced training data as input data of the model.

2. The method according to claim 1, characterized in that The important elements in the pre-trained sentences are identified based on the domain knowledge graph, including: Based on the triples in the domain knowledge graph, the entities in the pre-trained sentences are detected, and the important entities in the pre-trained sentences are detected through the semantic correlation between the pre-trained sentences and the replacement sentences after the detected entities are replaced by entities; the triples include entities, relations, and entities; According to the frequency of occurrence of words in the pre-training corpus, long-tail words in the pre-training sentences are detected.

3. The method according to claim 2, characterized in that The detecting of important entities in the pre-trained sentences by comparing the semantic relevance between the pre-trained sentences and the replacement sentences after the detected entities are replaced by entities includes: Performing entity replacement on the entities in the pre-trained sentence to obtain a replacement sentence including the replaced entity; Based on the layer normalization function, an embedded representation of the pre-trained sentence and an embedded representation of the replacement pre-sentence are obtained, and the semantic relevance between the pre-trained sentence and the replacement sentence is determined according to the embedded representation of the pre-trained sentence and the embedded representation of the replacement pre-sentence, Entities whose semantic relevance meets the preset conditions are identified as important entities.

4. The method according to any one of claims 1 to 3, characterized in that Also includes: Storing the detected embedding representations of important elements in a pre-established memory bank, wherein the memory bank includes an entity bank for storing the embedding representations of important entities and a word bank for storing the embedding representations of long-tail words; or updating the embedded representation of the important element stored in the memory bank based on the detected embedded representation of the important element; Correspondingly, injecting the important elements into the training data of the pre-trained language model includes: injecting the embedded representation of the important elements stored in the memory bank into the training data of the pre-trained language model.

5. The method according to any one of claims 1 to 3, characterized in that The updating of the embedded representation of the important element stored in the memory based on the detected embedded representation of the important element includes: Obtain the storage location of the embedded representation of the detected important elements in the memory bank; The stored embedded representation of the important element at the storage location and the new embedded representation obtained after the important element is detected this time are summed to obtain an updated embedded representation of the important element.

6. A knowledge-enhanced pre-trained language model training method, characterized in that: include: Input the knowledge-enhanced training data into the knowledge-enhanced pre-trained language model; The knowledge-enhanced training data is obtained by using the knowledge-enhanced pre-trained language model knowledge injection method described in any one of claims 1 to 5; For each layer of the feedforward network of the pre-trained language model, determine the probability of generating a correct answer to the knowledge evaluation target according to the input training data and the knowledge evaluation target, and determine the knowledge attribution score of each neuron according to the probability; Taking the neurons in each layer whose knowledge attribution scores meet preset conditions as knowledge neurons, and generating a knowledge path including the knowledge neurons; The parameters of the knowledge path are updated based on a preset loss function.

7. The method according to claim 6, characterized in that The step of determining the probability of generating a correct answer to the knowledge evaluation target based on the input training data and the knowledge evaluation target, and determining the knowledge attribution score of each neuron based on the probability, includes: A normalized exponential function is used to obtain the probability of generating a correct answer to the knowledge assessment target corresponding to the input sequence of the training data; For each neuron, a knowledge attribution score of the neuron is determined according to the gradient of the probability of generating a correct answer to the knowledge evaluation target.

8. The method according to claim 6, characterized in that The step of taking neurons in each layer whose knowledge attribution scores meet preset conditions as knowledge neurons and generating a knowledge path including the knowledge neurons comprises: The neuron with the highest knowledge attribution score in each layer is determined as the knowledge neuron of that layer, and the knowledge neurons of each layer are connected through paths to generate a knowledge path.

9. The method according to any one of claims 6 to 8, characterized in that: The updating of the parameters of the knowledge path based on a preset loss function includes: For the embedded representation obtained by processing the Transformer encoder of the entity included in the training sentence, a contrastive learning method is used to determine a contrastive learning loss function, wherein the loss function maximizes the similarity between the predicted correct answer output by the model and the true value, and minimizes the similarity between the predicted correct answer output by the model and the fake answer corresponding to the replacement entity; The gradient of the model parameters is calculated according to the loss function, and the gradient of the knowledge path is updated.

10. A knowledge-enhanced pre-trained language model knowledge injection system, characterized in that: include: Transformer encoder, used to identify important elements in pre-trained sentences based on domain knowledge graph, wherein the important elements include important entities detected by semantic correlation method and / or long-tail words detected by occurrence frequency; Injecting the important elements into the training data of the pre-trained language model; Memory, used to store embedded representations of important elements.

11. A knowledge-enhanced pre-trained language model training system, characterized in that: include: A Transformer encoder is used to identify important elements in a pre-trained sentence based on a domain knowledge graph, wherein the important elements include important entities detected by a semantic correlation method and long-tail words detected by an occurrence frequency; the important elements are injected into the training data of a pre-trained language model, wherein a dynamic routing module is provided for inputting the knowledge-enhanced training data into the knowledge-enhanced pre-trained language model; for each layer of the feedforward network of the pre-trained language model, the probability of generating a correct answer to the knowledge evaluation target is determined according to the input training data and the knowledge evaluation target, and the knowledge attribution score of each neuron is determined according to the probability; Taking the neurons in each layer whose knowledge attribution scores meet preset conditions as knowledge neurons, and generating a knowledge path including the knowledge neurons; Updating the parameters of the knowledge path based on a preset loss function; Memory, used to store embedded representations of important elements.

12. A computer storage medium, characterized in that: The computer storage medium stores computer executable instructions, which, when executed by the processor, implement the knowledge enhancement pre-trained language model knowledge injection method described in any one of claims 1-5 and / or the knowledge enhancement pre-trained language model training method described in any one of claims 6-9.

13. An electronic device, characterized in that: include: A memory, a processor, and a computer program stored in the memory and executable on the processor, wherein when the processor executes the program, the knowledge enhancement pre-trained language model knowledge injection method described in any one of claims 1-5 and / or the knowledge enhancement pre-trained language model training method described in any one of claims 6-9 are implemented.

Citation Information

Patent Citations

  • A method and apparatus for enhancing labeled samples

    CN110991181A

  • Knowledge injection method of pre-training language model and corresponding interaction system

    CN114936287A

  • Knowledge injection method and interaction system of Chinese pre-training language model

    CN115688753A

  • Knowledge injection and training method and system for knowledge enhancement pre-training language model

    CN116450839A

  • System and method for hybrid question answering over knowledge graph

    US20220292262A1

Cited By

  • Geographic name entity identification method based on spatial relation perception, medium and equipment

    CN119129600A

  • Model training method and device based on preference learning and storage medium thereof

    CN119441863A

  • Stable knowledge editing method and system based on attention drift constraint

    CN119443059A

  • Knowledge injection attack-based robustness evaluation method in field of large language model law

    CN119494405A

  • Retrieval enhancement generation method and device, computer program product and electronic equipment

    CN119621933A