Named entity recognition method, device, electronic device and readable storage medium
By extracting named entity categories of multiple data sets and building a named entity recognition model for multiple output branches, the problems of low acquisition efficiency and low recognition accuracy of named entity data sets are solved, and efficient acquisition and high accuracy recognition are achieved.
Patent Information
- Application Number
- CN202010920446.1
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2020-09-03
- Publication Date
- 2025-03-11
- Estimated Expiration
- 2040-09-03
AI Technical Summary
In the prior art, the acquisition efficiency of named entity data sets is low, and the recognition accuracy of named entity recognition models is not high, mainly due to the inconsistent data set annotation and the single model structure.
By extracting named entity categories from multiple data sets, a named entity recognition model for multiple output branches is constructed, and BERT is used as the main branch in the model, multiple output branches are added to identify different named entity categories.
It realizes efficient acquisition and recognition accuracy of named entity data sets, avoids the inefficiency problem of manual annotation, and improves the recognition ability of different named entity categories.
Smart Images

Figure CN112001179B_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to the field of data processing, and in particular to a method, device, electronic device and readable storage medium for named entity recognition. Background Art
[0002] In the field of natural language processing applications, named entity recognition is a basic task of natural language processing applications such as information retrieval, machine translation, automatic question answering, and sentiment analysis. The research on named entity recognition is of great significance.
[0003] Currently, there are few datasets related to named entities, and different datasets annotate different named entity categories. It is impossible to directly mix existing datasets to train named entity models. Manually annotating datasets is time-consuming and laborious, resulting in low efficiency in acquiring named entity datasets. At the same time, a single statistical-based model is usually used as a named entity recognition model to recognize different named entities. Due to the different structures and lengths of different named entities, the model's recognition accuracy for named entities is not high enough. Therefore, a named entity recognition method is urgently needed to improve the efficiency of acquiring named entity datasets and improve the accuracy of named entity recognition. Summary of the invention
[0004] In view of the above, it is necessary to provide a named entity recognition method to improve the efficiency of acquiring named entity datasets and improve the accuracy of named entity recognition.
[0005] The named entity recognition method provided by the present invention comprises:
[0006] Acquire multiple data sets from a database, and perform named entity category extraction on the multiple data sets to obtain sub-data sets corresponding to each named entity category;
[0007] Constructing a named entity recognition model, wherein the named entity recognition model includes a plurality of output branches, each output branch corresponds to a named entity category, and inputting a sub-data set corresponding to each named entity category into the named entity recognition model for training to obtain a trained named entity recognition model;
[0008] Responding to a named entity recognition request issued by a user based on a client, parsing the request, and obtaining the text to be named entity recognized and the target named entity category carried in the request;
[0009] The text to be named entity recognized is input into the trained named entity recognition model, and the recognition result output by the output branch corresponding to the target named entity category is used as the target recognition result of the text to be named entity recognized.
[0010] Optionally, performing named entity category extraction on the multiple data sets to obtain sub-data sets corresponding to each named entity category includes:
[0011] Converting the annotation information carried by each of the multiple data sets from an initial annotation format to a preset annotation format;
[0012] Determine the named entity category set corresponding to each data set according to the annotation information in the preset annotation format, and split each data set into initial data sets corresponding to each named entity category in the corresponding named entity category set;
[0013] The initial data sets corresponding to each named entity category are aggregated to obtain the sub-data sets corresponding to each named entity category.
[0014] Optionally, the building of a named entity recognition model includes:
[0015] The BERT model is used as the main branch of the named entity recognition model, and multiple output branches are added after the main branch according to the number of named entity categories, and the output branch includes a fully connected layer.
[0016] Optionally, the training process of the named entity recognition model includes:
[0017] Selecting a sub-dataset corresponding to a named entity category and inputting it into the named entity recognition model, and using the recognition result output by the output branch corresponding to the selected named entity category as the predicted named entity of the sub-dataset corresponding to the selected named recognition category;
[0018] The real named entities of the sub-dataset corresponding to the selected named entity category are obtained according to the annotation information of the preset annotation format, and the weight parameters of the output branch corresponding to the selected named entity category of the named entity recognition model are determined by minimizing the accuracy loss value between the real named entities and the predicted named entities.
[0019] Optionally, the calculation formula of the accuracy loss value is:
[0020]
[0021] Among them, q i is the predicted named entity of the sub-dataset corresponding to the i-th named entity category, p i is the real named entity of the sub-dataset corresponding to the i-th named entity category, loss(q i ,p i ) is the accuracy loss value between the real named entity and the predicted named entity in the sub-dataset corresponding to the i-th named entity category, and c is the total number of named entity categories.
[0022] Optionally, splitting each data set into initial data sets corresponding to each named entity category in the corresponding named entity category set includes:
[0023] For each data set, the positive samples corresponding to a specified named entity category in the corresponding named entity category set are retained, and the samples corresponding to other named entity categories are used as negative samples to obtain an initial data set corresponding to the specified named entity category.
[0024] Optionally, the initial annotation format includes BIOES, BMES and BIO, the preset annotation format is BIO, and converting the annotation information from the initial annotation format to the preset annotation format includes:
[0025] The I annotation in the BIOES format is deleted, the S annotation is changed to the B annotation, and the E annotation is changed to the I annotation;
[0026] The M mark in the BMES format is deleted, the S mark is changed to the B mark, and the E mark is changed to the I mark.
[0027] In order to solve the above problem, the present invention also provides a named entity recognition device, the device comprising:
[0028] An extraction module, used to obtain multiple data sets from a database, and perform named entity category extraction on the multiple data sets to obtain sub-data sets corresponding to each named entity category;
[0029] A training module is used to construct a named entity recognition model, wherein the named entity recognition model includes a plurality of output branches, each output branch corresponds to a named entity category, and a sub-data set corresponding to each named entity category is input into the named entity recognition model for training to obtain a trained named entity recognition model;
[0030] A request module, used to respond to a named entity recognition request issued by a user based on a client, parse the request, and obtain the text to be named entity recognized and the target named entity category carried in the request;
[0031] The output module is used to input the text to be named entity recognized into the trained named entity recognition model, and use the recognition result output by the output branch corresponding to the target named entity category as the target recognition result of the text to be named entity recognized.
[0032] In order to solve the above problem, the present invention further provides an electronic device, the electronic device comprising:
[0033] at least one processor; and,
[0034] a memory communicatively connected to the at least one processor; wherein,
[0035] The memory stores a named entity recognition program that can be executed by the at least one processor, and the named entity recognition program is executed by the at least one processor so that the at least one processor can perform the above-mentioned named entity recognition method.
[0036] In order to solve the above problem, the present invention also provides a computer-readable storage medium, on which a named entity recognition program is stored. The named entity recognition program can be executed by one or more processors to implement the above-mentioned named entity recognition method.
[0037] Compared with the prior art, the present invention first converts the annotation formats of multiple data sets into a preset annotation format, and then splits each data set according to the named entity category (the samples corresponding to the target named entity category are positive samples, and the samples corresponding to other named entity categories are negative samples), and obtains the initial data set corresponding to each named entity category in each data set, and then summarizes the initial data set to obtain the sub-data set corresponding to each named entity category. This step does not require any manual annotation, and multiple data sets with different annotation formats and different annotation entities can be merged to obtain a data set with a moderate amount of data corresponding to each named entity category, thereby improving the acquisition efficiency of the named entity data set; then, a named entity recognition model is constructed, and the named entity recognition model includes multiple output branches, each output branch corresponds to a named entity category, rather than the traditional use of one output branch to identify named entities of different categories, so that the named entity recognition accuracy is higher; finally, the text to be named entity recognized is input into the trained named entity recognition model, and the recognition result output by the output branch corresponding to the target named entity category is used as the target recognition result of the text to be named entity recognized, and the target recognition result obtained has a high accuracy. Therefore, the present invention improves the acquisition efficiency of the named entity data set and improves the accuracy of named entity recognition. BRIEF DESCRIPTION OF THE DRAWINGS
[0038] Figure 1 A flowchart of a method for named entity recognition provided by an embodiment of the present invention;
[0039] Figure 2 A schematic diagram of a module of a named entity recognition device provided by an embodiment of the present invention;
[0040] Figure 3 A schematic diagram of the structure of an electronic device for implementing a method for named entity recognition provided by an embodiment of the present invention;
[0041] The realization of the purpose, functional features and advantages of the present invention will be further explained in conjunction with embodiments and with reference to the accompanying drawings. DETAILED DESCRIPTION
[0042] In order to make the purpose, technical scheme and advantages of the present invention more clearly understood, the present invention is further described in detail below in conjunction with the accompanying drawings and embodiments. It should be understood that the specific embodiments described herein are only used to explain the present invention and are not intended to limit the present invention. Based on the embodiments of the present invention, all other embodiments obtained by ordinary technicians in this field without making creative work are within the scope of protection of the present invention.
[0043] It should be noted that the descriptions of "first", "second", etc. in the present invention are only used for descriptive purposes and cannot be understood as indicating or implying their relative importance or implicitly indicating the number of the indicated technical features. Therefore, the features defined as "first" and "second" may explicitly or implicitly include at least one of the features. In addition, the technical solutions between the various embodiments can be combined with each other, but they must be based on the ability of ordinary technicians in the field to implement them. When the combination of technical solutions is contradictory or cannot be implemented, it should be deemed that such a combination of technical solutions does not exist and is not within the scope of protection required by the present invention.
[0044] The present invention provides a method for named entity recognition. Figure 1 FIG. 1 is a flow chart of a method for named entity recognition provided by an embodiment of the present invention. The method can be executed by an electronic device, and the electronic device can be implemented by software and / or hardware.
[0045] In this embodiment, the named entity recognition method includes:
[0046] S1, obtaining multiple data sets from a database, performing named entity category extraction on the multiple data sets to obtain sub-data sets corresponding to each named entity category;
[0047] Named entities are names of people, organizations, places, and all other entities identified by names. For example, named entities also include numbers, dates, currencies, addresses, etc.
[0048] In this embodiment, the multiple data sets are data sets carrying annotation information related to named entity recognition that have been collected from the Internet, for example, MSRA, People's Daily, Weibo, CLUENER, BOSON and other data sets.
[0049] The purpose of this step is to merge the various data sets into a large data set of appropriate data volume to train the named entity recognition model.
[0050] The step of performing named entity category extraction on the multiple data sets to obtain sub-data sets corresponding to each named entity category includes steps A1-A3:
[0051] A1. Convert the annotation information carried in each of the multiple data sets from the initial annotation format to a preset annotation format;
[0052] The initial annotation formats of the collected data sets may not be unified. The initial annotation formats include BIOES, BMES, and BIO. For example, the annotation format of the CLUENER data set is BIOES, the annotation format of the Weibo data set is BMES, and the annotation format of the People's Daily data set is BIO.
[0053] In BIOES, B (begin) indicates the start of a named entity, I (inside) indicates the inside of a named entity, O (outside) indicates a non-named entity, E (end) indicates the end of a named entity, and S (single) indicates that a single character is a named entity. For example, "我是广东人" is annotated as "我 / S是 / S广 / B东 / I人 / E".
[0054] In BMES, B indicates the start of a named entity, M (middle) indicates the middle of a named entity, E indicates the end of a named entity, and S indicates that a single character is a named entity.
[0055] In BIO, B indicates the start of a named entity, I indicates the inside of a named entity, and O indicates a non-named entity.
[0056] In this embodiment, the preset annotation format is BIO. Converting the annotation information from the initial annotation format to the preset annotation format includes steps B1 - B2:
[0057] B1. Delete the I annotation in the BIOES format, modify the S annotation to a B annotation, and modify the E annotation to an I annotation;
[0058] B2. Delete the M annotation in the BMES format, modify the S annotation to a B annotation, and modify the E annotation to an I annotation.
[0059] Taking BIO as the target annotation format can quickly convert other annotation formats to the BIO format with high conversion efficiency. If converting the BIO format to the BIOES or BMES format, manual annotation is required, resulting in low conversion efficiency.
[0060] A2. Determine the set of named entity categories corresponding to each data set according to the annotation information in the preset annotation format, and split each data set into initial data sets corresponding to each named entity category in the corresponding set of named entity categories;
[0061] The named entity categories annotated in each data set may also be different. For example, there are time entities annotated in the People's Daily data set, but there are no time entities annotated in the MSRA data set. According to the annotation information, the named entity category set corresponding to each data set can be determined. Assuming that the annotation information of the MSRA data set annotates the three named entity categories of PER (personal name), LOC (place name), and ORG (organization name), L(MSRA) is used as the named entity category set corresponding to the MSRA data set, then L(MSRA) = {PER, LOC, ORG}. Similarly, this embodiment assumes that L(People's Daily) = {PER, LOC, ORG, TIM}, L{Weibo} = {PER, ORG, LOC}, L(CLUENER) = {PER, LOC, ORG, COM, ADD, GAME, GOV, SCENCE, BOOK, MOVIE}, and L(BOSON) = {PER, LOC, ORG, COM, TIM, PRODUCT}.
[0062] In this embodiment, splitting each data set into initial data sets corresponding to each named entity category in the corresponding named entity category set includes:
[0063] For each data set, the positive samples corresponding to a specified named entity category in the corresponding named entity category set are retained, and the samples corresponding to other named entity categories are used as negative samples to obtain an initial data set corresponding to the specified named entity category.
[0064] For example, for the MSRA dataset, L(MSRA) = {PER, LOC, ORG}, taking the PER category as an example, all positive samples of the PER category in the MSRA dataset are retained, and all other positive samples such as LOC and ORG are marked as negative samples. The negative samples originally existing in the MSRA dataset remain unchanged, and the newly obtained dataset only contains positive samples of the PER category, and all positive samples of other categories become negative samples. The newly obtained dataset is recorded as MSRA-PER (i.e., the initial dataset corresponding to the PER category in the MSRA dataset), and so on, the MSRA-ORG and MSRA-LOC datasets can be obtained. For the other four datasets, you can also go to CLUENER-PER, CLUENER-ADD... and other datasets.
[0065] A3. Summarize the initial data sets corresponding to each named entity category to obtain the sub-data sets corresponding to each named entity category.
[0066] According to the above step A2, for the PER category, five initial data sets can be obtained, namely MSRA-PER, People's Daily-PER, CLUENER-PER, Weibo-PER, and BOSON-PER. These five initial data sets only contain named entities of the PER category, and named entities of other categories are negative samples. Therefore, these five initial data sets can be mixed to form a new data set, which is recorded as the PER data set (that is, the sub-data set corresponding to the PER category). By analogy, sub-data sets corresponding to named entity categories such as LOC, ORG, TIM, ADD, COM, and BOOK can be obtained.
[0067] Therefore, the present invention can obtain a sub-dataset with a moderate amount of data corresponding to each named entity category without manual labeling, and the efficiency of obtaining the named entity data set is relatively high.
[0068] S2, constructing a named entity recognition model, wherein the named entity recognition model includes a plurality of output branches, each output branch corresponds to a named entity category, and inputting a sub-data set corresponding to each named entity category into the named entity recognition model for training to obtain a trained named entity recognition model;
[0069] The construction of the named entity recognition model includes:
[0070] The BERT model is used as the main branch of the named entity recognition model, and multiple output branches are added after the main branch according to the number of named entity categories, and the output branch includes a fully connected layer.
[0071] In this embodiment, the named entity recognition model has one input and multiple outputs, and each output branch outputs a recognition result of a named entity category.
[0072] The training process of the named entity recognition model includes:
[0073] C1. Select a sub-dataset corresponding to a named entity category and input it into the named entity recognition model, and use the recognition result output by the output branch corresponding to the selected named entity category as the predicted named entity of the sub-dataset corresponding to the selected named recognition category;
[0074] C2. Obtain the real named entities of the sub-dataset corresponding to the selected named entity category according to the annotation information of the preset annotation format, and determine the weight parameters of the output branch corresponding to the selected named entity category of the named entity recognition model by minimizing the accuracy loss value between the real named entities and the predicted named entities.
[0075] Through the above steps C1-C2, the weight parameters of the output branch corresponding to each named entity category of the named entity recognition model can be trained.
[0076] In this embodiment, the calculation formula of the accuracy loss value is:
[0077]
[0078] Among them, q i is the predicted named entity of the sub-dataset corresponding to the i-th named entity category, p i is the real named entity of the sub-dataset corresponding to the i-th named entity category, loss(q i ,p i ) is the accuracy loss value between the real named entity and the predicted named entity in the sub-dataset corresponding to the i-th named entity category, and c is the total number of named entity categories.
[0079] S3, responding to a named entity recognition request issued by a user based on a client, parsing the request, and obtaining a text to be named entity recognized and a target named entity category carried in the request;
[0080] S4. Input the text to be named entity recognition into the trained named entity recognition model, and use the recognition result output by the output branch corresponding to the target named entity category as the target recognition result of the text to be named entity recognition.
[0081] For example, the target named entity category carried in the request is PER (personal name). After the text to be recognized is input into the trained named entity recognition model, the result recognized by the output branch corresponding to the PER category in the model is used as the target recognition result.
[0082] The present invention increases the accuracy of named entity recognition by adding multiple output branches in the model, each of which corresponds to outputting a recognition result of a named entity category.
[0083] It can be seen from the above embodiments that the named entity recognition method proposed in the present invention, first, after the annotation formats of multiple data sets are uniformly converted into a preset annotation format, each data set is split according to the named entity category (the samples corresponding to the target named entity category are positive samples, and the samples corresponding to other named entity categories are negative samples), and the initial data set corresponding to each named entity category in each data set is obtained, and then the initial data set is summarized to obtain the sub-data set corresponding to each named entity category. This step does not require any manual annotation, and multiple data sets with different annotation formats and different annotation entities can be merged to obtain a data set with a moderate data volume corresponding to each named entity category, thereby improving the acquisition efficiency of the named entity data set; then, a named entity recognition model is constructed, and the named entity recognition model includes multiple output branches, each output branch corresponds to a named entity category, instead of the traditional use of one output branch to identify named entities of different categories, so that the named entity recognition accuracy is higher; finally, the text to be named entity recognized is input into the trained named entity recognition model, and the recognition result output by the output branch corresponding to the target named entity category is used as the target recognition result of the text to be named entity recognized, and the target recognition result obtained has a higher accuracy. Therefore, the present invention improves the efficiency of acquiring named entity datasets and improves the accuracy of named entity recognition.
[0084] like Figure 2 , which is a module diagram of a named entity recognition device provided by an embodiment of the present invention.
[0085] The named entity recognition device 100 of the present invention can be installed in an electronic device. According to the functions to be implemented, the named entity recognition device 100 may include an extraction module 110, a training module 120, a request module 130 and an output module 140. The module of the present invention may also be referred to as a unit, which refers to a series of computer program segments that can be executed by a processor of an electronic device and can complete fixed functions, which are stored in the memory of the electronic device.
[0086] In this embodiment, the functions of each module / unit are as follows:
[0087] An extraction module 110 is used to obtain multiple data sets from a database, and perform named entity category extraction on the multiple data sets to obtain sub-data sets corresponding to each named entity category;
[0088] Named entities are names of people, organizations, places, and all other entities identified by names. For example, named entities also include numbers, dates, currencies, addresses, etc.
[0089] In this embodiment, the multiple datasets are datasets carrying annotation information related to named entity recognition that have been collected from the network. For example, datasets such as MSRA, People's Daily, Weibo, CLUENER, and BOSON.
[0090] The purpose of this step is to fuse the individual datasets to form a large dataset with an appropriate data volume for training the named entity recognition model.
[0091] Performing named entity category extraction on the multiple datasets to obtain sub-datasets corresponding to each named entity category includes steps A1 - A3:
[0092] A1. Convert the annotation information carried in each of the multiple datasets from the initial annotation format to the preset annotation format;
[0093] The initial annotation formats of the collected individual datasets may not be unified. The initial annotation formats include BIOES, BMES, and BIO. For example, the annotation format of the CLUENER dataset is BIOES, while the annotation format of the Weibo dataset is BMES, and the annotation format of the People's Daily dataset is BIO.
[0094] In BIOES, B (begin) indicates the start of a named entity, I (inside) indicates inside a named entity, O (outside) indicates a non-named entity, E (end) indicates the end of a named entity, and S (single) indicates that a single character is a named entity. For example, "我是广东人" is annotated as "我 / S是 / S广 / B东 / I人 / E".
[0095] In BMES, B indicates the start of a named entity, M (middle) indicates the middle of a named entity, E indicates the end of a named entity, and S indicates that a single character is a named entity.
[0096] In BIO, B indicates the start of a named entity, I indicates the end of a named entity, and O indicates a non-named entity.
[0097] In this embodiment, the preset annotation format is BIO. Converting the annotation information from the initial annotation format to the preset annotation format includes steps B1 - B2:
[0098] B1. Delete the I annotation in the BIOES format, modify the S annotation to the B annotation, and modify the E annotation to the I annotation;
[0099] B2. Delete the M annotation in the BMES format, modify the S annotation to the B annotation, and modify the E annotation to the I annotation.
[0100] Using BIO as the target annotation format can quickly convert other annotation formats into BIO format with high conversion efficiency. If BIO format is converted into BIOES or BMES format, manual annotation is required and the conversion efficiency is low.
[0101] A2. Determine the named entity category set corresponding to each data set according to the annotation information in the preset annotation format, and split each data set into initial data sets corresponding to each named entity category in the corresponding named entity category set;
[0102] The named entity categories annotated in each data set may also be different. For example, there are time entities annotated in the People's Daily data set, but there are no time entities annotated in the MSRA data set. According to the annotation information, the named entity category set corresponding to each data set can be determined. Assuming that the annotation information of the MSRA data set annotates the three named entity categories of PER (personal name), LOC (place name), and ORG (organization name), L(MSRA) is used as the named entity category set corresponding to the MSRA data set, then L(MSRA) = {PER, LOC, ORG}. Similarly, this embodiment assumes that L(People's Daily) = {PER, LOC, ORG, TIM}, L{Weibo} = {PER, ORG, LOC}, L(CLUENER) = {PER, LOC, ORG, COM, ADD, GAME, GOV, SCENCE, BOOK, MOVIE}, and L(BOSON) = {PER, LOC, ORG, COM, TIM, PRODUCT}.
[0103] In this embodiment, splitting each data set into initial data sets corresponding to each named entity category in the corresponding named entity category set includes:
[0104] For each data set, the positive samples corresponding to a specified named entity category in the corresponding named entity category set are retained, and the samples corresponding to other named entity categories are used as negative samples to obtain an initial data set corresponding to the specified named entity category.
[0105] For example, for the MSRA dataset, L(MSRA) = {PER, LOC, ORG}, taking the PER category as an example, all positive samples of the PER category in the MSRA dataset are retained, and all other positive samples such as LOC and ORG are marked as negative samples. The negative samples originally existing in the MSRA dataset remain unchanged, and the newly obtained dataset only contains positive samples of the PER category, and all positive samples of other categories become negative samples. The newly obtained dataset is recorded as MSRA-PER (i.e., the initial dataset corresponding to the PER category in the MSRA dataset), and so on, the MSRA-ORG and MSRA-LOC datasets can be obtained. For the other four datasets, you can also go to CLUENER-PER, CLUENER-ADD... and other datasets.
[0106] A3. Summarize the initial data sets corresponding to each named entity category to obtain the sub-data sets corresponding to each named entity category.
[0107] According to the above step A2, for the PER category, five initial data sets can be obtained, namely MSRA-PER, People's Daily-PER, CLUENER-PER, Weibo-PER, and BOSON-PER. These five initial data sets only contain named entities of the PER category, and named entities of other categories are negative samples. Therefore, these five initial data sets can be mixed to form a new data set, which is recorded as the PER data set (that is, the sub-data set corresponding to the PER category). By analogy, sub-data sets corresponding to named entity categories such as LOC, ORG, TIM, ADD, COM, and BOOK can be obtained.
[0108] Therefore, the present invention can obtain a sub-dataset with a moderate amount of data corresponding to each named entity category without manual labeling, and the efficiency of obtaining the named entity data set is relatively high.
[0109] A training module 120 is used to construct a named entity recognition model, wherein the named entity recognition model includes a plurality of output branches, each output branch corresponds to a named entity category, and a sub-data set corresponding to each named entity category is input into the named entity recognition model for training to obtain a trained named entity recognition model;
[0110] The construction of the named entity recognition model includes:
[0111] The BERT model is used as the main branch of the named entity recognition model, and multiple output branches are added after the main branch according to the number of named entity categories, and the output branch includes a fully connected layer.
[0112] In this embodiment, the named entity recognition model has one input and multiple outputs, and each output branch outputs a recognition result of a named entity category.
[0113] The training process of the named entity recognition model includes:
[0114] C1. Select a sub-dataset corresponding to a named entity category and input it into the named entity recognition model, and use the recognition result output by the output branch corresponding to the selected named entity category as the predicted named entity of the sub-dataset corresponding to the selected named recognition category;
[0115] C2. Obtain the real named entities of the sub-dataset corresponding to the selected named entity category according to the annotation information of the preset annotation format, and determine the weight parameters of the output branch corresponding to the selected named entity category of the named entity recognition model by minimizing the accuracy loss value between the real named entities and the predicted named entities.
[0116] Through the above steps C1-C2, the weight parameters of the output branch corresponding to each named entity category of the named entity recognition model can be trained.
[0117] In this embodiment, the calculation formula of the accuracy loss value is:
[0118]
[0119] Among them, q i is the predicted named entity of the sub-dataset corresponding to the i-th named entity category, p i is the real named entity of the sub-dataset corresponding to the i-th named entity category, loss(q i ,p i ) is the accuracy loss value between the real named entity and the predicted named entity in the sub-dataset corresponding to the i-th named entity category, and c is the total number of named entity categories.
[0120] The request module 130 is used to respond to the named entity recognition request issued by the user based on the client, parse the request, and obtain the text to be named entity recognized and the target named entity category carried in the request;
[0121] The output module 140 is used to input the text to be named entity recognized into the trained named entity recognition model, and use the recognition result output by the output branch corresponding to the target named entity category as the target recognition result of the text to be named entity recognized.
[0122] For example, the target named entity category carried in the request is PER (personal name). After the text to be recognized is input into the trained named entity recognition model, the result recognized by the output branch corresponding to the PER category in the model is used as the target recognition result.
[0123] The present invention increases the accuracy of named entity recognition by adding multiple output branches in the model, each output branch correspondingly outputting a recognition result of a named entity category.
[0124] like Figure 3 , which is a schematic diagram of the structure of an electronic device for implementing a method for named entity recognition provided by an embodiment of the present invention.
[0125] The electronic device 1 is a device that can automatically perform numerical calculations and / or information processing according to pre-set or stored instructions. The electronic device 1 can be a computer, a single network server, a server group consisting of multiple network servers, or a cloud based on cloud computing consisting of a large number of hosts or network servers, wherein cloud computing is a type of distributed computing, a super virtual computer composed of a group of loosely coupled computer sets.
[0126] In this embodiment, the electronic device 1 includes, but is not limited to, a memory 11, a processor 12, and a network interface 13 that can be interconnected and communicated via a system bus. The memory 11 stores a named entity recognition program 10, and the named entity recognition program 10 can be executed by the processor 12. Figure 3 Only the electronic device 1 having components 11-13 and the named entity recognition program 10 is shown. It can be understood by those skilled in the art that Figure 3 The structure shown does not constitute a limitation on the electronic device 1 , and may include fewer or more components than shown in the figure, or combine certain components, or arrange the components differently.
[0127] Among them, the memory 11 includes a memory and at least one type of readable storage medium. The memory provides a cache for the operation of the electronic device 1; the readable storage medium may be a non-volatile storage medium such as a flash memory, a hard disk, a multimedia card, a card-type memory (e.g., SD or DX memory, etc.), a random access memory (RAM), a static random access memory (SRAM), a read-only memory (ROM), an electrically erasable programmable read-only memory (EEPROM), a programmable read-only memory (PROM), a magnetic memory, a disk, an optical disk, etc. In some embodiments, the readable storage medium may be an internal storage unit of the electronic device 1, such as a hard disk of the electronic device 1; in other embodiments, the non-volatile storage medium may also be an external storage device of the electronic device 1, such as a plug-in hard disk equipped on the electronic device 1, a smart memory card (Smart Media Card, SMC), a secure digital (Secure Digital, SD) card, a flash card (Flash Card), etc. In this embodiment, the readable storage medium of the memory 11 is generally used to store an operating system and various application software installed on the electronic device 1, such as storing the code of the named entity recognition program 10 in an embodiment of the present invention. In addition, the memory 11 can also be used to temporarily store various types of data that have been output or are to be output.
[0128] In some embodiments, the processor 12 may be a central processing unit (CPU), a controller, a microcontroller, a microprocessor, or other data processing chip. The processor 12 is generally used to control the overall operation of the electronic device 1, such as performing control and processing related to data interaction or communication with other devices. In this embodiment, the processor 12 is used to run the program code stored in the memory 11 or process data, such as running the named entity recognition program 10.
[0129] The network interface 13 may include a wireless network interface or a wired network interface, and the network interface 13 is used to establish a communication connection between the electronic device 1 and a client (not shown in the figure).
[0130] Optionally, the electronic device 1 may further include a user interface, which may include a display (Display), an input unit such as a keyboard (Keyboard), and the optional user interface may also include a standard wired interface and a wireless interface. Optionally, in some embodiments, the display may be an LED display, a liquid crystal display, a touch-sensitive liquid crystal display, and an OLED (Organic Light-Emitting Diode) touch device, etc. Among them, the display may also be appropriately referred to as a display screen or a display unit, which is used to display information processed in the electronic device 1 and to display a visual user interface.
[0131] It should be understood that the embodiment is for illustration only and the scope of the patent application is not limited to this structure.
[0132] The named entity recognition program 10 stored in the memory 11 of the electronic device 1 is a combination of multiple instructions, and when running in the processor 12, it can achieve:
[0133] Acquire multiple data sets from a database, and perform named entity category extraction on the multiple data sets to obtain sub-data sets corresponding to each named entity category;
[0134] Constructing a named entity recognition model, wherein the named entity recognition model includes a plurality of output branches, each output branch corresponds to a named entity category, and inputting a sub-data set corresponding to each named entity category into the named entity recognition model for training to obtain a trained named entity recognition model;
[0135] Responding to a named entity recognition request issued by a user based on a client, parsing the request, and obtaining the text to be named entity recognized and the target named entity category carried in the request;
[0136] The text to be named entity recognized is input into the trained named entity recognition model, and the recognition result output by the output branch corresponding to the target named entity category is used as the target recognition result of the text to be named entity recognized.
[0137] Specifically, the specific implementation method of the processor 12 for the named entity recognition program 10 can refer to Figure 1 The description of the relevant steps in the corresponding embodiment is not repeated here. It should be emphasized that in order to further ensure the privacy and security of each of the above data sets, the above data sets can also be stored in a node of a blockchain.
[0138] Furthermore, if the module / unit integrated in the electronic device 1 is implemented in the form of a software functional unit and sold or used as an independent product, it can be stored in a computer-readable storage medium. The computer-readable medium may include: any entity or device capable of carrying the computer program code, a recording medium, a USB flash drive, a mobile hard disk, a magnetic disk, an optical disk, a computer memory, and a read-only memory (ROM).
[0139] The computer-readable storage medium stores a named entity recognition program 10, which can be executed by one or more processors. The specific implementation of the computer-readable storage medium of the present invention is basically the same as the above-mentioned embodiments of the named entity recognition method, and will not be described in detail here.
[0140] In the several embodiments provided by the present invention, it should be understood that the disclosed devices, apparatuses and methods can be implemented in other ways. For example, the device embodiments described above are only schematic, for example, the division of the modules is only a logical function division, and there may be other division methods in actual implementation.
[0141] The modules described as separate components may or may not be physically separated, and the components shown as modules 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 modules may be selected according to actual needs to achieve the purpose of the solution of this embodiment.
[0142] In addition, each functional module in each embodiment of the present invention may be integrated into one processing unit, or each unit may exist physically separately, or two or more units may be integrated into one unit. The above-mentioned integrated unit may be implemented in the form of hardware or in the form of hardware plus software functional modules.
[0143] It is obvious to those skilled in the art that the present invention is not limited to the details of the above exemplary embodiments, and that the present invention can be implemented in other specific forms without departing from the spirit or essential characteristics of the present invention.
[0144] Therefore, no matter from which point of view, the embodiments should be regarded as illustrative and non-restrictive, and the scope of the present invention is limited by the appended claims rather than the above description, so it is intended that all changes falling within the meaning and scope of the equivalent elements of the claims are included in the present invention. Any attached figure mark in the claims should not be regarded as limiting the claims involved.
[0145] The blockchain referred to in this invention is a new application mode of computer technologies such as distributed data storage, peer-to-peer transmission, consensus mechanism, encryption algorithm, etc. Blockchain is essentially a decentralized database, a string of data blocks generated by cryptographic methods. Each data block contains a batch of network transaction information, which is used to verify the validity of its information (anti-counterfeiting) and generate the next block. Blockchain can include the underlying blockchain platform, platform product service layer, and application service layer.
[0146] In addition, it is clear that the word "comprising" does not exclude other units or steps, and the singular does not exclude the plural. Multiple units or devices stated in the system claim can also be implemented by one unit or device through software or hardware. The second and other words are used to indicate names, but not to indicate any particular order.
[0147] Finally, it should be noted that the above embodiments are only used to illustrate the technical solution of the present invention rather than to limit it. Although the present invention has been described in detail with reference to the preferred embodiments, those skilled in the art should understand that the technical solution of the present invention can be modified or replaced by equivalents without departing from the spirit and scope of the technical solution of the present invention.
Claims
1. A method for named entity recognition, characterized in that: The method comprises: Acquire multiple data sets from a database, determine a named entity category set corresponding to each data set, split each data set into initial data sets corresponding to each named entity category in the corresponding named entity category set, wherein the initial data set corresponding to one named entity category includes positive samples of the named entity category and negative samples of other named entity categories, and aggregate the initial data sets corresponding to each named entity category to obtain sub-data sets corresponding to each named entity category; Constructing a named entity recognition model, wherein the named entity recognition model includes a plurality of output branches, each output branch corresponds to a named entity category, and inputting a sub-data set corresponding to each named entity category into the named entity recognition model for training to obtain a trained named entity recognition model; Responding to a named entity recognition request issued by a user based on a client, parsing the request, and obtaining the text to be named entity recognized and the target named entity category carried in the request; The text to be named entity recognized is input into the trained named entity recognition model, and the recognition result output by the output branch corresponding to the target named entity category is used as the target recognition result of the text to be named entity recognized.
2. The method for named entity recognition according to claim 1, characterized in that: Determining a set of named entity categories corresponding to each data set includes: Converting the annotation information carried by each of the multiple data sets from an initial annotation format to a preset annotation format; A named entity category set corresponding to each data set is determined according to the annotation information in the preset annotation format.
3. The method for named entity recognition according to claim 1, wherein: The construction of the named entity recognition model includes: The BERT model is used as the main branch of the named entity recognition model, and multiple output branches are added after the main branch according to the number of named entity categories, and the output branch includes a fully connected layer.
4. The method for named entity recognition according to claim 2, wherein: The training process of the named entity recognition model includes: Selecting a sub-dataset corresponding to a named entity category and inputting it into the named entity recognition model, and using the recognition result output by the output branch corresponding to the selected named entity category as the predicted named entity of the sub-dataset corresponding to the selected named recognition category; The real named entities of the sub-dataset corresponding to the selected named entity category are obtained according to the annotation information of the preset annotation format, and the weight parameters of the output branch corresponding to the selected named entity category of the named entity recognition model are determined by minimizing the accuracy loss value between the real named entities and the predicted named entities.
5. The method for named entity recognition according to claim 4, characterized in that: The calculation formula of the accuracy loss value is: Among them, q i is the predicted named entity of the sub-dataset corresponding to the i-th named entity category, p i is the real named entity of the sub-dataset corresponding to the i-th named entity category, loss(q i ,p i ) is the accuracy loss value between the real named entity and the predicted named entity in the sub-dataset corresponding to the i-th named entity category, and c is the total number of named entity categories.
6. The method for named entity recognition according to claim 1, wherein: The step of splitting each data set into initial data sets corresponding to each named entity category in the corresponding named entity category set comprises: For each data set, the positive samples corresponding to a specified named entity category in the corresponding named entity category set are retained, and the samples corresponding to other named entity categories are used as negative samples to obtain an initial data set corresponding to the specified named entity category.
7. The method for named entity recognition according to claim 2, wherein: The initial annotation formats include BIOES, BMES and BIO, the preset annotation format is BIO, and converting the annotation information from the initial annotation format to the preset annotation format includes: The I annotation in the BIOES format is deleted, the S annotation is changed to the B annotation, and the E annotation is changed to the I annotation; The M mark in the BMES format is deleted, the S mark is changed to the B mark, and the E mark is changed to the I mark.
8. A named entity recognition device, characterized in that: The device comprises: An extraction module is used to obtain multiple data sets from a database, determine a named entity category set corresponding to each data set, split each data set into initial data sets corresponding to each named entity category in the corresponding named entity category set, wherein the initial data set corresponding to one named entity category includes positive samples of the named entity category and negative samples of other named entity categories, and aggregate the initial data sets corresponding to each named entity category to obtain sub-data sets corresponding to each named entity category; A training module is used to construct a named entity recognition model, wherein the named entity recognition model includes a plurality of output branches, each output branch corresponds to a named entity category, and a sub-data set corresponding to each named entity category is input into the named entity recognition model for training to obtain a trained named entity recognition model; A request module, used to respond to a named entity recognition request issued by a user based on a client, parse the request, and obtain the text to be named entity recognized and the target named entity category carried in the request; The output module is used to input the text to be named entity recognized into the trained named entity recognition model, and use the recognition result output by the output branch corresponding to the target named entity category as the target recognition result of the text to be named entity recognized.
9. An electronic device, characterized in that: The electronic device comprises: at least one processor; and, a memory communicatively connected to the at least one processor; wherein, The memory stores a named entity recognition program executable by the at least one processor, and the named entity recognition program is executed by the at least one processor so that the at least one processor can perform the named entity recognition method according to any one of claims 1 to 7.
10. A computer-readable storage medium, characterized in that: The computer-readable storage medium stores a named entity recognition program, and the named entity recognition program can be executed by one or more processors to implement the named entity recognition method according to any one of claims 1 to 7.
Citation Information
Patent Citations
Language Modeling Using Entities
US20150340024A1