A named entity recognition method, terminal, and storage medium
By training a feature extraction model and a named entity extraction network, the problem of needing specific vocabulary for voice control of home appliances was solved, realizing the recognition of speech semantics and the execution of operations, thus improving the user experience.
Patent Information
- Application Number
- CN202011637550.6
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2020-12-31
- Publication Date
- 2025-12-02
- Estimated Expiration
- 2040-12-31
AI Technical Summary
Current home appliance voice control requires users to say specific words, but it cannot recognize the semantics of the user's voice, resulting in inconvenience.
By training a feature extraction model and a named entity extraction network, the target feature vector of the text is extracted and named entities are identified, thereby achieving an understanding of speech semantics and allowing users to issue voice control terminal commands that are not limited to specific words.
This enables the terminal to recognize the semantics of speech and perform corresponding operations, making it more convenient for users.
Smart Images

Figure CN114692633B_ABST
Abstract
Description
Technical Field
[0001] This invention relates to the field of natural language processing technology, and in particular to a named entity recognition method, terminal, and storage medium. Background Technology
[0002] Currently, many home appliances support voice control. However, in existing technology, voice control of home appliances relies on pre-stored specific words. It determines whether a response is needed by recognizing the presence of specific words in the user's voice, such as requiring the user to say "turn on," "turn off," or "raise the temperature." It cannot recognize the semantics of the user's voice and thus execute the corresponding operation, making it inconvenient for users. Therefore, existing technology needs improvement and enhancement. Summary of the Invention
[0003] To address the aforementioned shortcomings of existing technologies, a named entity recognition method, terminal, and storage medium are provided, aiming to solve the problem of inconvenience in using existing voice control terminals where specific words need to be spoken.
[0004] A first aspect of the present invention provides a named entity recognition method, comprising:
[0005] The target text is input into a trained feature extraction model, and the target feature vector of the target text is extracted by the feature extraction model.
[0006] The target feature vector is input into a trained named entity extraction network to obtain the named entity recognition result output by the named entity extraction network.
[0007] The named entity recognition method, wherein extracting the target feature vector of the target text through the feature extraction model includes:
[0008] In the feature extraction model:
[0009] Obtain the position embedding vector of the target text and the initial feature vector of the target text;
[0010] The target feature vector of the target text is obtained based on the location embedding vector and the initial feature vector.
[0011] The named entity recognition method, wherein obtaining the position embedding vector of the target text includes:
[0012] Based on the relative positions of each word in the target text with other words;
[0013] The position embedding vector of the target text is obtained by finding the vector corresponding to each relative position in the position embedding matrix.
[0014] The named entity recognition method, wherein obtaining the initial feature vector of the target text includes:
[0015] The initial feature vector is obtained by finding the word embedding vector corresponding to each word of the target text in the word embedding matrix.
[0016] The named entity recognition method, wherein the feature extraction model includes at least one feature extraction module connected in sequence; the step of obtaining the target feature vector of the target text based on the position embedding vector and the initial feature vector includes:
[0017] The feature vector output by the last feature extraction module is used as the target feature vector.
[0018] In each of the feature extraction modules:
[0019] The initial self-attention calculation vector is obtained based on the feature vector output by the feature extraction module described above;
[0020] The position embedding vector and the self-attention calculation vector are used to obtain the feature matrix;
[0021] Obtain the target self-attention calculation vector at each position in the target text from the feature matrix;
[0022] After calculating the self-attention based on the target self-attention calculation vector, the feature vector of the target text is output.
[0023] Specifically, in the first feature extraction module, the initial self-attention calculation vector is obtained based on the initial feature vector.
[0024] The named entity recognition method, wherein obtaining the target self-attention calculation vector at each position in the target text from the feature matrix based on the relative position of each word in the target text with other words includes:
[0025] Obtain the relative position of the target location with respect to all locations in the target text, and select the corresponding data in the feature matrix based on the relative position to obtain the target self-attention calculation vector of the target location.
[0026] The named entity recognition method, wherein the feature extraction model is trained based on multiple sets of first training data, each set of first training data includes a first sample text and a second sample text corresponding to the first sample text, the first sample text is obtained by randomly masking words in the second sample text, each second sample text includes characters from at least two languages, and the semantics of the characters from each language in each second sample text are consistent.
[0027] The named entity recognition method, wherein the named entity extraction network is trained based on multiple sets of second training data, each set of second training data including the target feature vector of the third sample text and the named entity annotation result corresponding to the third sample text, wherein the target feature vector of the third sample text is obtained through the trained feature extraction model, and the text in the third sample text is the target language, which is one of the languages included in the second sample text.
[0028] In the named entity recognition method, the named entity extraction network is a pointer network.
[0029] In a second aspect, the present invention provides a terminal comprising: a processor and a storage medium communicatively connected to the processor, the storage medium being adapted to store a plurality of instructions, and the processor being adapted to invoke the instructions in the storage medium to execute steps implementing the named entity recognition method described in any of the preceding claims.
[0030] A third aspect of the present invention provides a computer-readable storage medium storing one or more programs that can be executed by one or more processors to implement the steps of the named entity recognition method described in any of the preceding claims.
[0031] Beneficial effects: Compared with the prior art, the present invention provides a named entity recognition method, terminal and storage medium. The named entity recognition method provided by the present invention pre-trains a feature extraction model and a named entity extraction network. The feature extraction model extracts the target feature vector in the text, and the named entity extraction network outputs the named entity recognition result of the target text based on the target feature vector. This allows the terminal to further recognize the semantics of the target text and perform corresponding operations based on the named entity recognition result. Users can control the terminal by uttering voice commands that are not limited to specific words, making it more convenient to use. Attached Figure Description
[0032] Figure 1 A flowchart illustrating an embodiment of the named entity recognition method provided by the present invention;
[0033] Figure 2 A schematic diagram of the feature extraction model in an embodiment of the named entity recognition method provided by the present invention;
[0034] Figure 3 A schematic diagram of the feature extraction model in an embodiment of the named entity recognition method provided by the present invention;
[0035] Figure 4 A schematic diagram of the structure of an embodiment of the terminal provided by the present invention. Detailed Implementation
[0036] To make the objectives, technical solutions, and effects of this invention clearer and more explicit, the invention will be further described in detail below with reference to the accompanying drawings and embodiments. It should be understood that the specific embodiments described herein are merely illustrative of the invention and are not intended to limit the invention.
[0037] This invention provides a named entity recognition method that can be applied to terminals, including but not limited to various personal computers, laptops, mobile phones, tablets, in-vehicle computers, and portable wearable devices. After acquiring target text, the terminal can identify the named entities in the target text using the named entity recognition method provided by this invention.
[0038] Example 1
[0039] like Figure 1 As shown, the named entity recognition method provided by this invention includes the following steps:
[0040] S100. Input the target text into the trained feature extraction model, and extract the target feature vector of the target text through the feature extraction model.
[0041] Specifically, the target text can be text converted from the user's voice used to control the terminal. After receiving the user's voice and converting it into the target text, the terminal identifies the named entities within it using the named entity recognition method provided in this embodiment. Named entities are people's names, organization names, place names, and all other entities identified by names. More broadly, entities also include numbers, dates, currencies, addresses, etc. Named entity recognition (NER) is a fundamental task in natural language processing. After extracting the named entities from the target text, semantic recognition can be achieved based on the extracted named entities.
[0042] After obtaining the target text, it is input into a trained feature extraction model. In this embodiment, the feature extraction model is trained based on multiple sets of first training data. Each set of first training data includes a first sample text and a second sample text corresponding to the first sample text. The first sample text is obtained by randomly masking words in the second sample text. Each second sample text includes characters from at least two languages, and the semantics of the characters in each language in each second sample text are consistent. It is worth noting that the semantic consistency of the characters in each language in each second sample text can mean that the characters have completely identical or similar meanings. The second sample text can be generated by combining translation corpora, that is, the characters in each language in the second sample text can be obtained by translating the characters in the second sample text into another language.
[0043] Specifically, masking is a commonly used training method in existing text feature vector extraction models, such as the BERT (Bidirectional Encoder Representations from Transformers) model. In this embodiment, the structure of the named entity recognition model can be constructed using RoBERTa, which is similar to the structure of the BERT model. During training, dynamic masking technology is used to randomly mask words in the training text each time. In this embodiment, the first training data used to train the feature extraction model is a translation corpus pair. Specifically, each set of first training data includes a second sample text, and each second sample text includes text from at least two languages. The semantics of the text from each language included in each second sample text are consistent. In practical applications, text from multiple languages can be crawled from the Internet to generate translation corpus pairs. That is, texts with the same meaning in different languages are concatenated to obtain the second sample text. Then, the words in the second sample text are randomly masked to obtain the first sample text corresponding to the second sample text. The first sample text and the second sample text form a set of training data for training the feature extraction model, which is then fed into the feature extraction model for training. In this way, during the training process, the alignment of similar words in different languages can be achieved. That is, words from different languages with similar meanings in a sentence can extract similar feature vectors.
[0044] Specifically, the step of extracting the target feature vector of the target text through the feature extraction model library includes:
[0045] In the feature extraction model:
[0046] S110. Obtain the position embedding vector of the target text and the initial feature vector of the target text;
[0047] S120. Obtain the target feature vector of the target text based on the position embedding vector and the initial feature vector.
[0048] When processing the target text using the feature extraction model to extract the target feature vector, the first step is to obtain the position embedding vector and the initial feature vector of the target text (e.g., ...). Figure 2 The step of obtaining the position embedding vector of the target text (using RelEmbedding and token embedding) includes:
[0049] S111. Based on the relative positions of each word in the target text with other words;
[0050] S112. Based on each of the relative positions, find the position embedding vector of the target text corresponding to the vector of each of the relative positions in the position embedding matrix.
[0051] In this embodiment, a position embedding matrix is first established, which includes multiple vectors. Each vector in the position embedding matrix corresponds to a relative position in a sentence. Specifically, in this embodiment, the relative position is the position of each word in the text relative to other words. For example, if the text contains 5 words, the position of the first word relative to the other words can be represented by 0, 1, 2, 3, 4, respectively; the position of the second word relative to the other words can be represented by -1, 0, 1, 2, 3, and so on. The position of the fifth word relative to the other words can be represented by -4, -3, -2, -1, 0, respectively. It is easy to see that for a text with n words, there are a total of 2n-1 relative positions. The size of the position embedding matrix can be determined according to the maximum length of text that can be processed in the application scenario of the named entity recognition method provided by this invention, which is preset. For example, for voice control of home appliances, short sentences need to be processed, so the number of vectors in the position embedding matrix can be smaller. Specifically, taking a text with a maximum length of 256 words as an example (256 characters in Chinese), the maximum-length text includes 176 positions: the position of the first word, the position of the second word, and so on, including 511 relative positions. The position embedding matrix includes 511 vectors, with each relative position corresponding to a vector. Each vector can have 128 dimensions or other dimensions. After obtaining the target text, the relative positions in the target text can be determined based on the number of words included in the target text. The vector corresponding to each relative position is then found in the position embedding matrix as the position embedding vector of the target text. It is easy to see that the position embedding vector is composed of multiple vectors. Assuming that the target text has 5 words, and each vector in the position embedding matrix is 128-dimensional, then the size of the position embedding vector is 9*128.
[0052] The process of obtaining the initial feature vector of the target text includes:
[0053] The initial feature vector is obtained by finding the word embedding vector corresponding to each word of the target text in the word embedding matrix.
[0054] The initial feature vector of the target text includes word embedding vectors corresponding to each word of the target text. The word embedding matrix is a pre-set matrix including multiple vectors. The word embedding matrix includes vectors corresponding to each preset word. After obtaining the target text, the vectors corresponding to each word of the target text are searched in the word embedding matrix to obtain the initial feature vector. Assuming that there are 5 words in the target text and each vector in the word embedding matrix is 128-dimensional, then the size of the initial feature vector is 5*128.
[0055] like Figure 2 As shown, the structure of the feature extraction model is a self-attention framework (Transformer) commonly used in existing natural language processing. Specifically, the feature extraction model includes at least one feature extraction module connected in sequence. The step of obtaining the target feature vector of the target text based on the position embedding vector and the initial feature vector includes:
[0056] The feature vector output by the last feature extraction module is used as the target feature vector.
[0057] In each feature extraction module, the following steps are performed:
[0058] S121. Obtain the initial self-attention calculation vector based on the feature vector output by the feature extraction module described above;
[0059] S122. Perform a calculation on the position embedding vector and the self-attention calculation vector to obtain the feature matrix;
[0060] S123. Obtain the target self-attention calculation vector at each position in the target text from the feature matrix;
[0061] S124. Calculate the self-attention based on the target self-attention calculation vector and output the feature vector of the target text.
[0062] In each feature extraction module, the feature vector output by the previous feature extraction module is further extracted to output a new feature vector. Specifically, in each feature extraction module, an initial self-attention calculation vector is first obtained based on the feature vector output by the previous feature extraction module. In Transformer, calculating self-attention requires three self-attention calculation vectors: query, key, and value, abbreviated as Q, K, and V, as follows: Figure 2As shown, it can be obtained through a linear mapping layer (qkv_liner). In existing technologies, the position embedding vector is directly added to the feature vector to obtain Q, K, and V before self-attention calculation. In this embodiment, the input feature vector (i.e., the feature vector output by the previous feature extraction module) is first calculated to obtain the initial self-attention calculation vector, i.e., the initial Q, K, and V. Then, the position embedding vector is calculated with the initial self-attention calculation vector to obtain the feature matrix. Specifically, each initial self-attention calculation vector is subjected to dimensionality increase operation to expand it to a size of N*M, where N is the number of relative positions in the target text, and M is the dimension of each word embedding vector. Assuming that the target text includes 5 words and the dimension of the word embedding vector is 128, then the dimension of the feature vector is 5*128, the dimensions of Q, K, and V are also 5*128, and the dimension of the position embedding vector is 9*128. The feature matrix obtained after calculating the position embedding vector with the self-attention calculation vector has a dimension of 9*128, thus achieving the effect of dimensionality increase of the self-attention calculation vector. When calculating the self-attention at each position in the target text, different self-attention calculation vectors are used. Specifically, obtaining the target self-attention calculation vectors at each position in the target text from the feature matrix includes:
[0063] Obtain the relative position of the target location with other locations, and select corresponding data from the feature matrix based on the relative position to obtain the target self-attention calculation vector of the target location.
[0064] The following example illustrates this. Assume the target text contains 5 words. When calculating the target self-attention vector for the first position, the relative positions of the first position with respect to all positions in the target text are obtained as 0, 1, 2, 3, 4. Then, in the feature matrices corresponding to Q, K, and V, vectors corresponding to these relative positions are selected to obtain new Q, K, and V, with a dimension of 5*128. Specifically, when operating the self-attention vector based on its position embedding vector, each self-attention vector generates a corresponding feature matrix. The size of the feature matrix is the same as the dimension of the position embedding vector, which is 9*128. That is, each row (or column) in the feature matrix corresponds to a relative position in the position embedding vector. When obtaining the target self-attention vector corresponding to the target position, data is selected from the feature matrix based on the relative position corresponding to the target position to form the target self-attention vector. The self-attention calculation vector includes Q, K, and V. The relative positions of the first position are 0, 1, 2, 3, 4. The data in the rows (or columns) corresponding to 0, 1, 2, 3, 4 in the feature matrices corresponding to Q, K, and V are selected as Q, K, and V in the target self-attention calculation vector. Similarly, when calculating the target self-attention calculation vector for the second position, the relative positions are -1, 0, 1, 2, 3. The data in the rows (or columns) corresponding to the relative positions -1, 0, 1, 2, 3 are selected as Q, K, and V in the target self-attention calculation vector, and so on. From the above explanation, it is easy to see that the process of obtaining the target self-attention calculation vector can be viewed as controlling a fixed-size serial port to offset and select data within the feature matrix.
[0065] like Figure 2 As shown, after obtaining the self-attention calculation vectors at each position, a self-attention score can be calculated, and then a new feature vector can be output through residual normalization. The calculation method of self-attention and the method of outputting the new feature vector after calculation are existing technologies and will not be elaborated here. In one possible implementation, the scale factor in the existing self-attention calculation can be removed when calculating the self-attention score, making the attention score sparser and more suitable for named entity recognition tasks.
[0066] There can be multiple feature extraction modules, such as... Figure 2As shown, there can be 24 features, but this number is not limited and can be increased or decreased based on the actual computational performance of the model. Steps S121-S124 are performed in each feature extraction module to further extract features. In the first feature extraction module, the initial self-attention calculation vector is obtained based on the initial feature vector. Because relative positional information is incorporated into the self-attention calculation at each position in the feature extraction module, the self-attention gains directionality, enhancing the accuracy of feature extraction.
[0067] Please refer to it again. Figure 1 The named entity recognition method provided in this embodiment further includes the following steps:
[0068] S200. Input the target feature vector into the trained named entity extraction network to obtain the named entity recognition result output by the named entity extraction network.
[0069] Specifically, the named entity extraction network is trained based on multiple sets of second training data. Each set of second training data includes the target feature vector of the third sample text and the named entity annotation result corresponding to the third sample text. The target feature vector of the third sample text is obtained through the trained feature extraction model. The text in the third sample text is the target language, which is one of the languages included in the second sample text.
[0070] After the feature extraction network is trained, the named entity extraction network is trained based on the feature extraction network. Specifically, when generating the second training data for the named entity extraction network, named entity annotation is performed on the third sample text, that is, the named entities in the third sample text are annotated. The target feature vector of the third sample text is obtained through the feature extraction network. The target feature vector of the third sample text and the named entity annotation result of the third sample text constitute a set of training data for training the named entity extraction network. As can be seen from the foregoing description, since the feature extraction network can output similar feature vectors for words with similar meanings in different languages, when training the named entity extraction network, only the text of one language needs to be annotated to achieve the recognition of named entities in texts of multiple languages through the named entity extraction network, resulting in low annotation costs.
[0071] The named entity extraction network can be a pointer network, such as... Figure 3As shown, the feature vector of the text is input into the named entity extraction network. It first undergoes dimensionality increase through a fully connected layer FFN0, then a non-linear transformation through a Gelu layer, followed by dimensionality reduction through a fully connected layer FFN1. It is then input into two fully connected network layers, FNN20 and FNN21, respectively, to align the dimension of the feature vector with the number of entity types to be predicted. Finally, a sigmoid activation function is applied for non-linear transformation, one path outputting the suggestive position of the named entity, and the other path predicting the ending position of the named entity. Of course, Figure 3 This is just an example; those skilled in the art can choose other named entity extraction network structures.
[0072] In summary, this embodiment provides a named entity recognition method. It pre-trains a feature extraction model and a named entity extraction network, extracts target feature vectors from the text through the feature extraction model, and then outputs the named entity recognition result of the target text based on the target feature vectors through the named entity extraction network. This allows the terminal to further recognize the semantics of the target text based on the named entity recognition result and perform corresponding operations. Users can control the terminal by uttering voice commands that are not limited to specific words, making it more convenient to use.
[0073] It should be understood that although the steps in the flowcharts shown in the accompanying drawings are displayed sequentially according to the arrows, these steps are not necessarily executed in the order indicated by the arrows. Unless explicitly stated herein, there is no strict order restriction on the execution of the steps in this invention, and these steps can be executed in other orders. Moreover, at least a portion of the steps in this invention may include multiple sub-steps or multiple stages. These sub-steps or stages are not necessarily completed at the same time, but can be executed at different times. The execution order of these sub-steps or stages is not necessarily sequential, but can be performed alternately or in turn with other steps or at least a portion of the sub-steps or stages of other steps.
[0074] Those skilled in the art will understand that all or part of the processes in the methods of the above embodiments can be implemented by a computer program instructing related hardware. The computer program can be stored in a non-volatile computer-readable storage medium. When executed, the computer program can include the processes of the embodiments of the above methods. Any references to memory, storage, databases, or other media used in the embodiments provided by this invention can include non-volatile and / or volatile memory. Non-volatile memory can include read-only memory (ROM), programmable ROM (PROM), electrically programmable ROM (EPROM), electrically erasable programmable ROM (EEPROM), or flash memory. Volatile memory can include random access memory (RAM) or external cache memory. By way of illustration and not limitation, RAM is available in various forms, such as static RAM (SRAM), dynamic RAM (DRAM), synchronous DRAM (SDRAM), dual data rate SDRAM (DDRSDRAM), enhanced SDRAM (ESDRAM), synchronous link DRAM (SLDRAM), RAMbus direct RAM (RDRAM), direct memory bus dynamic RAM (DRDRAM), and RAMbus dynamic RAM (RDRAM), etc.
[0075] Example 2
[0076] Based on the above embodiments, the present invention also provides a terminal, the principle block diagram of which can be as follows: Figure 4 As shown. The terminal includes a memory 10 and a processor 20. The memory 10 stores a computer program, and the processor 10, when executing the computer program, can perform at least the following steps:
[0077] The target text is input into a trained feature extraction model, and the target feature vector of the target text is extracted by the feature extraction model.
[0078] The target feature vector is input into a trained named entity extraction network to obtain the named entity recognition result output by the named entity extraction network.
[0079] Wherein, the step of extracting the target feature vector of the target text through the feature extraction model includes:
[0080] In the feature extraction model:
[0081] Obtain the position embedding vector of the target text and the initial feature vector of the target text;
[0082] The target feature vector of the target text is obtained based on the location embedding vector and the initial feature vector.
[0083] The step of obtaining the position embedding vector of the target text includes:
[0084] Based on the relative positions of each word in the target text with other words;
[0085] The position embedding vector of the target text is obtained by finding the vector corresponding to each relative position in the position embedding matrix.
[0086] The step of obtaining the initial feature vector of the target text includes:
[0087] The initial feature vector is obtained by finding the word embedding vector corresponding to each word of the target text in the word embedding matrix.
[0088] The feature extraction model includes at least one feature extraction module connected in sequence; obtaining the target feature vector of the target text based on the position embedding vector and the initial feature vector includes:
[0089] The feature vector output by the last feature extraction module is used as the target feature vector.
[0090] In each of the feature extraction modules:
[0091] The initial self-attention calculation vector is obtained based on the feature vector output by the feature extraction module described above;
[0092] The position embedding vector and the self-attention calculation vector are used to obtain the feature matrix;
[0093] Obtain the target self-attention calculation vector at each position in the target text from the feature matrix;
[0094] After calculating the self-attention based on the target self-attention calculation vector, the feature vector of the target text is output.
[0095] Specifically, in the first feature extraction module, the initial self-attention calculation vector is obtained based on the initial feature vector.
[0096] The step of obtaining the target self-attention calculation vector at each position in the target text from the feature matrix based on the relative position of each word in the target text with other words includes:
[0097] Obtain the relative position of the target location with respect to all locations in the target text, and select the corresponding data in the feature matrix based on the relative position to obtain the target self-attention calculation vector of the target location.
[0098] The feature extraction model is trained based on multiple sets of first training data. Each set of first training data includes a first sample text and a second sample text corresponding to the first sample text. The first sample text is obtained by randomly masking words in the second sample text. Each second sample text includes text from at least two languages, and the semantics of the text from each language in each second sample text are consistent.
[0099] The named entity extraction network is trained based on multiple sets of second training data. Each set of second training data includes the target feature vector of the third sample text and the named entity annotation result corresponding to the third sample text. The target feature vector of the third sample text is obtained through the trained feature extraction model. The text in the third sample text is the target language, which is one of the languages included in the second sample text.
[0100] The named entity extraction network is a pointer network.
[0101] Example 3
[0102] The present invention also provides a computer-readable storage medium storing one or more programs that can be executed by one or more processors to implement the steps of the named entity recognition method described in the above embodiments.
[0103] Finally, it should be noted that the above embodiments are only used to illustrate the technical solutions of the present invention, and not to limit them; although the present invention has been described in detail with reference to the foregoing embodiments, those skilled in the art should understand that modifications can still be made to the technical solutions described in the foregoing embodiments, or equivalent substitutions can be made to some of the technical features; and these modifications or substitutions do not cause the essence of the corresponding technical solutions to deviate from the spirit and scope of the technical solutions of the embodiments of the present invention.
Claims
1. A named entity recognition method, characterized in that, include: The target text is input into a trained feature extraction model, and the target feature vector of the target text is extracted by the feature extraction model. The step of extracting the target feature vector of the target text using the feature extraction model includes: In the feature extraction model: Obtain the position embedding vector of the target text and the initial feature vector of the target text; The target feature vector of the target text is obtained based on the location embedding vector and the initial feature vector. The feature extraction model includes at least one feature extraction module connected in sequence; The step of obtaining the target feature vector of the target text based on the position embedding vector and the initial feature vector includes: The feature vector output by the last feature extraction module is used as the target feature vector. In each of the feature extraction modules: The initial self-attention calculation vector is obtained based on the feature vector output by the feature extraction module described above; The location embedding vector is operated on with the initial self-attention calculation vector to obtain the feature matrix; The step of performing a calculation on the position embedding vector and the initial self-attention calculation vector to obtain the feature matrix specifically includes: When the initial self-attention calculation vector is calculated based on the position embedding vector, each initial self-attention calculation vector generates a corresponding feature matrix, wherein each row or column of the feature matrix corresponds to a relative position in the position embedding vector. Each of the initial self-attention calculation vectors is subjected to a dimensionality increase operation to expand the initial self-attention calculation vector to a size of N*M, where N is the number of relative positions in the target text and M is the dimension of each word embedding vector; Obtain the target self-attention calculation vector at each position in the target text from the feature matrix; The step of obtaining the target self-attention calculation vector at each position in the target text from the feature matrix includes: Obtain the relative position of the target location with respect to all locations in the target text, and select the corresponding data in the feature matrix based on the relative position to obtain the target self-attention calculation vector of the target location; After calculating the self-attention based on the target self-attention calculation vector, the feature vector of the target text is output. Specifically, in the first feature extraction module, the initial self-attention calculation vector is obtained based on the initial feature vector; The target feature vector is input into a trained named entity extraction network to obtain the named entity recognition result output by the named entity extraction network.
2. The named entity recognition method according to claim 1, characterized in that, The step of obtaining the position embedding vector of the target text includes: Based on the relative positions of each word in the target text with other words; The position embedding vector of the target text is obtained by finding the vector corresponding to each relative position in the position embedding matrix.
3. The named entity recognition method according to claim 1, characterized in that, The process of obtaining the initial feature vector of the target text includes: The initial feature vector is obtained by finding the word embedding vector corresponding to each word of the target text in the word embedding matrix.
4. The named entity recognition method according to claim 1, characterized in that, The feature extraction model is trained based on multiple sets of first training data. Each set of first training data includes a first sample text and a second sample text corresponding to the first sample text. The first sample text is obtained by randomly masking words in the second sample text. Each second sample text includes characters from at least two languages, and the semantics of the characters from each language in each second sample text are consistent.
5. The named entity recognition method according to claim 4, characterized in that, The named entity extraction network is trained based on multiple sets of second training data. Each set of second training data includes the target feature vector of the third sample text and the named entity annotation result corresponding to the third sample text. The target feature vector of the third sample text is obtained through the trained feature extraction model. The text in the third sample text is the target language, which is one of the languages included in the second sample text.
6. The named entity recognition method according to claim 4, characterized in that, The named entity extraction network is a pointer network.
7. A terminal, characterized in that, The terminal includes: a processor and a storage medium communicatively connected to the processor. The storage medium is adapted to store multiple instructions, and the processor is adapted to call the instructions in the storage medium to execute the steps of implementing the named entity recognition method according to any one of claims 1-6.
8. A computer-readable storage medium, characterized in that, The computer-readable storage medium stores one or more programs, which can be executed by one or more processors to implement the steps of the named entity recognition method as described in any one of claims 1-6.
Citation Information
Patent Citations
Named entity identification method and device
CN112115721A