Named entity recognition method and device, electronic device and storage medium

By adjusting the parameters of the entity recognition model and combining characters and location tags, the problem of difficulty in identifying multiple types of named entities in the existing technology is solved, the accurate positioning and identification of multiple types of entities in the text is achieved, and the accuracy of named entity recognition is improved. sex and efficiency.

CN116384399BActive Publication Date: 2024-09-10华润数字科技有限公司
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
CN202310330086.3
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2023-03-27
Publication Date
2024-09-10
Estimated Expiration
2043-03-27

AI Technical Summary

Technical Problem

It is difficult for the existing technology to accurately identify named entities of flat classes, nested classes and discontinuous classes in text at the same time, which affects the accuracy of named entity recognition.

Method used

By obtaining the sample text with character labels and sample category labels, input it into the preset original entity recognition model, perform character encoding and position recognition, adjust the model parameters, and generate the target entity recognition model to achieve accurate positioning and identification of different entity categories. Identify.

Benefits of technology

It achieves simultaneous recognition of three entity categories in text: flat, nested, and discontinuous types, improving the accuracy and efficiency of named entity recognition.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN116384399B
    Figure CN116384399B
Patent Text Reader

Abstract

The embodiments of the present application provide a method and device for named entity recognition, an electronic device and a storage medium, which belong to the field of artificial intelligence technology. The method includes: obtaining a sample text with a character label and a sample category label; inputting the sample text into a preset original entity recognition model; encoding the sample characters according to the initial coding layer to obtain a character vector; performing position recognition on the character vector according to the initial position recognition layer to obtain an initial position label; performing named entity recognition on the sample text according to the initial entity recognition layer to obtain a recognized entity and an initial recognition category label of the recognized entity; adjusting the parameters of the original entity recognition model according to the initial recognition category label, the initial position label, the character label, and the sample category label to obtain a target entity recognition model; performing named entity recognition on the acquired text to be recognized according to the target entity recognition model. The embodiments of the present application can improve the accuracy of entity recognition.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present application relates to the field of artificial intelligence technology, and in particular to a method and device for named entity recognition, an electronic device, and a storage medium. Background Art

[0002] Named Entity Recognition (NER) refers to identifying entities with specific meanings in text, such as dates, place names, etc. According to the position of the text fragment corresponding to the entity in the text, the entity category includes flat category, nested category, and non-continuous category. In the related technology, only one or two entity categories in the text can be recognized, which affects the accuracy of named entity recognition. Therefore, how to improve the accuracy of named entity recognition has become a technical problem that needs to be solved urgently. Summary of the invention

[0003] The main purpose of the embodiments of the present application is to propose a method and device for named entity recognition, an electronic device and a storage medium, aiming to improve the accuracy of named entity recognition.

[0004] To achieve the above objective, a first aspect of an embodiment of the present application proposes a method for named entity recognition, the method comprising:

[0005] Acquire a sample text having a character label and a sample category label; wherein the sample text includes sample characters and sample entities, the character label is used to indicate the character category of the sample character, and the character category includes at least one of the following: first character category, last character category, middle character category, transition character category, and non-entity category; the sample category label is used to indicate the entity category of the sample entity, and the entity category includes any one of the following: flat category, nested category, and non-continuous category;

[0006] Inputting the sample text into a preset original entity recognition model; wherein the original entity recognition model includes an initial encoding layer, an initial position recognition layer, and an initial entity recognition layer;

[0007] Encode the sample character according to the initial encoding layer to obtain a character vector;

[0008] Performing position recognition on the character vector according to the initial position recognition layer to obtain an initial position label; wherein the initial position label is used to indicate the character category of the sample character;

[0009] Performing named entity recognition on the sample text according to the initial entity recognition layer to obtain a recognized entity and an initial recognition category label of the recognized entity; wherein the initial recognition category label is used to indicate the entity category of the recognized entity;

[0010] Adjusting the parameters of the original entity recognition model according to the initial recognition category label, the initial position label, the character label, and the sample category label to obtain a target entity recognition model;

[0011] The acquired text to be recognized is subjected to named entity recognition according to the target entity recognition model.

[0012] In some embodiments, the sample text also includes sample non-entities;

[0013] The step of adjusting parameters of the original entity recognition model according to the initial recognition category label, the initial position label, the character label, and the sample category label to obtain a target entity recognition model includes:

[0014] Obtaining contrast loss data according to the sample entity and the sample non-entity;

[0015] Obtaining position loss data according to the initial position label and the character label;

[0016] Obtaining category loss data according to the initial recognition category label and the sample category label;

[0017] The parameters of the original entity recognition model are adjusted according to the contrast loss data, the position loss data, and the category loss data to obtain the target entity recognition model.

[0018] In some embodiments, the initial location identification layer includes a first classifier, a second classifier, a third classifier, a fourth classifier, and a fifth classifier;

[0019] The step of performing position recognition on the character vector according to the initial position recognition layer to obtain an initial position label includes:

[0020] Recognize the first character position of the character vector according to the first classifier to obtain a first recognition result;

[0021] Perform tail character position recognition on the character vector according to the second classifier to obtain a second recognition result;

[0022] Performing intermediate character position recognition on the character vector according to the third classifier to obtain a third recognition result;

[0023] Perform transition character position recognition on the character vector according to the fourth classifier to obtain a fourth recognition result;

[0024] Performing non-entity position recognition on the character vector according to the fifth classifier to obtain a fifth recognition result;

[0025] The initial position tag is obtained according to the first recognition result, the second recognition result, the third recognition result, the fourth recognition result, and the fifth recognition result.

[0026] In some embodiments, performing named entity recognition on the sample text according to the initial entity recognition layer to obtain a recognized entity and an initial recognition category label of the recognized entity includes:

[0027] Performing named entity recognition on the sample text according to the initial entity recognition layer to obtain the recognized entity;

[0028] Screening the sample characters according to the recognition entity to obtain target characters;

[0029] Taking the character vector corresponding to the target character as the target vector, performing mean processing on the target vector to obtain average data;

[0030] The average data is normalized to obtain the initial recognition category label.

[0031] In some embodiments, performing named entity recognition on the sample text according to the initial entity recognition layer to obtain a recognized entity and an initial recognition category label of the recognized entity includes:

[0032] Performing named entity recognition on the sample text according to the initial entity recognition layer to obtain the recognized entity;

[0033] Building an entity index set according to the identified entity, and obtaining a target vector from the entity index set;

[0034] Performing mean processing on the target vector to obtain average data;

[0035] The average data is normalized to obtain the initial recognition category label.

[0036] In some embodiments, obtaining contrast loss data according to the sample entity and the sample non-entity includes:

[0037] Combining the sample entities to obtain entity pair data;

[0038] Obtain first vector data according to the entity pair data;

[0039] Obtain second vector data according to the sample non-entity;

[0040] Contrast loss data is obtained according to the first vector data and the second vector data.

[0041] In some embodiments, the target entity recognition model includes a target encoding layer, a target position recognition layer, and a target entity recognition layer;

