A method, device, electronic device and storage medium for extracting named entities

By using pre-trained coding models and pointer set extraction methods in named entity recognition, the problem of not being able to identify and update named entities in the prior art is solved, and efficient named entity recognition and powerful data generalization capabilities are achieved.

CN112069821BActive Publication Date: 2025-02-25BEIJING XUEZHITU NETWORK TECH
View PDF 2 Cites 0 Cited by

Patent Information

Application Number
CN202010949598.4
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2020-09-10
Publication Date
2025-02-25
Estimated Expiration
2040-09-10

AI Technical Summary

Technical Problem

The existing named entity recognition method can only recognize recorded named entities, cannot recognize updated named entities, and has weak data generalization capabilities.

Method used

By entering the target text into the pre-trained coding model, the text matrix is ​​obtained, and the first and tail pointers sets are determined based on the matrix, thereby extracting the named entity and determining its category.

Benefits of technology

It realizes the recognition of updated named entities, improving the generalization ability of data and the efficiency of named entity recognition.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN112069821B_ABST
    Figure CN112069821B_ABST
Patent Text Reader

Abstract

The present application provides a method, device, electronic device and storage medium for extracting named entities, wherein the extraction method includes: inputting a target text into a pre-trained encoding model, obtaining a first text matrix corresponding to the target text output by the encoding model; determining a first head pointer set and a first tail pointer set corresponding to the target text based on the first text matrix corresponding to the target text; the first head pointer set includes a first feature value of the first word of a target word that meets a preset category in the target text; the first tail pointer set includes a second feature value of the tail word of a target word that meets a preset category in the target text; according to the first feature value in the first head pointer set and the second feature value in the first tail pointer set, extracting the named entity from the target text and determining the category corresponding to the named entity. The present application can identify updated named entities, has strong data generalization ability, and high named entity recognition efficiency.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present application relates to the field of computer information technology, and in particular to a method, device, electronic device and storage medium for extracting named entities. Background Art

[0002] At present, named entity recognition is a basic task in the field of natural language processing. It aims to identify named entities in text and classify the identified named entities. The effect of named entity recognition directly determines the processing accuracy of downstream tasks of natural language processing.

[0003] In practice, the method for identifying named entities is usually as follows: staff collect existing named entities in various fields, compile the collected multiple named entities into a named entity dictionary, extract named entities from the text to be processed based on the named entity dictionary, and determine the category to which the named entity belongs.

[0004] However, this named entity recognition method can only recognize recorded named entities, but cannot recognize updated named entities, and the data generalization ability is weak. Summary of the invention

[0005] In view of this, the purpose of the embodiments of the present application is to provide a method, device, electronic device and storage medium for extracting named entities, which can extract named entities from a target text based on a head pointer set and a tail pointer set corresponding to the target text, can identify updated named entities, have strong data generalization capabilities, and high named entity recognition efficiency.

[0006] In a first aspect, an embodiment of the present application provides a method for extracting a named entity, the method comprising:

[0007] Inputting the target text into a pre-trained encoding model, and obtaining a first text matrix corresponding to the target text output by the encoding model;

[0008] Based on a first text matrix corresponding to the target text, a first head pointer set and a first tail pointer set corresponding to the target text are determined; the first head pointer set includes a first feature value of a head word of a target word in the target text that meets a preset category; the first tail pointer set includes a second feature value of a tail word of a target word in the target text that meets a preset category;

[0009] According to the first feature value in the first head pointer set and the second feature value in the first tail pointer set, named entities are extracted from the target text, and categories corresponding to the named entities are determined.

[0010] In a possible implementation, determining a first head pointer set and a first tail pointer set corresponding to the target text based on a first text matrix corresponding to the target text includes:

[0011] Based on a pre-trained standard matrix, a first text matrix corresponding to the target text is transformed to obtain a first probability that each word in the target text belongs to the preset category;

[0012] For each character in the target text, determine whether the character is the first character or the last character of the target segmentation that meets the preset category according to the first probability that the character belongs to the preset category, the first probability that other characters in the target text belong to the preset category, and the positional relationship between the other characters and the character;

[0013] Based on the judgment result of whether the character is the first character or the last character of the target word that meets the preset category, and the feature value corresponding to each judgment result, a first first pointer set and a first last pointer set corresponding to the target text are generated.

[0014] In a possible implementation, extracting the named entity from the target text according to the first feature value in the first head pointer set and the second feature value in the first tail pointer set, and determining the category corresponding to the named entity includes:

[0015] For each first eigenvalue in the first head pointer set, selecting a second eigenvalue from the first tail pointer set, the second eigenvalue having a category consistent with the category of the first eigenvalue and a positional relationship with the first eigenvalue that satisfies a first preset condition;

[0016] The word segment corresponding to the first feature value and the selected second feature value is determined as a named entity in the target text, and the category of the first feature value is determined as the category of the named entity.

[0017] In a possible implementation manner, the encoding model and the standard matrix are trained in the following manner:

[0018] Constructing first training data, wherein the first training data includes a plurality of first sample texts, and a second head pointer set and a second tail pointer set corresponding to each first sample text;

[0019] Inputting a first sample text in the first training data into a coding model, and obtaining a second text matrix corresponding to the first sample text output by the coding model;

[0020] Based on the standard matrix, a matrix transformation is performed on the second text matrix corresponding to the first sample text to obtain a third head pointer set and a third tail pointer set corresponding to the first sample text;

[0021] Determine the loss value corresponding to the first sample text according to the second head pointer set and the second tail pointer set corresponding to the first sample text, and the third head pointer set and the third tail pointer set corresponding to the first sample text;

[0022] The encoding model and the standard matrix are adjusted based on the loss value until the loss value corresponding to any of the first sample texts is less than a preset threshold, thereby obtaining the pre-trained encoding model and the pre-trained standard matrix.

[0023] In a possible implementation, the first training data is constructed in the following manner:

[0024] Constructing second training data, wherein the second training data includes a plurality of second sample texts;

[0025] Inputting a second sample text in the second training data into a coding model, and obtaining a third text matrix corresponding to the second sample text output by the coding model;

