Text extraction method, device, computer equipment and storage medium
Through the preset extraction model, the drug instructions are encoded and feature extraction are identified to identify drug indications, which solves the problem of low recognition ability in the existing technology, realizes the identification of indications that do not appear in the dictionary library, and improves drug adaptation and recall.
Patent Information
- Application Number
- CN202111015728.8
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2021-08-31
- Publication Date
- 2025-01-17
- Estimated Expiration
- 2041-08-31
AI Technical Summary
In the identification of drug indications, the prior art has poor generalization ability and cannot identify indications that do not appear in the dictionary library, resulting in low recognition ability.
Use a preset extraction model for text encoding, and obtain target encoding vectors, network vectors and feature vectors through the encoding layer, the first network layer and the discriminant layer calculation, self-attention calculation and labeling sequence, and finally determine the indications of the drug, and improve the model's Generalization ability.
It improves the recognition accuracy and recall of drug indications, can identify indications that do not appear in the dictionary library, reduces dependence on the dictionary library, and saves resources.
Smart Images

Figure CN113657104B_ABST
Abstract
Description
Technical Field
[0001] The present application relates to the field of artificial intelligence technology, and in particular to a text extraction method, apparatus, computer equipment and storage medium. Background Art
[0002] For a medical document / data, such as the text of the drug instructions, extract the corresponding indications of the drug. For example, this product is a white tablet or a light blue or light green tablet with a colorant, or a film-coated tablet. It is used to treat duodenal ulcer, gastric ulcer, reflux esophagitis, stress ulcer and Zollinger-Ellison syndrome. For the treatment of duodenal ulcer or pathological hypersecretion state, 0.2-0.4g once, 4 times a day, after meals and before bedtime, or 0.8g once, once before bedtime; 5 indications of the drug can be extracted: duodenal ulcer; gastric ulcer; reflux esophagitis; stress ulcer; Zollinger-Ellison syndrome.
[0003] However, the current identification of drug indications mainly involves collecting indication names and generating an indication dictionary; then reading the drug instructions and matching the indication dictionary according to the maximum matching rule; and then generating matching indications. This method results in only the indications that appear in the dictionary being identified, and new indications cannot be identified, resulting in poor generalization and recognition capabilities. Summary of the invention
[0004] The purpose of the embodiments of the present application is to provide a text extraction method, apparatus, computer device and storage medium to solve the technical problem of inaccurate text extraction.
[0005] In order to solve the above technical problems, the present application embodiment provides a text extraction method, which adopts the following technical solution:
[0006] Obtaining a text to be processed and a preset extraction model, inputting the text to be processed into the preset extraction model, encoding the text to be processed according to the encoding layer of the preset extraction model, and obtaining a target encoding vector;
[0007] Input the target encoding vector to the first network layer of the preset extraction model, and calculate and obtain the first network vector corresponding to the text to be processed;
[0008] Inputting the first network vector to the second network layer of the preset extraction model, calculating a target feature matrix, performing self-attention calculation on the target feature matrix, and obtaining a target feature vector;
[0009] The target feature vector is input to the discriminant layer of the preset extraction model, the optimal annotation sequence corresponding to the text to be processed is calculated, the entity information corresponding to the optimal annotation sequence is obtained, and the entity information is determined to be the target extraction text of the text to be processed.
[0010] Furthermore, the step of encoding the text to be processed according to the encoding layer of the preset extraction model includes:
[0011] Acquire label information of the text to be processed, encode the label information according to the encoding layer to obtain a first vector, and encode the characters of the text to be processed according to the encoding layer to obtain a second vector;
[0012] The first vector and the second vector are concatenated to obtain the target encoding vector.
[0013] Furthermore, the step of obtaining the label information of the text to be processed, encoding the label information according to the encoding layer, and obtaining the first vector includes:
[0014] Obtaining the phonetic text, radical text and reverse translation text of the text to be processed, and using the phonetic text, radical text and reverse translation text as the label information;
[0015] According to the coding layer, the pinyin text, the radical text and the reverse translation text are respectively encoded to obtain a pinyin code, a radical code and a reverse translation code;
[0016] Self-attention calculation is performed on the pinyin code, the radical code and the reverse translation code to obtain the first vector.
[0017] Furthermore, the step of inputting the target encoding vector into the first network layer of the preset extraction model and calculating the first network vector corresponding to the text to be processed includes:
[0018] The first network layer includes a forward long short-term memory network and a backward long short-term memory network, the target encoding vector is input into the forward long short-term memory network in the positive order of the text to be processed, and a forward latent vector is calculated;
[0019] Inputting the target encoding vector into the backward long short-term memory network in the reverse order of the text to be processed, and calculating a backward latent vector;
[0020] The forward latent vector and the backward latent vector are concatenated to obtain the first network vector.
[0021] Furthermore, before the step of obtaining the text to be processed and the preset extraction model, the method further includes:
[0022] Collecting multiple groups of corpus texts and real extracted texts corresponding to the corpus texts, and annotating the real extracted texts and the corpus texts to obtain annotated texts;
[0023] Constructing a basic extraction model, inputting the annotated text into the basic extraction model, and calculating a loss function;
[0024] The parameters of the basic extraction model are adjusted according to the loss function. When the loss function converges, it is determined that the training of the basic extraction model is completed, and the trained basic extraction model is used as the preset extraction model.
[0025] Furthermore, the step of annotating the real extracted text and the corpus text to obtain the annotated text includes:
[0026] Performing word segmentation on the real extracted text to obtain word segmentation terms, and obtaining the position of each word segmentation term in the real extracted text;
[0027] Label the segmented words according to the starting position, the middle position and the ending position of the position to obtain a first subtext;
[0028] A preset tag of the corpus text is obtained, the corpus text is annotated as a second subtext according to the preset tag, and the first subtext and the second subtext are combined into the annotated text.
[0029] Furthermore, the step of inputting the annotated text into the basic extraction model and calculating the loss function includes:
[0030] Inputting the annotated text into the basic extraction model to obtain a predicted extracted text of the annotated text;
[0031] The loss function of the basic extraction model is calculated based on the predicted extracted text and the actual extracted text.
[0032] In order to solve the above technical problems, the embodiment of the present application further provides a text extraction device, which adopts the following technical solution:
[0033] An acquisition module, used for acquiring a text to be processed and a preset extraction model, inputting the text to be processed into the preset extraction model, encoding the text to be processed according to the encoding layer of the preset extraction model, and obtaining a target encoding vector;
[0034] A first calculation module, used for inputting the target encoding vector into the first network layer of the preset extraction model, and calculating and obtaining a first network vector corresponding to the text to be processed;
[0035] A second calculation module is used to input the first network vector to the second network layer of the preset extraction model, calculate a target feature matrix, perform self-attention calculation on the target feature matrix, and obtain a target feature vector;
[0036] A confirmation module is used to input the target feature vector into the discriminant layer of the preset extraction model, calculate the optimal annotation sequence corresponding to the text to be processed, obtain the entity information corresponding to the optimal annotation sequence, and determine that the entity information is the target extraction text of the text to be processed.
[0037] In order to solve the above technical problems, the embodiment of the present application further provides a computer device, which adopts the following technical solution:
[0038] Obtaining a text to be processed and a preset extraction model, inputting the text to be processed into the preset extraction model, encoding the text to be processed according to the encoding layer of the preset extraction model, and obtaining a target encoding vector;
[0039] Input the target encoding vector to the first network layer of the preset extraction model, and calculate and obtain the first network vector corresponding to the text to be processed;
[0040] Inputting the first network vector to the second network layer of the preset extraction model, calculating a target feature matrix, performing self-attention calculation on the target feature matrix, and obtaining a target feature vector;
[0041] The target feature vector is input to the discriminant layer of the preset extraction model, the optimal annotation sequence corresponding to the text to be processed is calculated, the entity information corresponding to the optimal annotation sequence is obtained, and the entity information is determined to be the target extraction text of the text to be processed.
[0042] In order to solve the above technical problems, the embodiment of the present application further provides a computer-readable storage medium, which adopts the following technical solution:
[0043] Obtaining a text to be processed and a preset extraction model, inputting the text to be processed into the preset extraction model, encoding the text to be processed according to the encoding layer of the preset extraction model, and obtaining a target encoding vector;
[0044] Input the target encoding vector to the first network layer of the preset extraction model, and calculate and obtain the first network vector corresponding to the text to be processed;
[0045] Inputting the first network vector to the second network layer of the preset extraction model, calculating a target feature matrix, performing self-attention calculation on the target feature matrix, and obtaining a target feature vector;
[0046] The target feature vector is input to the discriminant layer of the preset extraction model, the optimal annotation sequence corresponding to the text to be processed is calculated, the entity information corresponding to the optimal annotation sequence is obtained, and the entity information is determined to be the target extraction text of the text to be processed.
[0047] The present application obtains a text to be processed and a preset extraction model, inputs the text to be processed into the preset extraction model, encodes the text to be processed according to the encoding layer of the preset extraction model, and obtains a target encoding vector, so that the text to be processed can be accurately expressed through the target encoding vector; then, the target encoding vector is input to the first network layer of the preset extraction model, and the first network vector corresponding to the text to be processed is calculated, and the context feature information in the text to be processed can be extracted and expressed according to the first network vector; then, the first network vector is input to the second network layer of the preset extraction model, and the target feature matrix is calculated, and the self-attention calculation is performed on the target feature matrix to obtain the target feature vector; finally, the target feature vector is input to the discriminant layer of the preset extraction model, and the optimal annotation sequence corresponding to the text to be processed is calculated, and the entity information corresponding to the optimal annotation sequence is obtained, and the entity information is determined to be the target extraction text of the text to be processed, thereby improving the generalization ability of the model, and the text that does not appear in the dictionary library can also be recognized and extracted, and the improved model can recognize and extract the extracted text according to the context semantic information, thereby improving the recall rate and accuracy of the model, and there is no need to continuously maintain the dictionary library, saving resources. BRIEF DESCRIPTION OF THE DRAWINGS
[0048] In order to more clearly illustrate the scheme in the present application, a brief introduction is given below to the drawings required for use in the description of the embodiments of the present application. Obviously, the drawings described below are 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 work.
[0049] Figure 1 is an exemplary system architecture diagram to which the present application may be applied;
[0050] Figure 2 A flowchart according to an embodiment of the text extraction method of the present application;
[0051] Figure 3 is a structural schematic diagram of an embodiment of a text extraction device according to the present application;
[0052] Figure 4 It is a structural diagram of an embodiment of a computer device according to the present application.
[0053] Reference numerals: text extraction device 300 , acquisition module 301 , first calculation module 302 , second calculation module 303 , and confirmation module 304 . DETAILED DESCRIPTION
[0054] Unless otherwise defined, all technical and scientific terms used herein have the same meaning as those commonly understood by technicians in the technical field of the present application; the terms used in the specification of the application herein are only for the purpose of describing specific embodiments and are not intended to limit the present application; the terms "including" and "having" and any variations thereof in the specification and claims of the present application and the above-mentioned drawings are intended to cover non-exclusive inclusions. The terms "first", "second", etc. in the specification and claims of the present application or the above-mentioned drawings are used to distinguish different objects, not to describe a specific order.
[0055] Reference to "embodiments" herein means that a particular feature, structure, or characteristic described in conjunction with the embodiments may be included in at least one embodiment of the present application. The appearance of the phrase in various locations in the specification does not necessarily refer to the same embodiment, nor is it an independent or alternative embodiment that is mutually exclusive with other embodiments. It is explicitly and implicitly understood by those skilled in the art that the embodiments described herein may be combined with other embodiments.
[0056] In order to enable those skilled in the art to better understand the solution of the present application, the technical solution in the embodiments of the present application will be clearly and completely described below in conjunction with the accompanying drawings.
[0057] like Figure 1 As shown, the system architecture 100 may include terminal devices 101, 102, 103, a network 104 and a server 105. The network 104 is used to provide a medium for communication links between the terminal devices 101, 102, 103 and the server 105. The network 104 may include various connection types, such as wired, wireless communication links or optical fiber cables, etc.
[0058] Users can use terminal devices 101, 102, 103 to interact with server 105 through network 104 to receive or send messages, etc. Various communication client applications can be installed on terminal devices 101, 102, 103, such as web browser applications, shopping applications, search applications, instant messaging tools, email clients, social platform software, etc.
[0059] Terminal devices 101, 102, 103 can be various electronic devices with display screens and supporting web browsing, including but not limited to smart phones, tablet computers, e-book readers, MP3 players (Moving Picture Experts Group Audio Layer III), MP4 (Moving Picture Experts Group Audio Layer IV) players, laptop computers, desktop computers, etc.
[0060] The server 105 may be a server that provides various services, such as a background server that provides support for web pages displayed on the terminal devices 101 , 102 , and 103 .
[0061] It should be noted that the text extraction method provided in the embodiment of the present application is generally executed by a server / terminal device, and accordingly, the text extraction device is generally arranged in the server / terminal device.
[0062] It should be understood that Figure 1 The number of terminal devices, networks and servers in the embodiment is only for illustration. Any number of terminal devices, networks and servers may be provided according to implementation requirements.
[0063] Continue to refer Figure 2 , shows a flow chart of an embodiment of a method for text extraction according to the present application. The text extraction method comprises the following steps:
[0064] Step S201, obtaining a text to be processed and a preset extraction model, inputting the text to be processed into the preset extraction model, encoding the text to be processed according to the encoding layer of the preset extraction model, and obtaining a target encoding vector;
[0065] In this embodiment, the text to be processed is a text that needs to be extracted for information recognition. For example, for the extraction of drug indications, it is necessary to extract the indications corresponding to the drug from the drug instructions, and the drug instructions are the text to be processed. The preset extraction model is a pre-trained extraction model, and the preset extraction model includes a coding layer, a first network layer, a second network layer, and a discriminant layer. When the text to be processed is obtained, the text to be processed is encoded according to the coding layer of the preset extraction model to obtain the target coding vector corresponding to the text to be processed. The target coding vector can be obtained by encoding the coding structure of BERT (Bidirectional Encoder Representations from Transformers, pre-trained language model). Specifically, the text to be processed is positionally encoded, classified encoded, and embedded encoded to obtain a first coding result, a second coding result, and a third coding result; the first coding result, the second coding result, and the third coding result are spliced to obtain the target coding vector.
[0066] Step S202, inputting the target encoding vector into the first network layer of the preset extraction model, and calculating and obtaining a first network vector corresponding to the text to be processed;
[0067] In this embodiment, the first network layer adopts a bidirectional long short-term memory network (BiLSTM), which is composed of a forward long short-term memory network and a backward long short-term memory network. The target encoding vector is sequentially input into the forward long short-term memory network in the positive order of the text to be processed to obtain a forward latent vector; the target encoding vector is sequentially input into the backward long short-term memory network in the reverse order of the text to be processed to obtain a backward latent vector, and the forward latent vector and the backward latent vector are spliced to obtain a first network vector. The first network vector includes all the forward and backward information, and the semantic information features of the text context can be accurately represented according to the first network vector.
[0068] Step S203, inputting the first network vector to the second network layer of the preset extraction model, calculating a target feature matrix, performing self-attention calculation on the target feature matrix, and obtaining a target feature vector;
[0069] In this embodiment, when the first network vector is obtained, the first network vector is input into the second network layer, and the first network vector is feature extracted according to the second network layer, that is, the target extraction matrix is obtained. Specifically, the second network layer can use a neural network such as a convolutional neural network or a gated convolutional network to extract features from the first network vector. Taking the gated convolutional network (GCNN) as an example, when the first network vector is obtained, the first network vector is convolved in parallel according to the gated convolutional network to obtain the first convolution result and the second convolution result; one of the convolution results is selected and input into a preset activation function (sigmoid function), and the gated calculation result is calculated; the gated calculation result is multiplied with another group of convolution results that are not calculated by the activation function, and the target feature matrix is calculated. When the target feature matrix is obtained, the target feature matrix is self-attention calculated, that is, the target feature vector is obtained. When the indications of a drug are extracted from the drug instructions, the target feature vector is the feature vector corresponding to the drug instructions.
[0070] Step S204, input the target feature vector to the discriminant layer of the preset extraction model, calculate the optimal annotation sequence corresponding to the text to be processed, obtain the entity information corresponding to the optimal annotation sequence, and determine that the entity information is the target extraction text of the text to be processed.
[0071] In this embodiment, when the target extraction vector is obtained, the target feature vector is input into the discriminant layer of the preset extraction model, and the discriminant layer can adopt a discriminant model such as a conditional random field model (crf, Conditional Random Fields) or a hidden Markov model. Taking the conditional random field model as an example, the conditional random field model is an undirected graph model. The target feature vector is calculated according to the conditional random field model, and the label with the highest score corresponding to each word is selected from the target feature vector. The labels with the highest scores are combined into the optimal annotation sequence. For example, for w0, the score corresponding to "B-drug" is 1.5, which is the highest score, so "B-drug" is selected as the label with the highest score for w0. When the optimal annotation sequence is obtained, the entity information corresponding to the optimal annotation sequence is obtained, and the entity information is used as the target extraction text of the text to be processed.
[0072] It should be emphasized that in order to further ensure the privacy and security of the above-mentioned target extracted text, the above-mentioned target extracted text can also be stored in a node of a blockchain.
[0073] The blockchain referred to in this application is a new application model of computer technologies such as distributed data storage, peer-to-peer transmission, consensus mechanism, encryption algorithm, etc. Blockchain is essentially a decentralized database, a string of data blocks generated by cryptographic methods. Each data block contains a batch of network transaction information, which is used to verify the validity of its information (anti-counterfeiting) and generate the next block. Blockchain can include the underlying blockchain platform, platform product service layer, and application service layer.
[0074] This application improves the generalization ability of the model, and can also recognize and extract text that does not appear in the dictionary library. The improved model can recognize and extract text based on contextual semantic information, which improves the recall rate and accuracy of the model. There is no need to continuously maintain the dictionary library, saving resources.
[0075] In some optional implementations of this embodiment, the step of encoding the text to be processed according to the encoding layer of the preset extraction model includes:
[0076] Acquire label information of the text to be processed, encode the label information according to the encoding layer to obtain a first vector, and encode the characters of the text to be processed according to the encoding layer to obtain a second vector;
[0077] The first vector and the second vector are concatenated to obtain the target encoding vector.
[0078] In this embodiment, when encoding the text to be processed according to the encoding layer, the label information of the text to be processed is obtained, wherein the label information is the label expression of the text to be processed, such as the label information of the pinyin or radical of the text to be processed; the label information is encoded according to the encoding layer to obtain a first vector; the characters of the text to be processed are encoded according to the encoding layer to obtain a second vector. When the first vector and the second vector are obtained, the first vector and the second vector are vector-joined to obtain a target encoding vector.
[0079] This embodiment achieves accurate expression of the text to be processed by encoding the label information and the characters of the text to be processed, so that the target encoding vector obtained by calculation can more accurately reflect the text features of the text to be processed.
[0080] In some optional implementations of this embodiment, the step of obtaining the label information of the text to be processed, encoding the label information according to the encoding layer, and obtaining the first vector includes:
[0081] Obtaining the phonetic text, radical text and reverse translation text of the text to be processed, and using the phonetic text, radical text and reverse translation text as the label information;
[0082] According to the coding layer, the pinyin text, the radical text and the reverse translation text are respectively encoded to obtain a pinyin code, a radical code and a reverse translation code;
[0083] Self-attention calculation is performed on the pinyin code, the radical code and the reverse translation code to obtain the first vector.
[0084] In this embodiment, in order to more accurately encode and represent the text to be processed, when encoding the text to be processed according to the encoding layer, the pinyin text, radical text and reverse translation text of the text to be processed are obtained, and the pinyin text, radical text and reverse translation text are the label information of the text to be processed. According to the encoding layer, the pinyin text, radical text and reverse translation text are respectively encoded to obtain corresponding pinyin codes, radical codes and reverse translation codes; then, the pinyin codes, radical codes and reverse translation codes are self-attention calculated to obtain the first vector. Specifically, the pinyin codes, radical codes and reverse translation codes are vector spliced to obtain a spliced vector; when the spliced vector is obtained, the similarity between the vectors is calculated by self-attention for the spliced vector, and the similarity is represented by a probability distribution result to obtain a probability distribution result; finally, the probability distribution result is multiplied by the remaining encoding matrix to obtain the first vector.
[0085] This embodiment achieves full expression of the text to be processed by encoding the pinyin text, radical text and reverse translation text of the text to be processed, and further improves the accuracy of text extraction.
[0086] In some optional implementations of this embodiment, the step of inputting the target encoding vector to the first network layer of the preset extraction model and calculating the first network vector corresponding to the text to be processed includes:
[0087] The first network layer includes a forward long short-term memory network and a backward long short-term memory network, the target encoding vector is input into the forward long short-term memory network in the positive order of the text to be processed, and a forward latent vector is calculated;
[0088] Inputting the target encoding vector into the backward long short-term memory network in the reverse order of the text to be processed, and calculating a backward latent vector;
[0089] The forward latent vector and the backward latent vector are concatenated to obtain the first network vector.
[0090] In this embodiment, the first network layer includes a forward long short-term memory network and a backward long short-term memory network, and the forward long short-term memory network and the backward long short-term memory network both include three gate structures, namely a forget gate, a memory gate, and an output gate. The target coding vector is sequentially input into the forget gate of the forward long short-term memory network in the positive order of the text to be processed, and the output value of the forget gate is calculated based on the input target coding vector combined with the hidden layer state at the previous moment; the temporary cell state and the cell state at the previous moment are calculated according to the memory gate to obtain the cell state at the current moment, and the cell state at the current moment is input to the output gate to calculate the forward latent vector. Similarly, the target coding vector is sequentially input into the backward long short-term memory network in the reverse order of the text to be processed, and the backward latent vector is calculated according to the calculation method of the forward long short-term memory network. When the forward latent vector and the backward latent vector are obtained, the vectors at the corresponding positions of the forward latent vector and the backward latent vector are vector spliced to obtain the first network vector.
[0091] This embodiment performs feature calculation on the target encoding vector through a forward long short-term memory network and a backward long short-term memory network, thereby achieving accurate representation of the semantic information features of the text context, and further making the extracted text more accurate.
[0092] In some optional implementations of this embodiment, before the above step of obtaining the text to be processed and the preset extraction model, the following steps are also included:
[0093] Collecting multiple groups of corpus texts and real extracted texts corresponding to the corpus texts, and annotating the real extracted texts and the corpus texts to obtain annotated texts;
[0094] Constructing a basic extraction model, inputting the annotated text into the basic extraction model, and calculating a loss function;
[0095] The parameters of the basic extraction model are adjusted according to the loss function. When the loss function converges, it is determined that the training of the basic extraction model is completed, and the trained basic extraction model is used as the preset extraction model.
[0096] In this embodiment, before obtaining the preset extraction model, it is necessary to construct a basic extraction model, and train the basic extraction model to obtain the preset extraction model. Specifically, multiple groups of corpus texts and real extracted texts corresponding to the corpus texts are collected, the corpus texts and the real extracted texts are annotated, and the annotated corpus texts and the real extracted texts are used as annotated texts. Construct a basic extraction model, which has the same model structure as the preset extraction model, that is, both include a coding layer, a first network layer, a second network layer and a discriminant layer, but the parameters of the basic extraction model and the preset extraction model are different. The annotated text is input into the basic extraction model, and the loss function of the basic extraction model is calculated; the parameters of the basic extraction model are adjusted according to the loss function until the loss function calculated according to the basic extraction model after a certain parameter adjustment converges, and it is determined that the training of the basic extraction model is completed, and the basic training model that has been trained is the preset extraction model.
[0097] This embodiment trains the basic extraction model in advance so that the trained basic extraction model can accurately extract text, thereby improving the efficiency and accuracy of text extraction.
[0098] In some optional implementations of this embodiment, the step of annotating the real extracted text and the corpus text to obtain the annotated text includes:
[0099] Performing word segmentation on the real extracted text to obtain word segmentation terms, and obtaining the position of each word segmentation term in the real extracted text;
[0100] Label the segmented words according to the starting position, the middle position and the ending position of the position to obtain a first subtext;
[0101] A preset tag of the corpus text is obtained, the corpus text is annotated as a second subtext according to the preset tag, and the first subtext and the second subtext are combined into the annotated text.
[0102] In this embodiment, when the real extracted text is obtained, the real extracted text is segmented to obtain segmented words, and the position of each segmented word in the real extracted text is obtained, and the position includes the starting position, the middle position and the ending position. The segmented words of each real extracted text are labeled according to the starting position, the middle position and the ending position, and the annotated segmented words are the first subtext. At the same time, the preset label of the corpus text is obtained, and the corpus text is annotated as the second subtext according to the preset label, and the first subtext and the second subtext are combined into the annotated text.
[0103] Taking the text of a medical drug instruction manual as an example of the corpus text, this corpus text is "This product is a white tablet or a light blue or light green tablet with a colorant, or a film-coated tablet. It is used to treat duodenal ulcer, gastric ulcer, reflux esophagitis, stress ulcer, and Zollinger-Ellison syndrome. For the treatment of duodenal ulcer or pathological hypersecretion state, take 0.2 - 0.4 g once, 4 times a day, after meals and before going to bed, or take 0.8 g once, before going to bed only." The corresponding real extraction text for this corpus text is the extracted drug indications, including: duodenal ulcer, gastric ulcer, reflux esophagitis, stress ulcer, Zollinger-Ellison syndrome. In "duodenal ulcer", "twelve" is the word at the starting position, and "ulcer" is the word at the ending position. Therefore, "twelve" is marked as "B - indication starting position", "指肠" is marked as "M - indication middle position"... "ulcer" is marked as "E - indication ending position"; for the corpus text, it is marked as "O - other".
[0104] In this embodiment, by annotating the real extraction text and the corpus text, when performing text extraction through a preset extraction model, the text can be accurately extracted according to this annotated text, improving the accuracy of text extraction.
[0105] In some alternative implementation manners of this embodiment, the step of inputting the above-mentioned annotated text into the basic extraction model and calculating the loss function includes:
[0106] Input the annotated text into the basic extraction model to obtain the predicted extraction text of the annotated text;
[0107] Calculate the loss function of the basic extraction model according to the predicted extraction text and the real extraction text.
[0108] In this embodiment, when obtaining the annotated text, input this annotated text into the basic extraction model. When the annotated text is input into the basic extraction model for the first time, the parameters of this basic extraction model are the initial preset parameters; perform text extraction on this annotated text according to this basic extraction model, that is, predict the extraction text corresponding to this annotated text to obtain the predicted extraction text. Calculate the loss function according to this predicted extraction text and the real extraction text corresponding to this annotated text. By calculating the difference between the real and predicted results through this loss function, the degree of adjustment required for the model each time can be determined. Adjust the parameters of the basic extraction model according to the loss function. After each adjustment, input the annotated text into the adjusted basic extraction model again and calculate the loss function until the loss function converges when calculated according to the adjusted basic extraction model at a certain time. At this time, determine this adjusted basic extraction model as the preset extraction model.
[0109] This embodiment adjusts the parameters of the model through the loss function, thereby improving the training efficiency of the model and the prediction accuracy of the model.
[0110] Those skilled in the art can understand that all or part of the processes in the above-mentioned embodiments can be implemented by instructing the relevant hardware through computer-readable instructions, and the computer-readable instructions can be stored in a computer-readable storage medium. When the program is executed, it can include the processes of the embodiments of the above-mentioned methods. Among them, the aforementioned storage medium can be a non-volatile storage medium such as a disk, an optical disk, a read-only memory (ROM), or a random access memory (RAM).
[0111] It should be understood that, although the steps in the flowchart of the accompanying drawings are displayed in sequence as indicated by the arrows, these steps are not necessarily executed in sequence in the order indicated by the arrows. Unless otherwise specified herein, there is no strict order restriction on the execution of these steps, and they can be executed in other orders. Moreover, at least a part of the steps in the flowchart of the accompanying drawings may include multiple sub-steps or multiple stages, and these sub-steps or stages are not necessarily executed at the same time, but can be executed at different times, and their execution order is not necessarily sequential, but can be executed in turn or alternately with other steps or at least a part of the sub-steps or stages of other steps.
[0112] Further references Figure 3 , as a response to the above Figure 2 The present application provides an embodiment of a text extraction device, and the device embodiment is similar to Figure 2 Corresponding to the method embodiment shown, the device can be specifically applied to various electronic devices.
[0113] like Figure 3 As shown, the text extraction device 300 described in this embodiment includes: an acquisition module 301, a first calculation module 302, a second calculation module 303 and a confirmation module 304. Among them:
[0114] An acquisition module 301 is used to acquire a text to be processed and a preset extraction model, input the text to be processed into the preset extraction model, encode the text to be processed according to the encoding layer of the preset extraction model, and obtain a target encoding vector;
[0115] In some optional implementations of this embodiment, the acquisition module 301 includes:
[0116] An encoding unit, used for obtaining label information of the text to be processed, encoding the label information according to the encoding layer to obtain a first vector, and encoding the characters of the text to be processed according to the encoding layer to obtain a second vector;
[0117] A concatenation unit is used to concatenate the first vector and the second vector to obtain the target coding vector.
[0118] In some optional implementations of this embodiment, the encoding unit includes:
[0119] An acquisition subunit, used for acquiring the phonetic text, radical text and reverse translation text of the text to be processed, and using the phonetic text, radical text and reverse translation text as the label information;
[0120] An encoding subunit, used for encoding the pinyin text, the radical text and the reverse translation text according to the encoding layer to obtain a pinyin code, a radical code and a reverse translation code;
[0121] A calculation subunit is used to perform self-attention calculation on the pinyin code, the radical code and the reverse translation code to obtain the first vector.
[0122] In this embodiment, the text to be processed is a text that needs to be extracted for information recognition. For example, for the extraction of drug indications, it is necessary to extract the indications corresponding to the drug from the drug instructions, and the drug instructions are the text to be processed. The preset extraction model is a pre-trained extraction model, and the preset extraction model includes a coding layer, a first network layer, a second network layer, and a discriminant layer. When the text to be processed is obtained, the text to be processed is encoded according to the coding layer of the preset extraction model to obtain the target coding vector corresponding to the text to be processed. The target coding vector can be obtained by encoding the coding structure of BERT (Bidirectional Encoder Representations from Transformers, pre-trained language model). Specifically, the text to be processed is positionally encoded, classified encoded, and embedded encoded to obtain a first coding result, a second coding result, and a third coding result; the first coding result, the second coding result, and the third coding result are spliced to obtain the target coding vector.
[0123] A first calculation module 302 is used to input the target encoding vector to the first network layer of the preset extraction model to calculate and obtain a first network vector corresponding to the text to be processed;
[0124] In some optional implementations of this embodiment, the first calculation module 302 includes:
[0125] A first computing unit, for the first network layer including a forward long short-term memory network and a backward long short-term memory network, inputting the target encoding vector into the forward long short-term memory network in the positive order of the text to be processed, and calculating a forward latent vector;
[0126] A second calculation unit is used to input the target encoding vector into the backward long short-term memory network in the reverse order of the text to be processed, and calculate a backward latent vector;
[0127] The third computing unit is used to concatenate the forward latent vector and the backward latent vector to obtain the first network vector.
[0128] In this embodiment, the first network layer adopts a bidirectional long short-term memory network (BiLSTM), which is composed of a forward long short-term memory network and a backward long short-term memory network. The target encoding vector is sequentially input into the forward long short-term memory network in the positive order of the text to be processed to obtain a forward latent vector; the target encoding vector is sequentially input into the backward long short-term memory network in the reverse order of the text to be processed to obtain a backward latent vector, and the forward latent vector and the backward latent vector are spliced to obtain a first network vector. The first network vector includes all the forward and backward information, and the semantic information features of the text context can be accurately represented according to the first network vector.
[0129] A second calculation module 303 is used to input the first network vector to the second network layer of the preset extraction model, calculate a target feature matrix, perform self-attention calculation on the target feature matrix, and obtain a target feature vector;
[0130] In this embodiment, when the first network vector is obtained, the first network vector is input into the second network layer, and the first network vector is feature extracted according to the second network layer, that is, the target extraction matrix is obtained. Specifically, the second network layer can use a neural network such as a convolutional neural network or a gated convolutional network to extract features from the first network vector. Taking the gated convolutional network (GCNN) as an example, when the first network vector is obtained, the first network vector is convolved in parallel according to the gated convolutional network to obtain the first convolution result and the second convolution result; one of the convolution results is selected and input into a preset activation function (sigmoid function), and the gated calculation result is calculated; the gated calculation result is multiplied with another group of convolution results that are not calculated by the activation function, and the target feature matrix is calculated. When the target feature matrix is obtained, the target feature matrix is self-attention calculated, that is, the target feature vector is obtained. When the indications of a drug are extracted from the drug instructions, the target feature vector is the feature vector corresponding to the drug instructions.
[0131] The confirmation module 304 is used to input the target feature vector to the discriminant layer of the preset extraction model, calculate the optimal annotation sequence corresponding to the text to be processed, obtain the entity information corresponding to the optimal annotation sequence, and determine that the entity information is the target extraction text of the text to be processed.
[0132] In this embodiment, when the target extraction vector is obtained, the target feature vector is input into the discriminant layer of the preset extraction model, and the discriminant layer can adopt a discriminant model such as a conditional random field model (crf, Conditional Random Fields) or a hidden Markov model. Taking the conditional random field model as an example, the conditional random field model is an undirected graph model. The target feature vector is calculated according to the conditional random field model, and the label with the highest score corresponding to each word is selected from the target feature vector. The labels with the highest scores are combined into the optimal annotation sequence. For example, for w0, the score corresponding to "B-drug" is 1.5, which is the highest score, so "B-drug" is selected as the label with the highest score for w0. When the optimal annotation sequence is obtained, the entity information corresponding to the optimal annotation sequence is obtained, and the entity information is used as the target extraction text of the text to be processed.
[0133] It should be emphasized that in order to further ensure the privacy and security of the above-mentioned target extracted text, the above-mentioned target extracted text can also be stored in a node of a blockchain.
[0134] The blockchain referred to in this application is a new application model of computer technologies such as distributed data storage, peer-to-peer transmission, consensus mechanism, encryption algorithm, etc. Blockchain is essentially a decentralized database, a string of data blocks generated by cryptographic methods. Each data block contains a batch of network transaction information, which is used to verify the validity of its information (anti-counterfeiting) and generate the next block. Blockchain can include the underlying blockchain platform, platform product service layer, and application service layer.
[0135] In some optional implementations of this embodiment, the text extraction device 300 further includes:
[0136] A marking module, used for collecting multiple groups of corpus texts and real extracted texts corresponding to the corpus texts, marking the real extracted texts and the corpus texts to obtain marked texts;
[0137] A construction module is used to construct a basic extraction model, input the annotated text into the basic extraction model, and calculate the loss function;
[0138] An adjustment module is used to adjust the parameters of the basic extraction model according to the loss function. When the loss function converges, it is determined that the training of the basic extraction model is completed, and the trained basic extraction model is used as the preset extraction model.
[0139] In some optional implementations of this embodiment, the marking module includes:
[0140] A word segmentation unit is used to segment the real extracted text to obtain segmented words, and obtain the position of each segmented word in the real extracted text;
[0141] A first labeling unit is used to label the segmented words according to the starting position, the middle position and the ending position of the position to obtain a first subtext;
[0142] The second marking unit is used to obtain a preset label of the corpus text, mark the corpus text as a second subtext according to the preset label, and combine the first subtext and the second subtext into the marked text.
[0143] In some optional implementations of this embodiment, the building blocks include:
[0144] A prediction unit, used for inputting the annotated text into the basic extraction model to obtain a predicted extracted text of the annotated text;
[0145] The fourth calculation unit is used to calculate the loss function of the basic extraction model according to the predicted extracted text and the real extracted text.
[0146] In this embodiment, before obtaining the preset extraction model, it is necessary to construct a basic extraction model, and train the basic extraction model to obtain the preset extraction model. Specifically, multiple groups of corpus texts and real extracted texts corresponding to the corpus texts are collected, the corpus texts and the real extracted texts are annotated, and the annotated corpus texts and the real extracted texts are used as annotated texts. Construct a basic extraction model, which has the same model structure as the preset extraction model, that is, both include a coding layer, a first network layer, a second network layer and a discriminant layer, but the parameters of the basic extraction model and the preset extraction model are different. The annotated text is input into the basic extraction model, and the loss function of the basic extraction model is calculated; the parameters of the basic extraction model are adjusted according to the loss function until the loss function calculated according to the basic extraction model after a certain parameter adjustment converges, and it is determined that the training of the basic extraction model is completed, and the basic training model that has been trained is the preset extraction model.
[0147] The text extraction device proposed in this embodiment improves the generalization ability of the model, and can also recognize and extract text that does not appear in the dictionary library. The improved model can recognize and extract text based on contextual semantic information, thereby improving the recall rate and accuracy of the model. There is no need to continuously maintain the dictionary library, saving resources.
[0148] To solve the above technical problems, the present application also provides a computer device. Figure 4 , Figure 4 This is a basic structural block diagram of the computer device in this embodiment.
[0149] The computer device 6 includes a memory 61, a processor 62, and a network interface 63 that are interconnected through a system bus. It should be noted that the figure only shows a computer device 6 with components 61-63, but it should be understood that it is not required to implement all the components shown, and more or fewer components can be implemented instead. Among them, those skilled in the art can understand that the computer device here is a device that can automatically perform numerical calculations and / or information processing according to pre-set or stored instructions, and its hardware includes but is not limited to microprocessors, application specific integrated circuits (Application Specific Integrated Circuit, ASIC), programmable gate arrays (Field-Programmable Gate Array, FPGA), digital processors (Digital Signal Processor, DSP), embedded devices, etc.
[0150] The computer device may be a computing device such as a desktop computer, a notebook, a PDA, a cloud server, etc. The computer device may interact with a user through a keyboard, a mouse, a remote controller, a touch pad, or a voice control device.
[0151] The memory 61 includes at least one type of readable storage medium, and the readable storage medium includes flash memory, hard disk, multimedia card, card-type memory (for example, SD or DX memory, etc.), random access memory (RAM), static random access memory (SRAM), read-only memory (ROM), electrically erasable programmable read-only memory (EEPROM), programmable read-only memory (PROM), magnetic memory, disk, optical disk, etc. In some embodiments, the memory 61 can be an internal storage unit of the computer device 6, such as a hard disk or memory of the computer device 6. In other embodiments, the memory 61 can also be an external storage device of the computer device 6, such as a plug-in hard disk equipped on the computer device 6, a smart memory card (Smart Media Card, SMC), a secure digital (Secure Digital, SD) card, a flash card (FlashCard), etc. Of course, the memory 61 can also include both the internal storage unit of the computer device 6 and its external storage device. In this embodiment, the memory 61 is generally used to store the operating system and various application software installed on the computer device 6, such as computer-readable instructions of the text extraction method, etc. In addition, the memory 61 can also be used to temporarily store various types of data that have been output or are to be output.
[0152] The processor 62 may be a central processing unit (CPU), a controller, a microcontroller, a microprocessor, or other data processing chips in some embodiments. The processor 62 is generally used to control the overall operation of the computer device 6. In this embodiment, the processor 62 is used to run computer-readable instructions stored in the memory 61 or process data, such as computer-readable instructions for running the text extraction method.
[0153] The network interface 63 may include a wireless network interface or a wired network interface. The network interface 63 is generally used to establish a communication connection between the computer device 6 and other electronic devices.
[0154] The computer device proposed in this embodiment improves the generalization ability of the model and can also recognize and extract text that does not appear in the dictionary library. The improved model can recognize and extract text based on contextual semantic information, thereby improving the recall rate and accuracy of the model. There is no need to continuously maintain the dictionary library, saving resources.
[0155] The present application also provides another implementation, namely, providing a computer-readable storage medium, wherein the computer-readable storage medium stores computer-readable instructions, and the computer-readable instructions can be executed by at least one processor to enable the at least one processor to perform the steps of the text extraction method as described above.
[0156] The computer-readable storage medium proposed in this embodiment improves the generalization ability of the model, and can also recognize and extract text that does not appear in the dictionary library. The improved model can recognize and extract text based on contextual semantic information, thereby improving the recall rate and accuracy of the model. There is no need to continuously maintain the dictionary library, saving resources.
[0157] 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, magnetic disk, optical disk), and includes a number of instructions for a terminal device (which can be a mobile phone, computer, server, air conditioner, or network device, etc.) to execute the methods described in each embodiment of the present application.
[0158] Obviously, the embodiments described above are only some embodiments of the present application, rather than all embodiments. The preferred embodiments of the present application are given in the accompanying drawings, but they do not limit the patent scope of the present application. The present application can be implemented in many different forms. On the contrary, the purpose of providing these embodiments is to make the understanding of the disclosure of the present application more thorough and comprehensive. Although the present application is described in detail with reference to the aforementioned embodiments, for those skilled in the art, it is still possible to modify the technical solutions recorded in the aforementioned specific implementation methods, or to perform equivalent replacement of some of the technical features therein. Any equivalent structure made using the contents of the specification and drawings of this application, directly or indirectly used in other related technical fields, is similarly within the scope of patent protection of this application.
Claims
1. A text extraction method, characterized in that: The steps include: Obtaining a text to be processed and a preset extraction model, inputting the text to be processed into the preset extraction model, encoding the text to be processed according to the encoding layer of the preset extraction model, and obtaining a target encoding vector; Input the target encoding vector to the first network layer of the preset extraction model, and calculate and obtain the first network vector corresponding to the text to be processed; Inputting the first network vector to the second network layer of the preset extraction model, calculating a target feature matrix, performing self-attention calculation on the target feature matrix, and obtaining a target feature vector; Input the target feature vector to the discriminant layer of the preset extraction model, calculate the optimal annotation sequence corresponding to the text to be processed, obtain the entity information corresponding to the optimal annotation sequence, and determine that the entity information is the target extraction text of the text to be processed; The step of encoding the text to be processed according to the encoding layer of the preset extraction model comprises: Acquire label information of the text to be processed, encode the label information according to the encoding layer to obtain a first vector, and encode the characters of the text to be processed according to the encoding layer to obtain a second vector; Concatenate the first vector and the second vector to obtain the target encoding vector; The step of inputting the target encoding vector to the first network layer of the preset extraction model to calculate the first network vector corresponding to the text to be processed includes: The first network layer includes a forward long short-term memory network and a backward long short-term memory network, the target encoding vector is input into the forward long short-term memory network in the positive order of the text to be processed, and a forward latent vector is calculated; Inputting the target encoding vector into the backward long short-term memory network in the reverse order of the text to be processed, and calculating a backward latent vector; Concatenating the forward latent vector and the backward latent vector to obtain the first network vector; Before the step of obtaining the text to be processed and the preset extraction model, the method further includes: Collecting multiple groups of corpus texts and real extracted texts corresponding to the corpus texts, and annotating the real extracted texts and the corpus texts to obtain annotated texts; Constructing a basic extraction model, inputting the annotated text into the basic extraction model, and calculating a loss function; Adjusting the parameters of the basic extraction model according to the loss function, determining that the training of the basic extraction model is completed when the loss function converges, and using the trained basic extraction model as the preset extraction model; The second network layer is a convolutional neural network or a gated convolutional network.
2. The text extraction method according to claim 1, characterized in that: The step of obtaining the label information of the text to be processed, encoding the label information according to the encoding layer, and obtaining the first vector includes: Obtaining the phonetic text, radical text and reverse translation text of the text to be processed, and using the phonetic text, radical text and reverse translation text as the label information; According to the coding layer, the pinyin text, the radical text and the reverse translation text are respectively encoded to obtain a pinyin code, a radical code and a reverse translation code; Self-attention calculation is performed on the pinyin code, the radical code and the reverse translation code to obtain the first vector.
3. The text extraction method according to claim 1, characterized in that: The step of annotating the real extracted text and the corpus text to obtain the annotated text comprises: Performing word segmentation on the real extracted text to obtain word segmentation terms, and obtaining the position of each word segmentation term in the real extracted text; Label the segmented words according to the starting position, the middle position and the ending position of the position to obtain a first subtext; A preset tag of the corpus text is obtained, the corpus text is annotated as a second subtext according to the preset tag, and the first subtext and the second subtext are combined into the annotated text.
4. The text extraction method according to claim 1, characterized in that: The step of inputting the annotated text into the basic extraction model and calculating the loss function comprises: Inputting the annotated text into the basic extraction model to obtain a predicted extracted text of the annotated text; The loss function of the basic extraction model is calculated based on the predicted extracted text and the actual extracted text.
5. A text extraction device, characterized in that: The text extraction device, when executed, implements the steps of the text extraction method according to any one of claims 1 to 4, including: An acquisition module, used for acquiring a text to be processed and a preset extraction model, inputting the text to be processed into the preset extraction model, encoding the text to be processed according to the encoding layer of the preset extraction model, and obtaining a target encoding vector; A first calculation module, used for inputting the target encoding vector into the first network layer of the preset extraction model, and calculating and obtaining a first network vector corresponding to the text to be processed; A second calculation module is used to input the first network vector to the second network layer of the preset extraction model, calculate a target feature matrix, perform self-attention calculation on the target feature matrix, and obtain a target feature vector; A confirmation module is used to input the target feature vector into the discriminant layer of the preset extraction model, calculate the optimal annotation sequence corresponding to the text to be processed, obtain the entity information corresponding to the optimal annotation sequence, and determine that the entity information is the target extraction text of the text to be processed.
6. A computer device comprising a memory and a processor, wherein the memory stores computer-readable instructions, and the processor implements the steps of the text extraction method according to any one of claims 1 to 4 when executing the computer-readable instructions.
7. A computer-readable storage medium, characterized in that: The computer-readable storage medium stores computer-readable instructions, and when the computer-readable instructions are executed by a processor, the steps of the text extraction method according to any one of claims 1 to 4 are implemented.
Citation Information
Patent Citations
Knowledge extraction method and system based on memory neural network and device
CN108304911A
Pinyin labeling method and device, server and storage medium
CN111144110A