An entity recognition method, device and computer readable storage medium
Patent Information
- Application Number
- CN202310397144.4
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2023-04-11
- Publication Date
- 2026-11-03
- Estimated Expiration
- 2043-04-11
AI Technical Summary
Existing entity recognition methods cannot accurately identify non-continuous entities.
By acquiring the fragment features of text segments, calculating the hidden layer encoding representation using a pre-trained encoding model, performing entity prediction and classification based on the fragment features, introducing interval segments as a preset classification, connecting adjacent non-continuous entity segments, and identifying non-continuous entities.
It improves the accuracy of identifying non-continuous entities and avoids identification errors caused by nesting and overlapping.
Smart Images

Figure CN116644746B_ABST
Abstract
Description
Technical Field
[0001] This application relates to the field of text processing technology, and in particular to an entity recognition method, device and computer-readable storage medium. Background Technology
[0002] Entity recognition is a fundamental task in the field of natural language processing, specifically referring to the extraction of entities (or proper nouns, such as names of people, organizations, addresses, and times) with specific meanings from unstructured text. Based on whether entities are continuous in the text, they can be divided into two categories: continuous entities and non-continuous entities. Continuous entities are those that are continuous in the text, while non-continuous entities are multiple fragments scattered throughout the text that constitute the same entity.
[0003] Compared to continuous entities, discontinuous entities have more complex structures and are more difficult to identify. During their long-term research and development, the applicant of this application discovered that existing entity recognition methods cannot accurately identify discontinuous entities. Summary of the Invention
[0004] The main technical problem addressed by this application is to provide an entity recognition method, device, and computer-readable storage medium that can improve the accuracy of non-continuous entity recognition.
[0005] To address the aforementioned technical problems, this application provides a technical solution: an entity recognition method comprising: acquiring fragment features of several text segments contained in a target text; performing entity prediction and classification on each text segment based on the fragment features to obtain classification results, wherein the classification results include non-continuous entity segments, non-entity segments, and spaced segments, wherein spaced segments represent text segments located within non-continuous entities and between two adjacent non-continuous entity segments; and using non-continuous entity segments to determine the non-continuous entities contained in the target text.
[0006] Among them, determining non-continuous entities contained in the target text using non-continuous entity fragments includes: connecting non-continuous entity fragments that belong to the same non-continuous entity and are separated by interval fragments, based on the position information of each text fragment in the target text.
[0007] The non-continuous entity fragments include an entity start fragment and an entity end fragment, or an entity start fragment, an entity middle fragment, and an entity end fragment. Based on the positional information of each text fragment in the target text, the non-continuous entity fragments that belong to the same non-continuous entity and are separated by the interval fragments are connected, including: determining the entity start fragment; taking the entity start fragment as the starting point and the entity end fragment as the ending point, and according to the positional information of the text fragments in the target text, finding the entity end fragment separated by the interval fragments, or finding the entity middle fragment and entity end fragment separated by the interval fragments; and arranging the entity start fragment and the found entity end fragment or entity middle fragment and entity end fragment in sequence to form a non-continuous entity.
[0008] The classification results further include continuous entity fragments. The method includes: selecting continuous entity fragments from each text fragment and using them as continuous entities contained in the target text.
[0009] The process of obtaining fragment features of several text segments contained in the target text includes: constructing a character sequence using the target text; obtaining several text segments contained in the target text based on the character sequence; calculating the hidden layer encoding representation with contextual semantic information for each character in the character sequence using a pre-trained encoding model; for each text segment, obtaining the start encoding representation and end encoding representation from the hidden layer encoding representation using the position of the text segment in the character sequence; and concatenating the start encoding representation and end encoding representation with the segment length representation corresponding to the text segment to obtain the fragment features of the text segment.
[0010] The process of constructing a character sequence using the target text includes: dividing the target text into units of characters; adding a start character to the beginning of the target text and an end character to the end of the target text to obtain a character sequence; and, in response to the character sequence being less than a first preset length, using padding characters to fill the character sequence to the first preset length.
[0011] The method of obtaining several text segments contained in the target text based on the character sequence includes: taking each character in the character sequence as the starting point of the text segment and extracting text segments with a length less than a second preset length.
[0012] Among them, entity prediction and classification of each text segment based on segment features includes: using a pre-trained entity classification model to determine the probability that a text segment belongs to a preset classification type based on the segment features of the text segment, and selecting the classification type with the highest probability as the classification result.
[0013] To solve the above-mentioned technical problems, another technical solution adopted in this application is to provide an electronic device, including a memory and a processor coupled to each other, wherein the processor is used to execute program data stored in the memory to implement any of the above-mentioned entity recognition methods.
[0014] To solve the above-mentioned technical problems, another technical solution adopted in this application is to provide a computer-readable storage medium on which program data is stored, and when the program data is executed by a processor, it implements any of the above-mentioned entity recognition methods.
[0015] The above scheme classifies text fragments to identify the gaps between two adjacent non-continuous entity fragments located within non-continuous entities. By introducing these gaps as a pre-defined category in the fragment classification, the information of the gaps can be used to identify the non-continuous entity fragments they separate. Thus, by utilizing the classified gaps and non-continuous entity fragments, non-continuous entities in the target text can be accurately identified. Attached Figure Description
[0016] Figure 1 This is a flowchart illustrating an embodiment of the entity recognition method of this application;
[0017] Figure 2 This is a flowchart illustrating another embodiment of step S130 of this application;
[0018] Figure 3 This is a flowchart illustrating another embodiment of the entity recognition method of this application;
[0019] Figure 4 This is a flowchart illustrating another embodiment of step S310 of this application;
[0020] Figure 5 This is a flowchart illustrating another embodiment of step S411 of this application;
[0021] Figure 6 This is a schematic diagram of an embodiment of the text fragment classification results of this application;
[0022] Figure 7 This is a flowchart illustrating another embodiment of the entity recognition method of this application;
[0023] Figure 8 This is a schematic diagram of the framework of an embodiment of the entity recognition device of this application;
[0024] Figure 9 This is a schematic diagram of the framework of an embodiment of the electronic device of this application;
[0025] Figure 10 This is a schematic diagram of a framework of an embodiment of the computer-readable storage medium of this application. Detailed Implementation
[0026] To make the objectives, technical solutions, and effects of this application clearer and more explicit, the following detailed description is provided with reference to the accompanying drawings and embodiments. In the following description, specific details such as particular system structures, interfaces, and technologies are set forth for illustrative purposes rather than for limiting purposes, in order to provide a thorough understanding of this application.
[0027] In this document, the term "and / or" is merely a description of the relationship between related objects, indicating that three relationships can exist. For example, A and / or B can represent: A existing alone, A and B existing simultaneously, and B existing alone. Additionally, the character " / " generally indicates that the preceding and following related objects have an "or" relationship. Furthermore, "many" in this document means two or more. Moreover, the term "at least one" in this document means any combination of at least two of any one or more of a plurality of objects. For example, including at least one of A, B, and C can mean including any one or more elements selected from the set consisting of A, B, and C.
[0028] Please see Figure 1 , Figure 1 This is a flowchart illustrating an embodiment of the entity recognition method of this application.
[0029] Specifically, the method may include the following steps:
[0030] Step S110: Obtain the fragment features of several text segments contained in the target text.
[0031] The target text is the text used for entity recognition, that is, to identify the entities contained in the target text. The target text fragment contains several text fragments. Different text fragments may contain some of the same characters or may not contain the same characters. Each text fragment corresponds to fragment features.
[0032] For example, the text fragments included in "arm, thigh, and back muscle soreness" can include "arm", "arm", "thigh", "thigh, back", "thigh and back", "back", "back muscles", etc.
[0033] Step S120: Perform entity prediction and classification on each text segment based on segment features to obtain the classification results.
[0034] Based on whether entities are continuous in the text, entities can be divided into two categories: continuous entities and non-continuous entities. The classification results include non-continuous entity fragments, non-entity fragments, and gap fragments. Non-continuous entity fragments represent text fragments that make up a non-continuous entity, while non-entity fragments represent text fragments that do not belong to an entity. A non-continuous entity consists of at least two text fragments (non-continuous entity fragments). Gaps fragments represent text fragments located within a non-continuous entity, between two adjacent non-continuous entity fragments, connecting two non-continuous entity fragments. Specifically, gap fragments are located within a non-continuous entity, meaning their position in the target text is between the start and end characters of the non-continuous entity. During fragment classification, the pre-defined classification type of gap fragments is used to find text fragments within a non-continuous entity that do not belong to a non-continuous entity and are located between two adjacent non-continuous entity fragments. This pre-defined classification type can be applied to subsequent non-continuous entity recognition processes, and gap fragments can improve the accuracy of non-continuous entity recognition in text.
[0035] It should be noted that a corresponding classification result was obtained for each text segment.
[0036] In some embodiments, each text fragment may correspond to several classification results, that is, each text fragment may correspond to one or more tags. When determining the entities contained in the target text, any tag can be used as its corresponding tag for a text fragment with multiple tags.
[0037] In a specific application scenario, if a text segment has two or more tags, the tags of the text segment can be set as a vector, where the elements of the vector represent the probability that the segment belongs to a certain tag category. For example, the segment tags are: BE-1, BI-1, II-1, IE-1, II-N, O. If a segment is simultaneously labeled with BE-1 and BI-1, its tags can be set as the vector [1,1,0,0,0,0], where 1 in the vector indicates that the probability of the segment belonging to the BE-1 and BI-1 categories is 1.
[0038] Step S130: Use non-continuous entity fragments to identify non-continuous entities contained in the target text.
[0039] Based on the classification results above, non-continuous entity segments in all text fragments can be identified. A non-continuous entity comprises at least two non-continuous entity segments. Through the entity prediction classification described above, all non-continuous entity segments in the text fragments contained in the target text are obtained. These non-continuous entity segments can be used to identify the non-continuous entities contained in the target text.
[0040] For example, the phrase "arm, thigh, and back muscle soreness" contains three entities: "arm...muscle soreness," "thigh...muscle soreness," and "back muscle soreness." "Back muscle soreness" is a continuous entity, while "arm...muscle soreness" is composed of two text fragments: "arm" and "muscle soreness," making it a discontinuous entity in the text. Similarly, "thigh...muscle soreness" is composed of two text fragments: "thigh" and "muscle soreness," making it a discontinuous entity in the text.
[0041] In the process of entity recognition for "arm, thigh, and back muscle soreness", the classification prediction results of "arm" and "muscle soreness" are non-continuous entity segments. Using "arm" and "muscle soreness", the non-continuous entity "arm...muscle soreness" can be obtained.
[0042] The above scheme classifies text fragments to identify the gaps between two adjacent non-continuous entity fragments located within non-continuous entities. By introducing these gaps as a pre-defined category in the fragment classification, the information of the gaps can be used to identify the non-continuous entity fragments they separate. Thus, by utilizing the classified gaps and non-continuous entity fragments, non-continuous entities in the target text can be accurately identified.
[0043] Specifically, step S130 may include: connecting non-continuous entity segments that are separated by the interval segments and belong to the same non-continuous entity, based on the position information of each text segment in the target text.
[0044] Based on the positional information of each text fragment in the target text, the positional relationship between the fragments can be determined. The interval fragment represents the text fragment between two adjacent non-continuous entity fragments located inside a non-continuous entity. By connecting the text fragments that are separated by the interval fragment, belong to the same non-continuous entity, and are classified as non-continuous entity fragments, a non-continuous entity can be obtained.
[0045] For example, the target text "arm, thigh, and back muscle soreness" includes the segment ", thigh, and back". By connecting the segment "arm" and "muscle soreness", which belong to the same non-continuous entity, the non-continuous entity "arm...muscle soreness" can be obtained.
[0046] In some embodiments, when performing entity classification prediction, several types of entities can be predetermined. That is, the classification result may include several types of non-continuous entity fragments, non-entity fragments, and gap fragments. For example, non-continuous entity fragments of the person type, non-continuous entity fragments of the event type, non-continuous entity fragments of the vehicle type, non-entity fragments, and gap fragments. A non-continuous entity contains non-continuous entity fragments of the same entity type. The non-continuous entity "arm...muscle soreness" includes two disease types: "arm" and "muscle soreness."
[0047] Further, please refer to Figure 2 , Figure 2 This is a flowchart illustrating another embodiment of step S130 of this application. Specifically, step S130 may include:
[0048] Step S231: Determine the starting fragment of the entity.
[0049] In some cases, a non-contiguous entity consists of two text segments, where the earlier segment in the target text is the entity's starting segment, and the later segment is the entity's ending segment.
[0050] For example, the discontinuous entity “arm...muscle soreness” includes two discontinuous entity segments: “arm” and “muscle soreness”. “Arm” is the starting segment of the entity, and “muscle soreness” is the ending segment.
[0051] In some cases, a non-contiguous entity comprises three or more text segments. The first text segment in the target text is the entity start segment, the last text segment is the entity end segment, and the segment between the entity start segment and the entity end segment is the entity middle segment.
[0052] In some embodiments, the classification results include several types of non-continuous entity fragments. More specifically, the classification results may include several types of entity start fragments, entity middle fragments, entity end fragments, or several types of entity start fragments and entity end fragments.
[0053] For example, the classification results include the beginning segment of a person entity, the middle segment of a person entity, the ending segment of a person entity, non-entity segments, and interval segments.
[0054] After entity prediction and classification, and obtaining the classification results for each text segment in the target text, we can first filter out all the initial entity segments. Specifically, this can include initial entity segments corresponding to several different types. For example, 5 initial entity segments for people and 3 initial entity segments for things.
[0055] Step S232: Using the entity start fragment as the starting point and the entity end fragment as the ending point, according to the position information of the text fragment in the target text, find the entity end fragment that is separated by the interval fragment, or find the entity middle fragment and entity end fragment that are separated by the interval fragment.
[0056] Each entity's starting segment can serve as the starting point for a search. Based on the position of the text segment within the target text, the search proceeds forward from the entity's starting segment, following the entity's ending segment (separated by interval segments), or searching for the entity's middle and ending segments (separated by interval segments), forming a path with the entity's starting segment as the beginning and the entity's ending segment as the end. This path is formed according to the chronological order of the text segments. The entity's starting segment is the text segment that begins the entity; the entity's middle and ending segments are located after the entity's starting segment in the target text.
[0057] In some cases, a non-contiguous entity consists of two segments. In this case, the starting segment of the entity is used as the starting point, the ending segment of the entity that is separated by the interval segment is found, and the ending segment of the entity is used as the end point of the path.
[0058] In some cases, a non-contiguous entity consists of three or more segments. In this case, the starting segment of the entity is used as the starting point, and the middle segment of the entity and the ending segment of the entity are found by the interval segments. The ending segment of the entity is used as the endpoint of the path.
[0059] In some cases, starting from the beginning of an entity, the search proceeds to the middle or end of the entity. If the end of the entity cannot be found, then a complete path is not formed, and the complete non-continuous entity cannot be determined. In such cases, the search is invalid.
[0060] In some embodiments, the classification results include several types of non-continuous entity fragments. The objects targeted in a single search are non-continuous entity fragments of the same type. For example, starting from the beginning fragment of a person entity, the search finds the ending fragment of a person entity that is separated by interval fragments, or the search finds the middle fragment and the ending fragment of a person entity that are separated by interval fragments.
[0061] In a specific application scenario, the search path is the entity start segment, interval segment, and entity end segment.
[0062] In a specific application scenario, the search path is entity start segment, interval segment, entity middle segment, ..., interval segment, entity end segment. The search results include at least one entity middle segment, and each pair of adjacent non-contiguous entity segments is separated by an interval segment.
[0063] Step S233: Arrange the entity start fragment and the found entity end fragment or entity middle fragment and entity end fragment in sequence to form a non-continuous entity.
[0064] Arrange the entity's starting fragment and the found entity's ending fragment according to their order in the target text to form a non-contiguous entity. Alternatively, arrange the entity's starting fragment, the found entity's middle fragment, and the entity's ending fragment according to their order in the target text to form a non-contiguous entity.
[0065] For example, the search path is entity start fragment, interval fragment 1, entity middle fragment 1, interval fragment 2, entity middle fragment 2, interval fragment 3, entity end fragment. This path is formed according to the position information of the text fragments in the target text, arranged in chronological order, arranging entity start fragment, entity middle fragment 1, entity middle fragment 2, entity end fragment to form a non-contiguous entity.
[0066] It should be noted that text often contains multiple overlapping and nested non-continuous entities, which can lead to errors in the recognition of non-continuous entities. For example, the phrase "arm muscle fatigue and soreness" contains "arm muscle fatigue...phenomenon" and "arm muscle...soreness," which are composed of four segments: "arm muscle fatigue," "phenomenon," "arm muscle," and "soreness." The overlapping and nesting of non-continuous entities may result in two additional entities, "arm muscle fatigue...soreness" and "arm muscle...phenomenon," in addition to the two non-continuous entities mentioned above, leading to recognition errors.
[0067] The above scheme introduces interval segments. During the identification of discontinuous entities, these interval segments can be used to accurately determine whether closely connected discontinuous entity segments constitute a single discontinuous entity. Due to the presence of these interval segments, nesting and overlapping between different discontinuous entities do not interfere with entity identification, thereby improving the accuracy of discontinuous entity identification.
[0068] Please see Figure 3 , Figure 3 This is a flowchart illustrating another embodiment of the entity recognition method of this application.
[0069] Specifically, the method may include the following steps:
[0070] Step S310: Obtain the fragment features of several text segments contained in the target text.
[0071] The relevant description of step S310 can be found in the relevant content of step S110 in the foregoing embodiments, and will not be repeated here.
[0072] Step S320: Perform entity prediction and classification on each text fragment based on fragment features to obtain the classification results.
[0073] It should be noted that the classification results can include continuous entity fragments, non-continuous entity fragments, non-entity fragments, and spaced fragments. Among them, continuous entity fragments are text fragments that constitute continuous entities.
[0074] Specifically, non-continuous entity fragments can be used to identify non-continuous entities contained in the target text, while continuous entity fragments can be used to identify continuous entities contained in the target text. This allows us to obtain all entities contained in the target text.
[0075] Step S330: Use non-continuous entity fragments to identify non-continuous entities contained in the target text.
[0076] The relevant description of step S330 can be found in the previous embodiment regarding step S130, and will not be repeated here.
[0077] Step S340: Select continuous entity fragments from each text fragment and use them as continuous entities contained in the target text.
[0078] Based on the classification results of each text fragment, continuous entity fragments are selected from them. A continuous entity fragment can be regarded as a continuous entity contained in the target text.
[0079] It should be noted that the execution order of steps S330 and S340 is not restricted; they can be executed simultaneously or in any order.
[0080] In a specific application scenario, if a type C entity is determined, the classification result can include 4×C+2 categories. Specifically, these include continuous entity segments, entity start segments, entity middle segments, entity end segments, non-entity segments, and interval segments corresponding to type C.
[0081] In some embodiments, step S320 may include using a pre-trained entity classification model to determine the probability that a text segment belongs to a preset classification type based on the segment features of the text segment, and selecting the classification type with the highest probability as the classification result. The preset classification type is 4×C+2 classes. The preset classification type can be adjusted according to user needs; for example, in some cases, if only non-continuous entities need to be identified, continuous entity segments may not be included.
[0082] In a specific application scenario, the entity classification model can be a pre-trained linear classifier. The input to the linear classifier is the fragment features of the text segment, and the output result is processed by the softmax function to obtain the probability of each preset classification type. For each text segment, the classification type with the highest probability value is selected as the classification result.
[0083] The classification results are represented using the following notations: Beside (B), Inside (I), End (E), and Other (O). BE, BI, II, and IE represent continuous entity segments, entity start segments, entity middle segments, and entity end segments, respectively. * represents the entity type. Combining these, the classification results can be represented as BE-*, BI-*, II-*, and IE-*. Additionally, II-N represent interval segments, and O represents non-entity segments. Specifically, BE represents a continuous entity segment, where B on the left indicates the left end of the segment is the beginning of the entity, and E on the right indicates the right end of the segment is the end of the entity. For non-continuous entities composed of two or more segments, BI represents the entity start segment, where B on the left indicates the left end of the segment is the beginning of the entity, and I on the right indicates the right end of the segment is inside the entity. IE represents the entity end segment, where I on the left indicates the left end of the segment is inside the entity, meaning the non-continuous entity has not yet ended, and E on the right indicates the right end of the segment is the end of the entity. II represents the middle segment of the entity, and I represents the left and right ends, which are located inside the entity and need to be connected with the left and right segments to form a discontinuous entity.
[0084] In a specific application scenario, after obtaining the classification results of all text fragments, all non-entity fragments can be removed first, as these fragments are not used in determining the entities contained in the target text. Then, all consecutive entity fragments are filtered out, with each consecutive entity fragment constituting a separate consecutive entity. For the remaining non-consecutive entity fragments, the starting fragment of each entity is used as the starting point, and the ending fragment of the entity is searched within fragments of the same entity type. Alternatively, the middle fragment and the ending fragment of the entity separated by the interval fragments are searched, with the ending fragment of the entity used as the endpoint. One path can be used to determine one non-consecutive entity.
[0085] Continuing with the example of "arm muscle fatigue and soreness," we can represent the portion between adjacent entity segments using II-N, i.e., the segments "fatigue" and "soreness" in the text. We can then connect the preceding and following BI-* and IE-* segments to obtain the complete path BI-*→II-N→IE-*, thus avoiding decoding errors. Note that for non-contiguous entities composed of three or more segments, the corresponding path is BI-*→II-N→II-*→…→II-N→IE-*. When non-contiguous entities are nested or overlapping, decoding errors may occur. II-N is introduced to represent the non-entity portion between adjacent segments within an entity. In this way, non-contiguous entities can be represented as a continuous path starting from the entity's initial segment and ending at its final segment. Adjacent non-contiguous entity segments along the path are separated by interval segments, resulting in unambiguous decoding and improving the accuracy of non-contiguous entity recognition.
[0086] Please see Figure 4 , Figure 4 This is a flowchart illustrating another embodiment of step S310 of this application. Specifically, step S310 may include:
[0087] Step S411: Construct a character sequence using the target text.
[0088] The target text contains several characters. A character sequence is constructed using the characters contained in the target text.
[0089] Please see Figure 5 , Figure 5 This is a flowchart illustrating another embodiment of step S411 of this application. Specifically, step S411 may include:
[0090] Step S5111: Divide the target text into units of characters.
[0091] It should be noted that the source of the target text is not restricted; for example, it can come from the Internet or from user input. Before executing step S411, the device can also clean the acquired target text, for example, by deleting illegal characters, whitespace characters, etc.
[0092] Step S5112: Add a start character to the beginning of the target text and an end character to the end of the target text to obtain a character sequence.
[0093] After dividing the target text into character units, a start character is added to the beginning of the target text (i.e., before the first character of the target text) and an end character is added to the end of the target text (i.e. after the last character of the target text), thus obtaining a character sequence.
[0094] In a specific application scenario, <[BOS_never_used_51bce0c785ca2f68081bfa7d91973934]> token is the start character, and [SEP] token is the end character. After the target text "arm muscle fatigue and soreness phenomenon" is processed from step S5111 to step S51112, the following sequence is obtained:
[0095] <[BOS_never_used_51bce0c785ca2f68081bfa7d91973934]>, ar, m, m, u, s, c, l, e, f, a, t, i, g, u, e, ,, a, n, d, s, o, r, e, n, e, s, s, p, h, e, n, o, m, e, n, o, n, [SEP]
[0096] Step S5113: In response to the length of the character sequence being less than a first preset length, the character sequence is padded to the first preset length by using a padding character.
[0097] Herein, the first preset length may be adjusted according to actual user requirements.
[0098] In a specific application scenario, the padding character is [PAD], and the position padded with the padding character may be after the end character.
[0099] Step S412: Acquire a plurality of text segments included in the target text based on the character sequence.
[0100] Segments are extracted from the character sequence to serve as the text segments included in the target text. The extraction manner may be various, for example, each character in the character sequence is respectively used as a starting point of a text segment, and a text segment with a length less than a second preset length is extracted. The second preset length may be adjusted according to user requirements.
[0101] Further, the second preset length is determined, and in the character sequence, the position of each character is sequentially used as a start, and text segments with character lengths from zero to the second preset length are respectively extracted for each start.
[0102] In a specific application scenario, the following text segments are acquired on the basis of the character sequence "<[BOS_never_used_51bce0c785ca2f68081bfa7d91973934]>, ar, m, m, u, s, c, l, e, f, a, t, i, g, u, e, ,, a, n, d, s, o, r, e, n, e, s, s, p, h, e, n, o, m, e, n, o, n, [SEP]": "<[BOS_never_used_51bce0c785ca2f68081bfa7d91973934]>", "<[BOS_never_used_51bce0c785ca2f68081bfa7d91973934]>ar", "<[BOS_never_used_51bce0c785ca2f68081bfa7d91973934]>arm", ..., "p", "ph", "phenomenon", "phenomenon[SEP]", "h", "he", "henomenon[SEP]", ..., "[SEP]".
[0103] Step S413: Calculate hidden layer encoding representations with contextual semantic information of each character in the character sequence by using a pre-trained encoding model.
[0104] It should be noted that step S412 and step S413 are performed after step S411, and step S412 and step S413 may be performed simultaneously, or performed in any order one after another.
[0105] The encoding model processes the input character sequence to obtain a hidden-layer encoded representation of each character, representing the semantic information contained in each character, including the semantic information of the character's context. The encoding model can include, but is not limited to, the BERT model.
[0106] In some embodiments, the encoding model is a BERT model, and the pre-training process of the BERT model is divided into two stages: pre-training and fine-tuning. In the pre-training stage, the model is trained on different pre-training tasks using unlabeled data, thus incorporating a large amount of common-sense knowledge. One pre-training task is Masked Language Modeling, a cloze-style language modeling task that requires the model to select words to fill in based on context. Specifically, words in the text are randomly replaced with "[MASK]", and then the BERT model is used to reconstruct the text and predict the replaced words. For example, given the text "Potential bidders need to check email confirmation information promptly", the input sequence is "[CLS]Potential bidders need to check [MASK][MASK]confirmation information [SEP]", and the output is "email". In the fine-tuning stage, the encoding model is first initialized based on the parameters obtained from pre-training, and then all parameters are fine-tuned using labeled data from downstream specific tasks. Fine-tuning the BERT model enables it to learn domain-specific knowledge, such as relevant information in the medical field.
[0107] Specifically, the embedding vector for each character is obtained from the word embedding matrix. A positional encoding vector and a text type vector are then added to this matrix to obtain the final input vector sequence. This input vector sequence is then fed into a bidirectional encoder to capture the inter-character dependencies within the sequence, thus obtaining a hidden-layer encoded representation with contextual semantic information.
[0108] After obtaining the hidden layer encoding representation of each character in the character sequence, the fragment features of the text fragment can be obtained using the hidden layer encoding representations of the characters contained in the text fragment. There are various ways to obtain fragment features, such as concatenating the hidden layer encoding representations of each character in the text fragment.
[0109] Step S414: For each text segment, use the position of the text segment in the character sequence to obtain the start encoding representation and end encoding representation from the hidden layer encoding representation.
[0110] In this embodiment, the positions of the characters contained in the text segment in the character sequence are obtained, the start encoding representation corresponding to the first character of the text segment is obtained, and the end encoding representation corresponding to the last character of the text segment is obtained.
[0111] Step S415: Concatenate the start encoding representation, end encoding representation, and the segment length representation corresponding to the text segment to obtain the segment features of the text segment.
[0112] The device can pre-store segment length representations corresponding to the lengths of each segment, which can be obtained during pre-training. The segment length representation is related to the length of the text segment.
[0113] In a specific application scenario, a text fragment contains a character sequence (indexed starting from 0) with the character at index 0. In this case, the start and end encoding representations are both hidden layer encoding representations of the character at index 0, and the fragment length representation is the fragment length representation corresponding to a character length of 1. Concatenating these three representations yields the fragment features of the text fragment.
[0114] In a specific application scenario, a text fragment contains characters with indices 0 and 1 in a character sequence (indices starting from 0). The start encoding is represented by the hidden encoding of the character at index 0, the end encoding by the hidden encoding of the character at index 1, and the fragment length by the fragment length corresponding to a character length of 2. Concatenating these three representations yields the fragment features of the text fragment.
[0115] Please see Figure 6 , Figure 6 This is a schematic diagram of an embodiment of the text fragment classification results of this application.
[0116] As shown in the figure, the target text is "arm muscle fatigue and soreness". The target text contains two non-continuous entities, namely "arm muscle fatigue...phenomenon" and "arm muscle...soreness".
[0117] Figure 6 The diagram below illustrates the classification results of some text fragments in the target text. Specifically, the classification result for "arm muscle fatigue" is BI-Disorder (disease entity initiation fragment), the classification result for "soreness" is II-N (interval fragment), the classification result for "phenomenon" is IE-Disorder (disease entity ending fragment), the classification result for "arm muscle" is BI-Disorder (disease entity initiation fragment), the classification result for "fatigue" is II-N (interval fragment), and the classification result for "soreness phenomenon" is IE-Disorder (disease entity initiation fragment).
[0118] It should be noted that during the decoding process based on the classification results of each text fragment, there may be several decoding paths. Each decoding path corresponds to a non-continuous entity, indicating that a target text may include several non-continuous entities.
[0119] Based on the above classification results, two decoding paths can be obtained. The first path is "arm muscle fatigue" (BI-Disorder) → "soreness" (II-N) → "phenomenon" (IE-Disorder). The second path is "arm muscles" (BI-Disorder) → "fatigue" (II-N) → "soreness phenomenon" (IE-Disorder). This allows us to decode two discontinuous entities: "arm muscle fatigue...phenomenon" and "arm muscle...soreness phenomenon".
[0120] It should be noted that the device can train the entity classification model before using it for classification. During training, the encoding model can be pre-trained, or it can be fine-tuned or fine-tuned again during the entity classification model's training process. Additionally, the length embedding vector can be trained concurrently with the entity classification model.
[0121] In a specific application scenario, the entity recognition model consists of the BERT model, a linear classifier, and a set of separate-length embedding vectors. The BERT model has already undergone pre-training, and fine-tuning can be performed during the training process. Specifically, this includes: acquiring sample text, cleaning the sample text, and manually labeling non-continuous entities in the sample text according to preset rules. A sample character sequence is constructed using the sample text, in the same way as constructing a character sequence from the target text. Then, sample segments are enumerated, and entity prediction and classification are performed on each segment to obtain the sample classification result. The sample classification result is compared with the labeled non-continuous entities in the sample text. The model loss is calculated using the cross-entropy function, and the model parameters, including the parameters of the BERT model, the linear classifier, and the set of separate-length embedding vectors, are updated using gradient descent.
[0122] Please see Figure 7 , Figure 7 This is a flowchart illustrating another embodiment of the entity recognition method of this application.
[0123] As shown in the figure, after constructing the character sequence, it is input into the BERT (Bidirectional Encoder Representation from Transformers) model to obtain the hidden layer encoding representation of each character in the character sequence. The segment features of each segment are obtained by enumerating the text fragments contained in the character sequence and concatenating the hidden layer encoding representations of the first and last characters with the length embedding vector (segment length representation). A linear classifier is used to perform entity prediction classification on each segment based on the segment features, obtaining the classification result for each segment. Based on the classification results, an entity decoding algorithm is used to obtain the non-continuous entities in the target text. The specific decoding process can be found in the description of step S130.
[0124] Please see Figure 8 , Figure 8 This is a schematic diagram of the framework of an embodiment of the entity recognition device of this application.
[0125] In this embodiment, the entity recognition device 80 includes an acquisition module 81, a classification module 82, and a decoding module 83. The acquisition module 81 can be used to acquire fragment features of several text segments contained in the target text; the classification module 82 can be used to perform entity prediction classification on each text segment based on the fragment features to obtain a classification result, wherein the classification result includes non-continuous entity segments, non-entity segments, and spaced segments, where spaced segments represent text segments located within non-continuous entities and between two adjacent non-continuous entity segments; the decoding module 83 can be used to determine the non-continuous entities contained in the target text using the non-continuous entity segments.
[0126] The decoding module 83 can be used to determine the non-continuous entities contained in the target text using non-continuous entity fragments. Specifically, it includes connecting non-continuous entity fragments that are separated by interval fragments and belong to the same non-continuous entity based on the position information of each text fragment in the target text.
[0127] The non-continuous entity fragments include an entity start fragment and an entity end fragment, or an entity start fragment, an entity middle fragment, and an entity end fragment. The decoding module 83 can be used to connect non-continuous entity fragments belonging to the same non-continuous entity, separated by intervals, based on the positional information of each text fragment in the target text. Specifically, this includes: determining the entity start fragment; using the entity start fragment as the starting point and the entity end fragment as the ending point, according to the positional information of the text fragments in the target text, finding the entity end fragment separated by the intervals, or finding the entity middle fragment and entity end fragment separated by the intervals; and sequentially arranging the entity start fragment with the found entity end fragment or entity middle fragment and entity end fragment to form a non-continuous entity.
[0128] The classification results further include continuous entity fragments. The decoding module 83 can also be used to filter continuous entity fragments from each text fragment and use them as continuous entities contained in the target text.
[0129] The acquisition module 81 may include a construction unit, a partitioning unit, an encoding unit, an acquisition unit, and a concatenation unit. The construction unit can be used to construct a character sequence using the target text; the partitioning unit can be used to acquire several text segments contained in the target text based on the character sequence; the encoding unit can be used to calculate the hidden layer encoding representation with contextual semantic information for each character in the character sequence using a pre-trained encoding model; the acquisition unit can be used to acquire the start encoding representation and the end encoding representation from the hidden layer encoding representation for each text segment using the position of the text segment in the character sequence; and the concatenation unit can be used to concatenate the start encoding representation and the end encoding representation with the segment length representation corresponding to the text segment to obtain the segment features of the text segment.
[0130] The construction unit can include a division subunit, an addition subunit, and a filling subunit. The division subunit can be used to divide the target text into units of characters. The addition subunit can be used to add a start character to the beginning of the target text and an end character to the end of the target text to obtain a character sequence. The filling subunit can be used to fill the character sequence to the first preset length using filling characters in response to the length of the character sequence being less than the first preset length.
[0131] The segmentation unit is used to obtain several text segments contained in the target text based on the character sequence, specifically including: taking each character in the character sequence as the starting point of the text segment and extracting text segments with a length less than a second preset length.
[0132] The classification module 82 is used to perform entity prediction classification on each text segment based on segment features. Specifically, it includes: using a pre-trained entity classification model to determine the probability that a text segment belongs to a preset classification type based on the segment features of the text segment, and selecting the classification type with the highest probability as the classification result.
[0133] Please see Figure 9 , Figure 9 This is a schematic diagram of the framework of an embodiment of the electronic device of this application.
[0134] In this embodiment, the electronic device 90 includes a memory 91 and a processor 92, wherein the memory 91 is coupled to the processor 92. Specifically, the various components of the electronic device 90 can be coupled together via a bus, or the processor 92 of the electronic device 90 can be connected to each other component individually. The electronic device 90 can be any device with processing capabilities, such as a computer, tablet computer, mobile phone, etc.
[0135] The memory 91 is used to store program data executed by the processor 92, as well as data generated by the processor 92 during processing. Examples include text fragments and classification results. The memory 91 includes a non-volatile storage portion for storing the aforementioned program data.
[0136] Processor 92 controls the operation of electronic device 90. Processor 92 can also be called CPU (Central Processing Unit). Processor 92 may be an integrated circuit chip with signal processing capabilities. Processor 92 can also be a general-purpose processor, digital signal processor (DSP), application-specific integrated circuit (ASIC), field-programmable gate array (FPGA), or other programmable logic device, discrete gate or transistor logic device, or discrete hardware component. General-purpose processor can be a microprocessor or any conventional processor. In addition, processor 92 can be implemented by multiple integrated circuit chips.
[0137] The processor 92 executes instructions to implement any of the above-mentioned entity identification methods by calling the program data stored in the memory 91.
[0138] Please see Figure 10 , Figure 10 This is a schematic diagram of a framework of an embodiment of the computer-readable storage medium of this application.
[0139] In this embodiment, the computer-readable storage medium 100 stores processor-executable program data 101, which can be executed to implement any of the above-described entity recognition methods.
[0140] The computer-readable storage medium 100 can be a USB flash drive, a portable hard drive, a read-only memory (ROM), a random access memory (RAM), a magnetic disk, or an optical disk, or it can be a server storing the program data 101. The server can send the stored program data to other devices for execution, or it can run the stored program data itself.
[0141] In some embodiments, the computer-readable storage medium 100 may also be such as Figure 9 The memory shown.
[0142] The above description is merely an embodiment of this application and does not limit the patent scope of this application. Any equivalent structural or procedural transformations made using the content of this application's specification and drawings, or direct or indirect applications in other related technical fields, are similarly included within the patent protection scope of this application.
Claims
1. An entity recognition method, characterized in that, The method includes: Obtain the fragment features of several text segments contained in the target text; Based on the fragment features, entity prediction classification is performed on each of the text fragments to obtain classification results. The classification results include non-continuous entity fragments, non-entity fragments, and spaced fragments. The spaced fragments represent text fragments located within non-continuous entities and between two adjacent non-continuous entity fragments. The non-continuous entities contained in the target text are determined using the non-continuous entity fragments; The step of determining the non-continuous entities contained in the target text using the non-continuous entity fragments includes: connecting non-continuous entity fragments that are separated by the interval fragments and belong to the same non-continuous entity based on the position information of each text fragment in the target text; the non-continuous entity fragment includes an entity start fragment and an entity end fragment, the entity start fragment and the entity end fragment are arranged in sequence to form the non-continuous entity; or, the non-continuous entity fragment includes an entity start fragment, an entity middle fragment and an entity end fragment, the entity start fragment, the entity middle fragment and the entity end fragment are arranged in sequence to form the non-continuous entity.
2. The method according to claim 1, characterized in that, The step of connecting non-contiguous entity segments belonging to the same non-contiguous entity, separated by the interval segments, based on the position information of each text segment in the target text includes: Determine the initial segment of the entity; Starting from the entity's initial segment and ending from the entity's final segment, the entity's middle segment and entity's final segment are located within the target text according to the position information of the text segment within the target text; or, the entity's final segment is located within the interval segment. The entity's starting segment is arranged sequentially with the found entity's ending segment, or the entity's middle segment and the entity's ending segment, to form the non-continuous entity.
3. The method according to claim 1, characterized in that, The classification result further includes continuous entity fragments, and the method includes: The continuous entity fragments are selected from the text fragments and used as continuous entities contained in the target text.
4. The method according to claim 1, characterized in that, The step of obtaining fragment features of several text segments contained in the target text includes: Construct a character sequence using the target text; Based on the character sequence, obtain several text segments contained in the target text; The hidden layer encoding representation with contextual semantic information of each character in the character sequence is calculated using a pre-trained encoding model; For each of the text segments, the start encoding representation and the end encoding representation are obtained from the hidden layer encoding representation using the position of the text segment in the character sequence; The start encoding representation and end encoding representation are concatenated with the segment length representation corresponding to the text segment to obtain the segment feature of the text segment.
5. The method according to claim 4, characterized in that, The step of constructing a character sequence using the target text includes: The target text is divided into units of characters; Add a start character to the beginning of the target text and an end character to the end of the target text to obtain the character sequence; In response to the character sequence having a length less than a first preset length, the character sequence is padded to the first preset length using padding characters.
6. The method according to claim 4, characterized in that, The step of obtaining several text fragments contained in the target text based on the character sequence includes: Each character in the character sequence is used as the starting point of the text segment, and a text segment with a length less than a second preset length is extracted.
7. The method according to claim 4, characterized in that, The entity prediction and classification of each text segment based on the segment features includes: The probability of a text segment belonging to a preset classification type is determined based on the segment features of the text segment using a pre-trained entity classification model, and the classification type with the highest probability is selected as the classification result.
8. An electronic device, characterized in that, The device includes a memory and a processor coupled to each other, the processor being used to execute program data stored in the memory to implement the entity recognition method according to any one of claims 1 to 7.
9. A computer-readable storage medium storing program data thereon, characterized in that, When the program data is executed by the processor, it implements the entity recognition method according to any one of claims 1 to 7.
Citation Information
Patent Citations
Discontinuous disease entity extraction method and device and electronic equipment
CN114820212A
Method and apparatus for recognizing medical entity in medical text
US20210342539A1