[0026] Based on the standard matrix, a third text matrix corresponding to the second sample text is transformed to obtain a second probability that each character in the second sample text belongs to the preset category;

[0027] Determine a fourth head pointer set and a fourth tail pointer set corresponding to the second sample text based on a second probability that each word in the second sample text belongs to the preset category;

[0028] If the second probability that each word in the second sample text belongs to the preset category meets the second preset condition, the second sample text is determined as the first sample text, and the fourth first pointer set and the fourth last pointer set corresponding to the second sample text are respectively determined as the second first pointer set and the second last pointer set corresponding to the first sample text.

[0029] In a second aspect, an embodiment of the present application provides a device for extracting a named entity, the device comprising:

[0030] A first acquisition module, used for inputting a target text into a pre-trained encoding model, and acquiring a first text matrix corresponding to the target text output by the encoding model;

[0031] A first determination module is used to determine a first head pointer set and a first tail pointer set corresponding to the target text based on a first text matrix corresponding to the target text; the first head pointer set includes a first feature value of a head word of a target word in the target text that meets a preset category; the first tail pointer set includes a second feature value of a tail word of a target word in the target text that meets a preset category;

[0032] An extraction module is used to extract named entities from the target text according to the first feature value in the first head pointer set and the second feature value in the first tail pointer set, and determine the category corresponding to the named entity.

[0033] In a possible implementation manner, when the first determination module determines the first head pointer set and the first tail pointer set corresponding to the target text based on the first text matrix corresponding to the target text, the first determination module includes:

[0034] Based on a pre-trained standard matrix, a first text matrix corresponding to the target text is transformed to obtain a first probability that each word in the target text belongs to the preset category;

[0035] For each character in the target text, determine whether the character is the first character or the last character of the target segmentation that meets the preset category according to the first probability that the character belongs to the preset category, the first probability that other characters in the target text belong to the preset category, and the positional relationship between the other characters and the character;

[0036] Based on the judgment result of whether the character is the first character or the last character of the target word that meets the preset category, and the feature value corresponding to each judgment result, a first first pointer set and a first last pointer set corresponding to the target text are generated.

[0037] In a possible implementation, the extraction module, when extracting the named entity from the target text according to the first feature value in the first head pointer set and the second feature value in the first tail pointer set, and determining the category corresponding to the named entity, includes:

[0038] For each first eigenvalue in the first head pointer set, selecting a second eigenvalue from the first tail pointer set, the second eigenvalue having a category consistent with the category of the first eigenvalue and a positional relationship with the first eigenvalue that satisfies a first preset condition;

[0039] The word segment corresponding to the first feature value and the selected second feature value is determined as a named entity in the target text, and the category of the first feature value is determined as the category of the named entity.

[0040] In a third aspect, an embodiment of the present application provides an electronic device, comprising: a processor, a memory and a bus, wherein the memory stores machine-readable instructions executable by the processor, and when the electronic device is running, the processor communicates with the memory through the bus, and the processor executes the machine-readable instructions to perform the steps of the named entity extraction method described in any one of the first aspects.

[0041] In a fourth aspect, an embodiment of the present application provides a computer-readable storage medium, on which a computer program is stored. When the computer program is executed by a processor, the steps of the method for extracting named entities described in any one of the first aspects are executed.

[0042] The embodiment of the present application provides a method, device, electronic device and storage medium for extracting named entities, inputting a target text into a pre-trained encoding model, obtaining a first text matrix corresponding to the target text output by the encoding model; determining a first head pointer set and a first tail pointer set corresponding to the target text based on the first text matrix corresponding to the target text; the first head pointer set includes a first feature value of the first character of the target word that meets a preset category in the target text; the first tail pointer set includes a second feature value of the tail character of the target word that meets a preset category in the target text; according to the first feature value in the first head pointer set and the second feature value in the first tail pointer set, extracting named entities from the target text and determining the category corresponding to the named entity. The embodiment of the present application can extract named entities from the target text based on the head pointer set and the tail pointer set corresponding to the target text, can identify updated named entities, has strong data generalization ability, and high named entity recognition efficiency.

[0043] In order to make the above-mentioned objects, features and advantages of the present application more obvious and easy to understand, preferred embodiments are specifically cited below and described in detail with reference to the attached drawings. BRIEF DESCRIPTION OF THE DRAWINGS

[0044] In order to more clearly illustrate the technical solutions of the embodiments of the present application, the drawings required for use in the embodiments will be briefly introduced below. It should be understood that the following drawings only show certain embodiments of the present application and therefore should not be regarded as limiting the scope. For ordinary technicians in this field, other related drawings can be obtained based on these drawings without paying creative work.

[0045] Figure 1 A flowchart of a method for extracting named entities provided in an embodiment of the present application is shown;

[0046] Figure 2A flowchart of another method for extracting named entities provided in an embodiment of the present application is shown;

[0047] Figure 3 A flowchart of another method for extracting named entities provided in an embodiment of the present application is shown;

[0048] Figure 4 A flowchart of another method for extracting named entities provided in an embodiment of the present application is shown;

[0049] Figure 5 A flowchart of another method for extracting named entities provided in an embodiment of the present application is shown;

[0050] Figure 6 A schematic diagram of the structure of a named entity extraction device provided in an embodiment of the present application is shown;

[0051] Figure 7 A schematic diagram of an electronic device provided in an embodiment of the present application is shown. DETAILED DESCRIPTION

[0052] To make the purpose, technical scheme and advantages of the embodiments of the present application clearer, the technical scheme in the embodiments of the present application will be clearly and completely described below in conjunction with the drawings in the embodiments of the present application. Obviously, the described embodiments are only part of the embodiments of the present application, rather than all of the embodiments. The components of the embodiments of the present application generally described and shown in the drawings here can be arranged and designed in various different configurations. Therefore, the following detailed description of the embodiments of the present application provided in the drawings is not intended to limit the scope of the application claimed for protection, but merely represents the selected embodiments of the present application. Based on the embodiments of the present application, all other embodiments obtained by those skilled in the art without making creative work belong to the scope of protection of the present application.

