Text extraction method, device, electronic device and storage medium
By performing word segmentation processing and attention calculation on the text to be recognized, the extraction probability of word segmentation is generated, which solves the problem of low text extraction efficiency in the existing technology and realizes efficient text information extraction across fields and scenarios.
Patent Information
- Application Number
- CN202410579030.6
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2024-05-11
- Publication Date
- 2024-09-06
- Estimated Expiration
- 2044-05-11
AI Technical Summary
Existing text information extraction technology is inefficient for text extraction, especially in cross-domain or cross-scenario situations where language models need to be retrained, resulting in low efficiency.
By performing text segmentation processing on the text to be recognized, classification features and word segmentation features are generated, and attention calculations are performed to generate word segmentation extraction probabilities, and target text is generated based on preset thresholds to improve text extraction efficiency.
Different scores are generated through two attention calculation methods to determine the extraction probability of word segmentation, which improves the efficiency of text extraction and is suitable for text information extraction in multiple fields and scenarios.
Smart Images

Figure CN118171648B
Abstract
Description
Technical Field
[0001] The embodiments of the present application relate to the field of artificial intelligence, and in particular, to a text extraction method, device, electronic device and storage medium. Background Art
[0002] Text information extraction technology is a technical means to automatically obtain structured data from text materials. At the current technical level, text information extraction mainly adopts machine learning, deep learning and other methods to extract specific information for specific texts. At present, it is generally implemented through language models and rule constraints, but this method is generally limited to specific scenarios or specific fields. When it involves other scenarios or other fields, the language model needs to be retrained, which leads to the problem of low text extraction efficiency. Summary of the invention
[0003] The embodiments of the present application provide a text extraction method, device, electronic device and storage medium to solve the problem of low text extraction efficiency in the prior art.
[0004] To solve the above problems, this application is implemented as follows:
[0005] In a first aspect, an embodiment of the present application provides a text extraction method, the method comprising:
[0006] Perform text segmentation processing on the text to be recognized to obtain n segmentations, where n is greater than or equal to 2;
[0007] Classifying the n participles to obtain n classification features corresponding to the n participles one by one;
[0008] Performing attention calculation on the n classification features to obtain n first scores, and performing attention calculation on the n participles to obtain n second scores, wherein the n first scores correspond one-to-one to the n classification features, and the n second scores correspond one-to-one to the n participles;
[0009] Generating n calculated probabilities according to the n first scores and the n second scores, the calculated probabilities being probabilities that the n word segments are extracted from the text to be recognized;
[0010] A target text is generated according to all the target segmented words, wherein the target segmented words are the segmented words whose corresponding calculated probabilities exceed a preset threshold value among the n segmented words, and the target text is the text including all the target segmented words.
[0011] Optionally, performing text segmentation processing on the text to be recognized to obtain n segmented words includes:
[0012] Get word segmentation rules;
[0013] The text to be recognized is input into the target language model for text segmentation, and the n segmented words are output. The target language model is a model obtained by training a pre-trained language model according to the segmentation rule. The target language model is used to segment the input text according to the segmentation rule.
[0014] Optionally, performing attention calculation on the n classification features to obtain n first scores includes:
[0015] Performing attention calculation on the n classification features to obtain n third scores, where the n third scores correspond one-to-one to the n classification features;
[0016] Performing attention calculation on the n participles based on the target constraint word to obtain n fourth scores, wherein the n fourth scores correspond one-to-one to the n participles;
[0017] The n third scores and the n fourth scores are weightedly calculated according to preset first weight information to obtain the n first scores, wherein the first weight information includes n first weight parameters and n second weight parameters, the n first weight parameters correspond one-to-one to the n third scores, and the n second weight parameters correspond one-to-one to the n fourth scores.
[0018] Optionally, performing attention calculation on the n classification features to obtain n third scores includes:
[0019] Multiplying n first vectors with a trainable vector to determine n first features, wherein the n first vectors are obtained by converting the n classification features, the n first features correspond one-to-one to the classification features, the trainable vector is used to represent semantic features of the n classification features, and the trainable vector is determined based on the n classification features;
[0020] Attention calculation is performed on the n first features according to the target activation function to obtain the n third scores, wherein the attention calculation is used to respectively determine the degree of similarity between the n first features and the trainable vector.
[0021] Optionally, performing attention calculation on the n participles based on the target constraint word to obtain n fourth scores includes:
[0022] Generate n element pairs, each of which includes a participle and a label corresponding to the participle, wherein the label is used to indicate the sequence number of the corresponding participle;
[0023] The n element pairs are input into a target rectifier network model for attention calculation to obtain the n fourth scores, wherein the target rectifier network model is a model obtained by training a pre-trained rectifier network model according to a target constraint word, and the target rectifier network model is used to perform attention calculation on the input element pairs.
[0024] Optionally, performing attention calculation on the n participles to obtain n second scores includes:
[0025] Generate n feature vectors corresponding to the n word segments one by one;
[0026] Performing feature extraction on the n feature vectors according to a target extraction network to generate n second features, wherein the n second features correspond one-to-one to the n feature vectors;
[0027] Perform attention calculation on the n second features to obtain the n second scores.
[0028] Optionally, generating n calculated probabilities according to the n first scores and the n second scores includes:
[0029] Performing weighted calculation on the n first scores and the n second scores according to preset second weight information to obtain n fifth scores, wherein the second weight information includes n third weight parameters and n fourth weight parameters, the n third weight parameters correspond one-to-one to the n first scores, and the n fourth weight parameters correspond one-to-one to the n second scores;
[0030] Probability calculation is performed on the n fifth scores according to the parameter matrix and the bias matrix to obtain the n calculated probabilities.
[0031] In a second aspect, an embodiment of the present application further provides a text extraction device, the device comprising:
[0032] A processing module, used for performing text segmentation processing on the text to be recognized to obtain n segmented words, where n is greater than or equal to 2;
[0033] A classification module, used to classify the n participles to obtain n classification features corresponding to the n participles;
[0034] A calculation module, configured to perform attention calculation on the n classification features to obtain n first scores, and perform attention calculation on the n participles to obtain n second scores, wherein the n first scores correspond one-to-one to the n classification features, and the n second scores correspond one-to-one to the n participles;
[0035] A first generating module, configured to generate n calculated probabilities according to the n first scores and the n second scores, wherein the calculated probabilities are probabilities that the n word segments are extracted from the text to be recognized;
[0036] The second generation module is used to generate a target text according to all target segmentations, wherein the target segmentation is a segmentation among the n segmentations whose corresponding calculated probability exceeds a preset threshold, and the target text is a text including all the target segmentations.
[0037] In a third aspect, an embodiment of the present application further provides an electronic device, comprising: a transceiver, a memory, a processor, and a program stored in the memory and executable on the processor; the processor is used to read the program in the memory to implement the steps of the method described in the first aspect above.
[0038] In a fourth aspect, an embodiment of the present application further provides a readable storage medium for storing a program, which, when executed by a processor, implements the steps in the method described in the first aspect above.
[0039] In a fifth aspect, an embodiment of the present application further provides a computer program product, which is stored in a storage medium and is executed by at least one processor to implement the steps in the method described in the first aspect.
[0040] The present application provides a text extraction method, device, electronic device and storage medium, the method comprising: performing text segmentation processing on a text to be recognized to obtain n segmentations, wherein n is greater than or equal to 2; classifying the n segmentations to obtain n classification features corresponding one-to-one to the n segmentations; performing attention calculation on the n classification features to obtain n first scores, and performing attention calculation on the n segmentations to obtain n second scores, wherein the n first scores correspond one-to-one to the n classification features, and the n second scores correspond one-to-one to the n segmentations; generating n calculated probabilities according to the n first scores and the n second scores, wherein the calculated probabilities are the probabilities that the n segmentations are extracted from the text to be recognized; generating a target text according to all target segmentations, wherein the target segmentation is a segmentation among the n segmentations whose corresponding calculated probabilities exceed a preset threshold, and the target text is a text including all the target segmentations. This application performs word segmentation on the text to be recognized, generates different scores through two attention calculation methods, and determines the word segmentation extraction probability through the two scores, thereby completing the extraction of the text to be recognized and improving the efficiency of text extraction. BRIEF DESCRIPTION OF THE DRAWINGS
[0041] In order to more clearly illustrate the technical solutions of the embodiments of the present application, the drawings required for use in the description of the embodiments of the present application will be briefly introduced below. 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 paying any creative labor.
[0042] Figure 1 It is a flowchart of the text extraction method provided in the embodiment of the present application;
[0043] Figure 2 is a schematic diagram of a text information extraction model provided in an embodiment of the present application;
[0044] Figure 3 is a structural schematic diagram of a text extraction device provided in an embodiment of the present application;
[0045] Figure 4 It is a schematic diagram of the structure of an electronic device provided in an embodiment of the present application. DETAILED DESCRIPTION
[0046] The following will be combined with the drawings in the embodiments of the present application to clearly and completely describe the technical solutions in the embodiments of the present application. Obviously, the described embodiments are part of the embodiments of the present application, not all of the embodiments. Based on the embodiments in the present application, all other embodiments obtained by ordinary technicians in this field without creative work are within the scope of protection of this application.
[0047] The terms "first", "second" etc. in the embodiments of the present application are used to distinguish similar objects, and need not be used to describe a specific order or sequential order. In addition, the terms "include" and "have" and any variation thereof are intended to cover non-exclusive inclusions, for example, the process, method, system, product or equipment comprising a series of steps or units need not be limited to those steps or units clearly listed, but may include other steps or units that are not clearly listed or inherent to these processes, methods, products or equipment. In addition, "and / or" is used in the present application to represent at least one of connected objects, such as A and / or B and / or C, representing the inclusion of separate A, separate B, separate C, and A and B all exist, B and C all exist, A and C all exist, and 7 situations that A, B and C all exist.
[0048] See also Figure 1 , Figure 1 Schematic diagram of the text extraction method provided in the embodiment of the present application. Figure 1 As shown, the text extraction method may include the following steps:
[0049] Step 101: perform text segmentation processing on the text to be recognized to obtain n segmented words, where n is greater than or equal to 2.
[0050] In this embodiment, the text to be recognized may be a certain text content, which may include one or more sentences. It should be noted that the word segmentation process is used to split multiple words in the text to be recognized to obtain n word segments. For example, the text to be recognized may be divided according to parts of speech such as verbs, names, and adjectives.
[0051] It should be noted that after the word segmentation processing is performed on the text to be recognized, the number of word segments obtained is greater than or equal to two, wherein the word segments may be the same word segmentation or different word segmentations.
[0052] Step 102: classify the n participles to obtain n classification features corresponding to the n participles.
[0053] In this embodiment, the classification of the n participles is specifically to generate the superordinate concepts corresponding to the n participles, thereby generating classification features corresponding to the n participles one by one, wherein the classification features can be determined by part-of-speech analysis. For example, through part-of-speech analysis, conjunctions, prepositions, and verbs with linking and transitional meanings in the sentence can be found, and these words are regarded as constraint words. The present application believes that constraint words can play a certain constraint role, such as the candidate ontology element containing the constraint word "if", and its superordinate concept type is probably conditional.
[0054] Step 103: Perform attention calculation on the n classification features to obtain n first scores, and perform attention calculation on the n participles to obtain n second scores, wherein the n first scores correspond one-to-one to the n classification features, and the n second scores correspond one-to-one to the n participles.
[0055] In this embodiment, by performing two attention calculations respectively, n different first scores and n second scores are generated, wherein the n first scores correspond one-to-one to the n classification features, and the n second scores correspond one-to-one to the n participles.
[0056] Among them, attention calculation is a technique that allows the model to focus on specific parts of the input data to improve performance. This mechanism is inspired by human attention, where humans focus on certain parts and ignore other less important information when processing information. Specifically, the attention mechanism solves this problem by assigning a variable weight vector to each output step, which indicates which parts of the input sequence should be paid more attention to when generating the current output. In the example of machine translation, when the model is trying to translate a specific word, the attention mechanism can enable the model to focus on the part of the input sentence that is most relevant to that word.
[0057] For the n first scores, attention calculation is performed through n classification features to obtain multiple corresponding first scores, wherein when calculating the first score, it is calculated through n classification features, and when calculating the n second scores, it is calculated through n participles. Therefore, the objects calculated by the two are different. Generally, in the prior art, only n participles are used for calculation. In this application, it is taken into consideration that semantic hierarchical features are introduced, so that the model can not only learn the ontological concepts of text elements, but also learn the conceptual connections between text elements, improve the learning of contextual content, and thus improve the text information extraction performance.
[0058] Step 104: Generate n calculated probabilities according to the n first scores and the n second scores, where the calculated probabilities are probabilities that the n word segments are extracted from the text to be recognized.
[0059] In this embodiment, n calculation probabilities are generated by comprehensive calculation of n first scores and n second scores, wherein the n first scores and the n second scores can be determined by weight calculation. Specifically, different weight values can be assigned to the n first scores and the n second scores, respectively, so as to calculate and determine the calculation probability. Through the calculation probability, it can be accurately determined whether the n word segments can be extracted in the text to be recognized.
[0060] Step 105: Generate a target text based on all the target segmented words, wherein the target segmented words are the segmented words whose corresponding calculated probabilities exceed a preset threshold value among the n segmented words, and the target text is a text including all the target segmented words.
[0061] In this embodiment, a target text is generated by combining target segmentation words, wherein the target text refers to a target text generated by combining multiple target segmentation words, that is, the target text is the text obtained after the text to be recognized is extracted, wherein the target text is composed of at least one target segmentation word.
[0062] It should be noted that the target word segmentation is a word segmentation whose calculated probability exceeds a preset threshold, wherein the preset probability can be adaptively adjusted according to actual conditions and is not specifically limited in this embodiment.
[0063] The present application provides a text extraction method, which includes: performing text segmentation processing on a text to be recognized to obtain n segmentations, where n is greater than or equal to 2; classifying the n segmentations to obtain n classification features corresponding one-to-one to the n segmentations; performing attention calculation on the n classification features to obtain n first scores, and performing attention calculation on the n segmentations to obtain n second scores, where the n first scores correspond one-to-one to the n classification features, and the n second scores correspond one-to-one to the n segmentations; generating n calculated probabilities according to the n first scores and the n second scores, where the calculated probabilities are probabilities that the n segmentations are extracted from the text to be recognized; generating a target text according to all target segmentations, where the target segmentation is a segmentation among the n segmentations whose corresponding calculated probabilities exceed a preset threshold, and the target text is a text including all the target segmentations. This application performs word segmentation on the text to be recognized, generates different scores through two attention calculation methods, and determines the word segmentation extraction probability through the two scores, thereby completing the extraction of the text to be recognized and improving the efficiency of text extraction.
[0064] In some feasible implementations, optionally, performing text segmentation processing on the text to be recognized to obtain n segmented words includes:
[0065] Get word segmentation rules;
[0066] The text to be recognized is input into the target language model for text segmentation, and the n segmented words are output. The target language model is a model obtained by training a pre-trained language model according to the segmentation rule. The target language model is used to segment the input text according to the segmentation rule.
[0067] In this embodiment, if Figure 2 As shown, Figure 2 This is a schematic diagram of a text information extraction model for processing the text to be recognized in this embodiment. Figure 2 The text information extraction model shown can perform text extraction on the text to be recognized as a whole.
[0068] In this embodiment, text elements at the short text level with a relatively long length are not directly divided in general texts, and it is difficult for common text element extraction methods to obtain candidate text elements from unstructured texts.
[0069] To this end, the text to be recognized is first segmented, and stop words are removed using a custom stop word list. Unlike the common Chinese stop word list, conjunctions and prepositions are not included in the custom stop word list of this application. Among them, the division can be performed through the grammatical element segmentation rule table, as shown in Table 1:
[0070] Table 1
[0071] rule Rules Content Priority R1 Parts of speech in a sentence, such as nouns, verbs, etc. 1 R2 Punctuation marks and conjunctions in a sentence will be split. 2 R3 Some sentence patterns in sentences include "when..." and "in..." 3
[0072] Then, the segmented results can be passed through the target mainstream pre-trained language model, such as ERNIE, where ERNIE is a natural language processing pre-training model proposed by Baidu. The full name is "Enhanced Representation through kNowledge Integration", which means "enhanced representation through knowledge integration". ERNIE aims to improve the understanding and representation capabilities of the language model by more effectively integrating language knowledge and world knowledge. The ERNIE model has demonstrated excellent performance in many NLP tasks, including text classification, sentiment analysis, named entity recognition, question and answer, etc. Perform named entity recognition and part-of-speech analysis tasks, and record the corresponding labels. Based on the above results, the technical problem sentence is divided into multiple short sentence-level text elements according to the candidate text element segmentation rules shown in Table 1.
[0073] Finally, the text is represented as a sequence of n short sentences , where each s represents a short sentence level text element, which may also be entity level.
[0074] Encode the text elements into the hidden embedding, specifically, as follows:
[0075]
[0076] Here, E(·) is a neural network that encodes the sentence, using ERNIE as the encoder.
[0077] Optionally, performing attention calculation on the n classification features to obtain n first scores includes:
[0078] Performing attention calculation on the n classification features to obtain n third scores, where the n third scores correspond one-to-one to the n classification features;
[0079] Performing attention calculation on the n participles based on the target constraint word to obtain n fourth scores, wherein the n fourth scores correspond one-to-one to the n participles;
[0080] The n third scores and the n fourth scores are weightedly calculated according to preset first weight information to obtain the n first scores, wherein the first weight information includes n first weight parameters and n second weight parameters, the n first weight parameters correspond one-to-one to the n third scores, and the n second weight parameters correspond one-to-one to the n fourth scores.
[0081] In this embodiment, the n first scores are obtained by weighted calculation of the n third scores and the n fourth scores. Specifically, attention calculation is performed on the n classification features respectively to obtain the n third scores, and attention calculation is performed on the n segmented words based on the target constraint words to obtain the n fourth scores. Then, the n third scores and the n fourth scores are weightedly calculated by the obtained first weight information to generate the n first scores, wherein the first weight information includes n first weight parameters and n second weight parameters, the n first weight parameters correspond one-to-one to the n third scores, and the n second weight parameters correspond one-to-one to the n fourth scores.
[0082] For hidden layer embedding , the superordinate concept module gives an attention score to the hidden layer embedding to express the relevance of this embedding vector to the corresponding superordinate concept. At the same time, the constraint words in the learning sentence are used to obtain the superordinate concept scores of the candidate text elements before and after the constraint words. Figure 2 As shown, the present application sets up a joint module to combine the attention scores from different upper-level concept modules.
[0083] Optionally, performing attention calculation on the n classification features to obtain n third scores includes:
[0084] Multiplying n first vectors with a trainable vector to determine n first features, wherein the n first vectors are obtained by converting the n classification features, the n first features correspond one-to-one to the classification features, the trainable vector is used to represent semantic features of the n classification features, and the trainable vector is determined based on the n classification features;
[0085] Attention calculation is performed on the n first features according to the target activation function to obtain the n third scores, wherein the attention calculation is used to respectively determine the degree of similarity between the n first features and the trainable vector.
[0086] In this embodiment, attention calculation is performed on the n classification features to obtain n third scores. Specifically, since multiple text elements share the same high-level concept, the present application hopes to utilize the association of text elements through the upper-level concept to help better extract specific text elements. c To represent the semantic features of the superordinate concept c in the superordinate concept module. A multi-layer perceptron is used to calculate the attention score. The hidden state is calculated first. A softmax function, i.e. the target activation function, is used to get the attention score of the hidden embedding hi. Among them, W a and W bIt is a trainable matrix shared between different classification modules.
[0087] Optionally, performing attention calculation on the n participles based on the target constraint word to obtain n fourth scores includes:
[0088] Generate n element pairs, each of which includes a participle and a label corresponding to the participle, wherein the label is used to indicate the sequence number of the corresponding participle;
[0089] The n element pairs are input into a target rectifier network model for attention calculation to obtain the n fourth scores, wherein the target rectifier network model is a model obtained by training a pre-trained rectifier network model according to a target constraint word, and the target rectifier network model is used to perform attention calculation on the input element pairs.
[0090] In this embodiment, in the constraint learning part, through part-of-speech analysis, conjunctions, prepositions, and verbs with linking and transitional meanings in the sentence can be found, and these words are regarded as target constraint words. This application believes that the target constraint words can play a certain constraint role, such as the candidate ontology element containing the constraint word "if", and its superordinate concept type is likely to be conditional.
[0091] Set the ontology element pairs before and after the constraint word , and then create a binary label t for its structural legitimacy. Then the constraints on a given ontology feature label pair (X, t) are expressed as K linear inequalities. Formally, if Satisfy constraints All variables , then the kth constraint It can be expressed as a linear inequality: Weight and deviation is also a trainable parameter. Since Pan et al. proved that a system of linear inequalities is equivalent to a rectifier network, a two-layer rectifier network is used to learn the constraints: in is the attention score of the conditional type of the text element. This application uses supervised learning to train the parameters w of the rectifier network k and b k , training needs to be completed in advance, and the positive samples are the constraint words and corresponding results that appear in the labeled data.
[0092] In the joint module, for the hidden embedding hi of the candidate text element, its parent concepts c1, c2, ..., c k , the attention score obtained through the upper-level concept module is expressed as ; The attention score obtained from the constraint learning module is expressed as All information about the superordinate concept should be retained in the embedding of the superordinate concept type, so the weights of the two modules are adjusted by the above formula. Superordinate concept attention score: in, It is a hyperparameter for adjusting the weights of the superordinate concept module and the constraint learning module.
[0093] Then the weighted sum of the hidden embeddings is calculated as the embedding e for the superordinate concept type s :
[0094] Optionally, performing attention calculation on the n participles to obtain n second scores includes:
[0095] Generate n feature vectors corresponding to the n word segments one by one;
[0096] Performing feature extraction on the n feature vectors according to a target extraction network to generate n second features, wherein the n second features correspond one-to-one to the n feature vectors;
[0097] Perform attention calculation on the n second features to obtain the n second scores.
[0098] In this embodiment, the ontology concept module performs attention calculation on n word segments to generate corresponding n second scores. Specifically, the ontology concept module recognizes the candidate text elements themselves. , as the input of the Bidirectional Gated Recurrent Unit Network (BiGRU). BiGRU is composed of two GRUs in different directions. The specific calculation formula of BiGRU is shown in the following formula: The BiGRU neural network can be used to extract the position features of elements in the text. is the hidden state propagated forward at time t; is the hidden state propagated backward at time t; the final concatenation obtains the hidden state containing bidirectional semantic information .
[0099] Obtaining ontology concept type embedding through an attention mechanism : in, is the mapping layer parameter matrix, is the bias matrix.
[0100] Optionally, generating n calculated probabilities according to the n first scores and the n second scores includes:
[0101] Performing weighted calculation on the n first scores and the n second scores according to preset second weight information to obtain n fifth scores, wherein the second weight information includes n third weight parameters and n fourth weight parameters, the n third weight parameters correspond one-to-one to the n first scores, and the n fourth weight parameters correspond one-to-one to the n second scores;
[0102] Probability calculation is performed on the n fifth scores according to the parameter matrix and the bias matrix to obtain the n calculated probabilities.
[0103] In this embodiment, the embedding of the upper-level concept type is transformed into and Ontology-Oriented Concept Type Embedding Connected together, x is the initial embedding of the candidate text element, which serves as the input feature of the text element classifier. The candidate text element belongs to a certain text element type The probability P is shown in the following formula. in, is the parameter matrix, is the bias matrix.
[0104] The objective function of the model in this application is as follows: in, are all the parameters of the model, and Adam is used to minimize .
[0105] It should be noted that the present application has been applied to cloud space through a text information extraction method based on deep learning and semantic hierarchy. As an office collaboration software, cloud space contains a large amount of text information to be processed. The present application uses a text information extraction method to process the deposited information in the software, speed up the flow of information, and improve office efficiency.
[0106] Specifically, text information extraction is a basic capability of natural language processing, and is widely used in recommendations, question-answering, and intelligent messaging robots. As an OA product, the cloud space product will add intelligent office functions in 2024, such as various chatbots. Intelligent robots require certain text corpora as a basis for reply. This application mainly solves the automatic generation of text corpora of chatbots. At the same time, with the development of intelligence, it may also directly provide text information extraction functions for users in the future.
[0107] Directly extract text information from the pre-trained model ERNIE, use the pre-trained model ERNIE as an embedding, add BiGRU and attention mechanism to extract text information, and use the pre-trained model ERNIE as an embedding, and add this solution method to extract text information. In the three-way comparison experiment, this application achieved a 0.93% increase in F1 value. Cloud space currently lacks intelligent capabilities. This application adds the ability to extract product text information to help products become more intelligent.
[0108] This application performs word segmentation on the text to be recognized, generates different scores through two attention calculation methods, and determines the word segmentation extraction probability through the two scores, thereby completing the extraction of the text to be recognized and improving the efficiency of text extraction.
[0109] See also Figure 3 , Figure 3 is a structural diagram of a text extraction device provided in an embodiment of the present application. Figure 3 As shown, the text extraction device 300 includes:
[0110] The processing module 310 is used to perform text segmentation processing on the text to be recognized to obtain n segmented words, where n is greater than or equal to 2;
[0111] A classification module 320, configured to classify the n participles to obtain n classification features corresponding to the n participles;
[0112] A calculation module 330 is used to perform attention calculation on the n classification features to obtain n first scores, and to perform attention calculation on the n participles to obtain n second scores, wherein the n first scores correspond to the n classification features one-to-one, and the n second scores correspond to the n participles one-to-one;
[0113] A first generating module 340, configured to generate n calculated probabilities according to the n first scores and the n second scores, wherein the calculated probabilities are probabilities that the n word segments are extracted from the text to be recognized;
[0114] The second generating module 350 is used to generate a target text according to all target segmented words, wherein the target segmented words are the segmented words whose corresponding calculated probabilities among the n segmented words exceed a preset threshold, and the target text is a text including all the target segmented words.
[0115] Optionally, the processing module 310 includes:
[0116] Get submodule, used to get word segmentation rules;
[0117] The word segmentation submodule is used to input the text to be recognized into the target language model for text segmentation and output the n word segments. The target language model is a model obtained by training a pre-trained language model according to the word segmentation rules. The target language model is used to segment the input text according to the word segmentation rules.
[0118] Optionally, the calculation module 330 includes:
[0119] A first calculation submodule, configured to perform attention calculation on the n classification features to obtain n third scores, wherein the n third scores correspond one-to-one to the n classification features;
[0120] A second calculation submodule is used to perform attention calculation on the n participles based on the target constraint word to obtain n fourth scores, where the n fourth scores correspond to the n participles one by one;
[0121] A third calculation submodule is used to perform weighted calculation on the n third scores and the n fourth scores according to preset first weight information to obtain the n first scores, wherein the first weight information includes n first weight parameters and n second weight parameters, the n first weight parameters correspond one-to-one to the n third scores, and the n second weight parameters correspond one-to-one to the n fourth scores.
[0122] Optionally, the first computing submodule includes:
[0123] a determination unit, configured to multiply n first vectors by a trainable vector to determine n first features, wherein the n first vectors are obtained by converting the n classification features, the n first features correspond one-to-one to the classification features, the trainable vector is used to represent semantic features of the n classification features, and the trainable vector is determined based on the n classification features;
[0124] The first computing unit is used to perform attention calculation on the n first features according to the target activation function to obtain the n third scores, wherein the attention calculation is used to respectively determine the similarity between the n first features and the trainable vectors.
[0125] Optionally, the second computing submodule includes:
[0126] A generating unit, used to generate n element pairs, each of which includes a participle and a label corresponding to the participle, wherein the label is used to indicate the sequence number of the corresponding participle;
[0127] The second computing unit is used to input the n element pairs into a target rectifier network model for attention calculation to obtain the n fourth scores, wherein the target rectifier network model is a model obtained by training a pre-trained rectifier network model according to a target constraint word, and the target rectifier network model is used to perform attention calculation on the input element pairs.
[0128] Optionally, the calculation module 330 further includes:
[0129] A generating submodule, used for generating n feature vectors corresponding to the n word segments one by one;
[0130] An extraction submodule, used for performing feature extraction on the n feature vectors according to a target extraction network to generate n second features, wherein the n second features correspond one-to-one to the n feature vectors;
[0131] The fourth calculation submodule is used to perform attention calculation on the n second features to obtain the n second scores.
[0132] Optionally, the first generating module 340 includes:
[0133] a fifth calculation submodule, configured to perform weighted calculation on the n first scores and the n second scores according to preset second weight information to obtain n fifth scores, wherein the second weight information includes n third weight parameters and n fourth weight parameters, the n third weight parameters correspond one-to-one to the n first scores, and the n fourth weight parameters correspond one-to-one to the n second scores;
[0134] The sixth calculation submodule is used to perform probability calculation on the n fifth scores according to the parameter matrix and the bias matrix to obtain the n calculated probabilities.
[0135] This application performs word segmentation on the text to be recognized, generates different scores through two attention calculation methods, and determines the word segmentation extraction probability through the two scores, thereby completing the extraction of the text to be recognized and improving the efficiency of text extraction.
[0136] The present application also provides an electronic device. Figure 4 , the electronic device may include a processor 401, a memory 402, and a program 4021 stored in the memory 402 and executable on the processor 401.
[0137] When the program 4021 is executed by the processor 401, it can achieve Figure 1 Any step in the corresponding method embodiment:
[0138] Perform text segmentation processing on the text to be recognized to obtain n segmentations, where n is greater than or equal to 2;
[0139] Classifying the n participles to obtain n classification features corresponding to the n participles one by one;
[0140] Performing attention calculation on the n classification features to obtain n first scores, and performing attention calculation on the n participles to obtain n second scores, wherein the n first scores correspond one-to-one to the n classification features, and the n second scores correspond one-to-one to the n participles;
[0141] Generating n calculated probabilities according to the n first scores and the n second scores, the calculated probabilities being probabilities that the n word segments are extracted from the text to be recognized;
[0142] A target text is generated according to all the target segmented words, wherein the target segmented words are the segmented words whose corresponding calculated probabilities exceed a preset threshold value among the n segmented words, and the target text is the text including all the target segmented words.
[0143] Optionally, performing text segmentation processing on the text to be recognized to obtain n segmented words includes:
[0144] Get word segmentation rules;
[0145] The text to be recognized is input into the target language model for text segmentation, and the n segmented words are output. The target language model is a model obtained by training a pre-trained language model according to the segmentation rule. The target language model is used to segment the input text according to the segmentation rule.
[0146] Optionally, performing attention calculation on the n classification features to obtain n first scores includes:
[0147] Performing attention calculation on the n classification features to obtain n third scores, where the n third scores correspond one-to-one to the n classification features;
[0148] Performing attention calculation on the n participles based on the target constraint word to obtain n fourth scores, wherein the n fourth scores correspond one-to-one to the n participles;
[0149] The n third scores and the n fourth scores are weightedly calculated according to preset first weight information to obtain the n first scores, wherein the first weight information includes n first weight parameters and n second weight parameters, the n first weight parameters correspond one-to-one to the n third scores, and the n second weight parameters correspond one-to-one to the n fourth scores.
[0150] Optionally, performing attention calculation on the n classification features to obtain n third scores includes:
[0151] Multiplying n first vectors with a trainable vector to determine n first features, wherein the n first vectors are obtained by converting the n classification features, the n first features correspond one-to-one to the classification features, the trainable vector is used to represent semantic features of the n classification features, and the trainable vector is determined based on the n classification features;
[0152] Attention calculation is performed on the n first features according to the target activation function to obtain the n third scores, wherein the attention calculation is used to respectively determine the degree of similarity between the n first features and the trainable vector.
[0153] Optionally, performing attention calculation on the n participles based on the target constraint word to obtain n fourth scores includes:
[0154] Generate n element pairs, each of which includes a participle and a label corresponding to the participle, wherein the label is used to indicate the sequence number of the corresponding participle;
[0155] The n element pairs are input into a target rectifier network model for attention calculation to obtain the n fourth scores, wherein the target rectifier network model is a model obtained by training a pre-trained rectifier network model according to a target constraint word, and the target rectifier network model is used to perform attention calculation on the input element pairs.
[0156] Optionally, performing attention calculation on the n participles to obtain n second scores includes:
[0157] Generate n feature vectors corresponding to the n word segments one by one;
[0158] Performing feature extraction on the n feature vectors according to a target extraction network to generate n second features, wherein the n second features correspond one-to-one to the n feature vectors;
[0159] Perform attention calculation on the n second features to obtain the n second scores.
[0160] Optionally, generating n calculated probabilities according to the n first scores and the n second scores includes:
[0161] Performing weighted calculation on the n first scores and the n second scores according to preset second weight information to obtain n fifth scores, wherein the second weight information includes n third weight parameters and n fourth weight parameters, the n third weight parameters correspond one-to-one to the n first scores, and the n fourth weight parameters correspond one-to-one to the n second scores;
[0162] Probability calculation is performed on the n fifth scores according to the parameter matrix and the bias matrix to obtain the n calculated probabilities.
[0163] This application performs word segmentation on the text to be recognized, generates different scores through two attention calculation methods, and determines the word segmentation extraction probability through the two scores, thereby completing the extraction of the text to be recognized and improving the efficiency of text extraction.
[0164] The embodiment of the present application also provides a computer-readable storage medium, on which a computer program is stored. When the computer program is executed by a processor, each process of the above-mentioned text extraction method embodiment is implemented, and the same technical effect can be achieved. To avoid repetition, it is not repeated here. The computer-readable storage medium is, for example, a read-only memory (ROM), a random access memory (RAM), a magnetic disk or an optical disk.
[0165] The embodiment of the present application further provides a computer program product, which is stored in a storage medium. The computer program product is executed by at least one processor to implement the various processes of the above-mentioned text extraction method embodiment and can achieve the same technical effect. To avoid repetition, it will not be repeated here.
[0166] It should be noted that, in this article, the terms "include", "comprises" or any other variations thereof are intended to cover non-exclusive inclusion, so that a process, method, article or device including a series of elements includes not only those elements, but also other elements not explicitly listed, or also includes elements inherent to such process, method, article or device. In the absence of further restrictions, an element defined by the sentence "comprises a ..." does not exclude the existence of other identical elements in the process, method, article or device including the element.
[0167] Through the description of the above implementation methods, those skilled in the art can clearly understand that the above-mentioned embodiment methods can be implemented by means of software plus a necessary general hardware platform, and of course by hardware, but in many cases the former is a better implementation method. Based on such an understanding, the technical solution of the present application, or the part that contributes to the prior art, can be embodied in the form of a software product, which is stored in a storage medium (such as ROM / RAM, a magnetic disk, or an optical disk), and includes a number of instructions for a terminal (which can be a mobile phone, a computer, a server, an air conditioner, or a network device, etc.) to execute the methods described in each embodiment of the present application.
[0168] The embodiments of the present application are described above in conjunction with the accompanying drawings, but the present application is not limited to the above-mentioned specific implementation methods. The above-mentioned specific implementation methods are merely illustrative and not restrictive. Under the guidance of the present application, ordinary technicians in this field can also make many forms without departing from the purpose of the present application and the scope of protection of the claims, all of which are within the protection of the present application.
Claims
1. A text extraction method, It is characterized in that The method comprises: Perform text segmentation processing on the text to be recognized to obtain n segmentations, where n is greater than or equal to 2; Classifying the n participles to obtain n classification features corresponding to the n participles one by one; Attention calculation is performed on the n classification features to obtain n first scores, and attention calculation is performed on the n participles to obtain n second scores, the n first scores correspond to the n classification features one-to-one, and the n second scores correspond to the n participles one-to-one. The attention calculation is performed on the n classification features to obtain n first scores, including: performing attention calculation on the n classification features to obtain n third scores, the n third scores correspond to the n classification features one-to-one; performing attention calculation on the n participles based on the target constraint word The method comprises: performing attention calculation on the n classification features to obtain n fourth scores, wherein the n fourth scores correspond to the n participles one by one; performing weighted calculation on the n third scores and the n fourth scores according to preset first weight information to obtain the n first scores, wherein the first weight information includes n first weight parameters and n second weight parameters, wherein the n first weight parameters correspond to the n third scores one by one, and the n second weight parameters correspond to the n fourth scores one by one; performing attention calculation on the n classification features to obtain n third scores, comprising: adding the n first scores to the weighted scores; A vector is multiplied by a trainable vector to determine n first features, wherein the n first vectors are obtained by converting the n classification features, the n first features correspond to the classification features one by one, the trainable vector is used to represent the semantic features of the n classification features, and the trainable vector is determined based on the n classification features; attention calculation is performed on the n first features according to a target activation function to obtain the n third scores, and the attention calculation is used to respectively determine the similarity between the n first features and the trainable vector; the attention calculation is performed on the n word segments based on the target constraint word to obtain n fourth scores, including: generating n element pairs, each of the element pairs includes a word segment and a label corresponding to the word segment, and the label is used to indicate the sequence number of the corresponding word segment; the n element pairs are input into a target rectifier network model for attention calculation to obtain the n fourth scores, the target rectifier network model is a model obtained by training a pre-trained rectifier network model according to the target constraint word, and the target rectifier network model is used to perform attention calculation on the input element pairs; Generating n calculated probabilities according to the n first scores and the n second scores, the calculated probabilities being probabilities that the n word segments are extracted from the text to be recognized; A target text is generated according to all the target segmented words, wherein the target segmented words are the segmented words whose corresponding calculated probabilities among the n segmented words exceed a preset threshold, and the target text is a text including all the target segmented words.
2. The method according to claim 1, It is characterized in that The text to be recognized is subjected to text segmentation processing to obtain n segmented words, including: Get word segmentation rules; The text to be recognized is input into the target language model for text segmentation, and the n segmented words are output. The target language model is a model obtained by training a pre-trained language model according to the segmentation rule. The target language model is used to segment the input text according to the segmentation rule.
3. The method according to claim 1, It is characterized in that The performing attention calculation on the n participles to obtain n second scores includes: Generate n feature vectors corresponding to the n word segments one by one; Performing feature extraction on the n feature vectors according to a target extraction network to generate n second features, wherein the n second features correspond one-to-one to the n feature vectors; Perform attention calculation on the n second features to obtain the n second scores.
4. The method according to claim 1, It is characterized in that The generating n calculated probabilities according to the n first scores and the n second scores comprises: Performing weighted calculation on the n first scores and the n second scores according to preset second weight information to obtain n fifth scores, wherein the second weight information includes n third weight parameters and n fourth weight parameters, the n third weight parameters correspond one-to-one to the n first scores, and the n fourth weight parameters correspond one-to-one to the n second scores; Probability calculation is performed on the n fifth scores according to the parameter matrix and the bias matrix to obtain the n calculated probabilities.
5. A text extraction device, It is characterized in that The device comprises: A processing module, used for performing text segmentation processing on the text to be recognized to obtain n segmented words, where n is greater than or equal to 2; A classification module, used to classify the n participles to obtain n classification features corresponding to the n participles; a calculation module, configured to perform attention calculation on the n classification features to obtain n first scores, and to perform attention calculation on the n participles to obtain n second scores, wherein the n first scores correspond to the n classification features in a one-to-one manner, and the n second scores correspond to the n participles in a one-to-one manner, and the calculation module comprises: a first calculation submodule, configured to perform attention calculation on the n classification features to obtain n third scores, wherein the n third scores correspond to the n classification features in a one-to-one manner; and a second calculation submodule, configured to perform attention calculation on the n participles based on the target constraint words. The first computing submodule is configured to perform attention calculation on the n third scores and the n fourth scores according to preset first weight information to obtain the n first scores, wherein the first weight information includes n first weight parameters and n second weight parameters, wherein the n first weight parameters correspond to the n third scores in a one-to-one manner, and the n second weight parameters correspond to the n fourth scores in a one-to-one manner; the first computing submodule includes: a determining unit, configured to calculate the n third scores and the n fourth scores in a one-to-one manner. The first vector is multiplied by the trainable vector to determine n first features, wherein the n first vectors are obtained by converting the n classification features, the n first features correspond to the classification features one by one, the trainable vector is used to represent the semantic features of the n classification features, and the trainable vector is determined based on the n classification features; a first calculation unit is used to perform attention calculation on the n first features according to the target activation function to obtain the n third scores, and the attention calculation is used to respectively determine the similarity between the n first features and the trainable vector; the second calculation submodule includes: a generation unit, which is used to generate n element pairs, each of which includes a segmentation and a label corresponding to the segmentation, and the label is used to indicate the sequence number of the corresponding segmentation; a second calculation unit is used to input the n element pairs into a target rectifier network model for attention calculation to obtain the n fourth scores, the target rectifier network model is a model obtained by training a pre-trained rectifier network model according to a target constraint word pair, and the target rectifier network model is used to perform attention calculation on the input element pairs; A first generating module, configured to generate n calculated probabilities according to the n first scores and the n second scores, wherein the calculated probabilities are probabilities that the n word segments are extracted from the text to be recognized; The second generation module is used to generate a target text according to all target segmentations, wherein the target segmentation is a segmentation among the n segmentations whose corresponding calculated probability exceeds a preset threshold, and the target text is a text including all the target segmentations.
6. An electronic device, include: A memory, a processor, and a program stored in the memory and executable on the processor; wherein the processor is used to read the program in the memory to implement the steps in the text extraction method as described in any one of claims 1 to 4.
7. A readable storage medium for storing a program, It is characterized in that When the program is executed by a processor, the steps in the text extraction method according to any one of claims 1 to 4 are implemented.
8. A computer program product, It is characterized in that The computer program product is stored in a storage medium, and the computer program product is executed by at least one processor to implement the steps in the text extraction method according to any one of claims 1 to 4.
Citation Information
Cited By
Electromagnetic spectrum game situation extraction method based on large language model
CN119990107A