[0042] The step of performing named entity recognition on the acquired text to be recognized according to the target entity recognition model includes:

[0043] Acquire the text to be recognized; wherein the text to be recognized includes characters to be recognized;

[0044] Encode the character to be recognized according to the target encoding layer to obtain a target vector;

[0045] Performing position recognition on the target vector according to the target position recognition layer to obtain a target position label;

[0046] The target position label and the target vector are input into the target entity recognition layer for named entity recognition to obtain a target entity and a target recognition category label, wherein the target recognition category label is used to indicate the entity category of the target entity.

[0047] To achieve the above-mentioned purpose, a second aspect of an embodiment of the present application provides a named entity recognition device, the device comprising:

[0048] A text acquisition module, used to acquire a sample text with a character label and a sample category label; wherein the sample text includes sample characters and sample entities, the character label is used to indicate the character category of the sample character, and the character category includes at least one of the following: first character category, last character category, middle character category, transition character category, and non-entity category; the sample category label is used to indicate the entity category of the sample entity, and the entity category includes any one of the following: flat category, nested category, and non-continuous category;

[0049] An input module, used for inputting the sample text into a preset original entity recognition model; wherein the original entity recognition model includes an initial encoding layer, an initial position recognition layer, and an initial entity recognition layer;

[0050] An encoding module, used for encoding the sample character according to the initial encoding layer to obtain a character vector;

[0051] A position recognition module, used for performing position recognition on the character vector according to the initial position recognition layer to obtain an initial position label; wherein the initial position label is used to indicate the character category of the sample character;

[0052] a first named entity recognition module, configured to perform named entity recognition on the sample text according to the initial entity recognition layer, and obtain a recognized entity and an initial recognition category label of the recognized entity; wherein the initial recognition category label is used to indicate an entity category of the recognized entity;

[0053] A parameter adjustment module, used to adjust the parameters of the original entity recognition model according to the initial recognition category label, the initial position label, the character label, and the sample category label to obtain a target entity recognition model;

[0054] The second named entity recognition module is used to perform named entity recognition on the acquired text to be recognized according to the target entity recognition model.

[0055] To achieve the above objectives, a third aspect of an embodiment of the present application proposes an electronic device, which includes a memory and a processor, wherein the memory stores a computer program, and when the processor executes the computer program, the method described in the first aspect is implemented.

[0056] To achieve the above-mentioned purpose, the fourth aspect of an embodiment of the present application proposes a computer-readable storage medium, wherein the computer-readable storage medium stores a computer program, and when the computer program is executed by a processor, the method described in the first aspect is implemented.

[0057] The named entity recognition method and device, electronic device and storage medium proposed in the present application set the sample category label and the initial position label to a label that combines the first character class, the last character class, the middle character class and the transition character class, so that the target entity recognition model can accurately locate the position of each character in entities with different entity categories, thereby realizing the simultaneous recognition of three entity categories in the text: flat class, nested class and non-continuous class, thereby improving the recognition accuracy and efficiency of named entity recognition. BRIEF DESCRIPTION OF THE DRAWINGS

[0058] Figure 1 is a flowchart of a method for named entity recognition provided by an embodiment of the present application;

[0059] Figure 2 is a schematic diagram of a character label according to an embodiment of the present application;

[0060] Figure 3 yes Figure 1 A flow chart of step S104 in FIG.

[0061] Figure 4 yes Figure 1 A flow chart of step S105 in FIG.

[0062] Figure 5 yes Figure 1Another flow chart of step S105 in;

[0063] Figure 6 yes Figure 1 A flow chart of step S106 in FIG.

[0064] Figure 7 yes Figure 1 A flow chart of step S107 in FIG.

[0065] Figure 8 is a schematic diagram of the structure of a named entity recognition device provided in an embodiment of the present application;

[0066] Fig. 9 It is a schematic diagram of the hardware structure of the electronic device provided in the embodiment of the present application. DETAILED DESCRIPTION

[0067] In order to make the purpose, technical solution and advantages of the present application more clearly understood, the present application 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 application and are not used to limit the present application.

[0068] It should be noted that, although the functional modules are divided in the device schematic diagram and the logical order is shown in the flowchart, in some cases, the steps shown or described may be performed in a different order than the module division in the device or the order in the flowchart. The terms "first", "second", etc. in the specification, claims and the above drawings are used to distinguish similar objects, and are not necessarily used to describe a specific order or sequence.

[0069] Unless otherwise defined, all technical and scientific terms used herein have the same meaning as those commonly understood by those skilled in the art to which this application belongs. The terms used herein are only for the purpose of describing the embodiments of this application and are not intended to limit this application.

[0070] First, some nouns involved in this application are analyzed:

[0071] Artificial intelligence (AI) is a new technical science that studies and develops theories, methods, technologies and application systems for simulating, extending and expanding human intelligence. AI is a branch of computer science that attempts to understand the essence of intelligence and produce a new type of intelligent machine that can respond in a similar way to human intelligence. Research in this field includes robotics, speech recognition, image recognition, natural language processing and expert systems. AI can simulate the information process of human consciousness and thinking. AI is also a theory, method, technology and application system that uses digital computers or machines controlled by digital computers to simulate, extend and expand human intelligence, perceive the environment, acquire knowledge and use knowledge to obtain the best results.

[0072] Natural language processing (NLP): NLP uses computers to process, understand and apply human languages ​​(such as Chinese, English, etc.). NLP is a branch of artificial intelligence and an interdisciplinary subject between computer science and linguistics. It is often referred to as computational linguistics. Natural language processing includes grammatical analysis, semantic analysis, and text understanding. Natural language processing is often used in technical fields such as machine translation, handwritten and printed character recognition, speech recognition and text-to-speech conversion, information intent recognition, information extraction and filtering, text classification and clustering, public opinion analysis and opinion mining. It involves data mining related to language processing, machine learning, knowledge acquisition, knowledge engineering, artificial intelligence research, and linguistic research related to language computing.

[0073] Information Extraction: A text processing technology that extracts specified types of entity, relationship, event and other factual information from natural language text and forms structured data output. Information extraction is a technology that extracts specific information from text data. Text data is composed of some specific units, such as sentences, paragraphs, and chapters. Text information is composed of some small specific units, such as characters, words, phrases, sentences, paragraphs, or a combination of these specific units. Extracting noun phrases, names, place names, etc. from text data are all text information extraction. Of course, the information extracted by text information extraction technology can be various types of information.

[0074] Named Entity Recognition (NER) refers to identifying entities with specific meanings in text, such as dates, place names, etc. According to the position of the text fragment corresponding to the entity in the text, the entity category includes flat category, nested category, and non-continuous category. In the related technology, only one or two entity categories in the text can be recognized, which affects the accuracy of named entity recognition. Therefore, how to improve the accuracy of named entity recognition has become a technical problem that needs to be solved urgently.