[0053] At present, named entity recognition is a basic task in the field of natural language processing. It aims to identify named entities in text and classify the identified named entities. The effect of named entity recognition directly determines the processing accuracy of downstream tasks of natural language processing. In practice, the method of named entity recognition is usually: the staff collects existing named entities in various fields, compiles the collected multiple named entities into a named entity dictionary, extracts named entities from the text to be processed based on the named entity dictionary, and determines the category to which the named entity belongs. However, this method of named entity recognition can only recognize recorded named entities, and cannot recognize updated named entities, and the generalization ability of the data is weak.

[0054] Based on the above problems, an embodiment of the present application provides a method, device, electronic device and storage medium for extracting named entities, inputting a target text into a pre-trained encoding model, obtaining a first text matrix corresponding to the target text output by the encoding model; based on the first text matrix corresponding to the target text, determining a first head pointer set and a first tail pointer set corresponding to the target text; the first head pointer set includes a first feature value of the first character of the target word that meets a preset category in the target text; the first tail pointer set includes a second feature value of the tail character of the target word that meets a preset category in the target text; according to the first feature value in the first head pointer set and the second feature value in the first tail pointer set, extracting named entities from the target text and determining the category corresponding to the named entity. The embodiment of the present application can extract named entities from the target text based on the head pointer set and the tail pointer set corresponding to the target text, can identify updated named entities, has strong data generalization ability, and high named entity recognition efficiency.

[0055] The defects existing in the above solutions are the results obtained by the inventor after practice and careful research. Therefore, the process of discovering the above problems and the solutions proposed by this application for the above problems below should be the contributions made by the inventor to this application during the application process.

[0056] The technical solutions in the present application will be clearly and completely described below in conjunction with the drawings in the present application. Obviously, the described embodiments are only a part of the embodiments of the present application, rather than all the embodiments. The components of the present application generally described and shown in the drawings here can be arranged and designed in various different configurations. Therefore, the following detailed description of the embodiments of the present application provided in the drawings is not intended to limit the scope of the present application for protection, but merely represents the selected embodiments of the present application. Based on the embodiments of the present application, all other embodiments obtained by those skilled in the art without making creative work belong to the scope of protection of the present application.

[0057] It should be noted that similar reference numerals and letters denote similar items in the following drawings, and therefore, once an item is defined in one drawing, further definition and explanation thereof is not required in subsequent drawings.

[0058] To facilitate understanding of this embodiment, a method for extracting named entities disclosed in an embodiment of the present application is first introduced in detail.

[0059] See also Figure 1 As shown, Figure 1 A flowchart of a method for extracting named entities provided in an embodiment of the present application, the method comprising the following steps:

[0060] S101. Input a target text into a pre-trained encoding model, and obtain a first text matrix corresponding to the target text output by the encoding model.

[0061] In an embodiment of the present application, the target text is a text containing named entities, wherein the named entities include names of persons, organization names, place names, and all other entities identified by names. More general entities also include numbers, dates, currencies, addresses, and the like.

[0062] Optionally, the target text is a text related to 3C products, such as an introduction text of 3C products or an evaluation text of 3C products. 3C refers to the combination of computers, communications, and consumer electronics. 3C products specifically include: computers, tablet computers, mobile phones, digital cameras, walkmans, electronic dictionaries, audio and video players, digital audio players and other hardware devices.

[0063] The target text consists of multiple characters. Based on a preset character-character vector dictionary, the character vector corresponding to each character in the target text is determined, and the character vector of each character in the target text is input into the encoding model to obtain the first text matrix of the target text output by the encoding model, wherein the first text matrix is ​​used to represent the text semantics corresponding to the target text.

[0064] Optionally, the encoding model is a ROBERTA model, and the first text matrix output by the ROBERTA model is a B×N×768 matrix, wherein B is the size of a batch size (batch_size), the batch size is the number of data used in each batch when using the gradient descent method for learning and training, B can be 1, 32, 64, etc., different numbers of target texts, N is the target length of each target text, and the N corresponding to different target texts is the same. The method for determining N includes: obtaining the actual length of each target text, that is, the number of words in each target text, and determining the maximum value of the actual lengths of multiple target texts as N, or selecting N from the actual lengths of multiple target texts, where N is greater than 99% of the actual lengths of the target texts, and 768 is the output dimension of the ROBERTA model.

[0065] S102. Based on the first text matrix corresponding to the target text, determine a first head pointer set and a first tail pointer set corresponding to the target text; the first head pointer set includes a first feature value of a head word of a target word that meets a preset category in the target text; the first tail pointer set includes a second feature value of a tail word of a target word that meets a preset category in the target text.

[0066] In the embodiment of the present application, for each target text, a matrix transformation is performed on the first text matrix corresponding to the target text to obtain the first head pointer set and the first tail pointer set corresponding to the target text. The target text includes multiple word segments, and different word segments correspond to different categories, such as brand category, attribute category, and meaningless category. Each target text corresponds to a first head pointer set and a first tail pointer set. Each word in the target text has a corresponding feature value in the first head pointer set and the first tail pointer set. The feature value corresponding to the first word of the target word of the preset category in the target text in the first head pointer set is the first feature value, and the feature value corresponding to the last word of the target word of the preset category in the target text in the first tail pointer set is the second feature value. The first feature value corresponding to the first word of the target word of the preset category in the target text is different, and the last word of the target word of the preset category in the target text is different. The second feature values ​​corresponding to different characters are different. The first feature value corresponding to the first character of the target segmentation of the same category is the same as the second feature value corresponding to the last character of the target segmentation. For example, the first feature value corresponding to the first character of the target segmentation of the brand class (or the second feature value corresponding to the last character) is 1, the first feature value corresponding to the first character of the target segmentation of the attribute class (or the second feature value corresponding to the last character) is 2, the first feature value (second feature value) corresponding to each character in the target segmentation of the meaningless class is 0, and the first feature value (or second feature value) corresponding to the middle character (characters except the first character and the last character) of the target segmentation of the preset category (brand class and attribute class) is 0.

