Entity relationship joint extraction method and system for Chinese text in carbon neutralization field
By jointly extracting Chinese text entity relationships in the field of carbon neutrality, the ChatGLM3 interface is used for data enhancement, and noise and hierarchical demasking strategies are added to the Atom-7B large model, combined with dynamic loss functions, to solve the annotation imbalance. It solves the problem of model overfitting and improves the performance of entity relationship extraction.
Patent Information
- Application Number
- CN202410548218.4
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-05-06
- Publication Date
- 2024-09-03
- Estimated Expiration
- 2044-05-06
AI Technical Summary
Existing technologies have labeling imbalance problems and model overfitting problems in the joint extraction of entity relationships from Chinese texts in the carbon-neutral field, and the instruction fine-tuning method performs poorly in sequence labeling tasks, making it difficult to effectively extract features of Chinese texts.
The ChatGLM3 interface is used for data enhancement. By adding noise to the Embedding layer of the Atom-7B large model, and using a layered demasking strategy, combined with the dynamic loss function, the PFN module pays more attention to difficult tasks during the training process and optimizes Entity relationship joint extraction model.
It alleviates the problem of training set data imbalance, improves Chinese text feature extraction capabilities, and improves the performance of entity relationship extraction, especially in named entity recognition and relationship extraction tasks.
Smart Images

