A method, device, equipment and storage medium for constructing a drug knowledge graph
Through the multi-head attention mechanism, the drug instruction manual text is processed, the entity label and relationship probability values are automatically calculated, and the description text is generated, which solves the problems of high cost and low accuracy of existing drug knowledge graph construction methods, and achieves a more efficient and accurate drug knowledge graph Build.
Patent Information
- Application Number
- CN202311597842.5
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2023-11-27
- Publication Date
- 2024-11-29
- Estimated Expiration
- 2043-11-27
AI Technical Summary
Existing methods for drug knowledge graph construction rely on manual or regular expression rules, resulting in high cost, low accuracy and easy to cause operational errors.
The multi-headed attention mechanism is used to process the character vector sequence in the drug instruction manual text, calculate the probability value of the entity label and the relationship probability value between entities, and generate the description text through autoregression to automatically construct the drug knowledge graph.
It reduces the cost of building a drug knowledge map, improves accuracy, and reduces manual intervention and error.
Smart Images

Figure CN117594251B_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to knowledge graph technology, and in particular to a method, device, equipment and storage medium for constructing a drug knowledge graph. Background Art
[0002] The knowledge graph contains rich semantic information and represents entities or concepts in the real world and the relationships between them in a structured form. Its essence is a huge semantic network diagram that presents massive knowledge to users in a more intuitive way.
[0003] At present, knowledge graphs have relatively mature applications in Internet search and information recommendation systems, but there is no mature and public drug knowledge graph in the field of medicine. Although there are methods for constructing drug knowledge graphs in the prior art, these knowledge graphs are constructed by extracting structured data manually or using regular expression rules. Although the structured knowledge extracted by manual methods is more accurate, it consumes more manpower and time, and long-term manual operation is prone to fatigue and errors. Summary of the invention
[0004] The present invention provides a method, device, equipment and storage medium for constructing a drug knowledge graph to reduce costs and improve accuracy.
[0005] In a first aspect, the present invention provides a method for constructing a drug knowledge graph, comprising:
[0006] Obtaining a drug instruction manual text, and vectorizing characters in the drug instruction manual text to obtain a word vector sequence including a plurality of word vectors;
[0007] Using a multi-head attention mechanism to process the word vector sequence to obtain a feature vector sequence including multiple feature vectors;
[0008] Calculate a first probability value that the character is each entity label based on the feature vector, and determine the entity corresponding to the character based on the first probability value;
[0009] Calculating a second probability value of the relationship between the entity and other entities in the drug instruction text based on the feature vector and the first probability value, and determining the relationship between the entity and other entities in the drug instruction text based on the second probability value;
[0010] Based on the word vector sequence autoregression, a description text is generated to describe the relationship between the entity and other entities in the drug instruction manual text.
[0011] Optionally, characters in the drug instructions text are vectorized to obtain a word vector sequence including multiple word vectors, including:
[0012] Performing word embedding on the characters in the drug instructions text to obtain a word embedding vector;
[0013] Performing position embedding on the characters in the drug instructions text to obtain a position embedding vector;
[0014] The word embedding vector and the position embedding vector are merged to obtain a word vector representing the character;
[0015] Arrange the word vectors of the multiple characters according to word order to obtain a word vector sequence including the multiple word vectors.
[0016] Optionally, a multi-head attention mechanism is used to process the word vector sequence to obtain a feature vector sequence including multiple feature vectors, including:
[0017] The word vector sequence is input into an encoding module including multiple transformers stacked in sequence for processing to obtain a feature vector sequence including multiple feature vectors, wherein the transformer processes the input features based on a multi-head attention mechanism, and the output features of the previous transformer are used as the input features of the next transformer.
[0018] Optionally, the transformer includes a multi-head attention layer, a first normalization layer, a feedforward layer, and a second normalization layer, and the transformer processes the input features based on the multi-head attention mechanism as follows:
[0019] In the multi-head attention layer, the input features are processed based on the multi-head attention mechanism to obtain attention features;
[0020] Fusing the attention feature with the input feature to obtain a first fused feature;
[0021] Normalizing the first fused features in the first normalization layer to obtain first normalized features;
[0022] Performing full connection mapping on the first normalized feature in the feed-forward layer to obtain a fully connected feature;
[0023] Fusing the first normalized feature with the fully connected feature to obtain a second fused feature;
[0024] The second fused features are normalized in the second normalization layer to obtain output features of the transformer.
[0025] Optionally, calculating a first probability value that the character is each entity label based on the feature vector, and determining the entity corresponding to the character based on the first probability value includes:
[0026] For each of the eigenvectors, input the eigenvector into a first linearization layer for linearization processing to obtain a first space vector;
[0027] Inputting the first space vector into a first activation function layer for activation processing to obtain a first probability value of the character being each entity label;
[0028] When the maximum value of the first probability value is greater than a preset value, the entity label corresponding to the maximum value is used as the entity corresponding to the character.
[0029] Optionally, calculating a second probability value of the relationship between the entity and other entities in the drug instruction text based on the feature vector and the first probability value, and determining the relationship between the entity and other entities in the drug instruction text based on the second probability value includes:
[0030] For each of the eigenvectors, input the eigenvector into a first linearization layer for linearization processing to obtain a first space vector;
[0031] Inputting the first space vector into a first activation function layer for activation processing to obtain a first probability value of the character being each entity label;
[0032] When the maximum value of the first probability value is greater than a preset value, taking the entity label corresponding to the maximum value as the entity corresponding to the character;
[0033] Calculating the correlation between the entity and other entities in the drug instruction manual text to obtain a correlation vector;
[0034] Inputting the correlation vector into a second linearization layer for linearization processing to obtain a second space vector;
[0035] Inputting the second space vector into a second activation function layer for activation processing to obtain a second probability value of the relationship between the entity and other entities in the drug instruction manual text;
[0036] The relationship corresponding to the maximum value in the second probability value is used as the relationship between the entity and the target entity, wherein the target entity is the entity corresponding to the maximum value in the second probability value.
[0037] Optionally, generating a description text for describing the relationship between the entity and other entities in the drug instruction manual text based on the word vector sequence autoregression includes:
[0038] Fusing the word vector sequence and the initialized output text sequence to obtain a fused sequence;
[0039] Using a multi-head attention mechanism to process the fused sequence to obtain an intermediate vector;
[0040] Calculate the output character as a third probability value of each sample character in the vocabulary based on the intermediate vector;
[0041] Taking the sample character corresponding to the maximum value of the third probability value as the output character;
[0042] The output character is converted into a vector, the output text sequence is updated, and the step of fusing the word vector sequence and the output text sequence to obtain a fused sequence is returned until the output character is a terminator.
[0043] In a second aspect, the present invention further provides a drug knowledge graph construction device, comprising:
[0044] A vectorization module, used for obtaining a drug instruction text and vectorizing characters in the drug instruction text to obtain a word vector sequence including a plurality of word vectors;
[0045] An attention module, used for processing the word vector sequence using a multi-head attention mechanism to obtain a feature vector sequence including multiple feature vectors;
[0046] An entity determination module, configured to calculate a first probability value of the character being each entity label based on the feature vector, and determine the entity corresponding to the character based on the first probability value;
[0047] an entity relationship determination module, configured to calculate a second probability value of a relationship between the entity and other entities in the drug instruction text based on the feature vector and the first probability value, and determine the relationship between the entity and other entities in the drug instruction text based on the second probability value;
[0048] A description text generation module is used to generate description text for describing the relationship between the entity and other entities in the drug instruction manual text based on the word vector sequence autoregression.
[0049] In a third aspect, the present invention further provides an electronic device, comprising:
[0050] one or more processors;
[0051] A storage device for storing one or more programs;
[0052] When the one or more programs are executed by the one or more processors, the one or more processors implement the drug knowledge graph construction method provided in the first aspect of the present invention.
[0053] In a fourth aspect, the present invention further provides a computer-readable storage medium having a computer program stored thereon, which, when executed by a processor, implements the method for constructing a drug knowledge graph as provided in the first aspect of the present invention.
[0054] The method for constructing a drug knowledge graph provided by the present invention includes: obtaining a drug instruction text, and vectorizing characters in the drug instruction text to obtain a word vector sequence including multiple word vectors, using a multi-head attention mechanism to process the word vector sequence to obtain a feature vector sequence including multiple feature vectors, calculating a first probability value of a character being a label of each entity based on the feature vector, and determining the entity corresponding to the character based on the first probability value, calculating a second probability value of the relationship between the entity and other entities in the drug instruction text based on the feature vector and the first probability value, and determining the relationship between the entity and other entities in the drug instruction text based on the second probability value, and generating a description text for describing the relationship between the entity and other entities in the drug instruction text based on the autoregression of the word vector sequence, which can reduce costs and improve accuracy.
[0055] It should be understood that the contents described in this section are not intended to identify the key or important features of the embodiments of the present invention, nor are they intended to limit the scope of the present invention. Other features of the present invention will become easily understood through the following description. BRIEF DESCRIPTION OF THE DRAWINGS
[0056] In order to more clearly illustrate the technical solutions in the embodiments of the present invention, the following briefly introduces the drawings required for use in the description of the embodiments. Obviously, the drawings described below are only some embodiments of the present invention. For ordinary technicians in this field, other drawings can be obtained based on these drawings without creative work.
[0057] Figure 1 A flowchart of a method for constructing a drug knowledge graph provided by an embodiment of the present invention;
[0058] Figure 2 A schematic diagram of the structure of a drug knowledge graph construction model provided by an embodiment of the present invention;
[0059] Figure 3 A schematic diagram of the structure of a converter provided by an embodiment of the present invention;
[0060] Figure 4 A structural diagram of a description text generation model provided by an embodiment of the present invention;
[0061] Figure 5 A schematic diagram of the structure of a drug knowledge graph construction device provided by an embodiment of the present invention;
[0062] Figure 6A schematic diagram of the structure of an electronic device provided by an embodiment of the present invention.
[0063] The above drawings have shown clear embodiments of the present application, which will be described in more detail later. These drawings and text descriptions are not intended to limit the scope of the present application in any way, but to illustrate the concept of the present application to those skilled in the art by referring to specific embodiments. DETAILED DESCRIPTION
[0064] In order to enable those skilled in the art to better understand the scheme of the present invention, the technical scheme in the embodiments of the present invention will be clearly and completely described below in conjunction with the drawings in the embodiments of the present invention. Obviously, the described embodiments are only part of the embodiments of the present invention, not all of the embodiments. Based on the embodiments of the present invention, all other embodiments obtained by ordinary technicians in this field without creative work should fall within the scope of protection of the present invention.
[0065] It should be noted that the terms "first", "second", etc. in the specification and claims of the present invention and the above-mentioned drawings are used to distinguish similar objects, and are not necessarily used to describe a specific order or sequence. It should be understood that the data used in this way can be interchanged where appropriate, so that the embodiments of the present invention described herein can be implemented in an order other than those illustrated or described herein. In addition, the terms "including" and "having" and any variations thereof are intended to cover non-exclusive inclusions, for example, a process, method, system, product or device that includes a series of steps or units is not necessarily limited to those steps or units that are clearly listed, but may include other steps or units that are not clearly listed or inherent to these processes, methods, products or devices.
[0066] Figure 1 This is a flowchart of a method for constructing a drug knowledge graph provided by an embodiment of the present invention. This embodiment is applicable to the case where a drug knowledge graph is constructed using drug instructions. The method can be executed by a drug knowledge graph construction device provided by an embodiment of the present invention. The device can be implemented by software and / or hardware and is usually configured in an electronic device, such as Figure 1 As shown in FIG. 1 , the method for constructing a drug knowledge graph specifically includes the following steps:
[0067] S101. Obtain a drug instruction sheet text, and vectorize characters in the drug instruction sheet text to obtain a word vector sequence including multiple word vectors.
[0068] In an embodiment of the present invention, a drug instruction sheet is obtained, and the text in the drug instruction sheet text is extracted to obtain the drug instruction sheet text. Exemplarily, common optical character recognition technology can be used for text extraction, and the embodiment of the present invention is not repeated here. After obtaining the drug instruction sheet text, the characters in the drug instruction sheet text are vectorized to obtain a word vector sequence including multiple word vectors.
[0069] Characters can be understood as placeholders in the sentence to be processed, and each word or punctuation mark is a character. Exemplarily, in some embodiments of the present invention, methods such as Word2Vec or one-hot encoding can be used to vectorize the characters in the drug instructions text to obtain a word vector sequence including multiple word vectors.
[0070] In another embodiment of the present invention, the characters in the drug instructions text are vectorized using a BERT (Bidirectional Encoder Representations from Transformers)-base embedding layer to obtain a word vector sequence including multiple word vectors. Exemplarily, the characters in the drug instructions text are word embedded (TokenEmbedding) to obtain a word embedding vector, and the characters in the drug instructions text are position embedded (PositionEmbedding) to obtain a position embedding vector, and then the word embedding vector and the position embedding vector are fused to obtain a word vector representing the character, and finally the word vectors of multiple characters are arranged according to the word order to obtain a word vector sequence including multiple word vectors. Among them, the word embedding operation refers to representing each character with a code in a dictionary library and converting it into a word embedding vector of a fixed dimension; the position embedding operation refers to numbering each character position in the drug instructions text, and then each number corresponds to a vector, and by combining the position vector and the word vector, a certain position information is introduced to each character.
[0071] S102. Use a multi-head attention mechanism to process the word vector sequence to obtain a feature vector sequence including multiple feature vectors.
[0072] Exemplarily, a multi-head attention mechanism is used to process the word vector sequence to obtain a feature vector sequence including multiple feature vectors. The word vector sequence is a sequence with a very large dimension. The self-attention mechanism is usually used to solve the long dependency problem in the sequence, that is, the model needs to maintain connections between different positions in the sequence in order to correctly understand and process the information in the sequence.
[0073] Figure 2 A schematic diagram of a drug knowledge graph construction model provided by an embodiment of the present invention is shown in FIG. Figure 2As shown, exemplarily, in some embodiments of the present invention, a word vector sequence is input into an encoding module (Encoder) including multiple (exemplarily, in an embodiment of the present invention, the encoding module includes 96 transformers) stacked in sequence for processing to obtain a feature vector sequence including multiple feature vectors, wherein the transformer processes the input features based on a multi-head attention mechanism, and the output features of the previous transformer are used as the input features of the next transformer.
[0074] Figure 3 A schematic diagram of a converter structure provided by an embodiment of the present invention is shown in FIG. Figure 3 As shown in the figure, the transformer includes a multi-head attention layer Multi-Head Attention, a first normalization layer Norm1, a feed-forward layer FFN, and a second normalization layer Norm2. The transformer processes the input features based on the multi-head attention mechanism as follows:
[0075] 1. In the multi-head attention layer, the input features are processed based on the multi-head attention mechanism to obtain the attention features.
[0076] Exemplarily, three linear transformations are performed on the input features in the multi-head attention layer to obtain three vectors, two of which are used as the key vector K and the value vector V, and the other vector is used as the query vector Q to calculate the attention features.
[0077] 2. Fuse the attention feature with the input feature to obtain the first fused feature.
[0078] Exemplarily, the attention feature is fused with the input feature of the transformer to obtain a first fused feature.
[0079] 3. Normalize the first fusion feature in the first normalization layer to obtain the first normalized feature.
[0080] Exemplarily, the first fused feature is normalized in a first normalization layer to obtain a first normalized feature.
[0081] 4. Perform full connection mapping on the first normalized feature in the feed-forward layer to obtain the fully connected feature.
[0082] Exemplarily, the feed-forward layer is a fully connected layer, and the first normalized feature is fully connected mapped in the feed-forward layer to obtain a fully connected feature.
[0083] 5. Fuse the first normalized feature with the fully connected feature to obtain the second fused feature.
[0084] Exemplarily, the first normalized feature is fused with the fully connected feature to obtain a second fused feature.
[0085] 6. The second fusion feature is normalized in the second normalization layer to obtain the output feature of the transformer.
[0086] Exemplarily, the second fused features are normalized in a second normalization layer to obtain output features of the transformer.
[0087] S103: Calculate a first probability value of the character being each entity label based on the feature vector, and determine the entity corresponding to the character based on the first probability value.
[0088] In the embodiment of the present invention, a first probability value of a character being each entity label is calculated based on the feature vector, and an entity corresponding to the character is determined based on the first probability value. In the embodiment of the present invention, an entity can be a thing in the real world in the specification, such as a place name, a concept, a medicine, an ingredient, a company, etc., which is not limited in the embodiment of the present invention.
[0089] Exemplarily, for each feature vector, the feature vector is input into the first linearization layer for linearization processing to obtain a first space vector, and the first space vector is input into the first activation function layer for activation processing to obtain a first probability value of the character as each entity label. When the maximum value of the first probability value is greater than a preset value, the entity label corresponding to the maximum value is used as the entity corresponding to the character.
[0090] S104. Calculate a second probability value of the relationship between the entity and other entities in the drug instruction text based on the feature vector and the first probability value, and determine the relationship between the entity and other entities in the drug instruction text based on the second probability value.
[0091] In an embodiment of the present invention, a second probability value of the relationship between the entity and other entities in the drug instructions text is calculated based on the feature vector and the first probability value, and the relationship between the entity and other entities in the drug instructions text is determined based on the second probability value. The relationship between entities is used to express a certain connection between different entities. In the knowledge graph, "entity" is usually used to express the nodes in the graph, and "relationship" is used to express the "edge" in the graph.
[0092] Exemplarily, for each feature vector, the feature vector is input into the first linearization layer for linearization processing to obtain a first space vector, and the first space vector is input into the first activation function layer for activation processing to obtain a first probability value of the character as each entity label, and when the maximum value of the first probability value is greater than a preset value, the entity label corresponding to the maximum value is used as the entity corresponding to the character. In this way, all entities in the drug instructions text can be determined.
[0093] Next, the correlation between the entity and other entities in the drug instructions text is calculated to obtain a correlation vector. Exemplarily, the correlation can be characterized by similarity, Pearson correlation coefficient, etc., which is not limited in the embodiments of the present invention. The correlation vector is input into the second linearization layer for linearization processing to obtain a second space vector. The second space vector is input into the second activation function layer for activation processing to obtain a second probability value of the relationship between the entity and other entities in the drug instructions text. The relationship corresponding to the maximum value in the second probability value is used as the relationship between the entity and the target entity, wherein the target entity is the entity corresponding to the maximum value in the second probability value. For example, the second probability values corresponding to various relationships between entity A and entity B are calculated, and the relationship corresponding to the maximum value in the second probability value is used as the relationship between entity A and entity B.
[0094] S105. Generate descriptive text for describing the relationship between the entity and other entities in the drug instruction manual text based on word vector sequence autoregression.
[0095] In an embodiment of the present invention, a description text for describing the relationship between an entity and other entities in the drug instructions text can also be generated based on word vector sequence autoregression to describe the relationship between entities in the drug instructions.
[0096] Figure 4 A structural diagram of a description text generation model provided by an embodiment of the present invention, such as Figure 4 As shown, the model also uses the encoder in the aforementioned embodiment. Exemplarily, the text generation process is described as follows:
[0097] 1. Initialize the output text sequence, fuse the word vector sequence of the drug instructions text with the output text sequence to obtain a fused sequence.
[0098] 2. Input the fused sequence into the encoding module in the aforementioned embodiment, and the multi-head attention mechanism of the encoding module processes the fused sequence to obtain an intermediate vector. Exemplarily, the processing process of the encoding module has been described in detail in the aforementioned embodiment, and the embodiment of the present invention will not be repeated here.
[0099] 3. Calculate the third probability value of the output character as each sample character in the vocabulary based on the intermediate vector.
[0100] Exemplarily, in an embodiment of the present invention, the intermediate vector is input into the third linearization layer for linearization processing to obtain linearized features, and then the linearized features are input into the activation function layer (the activation function is the softmax function) for activation to obtain the output character as the third probability value of each sample character in the vocabulary.
[0101] 4. Take the sample character corresponding to the maximum value in the third probability value as the output character, convert the output character into a vector, update the output text sequence, and return to execute the step of fusing the word vector sequence and the output text sequence to obtain the fused sequence until the output character is the terminator.
[0102] Exemplarily, the sample character corresponding to the maximum value in the third probability value is taken as the output character, the output character is converted into a vector, the vector is written to the corresponding position of the output text sequence, the output text sequence is updated, and the step of executing the fused word vector sequence and the initialized output text sequence to obtain the fused sequence is returned until the output character is a terminator, thereby obtaining the description text.
[0103] It can be seen from the above embodiments that in the embodiments of the present invention, the construction of the drug knowledge graph includes three tasks, namely entity recognition, relationship extraction and text generation. Exemplarily, in the embodiments of the present invention, when training the drug knowledge graph construction model, during the training process, the sum of the loss values of the entity recognition task, the relationship extraction task and the text generation task is calculated to obtain the total loss value, and the parameters of the drug knowledge graph construction model are updated based on the total loss value.
[0104] The method for constructing a drug knowledge graph provided by an embodiment of the present invention includes: obtaining a drug instruction manual text, and vectorizing the characters in the drug instruction manual text to obtain a word vector sequence including multiple word vectors, using a multi-head attention mechanism to process the word vector sequence to obtain a feature vector sequence including multiple feature vectors, calculating a first probability value of the character as each entity label based on the feature vector, and determining the entity corresponding to the character based on the first probability value, calculating a second probability value of the relationship between the entity and other entities in the drug instruction manual text based on the feature vector and the first probability value, and determining the relationship between the entity and other entities in the drug instruction manual text based on the second probability value, and generating a description text for describing the relationship between the entity and other entities in the drug instruction manual text based on the autoregression of the word vector sequence, which can reduce costs and improve accuracy.
[0105] Figure 5 A schematic diagram of the structure of a drug knowledge graph construction device provided by an embodiment of the present invention, such as Figure 5 As shown, the drug knowledge graph construction device includes:
[0106] A vectorization module 201 is used to obtain a drug instruction text and vectorize characters in the drug instruction text to obtain a word vector sequence including a plurality of word vectors;
[0107] An attention module 202 is used to process the word vector sequence using a multi-head attention mechanism to obtain a feature vector sequence including multiple feature vectors;
[0108] An entity determination module 203, configured to calculate a first probability value of the character being each entity label based on the feature vector, and determine the entity corresponding to the character based on the first probability value;
[0109] An entity relationship determination module 204, configured to calculate a second probability value of a relationship between the entity and other entities in the drug instruction text based on the feature vector and the first probability value, and determine the relationship between the entity and other entities in the drug instruction text based on the second probability value;
[0110] The description text generation module 205 is used to generate description text for describing the relationship between the entity and other entities in the drug instruction manual text based on the word vector sequence autoregression.
[0111] In some embodiments of the present invention, the vectorization module 201 includes:
[0112] A word embedding submodule, used for embedding characters in the drug instructions text to obtain a word embedding vector;
[0113] A position embedding submodule, used for embedding the characters in the drug instructions text to obtain a position embedding vector;
[0114] A vector fusion submodule, used to fuse the word embedding vector and the position embedding vector to obtain a word vector representing the character;
[0115] The word vector sequence determination submodule is used to arrange the word vectors of the multiple characters according to the word order to obtain a word vector sequence including multiple word vectors.
[0116] In some embodiments of the present invention, the attention module 202 includes:
[0117] An attention encoding submodule is used to input the word vector sequence into an encoding module including multiple transformers stacked in sequence for processing, so as to obtain a feature vector sequence including multiple feature vectors, wherein the transformer processes the input features based on a multi-head attention mechanism, and the output features of the previous transformer are used as the input features of the next transformer.
[0118] In some embodiments of the present invention, the transformer includes a multi-head attention layer, a first normalization layer, a feedforward layer, and a second normalization layer. The transformer processes the input features based on the multi-head attention mechanism as follows:
[0119] In the multi-head attention layer, the input features are processed based on the multi-head attention mechanism to obtain attention features;
[0120] Fusing the attention feature with the input feature to obtain a first fused feature;
[0121] Normalizing the first fused features in the first normalization layer to obtain first normalized features;
[0122] Performing full connection mapping on the first normalized feature in the feed-forward layer to obtain a fully connected feature;
[0123] Fusing the first normalized feature with the fully connected feature to obtain a second fused feature;
[0124] The second fused features are normalized in the second normalization layer to obtain output features of the transformer.
[0125] In some embodiments of the present invention, the entity determination module 203 includes:
[0126] A first linearization submodule is used for inputting each of the feature vectors into a first linearization layer for linearization processing to obtain a first space vector;
[0127] A first activation submodule, configured to input the first space vector into a first activation function layer for activation processing, and obtain a first probability value of the character being each entity label;
[0128] The entity determination submodule is used to use the entity label corresponding to the maximum value as the entity corresponding to the character when the maximum value of the first probability value is greater than a preset value.
[0129] In some embodiments of the present invention, the entity relationship determination module 204 includes:
[0130] A first linearization submodule is used for inputting each of the feature vectors into a first linearization layer for linearization processing to obtain a first space vector;
[0131] A first activation submodule, configured to input the first space vector into a first activation function layer for activation processing, and obtain a first probability value of the character being each entity label;
[0132] An entity determination submodule, configured to, when a maximum value of the first probability value is greater than a preset value, use an entity label corresponding to the maximum value as an entity corresponding to the character;
[0133] A correlation calculation submodule, used to calculate the correlation between the entity and other entities in the drug instruction manual text to obtain a correlation vector;
[0134] A second linearization submodule, used for inputting the correlation vector into a second linearization layer for linearization processing to obtain a second space vector;
[0135] A second activation submodule, configured to input the second space vector into a second activation function layer for activation processing, and obtain a second probability value of the relationship between the entity and other entities in the drug instruction manual text;
[0136] The entity relationship determination submodule is used to use the relationship corresponding to the maximum value in the second probability value as the relationship between the entity and the target entity, wherein the target entity is the entity corresponding to the maximum value in the second probability value.
[0137] In some embodiments of the present invention, the description text generation module 205 includes:
[0138] A sequence fusion submodule, used to fuse the word vector sequence and the initialized output text sequence to obtain a fused sequence;
[0139] An intermediate vector determination submodule, used for processing the fused sequence using a multi-head attention mechanism to obtain an intermediate vector;
[0140] A calculation submodule, configured to calculate, based on the intermediate vector, a third probability value of the output character being each sample character in the vocabulary;
[0141] an output character determination submodule, configured to take a sample character corresponding to a maximum value among the third probability values as an output character;
[0142] The execution submodule is returned to convert the output character into a vector, update the output text sequence, and return to execute the step of fusing the word vector sequence and the initialized output text sequence to obtain a fused sequence until the output character is a terminator.
[0143] The above-mentioned drug knowledge graph construction device can execute the drug knowledge graph construction method provided by the aforementioned embodiment of the present invention, and has the corresponding functional modules and beneficial effects for executing the drug knowledge graph construction method.
[0144] Figure 6 A schematic diagram of the structure of an electronic device provided for an embodiment of the present invention. The electronic device is intended to represent various forms of digital computers, such as laptop computers, desktop computers, workstations, personal digital assistants, servers, blade servers, mainframe computers, and other suitable computers. The electronic device may also represent various forms of mobile devices, such as personal digital processing, cellular phones, smart phones, wearable devices (such as helmets, glasses, watches, etc.) and other similar computing devices. The components shown herein, their connections and relationships, and their functions are merely examples and are not intended to limit the implementation of the present invention described and / or required herein.
[0145] like Figure 6As shown, the electronic device includes at least one processor 11, and a memory connected to the at least one processor 11, such as a read-only memory (ROM) 12, a random access memory (RAM) 13, etc., wherein the memory stores a computer program that can be executed by at least one processor, and the processor 11 can perform various appropriate actions and processes according to the computer program stored in the read-only memory (ROM) 12 or the computer program loaded from the storage unit 18 to the random access memory (RAM) 13. In the RAM 13, various programs and data required for the operation of the electronic device can also be stored. The processor 11, the ROM 12, and the RAM 13 are connected to each other through a bus 14. An input / output (I / O) interface 15 is also connected to the bus 14.
[0146] A number of components in the electronic device are connected to the I / O interface 15, including: an input unit 16, such as a keyboard, a mouse, etc.; an output unit 17, such as various types of displays, speakers, etc.; a storage unit 18, such as a disk, an optical disk, etc.; and a communication unit 19, such as a network card, a modem, a wireless communication transceiver, etc. The communication unit 19 allows the electronic device to exchange information / data with other devices through a computer network such as the Internet and / or various telecommunication networks.
[0147] The processor 11 may be a variety of general and / or special processing components with processing and computing capabilities. Some examples of the processor 11 include, but are not limited to, a central processing unit (CPU), a graphics processing unit (GPU), various dedicated artificial intelligence (AI) computing chips, various processors running machine learning model algorithms, a digital signal processor (DSP), and any appropriate processor, controller, microcontroller, etc. The processor 11 executes the various methods and processes described above, such as a method for constructing a drug knowledge graph.
[0148] In some embodiments, the method for constructing a drug knowledge graph may be implemented as a computer program, which is tangibly contained in a computer-readable storage medium, such as a storage unit 18. In some embodiments, part or all of the computer program may be loaded and / or installed on an electronic device via ROM 12 and / or communication unit 19. When the computer program is loaded into RAM 13 and executed by processor 11, one or more steps of the method for constructing a drug knowledge graph described above may be performed. Alternatively, in other embodiments, the processor 11 may be configured to execute the method for constructing a drug knowledge graph in any other appropriate manner (e.g., by means of firmware).
[0149] Various implementations of the systems and techniques described above herein can be implemented in digital electronic circuit systems, integrated circuit systems, field programmable gate arrays (FPGAs), application specific integrated circuits (ASICs), application specific standard products (ASSPs), systems on chips (SOCs), load programmable logic devices (CPLDs), computer hardware, firmware, software, and / or combinations thereof. These various implementations can include: being implemented in one or more computer programs that can be executed and / or interpreted on a programmable system including at least one programmable processor, which can be a special purpose or general purpose programmable processor that can receive data and instructions from a storage system, at least one input device, and at least one output device, and transmit data and instructions to the storage system, the at least one input device, and the at least one output device.
[0150] Computer programs for implementing the methods of the present invention may be written in any combination of one or more programming languages. These computer programs may be provided to a processor of a general-purpose computer, a special-purpose computer, or other programmable data processing device, so that when the computer program is executed by the processor, the functions / operations specified in the flow chart and / or block diagram are implemented. The computer program may be executed entirely on the machine, partially on the machine, partially on the machine and partially on a remote machine as a stand-alone software package, or entirely on a remote machine or server.
[0151] In the context of the present invention, a computer-readable storage medium may be a tangible medium that may contain or store a computer program for use by or in combination with an instruction execution system, device or equipment. A computer-readable storage medium may include, but is not limited to, electronic, magnetic, optical, electromagnetic, infrared, or semiconductor systems, devices or equipment, or any suitable combination of the foregoing. Alternatively, a computer-readable storage medium may be a machine-readable signal medium. A more specific example of a machine-readable storage medium may include an electrical connection based on one or more lines, a portable computer disk, a hard disk, a random access memory (RAM), a read-only memory (ROM), an erasable programmable read-only memory (EPROM or flash memory), an optical fiber, a portable compact disk read-only memory (CD-ROM), an optical storage device, a magnetic storage device, or any suitable combination of the foregoing.
[0152] To provide interaction with a user, the systems and techniques described herein may be implemented on an electronic device having: a display device (e.g., a CRT (cathode ray tube) or LCD (liquid crystal display) monitor) for displaying information to the user; and a keyboard and a pointing device (e.g., a mouse or trackball) through which the user can provide input to the electronic device. Other types of devices may also be used to provide interaction with the user; for example, the feedback provided to the user may be any form of sensory feedback (e.g., visual feedback, auditory feedback, or tactile feedback); and input from the user may be received in any form (including acoustic input, voice input, or tactile input).
[0153] The systems and techniques described herein may be implemented in a computing system that includes backend components (e.g., as a data server), or a computing system that includes middleware components (e.g., an application server), or a computing system that includes frontend components (e.g., a user computer with a graphical user interface or a web browser through which a user can interact with implementations of the systems and techniques described herein), or a computing system that includes any combination of such backend components, middleware components, or frontend components. The components of the system may be interconnected by any form or medium of digital data communication (e.g., a communication network). Examples of communication networks include: a local area network (LAN), a wide area network (WAN), a blockchain network, and the Internet.
[0154] A computing system may include a client and a server. The client and the server are generally remote from each other and usually interact through a communication network. The client and server relationship is generated by computer programs running on the corresponding computers and having a client-server relationship with each other. The server may be a cloud server, also known as a cloud computing server or cloud host, which is a host product in the cloud computing service system to solve the defects of difficult management and weak business scalability in traditional physical hosts and VPS services.
[0155] An embodiment of the present invention also provides a computer program product, including a computer program, which, when executed by a processor, implements a method for constructing a drug knowledge graph as provided in any embodiment of the present application.
[0156] In the process of implementation, the computer program product can be written in one or more programming languages or a combination thereof to perform the computer program code of the present invention, including object-oriented programming languages, such as Java, Smalltalk, C++, and conventional procedural programming languages, such as "C" language or similar programming languages. The program code can be executed entirely on the user's computer, partially on the user's computer, as a separate software package, partially on the user's computer and partially on a remote computer, or entirely on a remote computer or server. In the case of a remote computer, the remote computer can be connected to the user's computer through any type of network, including a local area network (LAN) or a wide area network (WAN), or can be connected to an external computer (for example, using an Internet service provider to connect through the Internet).
[0157] It should be understood that the various forms of processes shown above can be used to reorder, add or delete steps. For example, the steps described in the present invention can be executed in parallel, sequentially or in different orders, as long as the desired results of the technical solution of the present invention can be achieved, and this document does not limit this.
[0158] The above specific implementations do not constitute a limitation on the protection scope of the present invention. It should be understood by those skilled in the art that various modifications, combinations, sub-combinations and substitutions can be made according to design requirements and other factors. Any modification, equivalent substitution and improvement made within the spirit and principle of the present invention should be included in the protection scope of the present invention.
Claims
1. A method for constructing a drug knowledge graph, characterized in that: include: Obtaining a drug instruction manual text, and vectorizing characters in the drug instruction manual text to obtain a word vector sequence including a plurality of word vectors; Using a multi-head attention mechanism to process the word vector sequence to obtain a feature vector sequence including multiple feature vectors; Calculate a first probability value that the character is each entity label based on the feature vector, and determine the entity corresponding to the character based on the first probability value; Calculating a second probability value of the relationship between the entity and other entities in the drug instruction text based on the feature vector and the first probability value, and determining the relationship between the entity and other entities in the drug instruction text based on the second probability value; Generate a description text for describing the relationship between the entity and other entities in the drug instruction manual text based on the word vector sequence autoregression; Calculating a second probability value of the relationship between the entity and other entities in the drug instruction text based on the feature vector and the first probability value, and determining the relationship between the entity and other entities in the drug instruction text based on the second probability value, including: For each of the eigenvectors, input the eigenvector into a first linearization layer for linearization processing to obtain a first space vector; Inputting the first space vector into a first activation function layer for activation processing to obtain a first probability value of the character being each entity label; When the maximum value of the first probability value is greater than a preset value, taking the entity label corresponding to the maximum value as the entity corresponding to the character; Calculating the correlation between the entity and other entities in the drug instruction manual text to obtain a correlation vector; Inputting the correlation vector into a second linearization layer for linearization processing to obtain a second space vector; Inputting the second space vector into a second activation function layer for activation processing to obtain a second probability value of the relationship between the entity and other entities in the drug instruction manual text; The relationship corresponding to the maximum value in the second probability value is used as the relationship between the entity and the target entity, wherein the target entity is the entity corresponding to the maximum value in the second probability value; Generate a description text for describing the relationship between the entity and other entities in the drug instruction manual text based on the word vector sequence autoregression, including: Fusing the word vector sequence and the initialized output text sequence to obtain a fused sequence; Using a multi-head attention mechanism to process the fused sequence to obtain an intermediate vector; Calculate, based on the intermediate vector, a third probability value that the output character is each sample character in the vocabulary; Taking the sample character corresponding to the maximum value of the third probability value as the output character; The output character is converted into a vector, the output text sequence is updated, and the step of fusing the word vector sequence and the output text sequence to obtain a fused sequence is returned until the output character is a terminator.
2. The method for constructing a drug knowledge graph according to claim 1, characterized in that: The characters in the drug instruction manual text are vectorized to obtain a word vector sequence including multiple word vectors, including: Performing word embedding on the characters in the drug instructions text to obtain a word embedding vector; Performing position embedding on the characters in the drug instructions text to obtain a position embedding vector; The word embedding vector and the position embedding vector are merged to obtain a word vector representing the character; Arrange the word vectors of the multiple characters according to word order to obtain a word vector sequence including the multiple word vectors.
3. The method for constructing a drug knowledge graph according to claim 1 or 2, characterized in that: The word vector sequence is processed using a multi-head attention mechanism to obtain a feature vector sequence including multiple feature vectors, including: The word vector sequence is input into an encoding module including multiple transformers stacked in sequence for processing to obtain a feature vector sequence including multiple feature vectors, wherein the transformer processes the input features based on a multi-head attention mechanism, and the output features of the previous transformer are used as the input features of the next transformer.
4. The method for constructing a drug knowledge graph according to claim 3, characterized in that: The transformer includes a multi-head attention layer, a first normalization layer, a feedforward layer, and a second normalization layer. The transformer processes the input features based on the multi-head attention mechanism as follows: In the multi-head attention layer, the input features are processed based on the multi-head attention mechanism to obtain attention features; Fusing the attention feature with the input feature to obtain a first fused feature; Normalizing the first fused features in the first normalization layer to obtain first normalized features; Performing full connection mapping on the first normalized feature in the feed-forward layer to obtain a fully connected feature; Fusing the first normalized feature with the fully connected feature to obtain a second fused feature; The second fused features are normalized in the second normalization layer to obtain output features of the transformer.
5. The method for constructing a drug knowledge graph according to claim 1, 2 or 4, characterized in that: Calculating a first probability value of the character being each entity label based on the feature vector, and determining an entity corresponding to the character based on the first probability value, including: For each of the eigenvectors, input the eigenvector into a first linearization layer for linearization processing to obtain a first space vector; Inputting the first space vector into a first activation function layer for activation processing to obtain a first probability value of the character being each entity label; When the maximum value of the first probability value is greater than a preset value, the entity label corresponding to the maximum value is used as the entity corresponding to the character.
6. A drug knowledge graph construction device, characterized in that: include: A vectorization module, used for obtaining a drug instruction text and vectorizing characters in the drug instruction text to obtain a word vector sequence including a plurality of word vectors; An attention module, used for processing the word vector sequence using a multi-head attention mechanism to obtain a feature vector sequence including multiple feature vectors; An entity determination module, configured to calculate a first probability value of the character being each entity label based on the feature vector, and determine the entity corresponding to the character based on the first probability value; an entity relationship determination module, configured to calculate a second probability value of a relationship between the entity and other entities in the drug instruction text based on the feature vector and the first probability value, and determine the relationship between the entity and other entities in the drug instruction text based on the second probability value; A description text generation module, used for generating a description text for describing the relationship between the entity and other entities in the drug instruction manual text based on the word vector sequence autoregression; The entity relationship determination module includes: A first linearization submodule is used for inputting each of the feature vectors into a first linearization layer for linearization processing to obtain a first space vector; A first activation submodule, configured to input the first space vector into a first activation function layer for activation processing, and obtain a first probability value of the character being each entity label; An entity determination submodule, configured to, when a maximum value of the first probability value is greater than a preset value, use an entity label corresponding to the maximum value as an entity corresponding to the character; A correlation calculation submodule, used to calculate the correlation between the entity and other entities in the drug instruction manual text to obtain a correlation vector; A second linearization submodule, used for inputting the correlation vector into a second linearization layer for linearization processing to obtain a second space vector; A second activation submodule, configured to input the second space vector into a second activation function layer for activation processing, and obtain a second probability value of the relationship between the entity and other entities in the drug instruction manual text; an entity relationship determination submodule, configured to use the relationship corresponding to the maximum value in the second probability value as the relationship between the entity and the target entity, wherein the target entity is the entity corresponding to the maximum value in the second probability value; The description text generation module includes: A sequence fusion submodule, used to fuse the word vector sequence and the initialized output text sequence to obtain a fused sequence; An intermediate vector determination submodule, used for processing the fused sequence using a multi-head attention mechanism to obtain an intermediate vector; A calculation submodule, configured to calculate, based on the intermediate vector, a third probability value of the output character being each sample character in the vocabulary; an output character determination submodule, configured to take a sample character corresponding to a maximum value among the third probability values as an output character; The execution submodule is returned to convert the output character into a vector, update the output text sequence, and return to execute the step of fusing the word vector sequence and the initialized output text sequence to obtain a fused sequence until the output character is a terminator.
7. An electronic device, characterized in that: include: one or more processors; A storage device for storing one or more programs; When the one or more programs are executed by the one or more processors, the one or more processors implement the drug knowledge graph construction method as described in any one of claims 1-5.
8. A computer-readable storage medium having a computer program stored thereon, characterized in that: When the program is executed by a processor, the method for constructing a drug knowledge graph as described in any one of claims 1 to 5 is implemented.
Citation Information
Patent Citations
Text generation method and device, electronic equipment and storage medium
CN116303940A
Knowledge graph construction method and device, storage medium and computer equipment
CN116595971A