[0067] For example, the target text 1 is "I like the screen of Huawei mobile phone", and the preset categories are brand category and attribute category. Among the multiple word segmentations of target text 1, the target word segmentation 1 of the "brand category" is "Huawei", and the target word segmentation 2 of the "attribute category" is "screen". The first and second feature values ​​corresponding to the "brand category" are both 1, and the first and second feature values ​​corresponding to the "attribute category" are both 2. Then the first head pointer set corresponding to the target text 1 is (0,0,0,1,0,0,0,0,2,0), and the first tail pointer set is (0,0,0,0,1,0,0,0,0,2).

[0068] S103: extract named entities from the target text according to the first feature value in the first head pointer set and the second feature value in the first tail pointer set, and determine categories corresponding to the named entities.

[0069] In an embodiment of the present application, named entities are extracted from the target text based on a first feature value corresponding to the first character of a target word that meets a preset category in the target text in a first first pointer set, and a second feature value corresponding to the last character of a target word that meets a preset category in the target text in a first last pointer set, and for each named entity, a category corresponding to the named entity is determined based on a category corresponding to both the first feature value and the second feature value corresponding to the named entity. For example, if the first feature value and the second feature value corresponding to the named entity are both 1, then the named entity is a brand.

[0070] The named entity extraction method provided in the embodiment of the present application extracts named entities from the target text based on the head pointer set and the tail pointer set corresponding to the target text, can identify updated named entities, has strong data generalization ability, and high named entity recognition efficiency.

[0071] For further information, see Figure 2 As shown, in the method for extracting named entities provided in an embodiment of the present application, the first text matrix corresponding to the target text is used to determine the first head pointer set and the first tail pointer set corresponding to the target text, including:

[0072] S201. Based on a pre-trained standard matrix, a first text matrix corresponding to the target text is transformed to obtain a first probability that each character in the target text belongs to the preset category.

[0073] In an embodiment of the present application, the first text matrix corresponding to the target text is multiplied by the pre-trained standard matrix to obtain a target matrix. Wherein, the number of columns of the standard matrix is ​​consistent with the number of the above-mentioned preset categories, for example, the preset categories are 8 categories, the number of columns of the standard matrix is ​​8 columns, the first text matrix of the target text is a 1×10×768 matrix (the target text includes 10 characters), and after the first text matrix is ​​multiplied by the standard matrix, the target matrix obtained is a 1×10×8 matrix, each row of the target matrix represents each character in the target text, and each column of the target matrix represents the probability that each character in the target text belongs to each preset category, and different columns of the target matrix correspond to different preset categories. Assuming that the third line of the target matrix is ​​(0.1, 0.2, 0.1, 0.9, ...), the probability that the third character of the target text belongs to the first preset category is 0.1, the probability that it belongs to the second preset category is 0.2, the probability that it belongs to the third preset category is 0.1, and the probability that it belongs to the fourth preset category is 0.9.

[0074] S202. For each character in the target text, determine whether the character is the first character or the last character of a target word that meets the preset category based on a first probability that the character belongs to the preset category, a first probability that other characters in the target text belong to the preset category, and a positional relationship between the other characters and the character.

[0075] In an embodiment of the present application, for each preset category, if the first probabilities that multiple consecutive characters in the target text belong to the preset category are all greater than a preset threshold, the above-mentioned multiple consecutive characters are determined as the target segmentation words of the preset category, the first character of the above-mentioned multiple consecutive characters is determined as the first character of the target segmentation word that meets the preset category, and the last character of the above-mentioned multiple consecutive characters is determined as the last character of the target segmentation word that meets the preset category.

[0076] For example, the second column of the target matrix is ​​(0.1, 0.2, 0.1, 0.2, 0.1, 0.2, 0.1, 0.1, 0.8, 0.9), and the preset category corresponding to the second column of the target matrix is ​​"attribute class", among which the first probability of the ninth position and the first probability of the tenth position are both greater than the preset threshold value 0.7, for the target text 1 "I like the screen of Huawei mobile phones", the "screen" at the ninth position is the first character of the target segmentation of the preset category "attribute class", and the "curtain" at the tenth position is the last character of the target segmentation of the preset category "attribute class".

[0077] S203, generating a first head pointer set and a first tail pointer set corresponding to the target text according to a judgment result of whether the character is the first character or the last character of a target word that meets a preset category, and a feature value corresponding to each judgment result.

[0078] In an embodiment of the present application, for each character, if the character is the first character of a target word segmentation that satisfies a preset category, the feature value corresponding to the character in the first first pointer set is determined as a first feature value that matches the preset category; if the character is the last character of a target word segmentation that satisfies a preset category, the feature value corresponding to the character in the first last pointer set is determined as a second feature value that matches the preset category. For example, the target text 1 is "I like the screen of Huawei mobile phone", where "Hua" is the first character of target segmentation word 1 "Huawei", "Ping" is the first character of target segmentation word 2 "screen", "Wei" is the last character of target segmentation word 1 "Huawei", and "Mu" is the last character of target segmentation word 2 "screen", and the first feature value (or first feature value) corresponding to "brand class" is "1", and the first feature value (or first feature value) corresponding to "attribute class" is "2", and the feature values ​​corresponding to other characters in the target text except the first and last characters of the above target segmentations are all "0", then the first head pointer set corresponding to the target text 1 is (0,0,0,1,0,0,0,0,2,0), and the corresponding first tail pointer set is (0,0,0,0,1,0,0,0,0,2).

[0079] For further information, see Figure 3 As shown, in the method for extracting named entities provided in an embodiment of the present application, the named entities are extracted from the target text according to the first feature value in the first head pointer set and the second feature value in the first tail pointer set, and the category corresponding to the named entity is determined, including:

[0080] S301. For each first eigenvalue in the first head pointer set, select from the first tail pointer set a second eigenvalue whose category is consistent with that of the first eigenvalue and whose positional relationship with the first eigenvalue satisfies a first preset condition.