[0075] Based on this, the embodiments of the present application provide a method and device for named entity recognition, an electronic device and a storage medium, aiming to improve the accuracy of named entity recognition.

[0076] The named entity recognition method and device, electronic device and storage medium provided in the embodiments of the present application are specifically illustrated through the following embodiments. First, the named entity recognition method in the embodiments of the present application is described.

[0077] The embodiments of the present application can acquire and process relevant data based on artificial intelligence technology. Among them, artificial intelligence (AI) is the theory, method, technology and application system that uses digital computers or machines controlled by digital computers to simulate, extend and expand human intelligence, perceive the environment, acquire knowledge and use knowledge to obtain the best results.

[0078] AI basic technologies generally include sensors, dedicated AI chips, cloud computing, distributed storage, big data processing technology, operation / interaction systems, mechatronics, etc. AI software technologies mainly include computer vision technology, robotics technology, biometrics technology, speech processing technology, natural language processing technology, and machine learning / deep learning.

[0079] The named entity recognition method provided in the embodiment of the present application relates to the field of artificial intelligence technology. The named entity recognition method provided in the embodiment of the present application can be applied to a terminal, can be applied to a server side, or can be software running in a terminal or a server side. In some embodiments, the terminal can be a smart phone, a tablet computer, a laptop computer, a desktop computer, etc.; the server side can be configured as an independent physical server, or a server cluster or distributed system composed of multiple physical servers, or a cloud server that provides basic cloud computing services such as cloud services, cloud databases, cloud computing, cloud functions, cloud storage, network services, cloud communications, middleware services, domain name services, security services, CDN, and big data and artificial intelligence platforms; the software can be an application that implements the named entity recognition method, etc., but is not limited to the above forms.

[0080] The present application can be used in many general or special computer system environments or configurations. For example: personal computers, server computers, handheld or portable devices, tablet devices, multiprocessor systems, microprocessor-based systems, set-top boxes, programmable consumer electronics, network PCs, minicomputers, mainframe computers, distributed computing environments including any of the above systems or devices, etc. The present application can be described in the general context of computer-executable instructions executed by a computer, such as program modules. Generally, program modules include routines, programs, objects, components, data structures, etc. that perform specific tasks or implement specific abstract data types. The present application can also be practiced in distributed computing environments, in which tasks are performed by remote processing devices connected through a communication network. In a distributed computing environment, program modules can be located in local and remote computer storage media including storage devices.

[0081] Figure 1 is an optional flowchart of the named entity recognition method provided in an embodiment of the present application. Figure 1 The method may include but is not limited to steps S101 to S107.

[0082] Step S101, obtaining a sample text with a character label and a sample category label; wherein the sample text includes sample characters and sample entities, the character label is used to indicate the character category of the sample character, and the character category includes at least one of the following: first character category, last character category, middle character category, transition character category, and non-entity category; the sample category label is used to indicate the entity category of the sample entity, and the entity category includes any one of the following: flat category, nested category, and non-continuous category;

[0083] Step S102, inputting the sample text into a preset original entity recognition model; wherein the original entity recognition model includes an initial encoding layer, an initial position recognition layer, and an initial entity recognition layer;

[0084] Step S103, encoding the sample character according to the initial encoding layer to obtain a character vector;

[0085] Step S104, performing position recognition on the character vector according to the initial position recognition layer to obtain an initial position label; wherein the initial position label is used to indicate the character category of the sample character;

[0086] Step S105, performing named entity recognition on the sample text according to the initial entity recognition layer to obtain a recognized entity and an initial recognition category label of the recognized entity; wherein the initial recognition category label is used to indicate the entity category of the recognized entity;

[0087] Step S106, adjusting the parameters of the original entity recognition model according to the initial recognition category label, the initial position label, the character label, and the sample category label to obtain a target entity recognition model;

[0088] Step S107, performing named entity recognition on the acquired text to be recognized according to the target entity recognition model.

[0089] In steps S101 to S107 shown in the embodiment of the present application, by setting the sample category label and the initial position label to a label that combines the first character class, the last character class, the middle character class, and the transition character class, the target entity recognition model can accurately locate the position of each character in entities with different entity categories, thereby realizing the simultaneous recognition of the three entity categories of flat class, nested class, and non-continuous class in the text, thereby improving the recognition accuracy and efficiency of named entity recognition.

[0090] In step S101 of some embodiments, a sample text is obtained. The sample text refers to the text used to train the original entity recognition model. The sample text includes sample characters and sample entities. The sample characters refer to the characters in the sample text. The sample entities refer to the words composed of sample characters that can represent place names, dates, times, product names, brand names, etc. with specific meanings. For example, for the sample text "The first children's high-top basketball shoes of X brand", it includes eleven sample characters: "X", "brand", "first", "section", "child", "ren", "high", "top", "basket", "ball", "shoes". These eleven sample characters can be arbitrarily combined into sample entities such as "X brand", "children's basketball shoes", "high-top basketball shoes", "children's high-top basketball shoes". The character labels and sample category labels of the sample text are obtained in advance by means of annotation, etc. The character labels are used to represent the character categories of the corresponding sample characters. The character categories include at least one of the following: first character class, last character class, middle character class, transition character class, non-entity class. Among them, the first character class means that the sample character is the first character of the corresponding sample entity; the last character class means that the sample character is the last character of the corresponding sample entity; the middle character class means that the sample character is the middle character of the corresponding sample entity. The middle character refers to the character other than the first character and the last character in the sample entity; the transition character class means that the sample character is the character that transitions the sample characters corresponding to other sample entities in the sample text; the non-entity class means that the sample character cannot form an entity with other sample characters. It can be seen that the character label is essentially used to represent the position of the sample character in the sample entity. Taking the sample entity "high-top basketball shoes" as an example, the sample character "high" is the first character of this sample entity, the sample character "shoes" is the last character of this sample entity, and the sample characters "top", "basket", "ball" are the middle characters of this sample entity. Secondly, taking the sample entity "children's basketball shoes" as an example, the sample characters "high", "top" are the transition characters of this sample entity. Therefore, for different sample entities, the character categories of the sample characters may be different. In the embodiments of the present application, B represents the first character class, I represents the middle character class, E represents the last character class, O represents the non-entity class, and M represents the transition character class. Therefore, the character label t ∈ {B, I, O, E, M}, and B, I, O, E, M all take values of 0 or 1. Taking B as an example, when B takes the value of 1, it indicates that the character category of the corresponding sample character includes the first character class; when B takes the value of 0, it indicates that the character category of the corresponding sample character does not include the first character class.

[0091] Refer to Figure 2 , which is the character label corresponding to each sample character in the sample text "The first children's high-top basketball shoes of X brand". For example, the character label y of the sample character "X" i ∈ {1, 0, 0, 0, 0}, and the character label y of the sample character "brand" i ∈ {1, 0, 0, 0, 0}.

