A text extraction method, device, equipment and storage medium
By extracting the reception text and the prompt text in small sample scenarios and using multiple loss values to train the text extraction model, the problem of inaccurate text extraction by deep learning in small sample scenarios is solved, and efficient text extraction under small sample conditions is achieved.
Patent Information
- Application Number
- CN202211116156.7
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2022-09-14
- Publication Date
- 2025-10-10
- Estimated Expiration
- 2042-09-14
AI Technical Summary
Existing deep learning-based text extraction methods have poor recognition and extraction effects in small sample scenarios, require a large number of samples to ensure accuracy, and cannot meet the application needs of professional fields.
By obtaining the text to be extracted and the extraction prompt text for splicing, using the text extraction model for training, combining the training prompt text, misleading text and influencing factor prompt text, and using multiple loss values to calculate and adjust the model, an accurate text extraction model is generated.
Under small sample conditions, the accuracy and speed of text extraction are improved, and it is suitable for vertical fields such as finance, biology or chemistry.
Smart Images

Figure CN115438163B_ABST
Abstract
Description
TECHNICAL FIELD
[0001] The present application relates to the technical field of text extraction, and particularly relates to a text extraction method, device, equipment and storage medium. BACKGROUND
[0002] Text extraction refers to recognizing and extracting text words with specific meanings in a text, including but not limited to organization names, personal names, place names, time or amounts, etc. Text words have the characteristics of openness and diversity, and the process of extracting text words is relatively difficult.
[0003] At present, text extraction methods mainly extract text based on deep learning, but this way has poor recognition and extraction effect in a small sample scene, and a large number of samples are needed to ensure the accuracy of recognition and extraction. SUMMARY
[0004] Therefore, the embodiments of the present application provide a text extraction method, device, equipment and storage medium, which can improve the accuracy of text extraction results in a small sample scene.
[0005] In a first aspect, the embodiments of the present application provide a text extraction method, which comprises:
[0006] obtaining a text to be extracted and an extraction prompt text corresponding to the text to be extracted, the extraction prompt text being a text indicating extraction of an entity corresponding to a target influence factor in the text to be extracted;
[0007] splicing the text to be extracted and the extraction prompt text to obtain a first input text;
[0008] inputting the first input text into a text extraction model to obtain a first extraction text output by the text extraction model, the text extraction model being trained according to a sample text and a training prompt text, the training prompt text corresponding to the sample text, and the training prompt text being a text indicating extraction of an entity corresponding to a second influence factor in the sample text.
[0009] Optionally, the text extraction model is trained by the following method:
[0010] obtaining a sample text, the training prompt text and a label of the sample text, the label of the sample text being a text of an entity corresponding to the first influence factor, and the training prompt text being a text indicating extraction of an entity corresponding to a second influence factor in the sample text;
[0011] splicing the sample text and the training prompt text to obtain a second input text;
[0012] Inputting the second input text into the extraction model to be trained to obtain a second extracted text output by the extraction model to be trained;
[0013] Calculating a first loss value based on the second extracted text and the label;
[0014] The extraction model to be trained is adjusted according to the first loss value, and the steps of obtaining the sample text, the training prompt text, and the label of the sample text and subsequent steps are returned to execute until the preset conditions are met to generate a text extraction model.
[0015] Optionally, the text extraction model is trained using the following method:
[0016] Obtaining a sample text, the training prompt text, the training misleading text, and a label of the sample text, wherein the training prompt text is a text indicating the extraction of an entity corresponding to a second influencing factor in the sample text, the training misleading text is a text indicating the extraction of an entity corresponding to a third influencing factor in the sample text, and the label of the sample text includes a first label and a second label, wherein the first label is the text of the entity corresponding to the second influencing factor, and the second label is the text of the entity corresponding to the third influencing factor;
[0017] Concatenate the sample text and the training prompt text to obtain a third input text;
[0018] Inputting the third input text into the extraction model to be trained to obtain a third extracted text output by the extraction model to be trained;
[0019] Calculating a second loss value based on the third extracted text and the first label;
[0020] splicing the sample text with the training misleading text to obtain a fourth input text;
[0021] Inputting the fourth input text into the extraction model to be trained to obtain a fourth extracted text output by the extraction model to be trained;
[0022] Calculating a third loss value based on the fourth extracted text and the second label;
[0023] Calculate the second loss value and the third loss value according to the weight ratio to obtain a fourth loss value;
[0024] The extraction model to be trained is adjusted according to the fourth loss value, and the steps of obtaining the sample text, the training prompt text, the training misleading text, and the label of the sample text, as well as subsequent steps, are returned to execute until a preset condition is met to generate a text extraction model.
[0025] Optionally, the text extraction model is trained by the following method:
[0026] obtaining a sample text, a training prompt text, an influence factor prompt text, and a label of the sample text, the training prompt text being a text indicating extraction of an entity corresponding to a second influence factor in the sample text, the influence factor prompt text being a text indicating extraction of a fourth influence factor in the sample text, the label of the sample text including a third label and a fourth label, the third label being a text of an entity corresponding to the second influence factor, and the fourth label being a text of an entity corresponding to the fourth influence factor;
[0027] splicing the sample text and the training prompt text to obtain a fifth input text;
[0028] inputting the fifth input text into a to-be-trained extraction model to obtain a fifth extraction text output by the to-be-trained extraction model;
[0029] calculating a fifth loss value according to the fifth extraction text and the third label;
[0030] splicing the sample text and the influence factor prompt text to obtain a sixth input text;
[0031] inputting the sixth input text into the to-be-trained extraction model to obtain a sixth extraction text output by the to-be-trained extraction model;
[0032] calculating a sixth loss value according to the sixth extraction text and the fourth label;
[0033] calculating a seventh loss value according to the fifth loss value and the sixth loss value in a weight ratio;
[0034] adjusting the to-be-trained extraction model according to the seventh loss value, and returning to execute the obtaining of the sample text, the training prompt text, the influence factor prompt text, and the label of the sample text, and subsequent steps until a preset condition is met to generate a text extraction model.
[0035] In a second aspect, an embodiment of the present application provides a text extraction device, and the device comprises:
[0036] an obtaining module configured to obtain a to-be-extracted text and an extraction prompt text corresponding to the to-be-extracted text, the extraction prompt text being a text indicating extraction of an entity corresponding to a target influence factor in the to-be-extracted text;
[0037] a splicing module configured to splice the to-be-extracted text and the extraction prompt text to obtain a first input text;
[0038] An extraction module is used to input the first input text into a text extraction model to obtain a first extracted text output by the text extraction model. The text extraction model is trained based on sample text and training prompt text. The training prompt text corresponds to the sample text, and the training prompt text is a text indicating the extraction of the entity corresponding to the second influencing factor in the sample text.
[0039] Optionally, the text extraction model is trained using the following method:
[0040] Acquire a sample text, the training prompt text, and a label of the sample text, wherein the label of the sample text is a text of an entity corresponding to the first influencing factor, and the training prompt text is a text indicating extraction of an entity corresponding to a second influencing factor from the sample text;
[0041] Splicing the sample text and the training prompt text to obtain a second input text;
[0042] Inputting the second input text into the extraction model to be trained to obtain a second extracted text output by the extraction model to be trained;
[0043] Calculating a first loss value based on the second extracted text and the label;
[0044] The extraction model to be trained is adjusted according to the first loss value, and the steps of obtaining the sample text, the training prompt text, and the label of the sample text and subsequent steps are returned to execute until the preset conditions are met to generate a text extraction model.
[0045] Optionally, the text extraction model is trained using the following method:
[0046] Obtaining a sample text, the training prompt text, the training misleading text, and a label of the sample text, wherein the training prompt text is a text indicating the extraction of an entity corresponding to a second influencing factor in the sample text, the training misleading text is a text indicating the extraction of an entity corresponding to a third influencing factor in the sample text, and the label of the sample text includes a first label and a second label, wherein the first label is the text of the entity corresponding to the second influencing factor, and the second label is the text of the entity corresponding to the third influencing factor;
[0047] Concatenate the sample text and the training prompt text to obtain a third input text;
[0048] Inputting the third input text into the extraction model to be trained to obtain a third extracted text output by the extraction model to be trained;
[0049] Calculating a second loss value based on the third extracted text and the first label;
[0050] splicing the sample text with the training misleading text to obtain a fourth input text;
[0051] Inputting the fourth input text into the extraction model to be trained to obtain a fourth extracted text output by the extraction model to be trained;
[0052] Calculating a third loss value based on the fourth extracted text and the second label;
[0053] Calculate the second loss value and the third loss value according to the weight ratio to obtain a fourth loss value;
[0054] The extraction model to be trained is adjusted according to the fourth loss value, and the steps of obtaining the sample text, the training prompt text, the training misleading text, and the label of the sample text, as well as subsequent steps, are returned to execute until a preset condition is met to generate a text extraction model.
[0055] Optionally, the text extraction model is trained using the following method:
[0056] Obtaining a sample text, the training prompt text, an influence factor prompt text, and a label of the sample text, wherein the training prompt text is a text indicating the extraction of an entity corresponding to a second influence factor in the sample text, the influence factor prompt text is a text indicating the extraction of a fourth influence factor in the sample text, and the label of the sample text includes a third label and a fourth label, wherein the third label is the text of the entity corresponding to the second influence factor, and the fourth label is the text of the entity corresponding to the fourth influence factor;
[0057] Concatenate the sample text and the training prompt text to obtain a fifth input text;
[0058] Inputting the fifth input text into the extraction model to be trained to obtain a fifth extracted text output by the extraction model to be trained;
[0059] Calculating a fifth loss value based on the fifth extracted text and the third label;
[0060] splicing the sample text with the impact factor prompt text to obtain a sixth input text;
[0061] Inputting the sixth input text into the extraction model to be trained to obtain a sixth extracted text output by the extraction model to be trained;
[0062] Calculating a sixth loss value based on the sixth extracted text and the fourth label;
[0063] Calculate the fifth loss value and the sixth loss value according to the weight ratio to obtain a seventh loss value;
[0064] The extraction model to be trained is adjusted according to the seventh loss value, and the steps of obtaining the sample text, the training prompt text, the influence factor prompt text and the label of the sample text, and subsequent steps are returned to execute until the preset conditions are met to generate a text extraction model.
[0065] In a third aspect, an embodiment of the present application provides a device comprising a memory and a processor, wherein the memory is used to store instructions or codes, and the processor is used to execute the instructions or codes so that the device performs the text extraction method described in any one of the first aspects above.
[0066] In a fourth aspect, an embodiment of the present application provides a computer storage medium, wherein the computer storage medium stores a code. When the code is executed, the device executing the code implements the text extraction method described in any one of the first aspects above.
[0067] The embodiments of the present application provide a method, apparatus, device, and storage medium for text extraction. When executing the method, a text to be extracted and an extraction prompt text are obtained, and the text to be extracted and the extraction prompt text are spliced to obtain a second input text. The second input text is used as the input of a text extraction model to obtain a first extracted text, and then a target text is generated based on the first extracted text to complete text extraction. The text extraction model is trained based on sample text and training prompt text. Based on the training prompt text, a text extraction model that can be trained to extract more accurately can be obtained under the condition of a small number of samples. Then, text extraction is completed based on the text extraction model. BRIEF DESCRIPTION OF THE DRAWINGS
[0068] In order to more clearly illustrate the technical solutions in this embodiment or the prior art, the following briefly introduces the drawings required for use in the embodiment or the prior art description. Obviously, the drawings described below are only some embodiments of the present application. For ordinary technicians in this field, other drawings can be obtained based on these drawings without creative work.
[0069] Figure 1 A flowchart of a text extraction method provided in an embodiment of the present application;
[0070] Figure 2 A flowchart of another text extraction method provided in an embodiment of the present application;
[0071] Figure 3 A schematic diagram of a text extraction model training process provided in an embodiment of the present application;
[0072] Figure 4A schematic diagram of the structure of a text extraction device provided in an embodiment of the present application. DETAILED DESCRIPTION
[0073] Currently, text extraction methods primarily rely on deep learning. However, deep learning-based text extraction methods require a large number of samples to train the model. In highly specialized fields, this often results in insufficient sample size for model training. Models trained on small sample sizes are unable to effectively extract text, resulting in inaccurate results and slow extraction speeds. Therefore, these deep learning-based text extraction methods are unsuitable for small sample sizes and cannot meet application requirements.
[0074] To address the above-mentioned issues, this application provides a method, apparatus, device, and storage medium for text extraction. This method uses sample text and training prompt text to train a model. Using a prompt-based learning training method, a text extraction model with relatively accurate extraction results can be trained. This text extraction model can then be used for text extraction. Even with small sample sizes, this method can effectively extract text, effectively resolving the aforementioned issues.
[0075] It should be noted that the text extraction method, device, equipment and storage medium provided in this application can be applied to vertical fields such as finance, biology or chemistry.
[0076] Obviously, the embodiments described in this application are only a part of the embodiments of this application, not all of the embodiments. Based on the embodiments in this application, all other embodiments obtained by ordinary technicians in this field without making creative efforts are within the scope of protection of this application.
[0077] See also Figure 1 , Figure 1 A flowchart of a text extraction method provided in an embodiment of the present application includes:
[0078] S101: Acquire a text to be extracted and an extraction prompt text corresponding to the text to be extracted.
[0079] The "to-be-extracted text" refers to the text that requires text extraction, such as financial statements, industry development overviews, or corporate annual reports. The "extraction hint text" indicates the entity corresponding to the target influencing factor in the to-be-extracted text. The "extraction hint text" corresponds to the to-be-extracted text and serves as a prompt during text extraction, assisting the text extraction model in extracting the text.
[0080] As an example, the text to be extracted is an industry development overview text. The text to be extracted is:
[0081] In the third quarter, the profit growth rate of Company A decreased, the profit growth rate of Company B decreased, and the profit growth rate of Company C increased.
[0082] If we need to extract companies with declining profit growth, the extraction prompt text will be "Extract the companies in this text with declining profit growth. Declining profit growth means that the company's profits have decreased on a quarter-on-quarter basis." This extraction prompt text can improve the accuracy and speed of the text extraction model in extracting companies with "declining profit growth." Furthermore, the explanation of "declining profit growth" in the extraction prompt text can also help the model understand the term "declining profit growth," thereby improving the accuracy of the extraction results.
[0083] S102: Concatenate the text to be extracted and the extraction prompt text to obtain a first input text.
[0084] The first input text includes the text to be extracted and the extraction prompt text. After obtaining the text to be extracted and the extraction prompt text corresponding to the text to be extracted, the two are spliced to obtain the first input text.
[0085] Based on the text to be extracted and the extraction prompt text in the above example, the second input text obtained by splicing the two can be "In the third quarter, the profit growth rate of Company A decreased, the profit growth rate of Company B decreased, and the profit growth rate of Company C increased. Find the companies in this text whose profit growth rate decreased. The decrease in profit growth rate means that the company's profit decreased on a quarter-on-quarter basis."
[0086] S103: Input the first input text into a text extraction model to obtain a first extracted text output by the text extraction model.
[0087] The text extraction model is trained based on sample text and training prompt text, where the training prompt text corresponds to the sample text. The text extraction model is used to perform text extraction on the text to be extracted, obtaining an extraction result. The sample text is labeled with the text of the entity corresponding to the first influencing factor, and the training prompt text is text indicating the entity corresponding to the second influencing factor in the sample text to be extracted. A first input text is input into the text extraction model, which processes the first input text based on the extraction prompt text, and then extracts the text to be extracted from the first input text, outputting a first extracted text.
[0088] Based on the above example, the first extracted text output is "Company A, Company B.".
[0089] In addition, this application introduces three training methods for text extraction models below.
[0090] An embodiment of the present application provides a method for text extraction. By concatenating the text to be extracted and the extraction prompt text to obtain a second input text, and using the second input text as the input of the text extraction model, the text extraction model can extract the text to be extracted based on the extraction prompt text, and the text extraction model is trained based on the sample text and the training prompt text. By training the model based on the training prompt text, even if the number of samples is small, a text extraction model that can extract text more accurately can be trained. In a small sample scenario, text can also be effectively extracted.
[0091] The text extraction method provided by the embodiments of the present application has been described in detail above. Based on the above embodiments, the training methods of three text extraction models will be described. It should be noted that the implementation methods given in the following description are only exemplary and do not represent all implementation methods of the embodiments of the present application.
[0092] The first one:
[0093] See also Figure 2 , Figure 2 A flowchart of a method for training a text extraction model provided in an embodiment of the present application includes:
[0094] S201: Obtain sample text, the training prompt text, and a label of the sample text.
[0095] The label of the sample text is the text of the entity corresponding to the first influencing factor. The training prompt text is the text that instructs the extraction of the entity corresponding to the second influencing factor in the sample text. The label of the sample text is the text of the entity corresponding to the second influencing factor. The label of the sample text can be manually annotated in advance. When obtaining the sample text and the training prompt text, the label of the sample text must also be obtained. The specific acquisition path and method can be set according to actual needs.
[0096] S202: Concatenate the sample text and the training prompt text to obtain a second input text.
[0097] The second input text includes a sample text and a training prompt text. After obtaining the sample text and the training prompt text corresponding to the sample text, the two are concatenated to obtain the second input text.
[0098] S203: Input the second input text into the extraction model to be trained to obtain a second extracted text output by the extraction model to be trained.
[0099] The second input text is used as the input of the extraction model to be trained. The recognition model to be trained processes the training prompt text in the second input text, and then extracts the sample text in the second input text to output the second extracted text.
[0100] S204: Calculate a first loss value according to the second extracted text and the label.
[0101] The first loss value can be calculated by comparing the result obtained by extracting the second input text by the to-be-trained extraction model with the pre-labeled label. The extraction error of the to-be-trained extraction model can be known through the first loss value, and the to-be-trained extraction model is adjusted according to the first loss value.
[0102] S205: Adjust the to-be-trained extraction model according to the first loss value, and return to execute the steps of obtaining the sample text, the training prompt text, the label of the sample text, and the subsequent steps until a text extraction model is generated when a preset condition is met.
[0103] The to-be-trained extraction model is adjusted according to the loss value, and the accuracy of the to-be-trained extraction model in recognizing the sample text is improved.
[0104] The steps S201-S204 are repeatedly executed to realize multiple training of the to-be-trained extraction model. Until the current to-be-trained extraction model meets the preset condition, the training of the to-be-trained extraction model is completed. The preset condition can be that the loss value is less than a set threshold, or the extraction speed is less than a preset time. When the to-be-trained extraction model meets the preset condition, the to-be-trained extraction model is used as the final model for extracting the to-be-extracted text, and a text extraction model is generated, and the model training is completed.
[0105] In the embodiment of the present application, the sample text and the training prompt text are spliced to obtain a second input text, and the second input text is taken as the input of the to-be-trained extraction model to output a second extracted text. A first loss value is calculated according to the second extracted text and the label, and the to-be-trained extraction model is adjusted based on the first loss value. The above method is repeatedly executed until a preset condition is met, and a text extraction model is generated. Through the above method, the to-be-trained extraction model is trained according to the training prompt text. Even if the text extraction model is trained based on a small sample, the text can also be extracted more accurately.
[0106] Second:
[0107] The second text extraction model training method provided in the present application is based on the first training method, and a training misleading text is added to reduce the probability of text extraction error of the text extraction model and improve the accuracy of text extraction of the text extraction model.
[0108] A1: Obtain a sample text, a training prompt text, a training misleading text, and a label of the sample text.
[0109] The training prompt text is used to indicate the extraction of the entity corresponding to the second influence factor in the sample text. The training misleading text is used to indicate the extraction of the entity corresponding to the third influence factor in the sample text. The meaning of the second influence factor can be opposite to that of the third influence factor. The labels of the sample text include a first label and a second label. The first label is the text of the entity corresponding to the second influence factor, and the second label is the text of the entity corresponding to the third influence factor.
[0110] Based on the above example:
[0111] The sample text is:
[0112] In the third quarter, the profit growth of A company decreased, the profit growth of B company decreased, and the profit growth of C company increased.
[0113] The second influence factor is the decrease in profit growth, and the training prompt text is used to indicate the extraction of the company with decreasing profit growth in the text. The third influence factor is the increase in profit growth, and the training misleading sample is used to indicate the extraction of the company with increasing profit growth in the text.
[0114] A2: Splice the sample text and the training prompt text to obtain a third input text.
[0115] The third input text includes the sample text and the training prompt text. After obtaining the sample text and the training prompt text corresponding to the sample text, the two are spliced to obtain the third input text.
[0116] A3: Input the third input text into the to-be-trained extraction model to obtain a third extraction text output by the to-be-trained extraction model.
[0117] The third input text is used as the input of the to-be-trained extraction model. The to-be-trained recognition model processes the training prompt text in the third input text, and then extracts the text of the entity corresponding to the influence factor in the sample text, and outputs the third extraction text.
[0118] Based on the above example, the third extraction text is "A company, B company".
[0119] A4: Calculate a second loss value according to the third extraction text and the first label.
[0120] The result obtained by the to-be-trained extraction model extracting the third input text is calculated with the pre-labeled first label, and the second loss value can be obtained.
[0121] A5: Splice the sample text and the training misleading text to obtain a fourth input text.
[0122] The fourth input text includes a sample text and a training misleading text. After obtaining the sample text and the training misleading text corresponding to the training prompt text, the two are concatenated to obtain the fourth input text.
[0123] A6: Input the fourth input text into the extraction model to be trained to obtain a fourth extracted text output by the extraction model to be trained.
[0124] The fourth input text is used as the input of the extraction model to be trained. The recognition model to be trained processes the training misleading text in the fourth input text, and then extracts the text of the entity in the sample text that is opposite to the impact factor, and outputs the fourth extracted text.
[0125] Based on the above example, the fourth extracted text is "C Company.".
[0126] A7: Calculate a third loss value based on the fourth extracted text and the second label.
[0127] The third loss value can be obtained by calculating the result obtained after the extraction model to be trained extracts the fourth input text and the pre-labeled second label.
[0128] A8: Calculate the second loss value and the third loss value according to the weight ratio to obtain a fourth loss value.
[0129] The weight ratio describes the percentage of the second loss value and the percentage of the third loss value. As an example, the second loss value and the third loss value can be weighted and summed according to the weight ratio to obtain a fourth loss value. The fourth loss value is the sum of the product of the second loss value and the weight of the second loss value, and the product of the third loss value and the weight of the third loss value.
[0130] A9: Adjust the extraction model to be trained according to the fourth loss value, and return to execute the steps of obtaining the sample text, the training prompt text, the training misleading text, and the label of the sample text, as well as subsequent steps, until the preset conditions are met to generate a text extraction model.
[0131] The extraction model to be trained is adjusted according to the fourth loss value to improve the accuracy of the extraction model to be trained in recognizing the sample text.
[0132] Repeat steps A1-A8 to train the extraction model to be trained multiple times. Training of the extraction model to be trained is completed until the current extraction model to be trained meets preset conditions. The preset conditions can be a loss value less than a set threshold or an extraction speed less than a preset time. When the extraction model to be trained meets the preset conditions, the extraction model to be trained is used as the final model for extracting the text to be extracted, generating a text extraction model and completing model training.
[0133] In an embodiment of the present application, based on the training method of the first text extraction model, a training misleading text is introduced, and the training misleading text is spliced with the sample text to obtain a fourth input text. The fourth input text is extracted using the extraction model to be trained to obtain a fourth extracted text. A third loss value is obtained using the fourth extracted text and the second label. The third loss value and the second loss value are calculated according to the weight ratio to obtain a fourth loss value, and then the extraction model to be trained is adjusted based on the fourth loss value. The above method is repeatedly executed until the preset conditions are met, and a text extraction model is generated. Model training based on training misleading text can reduce the probability of the text extraction model extracting incorrect text and improve the accuracy of the text extraction model in text extraction.
[0134] The third type:
[0135] The third text extraction model training method provided in this application is based on the first training method, and adds an impact factor prompt text, which can verify the impact factors in the training prompt text and improve the accuracy of text extraction by the text extraction model.
[0136] B1: Obtain sample text, the training prompt text, obtain impact factor prompt text and the label of the sample text.
[0137] The training prompt text is a text indicating the extraction of the entity corresponding to the second influencing factor in the sample text, and the impact factor prompt text is a text indicating the extraction of the fourth influencing factor in the sample text. The label of the sample text includes a third label and a fourth label. The third label is the text of the entity corresponding to the second influencing factor, and the fourth label is the text of the entity corresponding to the fourth influencing factor.
[0138] As an example, the text to be extracted is an industry development overview text. The text to be extracted is:
[0139] In the third quarter, the profit growth rate of Company A decreased, the profit growth rate of Company B decreased, and the profit growth rate of Company C increased.
[0140] The training prompt text is "Extract the companies with declining profit growth rate in this text. Declining profit growth rate means that the company's profit has declined on a month-on-month basis." The impact factor prompt text is "Extract the text of the impact factor in this text."
[0141] B2: Concatenate the sample text and the training prompt text to obtain a fifth input text.
[0142] The fifth input text includes sample text and training prompt text. After obtaining the sample text and the training prompt text corresponding to the sample text, the two are concatenated to obtain the fifth input text. Figure 3The fifth input text is "In the third quarter, the profit growth rate of Company A decreased, the profit growth rate of Company B decreased, and the profit growth rate of Company C increased. Extract the companies with decreased profit growth rate in this text. The decreased profit growth rate means that the company's profit decreased on a quarter-on-quarter basis."
[0143] B3: Inputting the fifth input text into the extraction model to be trained to obtain the fifth extracted text output by the extraction model to be trained.
[0144] The fifth input text is used as the input of the extraction model to be trained. The recognition model to be trained extracts the text of the entity corresponding to the impact factor in the sample text according to the training prompt text in the fifth input text, and outputs the fifth extracted text. Figure 3 , the fifth extracted text is "Company A, Company B.".
[0145] B4: Calculate a fifth loss value based on the fifth extracted text and the third label.
[0146] The fifth loss value can be obtained by calculating the result obtained after the extraction model to be trained extracts the fifth input text and the pre-labeled third label.
[0147] B5: Concatenate the sample text and the impact factor prompt text to obtain a sixth input text.
[0148] The sixth input text includes a sample text and an impact factor prompt text. After obtaining the sample text and the impact factor prompt text corresponding to the sample text, the two are concatenated to obtain the sixth input text. Figure 3 , the sixth input text is "In the third quarter, the profit growth rate of Company A decreased, the profit growth rate of Company B decreased, and the profit growth rate of Company C increased. Extract the text of the influencing factors in this text.".
[0149] B6: Inputting the sixth input text into the extraction model to be trained to obtain a sixth extracted text output by the extraction model to be trained.
[0150] The sixth input text is used as the input of the extraction model to be trained. The recognition model to be trained performs text extraction based on the influencing factor prompt text in the sixth input text, extracts the text of the influencing factor in the sample text, and outputs the sixth extracted text. Figure 3 , the sixth extracted text is "The profit growth rate has declined.".
[0151] B7: Calculate a sixth loss value based on the sixth extracted text and the fourth label.
[0152] The sixth loss value can be obtained by calculating the result obtained after the extraction model to be trained extracts the sixth input text and the pre-labeled fourth label.
[0153] B8: Calculate the fifth loss value and the sixth loss value according to the weight ratio to obtain a seventh loss value.
[0154] The weight ratio describes the percentage of the fifth loss value and the percentage of the sixth loss value. As an example, the fifth and sixth loss values can be weighted and summed according to the weight ratio to obtain the seventh loss value. This can be expressed as: the seventh loss value is the product of the fifth loss value and the weight of the fifth loss value, and the product of the sixth loss value and the weight of the sixth loss value.
[0155] B9: Adjust the extraction model to be trained according to the seventh loss value, return to execute the steps of obtaining the sample text, the training prompt text, obtaining the influence factor prompt text and the label of the sample text, and subsequent steps until the preset conditions are met to generate a text extraction model.
[0156] The extraction model to be trained is adjusted according to the seventh loss value to improve the accuracy of the extraction model to be trained in recognizing the sample text.
[0157] Repeat steps B1-B9 to train the extraction model to be trained multiple times. This training is completed until the current extraction model to be trained meets preset conditions. The preset conditions can be a loss value less than a set threshold or an extraction speed less than a preset time. When the extraction model to be trained meets the preset conditions, the extraction model to be trained is used as the final model for extracting the text to be extracted, generating a text extraction model and completing model training.
[0158] In an embodiment of the present application, based on the training method of the first text extraction model, an influence factor prompt text is introduced, the influence factor prompt text and the sample text are spliced to obtain a sixth input text, and the sixth input text is extracted using the extraction model to be trained to obtain a sixth extracted text. The sixth extracted text and the fourth label are used to obtain a sixth loss value. The fifth loss value and the sixth loss value are calculated according to the weight ratio to obtain a seventh loss value, and then the extraction model to be trained is adjusted based on the seventh loss value. The above method is repeatedly executed until the preset conditions are met, and a text extraction model is generated. Model training based on the influence factor prompt text can verify the influence factors summarized in the training prompt text, thereby improving the accuracy of text extraction by the text extraction model.
[0159] The above are some specific implementations of a text extraction method provided by the embodiment of the present application. Based on this, the present application also provides a corresponding device. The device provided by the embodiment of the present application will be introduced from the perspective of functional modularization.
[0160] See also Figure 4 , Figure 4 This is a structural diagram of a text extraction device provided in an embodiment of the present application. The device 400 includes an acquisition module 401, a splicing module 402 and an extraction module 403.
[0161] An acquisition module 401 is configured to acquire a text to be extracted and an extraction prompt text corresponding to the text to be extracted, wherein the extraction prompt text is a text indicating that an entity corresponding to a target impact factor in the text to be extracted should be extracted;
[0162] A splicing module 402 is used to splice the text to be extracted and the extraction prompt text to obtain a first input text;
[0163] Extraction module 403 is used to input the first input text into a text extraction model to obtain a first extracted text output by the text extraction model. The text extraction model is trained based on sample text and training prompt text. The training prompt text corresponds to the sample text. The training prompt text is a text indicating the extraction of the entity corresponding to the second influencing factor in the sample text.
[0164] In a possible implementation provided in the examples of the present application, the text extraction model is trained using the following method:
[0165] Acquire a sample text, the training prompt text, and a label of the sample text, wherein the label of the sample text is a text of an entity corresponding to the first influencing factor, and the training prompt text is a text indicating extraction of an entity corresponding to a second influencing factor from the sample text;
[0166] Splicing the sample text and the training prompt text to obtain a second input text;
[0167] Inputting the second input text into the extraction model to be trained to obtain a second extracted text output by the extraction model to be trained;
[0168] Calculating a first loss value based on the second extracted text and the label;
[0169] The extraction model to be trained is adjusted according to the first loss value, and the steps of obtaining the sample text, the training prompt text, and the label of the sample text and subsequent steps are returned to execute until the preset conditions are met to generate a text extraction model.
[0170] In a possible implementation provided in the examples of the present application, the text extraction model is trained using the following method:
[0171] Obtaining a sample text, the training prompt text, the training misleading text, and a label of the sample text, wherein the training prompt text is a text indicating the extraction of an entity corresponding to a second influencing factor in the sample text, the training misleading text is a text indicating the extraction of an entity corresponding to a third influencing factor in the sample text, and the label of the sample text includes a first label and a second label, wherein the first label is the text of the entity corresponding to the second influencing factor, and the second label is the text of the entity corresponding to the third influencing factor;
[0172] Concatenate the sample text and the training prompt text to obtain a third input text;
[0173] Inputting the third input text into the extraction model to be trained to obtain a third extracted text output by the extraction model to be trained;
[0174] Calculating a second loss value based on the third extracted text and the first label;
[0175] splicing the sample text with the training misleading text to obtain a fourth input text;
[0176] Inputting the fourth input text into the extraction model to be trained to obtain a fourth extracted text output by the extraction model to be trained;
[0177] Calculating a third loss value based on the fourth extracted text and the second label;
[0178] Calculate the second loss value and the third loss value according to the weight ratio to obtain a fourth loss value;
[0179] The extraction model to be trained is adjusted according to the fourth loss value, and the steps of obtaining the sample text, the training prompt text, the training misleading text, and the label of the sample text, as well as subsequent steps, are returned to execute until a preset condition is met to generate a text extraction model.
[0180] In a possible implementation provided in the examples of the present application, the text extraction model is trained using the following method:
[0181] Obtaining a sample text, the training prompt text, an influence factor prompt text, and a label of the sample text, wherein the training prompt text is a text indicating the extraction of an entity corresponding to a second influence factor in the sample text, the influence factor prompt text is a text indicating the extraction of a fourth influence factor in the sample text, and the label of the sample text includes a third label and a fourth label, wherein the third label is the text of the entity corresponding to the second influence factor, and the fourth label is the text of the entity corresponding to the fourth influence factor;
[0182] The sample text and the training prompt text are spliced to obtain a fifth input text;
[0183] The fifth input text is input into the to-be-trained extraction model to obtain a fifth extraction text output by the to-be-trained extraction model;
[0184] A fifth loss value is calculated according to the fifth extraction text and the third label;
[0185] The sample text and the influence factor prompt text are spliced to obtain a sixth input text;
[0186] The sixth input text is input into the to-be-trained extraction model to obtain a sixth extraction text output by the to-be-trained extraction model;
[0187] A sixth loss value is calculated according to the sixth extraction text and the fourth label;
[0188] The fifth loss value and the sixth loss value are calculated according to a weight ratio to obtain a seventh loss value;
[0189] The to-be-trained extraction model is adjusted according to the seventh loss value, and the subsequent steps of obtaining the sample text, the training prompt text, the influence factor prompt text, and the label of the sample text are executed until a preset condition is reached to generate a text extraction model.
[0190] Embodiments of the present application provide a text extraction device. By splicing the text to be extracted and the extraction prompt text to obtain a second input text, the text extraction model can extract text from the text to be extracted based on the extraction prompt text. And the text extraction model is trained based on the sample text and the training prompt text, and the model is trained based on the training prompt text, even if the sample size is small, a text extraction model that can accurately extract text can be trained. In a small sample scenario, text can also be effectively extracted.
[0191] Embodiments of the present application also provide corresponding devices and computer storage media for implementing the schemes provided by the embodiments of the present application.
[0192] The device includes a memory and a processor, the memory is used to store instructions or codes, and the processor is used to execute the instructions or codes to make the device execute the text extraction method described in any embodiment of the present application.
[0193] The computer storage medium stores codes, and when the codes are run, the device running the codes implements the text extraction method described in any embodiment of the present application.
[0194] The "first" and "second" in the names such as "first" and "second" (if any) mentioned in the embodiments of this application are only used as name identifiers and do not represent the first or second in order.
[0195] Through the description of the above embodiments, it can be known that those skilled in the art can clearly understand that all or part of the steps in the above embodiment methods can be implemented by means of software plus a general hardware platform. Based on this understanding, the technical solution of the present application can be embodied in the form of a software product, which can be stored in a storage medium, such as a read-only memory (ROM) / RAM, a magnetic disk, an optical disk, etc., and includes a number of instructions for enabling a computer device (which can be a personal computer, a server, or a network communication device such as a router) to execute the methods described in each embodiment or certain parts of the embodiments of the present application.
[0196] Each embodiment in this specification is described in a progressive manner. The same or similar parts between the embodiments can be referred to each other. Each embodiment focuses on the differences from other embodiments. In particular, for the device embodiment, since it is basically similar to the method embodiment, the description is relatively simple. For the relevant parts, refer to the partial description of the method embodiment. Some or all of the modules can be selected according to actual needs to achieve the purpose of the embodiment. Those of ordinary skill in the art can understand and implement it without paying any creative work.
[0197] The above description is merely an exemplary embodiment of the present application and is not intended to limit the scope of protection of the present application.
Claims
1. A text extraction method, characterized in that: The method comprises: Acquire a text to be extracted and an extraction prompt text corresponding to the text to be extracted, wherein the extraction prompt text is a text indicating that an entity corresponding to a target impact factor in the text to be extracted should be extracted; splicing the text to be extracted and the extraction prompt text to obtain a first input text; Inputting the first input text into a text extraction model to obtain a first extracted text output by the text extraction model, wherein the text extraction model is trained based on sample text and training prompt text, the training prompt text corresponds to the sample text, and the training prompt text is a text indicating that an entity corresponding to a second influencing factor in the sample text should be extracted; The text extraction model is trained using the following method: Obtaining a sample text, the training prompt text, an influence factor prompt text, and a label of the sample text, wherein the training prompt text is a text indicating the extraction of an entity corresponding to a second influence factor in the sample text, the influence factor prompt text is a text indicating the extraction of a fourth influence factor in the sample text, and the label of the sample text includes a third label and a fourth label, wherein the third label is the text of the entity corresponding to the second influence factor, and the fourth label is the text of the entity corresponding to the fourth influence factor; Concatenate the sample text and the training prompt text to obtain a fifth input text; Inputting the fifth input text into the extraction model to be trained to obtain a fifth extracted text output by the extraction model to be trained; Calculating a fifth loss value based on the fifth extracted text and the third label; splicing the sample text with the impact factor prompt text to obtain a sixth input text; Inputting the sixth input text into the extraction model to be trained to obtain a sixth extracted text output by the extraction model to be trained; Calculating a sixth loss value based on the sixth extracted text and the fourth label; Calculate the fifth loss value and the sixth loss value according to the weight ratio to obtain a seventh loss value; The extraction model to be trained is adjusted according to the seventh loss value, and the steps of obtaining the sample text, the training prompt text, the influence factor prompt text and the label of the sample text, and subsequent steps are returned to execute until the preset conditions are met to generate a text extraction model.
2. The method according to claim 1, characterized in that The text extraction model is trained using the following method: Acquire a sample text, the training prompt text, and a label of the sample text, wherein the label of the sample text is a text of an entity corresponding to a first impact factor, and the training prompt text is a text indicating extraction of an entity corresponding to a second impact factor from the sample text; Concatenate the sample text and the training prompt text to obtain a second input text; Inputting the second input text into the extraction model to be trained to obtain a second extracted text output by the extraction model to be trained; Calculating a first loss value based on the second extracted text and the label; The extraction model to be trained is adjusted according to the first loss value, and the steps of obtaining the sample text, the training prompt text, and the label of the sample text and subsequent steps are returned to execute until the preset conditions are met to generate a text extraction model.
3. The method according to claim 1, characterized in that The text extraction model is trained using the following method: Obtaining a sample text, the training prompt text, the training misleading text, and a label of the sample text, wherein the training prompt text is a text indicating the extraction of an entity corresponding to a second influencing factor in the sample text, the training misleading text is a text indicating the extraction of an entity corresponding to a third influencing factor in the sample text, and the label of the sample text includes a first label and a second label, wherein the first label is the text of the entity corresponding to the second influencing factor, and the second label is the text of the entity corresponding to the third influencing factor; Concatenate the sample text and the training prompt text to obtain a third input text; Inputting the third input text into the extraction model to be trained to obtain a third extracted text output by the extraction model to be trained; Calculating a second loss value based on the third extracted text and the first label; splicing the sample text with the training misleading text to obtain a fourth input text; Inputting the fourth input text into the extraction model to be trained to obtain a fourth extracted text output by the extraction model to be trained; Calculating a third loss value based on the fourth extracted text and the second label; Calculate the second loss value and the third loss value according to the weight ratio to obtain a fourth loss value; The extraction model to be trained is adjusted according to the fourth loss value, and the steps of obtaining the sample text, the training prompt text, the training misleading text, and the label of the sample text, as well as subsequent steps, are returned to execute until a preset condition is met to generate a text extraction model.
4. A text extraction device, characterized in that: The device comprises: An acquisition module, configured to acquire a text to be extracted and an extraction prompt text corresponding to the text to be extracted, wherein the extraction prompt text is a text indicating that an entity corresponding to a target impact factor in the text to be extracted should be extracted; a splicing module, configured to splice the text to be extracted and the extraction prompt text to obtain a first input text; an extraction module, configured to input the first input text into a text extraction model to obtain a first extracted text output by the text extraction model, wherein the text extraction model is trained based on sample text and training prompt text, the training prompt text corresponding to the sample text, and the training prompt text is a text indicating extraction of an entity corresponding to a second influencing factor in the sample text; The text extraction model is trained using the following method: Obtaining a sample text, the training prompt text, an influence factor prompt text, and a label of the sample text, wherein the training prompt text is a text indicating the extraction of an entity corresponding to a second influence factor in the sample text, the influence factor prompt text is a text indicating the extraction of a fourth influence factor in the sample text, and the label of the sample text includes a third label and a fourth label, wherein the third label is the text of the entity corresponding to the second influence factor, and the fourth label is the text of the entity corresponding to the fourth influence factor; Concatenate the sample text and the training prompt text to obtain a fifth input text; Inputting the fifth input text into the extraction model to be trained to obtain a fifth extracted text output by the extraction model to be trained; Calculating a fifth loss value based on the fifth extracted text and the third label; splicing the sample text with the impact factor prompt text to obtain a sixth input text; Inputting the sixth input text into the extraction model to be trained to obtain a sixth extracted text output by the extraction model to be trained; Calculating a sixth loss value based on the sixth extracted text and the fourth label; Calculate the fifth loss value and the sixth loss value according to the weight ratio to obtain a seventh loss value; The extraction model to be trained is adjusted according to the seventh loss value, and the steps of obtaining the sample text, the training prompt text, the influence factor prompt text and the label of the sample text, and subsequent steps are returned to execute until the preset conditions are met to generate a text extraction model.
5. The device according to claim 4, characterized in that The text extraction model is trained using the following method: Acquire a sample text, the training prompt text, and a label of the sample text, wherein the label of the sample text is a text of an entity corresponding to a first impact factor, and the training prompt text is a text indicating extraction of an entity corresponding to a second impact factor from the sample text; Concatenate the sample text and the training prompt text to obtain a second input text; Inputting the second input text into the extraction model to be trained to obtain a second extracted text output by the extraction model to be trained; Calculating a first loss value based on the second extracted text and the label; The extraction model to be trained is adjusted according to the first loss value, and the steps of obtaining the sample text, the training prompt text, and the label of the sample text and subsequent steps are returned to execute until the preset conditions are met to generate a text extraction model.
6. The device according to claim 4, characterized in that The text extraction model is trained using the following method: Obtaining a sample text, the training prompt text, the training misleading text, and a label of the sample text, wherein the training prompt text is a text indicating the extraction of an entity corresponding to a second influencing factor in the sample text, the training misleading text is a text indicating the extraction of an entity corresponding to a third influencing factor in the sample text, and the label of the sample text includes a first label and a second label, wherein the first label is the text of the entity corresponding to the second influencing factor, and the second label is the text of the entity corresponding to the third influencing factor; Concatenate the sample text and the training prompt text to obtain a third input text; Inputting the third input text into the extraction model to be trained to obtain a third extracted text output by the extraction model to be trained; Calculating a second loss value based on the third extracted text and the first label; splicing the sample text with the training misleading text to obtain a fourth input text; Inputting the fourth input text into the extraction model to be trained to obtain a fourth extracted text output by the extraction model to be trained; Calculating a third loss value based on the fourth extracted text and the second label; Calculate the second loss value and the third loss value according to the weight ratio to obtain a fourth loss value; The extraction model to be trained is adjusted according to the fourth loss value, and the steps of obtaining the sample text, the training prompt text, the training misleading text, and the label of the sample text, as well as subsequent steps, are returned to execute until a preset condition is met to generate a text extraction model.
7. A computer 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 computer program, the method for text extraction according to any one of claims 1 to 3 is implemented.
8. A computer storage medium, characterized in that The computer-readable storage medium stores instructions, and when the instructions are executed on a terminal device, the terminal device executes the text extraction method according to any one of claims 1 to 3.
Citation Information
Patent Citations
Model training method and device, text prediction method and device, electronic equipment and medium
CN113901799A
Small sample multi-label text classification model training method and text classification method
CN114818891A