[0081] In an embodiment of the present application, for each first eigenvalue in the first head pointer set corresponding to the target text, a second eigenvalue whose value is consistent with the first eigenvalue and is closest to the first eigenvalue is selected from the first tail pointer set corresponding to the target text.

[0082] For example, the first head pointer set corresponding to the target text 2 is (0,0,0,1,0,0,0,0,1,0), and the corresponding first tail pointer set is (0,0,0,0,1,0,0,0,0,1). The first head pointer set includes two first eigenvalues ​​"1", which are respectively at the fourth position and the ninth position, and the first tail pointer set includes two second eigenvalues ​​"1", which are respectively at the fifth position and the tenth position. For the first eigenvalue "1" at the fourth position, the first tail pointer set includes two second eigenvalues ​​whose values ​​are consistent with the first eigenvalue "1", among which the second eigenvalue "1" at the fifth position is closest to the first eigenvalue "1" at the fourth position, and the second eigenvalue "1" at the fifth position is matched with the first eigenvalue "1" at the fourth position, and the second eigenvalue "1" at the tenth position is closest to the first eigenvalue "1" at the ninth position, and the second eigenvalue "1" at the tenth position is matched with the first eigenvalue "1" at the ninth position.

[0083] S302: Determine the word segment corresponding to the first feature value and the selected second feature value as a named entity in the target text, and determine the category of the first feature value as the category of the named entity.

[0084] In an embodiment of the present application, for each first feature value, a second feature value matching the first feature value is selected, the character corresponding to the first feature value in the target text is the first character of the named entity, and the character corresponding to the second feature value in the target text is the last character of the named entity, and then the named entity is extracted from the target text, and the category of the named entity is determined by the category of the first feature value and the second feature value corresponding to the named entity.

[0085] For example, the target text 2 is "I like Huawei phones and Xiaomi", the second feature value "1" at the fifth position matches the first feature value "1" at the fourth position, and the named entity "Huawei" is extracted from the target text 2. The second feature value "1" at the tenth position matches the first feature value "1" at the ninth position, and the named entity "Xiaomi" is extracted from the target text 2. According to the first feature value (or second feature value) "1", it is determined that "Huawei" and "Xiaomi" are both brand-type named entities.

[0086] For further information, see Figure 4 As shown, in the method for extracting named entities provided in the embodiment of the present application, the encoding model and the standard matrix are trained in the following manner:

[0087] S401: Construct first training data, wherein the first training data includes a plurality of first sample texts, and a second head pointer set and a second tail pointer set corresponding to each first sample text.

[0088] In the embodiment of the present application, there are two types of training data, namely, first training data and second training data, wherein the first sample text in the first training data is a labeled sample text, namely, there is a second head pointer set and a second tail pointer set, and the second sample text in the second training data is an unlabeled sample text.

[0089] S402: Input a first sample text in the first training data into a coding model, and obtain a second text matrix corresponding to the first sample text output by the coding model.

[0090] In an embodiment of the present application, the first sample text is composed of a plurality of characters, and based on a preset character-character vector dictionary, the character vector corresponding to each character in the first sample text is determined, and the character vector of each character in the first sample text is input into the encoding model to obtain a second text matrix of the first sample text output by the encoding model, wherein the second text matrix is ​​used to characterize the text semantics corresponding to the first sample text. Optionally, the encoding model is a ROBERTA model, where the encoding model can be an initialized encoding model, a training encoding model, or a trained encoding model, and in the process of training the encoding model using the first sample text, the encoding model changes dynamically.

[0091] S403: Based on a standard matrix, perform a matrix transformation on a second text matrix corresponding to the first sample text to obtain a third head pointer set and a third tail pointer set corresponding to the first sample text.

[0092] In an embodiment of the present application, based on the standard matrix, a matrix transformation is performed on the second text matrix corresponding to the first sample text, that is, the second text matrix corresponding to the first sample text is multiplied by the standard matrix to obtain a third probability that each character in the first sample text belongs to a preset category. Here, the standard matrix can be an initialized standard matrix, a standard matrix in training, or a trained standard matrix. In the process of training the standard matrix using the first sample text, the standard matrix changes dynamically.

[0093] For each preset category, if the third probability that multiple consecutive characters in the first sample text belong to the preset category is greater than a preset threshold, the above-mentioned multiple consecutive characters are determined as the target segmentation words of the preset category, the first character of the above-mentioned multiple consecutive characters is determined as the first character of the target segmentation word, and the last character of the above-mentioned multiple consecutive characters is determined as the last character of the target segmentation word.

[0094] For each character, if the character is the first character of the target word segmentation that meets the preset category, the feature value corresponding to the character in the first first pointer set is determined as the first feature value matching the preset category; if the character is the last character of the target word segmentation that meets the preset category, the feature value corresponding to the character in the first last pointer set is determined as the second feature value matching the preset category, and a third first pointer set and a third last pointer set corresponding to the first sample text are obtained.

[0095] S404: Determine a loss value corresponding to the first sample text according to a second head pointer set and a second tail pointer set corresponding to the first sample text, and a third head pointer set and a third tail pointer set corresponding to the first sample text.

[0096] In the embodiment of the present application, the first loss value corresponding to the first sample text is determined based on the second head pointer set and the third head pointer set respectively corresponding to the first sample text; the second loss value corresponding to the first sample text is determined based on the second tail pointer set and the third tail pointer set respectively corresponding to the first sample text; the loss value corresponding to the first sample text is determined based on the first loss value and the second loss value corresponding to the first sample text. Optionally, the loss value corresponding to the first sample text is determined using a cross entropy function.

[0097] S405. Adjust the encoding model and the standard matrix based on the loss value until the loss value corresponding to any of the first sample texts is less than a preset threshold, thereby obtaining the pre-trained encoding model and the pre-trained standard matrix.

[0098] In an embodiment of the present application, a loss value corresponding to each first sample text in the first training data is obtained. If the loss value corresponding to any first sample text in the first training data is greater than a preset threshold, the parameters of the encoding model and the standard function are adjusted until the loss value corresponding to any first sample text in the first training data is less than the preset threshold. Then, the adjustment of the parameters of the encoding model and the standard function is stopped to obtain a trained encoding model and a trained standard matrix.