[0092] The sample category label is used to indicate the entity category of the sample entity, and the entity category includes any of the flat category, nested category, and non-continuous category. Taking the sample text "X brand's first children's high-top basketball shoes" as an example, the flat category refers to the multiple sample characters that make up the sample entity are continuous characters in the sample text, such as the sample entity "high-top basketball shoes"; the nested category refers to two or more sample entities, and their corresponding sample characters have overlapping characters, such as the sample entities "high-top basketball shoes" and "basketball shoes"; the non-continuous category refers to the multiple sample characters that make up the sample entity are non-continuous characters in the sample text, such as the sample entity "X brand basketball shoes".

[0093] In step S102 of some embodiments, an original entity recognition model including an initial encoding layer, an initial position recognition layer, and an initial entity recognition layer is pre-set.

[0094] In step S103 of some embodiments, the sample characters are used as input data of the initial coding layer, and the sample characters are vectorized by the initial coding layer to obtain character vectors. That is, the sample text X=[x 1 ,x 2 ,...,x n ] is expressed as H = [h 1 ,h 2 ,...,h n ]. Among them, h 1 is the sample character x 1 The character vector of the sample text has a total of n sample characters. It can be understood that the initial coding layer may include the original coding layer and a bidirectional long short-term memory layer (Long short-term memory, LSTM), or other network structures, which are not specifically limited in the embodiments of the present application.

[0095] In step S104 of some embodiments, the character vector is used as input data of the initial position recognition layer, and the character vector is positionally recognized by the initial position recognition layer to obtain an initial position label for representing the sample character corresponding to the character vector. The initial position label is used to represent the recognition result of the character category of the sample character by the initial position recognition layer. It can be understood that the character category of this embodiment is the same as the character category described in step S101, so the initial position label y 1 ∈{B,I,O,E,M}. The following is an explanation of the method for determining the initial position label.

[0096] Reference Figure 3 In some embodiments, step S104 includes but is not limited to steps S301 to S306.

[0097] Step S301, identifying the first character position of the character vector according to the first classifier to obtain a first recognition result;

[0098] Step S302, identifying the tail character position of the character vector according to the second classifier to obtain a second recognition result;

[0099] Step S303, identifying the middle character position of the character vector according to the third classifier to obtain a third recognition result;

[0100] Step S304, performing transition character position recognition on the character vector according to the fourth classifier to obtain a fourth recognition result;

[0101] Step S305, performing non-entity position recognition on the character vector according to the fifth classifier to obtain a fifth recognition result;

[0102] Step S306, obtaining an initial position tag according to the first recognition result, the second recognition result, the third recognition result, the fourth recognition result, and the fifth recognition result.

[0103] In the embodiment of the present application, the initial position recognition layer includes a first classifier, a second classifier, a third classifier, a fourth classifier, and a fifth classifier, and one classifier is used to recognize one character category.

[0104] In step S301 of some embodiments, the first classifier is used to identify the first character class of the character vector, and when the sample character corresponding to the character vector is the first character of a certain entity, the first recognition result is 1. Otherwise, the first recognition result is 0.

[0105] In step S302 of some embodiments, the second classifier is used to identify the tail character class of the character vector, and when the sample character corresponding to the character vector is the tail character of a certain entity, the second recognition result is 1. Otherwise, the second recognition result is 0.

[0106] In step S303 of some embodiments, the third classifier is used to identify the middle character class of the character vector, and when the sample character corresponding to the character vector is the middle character of a certain entity, the third recognition result is 1. Otherwise, the third recognition result is 0.

[0107] In step S304 of some embodiments, the fourth classifier is used to identify the transition character class of the character vector, and when the sample character corresponding to the character vector is a transition character of a certain entity, the fourth recognition result is 1. Otherwise, the fourth recognition result is 0.

[0108] In step S305 of some embodiments, the fifth classifier is used to identify the non-entity class of the character vector, and when the sample character corresponding to the character vector is not a character included in any entity, the fourth recognition result is 1. Otherwise, the fourth recognition result is 0.

[0109] In step S306 of some embodiments, the first recognition result, the second recognition result, the third recognition result, the fourth recognition result, and the fifth recognition result are aggregated to obtain an initial location tag.

[0110] The benefit of steps S301 to S306 is that it is possible to accurately identify whether the character category of the sample character includes the first character category, whether it includes the last character category, whether it includes the middle character category, whether it includes the transition character category, and whether it includes the non-entity category, thereby providing a basis for the subsequent flat entity recognition, nested entity recognition, and non-continuous entity recognition of the sample text. It is understandable that the first recognition result is 1 when the first character category is included, and the first recognition result is 0 when the first character category is not included, and the same applies to other character categories.

[0111] In step S105 of some embodiments, the sample text is used as input data of the initial entity recognition layer, and the named entities included in the sample text are recognized by the initial entity recognition layer to obtain the recognized entity and the initial recognition category label of the recognized entity. The recognized entity refers to the entity recognized by the initial entity recognition layer from the sample text, and the initial recognition category label refers to the entity category of the recognized entity, that is, the initial recognition category label is used to indicate whether the recognized entity is a flat class, a nested class, or a non-continuous class. The process of determining the initial recognition category label is described in detail below.

[0112] Reference Figure 4 In some embodiments, step S105 includes but is not limited to steps S401 to S404.

[0113] Step S401, performing named entity recognition on the sample text according to the initial entity recognition layer to obtain recognized entities;

[0114] Step S402, screening the sample characters according to the recognition entity to obtain the target characters;

[0115] Step S403, taking the character vector corresponding to the target character as the target vector, performing mean processing on the target vector to obtain average data;

[0116] Step S404, normalize the average data to obtain an initial recognition category label.

[0117] In step S401 of some embodiments, named entity recognition is performed on the sample text according to the initial entity recognition layer to determine recognized entities in the sample text.

[0118] In steps S402 to S403 of some embodiments, the sample characters included in the recognized entity are determined, and the sample characters included in the recognized entity are used as target characters. For example, the recognized entity "children's high-top basketball shoes" includes the following sample characters: child, child, high, top, basket, ball, shoes, and the above sample characters are used as target characters. The character vector corresponding to the target character is used as the target vector, and all target vectors are averaged to obtain average data. It can be seen that the average data is the average representation of the target vector. When the recognized entities are different, the corresponding average data will also be different. Therefore, the recognition error of the initial entity recognition layer can be determined by the average data.

[0119] In step S404 of some embodiments, the average data is normalized to determine the probability that the recognized entity corresponds to different entity categories, and the initial recognition category label is obtained according to the entity category with the largest probability value. For example, for a certain recognized entity, the probability of judging that it is a flat class is 10%, the probability of a nested class is 30%, and the probability of a non-continuous class is 60%, then the initial recognition label is used to indicate that the entity category of the recognized entity is a non-continuous class. Specifically, the initial recognition category label is calculated according to the following formula (1):

[0120]

[0121] Among them, W t represents the parameter matrix of the initial entity recognition layer, and g represents the average data.