Figure CN118585643A
Abstract
Description
Technical Field
[0001] The present invention relates to the field of natural language processing, and in particular to a method and system for jointly extracting entity relationships of Chinese texts in the field of carbon neutrality. Background Art
[0002] To build a knowledge graph in the field of carbon neutrality, we must first obtain text related to the field of carbon neutrality. The key is to extract relationship triplets from the text. The step of extracting relationship triplets is also called relationship extraction. There are two types of relationship extraction methods: pipeline method and joint extraction method. The joint extraction method directly obtains entity triplets with existing relationships through a joint model of entity recognition and relationship classification. At present, the joint extraction method has achieved higher performance and has received more attention. PFN (A Partition Filter Network for Joint Entity and Relation Extraction, 2021) proposes a partitioned filtering network to correctly model the two-way interaction between tasks, and uses the joint extraction mode to deeply interact the two subtasks of named entity recognition (NER) and relation extraction (RE), so that the two tasks promote each other and achieve excellent extraction performance.
[0003] Recently, some studies have tried to use large language models such as ChatGPT and ChatGLM in relation extraction tasks. They regard the relation extraction problem as a sequence-to-sequence task and linearize the relationship between entities into a target string generated according to the input. Some studies first use ChatGPT to generate thought chains, and then use the generated thought chains and data to fine-tune the Flan-T5Large model through instructions, which has achieved good results on the dataset. However, this method uses a manual evaluation strategy and ignores the problem that the instruction fine-tuning method may produce prediction results that are slightly different from the label.
[0004] Existing work has found that instruction fine-tuning methods may not perform well in sequence labeling tasks, which, unlike text generation tasks, have limited label space. LS-unLLaMA (LABEL SUPERVISED LLAMA FINETUNING, 2023) uses the LLaMA large model for sequence labeling tasks, which removes the causal mask from the decoder and restores LLaMA's unidirectional attention to bidirectional attention, achieving state-of-the-art performance in named entity recognition (NER). Large models such as LLaMA and LS-unLLaMA are suitable for English text, while the Atom-7B large model is an open source large model obtained by pre-training on large-scale Chinese data based on LLaMA2-7B, and has better language understanding and generation capabilities for Chinese text. Summary of the invention
[0005] In order to overcome the shortcomings of the prior art, the present invention provides a method and system for joint extraction of entity relationships of Chinese text in the field of carbon neutrality. Firstly, for samples with unbalanced annotations, the ChatGLM3 interface is used to perform data enhancement on text sentences corresponding to relationships with a small number of samples, and a sample set with the same relationship triples as the original samples is generated; then, noise is added to the Embedding layer of the Atom-7B large model to alleviate the overfitting phenomenon of the Atom-7B large model, and the feature extraction ability of Chinese text sentences is improved through hierarchical demasking; finally, in view of the different levels of difficulty of named entity recognition tasks and relationship extraction tasks, a dynamic loss function is added to make the PFN module focus more on more difficult tasks during the training process.
[0006] The technical solution adopted by the present invention to solve its technical problem is:
[0007] A method for joint extraction of entity relations of Chinese text in the field of carbon neutrality includes the following steps:
[0008] Step 1: Collection of carbon neutrality Chinese text data: Obtain carbon emission data of China and other countries in the world from the China Carbon Accounting Database, Global Real-time Carbon Data, and World Bank Database Website, collect carbon emission evaluation requirements and guidelines of various provinces and cities, crawl carbon neutrality policy standards, notices and related information on the Carbon Neutrality Information Network using web crawlers, obtain unstructured carbon neutrality Chinese text with entity relationships to be extracted from the specified paragraph, and a given ontology constraint set, which includes relationship name, head entity type, and tail entity type, and divide the labeled carbon neutrality Chinese text data into training set D according to a preset ratio. 1 and validation set D 2 , the carbon neutrality Chinese text data includes the subject, object, relationship and category label contained in each sample;
[0009] Step 2: Use ChatGLM3 to train the training set D 1 Perform data enhancement: statistical training set D 1 The number of times each relationship appears in all triples in the text is calculated to determine whether the relationship type has a long-tail distribution. For the training data with unbalanced relationship types, the ChatGLM3 interface is used to perform data enhancement on the relationship types with small sample sizes, and a sample set with the same relationship triples in the original text is generated and added to D 1 middle;
[0010] Step 3: Use the expanded D 1 Training entity relationship joint extraction model: D 1The Chinese text sentences are input into the Embedding layer, and noise is added after the embedding vector is obtained. The hierarchical demasked Atom-7B large model and PFN model are input in turn. The entity and relationship prediction values corresponding to the text sentences are output, and the dynamic loss function is calculated by automatically adjusting the loss weights of named entity recognition and relationship extraction. The parameters of the entity-relationship joint extraction model are jointly optimized according to the loss gradient, and the validation set D is saved. 2 Extract the model parameters with the best performance;
[0011] Step 4: Input the unlabeled carbon neutral Chinese text sentences into the trained Atom-7B large model, obtain the feature representation vector of the text sentence, and then pass the feature representation vector into the PFN module to output the entity relationship triple.
[0012] Further, in step 2, D 1 The relationship type with a small number of samples is selected, and the samples s containing this relationship type are selected. 0 , call the ChatGLM3 large model interface, generate a sample set with the same relationship triples as the original sample through dialogue, and add D 1 The process is as follows:
[0013] 2.1 Input "Please translate from Chinese to English, keeping the word # unchanged: %" to the ChatGLM3 large model interface, where # represents the triple list of relations in the text, and % represents the text sentence to be expanded. 0 ;
[0014] 2.2 ChatGLM3 large model interface outputs the sentence s′ translated into English 0 ;
[0015] 2.3 Input “Please translate the sentence into Chinese: $” into the ChatGLM3 large model interface, where $ represents s′ 0 ;
[0016] 2.4 ChatGLM3 large model interface outputs the sentence translated into Chinese, that is, the expanded text sentence s 1 ;
[0017] 2.5 Repeat 2.2-2.4 and add the expanded text sentence set {s 1 ,…,s m} and its relation triplet labels are added as sample sets to D 1 middle.
[0018] The process of step three is as follows:
[0019] 3.1 Add uniformly distributed noise to the Embedding layer of the Atom-7B large model: Input text sentence s j , through Tokenizer Atom Convert it into a token sequence vector t, randomly generate a noise vector ∈, scale it to the set strength, and add it to the embedding vector t to get the noisy embedding vector x:
[0020] x=Embedding Atom (t)+α∈
[0021] t=Tokenizer Atom (s j )
[0022] ∈~Uniform(-1,1)
[0023] where s j Yes D 1 The text sentence corresponding to the jth sample in Embedding Atom is the Embedding layer of the Atom-7B large model, ∈ is the noise that follows the uniform distribution, and α is the scaling factor of the noise;
[0024] 3.2 Input x into the decoder layer of the Atom-7B large model based on layered demasking, and output the text sentence s i The representation vector h of all tokens: The decoder layer of the Atom-7B large model is layered and recorded as W 0 is the frozen pre-trained decoder layer parameters, ΔW is the decoder layer parameters fine-tuned using LoRA technology, and the 1st to lth layers, i.e., Atom 1:l Without masking, layers l+1 to n, namely BiAtom l+1:n Remove the mask and get the feature representation vector h of all tokens:
[0025]
[0026]
[0027]
[0028]
[0029]
[0030] Q = xW q
[0031] K=xWk
[0032] V=xW v
[0033] ΔW=W down W up
[0034] in is the i-th head of the multi-head self-attention in layers 1 to l, is the i-th head of the multi-head self-attention in the l+1 to n-th layers, M is the causal mask of the Atom-7B large model, -∞ means that the current token is invisible to all subsequent tokens, that is, only one-way attention is calculated, M′ is the mask after removing -∞, that is, bidirectional self-attention is calculated, Q, K and V are Query, Key and Value in the multi-head self-attention mechanism, SoftMax is the activation function, d k is the dimension size of K, W q , W k , W v are three trainable parameter matrices, W down is the dimension reduction matrix of LoRA fine-tuning, W up It is the dimension-increasing matrix of LoRA fine-tuning. The parameters fine-tuned by LoRA technology include the three modules of q_proj, k_proj, and v_proj of the decoder layer. The update of the parameters of q_proj, k_proj, and v_proj modules will affect W q , W k , W v These three parameter matrices;
[0035] 3.3 Input the representation vectors h of all tokens into the PFN model to obtain the predicted values of entities and relations respectively and in represents the probability that the token pair starting with the i-th token and ending with the j-th token belongs to an entity of type k, Indicates the probability that the i-th token and the j-th token belong to the subject entity and the object entity starting word of the relation type l, and calculates the dynamic loss function, that is, at the beginning of training, the losses of named entity recognition and relation extraction are added as the total loss. During the training process, the loss weights of named entity recognition and relation extraction are automatically adjusted, giving a larger weight to the subtask with a larger loss, so that the model can focus more on more difficult tasks during training:
[0036]
[0037]
[0038]
[0039]
[0040] Among them, θ is the parameter of the PFN model, and are the labels of entities and relations, S and T are the sets of all entity labels and relation labels, respectively. ner and L re are the losses of the named entity recognition subtask and the relation extraction subtask, respectively. BCELoss is the binary cross entropy loss. σ represents the sigmoid activation function. exp represents the exponential operation. λ is the threshold.
[0041] 3.4 Jointly optimize the parameters of the entity relationship joint extraction model: According to the gradient value of the loss function, use LoRA technology to fine-tune some parameters ΔW of the Atom-7B large language model, and perform full parameter fine-tuning on the parameters θ of the PFN model;
[0042] 3.5 Repeat steps 3.1-3.4 until the maximum number of iterations is reached, and save the validation set D 2 Upper F 1 Parameters of the highest scoring joint entity relation extraction model.
[0043] A system for joint extraction of entity relations of Chinese texts in the field of carbon neutrality, the system comprising:
[0044] The carbon neutrality data collection module is used to obtain carbon emission and carbon neutrality related data, obtain the unstructured carbon neutrality Chinese text with entity relationships to be extracted from the specified paragraph, and the given ontology constraint set, which includes the relationship name, head entity type and tail entity type. The labeled carbon neutrality Chinese text data is divided into training set D according to the preset ratio. 1 and validation set D 2 ,Chinese text data includes the subject, object, relation and category labels contained in the current sample;
[0045] The training set data enhancement module is used to enhance the training set D 1 Perform preprocessing and statistical training set D 1 The number of times each relationship appears in all relationship triples in the , determines whether the relationship type has a long-tail distribution. For relationship types with unbalanced annotations, the ChatGLM3 interface is used to perform data enhancement on relationship types with small sample sizes. The generated text has the same relationship triples as the original text.
[0046] Joint extraction model training module, in the Atom-7B large model, the training set D 1The text sentence is sequentially passed through the embedding layer containing noise addition and the decoder layer of hierarchical demasking to obtain its feature representation vector. In PFN, the feature representation vector of the text sentence is input to obtain the corresponding entity and relationship prediction probability. The loss weights of named entity recognition and relationship extraction are automatically adjusted through the dynamic loss function. In the joint optimization, the LoRA technology is used to fine-tune some parameters of the Atom-7B large language model, and the full parameters of the PFN model are fine-tuned, and the validation set D is saved. 2 Extract the model parameters with the best performance;
[0047] The entity relationship triplet output module is used to input the unlabeled carbon-neutral Chinese text into the trained entity relationship joint extraction model, obtain the feature representation vector of the text sentence through the Atom-7B large model, and then output the entity relationship triplet through PFN.
[0048] The technical concept of the present invention is as follows: in the training set data preprocessing step, the number of occurrences of various relationship types is counted, and for samples with unbalanced relationship types in carbon neutral text data, the ChatGLM3 large model interface is used to expand the samples; in the entity relationship extraction model training stage, for the Atom-7B large model suitable for Chinese, by adding noise to the Embedding layer and using a hierarchical demasking decoder layer, the feature extraction capability of the Atom-7B large model for Chinese text sentences is better stimulated, a dynamic loss function is added to the PFN module, and the loss weights of the named entity recognition subtask and the relationship extraction subtask are automatically adjusted during the training process, so that the PFN model can focus on more difficult subtasks.
[0049] The beneficial effects of the present invention are as follows: data enhancement is performed using the ChatGLM3 interface, which alleviates the problem of data imbalance in the training set of Chinese text in the field of carbon neutrality. The feature representation vector of the sentence is obtained using the Atom-7B open source large model suitable for Chinese. By adding noise to the Embedding layer and adopting a hierarchical demasking strategy at the decoder layer, the feature representation ability of the Atom-7B large model to extract Chinese text sentences is better stimulated. In view of the different levels of difficulty of named entity recognition tasks and relationship extraction tasks, a dynamic loss function is added to enable the PFN model to focus on more difficult subtasks. BRIEF DESCRIPTION OF THE DRAWINGS
[0050] Figure 1 A block diagram of the method of the present invention.
[0051] Figure 2 This is a data enhancement block diagram of the present invention. DETAILED DESCRIPTION
[0052] The present invention will be further described below in conjunction with the accompanying drawings.
[0053] Reference Figure 1 and Figure 2 , a method for joint extraction of entity relations of Chinese text in the field of carbon neutrality, comprising the following steps:
[0054] Step 1: Collection of Chinese text data in the field of carbon neutrality: Obtain carbon emission data of China and other countries in the world from the China Carbon Accounting Database, Global Real-time Carbon Data, and the World Bank Database website, collect carbon emission evaluation requirements and guidelines for various provinces and cities, and crawl carbon neutrality policy standards, notices and related information on the Carbon Neutrality Information Network using web crawlers. Obtain unstructured carbon neutrality Chinese text with entity relationships to be extracted from the specified paragraph, as well as a given ontology constraint set, which includes relationship name, head entity type, and tail entity type. Divide the labeled carbon neutrality Chinese text data into training set D according to a preset ratio. 1 and validation set D 2 , the carbon neutrality Chinese text data includes the subject, object, relationship and category label contained in each sample;
[0055] Step 2: Use ChatGLM3 to train the training set D 1 Perform data enhancement: statistical training set D 1 The number of times each relationship appears in all triples in the text is calculated to determine whether the relationship type has a long-tail distribution. For the training data with unbalanced relationship types, the ChatGLM3 interface is used to perform data enhancement on the relationship types with small sample sizes, and a sample set with the same relationship triples in the original text is generated and added to D 1 middle;
[0056] In the step 2, D 1 The relationship type with a small number of samples is selected, and the samples s containing this relationship type are selected. 0 , call the ChatGLM3 large model interface, generate a sample set with the same relationship triples as the original sample through dialogue, and add D 1 The process is as follows:
[0057] 2.1 Input "Please translate from Chinese to English, keeping the word # unchanged: %" to the ChatGLM3 large model interface, where # represents the triple list of relations in the text, and % represents the text sentence to be expanded. 0 ;
[0058] 2.2 ChatGLM3 large model interface outputs the sentence s′ translated into English 0 ;
[0059] 2.3 Input “Please translate the sentence into Chinese: $” into the ChatGLM3 large model interface, where $ represents s′ 0 ;
[0060] 2.4 ChatGLM3 large model interface outputs the sentence translated into Chinese, that is, the expanded text sentence s 1 ;
[0061] 2.5 Repeat 2.2-2.4 and add the expanded text sentence set {s 1 ,…,s m} and its relation triplet labels are added as sample sets to D 1 middle.
[0062] Step 3: Use the expanded D 1 Training entity relationship joint extraction model: D 1 The Chinese text sentences are input into the Embedding layer, and noise is added after the embedding vector is obtained. The hierarchical demasked Atom-7B large model and PFN model are input in turn. The entity and relationship prediction values corresponding to the text sentences are output, and the dynamic loss function is calculated by automatically adjusting the loss weights of named entity recognition and relationship extraction. The parameters of the entity-relationship joint extraction model are jointly optimized according to the loss gradient, and the validation set D is saved. 2 Extract the model parameters with the best performance;
[0063] The process of step three is as follows:
[0064] 3.1 Add uniformly distributed noise to the Embedding layer of the Atom-7B large model: Input text sentence s j , through Tokenizer Atom Convert it into a token sequence vector t, randomly generate a noise vector ∈, scale it to the set strength, and add it to the embedding vector t to get the noisy embedding vector x:
[0065] x=Embedding Atom (t)+α∈
[0066] t=Tokenizer Atom (s j )
[0067] ∈~Uniform(-1,1)
[0068] where s j Yes D 1 The text sentence corresponding to the jth sample in Embedding Atom is the Embedding layer of the Atom-7B large model, ∈ is the noise that follows the uniform distribution, and α is the scaling factor of the noise;
[0069] 3.2 Input x into the decoder layer of the Atom-7B large model based on layered demasking, and output the text sentence s i The representation vector h of all tokens: The decoder layer of the Atom-7B large model is layered and recorded as W 0 is the frozen pre-trained decoder layer parameters, ΔW is the decoder layer parameters fine-tuned using LoRA technology, and the 1st to lth layers, i.e., Atom 1:l Without masking, layers l+1 to n, namely BiAtom l+1:n , remove the mask, the total number of layers n = 32, and the feature representation vector h of all tokens is obtained as
[0070]
[0071]
[0072]
[0073]
[0074]
[0075] Q = xW q
[0076] K=xW k
[0077] V=xW v
[0078] ΔW=W down W up
[0079] in is the i-th head of the multi-head self-attention in layers 1 to l, is the i-th head of the multi-head self-attention in the l+1 to n-th layers, M is the causal mask of the Atom-7B large model, -∞ means that the current token is invisible to all subsequent tokens, that is, only one-way attention is calculated, M′ is the mask after removing -∞, that is, bidirectional self-attention is calculated, Q, K and V are Query, Key and Value in the multi-head self-attention mechanism, SoftMax is the activation function, d k is the dimension size of K, W q , W k , W v are three trainable parameter matrices, W down is the dimension reduction matrix of LoRA fine-tuning, Wup It is the dimension-increasing matrix of LoRA fine-tuning. The parameters fine-tuned by LoRA technology include the three modules of q_proj, k_proj, and v_proj of the decoder layer. The update of the parameters of q_proj, k_proj, and v_proj modules will affect W q , W k , W v These three parameter matrices;
[0080] 3.3 Input the representation vectors h of all tokens into the PFN model to obtain the predicted values of entities and relations respectively and in represents the probability that the token pair starting with the i-th token and ending with the j-th token belongs to an entity of type k, Indicates the probability that the i-th token and the j-th token belong to the subject entity and the object entity starting word of the relation type l, and calculates the dynamic loss function, that is, at the beginning of training, the losses of named entity recognition and relation extraction are added as the total loss. During the training process, the loss weights of named entity recognition and relation extraction are automatically adjusted, giving a larger weight to the subtask with a larger loss, so that the model can focus more on more difficult tasks during training:
[0081]
[0082]
[0083]
[0084]
[0085] Among them, θ is the parameter of the PFN model, and are the labels of entities and relations, S and T are the sets of all entity labels and relation labels, respectively. ner and L re are the losses of the named entity recognition subtask and the relation extraction subtask, respectively. BCELoss is the binary cross entropy loss. σ represents the sigmoid activation function. exp represents the exponential operation. The threshold λ = 100.
[0086] 3.4 Jointly optimize the parameters of the entity relationship joint extraction model: According to the gradient value of the loss function, use LoRA technology to fine-tune some parameters ΔW of the Atom-7B large language model, and perform full parameter fine-tuning on the parameters θ of the PFN model;
[0087] 3.5 Repeat steps 3.1-3.4 until the maximum number of iterations is reached, and save the validation set D2 Upper F 1 Parameters of the highest scoring joint entity relation extraction model.
[0088] Step 4: Input the unlabeled Chinese text sentences in the field of carbon neutrality into the trained Atom-7B large model, obtain the feature representation vector of the text sentence, then pass the feature representation vector into the PFN module and output the entity relationship triple.
[0089] This embodiment also provides a method and system for joint extraction of entity relationships in Chinese text in the field of carbon neutrality, including: a carbon neutrality data collection module, a training set data enhancement module, a joint extraction model training module (including an Atom-7B unit, a PFN unit, and a joint optimization unit) and an entity relationship triple output module. The above modules correspond to the contents of steps 1 to 4 of the method of the present invention, namely:
[0090] The system comprises:
[0091] The carbon neutrality data collection module is used to obtain carbon emission and carbon neutrality related data, obtain the unstructured carbon neutrality Chinese text with entity relationships to be extracted from the specified paragraph, and the given ontology constraint set, which includes the relationship name, head entity type and tail entity type, and divide the annotated carbon neutrality Chinese text data into training set D according to the preset ratio. 1 and validation set D 2 ,Chinese text data includes the subject, object, relation and category labels contained in the current sample;
[0092] The training set data enhancement module is used to enhance the training set D 1 Perform preprocessing and statistical training set D 1 The number of times each relationship appears in all relationship triples in the , determines whether the relationship type has a long-tail distribution. For relationship types with unbalanced annotations, the ChatGLM3 interface is used to perform data enhancement on relationship types with small sample sizes. The generated text has the same relationship triples as the original text.
[0093] Joint extraction model training module, in the Atom-7B large model, the training set D 1 The text sentence is sequentially passed through the embedding layer containing noise addition and the decoder layer of hierarchical demasking to obtain its feature representation vector. In PFN, the feature representation vector of the text sentence is input to obtain the corresponding entity and relationship prediction probability. The loss weights of named entity recognition and relationship extraction are automatically adjusted through the dynamic loss function. In the joint optimization, the LoRA technology is used to fine-tune some parameters of the Atom-7B large language model, and the full parameters of the PFN model are fine-tuned, and the validation set D is saved. 2 Extract the model parameters with the best performance;
[0094] The entity relationship triplet output module inputs the unlabeled Chinese text in the carbon neutrality field into the trained entity relationship joint extraction model, obtains the feature representation vector of the text sentence through the Atom-7B large model, and then outputs the entity relationship triplet through PFN.
[0095] As described above, the specific implementation steps of this patent implementation make the present invention clearer. Within the spirit of the present invention and the protection scope of the claims, any modifications and changes made to the present invention fall within the protection scope of the present invention.
Claims
1. A method for joint extraction of entity relations in Chinese text in the field of carbon neutrality, characterized in that: The method comprises the following steps: Step 1, collection of carbon neutrality Chinese text data: obtain carbon emission data of China and other countries in the world from the China Carbon Accounting Database, Global Real-time Carbon Data, and the World Bank Database website, collect carbon emission evaluation requirement guidelines for various provinces and cities, and crawl carbon neutrality policy standards, notices and related information on the Carbon Neutrality Information Network using web crawlers. Obtain the unstructured carbon neutrality Chinese text with entity relationships to be extracted from the specified paragraph, as well as a given ontology constraint set, the ontology constraint set includes relationship name, head entity type, and tail entity type. Divide the labeled carbon neutrality Chinese text data into a training set D1 and a verification set D2 according to a preset ratio. The carbon neutrality Chinese text data includes the subject, object, relationship, and category labels contained in each sample; Step 2: Use ChatGLM3 to perform data enhancement on the training set D1: Count the number of occurrences of various relations in all triples in the training set D1, determine whether the relation type has a long-tail distribution, and use the ChatGLM3 interface to perform data enhancement on relation types with small sample sizes for training data with unbalanced relation types, and generate a sample set with the same relation triples in the original text and add it to D1; Step 3: Use the expanded D1 to train the entity-relationship joint extraction model: Input the Chinese text sentences of D1 into the Embedding layer, add noise after obtaining the embedding vector, input the hierarchical demasked Atom-7B large model and PFN model in turn, output the entity and relationship prediction values corresponding to the text sentences, and calculate the dynamic loss function by automatically adjusting the loss weights of named entity recognition and relationship extraction. According to the loss gradient, jointly optimize the parameters of the entity-relationship joint extraction model, and save the model parameters with the best extraction performance on the validation set D2; Step 4: Input the unlabeled carbon neutral Chinese text sentences into the trained Atom-7B large model, obtain the feature representation vector of the text sentence, and then pass the feature representation vector into the PFN module to output the entity relationship triple.
2. The entity relationship joint extraction method of Chinese text in the field of carbon neutrality as claimed in claim 1 is characterized in that: In step 2, for the relationship type with a small number of samples in D1, select the sample s0 containing the relationship type, call the ChatGLM3 large model interface, generate a sample set with the same relationship triples as the original sample in the form of dialogue, and add it to D1. The process is as follows: 2.1 Input "Please translate from Chinese to English, keeping the word#unchanged:%" into the ChatGLM3 large model interface, where # represents the triplet triple_list in the text, and % represents the text sentence s0 to be expanded; 2.2 ChatGLM3 large model interface outputs the sentence s′0 translated into English; 2.3 Input "Please translate the sentence into Chinese: $" into the ChatGLM3 large model interface, where $ represents s′0; 2.4 The ChatGLM3 large model interface outputs the sentence translated into Chinese, i.e. the expanded text sentence s1; 2.5 Repeat 2.2-2.4 and add the expanded text sentence set {s1,…,s m } and its relation triplet labels are added to D1 as sample sets.
3. The entity relationship joint extraction method of Chinese text in the field of carbon neutrality as described in claim 1 or 2 is characterized in that: The process of step three is as follows: 3.1 Add uniformly distributed noise to the Embedding layer of the Atom-7B large model: Input text sentence s j , through Tokenizer Atom Convert it into a token sequence vector t, randomly generate a noise vector ∈, scale it to the set strength, and add it to the embedding vector t to get the noisy embedding vector x: x=Embedding Atom (t)+α∈ t=Tokenizer Atom (s j ) ∈~Uniform(-1,1) where s j is the text sentence corresponding to the jth sample in D1, Embedding Atom is the Embedding layer of the Atom-7B large model, ∈ is the noise that follows the uniform distribution, and α is the scaling factor of the noise; 3.2 Input x into the decoder layer of the Atom-7B large model based on layered demasking, and output the text sentence s i The representation vector h of all tokens: The decoder layer of the Atom-7B large model is layered and recorded as W0 is the frozen pre-trained decoder layer parameter, ΔW is the decoder layer parameter fine-tuned using LoRA technology, and the 1st to lth layers, i.e., Atom 1:l Without masking, layers l+1 to n, namely BiAtom l+1:n Remove the mask and get the feature representation vector h of all tokens: Q=xW q K=xW k V=xW v ΔW=W down IN up in is the i-th head of the multi-head self-attention in layers 1 to l, is the i-th head of the multi-head self-attention in the l+1 to n layers, M is the mask of the Atom-7B large model, -∞ means that the current token is invisible to all subsequent tokens, that is, only one-way attention is calculated, M′ is the mask after removing -∞, that is, bidirectional self-attention is calculated, Q, K and V are Query, Key and Value in the multi-head self-attention mechanism, SoftMax is the activation function, d k is the dimension size of K, W q , W k , W v are three trainable parameter matrices, W down is the dimension reduction matrix of LoRA fine-tuning, W up It is the dimension-increasing matrix of LoRA fine-tuning. The parameters fine-tuned by LoRA technology include the three modules of q_proj, k_proj, and v_proj of the decoder layer. The update of the parameters of q_proj, k_proj, and v_proj modules will affect W q , W k , W v These three parameter matrices; 3.3 Input the representation vectors h of all tokens into the PFN model to obtain the predicted values of entities and relations respectively and in represents the probability that the token pair starting with the i-th token and ending with the j-th token belongs to an entity of type k, Indicates the probability that the i-th token and the j-th token belong to the subject entity and the object entity starting word of the relation type l, and calculates the dynamic loss function, that is, at the beginning of training, the losses of named entity recognition and relation extraction are added as the total loss. During the training process, the loss weights of named entity recognition and relation extraction are automatically adjusted, giving a larger weight to the subtask with a larger loss, so that the model can focus more on more difficult tasks during training: Among them, θ is the parameter of the PFN model, and are the labels of entities and relations, S and T are the sets of all entity labels and relation labels, respectively. ner and L re are the losses of the named entity recognition subtask and the relation extraction subtask, respectively. BCELoss is the binary cross entropy loss. σ represents the sigmoid activation function. exp represents the exponential operation. λ is the threshold. 3.4 Jointly optimize the parameters of the entity relationship joint extraction model: According to the gradient value of the loss function, use LoRA technology to fine-tune some parameters ΔW of the Atom-7B large language model, and perform full parameter fine-tuning on the parameters θ of the PFN model; 3.5 Repeat steps 3.1-3.4 until the maximum number of iterations is reached, and save the parameters of the entity relationship joint extraction model with the highest F1 score on the validation set D2.
4. A system for realizing entity relationship joint extraction of Chinese text in the field of carbon neutrality as claimed in claim 1, characterized in that: The system comprises: A carbon neutrality data collection module is used to obtain carbon emission and carbon neutrality data, obtain the unstructured carbon neutrality Chinese text with entity relationships to be extracted from the specified paragraph, and a given ontology constraint set, wherein the ontology constraint set includes the relationship name, the head entity type, and the tail entity type, and divide the annotated carbon neutrality Chinese text data into a training set D1 and a verification set D2 according to a preset ratio, wherein the Chinese text data includes the subject, object, relationship, and category label contained in the current sample; The training set data enhancement module is used to preprocess the training set D1, count the number of occurrences of various relations in all relation triplets in the training set D1, determine whether the relation type has a long-tail distribution, and use the ChatGLM3 interface to perform data enhancement on relation types with small sample sizes for relation types with unbalanced annotations. The generated text has the same relation triplets as the original text. Joint extraction model training module: In the Atom-7B large model, the text sentences of the training set D1 are sequentially passed through the embedding layer containing noise addition and the decoder layer of hierarchical demasking to obtain their feature representation vectors. In PFN, the feature representation vectors of the text sentences are input to obtain the corresponding entity and relationship prediction probabilities. The loss weights of named entity recognition and relationship extraction are automatically adjusted through the dynamic loss function. In the joint optimization, the LoRA technology is used to fine-tune some parameters of the Atom-7B large language model, and the PFN model is fine-tuned for all parameters, and the model parameters with the best extraction performance on the validation set D2 are saved; The entity relationship triplet output module is used to input the unlabeled carbon-neutral Chinese text into the trained entity relationship joint extraction model, obtain the feature representation vector of the text sentence through the Atom-7B large model, and then output the entity relationship triplet through PFN.
Citation Information
Patent Citations
Document-level relation extraction method based on long-tail data distribution
CN114861645A
Natural language understanding algorithm based on semantic matching and knowledge graph
CN117350378A
Document-specific gazetteers for named entity recognition
EP3136257A2
Reporting random access information for events or operations in shared channels
WO2024030060A1
Cited By
Named entity recognition method for man-machine conversation system
CN119808786A
A named entity recognition method for human-computer dialogue system
CN119808786B
Entity relationship joint extraction method and system for Chinese text in carbon finance field
CN120654694A