[0099] For further information, see Figure 5 As shown, in the method for extracting named entities provided in the embodiment of the present application, not only can the second head pointer set and the second tail pointer set corresponding to each first sample text be manually marked to construct the first training data, but the first training data can also be constructed in the following manner:

[0100] S501: Construct second training data, where the second training data includes a plurality of second sample texts.

[0101] In an embodiment of the present application, the second sample text in the second training data is a sample text without a label. After obtaining the trained encoding model and standard matrix based on the first sample text with a label, the second sample text in the second training data is obtained, and the second sample text is converted into the first sample text with a label. Based on the converted first sample text, the trained encoding model and standard matrix are trained again.

[0102] S502: Input the second sample text in the second training data into the encoding model, and obtain a third text matrix corresponding to the second sample text output by the encoding model.

[0103] In the embodiment of the present application, the second sample text is composed of a plurality of characters, and based on a preset character-character vector dictionary, the character vector corresponding to each character in the second sample text is determined, and the character vector of each character in the second sample text is input into the encoding model, and a third text matrix of the second sample text output by the encoding model is obtained, wherein the third text matrix is ​​used to characterize the text semantics corresponding to the second sample text, and here, the encoding model is the encoding model trained through steps 401 to 405. Optionally, the encoding model is a ROBERTA model.

[0104] S503: Based on the standard matrix, perform matrix transformation on the third text matrix corresponding to the second sample text to obtain a second probability that each character in the second sample text belongs to the preset category.

[0105] In the embodiment of the present application, based on the standard matrix, the third text matrix corresponding to the second sample text is transformed into a matrix, that is, the third text matrix corresponding to the second sample text is multiplied by the standard matrix to obtain a second probability that each word in the second sample text belongs to the preset category. Here, the standard matrix is ​​the standard matrix trained through steps 401 to 405.

[0106] S504: Determine a fourth head pointer set and a fourth tail pointer set corresponding to the second sample text based on a second probability that each character in the second sample text belongs to the preset category.

[0107] In an embodiment of the present application, for each preset category, if the second probability that multiple consecutive characters in the second sample text belong to the preset category is greater than a preset threshold, the above-mentioned multiple consecutive characters are determined as the target segmentation words of the preset category, the first character of the above-mentioned multiple consecutive characters is determined as the first character of the target segmentation word, and the last character of the above-mentioned multiple consecutive characters is determined as the last character of the target segmentation word.

[0108] For each character, if the character is the first character of the target word segmentation that meets the preset category, the feature value corresponding to the character in the first first pointer set is determined as the first feature value matching the preset category; if the character is the last character of the target word segmentation that meets the preset category, the feature value corresponding to the character in the first last pointer set is determined as the second feature value matching the preset category, and a fourth first pointer set and a fourth last pointer set corresponding to the second sample text are obtained.

[0109] S505. If the second probability that each word in the second sample text belongs to the preset category meets the second preset condition, the second sample text is determined as the first sample text, and the fourth first pointer set and the fourth last pointer set corresponding to the second sample text are respectively determined as the second first pointer set and the second last pointer set corresponding to the first sample text.

[0110] In an embodiment of the present application, a second probability that each word in the second sample text belongs to the preset category is obtained. If there is a word in the second sample text whose second probability is greater than a preset threshold, it means that the second sample text includes a named entity. The second sample text is used as the first sample text in the first training data, and the fourth head pointer set corresponding to the second sample text is marked as the second head pointer set corresponding to the first sample text, and the fourth tail pointer set corresponding to the second sample text is marked as the second tail pointer set corresponding to the first sample text.

[0111] The embodiment of the present application adopts a self-training method to effectively utilize the unlabeled second training data and increase the number of first sample texts in the first training data, so that the trained encoding model and standard matrix have high stability and accuracy.

[0112] Based on the same inventive concept, the embodiment of the present application also provides a named entity extraction device corresponding to the named entity extraction method. Since the principle of solving the problem by the device in the embodiment of the present application is similar to the named entity extraction method in the embodiment of the present application, the implementation of the device can refer to the implementation of the method, and the repeated parts will not be repeated.

[0113] See also Figure 6 As shown, Figure 6 A schematic diagram of a structure of a named entity extraction device provided in an embodiment of the present application, the extraction device comprising:

[0114] A first acquisition module 601 is used to input a target text into a pre-trained encoding model, and obtain a first text matrix corresponding to the target text output by the encoding model;

[0115] A first determination module 602 is used to determine a first head pointer set and a first tail pointer set corresponding to the target text based on a first text matrix corresponding to the target text; the first head pointer set includes a first feature value of a head word of a target word in the target text that meets a preset category; the first tail pointer set includes a second feature value of a tail word of a target word in the target text that meets a preset category;

[0116] The extraction module 603 is used to extract the named entities from the target text according to the first feature value in the first head pointer set and the second feature value in the first tail pointer set, and determine the category corresponding to the named entity.

[0117] In a possible implementation manner, when the first determining module 602 determines the first head pointer set and the first tail pointer set corresponding to the target text based on the first text matrix corresponding to the target text, the first determining module 602 includes:

[0118] Based on a pre-trained standard matrix, a first text matrix corresponding to the target text is transformed to obtain a first probability that each word in the target text belongs to the preset category;

[0119] For each character in the target text, determine whether the character is the first character or the last character of the target segmentation that meets the preset category according to the first probability that the character belongs to the preset category, the first probability that other characters in the target text belong to the preset category, and the positional relationship between the other characters and the character;

[0120] Based on the judgment result of whether the character is the first character or the last character of the target word that meets the preset category, and the feature value corresponding to each judgment result, a first first pointer set and a first last pointer set corresponding to the target text are generated.

[0121] In a possible implementation, the extraction module 603, when extracting the named entity from the target text according to the first feature value in the first head pointer set and the second feature value in the first tail pointer set, and determining the category corresponding to the named entity, includes:

[0122] For each first eigenvalue in the first head pointer set, selecting a second eigenvalue from the first tail pointer set, the second eigenvalue having a category consistent with the category of the first eigenvalue and a positional relationship with the first eigenvalue that satisfies a first preset condition;

[0123] The word segment corresponding to the first feature value and the selected second feature value is determined as a named entity in the target text, and the category of the first feature value is determined as the category of the named entity.

[0124] In a possible implementation, the named entity extraction device further includes:

[0125] A first construction module is used to construct first training data, wherein the first training data includes a plurality of first sample texts, and a second head pointer set and a second tail pointer set corresponding to each first sample text;

[0126] A second acquisition module, used for inputting a first sample text in the first training data into a coding model, and acquiring a second text matrix corresponding to the first sample text output by the coding model;

[0127] A first matrix transformation module is used to perform a matrix transformation on a second text matrix corresponding to the first sample text based on a standard matrix to obtain a third head pointer set and a third tail pointer set corresponding to the first sample text;

[0128] A second determination module, configured to determine a loss value corresponding to the first sample text according to a second head pointer set and a second tail pointer set corresponding to the first sample text, and a third head pointer set and a third tail pointer set corresponding to the first sample text;

[0129] An adjustment module is used to adjust the encoding model and the standard matrix based on the loss value until the loss value corresponding to any of the first sample texts is less than a preset threshold, thereby obtaining the pre-trained encoding model and the pre-trained standard matrix.

[0130] In a possible implementation, the named entity extraction device further includes:

[0131] A second construction module, used for constructing second training data, wherein the second training data includes a plurality of second sample texts;

[0132] A third acquisition module, used for inputting the second sample text in the second training data into the encoding model, and acquiring a third text matrix corresponding to the second sample text output by the encoding model;

[0133] A second matrix transformation module, configured to perform a matrix transformation on a third text matrix corresponding to the second sample text based on the standard matrix, to obtain a second probability that each character in the second sample text belongs to the preset category;

[0134] A third determination module, configured to determine a fourth head pointer set and a fourth tail pointer set corresponding to the second sample text based on a second probability that each character in the second sample text belongs to the preset category;

[0135] The fourth determination module is used to determine the second sample text as the first sample text if the second probability that each word in the second sample text belongs to the preset category meets the second preset condition, and determine the fourth first pointer set and the fourth last pointer set corresponding to the second sample text as the second first pointer set and the second last pointer set corresponding to the first sample text, respectively.

[0136] The named entity extraction device provided in the embodiment of the present application extracts named entities from the target text based on the head pointer set and the tail pointer set corresponding to the target text, can identify updated named entities, has strong data generalization ability, and high named entity recognition efficiency.

[0137] See also Figure 7 As shown, Figure 7 An electronic device 700 is provided for an embodiment of the present application, and the electronic device 700 includes: a processor 701, a memory 702 and a bus, wherein the memory 702 stores machine-readable instructions executable by the processor 701, and when the electronic device is running, the processor 701 communicates with the memory 702 via the bus, and the processor 701 executes the machine-readable instructions to perform the steps of the method for extracting named entities as described above.

[0138] Specifically, the memory 702 and the processor 701 can be general-purpose memories and processors, which are not specifically limited here. When the processor 701 runs the computer program stored in the memory 702, the method for extracting named entities can be executed.

[0139] Corresponding to the above-mentioned method for extracting named entities, an embodiment of the present application further provides a computer-readable storage medium, on which a computer program is stored, and when the computer program is executed by a processor, the steps of the above-mentioned method for extracting named entities are executed.

[0140] Those skilled in the art can clearly understand that, for the convenience and simplicity of description, the specific working process of the system and device described above can refer to the corresponding process in the aforementioned method embodiment, and will not be repeated here. In the several embodiments provided in the present application, it should be understood that the disclosed system, device and method can be implemented in other ways. The device embodiments described above are merely schematic. For example, the division of the modules is only a logical function division. There may be other division methods in actual implementation. For example, multiple modules or components can be combined or integrated into another system, or some features can be ignored or not executed. Another point is that the mutual coupling or direct coupling or communication connection shown or discussed can be through some communication interfaces, indirect coupling or communication connection of devices or modules, which can be electrical, mechanical or other forms.

[0141] The modules described as separate components may or may not be physically separated, and the components shown as modules may or may not be physical modules, that is, they may be located in one place or distributed on multiple network modules. Some or all of the modules may be selected according to actual needs to achieve the purpose of the solution of this embodiment.

[0142] In addition, each functional module in each embodiment of the present application may be integrated into one processing module, or each module may exist physically separately, or two or more modules may be integrated into one module.

[0143] If the functions are implemented in the form of software function modules and sold or used as independent products, they can be stored in a non-volatile computer-readable storage medium that can be executed by a processor. Based on this understanding, the technical solution of the present application can be essentially or partly embodied in the form of a software product that contributes to the prior art. The computer software product is stored in a storage medium, including several 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 application. The aforementioned storage medium includes: various media that can store program codes, such as a USB flash drive, a mobile hard disk, a read-only memory (ROM), a random access memory (RAM), a magnetic disk or an optical disk.

[0144] Finally, it should be noted that the above-described embodiments are only specific implementation methods of the present application, which are used to illustrate the technical solutions of the present application, rather than to limit them. The protection scope of the present application is not limited thereto. Although the present application is described in detail with reference to the above-mentioned embodiments, ordinary technicians in the field should understand that any technician familiar with the technical field can still modify the technical solutions recorded in the above-mentioned embodiments within the technical scope disclosed in the present application, or can easily think of changes, or make equivalent replacements for some of the technical features therein; and these modifications, changes or replacements do not make the essence of the corresponding technical solutions deviate from the spirit and scope of the technical solutions of the embodiments of the present application, and should be included in the protection scope of the present application. Therefore, the protection scope of the present application shall be based on the protection scope of the claims.

Claims