[0122] The advantage of step S401 to step S404 is that since step S401 to step S404 directly matches the target character corresponding to the recognized entity to obtain the target vector, the accuracy of determining the target vector can be improved to a certain extent, thereby improving the accuracy of determining the initial recognition category label.

[0123] In some embodiments, since steps S401 to S404 are directly matched to obtain the target vector, the matching speed is slow. Figure 5 In some other embodiments, step S105 includes but is not limited to steps S501 to S504.

[0124] Step S501, performing named entity recognition on the sample text according to the initial entity recognition layer to obtain recognized entities;

[0125] Step S502, constructing an entity index set according to the identified entity, and obtaining a target vector from the entity index set;

[0126] Step S503: Perform mean processing on the target vector to obtain average data;

[0127] Step S504: Perform normalization processing on the average data to obtain the initial recognition category label.

[0128] In step S501 of some embodiments, the implementation content of step 501 is similar to that of step S401, and the embodiments of this application will not elaborate on this again.

[0129] In step S502 of some embodiments, an entity index set is constructed. The entity index set is a set used to index recognized entities. For example, if the initial entity recognition layer recognizes two recognized entities, "children's basketball shoes" and "high-top basketball shoes", from the sample text "children's high-top basketball shoes", then the entity index set Z = [Z 1 , Z 2 . Among them, Z 1 is the index of the recognized entity "children's basketball shoes", and Z 2 is the index of the recognized entity "high-top basketball shoes". The entity index set also includes a character identification set corresponding to each index. The character identification is used to represent the positions of the characters that make up the recognized entity in the sample text. Taking the recognized entity "children's basketball shoes" as an example, this recognized entity includes the following characters: child, children, basket, ball, shoes. Assuming that the character identification corresponding to the first character in the sample text is set to 1, then the character identification corresponding to the character "child" is 1, the character identification corresponding to the character "children" is 2, the character identification corresponding to the character "basket" is 5, the character identification corresponding to the character "ball" is 6, and the character identification corresponding to the character "shoes" is 7. Therefore, the entity index set also includes the character identification set Z 1 corresponding to the index Z 1 = [1, 2, 5, 6, 7]. Similarly, the entity index set also includes the character identification set Z 2 corresponding to the index Z 2 = [3, 4, 5, 6, 7]. Traverse and extract the indexes in the entity index set, and obtain the target vector according to the character identification set corresponding to the extracted index from H = [h 1 , h 2 ,..., h n in step S103. For example, if the extracted index is Z 1 , at this time, according to the character identification set [1, 2, 5, 6, 7] corresponding to the index Z 1 , the following target vectors are obtained: h 1 , h 2 , h 5 , h 6 , h 7 . Similarly, the following target vectors can be obtained according to the index Z 2 : h 3 , h4 、h 5 、h 6 、h 7 .

[0130] In some embodiments, the implementation content of step S503 is similar to the implementation content of step S403, and the implementation content of step S504 is similar to the implementation content of step S404, which will not be repeated here.

[0131] It can be seen that the difference between steps S501 to S504 and steps S401 to S404 is only step S503. The advantage of steps S501 to S504 obtaining the target vector according to the entity index set is that since the amount of calculation for determining the target vector by matching numbers with numbers (the method shown in step S502) is less than the amount of calculation for determining the target vector by matching characters with vectors (the method shown in step S403), steps S501 to S504 can improve the speed of determining the target vector to a certain extent, thereby improving the speed of determining the initial recognition category label.

[0132] In step S106 of some embodiments, the error of the original entity recognition model in recognizing the named entity is determined based on the initial recognition category label and the sample category label, and the error of the original entity recognition model in position recognition is determined based on the initial position recognition label and the character label. The parameters of the original entity recognition model are adjusted based on the above two errors to improve the recognition accuracy of the original entity recognition model, and a target entity recognition model is obtained.

[0133] In some embodiments, in order to improve the recognition accuracy of the original entity recognition module for entities, comparative learning is also performed based on sample non-entities and sample entities in the sample text. That is to say, the sample text also includes sample non-entities, and sample non-entities refer to words in the sample text that do not belong to entities. Sample non-entities can be obtained in advance based on annotations and other methods. Taking the sample text "X brand's first children's high-top basketball shoes" as an example, it includes sample non-entities such as high basketball shoes, children's top basketball shoes, and first top basketball shoes. Parameter adjustment is a method of continuously reducing the recognition error of the original entity recognition model to obtain the target entity recognition model. The process of parameter adjustment is explained in detail below. Refer to Figure 6 , step S106 includes but is not limited to steps S601 to S604.

[0134] Step S601, obtaining contrast loss data according to sample entities and sample non-entities;

[0135] Step S602, obtaining position loss data according to the initial position label and the character label;

[0136] Step S603, obtaining category loss data according to the initial recognition category label and the sample category label;

[0137] Step S604: Adjust the parameters of the original entity recognition model according to the contrast loss data, position loss data, and category loss data to obtain the target entity recognition model.

[0138] In step S601 of some embodiments, the character vectors corresponding to the sample characters that make up the sample non-entity are screened out from the character vectors obtained in step S103. For example, for the sample non-entity "high basketball shoes", the character vectors of the following sample characters are screened out: high, basket, ball, shoes. The screened character vectors are subjected to mean processing as shown in step S403 to obtain the average data corresponding to the sample non-entity. The average data set of the sample non-entity is Neg = [q 1 ...]. Randomly select two sample entities from multiple sample entities to form a sample entity pair, and represent the average data of the two sample entities that make up the sample entity pair as g i and g j .

[0139] Calculate the contrast loss data loss according to the following formula (2) contrast .

[0140]

[0141] Among them, the hyperparameter T is a temperature coefficient used to control the attention degree of the original entity recognition model to the samples (including sample non-entities and sample entity pairs). The W' matrix is used to map the average data into another space for comparison.

[0142] It can be seen from this that step S601 can be summarized as the following steps:

[0143] Combine the sample entities to obtain entity pair data (i.e., sample entity pairs);

[0144] Obtain the first vector data according to the entity pair data (i.e., g i and g j );

[0145] Obtain the second vector data according to the sample non-entity (i.e., Neg = [q 1 ...]);

[0146] Obtain the contrast loss data according to the first vector data and the second vector data.

[0147] In step S602 of some embodiments, calculate the position loss data loss according to the following formulas (3) and (4) multi .

[0148]

[0149]

[0150] Among them, W z represents the parameter matrix of the z-th classifier, Represents the recognition result output by the zth classifier, y i represents the character label and CR() represents the cross entropy loss function.

[0151] In step S603 of some embodiments, the category loss data loss is calculated according to the following formula (5): cls .

[0152]

[0153] Among them, y′ i represents the sample category label, and L represents the number of sample entities determined in step S101.

[0154] In step S604 of some embodiments, the comparison loss data loss contrast , location loss data loss multi , category loss data loss cls The target loss data is obtained by summing the data. The parameters of the original entity recognition model are adjusted according to the target loss data to obtain a target entity recognition model with higher entity recognition accuracy. It is understandable that, according to the parameter adjustment, different adjustment weights can be set for the contrast loss data, position loss data, and category loss data to achieve adaptive adjustment according to actual conditions.

[0155] The benefit of steps S601 to S604 is that the ability of the original entity recognition model to distinguish entities from non-entities is enhanced through contrast loss data, the ability of the original entity recognition model to determine character categories is enhanced through position loss data, and the ability of the original entity recognition model to determine entity categories is enhanced through category loss data. Therefore, the target entity recognition model obtained based on contrast loss data, position loss data, and category loss data has higher entity recognition accuracy than the original entity recognition model.

[0156] In step S107 of one embodiment, the text to be recognized is used as input data of the target entity recognition model, and the target entity recognition model performs named entity recognition on the text to be recognized. Downstream tasks related to NLP such as knowledge graphs and question-answering systems can be performed based on the recognized named entities.

[0157] In some embodiments, the target entity recognition model obtained after parameter adjustment includes a target encoding layer, a target position recognition layer, and a target entity recognition layer. Figure 7 In some embodiments, step S107 includes but is not limited to steps S701 to S704.

[0158] Step S701, obtaining a text to be recognized; wherein the text to be recognized includes characters to be recognized;

[0159] Step S702, encoding the character to be recognized according to the target coding layer to obtain a target vector;

[0160] Step S703, performing position recognition on the target vector according to the target position recognition layer to obtain a target position label;

[0161] Step S704: Input the target position label and the target vector into the target entity recognition layer for named entity recognition to obtain the target entity and the target recognition category label, wherein the target recognition category label is used to indicate the entity category of the target entity.

[0162] In step S701 of some embodiments, the text to be recognized is obtained, and the text to be recognized refers to the text that needs to be recognized by named entity recognition. The text to be recognized includes characters to be recognized. When the present application is applied to a terminal, the terminal may be loaded with an application for executing the named entity recognition method, and the application may include an input window, and the text to be recognized is obtained by responding to the operation of pasting text in the input window. Alternatively, a file upload control is provided in the application, and a file with text to be recognized is obtained by responding to the operation of triggering the file upload control, and the text to be recognized is obtained by performing optical character recognition (OCR) and other operations on the file. It can be seen that the embodiment of the present application does not specifically limit the method of obtaining the text to be recognized.

[0163] In step S702 of some embodiments, the target coding layer refers to a model corresponding to the adjusted initial coding layer after the parameters of the original entity recognition model are adjusted. The characters to be recognized are used as input data of the target coding layer, and the characters to be recognized are vectorized through the target coding layer to obtain a target vector.

[0164] In step S703 of some embodiments, the target position recognition layer refers to the model corresponding to the adjusted initial position recognition layer after the parameters of the original entity recognition model are adjusted. The target vector is used as the input data of the target position recognition layer, and the position of the character to be recognized in the target entity that may be recognized is recognized by the target position recognition layer to obtain a target position label. The target position label is similar to the character label, and the target position label includes at least one of the following: first character class, last character class, middle character class, transition character class, and non-entity class. Among them, the target entity refers to the entity recognized by the target recognition model from the text to be recognized.

[0165] In step S704 of some embodiments, the target entity recognition layer refers to the model corresponding to the adjusted initial entity recognition layer after the parameters of the original entity recognition model are adjusted. The target position label and the target vector are used as input data of the target entity recognition layer. It can be understood that for a certain entity, the character category corresponding to the characters included therein can be the first character class + the last character class (for example, the entity "X brand"); or it can be the first character class + the middle character class + the last character class (for example, the entity "basketball shoes"); or it can be the first character class + (transition character class) + the middle character class + the last character class (for example, "X brand basketball shoes"), which means that the characters corresponding to the first character class and the characters corresponding to the middle character class are not continuous characters in the corresponding text, and the characters corresponding to the transition character class are separated; or it can be a combination of other character categories, which will not be listed one by one in the embodiments of the present application. It can be seen from this that an entity can be determined by a combination of different character categories, so the target entity recognition layer uses the target position label as the basis for identifying the target entity from multiple target vectors, and obtains the target entity, as well as the target recognition category label used to represent the entity category of the target entity.

[0166] The embodiment of the present application sets the sample category label and the initial position label as labels that combine the first character class, the last character class, the middle character class, and the transition character class, so that the target entity recognition model can accurately locate the position of each character in entities with different entity categories, thereby realizing the simultaneous recognition of the three entity categories of flat class, nested class, and non-continuous class in the text, thereby improving the recognition accuracy and efficiency of named entity recognition.

[0167] See also Figure 8 The embodiment of the present application also provides a named entity recognition device, which can implement the above-mentioned named entity recognition method, and the device includes:

[0168] The text acquisition module 801 is used to acquire a sample text with a character label and a sample category label; wherein the sample text includes sample characters and sample entities, the character label is used to indicate the character category of the sample character, and the character category includes at least one of the following: first character category, last character category, middle character category, transition character category, and non-entity category; the sample category label is used to indicate the entity category of the sample entity, and the entity category includes any one of the following: flat category, nested category, and non-continuous category;

[0169] An input module 802 is used to input the sample text into a preset original entity recognition model; wherein the original entity recognition model includes an initial encoding layer, an initial position recognition layer, and an initial entity recognition layer;

[0170] The encoding module 803 is used to encode the sample character according to the initial encoding layer to obtain a character vector;

[0171] The position recognition module 804 is used to perform position recognition on the character vector according to the initial position recognition layer to obtain an initial position label; wherein the initial position label is used to indicate the character category of the sample character;

[0172] The first named entity recognition module 805 is used to perform named entity recognition on the sample text according to the initial entity recognition layer to obtain a recognized entity and an initial recognition category label of the recognized entity; wherein the initial recognition category label is used to indicate the entity category of the recognized entity;

[0173] A parameter adjustment module 806 is used to adjust the parameters of the original entity recognition model according to the initial recognition category label, the initial position label, the character label, and the sample category label to obtain a target entity recognition model;

[0174] The second named entity recognition module 807 is used to perform named entity recognition on the acquired text to be recognized according to the target entity recognition model.

[0175] The specific implementation of the named entity recognition device is basically the same as the specific implementation of the above-mentioned named entity recognition method, and will not be repeated here.

[0176] The embodiment of the present application also provides an electronic device, the electronic device includes a memory and a processor, the memory stores a computer program, and the processor implements the above-mentioned named entity recognition method when executing the computer program. The electronic device can be any intelligent terminal including a tablet computer, a car computer, etc.

[0177] See also Fig. 9 , Fig. 9 The hardware structure of an electronic device of another embodiment is illustrated, and the electronic device includes:

[0178] The processor 901 may be implemented by a general-purpose CPU (Central Processing Unit), a microprocessor, an application-specific integrated circuit (Application Specific Integrated Circuit, ASIC), or one or more integrated circuits, and is used to execute relevant programs to implement the technical solutions provided in the embodiments of the present application;

[0179] The memory 902 can be implemented in the form of a read-only memory (ROM), a static storage device, a dynamic storage device, or a random access memory (RAM). The memory 902 can store an operating system and other application programs. When the technical solution provided in the embodiment of this specification is implemented by software or firmware, the relevant program code is stored in the memory 902, and the processor 901 calls and executes the named entity recognition method of the embodiment of this application;

[0180] Input / output interface 903, used to implement information input and output;

[0181] Communication interface 904, used to realize communication interaction between the device and other devices, which can be realized by wired mode (such as USB, network cable, etc.) or wireless mode (such as mobile network, WIFI, Bluetooth, etc.);

[0182] A bus 905 that transmits information between the various components of the device (e.g., the processor 901, the memory 902, the input / output interface 903, and the communication interface 904);

[0183] The processor 901 , the memory 902 , the input / output interface 903 and the communication interface 904 are connected to each other in communication within the device via a bus 905 .

[0184] An embodiment of the present application also provides a computer-readable storage medium, which stores a computer program. When the computer program is executed by a processor, the above-mentioned named entity recognition method is implemented.

[0185] The memory, as a non-transient computer-readable storage medium, can be used to store non-transient software programs and non-transient computer executable programs. In addition, the memory may include a high-speed random access memory, and may also include a non-transient memory, such as at least one disk storage device, a flash memory device, or other non-transient solid-state storage device. In some embodiments, the memory may optionally include a memory remotely disposed relative to the processor, and these remote memories may be connected to the processor via a network. Examples of the above-mentioned network include, but are not limited to, the Internet, an intranet, a local area network, a mobile communication network, and combinations thereof.

[0186] The embodiments described in the embodiments of the present application are intended to more clearly illustrate the technical solutions of the embodiments of the present application and do not constitute a limitation on the technical solutions provided in the embodiments of the present application. Those skilled in the art will appreciate that with the evolution of technology and the emergence of new application scenarios, the technical solutions provided in the embodiments of the present application are also applicable to similar technical problems.

[0187] Those skilled in the art will appreciate that the technical solutions shown in the figures do not constitute a limitation on the embodiments of the present application, and may include more or fewer steps than shown in the figures, or a combination of certain steps, or different steps.

[0188] The device embodiments described above are merely illustrative, and the units described as separate components may or may not be physically separated, 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.

[0189] Those skilled in the art will appreciate that all or some of the steps in the methods disclosed above, and the functional modules / units in the systems and devices may be implemented as software, firmware, hardware, or a suitable combination thereof.

[0190] The terms "first", "second", "third", "fourth", etc. (if any) in the specification of the present application and the above-mentioned drawings are used to distinguish similar objects, and are not necessarily used to describe a specific order or sequence. It should be understood that the data used in this way can be interchangeable where appropriate, so that the embodiments of the present application described herein can be implemented in an order other than those illustrated or described herein. In addition, the terms "including" and "having" and any of their variations are intended to cover non-exclusive inclusions, for example, a process, method, system, product or device comprising a series of steps or units is not necessarily limited to those steps or units clearly listed, but may include other steps or units that are not clearly listed or inherent to these processes, methods, products or devices.

[0191] It should be understood that in the present application, "at least one (item)" means one or more, and "plurality" means two or more. "And / or" is used to describe the association relationship of associated objects, indicating that three relationships may exist. For example, "A and / or B" can mean: only A exists, only B exists, and A and B exist at the same time, where A and B can be singular or plural. The character " / " generally indicates that the objects associated before and after are in an "or" relationship. "At least one of the following" or similar expressions refers to any combination of these items, including any combination of single or plural items. For example, at least one of a, b or c can mean: a, b, c, "a and b", "a and c", "b and c", or "a and b and c", where a, b, c can be single or multiple.

[0192] In the several embodiments provided in the present application, it should be understood that the disclosed devices and methods can be implemented in other ways. For example, the device embodiments described above are only schematic. For example, the division of the above units is only a logical function division. There may be other division methods in actual implementation, such as 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 interfaces, indirect coupling or communication connection of devices or units, which can be electrical, mechanical or other forms.

[0193] The units described above 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.

[0194] In addition, each functional unit in each embodiment of the present application 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 software functional units.

[0195] If the integrated unit 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. Based on this understanding, the technical solution of the present application, or the part that contributes to the prior art, or all or part of the technical solution can be embodied in the form of a software product, and the computer software product is stored in a storage medium, including multiple instructions to enable a computer device (which can be a personal computer, server, or network device, etc.) to execute all or part of the steps of the methods of various embodiments of the present application. The aforementioned storage medium includes: U disk, mobile hard disk, read-only memory (Read-Only Memory, referred to as ROM), random access memory (Random Access Memory, referred to as RAM), disk or optical disk and other media that can store programs.

[0196] The preferred embodiments of the present invention are described above with reference to the accompanying drawings, but the scope of the rights of the present invention is not limited thereto. Any modification, equivalent substitution and improvement made by a person skilled in the art without departing from the scope and essence of the present invention should be within the scope of the rights of the present invention.

Claims

1. A method for named entity recognition, It is characterized in that The method comprises: Acquire a sample text having a character label and a sample category label; wherein the sample text includes sample characters and sample entities, the character label is used to indicate the character category of the sample character, and the character category includes at least one of the following: first character category, last character category, middle character category, transition character category, and non-entity category; the sample category label is used to indicate the entity category of the sample entity, and the entity category includes any one of the following: flat category, nested category, and non-continuous category; wherein the sample text also includes sample non-entities; Inputting the sample text into a preset original entity recognition model; wherein the original entity recognition model includes an initial encoding layer, an initial position recognition layer, and an initial entity recognition layer; Encode the sample character according to the initial encoding layer to obtain a character vector; According to the initial position recognition layer, the character vector is positionally recognized to obtain an initial position label; wherein the initial position label is used to represent the character category of the sample character; the initial position recognition layer includes a first classifier, a second classifier, a third classifier, a fourth classifier and a fifth classifier, wherein the character vector is positionally recognized to obtain an initial position label according to the initial position recognition layer, including: according to the first classifier, the first character position is recognized to obtain a first recognition result; according to the second classifier, the last character position is recognized to obtain a second recognition result; according to the third classifier, the middle character position is recognized to obtain a third recognition result; according to the fourth classifier, the transition character position is recognized to obtain a fourth recognition result; according to the fifth classifier, the non-entity position is recognized to obtain a fifth recognition result; the initial position label is obtained according to the first recognition result, the second recognition result, the third recognition result, the fourth recognition result and the fifth recognition result; Performing named entity recognition on the sample text according to the initial entity recognition layer to obtain a recognized entity and an initial recognition category label of the recognized entity; wherein the initial recognition category label is used to indicate the entity category of the recognized entity; The parameters of the original entity recognition model are adjusted according to the initial recognition category label, the initial position label, the character label, and the sample category label to obtain a target entity recognition model, including: obtaining contrast loss data according to the sample entity and the sample non-entity; obtaining position loss data according to the initial position label and the character label; obtaining category loss data according to the initial recognition category label and the sample category label; adjusting the parameters of the original entity recognition model according to the contrast loss data, the position loss data, and the category loss data to obtain the target entity recognition model; The step of obtaining the contrast loss data according to the sample entity and the sample non-entity specifically includes: Combining the sample entities to obtain entity pair data; Obtaining first vector data according to the entity pair data, including and ; According to the sample non-entity, the second vector data Neg=[q 1 ...q k ]; Obtain contrast loss data based on the first vector data and the second vector data : Wherein, the hyperparameter T is a temperature coefficient, which is used to control the degree of attention paid by the original entity recognition model to the sample non-entity and the entity pair data; the W′ matrix is ​​used to map the second vector data into another space for comparison; Wherein, obtaining the position loss data according to the initial position label and the character label includes: in, represents the parameter matrix of the z-th classifier, represents a character vector, represents the recognition result output by the zth classifier, represents the character label, CR( ) represents the cross entropy loss function, indicating said position loss data; Wherein, obtaining the category loss data according to the initial recognition category label and the sample category label includes: in, represents the sample category label, L represents the number of sample entities, Indicates the loss data of the said category; The acquired text to be recognized is subjected to named entity recognition according to the target entity recognition model.

2. The method according to claim 1, It is characterized in that The step of performing named entity recognition on the sample text according to the initial entity recognition layer to obtain a recognized entity and an initial recognition category label of the recognized entity includes: Performing named entity recognition on the sample text according to the initial entity recognition layer to obtain the recognized entity; Screening the sample characters according to the recognition entity to obtain target characters; Taking the character vector corresponding to the target character as the target vector, performing mean processing on the target vector to obtain average data; The average data is normalized to obtain the initial recognition category label.

3. The method according to claim 1, It is characterized in that The step of performing named entity recognition on the sample text according to the initial entity recognition layer to obtain a recognized entity and an initial recognition category label of the recognized entity includes: Performing named entity recognition on the sample text according to the initial entity recognition layer to obtain the recognized entity; Building an entity index set according to the identified entity, and obtaining a target vector from the entity index set; Performing mean processing on the target vector to obtain average data; The average data is normalized to obtain the initial recognition category label.

4. The method according to claim 1, It is characterized in that The obtaining of contrast loss data according to the sample entity and the sample non-entity includes: Combining the sample entities to obtain entity pair data; Obtain first vector data according to the entity pair data; Obtain second vector data according to the sample non-entity; Contrast loss data is obtained according to the first vector data and the second vector data.

5. The method according to any one of claims 1 to 4, It is characterized in that The target entity recognition model includes a target encoding layer, a target position recognition layer, and a target entity recognition layer; The step of performing named entity recognition on the acquired text to be recognized according to the target entity recognition model includes: Acquire the text to be recognized; wherein the text to be recognized includes characters to be recognized; Encode the character to be recognized according to the target encoding layer to obtain a target vector; Performing position recognition on the target vector according to the target position recognition layer to obtain a target position label; The target position label and the target vector are input into the target entity recognition layer for named entity recognition to obtain a target entity and a target recognition category label; wherein the target recognition category label is used to represent the entity category of the target entity.

6. A named entity recognition device, It is characterized in that The device comprises: A text acquisition module, used for acquiring a sample text with a character label and a sample category label; wherein the sample text includes sample characters and sample entities, the character label is used for indicating the character category of the sample character, and the character category includes at least one of the following: first character category, last character category, middle character category, transition character category, and non-entity category; the sample category label is used for indicating the entity category of the sample entity, and the entity category includes any one of the following: flat category, nested category, and non-continuous category; wherein the sample text also includes sample non-entities; An input module, used for inputting the sample text into a preset original entity recognition model; wherein the original entity recognition model includes an initial encoding layer, an initial position recognition layer, and an initial entity recognition layer; An encoding module, used for encoding the sample character according to the initial encoding layer to obtain a character vector; A position recognition module, used for performing position recognition on the character vector according to the initial position recognition layer to obtain an initial position label; wherein the initial position label is used to represent the character category of the sample character; the initial position recognition layer includes a first classifier, a second classifier, a third classifier, a fourth classifier and a fifth classifier, wherein the performing position recognition on the character vector according to the initial position recognition layer to obtain the initial position label includes: performing first character position recognition on the character vector according to the first classifier to obtain a first recognition result; performing tail character position recognition on the character vector according to the second classifier to obtain a second recognition result; performing intermediate character position recognition on the character vector according to the third classifier to obtain a third recognition result; performing transition character position recognition on the character vector according to the fourth classifier to obtain a fourth recognition result; performing non-entity position recognition on the character vector according to the fifth classifier to obtain a fifth recognition result; and obtaining the initial position label according to the first recognition result, the second recognition result, the third recognition result, the fourth recognition result and the fifth recognition result; a first named entity recognition module, configured to perform named entity recognition on the sample text according to the initial entity recognition layer, and obtain a recognized entity and an initial recognition category label of the recognized entity; wherein the initial recognition category label is used to indicate an entity category of the recognized entity; A parameter adjustment module, used for adjusting the parameters of the original entity recognition model according to the initial recognition category label, the initial position label, the character label, and the sample category label to obtain a target entity recognition model, including: obtaining contrast loss data according to the sample entity and the sample non-entity; obtaining position loss data according to the initial position label and the character label; obtaining category loss data according to the initial recognition category label and the sample category label; adjusting the parameters of the original entity recognition model according to the contrast loss data, the position loss data, and the category loss data to obtain the target entity recognition model; The step of obtaining the contrast loss data according to the sample entity and the sample non-entity specifically includes: Combining the sample entities to obtain entity pair data; Obtaining first vector data according to the entity pair data, including and ; According to the sample non-entity, the second vector data Neg=[q 1 ...q k ]; Obtain contrast loss data based on the first vector data and the second vector data : Wherein, the hyperparameter T is a temperature coefficient, which is used to control the degree of attention paid by the original entity recognition model to the sample non-entity and the entity pair data; the W′ matrix is ​​used to map the second vector data into another space for comparison; Wherein, obtaining the position loss data according to the initial position label and the character label includes: in, represents the parameter matrix of the z-th classifier, represents a character vector, represents the recognition result output by the zth classifier, represents the character label, CR( ) represents the cross entropy loss function, indicating said position loss data; Wherein, obtaining the category loss data according to the initial recognition category label and the sample category label includes: in, represents the sample category label, L represents the number of sample entities, Indicates the loss data of the said category; The second named entity recognition module is used to perform named entity recognition on the acquired text to be recognized according to the target entity recognition model.

7. An electronic device, It is characterized in that The electronic device comprises a memory and a processor, the memory stores a computer program, and the processor implements the method according to any one of claims 1 to 5 when executing the computer program.

8. A computer-readable storage medium storing a computer program. It is characterized in that When the computer program is executed by a processor, the method according to any one of claims 1 to 5 is implemented.