Named entity recognition method and device, electronic equipment and storage medium
By fusing the hidden vectors of words and tags from dictionary queries into the named entity recognition model, the problem of insufficient recognition capabilities of existing models for mid-to-long-tail entities and new entities is solved, thereby improving recognition accuracy and generalization ability.
Patent Information
- Application Number
- CN202310686476.4
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2023-06-09
- Publication Date
- 2026-11-20
- Estimated Expiration
- 2043-06-09
AI Technical Summary
Existing named entity recognition models are insufficient in recognizing mid-to-long-tail entities and new entities, and require retraining when the dictionary changes frequently, resulting in poor recognition accuracy.
By querying the word to which a character belongs and its tag from the dictionary, and combining the hidden vectors and embedding vectors of the character and tag, a fused feature vector of the character is obtained. Decoding is then performed based on this feature vector, thereby improving the accuracy of named entity recognition.
It improves the recognition accuracy of the named entity recognition model, enabling it to better identify the named entity categories of words represented by different tags, and enhances the model's generalization ability.
Smart Images

Figure CN116956918B_ABST
Abstract
Description
Technical Field
[0001] This application relates to artificial intelligence technology, and more particularly to a method, apparatus, electronic device, and computer-readable storage medium for identifying named entities. Background Technology
[0002] Named entity recognition (NER), as a fundamental natural language processing task, has wide applications in search, information feed recommendation, and advertising recommendation. Traditional NER methods involve training a sequence labeling model to identify entities in text. However, these models have limited generalization ability and are relatively weak in recognizing mid-to-long-tail entities or novel entities.
[0003] In many business scenarios, entity dictionaries for the target domain can be obtained at low cost. However, how to use the dictionary to enhance the recognition effect of the model is a considerable challenge. The conventional approach is to use the dictionary as a tool to construct a large amount of back-index training data or for post-processing of the model recognition results.
[0004] In implementing the embodiments of this application, the applicant discovered that the related technology ignores the differences in named entity recognition caused by different named entity categories of words in the dictionary, resulting in poor recognition accuracy. Summary of the Invention
[0005] This application provides a method, apparatus, electronic device, and computer-readable storage medium for identifying named entities, which can improve the accuracy of named entity identification.
[0006] The technical solution of this application embodiment is implemented as follows: This application provides a method for identifying named entities, including: Obtain the text to be processed, wherein the text to be processed includes multiple characters; Retrieve from the dictionary at least one word to which each character belongs, and retrieve from the dictionary at least one tag for each word, wherein the tag includes the named entity category of the word; Determine the hidden layer vector for each character and the embedding vector for the label of each word; The hidden layer vector of each character and the embedding vector of the label of each word are fused to obtain the fused feature vector of each character; The named entity category of each character is obtained by decoding based on the fused feature vector of each character.
[0007] This application provides a named entity identification device, comprising: The acquisition module is used to acquire the text to be processed, wherein the text to be processed includes multiple characters; A query module is configured to query at least one word to which each character belongs from a dictionary, and to query at least one tag for each word from the dictionary, wherein the tag includes the named entity category of the word; A determination module is used to determine the hidden layer vector of each character and the embedding vector of the label of each word; The processing module is used to fuse the hidden layer vector of each character and the embedding vector of the label of each word to obtain the fused feature vector of each character. The decoding module is used to perform decoding processing based on the fused feature vector of each character to obtain the named entity category of each character.
[0008] This application provides an electronic device, including: Memory is used to store executable instructions for a computer; The processor, when executing executable instructions stored in the memory, implements the named entity identification method provided in the embodiments of this application.
[0009] This application provides a computer-readable storage medium storing executable instructions for inducing a processor to execute and implement the named entity identification method provided in this application.
[0010] This application provides a computer program product, including computer-executable instructions or a computer program, characterized in that the computer-executable instructions or the computer program, when executed by a processor, implement the named entity identification method provided in this application.
[0011] The embodiments of this application have the following beneficial effects: Each word in the dictionary corresponds to at least one label. By fusing the hidden vector of each character and the embedding vector of the label of each word, we can focus on the importance of the named entity category represented by different labels to named entity recognition, thereby improving the recognition accuracy of the named entity recognition model of the named entity recognition method. Attached Figure Description
[0012] Figure 1 This is a schematic diagram of the architecture of the named entity recognition system provided in the embodiments of this application; Figure 2 This is a schematic diagram of the structure of the server 200 for the application named entity recognition method provided in this embodiment of the application; Figure 3A This is a structural diagram of the overall named entity recognition model of the named entity recognition method provided in the embodiments of this application; Figure 3BThis is a structural diagram of an encoder for the named entity recognition method provided in the embodiments of this application; Figure 3C This is another structural diagram of the encoder of the named entity recognition method provided in the embodiments of this application; Figure 4A , Figure 4B , Figure 4C , Figure 4D , Figure 4E This is a flowchart illustrating the named entity recognition method provided in an embodiment of this application; Figure 5 This is a schematic diagram illustrating the determination of the fusion feature vector of a character in an embodiment of this application; Figure 6 This is another schematic diagram illustrating the determination of the fusion feature vector of characters in an embodiment of this application. Detailed Implementation
[0013] To make the objectives, technical solutions, and advantages of this application clearer, the application will be further described in detail below with reference to the accompanying drawings. The described embodiments should not be regarded as limitations on this application. All other embodiments obtained by those skilled in the art without creative effort are within the scope of protection of this application.
[0014] In the following description, references are made to “some embodiments,” which describe a subset of all possible embodiments. However, it is understood that “some embodiments” may be the same subset or different subsets of all possible embodiments and may be combined with each other without conflict.
[0015] Unless otherwise defined, all technical and scientific terms used herein have the same meaning as commonly understood by one of ordinary skill in the art to which this application belongs. The terminology used herein is for the purpose of describing embodiments of this application only and is not intended to limit this application.
[0016] Before providing a further detailed description of the embodiments of this application, the nouns and terms involved in the embodiments of this application will be explained, and the nouns and terms involved in the embodiments of this application shall be interpreted as follows.
[0017] 1) Named Entity Recognition (NER) is one of the fundamental tasks of Natural Language Processing (NLP) and has a wide range of applications in many business scenarios. It refers to the identification of entities with specific meanings in text, such as names of people, places, organizations, novels, proper nouns, etc.
[0018] 2) Lexicon enhancement refers to the use of an additional lexicon to improve the performance of the NER model. When using lexicon enhancement, word segmentation is not required, and all possible words are matched in the lexicon. Each character (token) matches one or more words in the lexicon, and then the matched words are comprehensively utilized to assist model learning, which introduces lexicon information while avoiding the error propagation problem caused by word segmentation.
[0019] 3) The lexicon refers to a dictionary composed of a plurality of entity words and a plurality of labels, and each entity word corresponds to at least one label.
[0020] Table 1 is a schematic diagram of querying at least one word to which a character belongs from the lexicon. As shown in Table 1, taking the character "yan" (meaning along / coastal) as an example, two words to which the character "yan" belongs are queried from the lexicon, which are "coastal open city" and "coastal" respectively.
[0021] Table 1
[0022] 4) The Lexicon Enhanced BERT (LEBERT) structure refers to using a lexicon to assist model learning.
[0023] The technical solutions in the related art have achieved certain indicator improvements on public NER test sets based on LEBERT, but LEBERT has some problems in the implementation of actual business scenarios, which are mainly the following three points: (1) It relies on externally pre-trained word vectors, and experiments have proved that loading pre-trained word vectors is superior to randomly initializing word vectors. (2) When new entity words are added to the lexicon, the entire model needs to be retrained, which is not applicable to business scenarios where the lexicon changes frequently. (3) For NER tasks with multiple categories, the lexicon does not explicitly indicate the category to which each word belongs. The above three defects of LEBERT lead to poor accuracy of named entity recognition.
[0024] To solve the above problems, embodiments of the present application provide a named entity recognition method, apparatus, electronic device, and computer-readable storage medium. The method includes acquiring a to-be-processed text, where the to-be-processed text includes a plurality of characters; querying at least one word to which each character belongs from a lexicon, and querying at least one label of each word from the lexicon, where the label includes a named entity category of the word; determining a hidden layer vector of each character, and determining an embedding vector of the label of each word; performing fusion processing on the hidden layer vector of each character and the embedding vector of the label of each said word to obtain a fused feature vector of each character; and performing decoding processing based on the fused feature vector of each character to obtain the named entity category of each character.
[0025] In this embodiment, each word in the dictionary corresponds to at least one label. By fusing the hidden vector of each character and the embedding vector of each word's label, the importance of the named entity category represented by different labels to named entity recognition can be considered, thereby improving the recognition accuracy of the named entity recognition model of the named entity recognition method.
[0026] The following describes exemplary applications of the electronic device provided in the embodiments of this application. The electronic device provided in the embodiments of this application can be implemented as a server. The following will describe exemplary applications when the device is implemented as a server.
[0027] The server can be a standalone physical server, a server cluster or a 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 communication, middleware services, domain name services, security services, and big data and artificial intelligence platforms. The server can be connected directly or indirectly through wired or wireless communication methods, and the embodiments of this application are not limited herein.
[0028] Artificial intelligence cloud services are generally also known as AIaaS (AI as a Service). This is currently a mainstream service model for artificial intelligence platforms. Specifically, AIaaS platforms break down several common AI services and provide them as independent or packaged services in the cloud. This service model is similar to opening an AI-themed marketplace: all developers can access and use one or more AI services provided by the platform through API interfaces. Some experienced developers can also use the AI framework and AI infrastructure provided by the platform to deploy and maintain their own dedicated cloud AI services. In the named entity recognition method provided in this application embodiment, the named entity recognition system can be deployed and maintained through the AI framework and AI infrastructure provided by the artificial intelligence cloud service.
[0029] See Figure 1 , Figure 1 This is a schematic diagram of the architecture of the named entity recognition system provided in the embodiments of this application. The named entity recognition system can be used to support the recognition of named entities of various information, such as the application scenario of recognizing novel titles, place names, etc. in text.
[0030] During user interaction with the terminal, terminal 400 sends a named entity recognition request to server 200. This request requests the return of named entity categories in the text. In response to the named entity recognition request sent by terminal 400, server 200 queries the dictionary to find at least one word to which each character belongs and at least one tag for each word, wherein the tag includes the named entity category of the word; determines the hidden vector of each character and the embedding vector of the tag for each word; fuses the hidden vector of each character and the embedding vector of the tag for each word to obtain a fused feature vector for each character; decodes the fused feature vector of each character to obtain the named entity category of each character, and returns the named entity category of each character to terminal 400 for presentation.
[0031] See Figure 2 , Figure 2 This is a schematic diagram of the structure of the server 200 for the application named entity recognition method provided in this embodiment of the application. Figure 2 The server 200 shown includes at least one processor 210, memory 250, and at least one network interface 220. The various components of server 200 are coupled together via a bus system 240. It is understood that the bus system 240 is used to implement communication between these components. In addition to a data bus, the bus system 240 also includes a power bus, a control bus, and a status signal bus. However, for clarity, ... Figure 2 The general labeled all buses as Bus System 240.
[0032] Processor 210 can be an integrated circuit chip with signal processing capabilities, such as a general-purpose processor, a digital signal processor (DSP), or other programmable logic devices, discrete gate or transistor logic devices, discrete hardware components, etc. Among them, the general-purpose processor can be a microprocessor or any conventional processor, etc.
[0033] The memory 250 may be removable, non-removable, or a combination thereof. Exemplary hardware devices include solid-state storage, hard disk drives, optical disk drives, etc. The memory 250 may optionally include one or more storage devices physically located away from the processor 210.
[0034] The memory 250 may include volatile memory or non-volatile memory, or both. The non-volatile memory may be read-only memory (ROM), and the volatile memory may be random access memory (RAM). The memory 250 described in this application embodiment is intended to include any suitable type of memory.
[0035] In some embodiments, memory 250 is capable of storing data to support various operations, examples of which include programs, modules, and data structures or subsets or supersets thereof, as illustrated below.
[0036] Operating system 251 includes system programs for handling various basic system services and performing hardware-related tasks, such as the framework layer, core library layer, driver layer, etc., for implementing various basic business functions and handling hardware-based tasks; The network communication module 252 is used to reach other computing devices via one or more (wired or wireless) network interfaces 220, such as Bluetooth, WiFi, and Universal Serial Bus (USB).
[0037] In some embodiments, the named entity recognition device provided in this application can be implemented in software. Figure 2 A named entity identification device 255 stored in memory 250 is shown, which includes multiple modules. The modules can be software in the form of programs and plug-ins, including the following software modules: acquisition module 2551, query module 2552, determination module 2553, processing module 2554, and decoding module 2555. These modules are logical and can therefore be arbitrarily combined or further split according to the functions they implement. The functions of each module will be described below.
[0038] The naming entity recognition method provided in this application will be described in conjunction with exemplary applications and implementations of the naming entity recognition system provided in the embodiments of this application. First, the model used in the naming entity recognition method provided in the embodiments of this application will be described.
[0039] The named entity recognition method provided in this application involves a named entity recognition model, including an encoder and a decoder.
[0040] See Figure 3A , Figure 3AThis is a structural diagram of the overall named entity recognition model of the named entity recognition method provided in this application embodiment. The overall model includes an encoder and a decoder. First, multiple characters are input into the encoder. The encoder queries the dictionary to find at least one word to which each character belongs and at least one tag for each word. The tag includes the named entity category of the word. Then, each character is embedded to obtain an embedding vector. The embedding vector of each character is encoded at least once to obtain a hidden vector for each character. The tag of each word is embedded to obtain an embedding vector for the tag of each word. The hidden vector of each character and the embedding vector of the tag of each word are fused to obtain a fused feature vector for each character. Finally, the decoder performs decoding based on the fused feature vector of each character to obtain the named entity category of each character.
[0041] See Figure 3B , Figure 3B This is a structural diagram of the encoder of the named entity recognition method provided in the embodiments of this application. The encoder includes a token embedding layer, a label embedding layer, L linear transformation layers, and a lexicon adapter. The lexicon adapter is set after the Kth linear transformation layer, where K is an integer greater than or equal to 1.
[0042] First, each character is embedded using a token embedding layer to obtain its embedding vector. Then, each character's embedding vector is encoded at least once using K cascaded linear transformation layers to obtain its hidden vector. Here, K is an integer greater than or equal to 1. Next, a lexicon adapter is used to query the dictionary to find at least one word to which each character belongs and at least one tag for each word. The tag includes the word's named entity category. Finally, a label embedding layer is used to embed the tag for each word to obtain its embedding vector.
[0043] Second, the hidden vector of each character and the embedding vector of each word's label are fused using a Lexicon Adapter to obtain a fused feature vector for each character.
[0044] As an example, the character and at least one label are fused together using two attention mechanisms.
[0045] Third, by using LK cascaded encoders, the fusion feature vector of the character is encoded at least once (LK times) to obtain the hidden layer vector of the fusion feature vector. The hidden layer vector of the fusion feature vector is used as the new fusion feature vector of the character to replace the fusion feature vector of the character obtained by the fusion process.
[0046] Fourth, using the softmax function, the fused feature vector corresponding to each character is mapped to the probability distribution of multiple labels. The named entity category represented by the label with the highest probability is taken as the named entity category of the character. This is a greedy algorithm. Alternatively, using a Conditional Random Field (CRF), the fused feature vector corresponding to each character is mapped to multiple label paths. Each label path includes a label corresponding to multiple characters and the corresponding probability. The score of the multiple label paths is determined based on the probability, which is the sum of the probabilities of the labels. The named entity category represented by the label of each character in the label path with the highest score is taken as the named entity category of the character.
[0047] See Figure 3C , Figure 3C This is another structural diagram of the encoder of the named entity recognition method provided in the embodiments of this application. The encoder includes a token embedding layer, a label embedding layer, L linear transformation layers, and a lexicon adapter. The lexicon adapter is set after the Kth linear transformation layer, where K is an integer greater than or equal to 1.
[0048] First, each character is embedded using a token embedding layer to obtain its embedding vector. Then, each character's embedding vector is encoded at least once using K cascaded linear transformation layers to obtain its hidden vector. Next, a lexicon adapter is used to query the dictionary for at least one word to which each character belongs and for at least one label for each word. The label includes the word's named entity category. Finally, a label embedding layer is used to embed the label of each word to obtain its embedding vector.
[0049] Second, the hidden vector of each character and the embedding vector of each word's label are fused using a Lexicon Adapter to obtain a fused feature vector for each character.
[0050] As an example, a unified attention mechanism is used to fuse characters and at least one label.
[0051] Third, by using LK cascaded encoders, the fusion feature vector of the character is encoded at least once (LK times) to obtain the hidden layer vector of the fusion feature vector. The hidden layer vector of the fusion feature vector is used as the new fusion feature vector of the character to replace the fusion feature vector of the character obtained by the fusion process.
[0052] Fourth, using the softmax function, the fused feature vector corresponding to each character is mapped to the probability distribution of multiple labels. The named entity category represented by the label with the highest probability is taken as the named entity category of the character. This is a greedy algorithm. Alternatively, using CRF, the fused feature vector corresponding to each character is mapped to multiple label paths. Each label path includes a label corresponding to multiple characters and the corresponding probability. The score of the multiple label paths is determined based on the probability, which is the sum of the probabilities of the labels. The named entity category represented by the label of each character in the label path with the highest score is taken as the named entity category of the character.
[0053] See Figure 4A , Figure 4A This is a flowchart illustrating the named entity recognition method provided in the embodiments of this application, which will be combined with... Figure 4A Steps 101-105 shown are explained below. Figure 4A The server is the entity that executes the steps.
[0054] In step 101, the text to be processed is obtained, wherein the text to be processed includes multiple characters.
[0055] As an example, characters can be represented by tokens.
[0056] In step 102, at least one word to which each character belongs is retrieved from the dictionary, and at least one tag for each word is retrieved from the dictionary, wherein the tag includes the named entity category of the word.
[0057] As an example, a label can be represented by the word "label".
[0058] As an example, the named entity category of a word can include: person's name, place name, organization name, time expression, date expression, and so on.
[0059] As an example, the label also includes the type of the character's position within its word.
[0060] For example, prefix information is added to the label returned when querying the dictionary, that is, the annotation of the token, which is used to accurately identify the boundary of a segment or span in the text sequence, and to ensure correct span classification, so that the model can better identify the boundary. Specifically, the format of token annotation-label can be adopted, wherein the token annotation adopts the BIOSE schema or the BMES schema, etc.
[0061] Wherein, the five-position sequence annotation method of BIOSE adopts five labels, which are B-begin, I-inside, O-outside, E-end, and S-single respectively. B represents the start of an entity, I represents the inside of an entity, O represents a non-entity, E represents the end of an entity, and S indicates that the word itself is an entity.
[0062] Wherein, the four-position sequence annotation method of BMES adopts four labels, which are B-begin, M-inside, E-end, and S-single respectively. B represents the start of an entity, I represents the middle of an entity, E represents the end of an entity, and S represents a separate entity.
[0063] Table 2 is a schematic diagram of at least one word to which a character queried from the dictionary belongs and at least one label of each word. As shown in Table 2, taking the character "hei" (black) as an example, two words that the character "hei" belongs to are queried from the dictionary, which are "heishan tou" (Heishantou) and "heishan" (Heishan) respectively. The label of the word "heishan tou" is represented by "LOC", which indicates the named entity category of the word, such as a county name, or is represented by "B-LOC", wherein "B" represents prefix information, which is used to indicate the start of an entity. The label of the word "heishan" can be represented by "GPE, PER, LOC", which respectively indicate the named entity categories of the word, such as person name, place name, and county name. Alternatively, the label of the word "heishan" can also be represented by "B-GPE, B-PER, B-LOC", wherein "B" represents prefix information, which is used to indicate the start of an entity.
[0064] Table 2
[0065] In some embodiments, the dictionary includes a plurality of words, and each word is associated with at least one label; in step 102, querying at least one word to which each of the characters belongs from the dictionary and querying at least one label of each of the words from the dictionary can be implemented through the following technical solution: performing the following processing for each of the characters: taking the character as an index, querying at least one word including the character from the dictionary, and performing the following processing for each queried word: querying at least one label associated with the word from the dictionary.
[0066] In step 103, the hidden vector of each character is determined, and the embedding vector of the label of each word is determined.
[0067] See Figure 4B , Figure 4B This is a flowchart illustrating the named entity recognition method provided in this application embodiment. In step 103, determining the hidden vector of each character and the embedding vector of the tag of each word can be achieved through steps 1031 to 1033.
[0068] In step 1031, each character is embedded to obtain an embedding vector for each character.
[0069] In step 1032, the embedding vector of each character is encoded at least once to obtain the hidden layer vector of each character.
[0070] In step 1033, the labels of each word are embedded to obtain the embedding vector of each word's label.
[0071] The encoder of the named entity recognition method provided in this application embodiment may include a token embedding layer, a label embedding layer, L linear transformation layers, and a lexicon adapter. The lexicon adapter is set after the Kth linear transformation layer, where K is an integer greater than or equal to 1.
[0072] As an example, the Lexicon Adapter can be combined with BERT to obtain the Lexicon-Enhanced BERT (LEBERT) model structure. The Lexicon Adapter can be inserted after any linear transformation layer for word feature fusion, and it works best when inserted after the first linear transformation layer.
[0073] As an example, each character can be embedded using a token embedding layer to obtain its embedding vector.
[0074] As an example, the hidden vector of each character can be obtained by encoding the embedding vector of each character at least once through K cascaded linear transformation layers.
[0075] As an example, a Lexicon Adapter may be used to query at least one word to which each character belongs from a lexicon, and query at least one label for each word from the lexicon, where the labels include the named entity category of the word, and a Label Embedding layer is used to perform embedding processing on the label of each word to obtain the embedding vector of the label of each word.
[0076] In step 104, the hidden layer vector of each character and the embedding vector of the label of each word are fused to obtain a fused feature vector of each character.
[0077] As an example, the fusion processing may be implemented based on an attention mechanism, where the attention mechanism may be implemented by an attention model.
[0078] In step 105, decoding processing is performed based on the fused feature vector of each character to obtain the named entity category of each character.
[0079] Refer to Figure 4C , Figure 4C which is a schematic flowchart of a named entity recognition method provided in the embodiments of the present application. The step of fusing the hidden layer vector of each character and the embedding vector of the label of each word to obtain the fused feature vector of each character in step 104 may be implemented through step 1041, and step 1041 includes step 10411 and step 10412.
[0080] In step 1041, the following processing is performed for each character: In step 10411, the attention weights respectively corresponding to the character and at least one label of each word are determined; In step 10412, based on the attention weights respectively corresponding to the character and at least one label of the word, weighted summation processing is performed on the hidden layer vector of the character and the embedding vector of each label, to obtain the fused feature vector of the character.
[0081] As an example, at least one label of the word matched for a token from the lexicon may not be distinguished, and unified attention processing is performed once, that is, the labels are flattened and treated uniformly.
[0082] For example, taking the character "hei" as an example, two words that the character "hei" belongs to are queried from the lexicon, which are "heishan tou" and "heishan" respectively. The label of the word "heishan tou" is represented by "LOC", which indicates the named entity category of the word, such as a county name. The labels of the word "heishan" are represented by "GPE, PER, LOC", which respectively indicate the named entity categories of the word, such as person name, place name, and county name.
[0083] Perform a unified single attention processing on the character "hei" and these four tags, which may specifically include: First, perform embedding processing on the character "hei" to obtain the embedding vector of the character "hei", and perform at least one encoding processing on the embedding vector of the character "hei" to obtain the hidden layer vector corresponding to the character "hei".
[0084] Second, perform embedding processing on the tags "GPE, PER, LOC" of the word "heishan" respectively to obtain the embedding vector of each tag, and perform embedding processing on the tag "LOC" of the word "heishantou" to obtain the embedding vector of this tag.
[0085] Third, determine the attention weights respectively corresponding to the character "hei", the tag "LOC" of the word "heishantou", and the three tags of the word "heishan".
[0086] Map the hidden layer vector E(hei) of the character "hei" to the query vector Q(hei), as shown in the following formula: Q_tans=nn.linear(input_dim,dim_q) Q(hei) = Q_tans(E(hei)) Wherein, nn.linear() is a linear transformation function, input_dim represents the input hidden layer vector of the character "hei", and dim_q represents the declared variable q, that is, the output query vector Q(hei).
[0087] Map the embedding vector of the tag "LOC" of the word "heishantou" to which the character "hei" belongs to the key vector K(LOC)_1 and the value vector V(LOC)_1 respectively, map the embedding vector of the tag "GPE" of the word "heishan" to which the character "hei" belongs to the key vector K(GPE)_2 and the value vector V(GPE)_2 respectively, map the embedding vector of the tag "PER" of the word "heishan" to which the character "hei" belongs to the key vector K(PER)_3 and the value vector V(PER)_3 respectively, and map the embedding vector of the tag "LOC" of the word "heishan" to which the character "hei" belongs to the key vector K(LOC)_4 and the value vector V(LOC)_4 respectively, as shown in the following formula: K_tans=nn.linear(input_dim,dim_k) V_tans=nn.linear(input_dim,dim_v) K(LOC)_1 = K_tans(E(LOC)) V(LOC)_1 = V_tans(E(LOC)) K(GPE)_2 = K_tans(E(GPE)) V(GPE)_2 = V_trans(E(GPE)) K(PER)_3 = K_trans(E(PER)) V(PER)_3 = V_trans(E(PER)) K(LOC)_4 = K_trans(E(LOC)) V(LOC)_4 = V_trans(E(LOC)) wherein nn.linear() is a linear transformation function, input_dim represents the embedding vector of the label of the input word, dim k represents the declared variable k, that is, the output key vector, and dim v represents the declared variable v, that is, the output value vector.
[0088] Determine the attention weight corresponding to the label of the character and the word, as shown in the following formula:
[0089] wherein, represents the attention weight corresponding to the label of the character and the word, Q represents the query vector corresponding to the character "hei", K represents the key vector corresponding to the label of the word, V represents the value vector corresponding to the label of the word, and dk represents the dimension of the hidden layer vector of the character "hei".
[0090] That is, according to the above formula, the query vector Q(hei), the key vector K(LOC)_1 and the value vector V(LOC)_1 obtained from the hidden layer vector of the character "hei" are used to obtain the attention weight w1 corresponding to the label "LOC" of the character "hei" and the word "heishantou", the query vector Q(hei), the key vector K(GPE)_2 and the value vector V(GPE)_2 obtained from the hidden layer vector of the character "hei" are used to obtain the attention weight w2 corresponding to the label "GPE" of the character "hei" and the word "heishan", the query vector Q(hei), the key vector K(PER)_3 and the value vector V(PER)_3 obtained from the hidden layer vector of the character "hei" are used to obtain the attention weight w3 corresponding to the label "PER" of the character "hei" and the word "heishan", and the query vector Q(hei), the key vector K(LOC)_4 and the value vector V(LOC)_4 obtained from the hidden layer vector of the character "hei" are used to obtain the attention weight w4 corresponding to the label "LOC" of the character "hei" and the word "heishan".
[0091] Fourth, based on the determined attention weights, a weighted sum process is performed on the hidden layer vector of the character "hei" and the embedding vector of each label to obtain a fused feature vector of the character.
[0092] As an example, it may refer to performing weighted summation processing on the value vector obtained from the embedding vector of each label using the attention weight determined by the query vector obtained based on the hidden layer vector of the character "Hei", and the key vector and value vector obtained from the embedding vector of the label, and concatenating the weighted summation result with the hidden layer vector of the character "Hei" to obtain a fused feature vector of the character.
[0093] For example, the attention weight corresponding to the character "Hei" and the label "LOC" of the word "Heishantou" is w1, the attention weight corresponding to the character "Hei" and the label "GPE" of the word "Heishan" is w2, the attention weight corresponding to the character "Hei" and the label "PER" of the word "Heishan" is w3, the attention weight corresponding to the character "Hei" and the label "LOC" of the word "Heishan" is w4, the value vector corresponding to the label "LOC" of the word "Heishantou" is V(LOC)_1, the value vector corresponding to the label "GPE" of the word "Heishan" is V(GPE)_2, the value vector corresponding to the label "PER" of the word "Heishan" is V(PER)_3, the value vector corresponding to the label "LOC" of the word "Heishan" is V(LOC)_4, and the hidden layer vector of the character "Hei" is E(Hei).
[0094] Then, the weighted summation processing is performed on the hidden layer vector of the character "Hei" and the embedding vector of each label to obtain the fused feature vector of the character, and the fused feature vector is expressed as {[w1×V(LOC)_1+w2×V(GPE)_2+w3×V(PER)_3+w4×V(LOC)_4], E(Hei)}.
[0095] Refer to Figure 4D , Figure 4D which is a schematic flowchart of a named entity recognition method provided in the embodiments of the present application, and determining the attention weight respectively corresponding to the character and at least one label of each character in step 10411 may be implemented through step 104111 and step 104112.
[0096] In step 104111, the following processing is performed for each word: determining the label-level attention weight respectively corresponding to the character and at least one label of the word, wherein the label-level attention weight characterizes the importance degree of the category of the named entity represented by the label; In step 104112, the following processing is performed for each word: determining the word-level attention weight respectively corresponding to the character and the word, wherein the word-level attention weight characterizes the importance degree of the word.
[0097] In some embodiments, determining the label-level attention weight respectively corresponding to the character and at least one label of the word in step 104111 may be implemented through the following technical solutions: Map the hidden layer vector of the character to a query vector, and map the embedding vector of at least one label of the word to a key vector and a value vector respectively; Perform a transposition operation on the key vector to obtain a transposed key vector; Perform a dot product operation on the query vector and the transposed key vector to obtain an operation result; Map the operation result and the value vector to a probability distribution based on an activation function, where the probability distribution includes a plurality of probability values; Take the plurality of probability values as the label-level attention weights respectively corresponding to the at least one label of the character and the word.
[0098] For example, taking the character "Hei" as an example, two words that the character "Hei" belongs to are queried from the dictionary, which are "Heishantou" and "Heishan" respectively. The label of the word "Heishantou" is represented by "LOC", and the labels of the word "Heishan" are represented by "GPE, PER, LOC", which respectively represent the named entity categories of the word, such as person name, place name, and county name.
[0099] First, perform embedding processing on the character "Hei" to obtain the embedding vector of the character "Hei", and perform at least one encoding processing on the embedding vector of the character "Hei" to obtain the hidden layer vector corresponding to the character "Hei".
[0100] Second, perform embedding processing on the labels "GPE, PER, LOC" of the word "Heishan" respectively to obtain the embedding vector of each label, and perform embedding processing on the label "LOC" of the word "Heishantou" to obtain the embedding vector of this label.
[0101] Third, determine the label-level attention weights respectively corresponding to the character "Hei", the label "LOC" of the word "Heishantou", and the three labels of the word "Heishan".
[0102] Map the hidden layer vector E(Hei) of the character "Hei" to the query vector Q(Hei), as shown in the following formula: Q_tans=nn.linear(input_dim,dim_q) Q(Hei) = Q_tans(E(Hei)) Wherein, nn.linear() is a linear transformation function, input_dim represents the input hidden layer vector of the character "Hei", and dim_q represents the declared variable q, that is, the output query vector Q(Hei).
[0103] Map the embedding vector of the label "LOC" of the word "Heishantou" to which the character "Hei" belongs to the key vector K(LOC)_1 and the value vector V(LOC)_1 respectively, map the embedding vector of the label "GPE" of the word "Heishan" to which the character "Hei" belongs to the key vector K(GPE)_2 and the value vector V(GPE)_2 respectively, map the embedding vector of the label "PER" of the word "Heishan" to which the character "Hei" belongs to the key vector K(PER)_3 and the value vector V(PER)_3 respectively, and map the embedding vector of the label "LOC" of the word "Heishan" to which the character "Hei" belongs to the key vector K(LOC)_4 and the value vector V(LOC)_4 respectively, as shown in the following formula: K_tans=nn.linear(input_dim,dim_k) V_tans=nn.linear(input_dim,dim_v) K(LOC)_1 = K_tans(E(LOC)) V(LOC)_1 = V_tans(E(LOC)) K(GPE)_2= K_tans(E(GPE)) V(GPE)_2 = V_tans(E(GPE)) K(PER)_3= K_tans(E(PER)) V(PER)_3 = V_tans(E(PER)) K(LOC)_4 = K_tans(E(LOC)) V(LOC)_4 = V_tans(E(LOC)) Herein, nn.linear() is a linear transformation function, input_dim represents the input embedding vector of the label of the word, dim_k represents the declared variable k, that is, the output key vector, and dim_v represents the declared variable v, that is, the output value vector.
[0104] Determine the label-level attention weight corresponding to the label of the character and the word, as shown in the following formula:
[0105] Herein, represents the label-level attention weight corresponding to the label of the character and the word, Q represents the query vector corresponding to the character "Hei", K represents the key vector corresponding to the label of the word, V represents the value vector corresponding to the label of the word, and dk represents the dimension of the hidden layer vector of the character "Hei".
[0106] That is, according to the above formula, the query vector Q(black), key vector K(LOC)_1 and value vector V(LOC)_1 obtained using the hidden layer vector of the character "black" are used to obtain the label-level attention weight w1 corresponding to the label "LOC" of the character "black" and the word "Heishantou"; the query vector Q(black), key vector K(GPE)_2 and value vector V(GPE)_2 obtained using the hidden layer vector of the character "black" are used to obtain the label-level attention weight w2 corresponding to the label "GPE" of the character "black" and the word "Heishan"; the query vector Q(black), key vector K(PER)_3 and value vector V(PER)_3 obtained using the hidden layer vector of the character "black" are used to obtain the label-level attention weight w3 corresponding to the label "PER" of the character "black" and the word "Heishan"; the query vector Q(black), key vector K(LOC)_4 and value vector V(LOC)_4 obtained using the hidden layer vector of the character "black" are used to obtain the label-level attention weight w4 corresponding to the label "LOC" of the character "black" and the word "Heishan".
[0107] In some embodiments, determining the word-level attention weights respectively corresponding to the character and the word in step 104112 can be implemented by the following technical solution: Map the hidden layer vector of the character to a query vector; Perform embedding processing on each word to obtain an embedding vector corresponding to each word, and map the embedding vector of each word to a key vector and a value vector respectively; Perform transposition operation processing on the key vector to obtain a transposed key vector; Perform dot product operation on the query vector and the transposed key vector to obtain an operation result; Map the operation result and the value vector to a probability distribution based on an activation function, wherein the probability distribution includes a plurality of probability values; Take the plurality of probability values as the word-level attention weights respectively corresponding to the character and the word.
[0108] For example, taking the character "black" as an example, two words that the character "black" belongs to are queried from the dictionary, which are "Heishantou" and "Heishan" respectively. The label of the word "Heishantou" is represented by "LOC", which represents the named entity category of the word, such as a county name. The labels of the word "Heishan" are represented by "GPE, PER, LOC", which respectively represent the named entity categories of the word, such as person name, place name, and county name.
[0109] First, embedding processing is performed on the character "black" to obtain the embedding vector of the character "black", and at least one encoding processing is performed on the embedding vector of the character "black" to obtain the hidden layer vector corresponding to the character "black".
[0110] Second, embedding processing is performed on the words "Heishan" and "Heishantou" respectively to obtain the embedding vector of each word.
[0111] Third, the word attention weights respectively corresponding to the character "Hei" and the words "Heishantou" and "Heishan" are determined.
[0112] The hidden layer vector E(Hei) of the character "Hei" is mapped to a query vector Q(Hei), as shown in the following formula: Q_tans=nn.linear(input_dim,dim_q) Q(Hei) = Q_tans(E(Hei)) Wherein, nn.linear() is a linear transformation function, input_dim represents the input hidden layer vector of the character "Hei", and dim_q represents the declared variable q, that is, the output query vector Q(Hei).
[0113] The embedding vector of the word "Heishantou" to which the character "Hei" belongs is mapped to a key vector K_1 and a value vector V_1 respectively, and the embedding vector of the word "Heishan" to which the character "Hei" belongs is mapped to a key vector K_2 and a value vector V_2 respectively, as shown in the following formula: K_tans=nn.linear(input_dim,dim_k) V_tans=nn.linear(input_dim,dim_v) K_1 = K_tans(E(Heishantou)) V_1 = V_tans(E(Heishantou)) K_2 = K_tans(E(Heishan)) V_2 = V_tans(E(Heishan)) Wherein, nn.linear() is a linear transformation function, input_dim represents the input embedding vector of the word, dim_k represents the declared variable k, that is, the output key vector, and dim_v represents the declared variable v, that is, the output value vector.
[0114] The word-level attention weights corresponding to the character and the word are determined, as shown in the following formula:
[0115] Wherein, represents the word-level attention weight corresponding to the character and the word, Q represents the query vector corresponding to the character "Hei", K represents the key vector corresponding to the word, V represents the value vector corresponding to the word, and dk represents the dimension of the hidden layer vector of the character "Hei".
[0116] That is, according to the above formula, the query vector Q(Black), key vector K_1 and value vector V_1 obtained using the hidden layer vector of the character "Black" are used to obtain the word-level attention weight w5 corresponding to the character "Black" and the word "Heishantou", and the query vector Q(Black), key vector K_2 and value vector V_2 obtained using the hidden layer vector of the character "Black" are used to obtain the word-level attention weight w6 corresponding to the character "Black" and the word "Heishan".
[0117] refer to Figure 4E , Figure 4E which is a schematic flowchart of the named entity recognition method provided in the embodiments of the present application. In step 10412, performing weighted summation processing on the hidden layer vector of the character and the embedding vector of each label based on the attention weights respectively corresponding to the character and at least one label to obtain the fused feature vector of the character can be implemented through step 104121 and step 104122.
[0118] In step 104121, the following processing is performed for each word: based on the label-level attention weights respectively corresponding to at least one label of the character and the word, weighted summation processing is performed on the hidden layer vector of the character and the embedding vector of the label of each word, so as to obtain the label-level fused feature vector between the character and the word; In step 104122, the following processing is performed for each word: based on the word-level attention weights respectively corresponding to the character and the word, weighted summation processing is performed on the hidden layer vector of the character and the label-level fused feature vector between each word that includes the character, so as to obtain the word-level fused feature vector between the character and each word that includes the character.
[0119] For example, taking the character "Black" as an example, two words to which "Black" belongs are queried from the dictionary, which are "Heishantou" and "Heishan" respectively. The label of the word "Heishantou" is represented by "LOC", which indicates the named entity category of the word, such as a county name. The labels of the word "Heishan" are represented by "GPE, PER, LOC", which respectively indicate the named entity categories of the word, such as person name, place name, and county name.
[0120] Two attention processing operations are performed on the character "Black" and these four labels, which may specifically include: The first attention processing process: First, the label-level attention weights respectively corresponding to at least one label of the character and the word are determined, and the specific implementation process has been described above, which will not be repeated here.
[0121] Then, based on the label-level attention weights respectively corresponding to at least one label of the character and the word, weighted summation processing is performed on the hidden layer vector of the character and the embedding vector of the label of each word, so as to obtain the label-level fused feature vector between the character and the word.
[0122] As an example, it may refer to performing weighted summation processing on the value vector obtained from the embedding vector of the label of each word according to the label-level attention weight determined by the query vector obtained based on the hidden layer vector of the character "hei", and the key vector and value vector obtained from the embedding vector of the label, and concatenating the weighted summation result with the hidden layer vector of the character to obtain the label-level fused feature vector between the character and the word.
[0123] For example, the query vector Q(hei) obtained by using the hidden layer vector E(hei) of the character "hei", the key vector K(LOC)_1 and the value vector V(LOC)_1 are used to obtain the label-level attention weight w1 corresponding to the label "LOC" of the character "hei" and the word "heishantou"; the query vector Q(hei) obtained from the hidden layer vector of the character "hei", the key vector K(GPE)_2 and the value vector V(GPE)_2 are used to obtain the label-level attention weight w2 corresponding to the label "GPE" of the character "hei" and the word "heishan"; the query vector Q(hei) obtained from the hidden layer vector of the character "hei", the key vector K(PER)_3 and the value vector V(PER)_3 are used to obtain the label-level attention weight w3 corresponding to the label "PER" of the character "hei" and the word "heishan"; the query vector Q(hei) obtained from the hidden layer vector of the character "hei", the key vector K(LOC)_4 and the value vector V(LOC)_4 are used to obtain the label-level attention weight w4 corresponding to the label "LOC" of the character "hei" and the word "heishan". The value vector corresponding to the label "LOC" of the word "heishantou" is V(LOC)_1, the value vector corresponding to the label "GPE" of the word "heishan" is V(GPE)_2, the value vector corresponding to the label "PER" of the word "heishan" is V(PER)_3, the value vector corresponding to the label "LOC" of the word "heishan" is V(LOC)_4, and the hidden layer vector of the character "hei" is E(hei).
[0124] Then the label-level fused feature vector between the character "hei" and the word "heishantou" is expressed as {w1×V(LOC)_1, E(hei)}, and the label-level fused feature vector between the character "hei" and the word "heishan" is expressed as {[w2×V(GPE)_2 + w3×V(PER)_3 + w4×V(LOC)_4], E(hei)}.
[0125] The second attention processing procedure: First, the word-level attention weights respectively corresponding to the character and the word are determined, and the specific implementation process has been described above, which will not be repeated here.
[0126] Then, based on the word-level attention weights corresponding to the characters and words respectively, a weighted summation process is performed on the hidden layer vectors of the characters and the label-level fused feature vectors between each word that includes the character, so as to obtain the word-level fused feature vectors between the character and each word that includes the character.
[0127] As an example, it may refer to performing a weighted summation process on the label-level fused feature vectors between each word of the character by using the word-level attention weights determined by the query vector obtained based on the hidden layer vector of the character "Hei", and the key vector and value vector obtained from the embedding vector of the word, and concatenating the weighted summation result with the hidden layer vector of the character, so as to obtain the word-level fused feature vector between the character and each word that includes the character.
[0128] For example, the word-level attention weight w5 corresponding to the character "Hei" and the word "Heishantou" is obtained by using the query vector Q(Hei) obtained from the hidden layer vector of the character "Hei", the key vector K_1 and the value vector V_1, the word-level attention weight w6 corresponding to the character "Hei" and the word "Heishan" is obtained by using the query vector Q(Hei) obtained from the hidden layer vector of the character "Hei", the key vector K_2 and the value vector V_2, and the hidden layer vector of the character "Hei" is E(Hei).
[0129] Then the word-level fused feature vector is expressed as { [w5×[w1×V(LOC)_1]+w6×[w2×V(GPE)_2+w3×V(PER)_3+w4×V(LOC)_4]], E(Hei)}.
[0130] In some embodiments, after the label-level fused feature vector between the character and each word including the character is obtained in step 104121, the following steps may also be performed: performing residual processing on the label-level fused feature vector to obtain a residual feature vector; performing normalization processing on the residual feature vector to obtain a normalized feature vector; and taking the normalized feature vector as a new label-level fused feature vector to replace the label-level fused feature vector obtained through the weighted summation process.
[0131] In some embodiments, after the word-level fused feature vector between the character and each word including the character is obtained in step 104122, the following steps may also be performed: performing residual processing on the word-level fused feature vector to obtain a residual feature vector; performing normalization processing on the residual feature vector to obtain a normalized feature vector; and taking the normalized feature vector as a new word-level fused feature vector to replace the word-level fused feature vector obtained through the weighted summation process.
[0132] In some embodiments, the decoding process based on the fused feature vector corresponding to each character in step 105 to obtain the named entity category of each character can be achieved through the following technical solutions: The fused feature vector corresponding to each character is mapped to a probability distribution of multiple labels, and the named entity category represented by the label with the highest probability is taken as the named entity category of the character, or The fused feature vector corresponding to each character is mapped to multiple label paths. Each label path includes a label corresponding to multiple characters and a corresponding probability. The scores of multiple label paths are determined based on the probabilities. The named entity category represented by the label of each character in the label path with the highest score is taken as the named entity category of the character.
[0133] As an example, the softmax function can be used to map the fused feature vector corresponding to each character to the probability distribution of multiple labels, and the named entity category represented by the label with the highest probability can be used as the named entity category of the character, which is a greedy algorithm.
[0134] Alternatively, using CRF, the fused feature vector corresponding to each character is mapped to multiple label paths. Each label path includes a label corresponding to multiple characters and a corresponding probability. The score of the multiple label paths is determined based on the probability, which is the sum of the probabilities of the labels. The named entity category represented by the label of each character in the label path with the highest score is taken as the named entity category of the character.
[0135] In some embodiments, before performing decoding processing based on the fused feature vector of each character in step 105, the following steps may also be performed: Perform the following processing for each character: The character fusion feature vector is encoded at least once to obtain the hidden layer vector of the fusion feature vector; The hidden layer vector of the fused feature vector is used as the new fused feature vector of the character to replace the fused feature vector of the character obtained through fusion processing.
[0136] As an example, the fusion feature vector of a character can be encoded at least once (LK times) using LK cascaded encoders to obtain the hidden layer vector of the fusion feature vector. The hidden layer vector of the fusion feature vector is used as the new fusion feature vector of the character to replace the fusion feature vector of the character obtained through the fusion process.
[0137] The embodiments of this application have the following technical effects: (1) Each word in the dictionary corresponds to at least one tag, and the hidden layer vector of each character and the embedding vector of the tag of each word are fused, so that the importance of the named entity category of the word represented by different tags to named entity recognition can be focused on, thereby improving the recognition accuracy of the named entity recognition model in the named entity recognition method.
[0138] That is to say, at least one word to which each character belongs is queried from the dictionary, and at least one tag of each word is queried from the dictionary, wherein the tag includes the named entity category of the word. Based on the attention mechanism, the attention weights respectively corresponding to the character and the at least one tag of each word are calculated. Based on the attention weights respectively corresponding to the character and the at least one tag, the hidden layer vector of each character and the embedding vector of the tag of each word are fused, so as to focus on the importance of the named entity category of the word represented by different tags to named entity recognition, thereby improving the recognition accuracy of the named entity recognition model in the named entity recognition method.
[0139] (2) The value range of the tags will not change as the scale of the dictionary expands, realizing the decoupling of the dictionary and the named entity recognition model, and the model does not need to be retrained even if the dictionary is expanded.
[0140] That is to say, as the scale of the dictionary expands, if the tags of the entity words in the dictionary are the same as the tags of the entity words in the training set required for model training, the model can be guaranteed to fully learn the tag information of the words in the dictionary. In other words, the recognition accuracy of the model can be guaranteed without retraining the model.
[0141] Refer to Figure 5 , Figure 5 which is a schematic diagram for determining the fused feature vector of a character according to an embodiment of the present application. Taking the character "Hei" (meaning black) as an example, two words that the character "Hei" belongs to are queried from the dictionary, namely "Heishantou" and "Heishan". The tag of the word "Heishantou" is represented by "LOC", which indicates the named entity category of the word, such as a county name. The tags of the word "Heishan" are represented by "GPE, PER, LOC", which respectively indicate the named entity categories of the word, such as person name, place name, and county name.
[0142] A unified one-time attention processing is performed on the character "Hei" and these four tags, which may specifically include: First, embedding processing is performed on the character "Hei" to obtain the embedding vector of the character "Hei", and at least one encoding processing is performed on the embedding vector of the character "Hei" to obtain the hidden layer vector of the character "Hei".
[0143] Second, embedding processing is performed on the tags "GPE, PER, LOC" of the word "Heishan" respectively to obtain the embedding vector of each tag, and embedding processing is performed on the tag "LOC" of the word "Heishantou" to obtain the embedding vector of this tag.
[0144] Third, the attention weights respectively corresponding to the character "Hei", the tag "LOC" of the word "Heishantou", and the three tags of the word "Heishan" are determined.
[0145] The hidden layer vector E(Hei) of the character "Hei" is mapped to the query vector Q(Hei), as shown in the following formula: Q_tans=nn.linear(input_dim,dim_q) Q(Hei) = Q_tans(E(Hei)) Wherein, nn.linear() is a linear transformation function, input_dim represents the hidden layer vector of the input character "Hei", and dim_q represents the declared variable q, that is, the output query vector Q(Hei).
[0146] The embedding vector of the tag "LOC" of the word "Heishantou" to which the character "Hei" belongs is mapped to the key vector K(LOC)_1 and the value vector V(LOC)_1 respectively, the embedding vector of the tag "GPE" of the word "Heishan" to which the character "Hei" belongs is mapped to the key vector K(GPE)_2 and the value vector V(GPE)_2 respectively, the embedding vector of the tag "PER" of the word "Heishan" to which the character "Hei" belongs is mapped to the key vector K(PER)_3 and the value vector V(PER)_3 respectively, and the embedding vector of the tag "LOC" of the word "Heishan" to which the character "Hei" belongs is mapped to the key vector K(LOC)_4 and the value vector V(LOC)_4 respectively, as shown in the following formula: K_tans=nn.linear(input_dim,dim_k) V_tans=nn.linear(input_dim,dim_v) K(LOC)_1 = K_tans(E(LOC)) V(LOC)_1 = V_tans(E(LOC)) K(GPE)_2 = K_tans(E(GPE)) V(GPE)_2 = V_tans(E(GPE)) K(PER)_3 = K_tans(E(PER)) V(PER)_3 = V_tans(E(PER)) K(LOC)_4 = K_trans(E(LOC)) V(LOC)_4 = V_trans(E(LOC)) wherein, nn.linear() is a linear transformation function, input_dim denotes the vector of the label of the input word, dim_k denotes the declared variable k, that is, the output key vector, and dim_v denotes the declared variable v, that is, the output value vector.
[0147] Determine the attention weight corresponding to the label of the character and the word, which is shown in the following formula:
[0148] wherein, denotes the attention weight corresponding to the label of the character and the word, Q denotes the query vector corresponding to the character "hei", K denotes the key vector corresponding to the label of the word, V denotes the value vector corresponding to the label of the word, and dk denotes the dimension of the hidden layer vector of the character "hei".
[0149] That is, according to the above formula, the query vector Q(hei), the key vector K(LOC)_1 and the value vector V(LOC)_1 obtained from the hidden layer vector of the character "hei" are used to obtain the attention weight w1 corresponding to the label "LOC" of the character "hei" and the word "heishantou"; the query vector Q(hei), the key vector K(GPE)_2 and the value vector V(GPE)_2 obtained from the hidden layer vector of the character "hei" are used to obtain the attention weight w2 corresponding to the label "GPE" of the character "hei" and the word "heishan"; the query vector Q(hei), the key vector K(PER)_3 and the value vector V(PER)_3 obtained from the hidden layer vector of the character "hei" are used to obtain the attention weight w3 corresponding to the label "PER" of the character "hei" and the word "heishan"; the query vector Q(hei), the key vector K(LOC)_4 and the value vector V(LOC)_4 obtained from the hidden layer vector of the character "hei" are used to obtain the attention weight w4 corresponding to the label "LOC" of the character "hei" and the word "heishan".
[0150] Fourth, based on the determined attention weight, perform weighted summation processing on the hidden layer vector of the character "hei" and the embedding vector of each label to obtain the fused feature vector of the character.
[0151] As an example, it may refer to that the attention weight determined by the query vector obtained based on the hidden layer vector of the character "hei", the key vector and the value vector obtained from the embedding vector of the label is used to perform weighted summation processing on the value vector obtained from the embedding vector of each label, and the weighted summation result is concatenated with the hidden layer vector of the character "hei" to obtain the fused feature vector of the character.
[0152] For example, the attention weight corresponding to the label "LOC" of the character "Hei" and the word "Heishantou" is w1, the attention weight corresponding to the label "GPE" of the character "Hei" and the word "Heishan" is w2, the attention weight corresponding to the label "PER" of the character "Hei" and the word "Heishan" is w3, the attention weight corresponding to the label "LOC" of the character "Hei" and the word "Heishan" is w4, the value vector corresponding to the label "LOC" of the word "Heishantou" is V(LOC)_1, the value vector corresponding to the label "GPE" of the word "Heishan" is V(GPE)_2, the value vector corresponding to the label "PER" of the word "Heishan" is V(PER)_3, the value vector corresponding to the label "LOC" of the word "Heishan" is V(LOC)_4, and the hidden layer vector of the character "Hei" is E(Hei).
[0153] Then, a weighted summation process is performed on the hidden layer vector of the character "Hei" and the embedding vector of each label to obtain the fused feature vector of the character, and the fused feature vector is expressed as { [w1×V(LOC)_1+w2×V(GPE)_2+w3×V(PER)_3+w4×V(LOC)_4], E(Hei)}.
[0154] Refer to Figure 6 , Figure 6 which is another schematic diagram for determining the fused feature vector of a character according to the embodiments of the present application. Taking the character "Hei" as an example, two words that the character "Hei" belongs to are queried from the dictionary, which are "Heishantou" and "Heishan" respectively. The label of the word "Heishantou" is represented by "LOC", and the labels of the word "Heishan" are represented by "GPE, PER, LOC", which respectively represent the named entity categories of the word, such as person name, place name, and county name.
[0155] Two attention processes are performed on the character "Hei" and the four labels, which may specifically include: The first attention processing process: First, embedding processing is performed on the character "Hei" to obtain the embedding vector of the character "Hei", and at least one encoding processing is performed on the embedding vector of the character "Hei" to obtain the hidden layer vector of the character "Hei".
[0156] Second, embedding processing is performed on the labels "GPE, PER, LOC" of the word "Heishan" respectively to obtain the embedding vector of each label, and embedding processing is performed on the label "LOC" of the word "Heishantou" to obtain the embedding vector of this label.
[0157] Third, the label-level attention weights respectively corresponding to the character "Hei", the three labels of the word "Heishan", and the label of the word "Heishantou" are determined, where the label-level attention weight characterizes the importance degree of the category of the named entity represented by the label.
[0158] Map the hidden layer vector E(Hei) of the character "Hei" to the query vector Q(Hei), as shown in the following formula: Q_trans=nn.linear(input_dim,dim_q) Q(Hei) = Q_trans(E(Hei)) Wherein, nn.linear() is a linear transformation function, input_dim represents the hidden layer vector corresponding to the character "Hei", and dim_q represents the declared variable q.
[0159] Map the embedding vector of the label "LOC" of the word "Heishantou" to which the character "Hei" belongs to the key vector K(LOC)_1 and the value vector V(LOC)_1 respectively, map the embedding vector of the label "GPE" of the word "Heishan" to which the character "Hei" belongs to the key vector K(GPE)_2 and the value vector V(GPE)_2 respectively, map the embedding vector of the label "PER" of the word "Heishan" to which the character "Hei" belongs to the key vector K(PER)_3 and the value vector V(PER)_3 respectively, and map the embedding vector of the label "LOC" of the word "Heishan" to which the character "Hei" belongs to the key vector K(LOC)_4 and the value vector V(LOC)_4 respectively, as shown in the following formula: K_trans=nn.linear(input_dim,dim_k) V_trans=nn.linear(input_dim,dim_v) K(LOC)_1 = K_trans(E(LOC)) V(LOC)_1 = V_trans(E(LOC)) K(GPE)_2 = K_trans(E(GPE)) V(GPE)_2 = V_trans(E(GPE)) K(PER)_3 = K_trans(E(PER)) V(PER)_3 = V_trans(E(PER)) K(LOC)_4 = K_trans(E(LOC)) V(LOC)_4 = V_trans(E(LOC)) Wherein, nn.linear() is a linear transformation function, input_dim represents the embedding vector of the input label, dim_k represents the declared variable k, that is, the output key vector, and dim_v represents the declared variable v, that is, the output value vector.
[0160] Determine the tag-level attention weights corresponding to the tags of characters and words, as shown in the following formula:
[0161] where, denotes the tag-level attention weight corresponding to the tags of characters and words, Q denotes the query vector corresponding to the character "hei", K denotes the key vector corresponding to the tag of the word, V denotes the value vector corresponding to the tag of the word, and dk denotes the dimension of the hidden layer vector of the character "hei".
[0162] That is, according to the above formula, the query vector Q(hei), key vector K(LOC)_1 and value vector V(LOC)_1 obtained from the hidden layer vector of the character "hei" are used to obtain the tag-level attention weight w1 corresponding to the tag "LOC" of the character "hei" and the word "heishantou"; the query vector Q(hei), key vector K(GPE)_2 and value vector V(GPE)_2 obtained from the hidden layer vector of the character "hei" are used to obtain the tag-level attention weight w2 corresponding to the tag "GPE" of the character "hei" and the word "heishan"; the query vector Q(hei), key vector K(PER)_3 and value vector V(PER)_3 obtained from the hidden layer vector of the character "hei" are used to obtain the tag-level attention weight w3 corresponding to the tag "PER" of the character "hei" and the word "heishan"; the query vector Q(hei), key vector K(LOC)_4 and value vector V(LOC)_4 obtained from the hidden layer vector of the character "hei" are used to obtain the tag-level attention weight w4 corresponding to the tag "LOC" of the character "hei" and the word "heishan".
[0163] Fourth, perform the following processing for each word: based on the tag-level attention weights respectively corresponding to at least one tag of the character and the word, perform a weighted summation process on the hidden layer vector of the character and the embedding vector of the tag of each word, so as to obtain a tag-level fused feature vector between the character and the word.
[0164] As an example, it may refer to performing a weighted summation process on the value vector obtained from the embedding vector of the tag of each word by using the tag-level attention weight determined based on the query vector obtained from the hidden layer vector of the character "hei", and the key vector and value vector obtained from the embedding vector of the tag, and concatenating the weighted summation result with the hidden layer vector of the character, so as to obtain the tag-level fused feature vector between the character and the word.
[0165] For example, the query vector Q(Hei), the key vector K(LOC)_1 and the value vector V(LOC)_1 obtained using the hidden layer vector of the character "Hei" are used to obtain the label-level attention weight w1 corresponding to the label "LOC" of the character "Hei" and the word "Heishantou"; the query vector Q(Hei), the key vector K(GPE)_2 and the value vector V(GPE)_2 obtained using the hidden layer vector of the character "Hei" are used to obtain the label-level attention weight w2 corresponding to the label "GPE" of the character "Hei" and the word "Heishan"; the query vector Q(Hei), the key vector K(PER)_3 and the value vector V(PER)_3 obtained using the hidden layer vector of the character "Hei" are used to obtain the label-level attention weight w3 corresponding to the label "PER" of the character "Hei" and the word "Heishan"; the query vector Q(Hei), the key vector K(LOC)_4 and the value vector V(LOC)_4 obtained using the hidden layer vector of the character "Hei" are used to obtain the label-level attention weight w4 corresponding to the label "LOC" of the character "Hei" and the word "Heishan". The value vector corresponding to the label "LOC" of the word "Heishantou" is V(LOC)_1, the value vector corresponding to the label "GPE" of the word "Heishan" is V(GPE)_2, the value vector corresponding to the label "PER" of the word "Heishan" is V(PER)_3, the value vector corresponding to the label "LOC" of the word "Heishan" is V(LOC)_4, and the hidden layer vector of the character "Hei" is E(Hei).
[0166] Then the label-level fused feature vector between the character "Hei" and the word "Heishantou" is expressed as {w1×V(LOC)_1, E(Hei)}, and the label-level fused feature vector between the character "Hei" and the word "Heishan" is expressed as {[w2×V(GPE)_2 + w3×V(PER)_3 + w4×V(LOC)_4], E(Hei)}.
[0167] Second attention processing procedure: Fifth, determine the word-level attention weights corresponding to the character and the word respectively, where the word-level attention weight characterizes the importance degree of the word.
[0168] Map the hidden layer vector E(Hei) of the character "Hei" to the query vector Q(Hei), as shown in the following formula: Q_tans=nn.linear(input_dim,dim_q) Q(Hei) = Q_tans(E(Hei)) Wherein, nn.linear() is a linear transformation function, input_dim represents the input hidden layer vector of the character "Hei", and dim_q represents the declared variable q, that is, the output query vector Q(Hei).
[0169] Perform embedding processing on each word to obtain the embedding vector corresponding to each word, and map the embedding vectors between each word to a key vector and a value vector respectively, as shown in the following formula: K_tans=nn.linear(input_dim,dim_k) V_tans=nn.linear(input_dim,dim_v) K(Heishantou)_1 = K_tans(E(Heishantou)) V(Heishantou)_1 = V_tans(E(Heishantou)) K(Heishan)_1 = K_tans(E(Heishan)) V(Heishan)_1 = V_tans(E(Heishan)) Herein, nn.linear() is a linear transformation function, input_dim represents the embedding vector of the word corresponding to the character "Hei", dim_k represents the declared variable k, and dim_v represents the declared variable v.
[0170] Determine the word-level attention weights corresponding to characters and words, as shown in the following formula:
[0171] Herein, represents the word-level attention weight corresponding to a character and a word, Q represents the query vector corresponding to the character "Hei", K represents the key vector corresponding to a word, V represents the value vector corresponding to a word, and dk represents the dimension of the hidden layer vector of the character "Hei".
[0172] That is, according to the above formula, the query vector Q(Hei), key vector K_1 and value vector V_1 obtained from the hidden layer vector of the character "Hei" are used to obtain the word-level attention weight w5 corresponding to the character "Hei" and the word "Heishantou", and the query vector Q(Hei), key vector K_2 and value vector V_2 obtained from the hidden layer vector of the character "Hei" are used to obtain the word-level attention weight w6 corresponding to the character "Hei" and the word "Heishan".
[0173] Sixth, perform the following processing for each word: based on the respective word-level attention weights corresponding to the character and the word, perform weighted summation processing on the hidden layer vector of the character and the label-level fused feature vector between each word that includes the character, so as to obtain the word-level fused feature vector between the character and each word that includes the character.
[0174] As an example, it may refer to performing weighted summation processing on the label-level fused feature vectors between each word of the character using the word-level attention weights determined by the query vector obtained based on the hidden layer vector of the character "hei", the key vector and value vector obtained from the embedding vector of the word, and concatenating the weighted summation result with the hidden layer vector of the character to obtain the word-level fused feature vector between the character and each word including the character.
[0175] For example, the query vector Q(hei), key vector K_1 and value vector V_1 obtained using the hidden layer vector of the character "hei" are used to obtain the word-level attention weight w5 corresponding to the character "hei" and the word "heishan tou", and the query vector Q(hei), key vector K_2 and value vector V_2 obtained using the hidden layer vector of the character "hei" are used to obtain the word-level attention weight w6 corresponding to the character "hei" and the word "heishan", where the hidden layer vector of the character "hei" is E(hei).
[0176] Then the word-level fused feature vector is expressed as { [w5×[w1×V(LOC)_1]+w6×[w2×V(GPE)_2+w3×V(PER)_3+w4×V(LOC)_4]], E(hei)}.
[0177] In the following, an exemplary application of the named entity recognition method provided in the embodiments of the present application in a practical application scenario will be described.
[0178] A user inputs the text "Wu Song avenges his brother (4) End #New Water Margin##Wu Song##Ximen Qing#" in a browser, and the terminal used by the user sends a named entity recognition request to the server, where the named entity recognition request is used to request the return of the named entity categories in the text.
[0179] The process of the server responding to the named entity recognition request and returning the named entity categories in the text may include: First, at least one word to which each character in the text belongs is queried from the dictionary, and at least one label of each word is queried from the dictionary, where the label includes the named entity category of the word.
[0180] Assume that the words stored in the dictionary are "New Water Margin", "Zhui Xu", and "Legend of the White Snake", the label corresponding to "New Water Margin" is label1, which indicates that the named entity category of the word is novel name, the label corresponding to "Zhui Xu" is label2, which indicates that the named entity category of the word is novel name, and the label corresponding to "Legend of the White Snake" is label3, which indicates that the named entity category of the word is novel name.
[0181] Second, embedding processing is performed on each character to obtain an embedding vector of each character, at least one encoding processing is performed on the embedding vector of each character to obtain a hidden layer vector of each character, and embedding processing is performed on the label of each word to obtain an embedding vector of the label of each word.
[0182] Third, fusion processing is performed on the hidden layer vector of each character and the embedding vector of the label of each word, to obtain a fused feature vector of each character.
[0183] Taking the four characters (tokens) "Xin", "Shui", "Hu" and "Zhuan" as an example, fusion processing is performed on the hidden layer vector of each character and the embedding vector of the label of each word to obtain the fused feature vector of each character, and the specific implementation process is similar to the calculation process of the character "Hei" in the above text, which will not be repeated here.
[0184] Fourth, a decoder performs decoding processing based on the fused feature vector of each character, to obtain the named entity category of each character.
[0185] Through the named entity recognition model of the named entity recognition method provided in the embodiments of the present application, the named entity in the input text, that is, the novel title "Xin Shui Hu Zhuan", is identified in combination with the lexicon.
[0186] Finally, the identified named entity category of each character is returned to the terminal, for the terminal to display to the user.
[0187] Considering that in the business scenario of extracting novel titles, the search text (query) input by the user has novel titles with non-standard grammar and high ambiguity, and new novel titles are added every day leading to constant changes in the lexicon, the named entity recognition model of the named entity recognition method provided in the embodiments of the present application has obvious advantages in the recall of novel titles.
[0188] Table 3 shows a comparison in terms of recall rate between the BERT Base model (without adding a lexicon) and the BowenNER model (introducing labels in the lexicon). The BoweNER model (adding a lexicon and introducing labels) has a significantly better recall advantage than the BERT Base model (without adding a lexicon). Among them, BowenNER is the named entity recognition model of the named entity recognition method provided in the embodiments of the present application.
[0189] Table 3
[0190] The relevant experiments conducted in the embodiments of the present application are described below.
[0191] 1. The goal achieved by the experiment is: (1) The BowenNER (named entity recognition model of the named entity recognition method provided in the embodiments of this application) which explicitly introduces label information is better than LEBERT.
[0192] (2) When the dictionary size is expanded, the model does not need to be retrained and the performance can still be improved.
[0193] The experimental dataset is a fine-grained NER dataset with manual annotation, and the category system includes 26 major categories and 132 subcategories. The dictionary consists of a selection of entity words from topbase (a very large entity database with label information), and the dictionary size is 580,000.
[0194] Table 4 shows the distribution of our own business datasets.
[0195] Table 4
[0196] Experiment 1 shows that, with a significant reduction in model parameters (the reduction is reflected in the size of the newly added embedding being reduced from the number of words in the dictionary to the number of labels), the effect of the vocabulary augmentation model can be improved by introducing label information.
[0197] Table 5 shows the performance of BowenNER compared to LEBERT on fine-grained datasets.
[0198] Table 5
[0199] Experiment 2 randomly selected 180,000 words from a dictionary of 580,000 words to form a small dictionary for model training. The trained model was then used to make predictions on dictionaries of different sizes.
[0200] Table 6 shows the model trained with a dictionary of 180,000 words. After obtaining the optimal checkpoint (where the checkpoint refers to saving the model's weights after training), inference was performed on dictionaries of 180,000 and 580,000 words respectively. Table 6 compares the model's performance before and after expanding the dictionary. "Inference only" means that the model was not retrained; the pre-trained model was loaded and inference was performed on the new dictionary.
[0201] Table 6
[0202] 2. Strengthen the role of dictionaries 2.1 Expected vocabulary enhancement effect Once the model training is complete and the model is deployed, the following two points should be achieved by expanding the dictionary: (1) Entities that the model failed to recall can be recalled after being added to the dictionary. (2) The model for adding ambiguous words to the dictionary can avoid false recalls or type judgment errors. Can BowenNER achieve this effect? We can experiment by adding specific words to the dictionary. The added words include positive examples and negative examples. Positive examples are entity words that the current model cannot recall, to verify that the model can recall such words after the dictionary change. Negative examples are noise words, to verify whether the newly added noisy entity words in the dictionary will affect the model's judgment, leading to false recall or incorrect category judgment.
[0203] The positive example word is: Baby sucking their hands - medical information - diseases The counterexample is: The Four Great Classical Novels have been changed from the category of books to novels. The executing agency has been changed from an organization category (institution) to an organization category (company). Hepatitis A vaccine changed from a medical term to a medical disease. September Characters - Virtual Characters Sample 1: Benefits of babies sucking their hands during the oral stage goldern [['Baby sucking their thumb', 3, 'Medical symptoms']] predict [['oral stage', 0, 'medical_disease']] The BowenNER model only successfully corrected the prediction result of the second of the four samples, but it is worth noting that the newly added noisy words did not cause the model to make any misjudgments.
[0204] The small experiment above illustrates that the dictionary has relatively weak control over the model. This is because the model hasn't fully learned the label information from the dictionary; it doesn't know when to trust the dictionary and when to trust the model itself. To investigate the factors influencing whether the model has sufficiently learned the label information from the dictionary, experiments were conducted on the public dataset ontonotes.
[0205] 2.2 Vocabulary reinforcement with controllable strength and weakness Whether the label information in the dictionary is sufficiently learned is determined by the dictionary's entity coverage of the training set (coverage refers to the ratio of all words in the dictionary to the entity words in the training set), not by the size of the dictionary. In the extreme case, all words in the dictionary consist of entity words from the training set, resulting in 100% entity coverage. In this case, all entity words in the training samples participate in label learning. That is, label learning is most thorough in this situation.
[0206] Before the experiment, the following dictionary was constructed: The topbase dictionary consists of 3.4 million words extracted from the topbase entity database, including names of people, places, and organizations.
[0207] Training set entity dictionary: It consists of all entity words in the training set, and the label corresponding to each word is its golden category.
[0208] Test set entity dictionary: It consists of all entity words in the test set, and the label corresponding to each word is its golden category.
[0209] Table 7 shows the distribution of the ontonotes dataset.
[0210] Table 7
[0211] 2.3 Experiment on entity word coverage in vocabulary enhancement Five sets of experiments were set up: Bert base experiment, LEBERT experiment (topbase dictionary), LEBERT experiment (training set entity dictionary), BowenNER experiment (topbase dictionary), and BowenNER experiment (training set entity dictionary).
[0212] Table 8 shows a comparison of the experimental results of ontonotes.
[0213] Table 8
[0214] The checkpoints obtained by training BowenNER using the topbase dictionary and the training set entity dictionary are used for inference, and the corresponding dictionary is changed to the test set entity dictionary during inference.
[0215] Table 9 compares the inference performance of ontonotes on the entity dictionary of the test set.
[0216] Table 9
[0217] 2.1.1 Experimental Analysis (1) Due to the characteristics of LEBERT, the training and testing dictionaries must be consistent.
[0218] Experiments show that the coverage of the dictionary on the test set affects the model's performance. The topbase dictionary has a higher coverage of entities in the test set compared to the entity dictionary in the training set, and therefore its metrics are better.
[0219] (2) In the BowenNER experiment, the coverage of the entity dictionary in the training set was 100%, which was much higher than the coverage of the topbase dictionary in the training set of 34%.
[0220] Experimental results show that when the dictionary achieves 100% entity coverage in the training set, the model essentially loses its generalization ability and degenerates into keyword matching. Furthermore, because the dictionary's entity coverage in the test set is insufficient, the model performs poorly on the test set.
[0221] (3) BowenNER can decouple the dictionary and the model, meaning that the training and testing dictionaries can be completely different, as long as the value range of the label is the same.
[0222] Table 9 shows that when the trained BowenNER checkpoints are used for inference on the test set entity dictionary, the checkpoints corresponding to the training set entity dictionary show a significant improvement in performance, indicating that the checkpoint dictionary trained in this way can influence the model's inference results. The dictionary's control over the model reaches its peak.
[0223] 2.1.2 Experimental Conclusions (1) For BowenNER, as the coverage of the dictionary to entity words in the training set increases, the dictionary’s control over the model is enhanced.
[0224] (2) For BowenNER, as the coverage of the dictionary of entity words in the training set increases, the generalization ability of the model gradually weakens.
[0225] 2.4 Lexical reinforcement perturbation experiment The above experiments demonstrate that increasing the dictionary's coverage of entity words in the training set can enhance the dictionary's control over the BowenNER model. So how can we control this strength just right to obtain a model with strong dictionary control and strong generalization ability? The answer is "perturbation".
[0226] If the dictionary is not 100% accurate, perturbation needs to be added. The size of the perturbation depends on the quality of the dictionary. Higher quality dictionaries can have smaller perturbations, while lower quality dictionaries should have larger perturbation values. Similar to BERT's mask task, a perturbation is added during dictionary matching. The specific implementation is as follows: (1) Randomly select some spans in the sentence that are not matched by the dictionary, and assign them a random type.
[0227] (2) For a span that is matched by the dictionary, randomly replace its label with another non-current label.
[0228] (3) For spans that are matched by the dictionary, delete their corresponding label information and change them to misses.
[0229] Table 10 shows the model's performance after introducing a certain proportion of perturbation.
[0230] Table 10
[0231] Table 11 shows the model's inference performance after changing the dictionary to the test set entity dictionary.
[0232] Table 11
[0233] Experimental results show that by adding perturbations of different proportions, the control strength of the dictionary over the model can be adjusted, and ultimately the generalization of the model and the control of the dictionary over the model can be balanced.
[0234] 2.5 Simulation of Real Production Environment Experiment In real-world production environments, continuously adding new words to the dictionary can improve its coverage of entities in the open set. However, this constant addition can also introduce interference. As the dictionary size increases, the model's robustness needs to be assessed. To verify this, two dictionaries were constructed: topbase + training set entity words, and topbase + test set entity words. The stability of the model was verified by merging the topbase dictionary to introduce interference.
[0235] Table 12 shows the metrics for the ontonotes dataset in a simulated production environment.
[0236] Table 12
[0237] Table 13 shows the model's inference performance after changing the dictionary to the topbase + test set entity dictionary.
[0238] Table 13
[0239] Experimental results show that the interference from dictionary expansion has a very limited impact on the model. With a 10% perturbation, the metric decreased from 83.77% to 83.51% compared to adding the topbase dictionary. This type of vocabulary enhancement model, with its controllable strength, is very suitable for users with a business-accumulated dictionary.
[0240] The following description continues to illustrate the exemplary structure of the named entity recognition device 255 provided in the embodiments of this application as a software module. In some embodiments, such as Figure 2As shown, the software modules stored in the named entity recognition device 255 in the memory 250 may include: an acquisition module 2551 for acquiring text to be processed, wherein the text to be processed includes multiple characters; a query module 2552 for querying at least one word to which each character belongs from the dictionary, and querying at least one tag for each word from the dictionary, wherein the tag includes the named entity category of the word; a determination module 2553 for determining the hidden layer vector of each character and determining the embedding vector of the tag of each word; a processing module 2554 for fusing the hidden layer vector of each character and the embedding vector of the tag of each word to obtain a fused feature vector of each character; and a decoding module 2555 for decoding based on the fused feature vector of each character to obtain the named entity category of each character.
[0241] In the above scheme, the label also includes the type of the character's position in its word.
[0242] In the above scheme, the determining module 2553 is further used to: perform embedding processing on each character to obtain the embedding vector of each character; perform encoding processing on the embedding vector of each character at least once to obtain the hidden layer vector of each character; and perform embedding processing on the tag of each word to obtain the embedding vector of the tag of each word.
[0243] In the above scheme, the processing module 2554 is further configured to: perform the following processing for each character: determine the attention weights corresponding to the character and at least one label of each word; and, based on the attention weights corresponding to the character and at least one label, perform weighted summation on the hidden layer vector of the character and the embedding vector of each label to obtain the fused feature vector of the character.
[0244] In the above scheme, the determining module 2553 is further configured to: perform the following processing for each word: determine the label-level attention weights corresponding to at least one label of the character and the word, wherein the label-level attention weights represent the importance of the category of the named entity represented by the label; and perform the following processing for each word: determine the word-level attention weights corresponding to the character and the word, wherein the word-level attention weights represent the importance of the word.
[0245] In the above scheme, the processing module 2554 is further configured to: perform the following processing for each word: based on the label-level attention weights corresponding to at least one label of the character and the word, perform weighted summation on the hidden layer vector of the character and the embedding vector of the label of each word to obtain the label-level fusion feature vector between the character and the word; and perform the following processing for each word: based on the word-level attention weights corresponding to the character and the word, perform weighted summation on the hidden layer vector of the character and the label-level fusion feature vector between each word including the character to obtain the word-level fusion feature vector between the character and each word including the character.
[0246] In the above scheme, the determining module 2553 is further configured to: map the hidden layer vector of a character to a query vector, and map the embedding vector of at least one label of a word to a key vector and a value vector respectively; perform a transpose operation on the key vector to obtain a transposed key vector; perform a dot product operation on the query vector and the transposed key vector to obtain the operation result; map the operation result and the value vector to a probability distribution based on the activation function, wherein the probability distribution includes multiple probability values; and use the multiple probability values as the label-level attention weights corresponding to at least one label of the character and the word respectively.
[0247] In the above scheme, the determining module 2553 is further configured to: map the hidden layer vector of the character to the query vector; perform embedding processing on each word to obtain the embedding vector corresponding to each word, and map the embedding vector of each word to the key vector and the value vector respectively; perform transpose processing on the key vector to obtain the transposed key vector; perform dot product operation on the query vector and the transposed key vector to obtain the operation result; map the operation result and the value vector to a probability distribution based on the activation function, wherein the probability distribution includes multiple probability values; and use the multiple probability values as word-level attention weights corresponding to the character and the word respectively.
[0248] In the above scheme, the processing module 2554 is further configured to, after obtaining the tag-level fusion feature vector between the character and each word including the character, perform residual processing on the tag-level fusion feature vector to obtain a residual feature vector; perform normalization processing on the residual feature vector to obtain a normalized feature vector; and use the normalized feature vector as a new tag-level fusion feature vector to replace the tag-level fusion feature vector obtained by weighted summation processing.
[0249] In the above scheme, the processing module 2554 is further configured to, after obtaining the word-level fusion feature vector between the character and each word including the character, perform residual processing on the word-level fusion feature vector to obtain a residual feature vector; perform normalization processing on the residual feature vector to obtain a normalized feature vector; and use the normalized feature vector as a new word-level fusion feature vector to replace the word-level fusion feature vector obtained by weighted summation processing.
[0250] In the above scheme, the decoding module 2555 is further configured to perform the following processing for each character before performing decoding processing based on the fusion feature vector of each character: perform encoding processing on the fusion feature vector of the character at least once to obtain the hidden layer vector of the fusion feature vector; and use the hidden layer vector of the fusion feature vector as the new fusion feature vector of the character to replace the fusion feature vector of the character obtained through fusion processing.
[0251] In the above scheme, the decoding module 2555 is further configured to: map the fusion feature vector corresponding to each character to a probability distribution corresponding to multiple labels, and take the named entity category represented by the label with the highest probability as the named entity category of the character; or, map the fusion feature vector corresponding to each character to multiple label paths, wherein each label path includes a label corresponding to multiple characters and the corresponding probability, determine the score of multiple label paths based on the probability, and take the named entity category represented by the label of each character in the label path with the highest score as the named entity category of the character.
[0252] In the above scheme, the dictionary includes multiple words, and each word is associated with at least one tag; the query module 2552 is also used to: perform the following processing for each character: use the character as an index to query at least one word containing the character from the dictionary, and perform the following processing for each word found: query at least one tag associated with the word from the dictionary.
[0253] This application provides a computer program product or computer program that includes computer instructions stored in a computer-readable storage medium. A processor of a computer device reads the computer instructions from the computer-readable storage medium and executes the computer instructions, causing the computer device to perform the named entity identification method described above in this application.
[0254] This application provides a computer-readable storage medium storing executable instructions, wherein the executable instructions are stored and, when executed by a processor, will cause the processor to execute the method provided in this application.
[0255] In some embodiments, the computer-readable storage medium may be a memory such as FRAM, ROM, PROM, EPROM, EEPROM, flash memory, magnetic surface memory, optical disk, or CD-ROM; or it may be a variety of devices including one or any combination of the above-mentioned memories.
[0256] In some embodiments, executable instructions may take the form of a program, software, software module, script, or code, written in any form of programming language (including compiled or interpreted languages, or declarative or procedural languages), and may be deployed in any form, including as a standalone program or as a module, component, subroutine, or other unit suitable for use in a computing environment.
[0257] As an example, executable instructions may, but do not necessarily, correspond to files in a file system. They may be stored as part of a file that holds other programs or data, for example, in one or more scripts in a HyperText Markup Language (HTML) document, in a single file dedicated to the program in question, or in multiple collaborating files (e.g., files that store one or more modules, subroutines, or code sections).
[0258] As an example, executable instructions can be deployed to execute on a single computing device, or on multiple computing devices located in one location, or on multiple computing devices distributed across multiple locations and interconnected via a communication network.
[0259] The above are merely embodiments of this application and are not intended to limit the scope of protection of this application. Any modifications, equivalent substitutions, and improvements made within the spirit and scope of this application are included within the scope of protection of this application.
Claims
1. A method for recognizing named entities, characterized in that, include: Obtain the text to be processed, wherein the text to be processed includes multiple characters; Retrieve from the dictionary at least one word to which each character belongs, and retrieve from the dictionary at least one tag for each word, wherein the tag includes the named entity category of the word; Determine the hidden layer vector for each character and the embedding vector for the label of each word; Perform the following processing for each of the aforementioned words: Determine the label-level attention weights corresponding to at least one label of the character and the word, wherein the label-level attention weights characterize the importance of the category of the named entity represented by the label; Determine the word-level attention weights corresponding to the character and the word, wherein the word-level attention weights represent the importance of the word; Based on the label-level attention weights corresponding to at least one label of the character and the word, the hidden layer vector of the character and the embedding vector of each label of the word are weighted and summed to obtain the label-level fusion feature vector between the character and the word. Based on the word-level attention weights corresponding to the character and the word respectively, the hidden layer vector of the character and the label-level fusion feature vector between each word including the character are weighted and summed to obtain the word-level fusion feature vector between the character and each word including the character. The word-level fusion feature vector between the character and each word including the character is used as the fusion feature vector of the character; The named entity category of each character is obtained by decoding based on the fused feature vector of each character.
2. The method according to claim 1, characterized in that, The label also includes the type of the character's position within its word.
3. The method according to claim 1, characterized in that, Determining the hidden vector for each character includes: Each character is embedded to obtain an embedding vector for each character; The embedding vector of each character is encoded at least once to obtain the hidden layer vector of each character; Determining the embedding vector of the label for each word includes: Embedding processing is performed on the label of each word to obtain the embedding vector of the label of each word.
4. The method according to claim 1, characterized in that, The step of determining the label-level attention weights corresponding to at least one label of the character and the word includes: The hidden vector of the character is mapped to a query vector, and the embedding vector of at least one tag of the word is mapped to a key vector and a value vector, respectively. The key vector is transposed to obtain the transposed key vector; Perform a dot product operation between the query vector and the transpose key vector to obtain the result; The operation result is mapped to the value vector as a probability distribution based on the activation function, wherein the probability distribution includes multiple probability values; The plurality of probability values are used as label-level attention weights corresponding to at least one label of the character and the word, respectively.
5. The method according to claim 1, characterized in that, Determining the word-level attention weights corresponding to the character and the word respectively includes: Map the hidden vector of the character to a query vector; Each word is embedded to obtain an embedding vector for each word, and the embedding vector of each word is mapped to a key vector and a value vector respectively. The key vector is transposed to obtain the transposed key vector; Perform a dot product operation between the query vector and the transpose key vector to obtain the result; The operation result is mapped to the value vector as a probability distribution based on the activation function, wherein the probability distribution includes multiple probability values; The plurality of probability values are used as word-level attention weights for the character and the word, respectively.
6. The method according to claim 1, characterized in that, After obtaining the label-level fused feature vector between the character and the word, the method further includes: The label-level fused feature vector is subjected to residual processing to obtain a residual feature vector; The residual feature vector is normalized to obtain a normalized feature vector; The normalized feature vector is used as the new label-level fusion feature vector to replace the label-level fusion feature vector obtained by weighted summation.
7. The method according to claim 1, characterized in that, After obtaining the word-level fusion feature vector between the character and each word including the character, the method further includes: The word-level fused feature vector is subjected to residual processing to obtain a residual feature vector; The residual feature vector is normalized to obtain a normalized feature vector; The normalized feature vector is used as the new word-level fusion feature vector to replace the word-level fusion feature vector obtained by weighted summation.
8. The method according to any one of claims 1 to 7, characterized in that, Before performing the decoding process based on the fused feature vector of each character, the method further includes: Perform the following processing for each of the characters: The fusion feature vector of the character is encoded at least once to obtain the hidden layer vector of the fusion feature vector; The hidden layer vector of the fused feature vector is used as the new fused feature vector of the character to replace the fused feature vector of the character.
9. The method according to any one of claims 1 to 7, characterized in that, The decoding process based on the fused feature vector of each character to obtain the named entity category of each character includes: The fused feature vector of each character is mapped to a probability distribution corresponding to multiple labels, and the named entity category represented by the label with the highest probability is taken as the named entity category of the character, or The fusion feature vector of each character is mapped to multiple label paths, wherein each label path includes a label corresponding to each of the multiple characters and a corresponding probability. The score of the multiple label paths is determined based on the probability, and the named entity category represented by the label of each character in the label path with the highest score is taken as the named entity category of the character.
10. The method according to any one of claims 1 to 7, characterized in that, The dictionary includes multiple words, and each word is associated with at least one tag; The step of querying the dictionary for at least one word to which each character belongs, and querying the dictionary for at least one tag for each word, includes: Perform the following processing for each of the characters: Using the character as an index, query the dictionary for at least one word containing the character, and perform the following processing for each of the queried words: Retrieve from the dictionary at least one tag associated with the word.
11. A named entity identification device, characterized in that, include: The acquisition module is used to acquire the text to be processed, wherein the text to be processed includes multiple characters; A query module is configured to query at least one word to which each character belongs from a dictionary, and to query at least one tag for each word from the dictionary, wherein the tag includes the named entity category of the word; A determination module is used to determine the hidden layer vector of each character and the embedding vector of the label of each word; The determining module is further configured to determine the tag-level attention weights corresponding to at least one tag of the character and the word, wherein the tag-level attention weights characterize the importance of the category of the named entity represented by the tag; and to determine the word-level attention weights corresponding to the character and the word, wherein the word-level attention weights characterize the importance of the word; The processing module is configured to: perform weighted summation on the hidden layer vector of the character and the embedding vector of each word's label based on the label-level attention weights corresponding to at least one label of the character and the word, to obtain a label-level fusion feature vector between the character and the word; perform weighted summation on the hidden layer vector of the character and the label-level fusion feature vector between each word including the character based on the word-level attention weights corresponding to the character and the word, to obtain a word-level fusion feature vector between the character and each word including the character; and use the word-level fusion feature vector between the character and each word including the character as the fusion feature vector of the character. The decoding module is used to perform decoding processing based on the fused feature vector of each character to obtain the named entity category of each character.
12. The apparatus according to claim 11, characterized in that, The label also includes the type of the character's position within its word.
13. The apparatus according to claim 11, characterized in that, The determining module is further configured to perform embedding processing on each of the characters to obtain an embedding vector for each character; perform encoding processing on the embedding vector of each character at least once to obtain a hidden layer vector for each character; and perform embedding processing on the tag of each word to obtain an embedding vector for the tag of each word.
14. The apparatus according to claim 11, characterized in that, The determining module is further configured to: The hidden vector of the character is mapped to a query vector, and the embedding vector of at least one tag of the word is mapped to a key vector and a value vector, respectively. The key vector is transposed to obtain the transposed key vector; Perform a dot product operation between the query vector and the transpose key vector to obtain the result; The operation result is mapped to the value vector as a probability distribution based on the activation function, wherein the probability distribution includes multiple probability values; The plurality of probability values are used as label-level attention weights corresponding to at least one label of the character and the word, respectively.
15. The apparatus according to claim 11, characterized in that, The determining module is further configured to: Map the hidden vector of the character to a query vector; Each word is embedded to obtain an embedding vector for each word, and the embedding vector of each word is mapped to a key vector and a value vector respectively. The key vector is transposed to obtain a transposed key vector; the query vector and the transposed key vector are multiplied by a dot product to obtain the result. The operation result is mapped to the value vector as a probability distribution based on the activation function, wherein the probability distribution includes multiple probability values; The plurality of probability values are used as word-level attention weights for the character and the word, respectively.
16. The apparatus according to claim 11, characterized in that, The processing module is further configured to, after obtaining the tag-level fusion feature vector between the character and the word, perform residual processing on the tag-level fusion feature vector to obtain a residual feature vector; perform normalization processing on the residual feature vector to obtain a normalized feature vector; and use the normalized feature vector as a new tag-level fusion feature vector to replace the tag-level fusion feature vector obtained by weighted summation processing.
17. The apparatus according to claim 11, characterized in that, The processing module is further configured to, after obtaining the word-level fusion feature vector between the character and each word including the character, perform residual processing on the word-level fusion feature vector to obtain a residual feature vector; and perform normalization processing on the residual feature vector to obtain a normalized feature vector. The normalized feature vector is used as the new word-level fusion feature vector to replace the word-level fusion feature vector obtained by weighted summation.
18. The apparatus according to any one of claims 11 to 17, characterized in that, The decoding module is further configured to perform the following processing for each character before performing the decoding processing based on the fused feature vector of each character: The fusion feature vector of the character is encoded at least once to obtain the hidden layer vector of the fusion feature vector; The hidden layer vector of the fused feature vector is used as the new fused feature vector of the character to replace the fused feature vector of the character.
19. The apparatus according to any one of claims 11 to 17, characterized in that, The decoding module is also used for: The fused feature vector of each character is mapped to the probability distribution of multiple corresponding labels, and the named entity category represented by the label with the highest probability is taken as the named entity category of the character. or The fusion feature vector of each character is mapped to multiple label paths, wherein each label path includes a label corresponding to each of the multiple characters and a corresponding probability. The score of the multiple label paths is determined based on the probability, and the named entity category represented by the label of each character in the label path with the highest score is taken as the named entity category of the character.
20. The apparatus according to any one of claims 11 to 17, characterized in that, The dictionary includes multiple words, and each word is associated with at least one tag; The query module is further configured to perform the following processing for each character: Using the character as an index, query the dictionary for at least one word containing the character, and perform the following processing for each of the queried words: Retrieve from the dictionary at least one tag associated with the word.
21. An electronic device, characterized in that, include: Memory is used to store executable instructions for a computer; A processor, when executing computer-executable instructions stored in the memory, implements the method according to any one of claims 1 to 10.
22. A computer-readable storage medium storing computer-executable instructions or a computer program, characterized in that, When the computer-executable instructions or computer program are executed by a processor, they implement the method described in any one of claims 1 to 10.
23. A computer program product comprising computer-executable instructions or a computer program, characterized in that, When the computer-executable instructions or computer program are executed by a processor, they implement the method according to any one of claims 1 to 10.
Citation Information
Patent Citations
Chinese field text named entity recognition method fused with vocabulary category representation
CN115545033A