1. A method for extracting named entities, characterized in that: The extraction method comprises: Inputting the target text into a pre-trained encoding model, and obtaining a first text matrix corresponding to the target text output by the encoding model; Based on a first text matrix corresponding to the target text, a first head pointer set and a first tail pointer set corresponding to the target text are determined; the first head pointer set includes a first feature value of a head word of a target word in the target text that meets a preset category; the first tail pointer set includes a second feature value of a tail word of a target word in the target text that meets a preset category; Extracting named entities from the target text according to the first feature value in the first head pointer set and the second feature value in the first tail pointer set, and determining categories corresponding to the named entities; The determining, based on the first text matrix corresponding to the target text, a first head pointer set and a first tail pointer set corresponding to the target text comprises: Based on a pre-trained standard matrix, a first text matrix corresponding to the target text is transformed to obtain a first probability that each word in the target text belongs to the preset category; For each character in the target text, determine whether the character is the first character or the last character of the target segmentation that meets the preset category according to the first probability that the character belongs to the preset category, the first probability that other characters in the target text belong to the preset category, and the positional relationship between the other characters and the character; Generate a first head pointer set and a first tail pointer set corresponding to the target text according to a judgment result of whether the character is the first character or the last character of a target word that meets a preset category, and a feature value corresponding to each judgment result; The step of extracting a named entity from the target text according to the first feature value in the first head pointer set and the second feature value in the first tail pointer set, and determining a category corresponding to the named entity, includes: For each first eigenvalue in the first head pointer set, selecting a second eigenvalue from the first tail pointer set, the second eigenvalue having a category consistent with the category of the first eigenvalue and a positional relationship with the first eigenvalue that satisfies a first preset condition; The word segment corresponding to the first feature value and the selected second feature value is determined as a named entity in the target text, and the category of the first feature value is determined as the category of the named entity.

2. The method for extracting named entities according to claim 1, characterized in that: The coding model and the standard matrix are trained in the following manner: Constructing first training data, wherein the first training data includes a plurality of first sample texts, and a second head pointer set and a second tail pointer set corresponding to each first sample text; Inputting a first sample text in the first training data into a coding model, and obtaining a second text matrix corresponding to the first sample text output by the coding model; Based on the standard matrix, a matrix transformation is performed on the second text matrix corresponding to the first sample text to obtain a third head pointer set and a third tail pointer set corresponding to the first sample text; Determine the loss value corresponding to the first sample text according to the second head pointer set and the second tail pointer set corresponding to the first sample text, and the third head pointer set and the third tail pointer set corresponding to the first sample text; The encoding model and the standard matrix are adjusted based on the loss value until the loss value corresponding to any of the first sample texts is less than a preset threshold, thereby obtaining the pre-trained encoding model and the pre-trained standard matrix.

3. The method for extracting named entities according to claim 2, characterized in that: The first training data is constructed as follows: Constructing second training data, wherein the second training data includes a plurality of second sample texts; Inputting a second sample text in the second training data into a coding model, and obtaining a third text matrix corresponding to the second sample text output by the coding model; Based on the standard matrix, a third text matrix corresponding to the second sample text is transformed to obtain a second probability that each character in the second sample text belongs to the preset category; Determine a fourth head pointer set and a fourth tail pointer set corresponding to the second sample text based on a second probability that each word in the second sample text belongs to the preset category; If the second probability that each word in the second sample text belongs to the preset category meets the second preset condition, the second sample text is determined as the first sample text, and the fourth first pointer set and the fourth last pointer set corresponding to the second sample text are respectively determined as the second first pointer set and the second last pointer set corresponding to the first sample text.

4. A named entity extraction device, characterized in that: The extraction device comprises: A first acquisition module, used for inputting a target text into a pre-trained encoding model, and acquiring a first text matrix corresponding to the target text output by the encoding model; A first determination module is used to determine a first head pointer set and a first tail pointer set corresponding to the target text based on a first text matrix corresponding to the target text; the first head pointer set includes a first feature value of a head word of a target word in the target text that meets a preset category; the first tail pointer set includes a second feature value of a tail word of a target word in the target text that meets a preset category; An extraction module, configured to extract named entities from the target text according to the first feature value in the first head pointer set and the second feature value in the first tail pointer set, and determine the category corresponding to the named entity; The first determination module, when determining a first head pointer set and a first tail pointer set corresponding to the target text based on a first text matrix corresponding to the target text, includes: Based on a pre-trained standard matrix, a first text matrix corresponding to the target text is transformed to obtain a first probability that each word in the target text belongs to the preset category; For each character in the target text, determine whether the character is the first character or the last character of the target segmentation that meets the preset category according to the first probability that the character belongs to the preset category, the first probability that other characters in the target text belong to the preset category, and the positional relationship between the other characters and the character; Generate a first head pointer set and a first tail pointer set corresponding to the target text according to a judgment result of whether the character is the first character or the last character of a target word that meets a preset category, and a feature value corresponding to each judgment result; The extraction module, when extracting the named entity from the target text according to the first feature value in the first head pointer set and the second feature value in the first tail pointer set, and determining the category corresponding to the named entity, includes: For each first eigenvalue in the first head pointer set, selecting a second eigenvalue from the first tail pointer set, the second eigenvalue having a category consistent with the category of the first eigenvalue and a positional relationship with the first eigenvalue that satisfies a first preset condition; The word segment corresponding to the first feature value and the selected second feature value is determined as a named entity in the target text, and the category of the first feature value is determined as the category of the named entity.

5. An electronic device, characterized in that: include: A processor, a memory and a bus, wherein the memory stores machine-readable instructions executable by the processor, and when the electronic device is running, the processor communicates with the memory via the bus, and the processor executes the machine-readable instructions to perform the steps of the method for extracting named entities as described in any one of claims 1 to 3.

6. A computer-readable storage medium, characterized in that: The computer-readable storage medium stores a computer program, which, when executed by a processor, executes the steps of the method for extracting named entities according to any one of claims 1 to 3.

Citation Information

Patent Citations

  • Method and device for mining entity focuses in text

    CN111274815A

  • A system for biomedical named entity recognition

    KR102139272B1