A method and device for identifying named entities in sentences
By using attention function weighting to combine character vectors and word vectors in named entity recognition, the problem of not considering word weights in the existing technology is solved, the recognition accuracy and training efficiency are improved, and the training time is shortened.
Patent Information
- Application Number
- CN201910354890.9
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2019-04-29
- Publication Date
- 2024-10-29
- Estimated Expiration
- 2039-04-29
AI Technical Summary
When identifying named entities in a sentence, the existing technology does not consider the weight of each word relative to the entire sentence, resulting in a complex and time-consuming model training process.
The attention function is used to weightedly combine character vectors and word vectors, and a pre-trained recognition model is used to generate sentence feature vectors to determine the label of each word, including the name of a person, a place, and an organization.
The accuracy of named entity recognition is improved, the convergence speed of model training is accelerated, and the training time is shortened.
Smart Images

Figure CN111859964B_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to the technical field of machine learning and sentence processing, and in particular to a method and device for identifying named entities in sentences. Background Art
[0002] Named entity recognition (NER) is the basic work of some complex tasks in natural language processing (such as information extraction, question-answering system, and machine translation). It refers to finding named referential items from a natural language text and marking their positions and types. The existing technology is to use large-scale corpus to learn the annotation model based on traditional machine learning methods, so as to annotate each position of the sentence. Commonly used models applied to NER tasks mainly include generative model hidden Markov (HMM), discriminative model conditional random field (CRF), etc. The commonly used method at present is to manually define some binary feature functions to mine the composition characteristics of the named entity and the context. For a given position in a sentence, the extracted feature is a position, that is, the context position. And different feature templates can be combined to form a new feature template. Then, when extracting features from each position of the sentence, these features are input into CRF. Its objective function not only considers the input state feature function, but also includes the label transfer feature function. When the model is known, it is a dynamic programming problem to predict the output sequence for the input sequence, that is, to find the optimal sequence that maximizes the objective function. Viterbi algorithm is used for decoding.
[0003] However, the main disadvantage of traditional methods is that the training time complexity is very high, the convergence speed is slow, the training time is long, and sometimes even the training cost is unbearable. Although the morphological characteristics of words at the character level are taken into account, the splicing method is simple and crude, and it is difficult to flexibly adjust the weights between character features and word features according to the training data; in addition, the influence of the specific training data distribution on the character vector weight is not taken into account, and it is difficult to learn the distribution rules between characters.
[0004] In actual application, the inventors found that the existing method of identifying named entities in sentences did not consider the weight of each word as a named entity relative to other words in the entire sentence. This method of giving each word the same weight makes the model training process more complicated and time-consuming. Summary of the invention
[0005] An embodiment of the present invention provides a method and device for identifying named entities in a sentence, so as to solve the problem that the method for identifying named entities in a sentence in the prior art does not consider the weight of each word as a named entity relative to other words in the entire sentence. This method of assigning the same weight to each word makes the training process of the model more complicated and time-consuming.
[0006] In view of the above technical problems, an embodiment of the present invention provides a method for identifying named entities in a sentence, comprising:
[0007] For a target sentence to be subjected to named entity recognition, a character vector corresponding to each character obtained from the target sentence and a word vector corresponding to each word divided from the target sentence are obtained;
[0008] Inputting the character vector corresponding to each character and the word vector corresponding to each word into a pre-trained recognition model, and the recognition model outputs a label corresponding to each word indicating a word attribute;
[0009] Output the words belonging to the named entity in the target sentence according to the label corresponding to each word;
[0010] Among them, the recognition model generates a sentence feature vector corresponding to each word through an attention function based on the character vector and word vector of the input target sentence, and determines the label corresponding to each word by the sentence feature vector corresponding to each word; word attributes include personal nouns, place nouns and institutional nouns.
[0011] An embodiment of the present invention provides a device for identifying named entities in a sentence, comprising:
[0012] An acquisition module, for acquiring, for a target sentence to be subjected to named entity recognition, a character vector corresponding to each character obtained from the target sentence and a word vector corresponding to each word divided from the target sentence;
[0013] A recognition module, used for inputting the character vector corresponding to each character and the word vector corresponding to each word into a pre-trained recognition model, and the recognition model outputs a label corresponding to each word indicating a word attribute;
[0014] An output module, used for outputting the words belonging to the named entity in the target sentence according to the label corresponding to each word;
[0015] Among them, the recognition model generates a sentence feature vector corresponding to each word through an attention function based on the character vector and word vector of the input target sentence, and determines the label corresponding to each word by the sentence feature vector corresponding to each word; word attributes include personal nouns, place nouns and institutional nouns.
[0016] An embodiment of the present invention provides an electronic device, including a memory, a processor, and a computer program stored in the memory and executable on the processor, wherein the processor implements the steps of the method for identifying named entities in sentences described above when executing the program.
[0017] An embodiment of the present invention provides a non-transitory computer-readable storage medium having a computer program stored thereon. When the computer program is executed by a processor, the steps of the method for identifying named entities in a sentence described above are implemented.
[0018] The embodiment of the present invention provides a method and device for identifying named entities in a sentence. After obtaining the character vector and word vector of the target sentence, the character vector corresponding to each character and the word vector corresponding to each word are input into a pre-trained recognition model, and the recognition model outputs a label representing the word attribute corresponding to each word, and then outputs the words belonging to the named entities in the target sentence according to the label corresponding to each word. The recognition model performs weighted combination of the character vector and the word vector through the attention function, and the weight of each word as a named entity relative to other words in the entire sentence is extracted to extract useful information for named entity recognition, and weaken the influence of words in the sentence that do not belong to named entities on the model training process, which not only improves the accuracy of the trained recognition model in identifying named entities, but also accelerates the convergence speed of the model training process and shortens the training time. BRIEF DESCRIPTION OF THE DRAWINGS
[0019] In order to more clearly illustrate the embodiments of the present invention or the technical solutions in the prior art, the following briefly introduces the drawings required for use in the embodiments or the description of the prior art. Obviously, the drawings described below are some embodiments of the present invention. For ordinary technicians in this field, other drawings can be obtained based on these drawings without paying creative work.
[0020] Figure 1 It is a flowchart of a method for identifying named entities in a sentence provided by an embodiment of the present invention;
[0021] Figure 2 It is a schematic diagram of the principle of identifying named entities in a sentence provided by another embodiment of the present invention;
[0022] Figure 3 is a structural block diagram of a device for identifying named entities in a sentence provided by another embodiment of the present invention;
[0023] Figure 4 It is a structural block diagram of an electronic device provided by another embodiment of the present invention. DETAILED DESCRIPTION
[0024] In order to make the purpose, technical solution and advantages of the embodiments of the present invention clearer, the technical solution in the embodiments of the present invention will be clearly and completely described below in conjunction with the drawings in the embodiments of the present invention. Obviously, the described embodiments are part of the embodiments of the present invention, not all of the embodiments. Based on the embodiments of the present invention, all other embodiments obtained by ordinary technicians in this field without creative work are within the scope of protection of the present invention.
[0025] Figure 1 is a flowchart of a method for identifying named entities in a sentence provided by this embodiment, see Figure 1 , the method comprising:
[0026] 101: For a target sentence to be subjected to named entity recognition, obtain a character vector corresponding to each character obtained from the target sentence and a word vector corresponding to each word divided from the target sentence;
[0027] 102: Inputting the character vector corresponding to each character and the word vector corresponding to each word into a pre-trained recognition model, and the recognition model outputs a label corresponding to each word indicating a word attribute;
[0028] 103: Outputting the words belonging to the named entity in the target sentence according to the label corresponding to each word;
[0029] Among them, the recognition model generates a sentence feature vector corresponding to each word through an attention function based on the character vector and word vector of the input target sentence, and determines the label corresponding to each word by the sentence feature vector corresponding to each word; word attributes include personal nouns, place nouns and institutional nouns.
[0030] The method provided in this embodiment is executed by a device installed with software that executes the above steps. The device can be a server or a terminal, and this embodiment does not impose specific restrictions on this. The device processes the input target sentence, or processes the input article sentence by sentence, and extracts the named entities. For example, for a planned article, since the article title provided by the contributors may not reflect the key content of the article, a sentence indicating the relationship between the named entities can be regenerated based on the named entities extracted by the above method, and the sentence is used as a descriptive sentence for the article. A corresponding relationship between the descriptive sentence and the article is established in the search library of a search engine, so as to realize a quick search for the article through the descriptive sentence or the named entities extracted from the article.
[0031] Furthermore, it also includes: generating a new sentence through the output named entity, using the new sentence as a descriptive sentence for searching the target sentence, storing the correspondence between the descriptive sentence and the target sentence, so as to search the target sentence through the descriptive sentence or the named entity output by the recognition model.
[0032] The character vector corresponding to each character in the target sentence can be obtained through a pre-trained model, or generated through a pre-stored mapping relationship between characters and character vectors. The word vector corresponding to each word in the target sentence can be obtained by dividing the words in the target sentence through a pre-trained model and then generating the word vector corresponding to each word, or the target sentence can be divided into words in advance according to a certain set word segmentation standard, and then generated according to a pre-stored mapping relationship between words and word vectors. The recognition model is a trained model that outputs labels corresponding to each word representing word attributes based on the input character vector and word vector. Word attributes include personal nouns, place nouns, and institutional nouns, or verbs, adjectives, etc.
[0033] This embodiment provides a method for identifying named entities in a sentence. After obtaining the character vector and word vector of the target sentence, the character vector corresponding to each character and the word vector corresponding to each word are input into a pre-trained recognition model. The recognition model outputs a label representing the word attribute corresponding to each word, and then outputs the words belonging to the named entities in the target sentence according to the label corresponding to each word. The recognition model performs weighted combination of the character vector and the word vector through the attention function, and the weight of each word as a named entity relative to other words in the entire sentence is extracted to extract useful information for named entity recognition, and weaken the influence of words in the sentence that do not belong to named entities on the model training process, which not only improves the accuracy of the trained recognition model in identifying named entities, but also accelerates the convergence speed of the model training process and shortens the training time.
[0034] Further, based on the above embodiment, the training of the recognition model includes:
[0035] Obtain several sample sentences, for each sample sentence, pre-divide the words in the sample sentence, obtain the character vector corresponding to each character and the word vector corresponding to each word in the sample sentence, and add a label representing the word attribute to each divided word, use the character vector corresponding to each character and the word vector corresponding to each word in the sample sentence as input parameters of a recurrent neural network, use the label corresponding to each word of the sample sentence as the expected output, train the recurrent neural network, and obtain the recognition model;
[0036] Among them, in the process of training the recurrent neural network, the recurrent neural network generates a sentence feature vector corresponding to each word through an attention function based on the input character vector and word vector, and determines the label corresponding to each word by the sentence feature vector corresponding to each word.
[0037] Further, on the basis of the above embodiments, in the process of training the recurrent neural network, the recurrent neural network generates a sentence feature vector corresponding to each word through an attention function according to the input character vector and word vector, and determines a label corresponding to each word by the sentence feature vector corresponding to each word, including:
[0038] In the process of training the recurrent neural network, the recurrent neural network is trained by the formula Z t =σ[w3*tanh(w1*X t +w2*m t )] and X′ t =Z t *X t +(1-Z t )*m t Calculate the sentence feature vector corresponding to each word;
[0039] Determine the probability that the word attribute of the word is each preset label through a conditional random field based on the sentence feature vector corresponding to each word, and use the probability that the word attribute of the word is each preset label as the output of the recognition model;
[0040] The recurrent neural network is a bidirectional long short-term memory network, w1, w2 and w3 are parameter values of the attention function, y=σ(x) is a sigmoid function, and for any word, X t is the word vector of the word input into the recurrent neural network at time t, m t is the character vector of the word input into the recurrent neural network at time t, Z t is the weight corresponding to the word, X′ t is the sentence feature vector corresponding to the word.
[0041] The process of training the recognition model is actually the process of adjusting the parameters w1, w2 and w3 of the attention function in the hidden layer of the bidirectional long short-term memory network (LSTM) so that the attention function (i.e. Z t =σ[w3*tanh(w1*X t +w2*m t )] and X′ t =Z t *X t +(1-Z t )*mt ) The sentence feature vector X′ generated t It is the result of weighted concatenation of the word vector and character vector. During the training process, it can quickly adjust the output sentence feature vector through weights, quickly narrow the difference between the actual output and the expected output of the trained model, and obtain a recognition model with higher recognition accuracy.
[0042] During the training process, after the sentence feature vector is generated by the attention function, the label corresponding to each sentence feature vector is determined by the conditional random field (CRF). Further, the method provided in this embodiment calculates the probability that the word attribute of each word is each preset label through a greedy algorithm.
[0043] This embodiment provides a method for identifying named entities in a sentence, generates a sentence feature vector by weighted concatenation in an attention function, accelerates the convergence speed of model training, and improves training efficiency. The label corresponding to a word is determined by a greedy algorithm, so that when determining a word label, the possibility of it being each preset label can be considered.
[0044] Further, on the basis of the above embodiments, for each sample sentence, the words in the sample sentence are pre-divided, the character vector corresponding to each character and the word vector corresponding to each word in the sample sentence are obtained, and a label representing the word attribute is added to each divided word, the character vector corresponding to each character and the word vector corresponding to each word in the sample sentence are used as input parameters of the recurrent neural network, and the label corresponding to each word of the sample sentence is used as the expected output, and the recurrent neural network is trained, including:
[0045] For each sample sentence, the sample sentence is input into a pre-trained character segmentation model to obtain a character vector corresponding to each character in the sample sentence, the sample sentence is input into a pre-trained word segmentation model to obtain a word vector corresponding to each word in the sample sentence, and the character vector obtained by the character segmentation model and the word vector obtained by the word segmentation model are used as input parameters of a recurrent neural network;
[0046] The words in the sample sentence are divided in advance according to the set word segmentation standard, a label representing the word attribute is added to each word divided according to the set word segmentation standard, each word divided according to the set word segmentation standard and the label corresponding to each word are used as the expected output to train the recurrent neural network.
[0047] The character segmentation model is a model obtained by training the convolutional neural network (CNN), and the word segmentation model is a model obtained by training word2vec. The word segmentation standard is set to be a standard for dividing words in a sentence that is determined manually. For example, the words in the sample sentence are divided manually by the set word segmentation standard, and a label is added to each word as the expected output.
[0048] The convolution layer in the convolutional neural network can well describe the local features of the data, and the most representative part of the local features can be further extracted through the pooling layer. Therefore, the present invention uses CNN to extract the character-level features in the sentence. The structure of CNN mainly consists of a character vector table, a convolution layer, and a pooling layer. The character vector table converts a word into a character vector, which is passed into the CNN structure to extract the features of the word. The character vector table is continuously updated through the back propagation algorithm during the model training process. The convolution layer uses a convolution kernel of size T to convolve on the character vector matrix of the word to extract local features. The convolution kernel size T determines that the features of T words around the word can be extracted, and finally the character-level feature vector is obtained through the pooling layer.
[0049] Figure 2 For a schematic diagram of the principle of identifying named entities in a sentence provided in this embodiment, see Figure 2 For the target sentence, it is input into the character segmentation model to obtain the character vector, and then into the word segmentation model to obtain the word vector. The character vector and word vector are input into the trained recognition model. The bidirectional long short-term memory network (LSTM) in the recognition model generates the sentence feature vector corresponding to the word through the attention function, and generates the label corresponding to each word through CRF.
[0050] This embodiment provides a method for identifying named entities in a sentence. During the training process, character vectors and word vectors are generated through a character segmentation model and a word segmentation model, thereby realizing rapid vectorization of the sentence.
[0051] Furthermore, based on the above embodiments, it also includes:
[0052] After the number of training times exceeds the preset number of training times, if the difference between the actual output of the current model obtained by training the recurrent neural network and the expected output is greater than the preset difference, the parameters in the word segmentation model and the character segmentation model are adjusted until the difference between the actual output of the current model and the expected output is less than or equal to the preset difference after the word vector obtained by the adjusted word segmentation model and the character vector obtained by the character segmentation model are input into the current model, and the current model is used as the recognition model, and the word vector output by the adjusted word segmentation model and the character vector output by the adjusted character segmentation model are used as input parameters of the recognition model;
[0053] If there are words in the actual output that are inconsistent with the expected output, the difference between the actual output and the expected output is greater than the preset difference.
[0054] It should be noted that there may be a situation where the word vector output by the word segmentation model or the character vector output by the character segmentation model is different from the word vector and character vector obtained by setting the word segmentation standard above. In this case, the word segmentation model and the character segmentation model need to be trained to ensure that when the word segmentation model, the character segmentation model and the recognition model are used together, the correct labels can be output.
[0055] This embodiment provides a method for identifying named entities in a sentence, by training a word segmentation model and a character segmentation model, ensuring that the character vector and word vector input to the recognition model can output the correct label after passing through the recognition model. While providing a method for quickly generating character vectors and word vectors, the accuracy of the output results when the word segmentation model, the character segmentation model and the recognition model are used in combination is improved.
[0056] Further, based on the above embodiments, outputting the words belonging to the named entity in the target sentence according to the label corresponding to each word includes:
[0057] For each word, obtain the probability that the word attribute of the word output by the recognition model is each preset label, and determine in each preset label whether there is a preset label that is a named entity and the corresponding probability is greater than the preset probability. If so, the word belongs to the named entity, and output all the words in the target sentence that belong to the named entity.
[0058] The recognition model trained by the above method outputs the probability of each word being each preset label for each word. When outputting words belonging to named entities, the probability corresponding to each label output by the recognition model is determined. The preset probability is a set value, for example, 50%.
[0059] This embodiment provides a method for identifying named entities in a sentence. For each word, if there is a preset tag that is a named entity and the probability is greater than a preset probability among the preset tags, then the word belongs to the named entity.
[0060] Further, based on the above embodiments, the character vector corresponding to each character obtained according to the target sentence and the word vector corresponding to each word divided from the target sentence include:
[0061] The target sentence is input into the character segmentation model to obtain a character vector, the target sentence is input into the word segmentation model to obtain a word segmentation vector, and the character vector output by the character segmentation model and the word segmentation vector output by the word segmentation model are used as the character vector and word vector input into the recognition model.
[0062] The character segmentation model and word segmentation model are trained by the above method. When performing named entity recognition on the target sentence, the character segmentation model, word segmentation model and recognition model can be used together, which can not only quickly obtain the character vector and word vector of the target sentence, but also quickly identify the named entities in the target sentence.
[0063] Specifically, the method provided in this embodiment combines LSTM and CRF to perform named entity recognition in Chinese. The model training process generally includes: (1) preprocessing the training data to obtain the character vector of the sentence through character-level mapping; (2) inputting the character vector obtained in step (1) into the CNN network to obtain the word vector representation of each word; (3) obtaining the word vector representation through the word2vec model; (4) concatenating the word vector representation obtained in step (3) and the character vector representation obtained in step (2) through the attention mechanism, and passing them into the bidirectional LSTM neural network to obtain the semantic feature vector of the sentence; (5) for the semantic feature vector obtained in step (4), using the conditional random field to perform entity annotation on each word and decode the entity label.
[0064] For the above step (1), the training data is split into characters one by one, and the characters and labels are counted to obtain the character table C and the label table L. The character vector representation of the sentence is obtained through character-level embedding mapping. Let d c For each character vector, n is the dimension c The length of the sentence decomposed into characters includes spaces, so the obtained sentence expression S c ∈R nc x dc .
[0065] For the above step (2), the character vector representation S obtained in step (1) is c Enter the CNN network.
[0066] For the above step (3), the pre-trained word vector is initialized as a mapping matrix, and the word vector is trained through the word2vec model. The Chinese corpus is used for training. The corpus is first segmented. The jieba tool is used for segmentation. Let d w is the dimension of each character vector, n is the length of the sentence after being decomposed into words, and the word vector representation of the sentence is obtained through word-level embedding mapping. In order to solve the problem of different word vector representations caused by different word lengths, the longest word is used as the standard, and placeholders are added in the blanks of the word to make the word vector representation length of all words consistent.
[0067] For the above step (4), let X t and m tRepresent the word vector representation and character vector representation of the input at time t respectively. By constructing the attention function, the weighted concatenation of the character vector and the word vector is realized to obtain the sentence feature vector. The obtained sentence feature vector is input into a bidirectional LSTM network. Among them, the long short-term memory network (LSTM) is a special recurrent neural network (RNN) model, which overcomes the problem of gradient diffusion caused by the long sequence of the traditional RNN model. Using a bidirectional LSTM network, starting from the first word, recursing from left to right and starting from the last word, recursing from right to left, can effectively utilize the context information, and the obtained hidden layer output H = {h1, h2, h3, h4..., hn} (n is the number of words contained in the input sentence) is the sentence feature vector of the sentence.
[0068] For the above step (5), the output sequence H = {h1, h2, h3, h4..., hn} obtained in step (4) is used as the input of the CRF layer. Let y = {y1, y2, y3, y4..., yn} represent the possible output labels of the CRF layer. The modified Viterbi algorithm is used to solve the CRF parameters and select the best label sequence from the learning results. When selecting a sequence, a threshold value of the probability value of the selected sequence is set, and this threshold is used to determine whether it is the optimal result. If it exceeds the threshold, it is considered to be the optimal result. If it does not exceed the threshold, the improved greedy algorithm is used to re-label it and re-select the result. The improved greedy algorithm is to find the segmentation result by obtaining the path with the largest weight. The longer the selected word, the less frequent it appears than the shorter word.
[0069] It should be noted that in the training phase, the optimizer uses Adam, the learning rate is 0.001, and Dropout is added to the input and output parts of the bidirectional LSTM to reduce overfitting, and the dropout is selected as 0.7. In the test phase, the formula y*=argmax is used y ∈YH s(H,y’) Find the sequence with the highest conditional probability from all possible label sequences and label it.
[0070] The method provided in this implementation uses a convolutional neural network to extract word vector features, increasing the number of features. The word vector and the word vector are weighted and combined through the attention mechanism to extract useful information for the NER tagging task, speeding up the convergence of training and improving the accuracy of named entity recognition.
[0071] Figure 3 FIG. 1 shows a structural block diagram of a device for identifying named entities in a sentence provided by an embodiment of the present invention. Figure 3 The present embodiment provides a device for identifying named entities in a sentence, comprising an acquisition module 301, a recognition module 302 and an output module 303, wherein:
[0072] An acquisition module 301 is used to acquire, for a target sentence to be subjected to named entity recognition, a character vector corresponding to each character obtained from the target sentence and a word vector corresponding to each word divided from the target sentence;
[0073] A recognition module 302, used for inputting the character vector corresponding to each character and the word vector corresponding to each word into a pre-trained recognition model, and the recognition model outputs a label corresponding to each word indicating a word attribute;
[0074] An output module 303, configured to output the words belonging to the named entity in the target sentence according to the label corresponding to each word;
[0075] Among them, the recognition model generates a sentence feature vector corresponding to each word through an attention function based on the character vector and word vector of the input target sentence, and determines the label corresponding to each word by the sentence feature vector corresponding to each word; word attributes include personal nouns, place nouns and institutional nouns.
[0076] The apparatus for identifying named entities in a sentence provided in this embodiment is applicable to the method for identifying named entities in a sentence provided in the above embodiments, which will not be described in detail here.
[0077] An embodiment of the present invention provides a device for identifying named entities in a sentence. After obtaining the character vector and word vector of the target sentence, the character vector corresponding to each character and the word vector corresponding to each word are input into a pre-trained recognition model, and the recognition model outputs a label representing the word attribute corresponding to each word, and then outputs the words belonging to the named entities in the target sentence according to the label corresponding to each word. The recognition model performs weighted combination of the character vector and the word vector through the attention function, and the weight of each word as a named entity relative to other words in the entire sentence is extracted to extract useful information for named entity recognition, and weaken the influence of words in the sentence that do not belong to named entities on the model training process, which not only improves the accuracy of the trained recognition model in identifying named entities, but also accelerates the convergence speed of the model training process and shortens the training time.
[0078] Figure 4 It is a block diagram showing the structure of the electronic device provided by this embodiment.
[0079] Reference Figure 4, the electronic device includes: a processor (processor) 410, a communication interface (CommunicationsInterface) 420, a memory (memory) 430 and a communication bus 440, wherein the processor 410, the communication interface 420, and the memory 430 communicate with each other through the communication bus 440. The processor 410 can call the logic instructions in the memory 430 to execute the following method: for the target sentence to be recognized as a named entity, obtain the character vector corresponding to each character obtained according to the target sentence and the word vector corresponding to each word divided from the target sentence; input the character vector corresponding to each character and the word vector corresponding to each word into a pre-trained recognition model, and the recognition model outputs a label representing the word attribute corresponding to each word; output the words belonging to the named entity in the target sentence according to the label corresponding to each word; wherein the recognition model generates a sentence feature vector corresponding to each word through an attention function according to the input character vector and word vector of the target sentence, and determines the label corresponding to each word according to the sentence feature vector corresponding to each word; the word attribute includes person nouns, place nouns and organization nouns.
[0080] In addition, the logic instructions in the above-mentioned memory 430 can be implemented in the form of a software functional unit and can be stored in a computer-readable storage medium when it is sold or used as an independent product. Based on such an understanding, the technical solution of the present invention, in essence, or the part that contributes to the prior art or the part of the technical solution, can be embodied in the form of a software product, and the computer software product is stored in a storage medium, including a number of instructions for a computer device (which can be a personal computer, a server, or a network device, etc.) to perform all or part of the steps of the method described in each embodiment of the present invention. The aforementioned storage medium includes: U disk, mobile hard disk, read-only memory (ROM, Read-Only Memory), random access memory (RAM, Random Access Memory), disk or optical disk and other media that can store program codes.
[0081] The present embodiment provides a non-transitory computer-readable storage medium having a computer program stored thereon, the computer program being executed by a processor in the following method: for a target sentence to be subjected to named entity recognition, obtaining a character vector corresponding to each character obtained from the target sentence and a word vector corresponding to each word divided from the target sentence; inputting the character vector corresponding to each character and the word vector corresponding to each word into a pre-trained recognition model, and having the recognition model output a label representing a word attribute corresponding to each word; outputting words belonging to the named entity in the target sentence according to the label corresponding to each word; wherein the recognition model generates a sentence feature vector corresponding to each word through an attention function based on the input character vector and word vector of the target sentence, and determining a label corresponding to each word according to the sentence feature vector corresponding to each word; word attributes include personal nouns, place nouns, and institutional nouns.
[0082] The present embodiment discloses a computer program product, which includes a computer program stored on a non-transitory computer-readable storage medium, and the computer program includes program instructions. When the program instructions are executed by a computer, the computer can execute the methods provided by the above-mentioned method embodiments, for example, including: for a target sentence to be subjected to named entity recognition, obtaining a character vector corresponding to each character obtained according to the target sentence and a word vector corresponding to each word divided from the target sentence; inputting the character vector corresponding to each character and the word vector corresponding to each word into a pre-trained recognition model, and the recognition model outputs a label representing a word attribute corresponding to each word; outputting words belonging to the named entity in the target sentence according to the label corresponding to each word; wherein the recognition model generates a sentence feature vector corresponding to each word through an attention function based on the input character vector and word vector of the target sentence, and determines the label corresponding to each word according to the sentence feature vector corresponding to each word; word attributes include personal nouns, place nouns, and institutional nouns.
[0083] The electronic device and other embodiments described above are merely illustrative, wherein the units described as separate components may or may not be physically separated, and the components displayed as units may or may not be physical units, that is, they may be located in one place, or they may be distributed on multiple network units. Some or all of the modules may be selected according to actual needs to achieve the purpose of the scheme of this embodiment. Ordinary technicians in this field can understand and implement it without creative work.
[0084] Through the description of the above implementation methods, those skilled in the art can clearly understand that each implementation method can be implemented by means of software plus a necessary general hardware platform, and of course, it can also be implemented by hardware. Based on this understanding, the above technical solution is essentially or the part that contributes to the prior art can be embodied in the form of a software product, and the computer software product can be stored in a computer-readable storage medium, such as ROM / RAM, a disk, an optical disk, etc., including a number of instructions for a computer device (which can be a personal computer, a server, or a network device, etc.) to execute the methods described in each embodiment or some parts of the embodiments.
[0085] Finally, it should be noted that the above embodiments are only used to illustrate the technical solutions of the embodiments of the present invention, rather than to limit them. Although the embodiments of the present invention have been described in detail with reference to the aforementioned embodiments, those skilled in the art should understand that they can still modify the technical solutions described in the aforementioned embodiments, or replace some or all of the technical features therein with equivalents. However, these modifications or replacements do not cause the essence of the corresponding technical solutions to deviate from the scope of the technical solutions of the embodiments of the present invention.
Claims
1. A method for identifying named entities in sentences, It is characterized in that include: For a target sentence to be subjected to named entity recognition, a character vector corresponding to each character obtained from the target sentence and a word vector corresponding to each word divided from the target sentence are obtained; Inputting the character vector corresponding to each character and the word vector corresponding to each word into a pre-trained recognition model, and the recognition model outputs a label corresponding to each word indicating a word attribute; Output the words belonging to the named entity in the target sentence according to the label corresponding to each word; The recognition model generates a sentence feature vector corresponding to each word through an attention function according to the character vector and word vector of the input target sentence, and determines the label corresponding to each word by the sentence feature vector corresponding to each word; the word attributes include person nouns, place nouns and organization nouns; The training of the recognition model includes: Obtain several sample sentences, for each sample sentence, pre-divide the words in the sample sentence, obtain the character vector corresponding to each character and the word vector corresponding to each word in the sample sentence, and add a label representing the word attribute to each divided word, use the character vector corresponding to each character and the word vector corresponding to each word in the sample sentence as input parameters of a recurrent neural network, use the label corresponding to each word of the sample sentence as the expected output, train the recurrent neural network, and obtain the recognition model; Wherein, in the process of training the recurrent neural network, the recurrent neural network generates a sentence feature vector corresponding to each word through an attention function according to the input character vector and word vector, and determines the label corresponding to each word by the sentence feature vector corresponding to each word; In the process of training the recurrent neural network, the recurrent neural network generates a sentence feature vector corresponding to each word through an attention function according to the input character vector and word vector, and determines a label corresponding to each word by the sentence feature vector corresponding to each word, including: In the process of training the recurrent neural network, the recurrent neural network is trained by the formula Z t =σ[w 3 *tanh(w 1 *X t +w 2 *m t )] and X t '=Z t *X t +(1-Z t )*m t Calculate the sentence feature vector corresponding to each word; Determine the probability that the word attribute of the word is each preset label through a conditional random field based on the sentence feature vector corresponding to each word, and use the probability that the word attribute of the word is each preset label as the output of the recognition model; Wherein, the recurrent neural network is a bidirectional long short-term memory network, w 1 、w 2 and w 3 is the parameter value of the attention function, y=σ(x) is the sigmoid function, for any word, X t is the word vector of the word input into the recurrent neural network at time t, m t is the character vector of the word input into the recurrent neural network at time t, Z t is the weight corresponding to the word, X' t is the sentence feature vector corresponding to the word; For each sample sentence, words in the sample sentence are pre-divided, a character vector corresponding to each character and a word vector corresponding to each word in the sample sentence are obtained, and a label indicating a word attribute is added to each divided word, and the character vector corresponding to each character and the word vector corresponding to each word in the sample sentence are used as input parameters of a recurrent neural network, and the label corresponding to each word in the sample sentence is used as an expected output, and the recurrent neural network is trained, including: for each sample sentence, the sample sentence is input into a pre-trained character segmentation model to obtain a character vector corresponding to each character in the sample sentence, the sample sentence is input into a pre-trained word segmentation model to obtain a word vector corresponding to each word in the sample sentence, and the character vector obtained by the character segmentation model and the word vector obtained by the word segmentation model are used as input parameters of the recurrent neural network; the character segmentation model is a model obtained by training a convolutional neural network CNN; the word segmentation model is a model obtained by training word2vec; The words in the sample sentence are divided in advance according to the set word segmentation standard, a label representing the word attribute is added to each word divided according to the set word segmentation standard, each word divided according to the set word segmentation standard and the label corresponding to each word are used as the expected output, and the recurrent neural network is trained.
2. The method for identifying named entities in a sentence according to claim 1, It is characterized in that Also includes: After the number of training times exceeds the preset number of training times, if the difference between the actual output of the current model obtained by training the recurrent neural network and the expected output is greater than the preset difference, the parameters in the word segmentation model and the character segmentation model are adjusted until the difference between the actual output of the current model and the expected output is less than or equal to the preset difference after the word vector obtained by the adjusted word segmentation model and the character vector obtained by the character segmentation model are input into the current model, and the current model is used as the recognition model, and the word vector output by the adjusted word segmentation model and the character vector output by the adjusted character segmentation model are used as input parameters of the recognition model; If there are words in the actual output that are inconsistent with the expected output, the difference between the actual output and the expected output is greater than the preset difference.
3. The method for identifying named entities in a sentence according to claim 1, It is characterized in that The step of outputting the words belonging to the named entity in the target sentence according to the label corresponding to each word includes: For each word, obtain the probability that the word attribute of the word output by the recognition model is each preset label, and determine in each preset label whether there is a preset label that is a named entity and the corresponding probability is greater than the preset probability. If so, the word belongs to the named entity, and output all the words in the target sentence that belong to the named entity.
4. The method for identifying named entities in a sentence according to claim 2, It is characterized in that The character vector corresponding to each character obtained according to the target sentence and the word vector corresponding to each word divided from the target sentence include: The target sentence is input into the character segmentation model to obtain a character vector, the target sentence is input into the word segmentation model to obtain a word segmentation vector, and the character vector output by the character segmentation model and the word segmentation vector output by the word segmentation model are used as the character vector and word vector input into the recognition model.
5. A device for identifying named entities in a sentence, It is characterized in that include: An acquisition module, for acquiring, for a target sentence to be subjected to named entity recognition, a character vector corresponding to each character obtained from the target sentence and a word vector corresponding to each word divided from the target sentence; A recognition module, used for inputting the character vector corresponding to each character and the word vector corresponding to each word into a pre-trained recognition model, and the recognition model outputs a label corresponding to each word indicating a word attribute; An output module, used for outputting the words belonging to the named entity in the target sentence according to the label corresponding to each word; The recognition model generates a sentence feature vector corresponding to each word through an attention function according to the character vector and word vector of the input target sentence, and determines the label corresponding to each word by the sentence feature vector corresponding to each word; the word attributes include person nouns, place nouns and organization nouns; The training of the recognition model includes: Obtain several sample sentences, for each sample sentence, pre-divide the words in the sample sentence, obtain the character vector corresponding to each character and the word vector corresponding to each word in the sample sentence, and add a label representing the word attribute to each divided word, use the character vector corresponding to each character and the word vector corresponding to each word in the sample sentence as input parameters of a recurrent neural network, use the label corresponding to each word of the sample sentence as the expected output, train the recurrent neural network, and obtain the recognition model; Wherein, in the process of training the recurrent neural network, the recurrent neural network generates a sentence feature vector corresponding to each word through an attention function according to the input character vector and word vector, and determines the label corresponding to each word by the sentence feature vector corresponding to each word; In the process of training the recurrent neural network, the recurrent neural network generates a sentence feature vector corresponding to each word through an attention function according to the input character vector and word vector, and determines a label corresponding to each word by the sentence feature vector corresponding to each word, including: In the process of training the recurrent neural network, the recurrent neural network is trained by the formula Z t =σ[w 3 *tanh(w 1 *X t +w 2 *m t )] and X' t =Z t *X t +(1-Z t )*m t Calculate the sentence feature vector corresponding to each word; Determine the probability that the word attribute of the word is each preset label through a conditional random field based on the sentence feature vector corresponding to each word, and use the probability that the word attribute of the word is each preset label as the output of the recognition model; Wherein, the recurrent neural network is a bidirectional long short-term memory network, w 1 、w 2 and w 3 is the parameter value of the attention function, y=σ(x) is the sigmoid function, for any word, X t is the word vector of the word input into the recurrent neural network at time t, m t is the character vector of the word input into the recurrent neural network at time t, Z t is the weight corresponding to the word, X' t is the sentence feature vector corresponding to the word; For each sample sentence, words in the sample sentence are pre-divided, a character vector corresponding to each character and a word vector corresponding to each word in the sample sentence are obtained, and a label indicating a word attribute is added to each divided word, and the character vector corresponding to each character and the word vector corresponding to each word in the sample sentence are used as input parameters of a recurrent neural network, and the label corresponding to each word in the sample sentence is used as an expected output, and the recurrent neural network is trained, including: for each sample sentence, the sample sentence is input into a pre-trained character segmentation model to obtain a character vector corresponding to each character in the sample sentence, the sample sentence is input into a pre-trained word segmentation model to obtain a word vector corresponding to each word in the sample sentence, and the character vector obtained by the character segmentation model and the word vector obtained by the word segmentation model are used as input parameters of the recurrent neural network; the character segmentation model is a model obtained by training a convolutional neural network CNN; the word segmentation model is a model obtained by training word2vec; The words in the sample sentence are divided in advance according to the set word segmentation standard, a label representing the word attribute is added to each word divided according to the set word segmentation standard, each word divided according to the set word segmentation standard and the label corresponding to each word are used as the expected output, and the recurrent neural network is trained.
6. An electronic device comprising a memory, a processor, and a computer program stored in the memory and executable on the processor, It is characterized in that When the processor executes the program, the steps of the method for identifying named entities in a sentence as described in any one of claims 1 to 4 are implemented.
7. A non-transitory computer-readable storage medium having a computer program stored thereon, It is characterized in that When the computer program is executed by a processor, the steps of the method for identifying named entities in a sentence as described in any one of claims 1 to 4 are implemented.
Citation Information
Patent Citations
Named entity identification method capable of combining attention mechanism and multi-target cooperative training
CN108628823A
