Entity recognition method and device and electronic equipment
By using position encoding to identify the head and tail words in the text in the entity recognition method, the accuracy problem of traditional methods when dealing with nested or overlapping entities is solved, and more efficient and accurate entity recognition is achieved, improving the performance of network security technology.
Patent Information
- Application Number
- CN202411648517.1
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-11-18
- Publication Date
- 2025-03-14
- Estimated Expiration
- 2044-11-18
AI Technical Summary
Traditional entity recognition methods are not efficient and accurate when processing unstructured or semi-structured texts unique to the field of network security, especially when facing nested or overlapping entity types, they cannot accurately identify all entities.
By obtaining multiple participles in the text to be identified, the position code of each participle is determined, and the head and tail words are then identified, and the target entity type is determined based on these position codes, and all entities included in the text are finally combined.
It improves the accuracy of entity recognition, especially in the presence of nesting or overlapping, and can identify entity boundaries more finely, reduce false alarms and irrelevant alarms, and improve the response speed and targetedness of network security technology.
Smart Images

Figure CN119623468A_ABST
Abstract
Description
Technical Field
[0001] The present application relates to the field of network security technology, and in particular to an entity identification method, device and electronic device. Background Art
[0002] In the field of network security, entity recognition technology is a basic natural language processing technology that can automatically extract key information from text, such as IP addresses, user names, device identifiers, etc. This information is crucial for a variety of security operations in the field of network security. However, with the increasing complexity of the network environment and the increasing number of security threats, traditional security entity recognition technology faces more and more challenges.
[0003] Traditional entity recognition methods are usually based on rules or statistical learning models. These methods work well when processing texts with simple structures and standardized formats, but their efficiency and accuracy are often unsatisfactory when faced with unstructured or semi-structured texts that are unique to the field of network security.
[0004] In recent years, with the development of deep learning technology, entity recognition methods based on neural networks have gradually emerged. For example, the Bidirectional Encoder Representations from Transformers (BERT) model can capture the contextual relationships in the text through a pre-trained bidirectional Transformer network, thereby improving the performance of entity recognition. However, BERT mainly relies on absolute position encoding to process position information in the text, which still has limitations when processing text containing long-distance dependencies. In addition, when there is nesting or overlap between entities belonging to different entity types in the text, BERT cannot accurately identify all entities included in the text. Summary of the invention
[0005] The embodiments of the present application provide an entity recognition method, device and electronic device to solve the problem that related technologies cannot accurately recognize all entities when there is nesting or overlap between entities belonging to different entity types in a text.
[0006] In a first aspect, an embodiment of the present application provides an entity recognition method, comprising: obtaining multiple word segments included in a text to be recognized; determining a position code of each word segment according to the positions of each of the multiple word segments in the text to be recognized; determining a head word segment and a tail word segment included in the multiple word segments, and a target entity type corresponding to the head word segment and the tail word segment according to the position code of each word segment; the head word segment represents a word segment located at the starting position of any entity, and the tail word segment represents a word segment located at the ending position of any entity; determining at least one target entity included in the text to be recognized according to the positions of each of the head word segment and the tail word segment corresponding to the same target entity type in the text to be recognized.
[0007] In a possible implementation, determining the position code of each word segment according to the positions of each word segment in the text to be recognized includes: determining the embedding vectors corresponding to each word segment according to the arrangement positions of each word segment in the text to be recognized; determining the position codes of each word segment according to the embedding vectors corresponding to each word segment and the relative position relationship between the word segment.
[0008] In a possible implementation, the determining the position codes of the multiple segmentations according to the embedding vectors corresponding to the multiple segmentations and the relative position relationship between the multiple segmentations includes: obtaining a relative position difference mapping of the text to be recognized; the relative position difference mapping includes the relative position difference between every two segmentations in the multiple segmentations; for any one of the multiple segmentations, performing the following operations respectively: in the relative position difference mapping, obtaining a reference relative position difference between the any one segmentation and each other segmentation in the multiple segmentations according to the arrangement position of the any one segmentation; determining each relative position score between the any one segmentation and each other segmentation according to each obtained reference relative position difference; the relative position score corresponds to the reference relative position difference one by one, and the relative position score is positively correlated with the reference relative position difference; determining each attention score between the any one segmentation and each other segmentation according to the embedding vectors corresponding to the multiple segmentations and the determined relative position scores; encoding the any one segmentation according to each determined attention score to obtain the position code of the any one segmentation.
[0009] In a possible implementation, the determining, according to the position code of each segmentation, the head segmentation and the tail segmentation included in the multiple segmentations, and the target entity type corresponding to the head segmentation and the tail segmentation, includes: for any one of the at least one preset entity type, performing the following operations respectively: for any one of the multiple segmentations, based on the position code of the any one segmentation and the head prediction model and the tail prediction model corresponding to the any one entity type, determining a first probability that the any one segmentation is the head segmentation corresponding to the any one entity type, and a second probability that the any one segmentation is the tail segmentation corresponding to the any one entity type; when there is a first probability that satisfies a preset first probability condition, and there is a second probability that satisfies a preset second probability condition, determining the any one entity type as the target entity type; using the segmentation corresponding to the first probability that satisfies the preset first probability condition as the head segmentation corresponding to the target entity type, and using the segmentation corresponding to the second probability that satisfies the preset second probability condition as the tail segmentation corresponding to the target entity type.
[0010] In a possible implementation, after determining the first probability that the segmentation is the head segmentation corresponding to any one entity type and the second probability that the segmentation is the tail segmentation corresponding to any one entity type based on the position coding of the segmentation and the head prediction model and the tail prediction model corresponding to any one entity type, the method further includes: performing head marking on the segmentation belonging to the first probability that satisfies the preset first probability condition, and performing tail marking on the segmentation belonging to the second probability that satisfies the preset second probability condition; when both the head marking and the tail marking exist, determining that any one entity type is the target entity type; using the segmentation corresponding to the first probability that satisfies the preset first probability condition as the head segmentation corresponding to the target entity type, and using the segmentation corresponding to the second probability that satisfies the preset second probability condition as the tail segmentation corresponding to the target entity type, includes: using the segmentation containing the head marking as the head segmentation corresponding to the target entity type; using the segmentation containing the tail marking as the tail segmentation corresponding to the target entity type.
[0011] In a possible implementation, before determining, for the multiple word segmentations, based on the position codes of the word segmentations and the head prediction model and the tail prediction model corresponding to the any entity type, the first probability that the word segmentation is the head word segmentation corresponding to the any entity type, and the second probability that the word segmentation is the tail word segmentation corresponding to the any entity type, the method further includes: for the any entity type, constructing a pointer matrix corresponding to the any entity type; the pointer matrix includes a head row and a tail row; the head marking of the word segmentation belonging to the first probability that meets the preset first probability condition, and the tail marking of the word segmentation belonging to the second probability that meets the preset second probability condition, include: when there is a first probability that meets the preset first probability condition in the first probabilities of each of the multiple word segmentations, the head marking is performed at the position corresponding to the corresponding word in the head row of the pointer matrix; when there is a second probability that meets the preset second probability condition in the second probabilities of each of the multiple word segmentations, the tail marking is performed at the position corresponding to the corresponding word in the tail row of the pointer matrix.
[0012] In a possible implementation, the method of determining at least one target entity included in the text to be recognized based on the positions of head word segments and tail word segments corresponding to the same target entity type in the text to be recognized comprises: for any one of the at least one target entity type, performing the following operations respectively: combining the head word segments, tail word segments, and word segments located between the head word segments and tail word segments corresponding to the any one entity type into a target entity.
[0013] In a second aspect, an embodiment of the present application provides an entity recognition device, including:
[0014] An acquisition unit, used for acquiring a plurality of segmented words included in the text to be recognized;
[0015] A processing unit is used to determine the position code of each word segment according to the respective positions of the multiple word segments in the text to be recognized; determine the head word segment and the tail word segment included in the multiple word segments, and the target entity type corresponding to the head word segment and the tail word segment according to the position code of each word segment; the head word segment represents the word segment located at the starting position of any entity, and the tail word segment represents the word segment located at the ending position of any entity; determine at least one target entity included in the text to be recognized according to the respective positions of the head word segment and the tail word segment corresponding to the same target entity type in the text to be recognized.
[0016] In a possible implementation, the processing unit determines the position code of each word segment according to the positions of each word segment in the text to be recognized, and is specifically used to: determine the embedding vectors corresponding to each word segment according to the arrangement positions of each word segment in the text to be recognized; determine the position code of each word segment according to the embedding vectors corresponding to each word segment and the relative position relationship between the word segment.
[0017] In a possible implementation, the processing unit determines the position codes of each of the multiple participles according to the embedding vectors corresponding to each of the multiple participles and the relative position relationship between the multiple participles, and is specifically used to: obtain a relative position difference mapping of the text to be recognized; the relative position difference mapping includes the relative position difference between every two participles in the multiple participles; for any one of the multiple participles, the following operations are performed respectively: in the relative position difference mapping, according to the arrangement position of the any one participle, a reference relative position difference between the any one participle and each other participle in the multiple participles is obtained; according to each obtained reference relative position difference, each relative position score between the any one participle and each other participle is determined; the relative position score corresponds to the reference relative position difference one by one, and the relative position score is positively correlated with the reference relative position difference; according to the embedding vectors corresponding to each of the multiple participles and the determined relative position scores, each attention score between the any one participle and each other participle is determined; according to each determined attention score, the any one participle is encoded to obtain the position code of the any one participle.
[0018] In a possible implementation, the processing unit determines the head part and tail part included in the multiple participles, and the target entity type corresponding to the head part and tail part according to the position code of each participle, and is specifically used to: for any one of the at least one preset entity type, perform the following operations respectively: for any one of the multiple participles, based on the position code of the any one participle and the head prediction model and tail prediction model corresponding to the any one entity type, determine the first probability that the any one participle is the head part corresponding to the any one entity type, and the second probability that the any one participle is the tail part corresponding to the any one entity type; when there is a first probability that satisfies a preset first probability condition, and there is a second probability that satisfies a preset second probability condition, determine the any one entity type as the target entity type; use the participle corresponding to the first probability that satisfies the preset first probability condition as the head part corresponding to the target entity type, and use the participle corresponding to the second probability that satisfies the preset second probability condition as the tail part corresponding to the target entity type.
[0019] In a possible implementation, the processing unit determines the first probability that the segmentation is the head segmentation corresponding to any one of the entity types, and the second probability that the segmentation is the tail segmentation corresponding to any one of the entity types based on the position code of the segmentation and the head prediction model and the tail prediction model corresponding to any one of the entity types, and is further used to: perform head marking on the segmentation belonging to the first probability that meets the preset first probability condition, and perform tail marking on the segmentation belonging to the second probability that meets the preset second probability condition; when both the head marking and the tail marking exist, determine that any one of the entity types is the target entity type;
[0020] The processing unit uses the segmentation corresponding to the first probability that meets the preset first probability condition as the head segmentation corresponding to the target entity type, and uses the segmentation corresponding to the second probability that meets the preset second probability condition as the tail segmentation corresponding to the target entity type, specifically for: using the segmentation containing the head annotation as the head segmentation corresponding to the target entity type; using the segmentation containing the tail annotation as the tail segmentation corresponding to the target entity type.
[0021] In a possible implementation, the processing unit is further used to: construct a pointer matrix corresponding to any one entity type for the multiple word segments, based on the position codes of the word segments and the head prediction model and the tail prediction model corresponding to any one entity type, before determining the first probability that the word segment is the head word segment corresponding to any one entity type and the second probability that the word segment is the tail word segment corresponding to any one entity type; the pointer matrix includes a head row and a tail row;
[0022] The processing unit performs head marking on word segments that belong to the first probability and meet the preset first probability condition, and performs tail marking on word segments that belong to the second probability and meet the preset second probability condition, and is specifically used for: when there is a first probability that meets the preset first probability condition among the first probabilities of the multiple word segments, the position corresponding to the corresponding word in the head row of the pointer matrix is marked with the head; when there is a second probability that meets the preset second probability condition among the second probabilities of the multiple word segments, the position corresponding to the corresponding word in the tail row of the pointer matrix is marked with the tail.
[0023] In one possible implementation, the processing unit determines at least one target entity included in the text to be recognized based on the positions of the head word fragment and the tail word fragment corresponding to the same target entity type in the text to be recognized, and is specifically used to: for any one of the at least one target entity type, perform the following operations respectively: combine the head word fragment, the tail word fragment, and the participle located between the head word fragment and the tail word fragment corresponding to the any one entity type into a target entity.
[0024] In a third aspect, an embodiment of the present application provides an electronic device, including:
[0025] Memory, for storing computer instructions;
[0026] A processor is connected to the memory, and is used to execute computer instructions in the memory, and implement the method as described in any one of the first aspects when executing the computer instructions.
[0027] In a fourth aspect, an embodiment of the present application provides a computer-readable storage medium, including:
[0028] The computer-readable storage medium stores computer instructions, and when the computer instructions are executed on a computer, the computer is enabled to perform the method as described in any one of the first aspects.
[0029] The beneficial effects of this application are as follows:
[0030] The embodiments of the present application provide an entity recognition method, apparatus, device and storage medium, the method comprising: obtaining multiple word segments included in a text to be recognized, and determining a position code of each word segment according to the respective positions of the multiple word segments in the text to be recognized; determining a head word segment and a tail word segment included in the multiple word segments, and a target entity type corresponding to the head word segment and the tail word segment according to the position code of each word segment; determining at least one target entity included in the text to be recognized according to the respective positions of the head word segment and the tail word segment corresponding to the same target entity type in the text to be recognized, wherein the head word segment represents a word segment located at the starting position of any entity, and the tail word segment represents a word segment located at the ending position of any entity.
[0031] The embodiment of the present application can determine the starting position and ending position of the entity by determining the head participle and tail participle included in multiple participles, so it can provide more sophisticated context analysis and entity boundary recognition capabilities, and because it does not directly recognize the entire entity, but identifies the target entity through the starting position and the ending position, so when there is nesting or overlap, the present application can combine all the entities included in the text as long as the corresponding head participle and the corresponding tail participle are identified, thereby improving the accuracy of entity recognition. Further, since the accuracy of entity recognition is improved, in the field of network security technology, it can also greatly reduce the false positives and irrelevant alarms of related entities, thereby increasing the attention and processing efficiency of relevant technical personnel to real threats.
[0032] Other features and advantages of the present application will be described in the subsequent description, and partly become apparent from the description, or be understood by practicing the present application. The purpose and other advantages of the present application can be realized and obtained by the structures specifically pointed out in the written description, claims, and drawings. BRIEF DESCRIPTION OF THE DRAWINGS
[0033] In order to more clearly illustrate the embodiments of the present application or the technical solutions in the prior art, the drawings required for describing the embodiments will be briefly introduced below. Obviously, the drawings described below are only some embodiments of the present application.
[0034] Figure 1 A schematic diagram of the system architecture for the application of the entity recognition method provided in the embodiment of the present application;
[0035] Figure 2 An exemplary flow chart of an entity recognition method provided in an embodiment of the present application;
[0036] Figure 3 A schematic diagram of the position encoding process provided in an embodiment of the present application;
[0037] Figure 4 A schematic diagram of a pointer matrix provided in an embodiment of the present application;
[0038] Figure 5 A schematic diagram of the marking process provided in an embodiment of the present application;
[0039] Figure 6 A schematic diagram of a process of an entity recognition method provided in an embodiment of the present application;
[0040] Figure 7 A schematic diagram of an entity recognition device provided in an embodiment of the present application;
[0041] Figure 8 A schematic diagram of the structure of an electronic device provided in an embodiment of the present application. DETAILED DESCRIPTION
[0042] In order to facilitate understanding of the technical solutions provided by the embodiments of the present application, the professional terms involved in the embodiments of the present application are introduced below.
[0043] (1) Entities are words or phrases in a text that have a specific meaning or proper name. They usually represent certain specific objects, people, places, organizations, time, etc. The goal of entity recognition is to identify these entities from the text and classify them into different categories.
[0044] In order to make the purpose, technical solution and advantages of the embodiments of the present application clearer, the technical solution 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 part of the embodiments of the technical solution of the present application, rather than all of the embodiments. Based on the embodiments recorded in the application documents, all other embodiments obtained by ordinary technicians in this field without creative work are within the scope of protection of the technical solution of the present application.
[0045] The terms "first" and "second" in the embodiments of the present application are used to distinguish different objects, rather than to describe a specific order. In addition, the term "comprising" and any of their variations are intended to cover non-exclusive protection. For example, a process, method, system, product or device comprising a series of steps or units is not limited to the listed steps or units, but optionally also includes steps or units that are not listed, or optionally also includes other steps or units inherent to these processes, methods, products or devices. "Multiple" in the present application can mean at least two, for example, two, three or more, and the embodiments of the present application are not limited.
[0046] In addition, the term "and / or" in this article is only a description of the association relationship of associated objects, indicating that there can be three relationships. For example, A and / or B can represent: A exists alone, A and B exist at the same time, and B exists alone. In addition, the character " / " in this article, unless otherwise specified, generally indicates that the associated objects before and after are in an "or" relationship.
[0047] In the field of network security, entity recognition technology is a basic natural language processing technology, but traditional entity recognition methods are usually based on rules or statistical learning models. These methods work well when processing texts with simple structures and standardized formats, but their efficiency and accuracy are often unsatisfactory when facing unstructured or semi-structured texts that are unique to the field of network security.
[0048] In recent years, with the development of deep learning technology, entity recognition methods based on neural networks have gradually emerged. For example, the BERT model can capture the contextual relationship in the text through a pre-trained bidirectional Transformer network, thereby improving the performance of entity recognition. However, BERT mainly relies on absolute position encoding to process the position information in the text, which still has limitations when processing text containing long-distance dependencies. In addition, when there is nesting or overlap between entities belonging to different entity types in the text, BERT cannot accurately identify all entities included in the text.
[0049] In view of this, an embodiment of the present application provides an entity recognition method, which includes: obtaining multiple word segments included in a text to be recognized. According to the positions of each of the multiple word segments in the text to be recognized, determining the position code of each word segment, and then according to the position code of each word segment, determining the head word segment and the tail word segment included in the multiple word segments, and the target entity type corresponding to the head word segment and the tail word segment, and finally determining at least one target entity included in the text to be recognized according to the positions of each of the head word segment and the tail word segment corresponding to the same target entity type in the text to be recognized.
[0050] By using the above method, the head word segment and tail word segment included in multiple word segmentations are determined, and the starting position and ending position of the entity can be determined, so that a more sophisticated context analysis and entity boundary recognition capability can be provided, and because the entire entity is not directly recognized, but the target entity is recognized by the starting position and the ending position, when there is nesting or overlap, the present application can combine all entities included in the text as long as the corresponding head word segment and the corresponding tail word segment are recognized, thereby improving the accuracy of entity recognition. Furthermore, since the accuracy of entity recognition is improved, in the field of network security technology, it can also greatly reduce the false positives and irrelevant alarms of related entities, thereby improving the attention and processing efficiency of relevant technical personnel to real threats.
[0051] See also Figure 1A schematic diagram of the system architecture of the entity recognition method provided in the embodiment of the present application. The system can be a server 100, including: a memory 110, a processor 120 and a communication interface 130. Among them, the communication interface 130 can be used to obtain multiple segmented words included in the text to be recognized. The processor 120 is the control center of the server 100, and uses various interfaces and lines to connect the various parts of the entire server 100. By running or executing the software program or module stored in the memory 110, and calling the data stored in the memory 110, the various functions of the server 100 and the processing data are executed. When executing the entity recognition method provided in the embodiment of the present application, the processor 120 can be used to determine the position code of each segmented word according to the position of each of the multiple segmented words included in the text to be recognized in the text to be recognized. According to the position code of each segmented word, the head segmented words and the tail segmented words included in the multiple segmented words, as well as the target entity type corresponding to the head segmented words and the tail segmented words are determined; the head segmented words represent the segmented words located at the starting position of any entity, and the tail segmented words represent the segmented words located at the ending position of any entity. At least one target entity included in the text to be recognized is determined according to the positions of the head word segment and the tail word segment corresponding to the same target entity type in the text to be recognized.
[0052] Optionally, the processor 120 may include one or more processing units. The memory 110 may be a high-speed random access memory, or a non-volatile memory, such as at least one disk storage device, a flash memory device, or other volatile solid-state storage devices.
[0053] It should be noted that the above Figure 1 The structure shown is only an example and is not limited to this embodiment of the present application.
[0054] See also Figure 2 An exemplary flow chart of an entity recognition method provided in an embodiment of the present application, which can be applied to Figure 1 The server 100 shown may include the following process:
[0055] S201, obtaining a plurality of word segments included in the text to be recognized.
[0056] The text to be identified can be the text included in the data such as security logs, malware descriptions, attacker strategies, security vulnerability reports, etc. generated by the network and system. The entities that can be identified in these texts include but are not limited to key information such as IP addresses, domain names, hash values, vulnerability numbers, timestamps, user IDs, and operation codes.
[0057] In some embodiments, when the server obtains the text to be recognized, it may obtain the text to be recognized for entity recognition from the system that needs entity recognition as the text to be recognized. For example, obtain each security log stored in the security log management system and use each security log as the text to be recognized respectively, and execute the entity recognition method provided by the embodiments of the present application respectively.
[0058] In other embodiments, when the server obtains the text to be recognized, it may also obtain the text to be recognized for entity recognition input by the user in the terminal device through the network, and then execute the entity recognition method provided by the embodiments of the present application on the text to be recognized.
[0059] After the server obtains the text to be recognized, it may first perform a word segmentation operation on the text to be recognized to obtain multiple word segments (tokens) included in the text to be recognized. This word segmentation operation may also be performed by a word segmenter. The word segmenter may be included in the encoding model. For example, WordPiece, SentencePiece, etc. in models such as BERT. Or, the word segmenter may be independent of the encoding model. For example, when the text to be recognized is in Chinese, jieba word segmentation may be used to perform word segmentation on the text to be recognized, and then the segmented result is input into the encoding model constructed in the embodiments of the present application. The present application does not make any limitations in this regard.
[0060] It should be noted that the word segmentation in the present application may also be referred to as a token or a sub-word. Depending on the language and the word segmentation algorithm, the composition of each word segment may be different. For example, for English characters in the text to be recognized, a word segment may correspond to a single word, such as "apple", or the root of a word, such as "app"; for Chinese characters in the text to be recognized, a word segment may correspond to a single character. For example, "日期" can be divided into 2 word segments: "日" and "期"; for Arabic numerals in the text to be recognized, a word segment may correspond to a string of numbers, such as "2021"; in addition, a word segment may also correspond to a string composed of numbers and letters, such as "APT28".
[0061] S202. Determine the position encoding of each word segment according to the position of each word segment in the text to be recognized.
[0062] In a possible implementation manner, when the server determines the position encoding of each word segment according to the position of each word segment in the text to be recognized, it may determine the embedding vector corresponding to each word segment according to the arrangement position of each word segment in the text to be recognized. Then, according to the embedding vector corresponding to each word segment and the relative position relationship between the word segments, determine the position encoding of each word segment. Among them, the arrangement position may refer to the absolute position of the word segment.
[0063] In one example, when determining the embedding vectors corresponding to multiple word segments, the text to be recognized can be input into the encoding model, and the encoding model performs word segmentation embedding (Token Embeddings), sentence embedding (Segment Embeddings) and position embedding (Position Embeddings) on the text to be recognized to obtain the embedding vector corresponding to each word segment.
[0064] Among them, the encoding model used in this application is built based on the BERT model, which combines relative position encoding and absolute position encoding. The input embedding operation in the RaBERT model is the same as that in the BERT model.
[0065] Specifically, word segmentation embedding can be achieved by using the WordPiece word segmentation algorithm in the RaBERT model to split the text to be recognized into smaller units (such as roots, prefixes, or suffixes). At this time, these units can be called "word segments". For example, "playing" may be split into ['play', '##ing']. Each word segment has a corresponding embedding, which is obtained by looking up the vocabulary. Each word segment corresponds to a fixed-size vector (for example, 768 dimensions) to represent the semantic information of the word unit.
[0066] Sentence embedding is used to determine whether each word in the text to be recognized belongs to sentence A or sentence B when the text to be recognized consists of two sentences. For example, for all words in sentence A, their sentence embedding can be set to 0, indicating that these words belong to sentence A; for all words in sentence B, their sentence embedding can be set to 1, indicating that these words belong to sentence B. When the text to be recognized consists of only one sentence, only E is used. A .
[0067] Position embedding is used to add position information to each word segment, indicating the arrangement position of each word in the text to be recognized. Specifically, absolute position encoding can be used to map each arrangement position to a position vector, and these position vectors are added to the word segment embedding so that the encoding model can understand the order relationship between each word segment in the text to be recognized.
[0068] For each word segment, the above three embeddings are added together to obtain the embedding vector corresponding to the corresponding word segment, satisfying formula (1).
[0069] E i = E Ti + E Si+ E Pi Formula (1)
[0070] In the formula, E i represents the embedding vector of the i-th word segment, E Ti represents the word embedding of the i-th word, E Si represents the sentence embedding of the i-th word, E Pi Represents the position embedding of the i-th word.
[0071] It should be noted that the dimension of the embedding vector corresponding to each word segment is usually 768 dimensions. In specific applications, the dimension can be configured in the encoding model according to actual needs, and this application does not limit this.
[0072] In some embodiments, when determining the position encodings of multiple word segmentations based on the embedding vectors corresponding to each of the multiple word segmentations and the relative position relationship between the multiple word segmentations in the RaBERT model, the relative position difference mapping of the text to be recognized can be obtained first, wherein the relative position difference mapping includes the relative position difference between every two word segmentations in the multiple word segmentations.
[0073] After obtaining the relative position difference mapping, you can perform the following operations on any of the multiple segmented words to determine the position encoding of each segmented word:
[0074] In the relative position difference mapping, according to the arrangement position of any segmentation, the reference relative position difference between any segmentation and other segmentations in multiple segmentations is obtained. According to the obtained reference relative position differences, the relative position scores between any segmentation and other segmentations are determined. According to the embedding vectors corresponding to the multiple segmentations and the determined relative position scores, the attention scores between any segmentation and other segmentations are determined. According to the determined attention scores, any segmentation is encoded to obtain the position encoding of any segmentation. Among them, the relative position score corresponds to the reference relative position difference one by one, and the relative position score is positively correlated with the reference relative position difference.
[0075] Specifically, the relative position difference mapping can be determined after determining the embedding vectors corresponding to the multiple word segments. The relative position difference mapping can be a relative position difference table. Assuming that the text to be recognized includes n word segments, the word segment numbers can be 1 to n, and the relative position difference between two word segments i and j is Δ ij =ij, i and j are both 1 to n. At this time, we can define a matrix R with dimension n, where the element R in the i-th row and j-th column is ij That is, the reference relative position difference between i and j, and the matrix R is the relative position difference table.
[0076] Furthermore, the data R in the ijth row of the matrix Ri-j That is, the reference relative position difference vector between i and j.
[0077] When calculating the relative position score, it can be calculated using formula (2).
[0078] S ij =Q i ·R i-j Formula (2)
[0079] In the formula, S ij is the relative position score between i and j, Q i is the query vector of the i-th word segmentation, R i-j is the reference relative position difference vector between i and j.
[0080] According to the embedding vectors corresponding to the multiple participles and the determined relative position scores, when calculating the attention scores between any participle and the other participles, the calculation can be performed using formula (3).
[0081]
[0082] Where Q is the query vector, K is the key, V is the value, and S is the relative position score.
[0083] For example, assuming that the text to be recognized includes tokenA, tokenB and tokenC, when determining the position code of the word segmentation tokenA, the reference relative position difference between tokenA and tokenB, and the reference relative position difference between tokenA and tokenC can be found in the relative position difference mapping based on the arrangement position of tokenA in the text to be recognized.
[0084] Then, according to the reference relative position difference found, the relative position score between tokenA and tokenB, and the relative position score between tokenA and tokenC are calculated by formula (2). Then, using formula (3), the attention score between tokenA and tokenB, and the attention score between tokenA and tokenC are determined. Finally, the position code of the segmentation tokenA is determined according to the attention score.
[0085] After that, continue to determine the position codes of tokenB and tokenC respectively according to the above method.
[0086] See also Figure 3 Schematic diagram of the position encoding process provided in the embodiment of the present application. Figure 3 As shown, it is assumed that the text to be recognized includes words T1 to T n, the coding model is the RaBERT model proposed in the embodiment of the present application, then through the RaBERT model, according to the above position coding method, T1 can be position-coded to obtain C1, T2 can be position-coded to obtain C2, T3 can be position-coded to obtain C3, and so on, the position codes C1 to C n Among them, C1~C n The dimension of can be 768 dimensions.
[0087] The above method can combine absolute position encoding and relative position encoding in the attention mechanism, so that the encoding model can consider both their absolute position and relative position when parsing the relationship between each pair of word segments. Absolute position information provides information about the fixed position of words in the text. It helps the model grasp the overall layout of the sentence and the sequential relationship of its components. Relative position information emphasizes the distance and relationship between words, which is particularly important for understanding the deep meaning of complex sentences. This dual position encoding strategy provides a more comprehensive understanding of the text, allowing the model to more accurately capture and utilize long-distance dependencies, thereby improving the accuracy and efficiency of entity recognition.
[0088] S203, determining the head word segment and the tail word segment included in the multiple word segments, and the target entity types corresponding to the head word segment and the tail word segment according to the position code of each word segment.
[0089] The head participle represents the participle located at the starting position of any entity, and the tail participle represents the participle located at the ending position of any entity.
[0090] Before executing the entity recognition method provided in the embodiment of the present application, at least one entity type that may be included in the text to be recognized may be set according to the actual application scenario. For example, in the field of network security, entity types may include attack types, vulnerabilities, attackers, attack organizations, tools, etc. In addition, entity types such as time, place, and name may also be included, which are not limited in the present application.
[0091] After setting at least one entity type, the corresponding head prediction model and tail prediction model can be trained for each entity type to predict whether a certain word is the head word corresponding to the entity type, and whether a certain word is the tail word corresponding to the entity type. The training method can refer to the model training method in the relevant technology, and this application will not elaborate on it.
[0092] In a possible implementation, S203 may be specifically performed as follows:
[0093] For any entity type of at least one preset entity type, perform the following operations:
[0094] For any one of multiple word segments, respectively based on the position encoding of any one of the word segments and the head prediction model and tail prediction model corresponding to any one entity type, determine the first probability that any one of the word segments is the head word segment corresponding to any one entity type, and the second probability that any one of the word segments is the tail word segment corresponding to any one entity type.
[0095] When there is a first probability that meets the preset first probability condition and a second probability that meets the preset second probability condition, determine that any one entity type is the target entity type, and use the word segment corresponding to the first probability that meets the preset first probability condition as the head word segment corresponding to the target entity type, and use the word segment corresponding to the second probability that meets the preset second probability condition as the tail word segment corresponding to the target entity type. Wherein, the target entity type represents the entity type included in the text to be recognized.
[0096] For example, assume that the word segments included in the text to be recognized are respectively "black", "hacker", "group", "organization", "APT28". Then for the attacker type in the entity type, according to the position encoding of "black", determine the first probability that "black" is the head word segment corresponding to the attacker type, and the second probability that "black" is the tail word segment corresponding to the attacker type; according to the position encoding of "hacker", determine the first probability that "hacker" is the head word segment corresponding to the attacker type, and the second probability that "hacker" is the tail word segment corresponding to the attacker type; according to the position encoding of "group", determine the first probability that "group" is the head word segment corresponding to the attacker type, and the second probability that "group" is the tail word segment corresponding to the attacker type, and so on, to obtain the first probability and the second probability corresponding to each word segment. Assume that the first probability of "APT28" meets the preset first probability condition, and the second probability of "APT28" meets the preset second probability condition, then it can be determined that the attacker type is the target entity type, and "APT28" is the head word segment and tail word segment corresponding to the attacker type.
[0097] Specifically, in the head prediction model corresponding to any one entity type, the first probability that each word segment is the head word segment corresponding to any one entity type can be determined by formula (4).
[0098]
[0099] In the formula, represents the first probability that the i-th word segment is the head word segment corresponding to any one entity type, σ represents the activation function, x i represents the position encoding of the i-th word segment, W start represents the weight matrix in the trained head prediction model corresponding to any one entity type. b startRepresents the bias matrix in the trained head prediction model corresponding to any entity type.
[0100] In the tail prediction model corresponding to any entity type, the second probability that any word segment is the tail word segment corresponding to any entity type can be determined by formula (5).
[0101]
[0102] In the formula, represents the first probability that the i-th word is the tail word corresponding to any entity type, σ represents the activation function, x i represents the positional encoding of the i-th word, W end Represents the weight matrix in the trained tail prediction model corresponding to any entity type. b end Represents the bias matrix in the trained tail prediction model corresponding to any entity type.
[0103] Among them, the weight matrix and the bias matrix are obtained after the head prediction model and the tail prediction model are trained.
[0104] In a possible implementation, the preset first probability condition may be that the first probability is greater than or equal to the first probability threshold, and similarly, the preset second probability condition may be that the second probability is greater than or equal to the second probability threshold. The first probability threshold and the second probability threshold may be set based on experience or actual conditions, and the first probability threshold and the second probability threshold may be the same or different. For example, the first probability threshold and the second probability threshold may both be 0.7, or the first probability threshold may be 0.6, and the second probability threshold may be 0.7, etc., and this application does not limit this.
[0105] In some embodiments, after determining the first probability that each participle is the head participle corresponding to any entity type, and the second probability that each participle is the tail participle corresponding to any entity type, the server can perform head marking on the participles that belong to the first probability and meet the preset first probability condition, and perform tail marking on the participles that belong to the second probability and meet the preset second probability condition. When both the head marking and the tail marking exist, any entity type is determined to be the target entity type. In this case, after performing the head marking and the tail marking, when determining the head participle and the tail participle, the participle containing the head marking can be used as the head participle corresponding to the target entity type. The participle containing the tail marking can be used as the tail participle corresponding to the target entity type.
[0106] Optionally, when performing head marking and tail marking, different numbers can be used for annotation. For example, when performing head marking on a participle that belongs to a first probability and satisfies a preset first probability condition, the participle can be marked as 1, and when performing tail marking on a participle that belongs to a second probability and satisfies a preset second probability condition, the participle can be marked as 2.
[0107] In a possible implementation, before determining the first probability that each word segment is a head word segment corresponding to any entity type and the second probability that each word segment is a tail word segment corresponding to any entity type, the server may also construct a pointer matrix corresponding to any entity type for any entity type. The pointer matrix may include a head row and a tail row.
[0108] Specifically, the server can construct corresponding pointer matrices for at least one preset entity type, and obtain at least one pointer matrix including a head row and a tail row. The number of columns of the pointer matrix is the same as the number of segmented words included in the text to be recognized. For example, assuming that 9 entity types are pre-configured, 9 pointer matrices can be constructed, each pointer matrix including a head row and a tail row.
[0109] See also Figure 4 Schematic diagram of the pointer matrix provided in the embodiment of the present application. Assuming that there are three entity types: entity type A, entity type B and entity type C, and the text to be recognized includes 10 segmented words, the constructed pointer matrix is as follows: Figure 4 As shown, entity type A, entity type B and entity type C correspond to a pointer matrix of 2 rows and 10 columns respectively, and each element in the matrix is 0.
[0110] In some embodiments, after constructing the pointer matrix corresponding to each entity type, when the head of the segmented words belonging to the first probability that meets the preset first probability condition is marked, and the tail of the segmented words belonging to the second probability that meets the preset second probability condition is marked, when there is a first probability that meets the preset first probability condition among the first probabilities of the multiple segmented words, the head marking can be performed at the position corresponding to the corresponding segmented words in the head row of the pointer matrix. When there is a second probability that meets the preset second probability condition among the second probabilities of the multiple segmented words, the tail marking can be performed at the position corresponding to the corresponding segmented words in the tail row of the pointer matrix.
[0111] Specifically, when the position corresponding to the corresponding word in the head row of the pointer matrix is marked as a head, the position corresponding to the corresponding word in the head row of the pointer matrix can be marked as 1. Similarly, when the position corresponding to the corresponding word in the tail row of the pointer matrix is marked as a tail, the position corresponding to the corresponding word in the head and tail rows of the pointer matrix can be marked as 1. Then, after marking, 1 can be used to indicate that the word is a head word or a tail word of the corresponding entity type, and 0 can be used to indicate that the word is not a head word or a tail word of the corresponding entity type.
[0112] based on Figure 4 When marking the head and tail words in the pointer matrix shown in Figure 5 A schematic diagram of the labeling process provided for an embodiment of the present application, assuming that after determining the first probabilities of each word segmentation and the second probabilities of each word segmentation, the first probability that the third word segmentation is the head word segment of entity type A is greater than the first probability threshold, then the third element in the head row of the pointer matrix corresponding to entity type A can be labeled as 1, that is, the element in the first row and third column is changed from 0 to 1; assuming that the second probability that the fourth word segmentation is the tail word segment of entity type A is greater than the second probability threshold, then the fourth element in the tail row of the pointer matrix corresponding to entity type A can be labeled as 1, that is, the element in the second row and fourth column is changed from 0 to 1.
[0113] If the first probability that the third word segmentation is the head word of entity type B is greater than the first probability threshold, the third element in the head row of the pointer matrix corresponding to entity type B can be marked as 1, that is, the element in the first row and third column is changed from 0 to 1; assuming that the second probability that the sixth word segmentation is the tail word of entity type B is greater than the second probability threshold, the sixth element in the tail row of the pointer matrix corresponding to entity type B can be marked as 1, that is, the element in the second row and sixth column is changed from 0 to 1.
[0114] If the first probability that each word segmentation is the head word segment of entity type C is less than the first probability threshold, the elements of the head row of the pointer matrix corresponding to entity type C will not be modified. Similarly, if the second probability that each word segmentation is the tail word segment of entity type C is less than the second probability threshold, the elements of the tail row of the pointer matrix corresponding to entity type C will not be modified. At this time, it can be determined that entity type C is not the target entity type, that is, the text to be identified does not include entities of entity type C.
[0115] Based on the above scheme, through the head and tail annotations in the pointer matrix, these nested or complex entities can be effectively identified and classified, and the relationship between them can be understood, thereby helping relevant personnel to quickly obtain and analyze threat intelligence, improve response speed and the pertinence of preventive measures.
[0116] S204, determining at least one target entity included in the text to be recognized according to the positions of the head word segment and the tail word segment corresponding to the same target entity type in the text to be recognized.
[0117] In one possible implementation, S204 can be executed to perform the following operations for any one of the at least one target entity types: combine the head word segment, tail word segment, and word segment between the head word segment and the tail word segment corresponding to any one of the entity types into a target entity.
[0118] In some embodiments, when an entity type corresponds to only one head word and one tail word, the head word, tail word, and word segmentation between the head word and the tail word corresponding to the entity type can be directly combined into a target entity.
[0119] For example, assuming that the head word corresponding to the attacker type is the second word in the text to be recognized, and the tail word corresponding to the attacker type is the fourth word in the text to be recognized, the second word, the third word, and the fourth word are combined into a target entity, and the entity type of the target entity is the attacker type.
[0120] In other embodiments, when an entity type corresponds to multiple head words or multiple tail words, the head words and tail words corresponding to the entity type that are closest can be determined according to the principle of proximity, and the head words and tail words that are closest, as well as the participles located between the head words and tail words that are closest, can be combined into the target entity.
[0121] For example, assuming that the head word corresponding to the attack organization type is the second word in the text to be identified, and the tail word corresponding to the attacker type is the fifth and eighth words in the text to be identified, since the second word is closest to the fifth word, the second word, the third word, the fourth word and the fifth word are combined into a target entity, and the entity type of the target entity is the attack organization type.
[0122] Below, in order to more clearly understand the solution proposed in the embodiments of the present application, an entity recognition method provided by the present application will be introduced in combination with a specific embodiment.
[0123] See also Figure 6 , is a process diagram of an entity recognition method provided in an embodiment of the present application,
[0124] Assume that the preset entity types include: attack organization, attacker, IP address and date, and the text to be identified is: "The hacker organization APT28 attacked the target company in October 2021". Then, the text to be identified can be segmented to obtain: "black", "customer", "group", "organization", "APT28", "in", "2021", "year", "10", "month", "attack", "attack", "target", "standard", "company", "company". Then, position code each segmented word respectively to obtain position codes C1~C 17 , and then calculate the probability p of each word being the head word corresponding to the attack organization according to the above method i Astart , is the probability p of the tail word corresponding to the attack organization i Aend ; Calculate the probability p that each word is the head word corresponding to the attacker i Bstart , is the probability p of the tail word corresponding to the attacker i Bend ; Calculate the probability p that each word is the head word corresponding to the IP address i Cstart , is the probability p of the tail word corresponding to the IP address i Cend ; Calculate the probability p that each word is the head word corresponding to the date i Dstart , is the probability p of the tail word corresponding to the date i Dend . The value of i ranges from 1 to 17.
[0125] Assume p5 Astart If p5 is greater than the first probability threshold, the fifth element in the head row of the pointer matrix corresponding to the attacking organization can be marked as 1. Aend If the probability of the attack organization is greater than the second probability threshold, the fifth element in the tail row of the pointer matrix corresponding to the attack organization can be marked as 1.
[0126] p7 Dstart is greater than the first probability threshold, then the seventh element in the head row of the pointer matrix corresponding to the date can be marked as 1. Assuming that p 10 Dend If the probability of the date is greater than the second probability threshold, the 10th element in the tail row of the pointer matrix corresponding to the date can be marked as 1.
[0127] After marking, we can get Figure 6According to the annotations in the pointer matrix shown, it can be determined that the target entities included in the text to be identified are "APT28" and "October 2021", among which the entity type of "APT28" is the attack organization, and the entity type of "October 2021" is the date.
[0128] Based on the same concept of the above method, see Figure 7 , is an entity recognition device 700 provided in an embodiment of the present application, the device 700 can execute each step in the above method, and the device 700 includes an acquisition unit 701 and a processing unit 702. In one scenario:
[0129] An acquisition unit 701 is used to acquire a plurality of segmented words included in the text to be recognized;
[0130] Processing unit 702 is used to determine the position code of each word segment according to the respective positions of the multiple word segments in the text to be recognized; determine the head word segment and the tail word segment included in the multiple word segments, and the target entity type corresponding to the head word segment and the tail word segment according to the position code of each word segment; the head word segment represents the word segment located at the starting position of any entity, and the tail word segment represents the word segment located at the ending position of any entity; determine at least one target entity included in the text to be recognized according to the respective positions of the head word segment and the tail word segment corresponding to the same target entity type in the text to be recognized.
[0131] In a possible implementation, the processing unit 702 determines the position code of each word segment according to the positions of each word segment in the text to be recognized, and is specifically used to: determine the embedding vectors corresponding to each word segment according to the arrangement positions of each word segment in the text to be recognized; determine the position codes of each word segment according to the embedding vectors corresponding to each word segment and the relative position relationship between the word segment.
[0132] In a possible implementation, the processing unit 702 determines the position codes of each of the multiple segmentations according to the embedding vectors corresponding to each of the multiple segmentations and the relative position relationship between the multiple segmentations, and is specifically used to: obtain a relative position difference mapping of the text to be recognized; the relative position difference mapping includes the relative position difference between every two segmentations in the multiple segmentations; for any one of the multiple segmentations, the following operations are performed respectively: in the relative position difference mapping, according to the arrangement position of the any one segmentation, a reference relative position difference between the any one segmentation and each other segmentation in the multiple segmentations is obtained; according to each obtained reference relative position difference, each relative position score between the any one segmentation and each other segmentation is determined; the relative position score corresponds to the reference relative position difference one by one, and the relative position score is positively correlated with the reference relative position difference; according to the embedding vectors corresponding to each of the multiple segmentations and the determined relative position scores, each attention score between the any one segmentation and each other segmentation is determined; according to each determined attention score, the any one segmentation is encoded to obtain the position code of the any one segmentation.
[0133] In a possible implementation, the processing unit 702 determines the head part word and the tail part word included in the multiple part word according to the position code of each part word, and the target entity type corresponding to the head part word and the tail part word, and is specifically used to: for any one of the at least one preset entity type, perform the following operations respectively: for any one of the multiple part word, based on the position code of the any one part word and the head prediction model and the tail prediction model corresponding to the any one entity type, determine the first probability that the any one part word is the head part word corresponding to the any one entity type, and the second probability that the any one part word is the tail part word corresponding to the any one entity type; when there is a first probability that satisfies a preset first probability condition, and there is a second probability that satisfies a preset second probability condition, determine the any one entity type as the target entity type; use the part word corresponding to the first probability that satisfies the preset first probability condition as the head part word corresponding to the target entity type, and use the part word corresponding to the second probability that satisfies the preset second probability condition as the tail part word corresponding to the target entity type.
[0134] In a possible implementation, the processing unit 702 determines the first probability that the segmentation is the head segmentation corresponding to any one of the entity types, and the second probability that the segmentation is the tail segmentation corresponding to any one of the entity types based on the position code of the segmentation and the head prediction model and the tail prediction model corresponding to any one of the entity types, and is further used to: perform head marking on the segmentation belonging to the first probability that meets the preset first probability condition, and perform tail marking on the segmentation belonging to the second probability that meets the preset second probability condition; when both the head marking and the tail marking exist, determine that any one of the entity types is the target entity type;
[0135] The processing unit 702 uses the segmentation corresponding to the first probability that meets the preset first probability condition as the head segmentation corresponding to the target entity type, and uses the segmentation corresponding to the second probability that meets the preset second probability condition as the tail segmentation corresponding to the target entity type, specifically for: using the segmentation containing the head annotation as the head segmentation corresponding to the target entity type; using the segmentation containing the tail annotation as the tail segmentation corresponding to the target entity type.
[0136] In a possible implementation, the processing unit 702 determines, for the multiple word segments, a first probability that the word segment is a head word segment corresponding to the any one entity type, and a second probability that the word segment is a tail word segment corresponding to the any one entity type based on the position codes of the word segment and the head prediction model and the tail prediction model corresponding to the any one entity type, and is further used to: construct a pointer matrix corresponding to the any one entity type; the pointer matrix includes a head row and a tail row;
[0137] The processing unit 702 performs head marking on the word segments that belong to the first probability and meet the preset first probability condition, and performs tail marking on the word segments that belong to the second probability and meet the preset second probability condition, and is specifically used for: when there is a first probability that meets the preset first probability condition among the first probabilities of the multiple word segments, the position corresponding to the corresponding word in the head row of the pointer matrix is marked with the head; when there is a second probability that meets the preset second probability condition among the second probabilities of the multiple word segments, the position corresponding to the corresponding word in the tail row of the pointer matrix is marked with the tail.
[0138] In one possible implementation, the processing unit 702 determines at least one target entity included in the text to be recognized based on the positions of the head word segment and the tail word segment corresponding to the same target entity type in the text to be recognized, and is specifically used to: for any one of the at least one target entity type, perform the following operations respectively: combine the head word segment, the tail word segment, and the word segment located between the head word segment and the tail word segment corresponding to the any one entity type into a target entity.
[0139] Based on the same concept of the above method, see Figure 8 , is a schematic diagram of the structure of an electronic device provided in an embodiment of the present application, the electronic device includes at least one processor 802, and a memory 801 connected or coupled to the at least one processor 802, and further, the electronic device may also include a communication interface 803. The electronic device may exchange information with other devices through the communication interface 803.
[0140] Exemplarily, the communication interface 803 may be a transceiver, circuit, bus, module, pin or other type of communication interface. When the electronic device is a chip-type device or circuit, the communication interface 803 in the electronic device may also be an input-output circuit that can input information (or receive information) and output information (or send information), and the processor is an integrated processor or microprocessor or integrated circuit or logic circuit, and the processor may determine output information based on input information.
[0141] The coupling in the embodiment of the present application is an indirect coupling or communication connection between devices, units or modules, which can be electrical, mechanical or other forms, and is used for information exchange between devices, units or modules. The processor 802 may cooperate with the memory 801 and the communication interface 803. The specific connection medium between the above-mentioned processor 802, memory 801 and communication interface 803 is not limited in this application.
[0142] Optional, see Figure 8 The processor 802, the memory 801 and the communication interface 803 are connected to each other via a bus. The bus may be a peripheral component interconnect (PCI) bus or an extended industry standard architecture (EISA) bus. The bus may be divided into an address bus, a data bus, a control bus, etc. For ease of representation, Figure 8 Only one thick line is used in the diagram, but this does not mean that there is only one bus or only one type of bus.
[0143] In the embodiment of the present application, the memory 801 is a non-volatile computer-readable storage medium, which can be used to store non-volatile software programs, non-volatile computer executable programs and modules. The memory 801 may include at least one type of storage medium, for example, it may include flash memory, hard disk, multimedia card, card-type memory, random access memory (Random Access Memory, RAM), static random access memory (Static Random Access Memory, SRAM), programmable read-only memory (Programmable Read Only Memory, PROM), read-only memory (ReadOnly Memory, ROM), electrically erasable programmable read-only memory (Electrically ErasableProgrammable Read-Only Memory, EEPROM), magnetic memory, disk, optical disk, etc. The memory 801 is any other medium that can be used to carry or store the desired program code in the form of instructions or data structures and can be accessed by a computer, but is not limited thereto. The memory 801 in the embodiment of the present application can also be a circuit or any other device that can realize a storage function, for storing instructions, computer programs and / or data.
[0144] In the embodiment of the present application, the processor 802 can be a general-purpose processor, such as a central processing unit (CPU), a digital signal processor, an application-specific integrated circuit, a field programmable gate array or other programmable logic device, a discrete gate or transistor logic device, a discrete hardware component, and can implement or execute the various methods, steps and logic block diagrams disclosed in the embodiment of the present application. The general-purpose processor can be a microprocessor or any conventional processor, etc. The steps of the entity recognition method disclosed in the embodiment of the present application can be directly embodied as a hardware processor to be executed, or the hardware and software modules in the processor can be combined and executed.
[0145] By designing and programming the processor 802, the code corresponding to the entity recognition method introduced in the aforementioned embodiment can be solidified into the chip, so that the chip can execute the steps of the aforementioned entity recognition method during operation. How to design and program the processor 802 is a technology well known to those skilled in the art and will not be repeated here.
[0146] In one or more embodiments, the memory 801 stores instructions that can be executed by at least one processor 802 , and the at least one processor 802 can implement the steps of any of the above methods by calling the instructions or computer programs stored in the memory 801 .
[0147] The embodiment of the present application further provides a computer-readable storage medium on which computer instructions are stored. When the computer instructions are executed on a computer, the computer executes the steps of any of the above methods.
[0148] Based on the same inventive concept, the embodiment of the present application also provides a computer program product, which includes: computer program code, when the computer program code is run on a computer, the computer executes any of the entity recognition methods discussed above. Since the principle of solving the problem by the above computer program product is similar to that of the entity recognition method, the implementation of the above computer program product can refer to the implementation of the method, and the repeated parts will not be repeated.
[0149] Those skilled in the art can understand that all or part of the steps of implementing the above-mentioned method embodiments can be completed by hardware related to program instructions. The aforementioned program can be stored in a computer-readable storage medium. When the program is executed, the steps of the above-mentioned method embodiments are executed; and the aforementioned storage medium includes: ROM, RAM, disk or optical disk and other media that can store program codes.
[0150] Although the specific embodiments of the present application are described above, it should be understood by those skilled in the art that these are merely examples, and the scope of protection of the present application is limited by the attached claims. Those skilled in the art may make various changes or modifications to these embodiments without departing from the principles and essence of the present application, but these changes and modifications all fall within the scope of protection of the present application. Although the preferred embodiments of the present application have been described, once those skilled in the art are aware of the basic creative concepts, additional changes and modifications may be made to these embodiments. Therefore, the attached claims are intended to be interpreted as including the preferred embodiments and all changes and modifications falling within the scope of the present application.
[0151] Obviously, those skilled in the art can make various changes and modifications to the present application without departing from the scope of the present application. Thus, if these modifications and variations of the present application fall within the scope of the claims of the present application and their equivalents, the present application is also intended to include these modifications and variations.
Claims
1. An entity recognition method, characterized in that: include: Obtain multiple word segments included in the text to be recognized; Determine a position code of each segmented word according to the positions of each of the multiple segmented words in the to-be-recognized text; According to the position code of each participle, determine the head participle and the tail participle included in the multiple participles, and the target entity types corresponding to the head participle and the tail participle; the head participle represents the participle located at the starting position of any entity, and the tail participle represents the participle located at the ending position of any entity; At least one target entity included in the text to be recognized is determined according to the positions of the head word segment and the tail word segment corresponding to the same target entity type in the text to be recognized.
2. The method according to claim 1, characterized in that Determining the position code of each segmented word according to the positions of each of the multiple segmented words in the to-be-recognized text includes: Determine the embedding vectors corresponding to the multiple word segments according to the arrangement positions of the multiple word segments in the text to be recognized; According to the embedding vectors corresponding to the multiple word segments and the relative position relationship between the multiple word segments, the position codes of the multiple word segments are determined.
3. The method according to claim 2, characterized in that The determining the position codes of the multiple word segments according to the embedding vectors corresponding to the multiple word segments and the relative position relationship between the multiple word segments includes: Acquire a relative position difference mapping of the text to be recognized; the relative position difference mapping includes a relative position difference between every two participles in the plurality of participles; For any one of the multiple participles, perform the following operations: In the relative position difference mapping, a reference relative position difference between the arbitrary word and each other word in the plurality of word segments is obtained according to the arrangement position of the arbitrary word segment; Determine the relative position scores between the arbitrary word and the other word according to the obtained reference relative position differences; the relative position scores correspond to the reference relative position differences one by one, and the relative position scores are positively correlated with the reference relative position differences; Determine, according to the embedding vectors corresponding to the multiple participles and the determined relative position scores, respective attention scores between the any participle and each of the other participles; According to the determined attention scores, any one of the word segments is encoded to obtain a position code of the any one of the word segments.
4. The method according to claim 1, characterized in that The step of determining, according to the position code of each participle, the head participle and the tail participle included in the multiple participles, and the target entity types corresponding to the head participle and the tail participle, comprises: For any entity type of at least one preset entity type, perform the following operations: For any one of the multiple participles, based on the position code of the any one participle and the head prediction model and the tail prediction model corresponding to the any one entity type, determine a first probability that the any one participle is a head participle corresponding to the any one entity type, and a second probability that the any one participle is a tail participle corresponding to the any one entity type; When there is a first probability that satisfies a preset first probability condition, and there is a second probability that satisfies a preset second probability condition, determining that any one entity type is a target entity type; The word segment corresponding to the first probability that meets the preset first probability condition is used as the head word segment corresponding to the target entity type, and the word segment corresponding to the second probability that meets the preset second probability condition is used as the tail word segment corresponding to the target entity type.
5. The method according to claim 4, characterized in that After determining the first probability that the segmentation is the head segmentation corresponding to the any one entity type and the second probability that the segmentation is the tail segmentation corresponding to the any one entity type based on the position code of the segmentation and the head prediction model and the tail prediction model corresponding to the any one entity type, the method further includes: Marking the head of the word segmentation with the first probability attribution that meets the preset first probability condition, and marking the tail of the word segmentation with the second probability attribution that meets the preset second probability condition; When both the head annotation and the tail annotation exist, determining any one entity type as a target entity type; The step of using the word segment corresponding to the first probability that satisfies the preset first probability condition as the head word segment corresponding to the target entity type, and using the word segment corresponding to the second probability that satisfies the preset second probability condition as the tail word segment corresponding to the target entity type includes: Using the word segment containing the head annotation as the head word segment corresponding to the target entity type; The word segment containing the tail tag is used as the tail word segment corresponding to the target entity type.
6. The method according to claim 5, characterized in that Before determining, for the multiple word segments, a first probability that the word segment is a head word segment corresponding to any one of the entity types and a second probability that the word segment is a tail word segment corresponding to any one of the entity types based on the position codes of the word segment and the head prediction model and the tail prediction model corresponding to any one of the entity types, the method further includes: For any one of the entity types, construct a pointer matrix corresponding to the any one of the entity types; the pointer matrix includes a head row and a tail row; The step of marking the head of the word segmentation attribution of the first probability that meets the preset first probability condition, and marking the tail of the word segmentation attribution of the second probability that meets the preset second probability condition, includes: When there is a first probability that satisfies a preset first probability condition among the first probabilities of the plurality of word segments, a head mark is performed at a position corresponding to the corresponding word segment in the head row of the pointer matrix; When there is a second probability satisfying a preset second probability condition among the second probabilities of the plurality of word segments, a tail mark is performed on a position corresponding to the corresponding word segment in the tail row of the pointer matrix.
7. The method according to any one of claims 1 to 6, characterized in that: The step of determining at least one target entity included in the text to be recognized according to the positions of the head word and the tail word corresponding to the same target entity type in the text to be recognized comprises: For any entity type of the at least one target entity type, perform the following operations respectively: The head part word, the tail part word, and the participle located between the head part word and the tail part word corresponding to any one of the entity types are combined into a target entity.
8. An entity recognition device, characterized in that: include: An acquisition unit, used for acquiring a plurality of segmented words included in the text to be recognized; A processing unit, configured to determine a position code of each segmented word according to the positions of each of the multiple segmented words in the text to be recognized; According to the position code of each participle, the head participle and the tail participle included in the multiple participles, and the target entity types corresponding to the head participle and the tail participle are determined; the head participle represents the participle located at the starting position of any entity, and the tail participle represents the participle located at the ending position of any entity; according to the positions of the head participle and the tail participle corresponding to the same target entity type in the text to be recognized, at least one target entity included in the text to be recognized is determined.
9. An electronic device, characterized in that: include: Memory, for storing computer instructions; A processor is connected to the memory, and is used to execute computer instructions in the memory, and implement the method according to any one of claims 1 to 7 when executing the computer instructions.
10. A computer-readable storage medium, characterized in that: include: The computer-readable storage medium stores computer instructions, and when the computer instructions are executed on a computer, the computer is caused to perform the method according to any one of claims 1 to 7.
Citation Information
Patent Citations
Named entity identification method and device, equipment, medium and product
CN114298049A
Named entity identification method and device, electronic equipment and storage medium
CN115600596A
XES log intelligent conversion method and system
CN115757325A
Entity recognition method, apparatus, electronic device and computer readable storage medium
WO2022005188A1
Cited By
Network traffic classification method and system based on dual position coding and mixed mask mechanism
CN121547281A