Entity extraction method, device, electronic device and storage medium
By using pre-set extraction models and prior knowledge in the knowledge graph construction, the optimal extraction results of the text to be extracted are obtained, and the problems of low accuracy of entity extraction and high labor consumption in the prior art are solved, and more efficient and accurate entity extraction is achieved.
Patent Information
- Application Number
- CN202111598982.5
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2021-12-24
- Publication Date
- 2025-03-25
- Estimated Expiration
- 2041-12-24
AI Technical Summary
When the prior art uses plain text data to build knowledge graphs, the accuracy of entity extraction is low, and a large number of professionals are required to maintain rule templates, which consumes a lot of manpower.
By obtaining the prior knowledge of the text to be extracted and the preset, input the preset first extraction model and the second extraction model to obtain the optimal extraction result, including entity, type, subject-object type and location.
It improves the accuracy of entity extraction, reduces dependence on professionals, and reduces manpower consumption.
Smart Images

Figure CN114265919B_ABST
Abstract
Description
Technical Field
[0001] The present application relates to the field of data processing technology, and in particular to an entity extraction method, device, electronic device and storage medium. Background Art
[0002] At present, the method of building a knowledge graph using plain text data is to use relatively static entity dictionaries and rule templates to obtain entities and entity relationships. This method has poor timeliness. If the entities in the threat intelligence are not updated to the entity dictionary, the entities will be missed; if the rule templates in the threat intelligence fail to cover the types, there will also be missed labels, resulting in reduced accuracy. In addition, the method of obtaining entities and entity relationships through rule templates requires a large number of professionals to maintain the rule templates, which consumes a lot of manpower. In addition, in recent years, the construction of knowledge graphs has borrowed the idea of deep learning and used the BiLSTM+CRF method for knowledge extraction. Although the accuracy has improved, it still cannot meet the requirements of use. Summary of the invention
[0003] The purpose of the embodiments of the present application is to provide an entity extraction method, device, electronic device and storage medium to improve the problem of "poor accuracy of entity extraction in the prior art".
[0004] The present invention is achieved in that:
[0005] In a first aspect, an embodiment of the present application provides an entity extraction method, the method comprising: obtaining first input data, the first input data comprising a text to be extracted and preset prior knowledge, the prior knowledge comprising vocabulary for defining entities or characterizing entity types; obtaining second input data, the second input data comprising the text to be extracted and entities and entity types identified in the text to be extracted; inputting the first input data into a preset first extraction model to obtain a first extraction result, the first extraction result comprising each extracted entity and the type, position and probability of the entity; inputting the second input data into a preset second extraction model to obtain a second extraction result, the second extraction result comprising the type, position, subject and object type and probability of each extracted entity; obtaining an optimal extraction result based on the first extraction result and the second extraction result, the optimal extraction result comprising each entity corresponding to the text to be extracted and the type, subject and object type and position of the entity.
[0006] In the embodiment of the present application, by inputting the first input data into a pre-set first extraction model to obtain the first extraction result, and inputting the second input data into a pre-set second extraction model to obtain the second extraction result, the first extraction model can understand the semantics of the text to be extracted more quickly and accurately based on the prior knowledge of the first input data, and the second extraction model can understand the entities and entity types marked in the second input data based on the entities, thereby improving the accuracy of extracting entities from the text to be extracted. Moreover, based on the first extraction result and the second extraction result, the optimal extraction result can be obtained, thereby further improving the accuracy of extracting entities from the text to be extracted.
[0007] In combination with the technical solution provided in the first aspect above, in some possible implementations, obtaining the first input data includes: concatenating the text to be extracted with each definition text in a preset entity definition library to obtain the first input data; or concatenating the text to be extracted with preset words representing each entity type to obtain the first input data.
[0008] In the embodiment of the present application, the first input data can be quickly and accurately acquired in this manner.
[0009] In combination with the technical solution provided in the first aspect above, in some possible implementation methods, obtaining the second input data includes: matching the text to be extracted through an AC automaton to obtain the entity corresponding to the text to be extracted and the type corresponding to the entity; splicing the text to be extracted and the matched entity and the type corresponding to the entity to obtain the second input data.
[0010] In the embodiment of the present application, the second input data can be quickly and accurately acquired in this manner.
[0011] In combination with the technical solution provided in the first aspect above, in some possible implementation methods, the first extraction model is obtained according to the following steps: obtain a first training set, the first training set includes a first training sample and a first label, the first training sample is a text after the preset text and the prior knowledge are respectively spliced, and the first label is the text after the preset text is entity labeled; use the first training set to train the initial first extraction model to obtain the first extraction model.
[0012] In combination with the technical solution provided in the first aspect above, in some possible implementation methods, the second extraction model is obtained according to the following steps: obtaining a second training set, the second training set including a second training sample and a second label, the second training sample being a text obtained by matching a preset text with a corresponding entity and a type corresponding to the entity through an AC automaton and concatenating the text with the preset text, and the second label being a text obtained by entity annotating the preset text; using the second training set to train the initial second extraction model to obtain the second extraction model.
[0013] In combination with the technical solution provided in the first aspect above, in some possible implementation methods, obtaining the optimal extraction result based on the first extraction result and the second extraction result includes: calculating the probability of each entity in the first extraction result and the probability of each entity in the second extraction result according to the preset weight ratio of the first extraction model and the first extraction model, and obtaining the total probability corresponding to each entity; comparing the total probability with a preset threshold, obtaining the entity whose total probability is greater than the preset threshold and the type, host and guest type and position corresponding to the entity, and the optimal extraction result includes all entities whose total probability is greater than the preset threshold and the type, host and guest type and position corresponding to the entity.
[0014] In an embodiment of the present application, through the above method, the accuracy of extracting entities according to the first extraction model and the second extraction model can be used, and the output results of the two (i.e., the first extraction result and the second extraction result) can be fused, thereby improving the accuracy of the optimal extraction result obtained.
[0015] In combination with the technical solution provided in the first aspect above, in some possible implementations, the method further includes: obtaining an entity pair based on each entity in the optimal extraction result; marking the text to be extracted based on the entity pair and the optimal extraction result; inputting the marked text to be extracted into a preset RoBERTa model to obtain the encoding of each entity in the entity pair; splicing the encoding corresponding to the first character of each entity in the entity pair, and performing relationship classification on the spliced encoding according to a preset classification algorithm to obtain the entity relationship corresponding to the entity pair.
[0016] In the embodiment of the present application, since the optimal extraction result with a high accuracy is obtained, and the optimal extraction result includes each entity corresponding to the text to be extracted and the type, subject and object type and position of the entity, the corresponding entity pair is obtained according to each entity in the optimal extraction result, which can improve the accuracy of the obtained entity pair, that is, each entity pair can be more accurately obtained according to the optimal extraction result. In addition, by marking the text to be extracted according to the optimal extraction result and the extracted entity pair, and inputting the marked text to be extracted into a pre-set RoBERTa model to obtain the encoding of each entity in the entity pair; then the encoding corresponding to the first character of each entity in the entity pair is spliced, and the spliced encoding is classified according to the preset classification algorithm, so that the entity relationship corresponding to the entity pair can be accurately obtained according to the marked text to be extracted.
[0017] In a second aspect, an embodiment of the present application provides an entity extraction device, the device comprising: an acquisition module, used to acquire first input data, the first input data including a text to be extracted and preset prior knowledge, the prior knowledge including vocabulary that defines each entity or characterizes each entity type; acquiring second input data, the second input data including the text to be extracted and entities and entity types that have been identified in the text to be extracted; an extraction module, used to input the first input data into a preset first extraction model to acquire a first extraction result, the first extraction result including each extracted entity and the type, position and probability of the entity; input the second input data into a preset second extraction model to acquire a second extraction result, the second extraction result including the type, position, subject and object type and probability of each extracted entity; a processing module, used to acquire an optimal extraction result based on the first extraction result and the second extraction result, the optimal extraction result including each entity corresponding to the text to be extracted and the type, subject and object type and position of the entity.
[0018] In a third aspect, an embodiment of the present application provides an electronic device, comprising: a processor and a memory, wherein the processor and the memory are connected; the memory is used to store programs; the processor is used to call the programs stored in the memory to execute the method provided in the above-mentioned first aspect embodiment and / or in combination with some possible implementation methods of the above-mentioned first aspect embodiment.
[0019] In a fourth aspect, an embodiment of the present application provides a computer-readable storage medium having a computer program stored thereon, which, when executed by a processor, executes a method provided in the embodiment of the first aspect above and / or in combination with some possible implementations of the embodiment of the first aspect above. BRIEF DESCRIPTION OF THE DRAWINGS
[0020] In order to more clearly illustrate the technical solutions of the embodiments of the present application, the drawings required for use in the embodiments of the present application will be briefly introduced below. It should be understood that the following drawings only show certain embodiments of the present application and therefore should not be regarded as limiting the scope. For ordinary technicians in this field, other related drawings can be obtained based on these drawings without paying creative work.
[0021] Figure 1 A flowchart of the steps of an entity extraction method provided in an embodiment of the present application.
[0022] Figure 2 A module block diagram of an entity extraction device provided in an embodiment of the present application.
[0023] Figure 3 A module block diagram of an electronic device provided in an embodiment of the present application. DETAILED DESCRIPTION
[0024] The technical solutions in the embodiments of the present application will be described below in conjunction with the drawings in the embodiments of the present application.
[0025] In view of the poor accuracy of entity extraction in the prior art, the inventors of the present application have proposed the following embodiments to solve the above problems after research and exploration.
[0026] The embodiment of the present application provides an entity extraction method for extracting entities from plain text data. The entity extraction method includes a pre-set first extraction model and a second extraction model. To facilitate the subsequent description of the entity extraction method, the acquisition of the first extraction model and the second extraction model is first described below.
[0027] The steps for obtaining the first extraction model are:
[0028] A first training set is obtained, the first training set includes a first training sample and a first label, the first training sample is a text obtained by concatenating a preset text with various prior knowledge, and the first label is a text obtained by entity annotating the preset text; an initial first extraction model is trained using the first training set to obtain a first extraction model.
[0029] For example: The preset text is: The relevant research team has recently discovered a new C-type remote access Trojan horse variant, which is associated with Group B in a certain country and is specially designed for Operating System A.
[0030] When the prior knowledge includes the definition of computer virus, organization and operating system, the first training samples are: "[CLS] A computer virus is a set of computer instructions or program codes that are inserted by the compiler into a computer program to destroy computer functions or data, affect the normal use of the computer and can replicate itself (i.e., the definition of computer virus) [SEP] The relevant research team has recently discovered a new type of C remote access Trojan horse variant, which is associated with Group B in a certain country and is specially designed for Operating System A. [SEP]", "[CLS] An organization is an organic whole composed of two or more individuals to achieve a common goal (i.e., the definition of organization) [SEP] The relevant research team has recently discovered a new type of C remote access Trojan horse variant, which is associated with Group B in a certain country and is specially designed for Operating System A. [SEP]" and "[CLS] An operating system is a computer program that manages computer hardware and software resources (i.e., the definition of operating system) [SEP] The relevant research team has recently discovered a new type of C remote access Trojan horse variant, which is associated with Group B in a certain country and is specially designed for Operating System A. [SEP]".
[0031] When the prior knowledge is computer virus, organization and operating system (i.e., the vocabulary that characterizes each entity type), the first training samples are: "[CLS] Computer virus [SEP] The relevant research team has recently discovered a new C-type remote access Trojan horse variant, which is associated with Group B in a certain country and is specially designed for Operating System A. [SEP]", "[CLS] Organization [SEP] The relevant research team has recently discovered a new C-type remote access Trojan horse variant, which is associated with Group B in a certain country and is specially designed for Operating System A. [SEP]" and "[CLS] Operating system [SEP] The relevant research team has recently discovered a new C-type remote access Trojan horse variant, which is associated with Group B in a certain country and is specially designed for Operating System A. [SEP]".
[0032] It should be noted that each prior knowledge can be spliced at the beginning or at the end of the preset text, which is not limited here. In addition, when splicing the prior knowledge of the preset text, it is necessary to add corresponding separators to the spliced prior knowledge and the preset text, that is, [CLS] and [SEP] in the above example, where [CLS] is used to be placed at the first position of the spliced text, and [SEP] is used to separate the prior knowledge and the preset text.
[0033] Furthermore, the first label is the text after the preset text is entity-annotated, that is, the entity corresponding to the preset text and the type corresponding to the entity need to be marked in the preset text, and according to the annotated text, the position of the entity in the preset text, that is, the starting position and the ending position of the entity in the preset text can also be obtained. Continuing with the above preset text as an example, Chinese characters are calculated as one character corresponding to one position, and English letters are calculated as one letter corresponding to one position. Then, the position corresponding to Class C in the preset text is "16 20", and the position corresponding to the Trojan horse variant in the preset text is "25 31". In addition, the entity types of Class C and Trojan horse variants in the preset text are computer viruses, the entity type of B is organization, and the entity type of A is operating system. It should be noted that when setting the first label, the BIESO label system can be used for labeling. The BIESO label system is a labeling method well known to those skilled in the art and will not be described here.
[0034] It should be noted that the first extraction model adopts the RoBERTa pre-trained model and two classifiers, wherein the task layer is the above two classifiers. Specifically, the task layer trains the above two classifiers, which are respectively used to predict the start position and the end position of the entity span, and obtains the loss value LossA of the initial first extraction model based on the prediction results. LossA is the sum of the loss values of the two classifiers. For example: for the loss value of the classifier predicting the start position of the entity span, loss(Start)=CE(prediction start, label start), for the loss value of the classifier predicting the end position of the entity span, loss(End)=CE(prediction end, label end), the loss value LossA=loss(Start)+loss(End). The initial first extraction model is trained with the first training set to obtain the first extraction model. The above-mentioned RoBERTa pre-trained model structure, the above-mentioned training method and the above-mentioned classifier can adopt the commonly used technical means in this field, which will not be described here.
[0035] The steps for obtaining the second extraction model are:
[0036] Obtain a second training set, the second training set includes a second training sample and a second label, the second training sample is a text obtained by matching the preset text with the corresponding entity and the type corresponding to the entity through the AC automaton and concatenating it with the preset text, and the second label is a text after the preset text is annotated with entities; use the second training set to train the initial second extraction model to obtain a second extraction model. It should be noted that there is a preset entity library for the matching of the AC automaton, and a plurality of entities are pre-set in the entity library. When the preset text is matched through the AC automaton, it is matched according to each entity in the above entity library.
[0037] For example, the preset text is: The relevant research team has recently discovered a new C-type remote access Trojan horse variant, which is associated with Group B in a certain country and is specially designed for A operating system. The preset text can be used by the AC automaton to obtain four entities: Class C (computer virus, vul), Trojan horse variant (computer virus, vul), B (organization, org) and A (operating system, sys) and the entity type corresponding to each entity. Then the second training sample is "The relevant research team has recently discovered a new C-type remote access Trojan horse variant, which is associated with Group B in a certain country and is specially designed for A operating system. <vul> Category C< / vul> <vul> Trojan horse variants< / vul> <org> B< / org> <sys> A< / sys> . ".
[0038] It should be noted that the matched entities and the entity type of the entity can be spliced at the beginning of the preset text or at the end of the preset text, which is not limited here.
[0039] Furthermore, the second tag is the same as the first tag, which is the text after the preset text is annotated with entities, that is, the entity corresponding to the preset text and the type corresponding to the entity need to be marked in the preset text, and according to the annotated text, the position of the entity in the preset text can also be obtained, that is, the starting position and the ending position of the entity in the preset text. In order to avoid redundancy, it will not be explained here, and please refer to the description of the first tag for the second tag.
[0040] The initial second extraction model is trained by the second training set to obtain the second extraction model. The above training method can adopt a training method well known to those skilled in the art, which will not be described here.
[0041] It should be noted that the above-mentioned preset text can be a plurality of different texts, and the above-mentioned prior knowledge can include a plurality of different entity definitions or a plurality of different words representing each entity type, and the number is not limited here. It should also be noted that the above-mentioned second extraction model adopts the RoBERTa pre-training model and the CRF model, wherein the CRF model is the task layer. The RoBERTa pre-training model structure and the CRF model structure are well known to those skilled in the art and will not be described here.
[0042] After the first extraction model and the second extraction model are obtained, the first extraction model and the second extraction model can be used to extract entities from the plain text data. The specific process and steps of the above entity extraction method are described below in conjunction with FIG.
[0043] It should be noted that the entity extraction method provided in the embodiment of the present application is not limited to the order shown in Figure 1 and below.
[0044] Step S101: obtaining first input data, where the first input data includes text to be extracted and various preset prior knowledge.
[0045] Prior knowledge includes definitions of entities or words that represent entity types. The text to be extracted is a preprocessed text, which includes uppercase and lowercase letter conversion, special symbol removal, and conversion of uncommon nouns in the text to be extracted into common nouns.
[0046] Specifically, the text to be extracted is concatenated with each definition text in a preset entity definition library to obtain the first input data; or, the text to be extracted is concatenated with preset words representing each entity type to obtain the first input data.
[0047] For example, the text to be extracted is: It was recently discovered that the M variant is associated with the D organization.
[0048] When the prior knowledge is defined for each entity, and the definition text in the entity definition library includes: security vulnerability definition text and organization definition text, the first input data is "[CLS] Security vulnerability refers to a defect or error in the logical design of system software, which is exploited by criminals to attack or control the entire computer (i.e., security vulnerability definition) [SEP] Recently, it was discovered that the M variant is associated with the D organization. [SEP]" and "[CLS] An organization is an organic whole composed of two or more individuals to achieve a common goal (i.e., organization definition) [SEP] Recently, it was discovered that the M variant is associated with the D organization. [SEP]".
[0049] When the prior knowledge is the vocabulary that represents each entity type, and the preset vocabulary is security vulnerability and organization, the first input data is "[CLS] Security vulnerability [SEP] Recently discovered M variant is associated with D organization. [SEP]" and "[CLS] Organization [SEP] Recently discovered M variant is associated with D organization. [SEP]".
[0050] It should be noted that each definition text or each word representing each entity type can be spliced at the beginning or the end of the text to be extracted, and there is no limitation here. In addition, when performing prior knowledge splicing on the text to be extracted, it is necessary to add corresponding separators to the spliced prior knowledge and the text to be extracted, that is, [CLS] and [SEP] in the above examples, where [CLS] is used to be placed at the first position of the spliced text, and [SEP] is used to separate the prior knowledge and the text to be extracted.
[0051] Through the above method, the first input data can be quickly and accurately acquired.
[0052] Step S102: Acquire second input data, where the second input data includes the text to be extracted and the entities and entity types identified in the text to be extracted.
[0053] Specifically, the text to be extracted is matched by the AC automaton to obtain the entity corresponding to the text to be extracted and the type corresponding to the entity; the text to be extracted and the matched entity and the type corresponding to the entity are concatenated to obtain the second input data. It should be noted that there is a preset entity library for the matching of the AC automaton, and a plurality of entities are pre-set in the entity library. When the text to be extracted is matched by the AC automaton, the matching is performed according to the entities in the above entity library.
[0054] For example, the text to be extracted is: Recently, it was found that the M variant is associated with the D organization. The AC automaton can obtain the two entities of M variant (virus, vul) and D (organization, org) and the entity type corresponding to each entity. Then the second input data is "Recently, it was found that the M variant is associated with the D organization <vul> M variant< / vul> <org> D Organization< / org> . ".
[0055] It should be noted that the matched entities and the entity type of the entity can be spliced at the beginning of the text to be extracted, or at the end of the text to be extracted, which is not limited here.
[0056] Through the above method, the second input data can be quickly and accurately acquired.
[0057] It should be noted that the first input data and the second input data are constructed in the same way as the first training samples and the second training samples trained by the aforementioned model. To avoid redundancy, they are not described here and the same parts are referenced to each other.
[0058] It should also be noted that step S101 and step S102 may be performed simultaneously or in a certain order, that is, step S101 may be performed first and then step S102, or step S102 may be performed first and then step S101, which is not limited here.
[0059] After the first input data and the second input data are acquired, the method proceeds to step S103 .
[0060] Step S103: input the first input data into a preset first extraction model to obtain a first extraction result.
[0061] The first extraction result includes each entity extracted and the type, position and probability of the entity. The position is the starting position and the ending position of the entity in the text to be extracted. For example, the text to be extracted is the recently discovered M variant associated with the D organization. The position of the M variant in the text to be extracted is "5 9", that is, 5 represents the M variant in the 5th position in the text to be extracted, and 9 represents the M variant in the 9th position in the text to be extracted; and the entity type corresponding to the M variant is virus; the probability of the entity indicates the probability of the first extraction model predicting the appearance of the entity in the text to be extracted, for example, the probability of the M variant is 60%, which means that the first extraction model predicts that the probability of the M variant appearing in the text to be extracted is 60%.
[0062] Step S104: input the second input data into a preset second extraction model to obtain a second extraction result.
[0063] The second extraction result includes the type, position, subject and object type and probability of each entity extracted. The probability of the entity indicates the probability of the entity appearing in the text to be extracted predicted by the second extraction model.
[0064] In the embodiment of the present application, the type and position of each entity refer to the entity type, position and probability in the aforementioned step S103, and no further description is given here to avoid redundancy. The above-mentioned subject-object type refers to whether the entity is in the position of the subject or the position of the object in the text to be extracted, that is, the subject-object type is determined according to the position of the entity.
[0065] It should be noted that step S103 and step S104 may be performed simultaneously or in sequence, that is, step S103 may be performed first and then step S104, or step S104 may be performed first and then step S103, which is not limited here.
[0066] After obtaining the first extraction result and the second extraction result, the method proceeds to step S015.
[0067] Step S105: Obtain the optimal extraction result according to the first extraction result and the second extraction result.
[0068] Among them, the optimal extraction result includes each entity corresponding to the text to be extracted and the type, subject and object type and position of the entity.
[0069] Specifically, according to the preset weight ratio of the first extraction model and the second extraction model, the probability of each entity in the first extraction result and the probability of each entity in the second extraction result are calculated to obtain the total probability corresponding to each entity; the total probability is compared with the preset threshold to obtain entities with a total probability greater than the preset threshold and the type, subject and object type and position corresponding to the entity, the optimal extraction result includes all entities with a total probability greater than the preset threshold and the type, subject and object type and position corresponding to the entity.
[0070] For example, in the first extraction result, the entity at the position "5 9" is an M variant, and its entity type is virus with a probability of 60%. In the second extraction result, the entity at the position "5 9" is an M variant, and its entity type is virus, and its subject and object type is subject with a probability of 70%. The weight of the above-mentioned preset first extraction model is a, and the weight of the second extraction model is b. Then, the total probability of the above-mentioned M variant is 60%a+70%b. The total probability is compared with the preset threshold. If the total probability is greater than the preset threshold, the probability of the M variant appearing at the position "5 9" in the text to be extracted is relatively high. At this time, the M variant and the type, subject and object position and position corresponding to the M variant can be used as the optimal extraction result.
[0071] It should be noted that the values of a and b can be: a is 0.5, b is 0.5; or, a is 0.4, b is 0.6; the value of the preset threshold can be: any one of 0.7, 0.8, 0.85, and 0.9. In addition, it should be noted that the weight of the first extraction model, the weight of the second extraction model, and the preset threshold can be set according to actual conditions.
[0072] In an embodiment of the present application, by inputting the first input data into a pre-set first extraction model to obtain a first extraction result, and inputting the second input data into a pre-set second extraction model to obtain a second extraction result, the first extraction model can understand the semantics of the text to be extracted faster and more accurately based on the prior knowledge of the first input data, and the second extraction model can understand the entities and entity types marked in the second input data based on the entities, thereby improving the accuracy of extracting entities in the text to be extracted. Based on the first extraction result and the second extraction result, the optimal extraction result can be obtained, thereby further improving the accuracy of extracting entities from the text to be extracted. In addition, based on the accuracy of extracting entities from the first extraction model and the second extraction model, the output results of the two (i.e., the first extraction result and the second extraction result) are fused, thereby improving the accuracy of the optimal extraction result obtained.
[0073] After obtaining the optimal extraction result, entity pairs may be obtained according to the optimal extraction result, and the relationship between the entity pairs may be obtained.
[0074] Specifically, according to each entity in the optimal extraction result, an entity pair is obtained; according to the entity pair and the optimal extraction result, the text to be extracted is marked; the marked text to be extracted is input into a preset RoBERTa model to obtain the encoding of each entity in the entity pair; the encoding corresponding to the first character of each entity in the entity pair is concatenated, and the relationship classification is performed on the concatenated encoding according to a preset classification algorithm to obtain the entity relationship corresponding to the entity pair.
[0075] After the optimal extraction result is obtained for the text to be extracted, each entity in the optimal extraction result can be paired into entity pairs. For example, the text to be extracted is: M variant was recently found to be associated with D organization. The entities extracted from the text to be extracted are: M variant and D organization. Based on the above two entities, the entity pair obtained is (M variant, D organization).
[0076] According to the entity pairs and the optimal extraction results (i.e., each entity and its type, subject and object type, and position), the text to be extracted is marked for each entity pair.
[0077] Taking (M variant, D organization) as an example, the label for the entity pair (M variant, D organization) is: recently discovered <s:vul>M variant <s:vul>Related to <o:sys>D Organization <o:sys>Among them, S indicates that the entity is a subject, O indicates that the entity is an object, vul indicates that the entity type is a virus, and org indicates that the entity type is an organization.
[0078] It should be noted that if there are more than two entities extracted from the text to be extracted, each entity needs to be paired into entity pairs. For example, if the entities proposed by the text to be extracted are A, B, C and D, then six entity pairs can be obtained based on the above four entities, namely: (A, B), (A, C), (A, D), (B, C), (B, D) and (C, D). In addition, based on the entity pairs and the optimal extraction results, the text to be extracted needs to be marked separately for each entity pair.
[0079] Input the marked text corresponding to each entity pair into the preset RoBERTa model to obtain the encoding of each entity in the entity pair. The encoding is generated for each character of each entity in the entity pair. The encoding corresponding to the first character of each entity in the entity pair is spliced, and then the spliced data is put into the classification algorithm (such as softmax) for relationship classification to obtain the entity relationship corresponding to the entity pair. The RoBERTa model and softmax algorithm are well known to those skilled in the art and will not be described here.
[0080] In the embodiment of the present application, since the optimal extraction result with a higher accuracy is obtained, the corresponding entity pairs are obtained according to each entity in the optimal extraction result, which can improve the accuracy of the obtained entity pairs, that is, each entity pair can be more accurately obtained according to the optimal extraction result. In addition, by marking the text to be extracted according to the optimal extraction result and the extracted entity pair, and inputting the marked text to be extracted into a pre-set RoBERTa model, the encoding of each entity in the entity pair is obtained; then the encoding corresponding to the first character of each entity in the entity pair is spliced, and the spliced encoding is classified according to the preset classification algorithm, so that the entity relationship corresponding to the entity pair can be accurately obtained according to the marked text to be extracted.
[0081] Please refer to FIG. 2 . Based on the same inventive concept, the embodiment of the present application further provides an entity extraction device 100 . The device 100 includes: an acquisition module 101 , an extraction module 102 , and a processing module 103 .
[0082] The acquisition module 101 is used to acquire first input data, the first input data includes the text to be extracted and preset prior knowledge, the prior knowledge includes the vocabulary of each entity definition or characterization of each entity type; and acquire second input data, the second input data includes the text to be extracted and the entities and entity types identified in the text to be extracted.
[0083] The extraction module 102 is used to input the first input data into a preset first extraction model to obtain a first extraction result, which includes the extracted entities and the type, position and probability of the entity; and input the second input data into a preset second extraction model to obtain a second extraction result, which includes the type, position, subject and object type and probability of the extracted entities.
[0084] The processing module 103 is used to obtain an optimal extraction result according to the first extraction result and the second extraction result. The optimal extraction result includes each entity corresponding to the text to be extracted and the type, subject and object type and position of the entity.
[0085] Optionally, the acquisition module 101 is specifically used to concatenate the text to be extracted with each definition text in a preset entity definition library to obtain first input data; or, concatenate the text to be extracted with preset words representing each entity type to obtain first input data.
[0086] Optionally, the acquisition module 101 is specifically used to match the text to be extracted through an AC automaton to obtain the entity corresponding to the text to be extracted and the type corresponding to the entity; the text to be extracted and the matched entity and the type corresponding to the entity are concatenated to obtain the second input data.
[0087] Optionally, the entity extraction device 100 also includes a construction module 104, which is used to obtain a first training set, the first training set includes a first training sample and a first label, the first training sample is a text after the preset text and various prior knowledge are respectively spliced, and the first label is the text after the preset text is entity labeled; the initial first extraction model is trained using the first training set to obtain a first extraction model.
[0088] Optionally, construction module 104 is also used to obtain a second training set, the second training set includes a second training sample and a second label, the second training sample is a text obtained by matching the preset text with the corresponding entity and the type corresponding to the entity through an AC automaton and concatenating the text with the preset text, and the second label is the text after the preset text is entity-labeled; the initial second extraction model is trained using the second training set to obtain a second extraction model.
[0089] Optionally, the processing module 103 is specifically used to calculate the probability of each entity in the first extraction result and the probability of each entity in the second extraction result according to the preset weight ratio of the first extraction model and the second extraction model, to obtain the total probability corresponding to each entity; compare the total probability with a preset threshold, to obtain entities with a total probability greater than the preset threshold and the type, subject and object type and position corresponding to the entity, the optimal extraction result includes all entities with a total probability greater than the preset threshold and the type, subject and object type and position corresponding to the entity.
[0090] Optionally, the processing module 103 is also used to obtain entity pairs based on each entity in the optimal extraction result; mark the text to be extracted based on the entity pair and the optimal extraction result; input the marked text to be extracted into a preset RoBERTa model to obtain the encoding of each entity in the entity pair; splice the encoding corresponding to the first character of each entity in the entity pair, and perform relationship classification on the spliced encoding according to a preset classification algorithm to obtain the entity relationship corresponding to the entity pair.
[0091] See also Figure 3 Based on the same inventive concept, the present application embodiment provides a schematic structural block diagram of an electronic device 200, which is used for the above-mentioned entity extraction method. In the embodiment of the present application, the electronic device 200 can be, but is not limited to, a personal computer (PC), a smart phone, a tablet computer, a personal digital assistant (PDA), a mobile Internet device (MID), etc. Structurally, the electronic device 200 may include a processor 210 and a memory 220.
[0092] The processor 210 is electrically connected to the memory 220 directly or indirectly to realize data transmission or interaction. For example, these elements can be electrically connected to each other through one or more communication buses or signal lines. Among them, the processor 210 can be an integrated circuit chip with signal processing capabilities. The processor 210 can also be a general-purpose processor, for example, it can be a central processing unit (CPU), a digital signal processor (DSP), an application-specific integrated circuit (ASIC), a discrete gate or transistor logic device, a discrete hardware component, and can implement or execute the various methods, steps and logic block diagrams disclosed in the embodiments of the present application. In addition, the general-purpose processor can be a microprocessor or any conventional processor, etc.
[0093] The memory 220 may be, but is not limited to, a random access memory (RAM), a read only memory (ROM), a programmable read-only memory (PROM), an erasable programmable read-only memory (EPROM), and an electric erasable programmable read-only memory (EEPROM). The memory 220 is used to store a program, and the processor 210 executes the program after receiving an execution instruction.
[0094] It should be understood that Figure 3 The structure shown is for illustration only. The electronic device 200 provided in the embodiment of the present application may also have Figure 3 Fewer or more components, or with Figure 3 In addition, Figure 3 The components shown may be implemented by software, hardware or a combination thereof.
[0095] It should be noted that, since technicians in the relevant field can clearly understand that for the convenience and brevity of description, the specific working processes of the systems, devices and units described above can refer to the corresponding processes in the aforementioned method embodiments and will not be repeated here.
[0096] Based on the same inventive concept, an embodiment of the present application further provides a computer-readable storage medium on which a computer program is stored. When the computer program is executed, the method provided in the above embodiment is executed.
[0097] The computer-readable storage medium may be any available medium that can be accessed by a computer or a data storage device such as a server or a data center that includes one or more available media. The available medium may be a magnetic medium (e.g., a floppy disk, a hard disk, a tape), an optical medium (e.g., a DVD), or a semiconductor medium (e.g., a solid state disk (SSD)).
[0098] In the embodiments provided in the present application, it should be understood that the disclosed devices and methods can be implemented in other ways. The device embodiments described above are merely schematic. For example, the division of the units is only a logical function division. There may be other division methods in actual implementation. For example, multiple units or components can be combined or integrated into another system, or some features can be ignored or not executed. Another point is that the mutual coupling or direct coupling or communication connection shown or discussed can be through some communication interfaces, and the indirect coupling or communication connection of the devices or units can be electrical, mechanical or other forms.
[0099] In addition, the units described as separate components may or may not be physically separated, and the components shown as units may or may not be physical units, that is, they may be located in one place or distributed on multiple network units. Some or all of the units may be selected according to actual needs to achieve the purpose of the solution of this embodiment.
[0100] Furthermore, the functional modules in the various embodiments of the present application may be integrated together to form an independent part, or each module may exist separately, or two or more modules may be integrated to form an independent part.
[0101] In this document, relational terms such as first and second, etc. are used merely to distinguish one entity or operation from another entity or operation, but do not necessarily require or imply any such actual relationship or order between these entities or operations.
[0102] The above description is only an embodiment of the present application and is not intended to limit the protection scope of the present application. For those skilled in the art, the present application may have various modifications and variations. Any modification, equivalent replacement, improvement, etc. made within the spirit and principle of the present application shall be included in the protection scope of the present application.< / o:sys> < / o:sys> < / s:vul> < / s:vul>
Claims
1. An entity extraction method, characterized in that: The method comprises: Acquire first input data, wherein the first input data includes a text to be extracted and preset prior knowledge, wherein the prior knowledge includes definitions of entities or vocabulary representing entity types; Acquire second input data, where the second input data includes the text to be extracted and entities and entity types identified in the text to be extracted; Input the first input data into a preset first extraction model to obtain a first extraction result, wherein the first extraction result includes each extracted entity and the type, position and probability of the entity; wherein the position is the starting position and the ending position of the entity in the text to be extracted; Inputting the second input data into a preset second extraction model to obtain a second extraction result, wherein the second extraction result includes the type, position, subject and object type, and probability of each extracted entity; An optimal extraction result is obtained according to the first extraction result and the second extraction result, wherein the optimal extraction result includes each entity corresponding to the text to be extracted and the type, subject and object type, and position of the entity.
2. The method according to claim 1, characterized in that The obtaining of the first input data comprises: The text to be extracted is respectively concatenated with each definition text in a preset entity definition library to obtain the first input data; Alternatively, the text to be extracted is concatenated with preset words representing each entity type to obtain the first input data.
3. The method according to claim 1, characterized in that: The obtaining of the second input data comprises: Matching the text to be extracted by an AC automaton to obtain an entity corresponding to the text to be extracted and a type corresponding to the entity; The text to be extracted, the matched entity and the type corresponding to the entity are concatenated to obtain second input data.
4. The method according to claim 1, characterized in that The first extraction model is obtained according to the following steps: Obtain a first training set, the first training set including a first training sample and a first label, the first training sample is a text obtained by concatenating a preset text with each of the prior knowledge, and the first label is a text obtained by entity annotating the preset text; The initial first extraction model is trained using the first training set to obtain the first extraction model.
5. The method according to claim 1, characterized in that The second extraction model is obtained according to the following steps: Obtain a second training set, the second training set including a second training sample and a second label, the second training sample is a text obtained by matching a corresponding entity and a type corresponding to the entity with the preset text through an AC automaton, and the second label is a text obtained by entity-labeling the preset text; The initial second extraction model is trained using the second training set to obtain the second extraction model.
6. The method according to claim 1, characterized in that The obtaining the optimal extraction result according to the first extraction result and the second extraction result includes: Calculate the probability of each entity in the first extraction result and the probability of each entity in the second extraction result according to the preset weight ratio of the first extraction model and the second extraction model to obtain a total probability corresponding to each entity; The total probability is compared with a preset threshold, and the entities whose total probability is greater than the preset threshold and the types, host and guest types and positions corresponding to the entities are obtained. The optimal extraction result includes all entities whose total probability is greater than the preset threshold and the types, host and guest types and positions corresponding to the entities.
7. The method according to claim 1, characterized in that The method further comprises: According to each entity in the optimal extraction result, obtaining an entity pair; Marking the text to be extracted according to the entity pair and the optimal extraction result; Input the marked text to be extracted into a preset RoBERTa model to obtain the encoding of each entity in the entity pair; The codes corresponding to the first character of each entity in the entity pair are concatenated, and the concatenated codes are subjected to relationship classification according to a preset classification algorithm to obtain the entity relationship corresponding to the entity pair.
8. An entity extraction device, characterized in that: The device comprises: The acquisition module is used to acquire first input data, wherein the first input data includes the text to be extracted and various preset prior knowledge, wherein the prior knowledge includes definitions of entities or words representing various entity types; and acquire second input data, wherein the second input data includes the text to be extracted and entities and entity types identified in the text to be extracted; An extraction module is used to input the first input data into a preset first extraction model to obtain a first extraction result, wherein the first extraction result includes each extracted entity and the type, position and probability of the entity; input the second input data into a preset second extraction model to obtain a second extraction result, wherein the second extraction result includes the type, position, subject and object type and probability of each extracted entity; wherein the position is the starting position and the ending position of the entity in the text to be extracted; A processing module is used to obtain an optimal extraction result according to the first extraction result and the second extraction result, wherein the optimal extraction result includes each entity corresponding to the text to be extracted and the type, subject and object type and position of the entity.
9. An electronic device, characterized in that: include: A processor and a memory, the processor and the memory being connected; The memory is used to store programs; The processor is configured to run a program stored in the memory to execute the method according to any one of claims 1 to 7.
10. A computer-readable storage medium, characterized in that: A computer program is stored thereon, and when the computer program is executed by a computer, the method according to any one of claims 1 to 7 is executed.
Citation Information
Patent Citations
Text relation extraction method based on double-layer attention mechanism and bidirectional GRU
CN110502749A
Entity relationship extraction method and device of text and storage medium
CN110569366A