Text information extraction method and system based on large language model
By combining generative and discriminative models, discriminative components and dynamic generation probability calculation module are introduced, the hallucination problems and data noise sensitivity in generative information extraction are solved, the stability of the model and the accuracy of the extraction results are improved, and it is suitable for knowledge graph construction and public opinion analysis.
Patent Information
- Application Number
- CN202510411787.9
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2025-04-02
- Publication Date
- 2025-08-01
AI Technical Summary
In the prior art, generative information extraction is prone to hallucination problems, high engineering dependence and strong data noise sensitivity, resulting in insufficient model stability and difficulty in extracting high-quality entities and relationships from unstructured text.
Combining the generative and discriminative models, a discriminative component and a dynamic generation probability calculation module are introduced, and the dialogue strategy gradient discrete prompt optimization framework and noise channel matrix are trained to optimize the balance between generation and replication, and improve the model stability and accuracy of the extraction results.
Effectively reduce hallucinations, improve the stability of the model and the accuracy of the extraction results, and more stably extract high-quality entities and relationships from unstructured texts, and are widely used in fields such as knowledge graph construction and public opinion analysis.
Smart Images

Figure CN120407802A_ABST
Abstract
Description
Technical Field
[0001] The present invention belongs to the technical field of natural language processing, and particularly relates to a method and system for text information extraction based on a large language model. Background Art
[0002] Text Information Extraction aims to identify structured information such as entities and relationships from unstructured text, and is a core technology in fields such as public opinion analysis and knowledge graph construction. Traditional methods rely on rule templates or discriminant models (such as BiLSTM-CRF). With the rise of large language models (LLMs) represented by ChatGPT, generative information extraction has gradually become the mainstream. However, this method still has the following key problems:
[0003] 1. The problem of generative hallucinations. Generative information extraction relies on large language models to directly generate entities and relationships, which is essentially a probability-driven text generation process, and is prone to the "hallucination" phenomenon that does not conform to the original text semantics (such as fabricating entities not mentioned or wrongly associating relationships), resulting in unreliable extraction results.
[0004] 2. High dependence on prompt engineering. The generative method highly depends on manually designed prompts (Prompts), and different prompt templates will lead to significant differences in output results. The existing technology lacks a prompt optimization mechanism for dynamically adapting to inputs, resulting in insufficient model stability.
[0005] 3. Strong sensitivity to data noise. The performance of large language models is significantly affected by the quality of training data, and data noise generally exists in practical applications: spelling mistakes, network neologisms, and residual cleaning noise in social media text, as well as annotation noise caused by missing or mislabeling in manual annotation. The above-mentioned noise will mislead model training and reduce the robustness of extraction results.
[0006] On the one hand, regarding the hallucination problem, existing research mostly filters the generated results through post-processing rules, but it is difficult to cover complex semantic scenarios; on the other hand, prompt engineering depends on empirical design and lacks an automated optimization framework; in addition, data denoising methods (such as rule cleaning and crowdsourcing verification) are costly and have limited generalization ability.
[0007] Therefore, it is necessary to design a method and system for text information extraction based on a large language model that combines the advantages of generative and discriminant methods, and combines dynamic prompt optimization and data augmentation techniques to address the above problems. Summary of the Invention
[0008] The object of the present invention is to address the problems of hallucination in generative information extraction in the prior art and insufficient stability caused by high dependence on prompt engineering and data quality. A method and system for text information extraction based on a large language model are provided. By introducing a discriminant component, the stability of the model and the accuracy of the extraction results are effectively improved. By designing a dynamic generation probability calculation module and an extended vocabulary mechanism, the balance between generation and copying is optimized, enabling the text information extraction model to more stably extract high-quality entities and relationships from unstructured text, and it can be widely applied in fields such as knowledge graph construction and public opinion analysis, effectively improving the efficiency and accuracy of information extraction.
[0009] According to one aspect of this specification, a method for text information extraction based on a large language model is provided, including:
[0010] Obtain text information data;
[0011] Input the obtained text information data into a trained text information extraction model for text information processing; wherein, the training of the text information extraction model includes:
[0012] Construct a generative and discriminative text information extraction model based on a large language model, introduce a discriminant component in the decoder layer, and achieve the balance between generation and copying by analyzing the output of the hidden layer of the decoder using a dynamic generation probability calculation module;
[0013] Construct a conversational policy gradient discrete prompt optimization framework for prompt stability enhancement training;
[0014] Construct a noise channel matrix for data augmentation training and stability enhancement training.
[0015] Furthermore, constructing a conversational policy gradient discrete prompt optimization framework for prompt stability enhancement training includes:
[0016] In the prompt set construction stage based on multi-round dialogue alignment, use a dialogue model to generate a basic prompt set aligned with the training data distribution;
[0017] In the prompt matching stage based on reinforcement learning, dynamically select a prompt template adapted to the current input through a policy network.
[0018] Furthermore, the prompt set construction stage includes:
[0019] Randomly select k samples from the training set as the initial seed set;
[0020] Execute multi-round dialogues through a dialogue model to form a candidate set containing all optimized prompts.
[0021] Furthermore, the construction of the noise channel matrix includes:
[0022] Build a character-level noise probability distribution model to simulate three types of noise interference processes: insertion operation, deletion operation, and substitution operation;
[0023] Generate an extended input by inserting placeholders before and after the original input sequence, randomly sample according to the noise probability distribution to generate a perturbed text, and finally remove the placeholders to obtain a noisy sample.
[0024] Furthermore, the loss function of the text information extraction model combines the characteristics of generative and discriminative models and is defined as:
[0025]
[0026] where T is time, and the loss of state is the negative log-likelihood of the target word at this state .
[0027] Furthermore, the stability-enhanced training introduces a KL divergence similarity constraint, including:
[0028]
[0029]
[0030] where is the target of a standard sequence labeling problem, where x is the input text and y is the corresponding true label sequence, are the parameters of F(x), is the loss function, is the stability-enhanced loss, is the text after introducing noise, α is the weight of the noise loss component, and represent the logits probability distributions of the original sample and the noisy sample respectively.
[0031] According to one aspect of the present specification, a text information extraction system based on a large language model is provided, including:
[0032] A data acquisition module for acquiring text information data;
[0033] A text information extraction module for inputting the acquired text information data into a trained text information extraction model for text information processing; wherein, the training of the text information extraction model includes:
[0034] Construct a generative and discriminative text information extraction model based on a large language model, introduce a discriminative component in the decoder layer, and achieve a balance between generation and copying by analyzing the hidden layer output of the decoder using a dynamic generation probability calculation module;
[0035] Construct a dialogue-style policy gradient discrete prompt optimization framework for enhanced training of prompt stability;
[0036] Construct a noise channel matrix for data augmentation training and enhanced stability training.
[0037] According to one aspect of this specification, there is provided an electronic device including a memory and a processor, the memory storing a computer program, characterized in that when the processor executes the computer program, the steps of the text information extraction method based on a large language model are implemented.
[0038] According to one aspect of this specification, there is provided a computer-readable storage medium having a computer program stored thereon, characterized in that when the computer program is executed by a processor, the steps of the text information extraction method based on a large language model are implemented.
[0039] Compared with the prior art, the beneficial effects of the present invention are:
[0040] 1. Through a hybrid model that combines generative and discriminative methods, the present invention breaks through the limitation of insufficient accuracy caused by hallucination problems in traditional generative information extraction methods, and effectively improves the stability of the model and the accuracy of extraction results by introducing a discriminative component;
[0041] 2. By designing a dynamic generation probability calculation module and an extended vocabulary mechanism, the present invention optimizes the balance between generation and copying, solves the problems in the prior art that generative information extraction depends on prompt engineering and is vulnerable to data noise, enables the text information extraction model to more stably extract high-quality entities and relationships from unstructured text, and can be widely applied to fields such as knowledge graph construction and public opinion analysis, effectively improving the efficiency and accuracy of information extraction. BRIEF DESCRIPTION OF THE DRAWINGS
[0042] In order to more clearly illustrate the technical solutions in the embodiments of the present invention or the prior art, the following will briefly introduce the drawings required for use in the description of the embodiments or the prior art. Obviously, the following drawings are only some embodiments of the present invention, and those of ordinary skill in the art can obtain other drawings without creative efforts based on these drawings.
[0043] Figure 1 It is a flowchart of the method for the embodiment of the present invention. DETAILED DESCRIPTION OF THE EMBODIMENTS
[0044] It should be noted that: without conflict, the embodiments in the present invention and the features in the embodiments can be combined with each other.
[0045] Next, the technical solutions in the embodiments of the present invention will be clearly and completely described in conjunction with the accompanying drawings in the embodiments of the present invention. Obviously, the described embodiments are only a part of the embodiments of the present invention, rather than all the embodiments. All other embodiments obtained by those of ordinary skill in the art based on the embodiments of the present invention without creative efforts shall fall within the protection scope of the present invention.
[0046] As Figure 1 shown, an embodiment of the present invention provides a method for extracting text information based on a large language model, including: Step 1, by introducing a discriminant component into the decoder layer of the model, combining the flexibility of the generative model and the accuracy of the discriminative model, designing a dynamic generation probability calculation module and an extended vocabulary mechanism, effectively reducing the hallucination problem in generative information extraction, and improving the stability and accuracy of the extraction results; Step 2, performing stability enhancement training on the prompts of the large language model, and dynamically optimizing the prompt template through a conversational policy gradient framework; Step 3, performing stability enhancement training on the training data, constructing a noise channel matrix to simulate the real text noise process, and obtaining adversarial samples.
[0047] Specifically, in Step 1, the generative and discriminative methods are combined, and an extraction module is added on the basis of the existing large language model to alleviate the hallucination problem of the large language model. By introducing the generation probability , as the probability of obtaining a vocabulary from the vocabulary, while can be used as the probability of selecting a word from the original sentence. Combining the vocabulary and the input to generate a new extended vocabulary, and performing information extraction on this basis can take into account both the diversity and accuracy of generation. The following is a detailed description of the extraction process.
[0048] Specifically, first construct the input prompt, input it into the large language model (LLMs), and use the output of the model's hidden layer as the attention matrix, denoted as , where represents the number of neurons in the hidden layer.
[0049] (1)
[0050] As the model generates, the output of the model's hidden layer at the current state is denoted as :
[0051] [[ID=?]] (2)
[0052] Among them, represents the content that has been generated at the current state.
[0053] From Note: There seems to be a formatting or numbering issue with the "?" in the translation. It should be "34" as per the original text's numbering sequence. Please check and correct if necessary.We can calculate the probability distribution on the original vocabulary. :
[0054] (3)
[0055] The attention matrix and the current hidden layer state can calculate the current context vector. : :
[0056] (4)
[0057] By combining the context vector with the hidden layer state and performing a sigmoid operation, the generation probability of the current state can be calculated. :
[0058] (5)
[0059] Among them, 、 and are learnable parameters, is the transpose of , is the transpose of , is a soft switch that selects whether to sample to generate a word from the vocabulary or copy a word from the input sequence through the attention distribution sample.
[0060] The extended vocabulary is represented as the union of the original vocabulary and the original text. By comprehensively selecting the results, the final probability distribution on the extended vocabulary at state t can be obtained:
[0061] (6)
[0062] Among them, when is a word outside the vocabulary, is 0. Similarly, when does not appear in the original sentence, is 0.
[0063] Finally, we select the word with the highest probability distribution from the extended vocabulary as the output at the current state . The loss of state is the negative log-likelihood of the target word at this state:
[0064] (7)
[0065] Overall Definition As follows, where represents the total number of all states.
[0066] (8)
[0067] Specifically, in step 2, the stability of the prompts for the large language model is enhanced by dynamically optimizing the prompt templates through a conversational policy gradient framework, including: constructing a prompt set driven by multi-round conversations and generating a candidate prompt set that aligns with the training data distribution using a dialogue model; prompt matching guided by reinforcement learning, constructing a Markov decision process, and dynamically selecting a prompt template that adapts to the input semantics through a policy network.
[0068] First, select the ACE2005 dataset as the basic corpus, and randomly extract k = 10 samples from it to form a seed set. Each sample contains the text input z and its annotated entity labels, and the text length is limited to 256 words. Call the GPT-4 API (version gpt-4-1106-preview), set the temperature parameter to 0.5, and the maximum generation length to 512.
[0069] Specifically, in the multi-round conversation execution stage, randomly select 2 samples from the seed set (such as ), and send the instruction to GPT-4: "Generate 5 information extraction prompt templates based on the following input features: ". Obtain the initial prompt set . Subsequently, input the remaining 8 seed samples into the conversation process in turn. Taking the sample as an example, send the optimization instruction: "Optimize the semantic structure of according to the F1 score of in the input , and rewrite the prompt". After 3 rounds of optimization iterations, obtain the optimized prompt .
[0070] Specifically, perform 5 rounds of shuffling on the seed set, and repeat the multi-round conversation execution stage after each shuffle. Finally, generate a candidate set containing 50 optimized prompts, and select the first 15 inputs as the final prompt set.
[0071] Specifically, in the prompt matching stage, we define the discrete prompt matching problem as a reinforcement learning problem, a Markov decision process. For the action space of the reinforcement learning agent, the action means that the agent selects a prompt from the prompt set constructed in the prompt set construction stage. Given a training set of size T interactions , test set , pre-trained language model , prompt set We first describe the details of the state space, action space, and reward design.
[0072] Specifically, the embodiment of the present invention further provides a state space, which uses the last hidden layer embedding input in the pre-trained language model to represent the state , and input it into the policy network. To avoid the state differences being too small to make the reinforcement learning agent difficult to distinguish, we normalize the states during the training process of the policy network.
[0073] Specifically, the embodiment of the present invention also provides an action space, an action The goal is to match the appropriate input prompts based on the observed state. To make action decisions, we will train a policy network , the network is a simple two-layer fully connected network with parameters Optimization is performed using the policy gradient algorithm. For the input , The probability distribution of the output action is as follows:
[0074] (9)
[0075] in, and Represents the parameters of the two fully connected layers , , is a trainable parameter, is the hidden layer dimension, Prompts the cardinality of the collection.
[0076] Specifically, the embodiment of the present invention also provides a reward design, which is a reinforcement learning agent that receives feedback and directly guides the update direction of the policy network. In order to ensure the quality of the information extraction task and maintain a balanced distribution of predicted labels, we use the F1 score to illustrate the degree of match between the prompt and the input. Specifically, given an input , we will select the prompt of As a reinforcement learning agent in step Rewards .
[0077] Specifically, the reward function is constructed based on the F1 score of information extraction , the calculation formula of F1 score is:
[0078] F1=2*P*R / (P+R) (10)
[0079] Among them, \(P = TP / (TP + FP)\), where \(TP\) represents True Positive, True indicates correct prediction, and Positive indicates positive sample. Similarly, \(FP\) represents False Positive, and \(FN\) represents False Negative. And normalize the batch reward:
[0080] (11)
[0081] Among them, are the mean and standard deviation of the current batch reward.
[0082] Specifically, in each interaction during the training phase , given the state , that is, the last hidden layer embedding of the input ; the reinforcement learning agent selects a prompt from the prompt set according to the policy , where are the learnable parameters of the policy network; connect the prompt and the input , input them into the pre-trained language model to complete the information extraction task, and calculate the reward of the reinforcement learning agent according to the output of the model. The goal of the reinforcement learning agent is to maximize the expected reward , where is the discount factor at step .
[0083] Specifically, in the test phase, the policy network selects the prompt with the largest action probability value and inputs it into the pre-trained language model to perform the information extraction task.
[0084] Specifically, in step 3, in order to simulate real text noise, a noise process \(N\) is modeled to simulate real noise. First, establish character-level noise operations, introduce placeholder to construct an extended input sequence to achieve the mathematical computability of noise operations, and generate perturbed text that conforms to the real noise distribution through random sampling. Among them, the insertion operation simulates the probability distribution of randomly adding redundant characters, the deletion operation characterizes the probability of character deletion, and the replacement operation quantifies the possibility of replacing similar-shaped characters and homophonic characters. Assume that the noise probabilities of the three operations are equal, as shown in formula (12).
[0085] (12)
[0086] Among them, \(c\) and respectively represent the original characters and the characters after introducing noise, and the probabilities of character insertion and replacement are uniform on the dataset.
[0087] Specifically, in the embodiments of the present invention, a noise induction program is used to generate distorted samples of the input. Let x represent the original text of the input. For each character in the text , independent noise operations are performed on them through the following program, where K represents the length of the original text x:
[0088] (1) Insert symbols before and after each character to obtain .
[0089] (2) For each character in , we randomly sample a replacement character from the corresponding probability distribution to obtain the extended input with noise introduced , where the probability distribution can be obtained from the row corresponding to the character in the noise channel matrix.
[0090] (3) Remove the symbols in the extended input to obtain the input with noise introduced
[0091] Specifically, in the design of the training mechanism, the process of designing a composite loss function with mixed weights is as follows. Given that is the target of a standard sequence labeling problem, where x is the input text and y is the corresponding true label sequence, represents the parameters of F(x), and a composite loss function is designed:
[0092] (13)
[0093] where is the text with noise introduced, and α is the weight of the noise loss component. The composite loss function in our data augmentation method uses the original text and the text with noise introduced to train the model. The goal of stability training is to stabilize the output y(x) of the information extraction model against input perturbations. We regard this problem as flattening y(x) in the neighborhood of any input sentence x, that is, when the input with noise introduced is close to the original input x, the output y( ) of the model should also be close to y(x). In the stability enhancement stage, a KL divergence similarity constraint is introduced, and D is defined as the KL divergence to measure the distance between the model's responses to the original input and the input with noise introduced:
[0094] (14)
[0095] (15)
[0096] (16)
[0097] Among them, is the loss function, which can improve the similarity between the model's output for x and ; Stability enhancement loss; and respectively represent the logits probability distributions of the original sample and the noise sample. The key difference between data augmentation and stability training is that data augmentation applies the noise sample to the original task, while stability training only uses the noise sample for the stability objective.
[0098] The implementation basis of each embodiment of the present invention is achieved through programmed processing by a device with processor functions. Therefore, in engineering practice, the technical solutions and functions of each embodiment of the present invention are encapsulated into various modules. Based on this actual situation, on the basis of the above embodiments, an embodiment of the present invention provides a text information extraction system based on a large language model, which is used to execute a text information extraction method based on a large language model in the above method embodiments.
[0099] The system includes: a data acquisition module for acquiring text information data; a text information extraction module for inputting the acquired text information data into a trained text information extraction model for text information processing; wherein, the training of the text information extraction model includes: constructing a generative and discriminative text information extraction model based on a large language model, introducing a discriminative component in the decoder layer, and achieving the balance between generation and replication by analyzing the hidden layer output of the decoder and using a dynamic generation probability calculation module; constructing a dialog policy gradient discrete prompt optimization framework for prompt stability enhancement training; constructing a noise channel matrix for data augmentation training and stability enhancement training.
[0100] The text information extraction system based on a large language model provided by the embodiment of the present invention solves the problems of hallucination in generative information extraction in the prior art and insufficient stability caused by high dependence on prompt engineering and data quality. By adopting several modules and introducing a discriminative component, the stability of the model and the accuracy of the extraction result are effectively improved. By designing a dynamic generation probability calculation module and an extended vocabulary mechanism, the balance between generation and replication is optimized, enabling the text information extraction model to more stably extract high-quality entities and relationships from unstructured text, and it can be widely applied to fields such as knowledge graph construction and public opinion analysis, effectively improving the efficiency and accuracy of information extraction.
[0101] Based on the same inventive concept as the foregoing embodiments, an embodiment of the present invention further provides an electronic device, including a memory and a processor. The memory is used to store computer-executable instructions, and the processor is used to execute the computer-executable instructions to implement a method for extracting text information based on a large language model as proposed in the above embodiments.
[0102] An embodiment of the present invention further provides a computer-readable storage medium, on which a computer program is stored. When the program is executed by a processor, it overcomes the problems of hallucination, prompt engineering relying on empirical design, and lack of an automated optimization framework, effectively improves the stability of the model and the accuracy of the extraction results, optimizes the balance between generation and replication, and enables the text information extraction model to more stably extract high-quality entities and relationships from unstructured text.
[0103] The storage medium can be any non-volatile storage device such as a hard disk, a solid-state drive, a flash drive, an optical disc, etc., for storing computer program code and necessary data files. The stored computer program includes: a data acquisition module, a text information extraction module.
[0104] Finally, it should be pointed out that the above specific embodiments are only relatively representative examples of the present invention. Obviously, the present invention is not limited to the above specific embodiments and there can be many variations. Any simple modification, equivalent change and modification made to the above specific embodiments based on the technical essence of the present invention shall be considered as belonging to the protection scope of the present invention.
Claims
1. A text information extraction method based on a large language model, characterized in that, Including: Obtain text information data; Input the obtained text information data into a trained text information extraction model to obtain a text information extraction result; wherein, the training of the text information extraction model includes: Construct a generative and discriminative text information extraction model based on a large language model, introduce a discriminative component in the decoder layer, analyze the hidden layer output of the decoder, and use a dynamic generation probability calculation module to achieve the balance between generation and copying; Construct a conversational policy gradient discrete prompt optimization framework for prompt stability enhancement training; Construct a noise channel matrix for data augmentation training and stability enhancement training.
2. The text information extraction method based on a large language model according to claim 1, characterized in that, Construct a conversational policy gradient discrete prompt optimization framework for prompt stability enhancement training, including: Based on the prompt set construction stage of multi-round dialogue alignment, use a dialogue model to generate a basic prompt set aligned with the training data distribution; Based on the prompt matching stage of reinforcement learning, dynamically select a prompt template adapted to the current input through a policy network.
3. A method for extracting text information based on a large language model according to claim 2, characterized in that, The prompt set construction stage includes: Randomly select k samples from the training set as the initial seed set; Execute multi-round dialogues through a dialogue model to form a candidate set containing all optimized prompts.
4. A method for extracting text information based on a large language model according to claim 1, characterized in that, The construction of the noise channel matrix includes: Establish a character-level noise probability distribution model to simulate three types of noise interference processes: insertion, deletion, and replacement operations; Generate an extended input by inserting placeholders before and after the original input sequence, randomly sample according to the noise probability distribution to generate a perturbed text, and finally remove the placeholders to obtain a noisy sample.
5. A method for extracting text information based on a large language model according to claim 1, characterized in that The loss function of the text information extraction model combines the characteristics of generative and discriminative, and is defined as: , where T is the time, and the loss of the state is the negative log-likelihood of the target word in this state . .
6. A method for extracting text information based on a large language model according to claim 1, wherein, The stability enhancement training introduces a KL divergence similarity constraint, including: , , Among them, is the target of the standard sequence labeling problem, where x is the input text and y is the corresponding true label sequence, are the parameters of F(x), is the loss function, Stability-enhanced loss, is the text after introducing noise, and α is the weight of the noise loss component, and respectively represent the logits probability distributions of the original sample and the noise sample.
7. A text information extraction system based on a large language model, characterized in that, Including: An acquisition data module for obtaining text information data; A text information extraction module for inputting the obtained text information data into a trained text information extraction model for text information processing; wherein, the training of the text information extraction model includes: Construct a generative and discriminative text information extraction model based on a large language model, introduce a discriminative component in the decoder layer, analyze the hidden layer output of the decoder, and use a dynamic generation probability calculation module to achieve the balance between generation and copying; Construct a conversational policy gradient discrete prompt optimization framework for prompt stability enhancement training; Construct a noise channel matrix for data augmentation training and stability enhancement training.
8. An electronic device, comprising a memory and a processor, the memory storing a computer program, characterized in that, When the processor executes the computer program, it implements the steps of the large language model-based text information extraction method described in claims 1 to 6.
9. A computer-readable storage medium having a computer program stored thereon, characterized in that, When the computer program is executed by the processor, it implements the steps of the large language model-based text information extraction method described in claims 1 to 6.
Citation Information
Cited By
Chinese multi-round dialogue model
CN121301535A
Chinese multi-turn dialogue model
CN121301535B