Labeling method, device, equipment and storage medium for triple relationship extraction task
Highlighted text is generated through highlighted annotation and regular matching, and the offset set is obtained by combining the word segmenter, which solves the annotation problem of nested entities and multiple triples in the triplet relationship extraction task, and realizes the completeness of the entity relationship table Improvement of sexual and model training efficiency.
Patent Information
- Application Number
- CN202210655142.6
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2022-06-10
- Publication Date
- 2024-08-27
- Estimated Expiration
- 2042-06-10
AI Technical Summary
The existing technology has poor integrity of entity annotation in triplet relationship extraction task, especially the annotation problem of nested entities and multiple triplets, which leads to the inability to accurately map the index after missing tags and word segmentation, affecting the relationship. Extract the training effect of the model.
Generate highlight text through highlighted annotation and regular matching, use the stack to obtain the highlighted entity index, combine the word segmenter to obtain the offset set, and convert it into an identifier-level entity relationship table, ensuring the accurate mapping of the index before and after word segmentation, and solving the nested type Annotation issues with entities and multiple triples.
It improves the integrity of entity annotation and the training efficiency of the relational extraction model, ensures the accurate mapping of indexes before and after word segmentation, and enhances the accuracy and efficiency of the model.
Smart Images

Figure CN115098617B
Abstract
Description
Technical Field
[0001] The present application relates to the technical field of text processing, and in particular to a labeling method, device, equipment and storage medium for a triple relationship extraction task. Background Art
[0002] The relation extraction task is one of the important tasks in natural language processing. It aims to extract structured information from large-scale unstructured or semi-structured natural language texts. It is an important step in building complex knowledge base systems, including knowledge graphs, information retrieval, intelligent question answering, etc. This task is to identify named entities from text and extract semantic relationships between entities. It is a problem of classifying the relationships between target entities in the original text. Entity relationship extraction refers to extracting relationship triples from a text: triples of subject entity-relationship-object entity. The annotation of triple relationship extraction tasks is an important part of entity relationship extraction. In the prior art, when annotating triple relationship extraction tasks, due to the existence of multiple triples and nested entities, the integrity of entity annotation is poor, and entities are often missed. At the same time, the accurate mapping of the index of the relationship entity before and after word segmentation cannot be obtained, resulting in the inability to perform entity relationship annotation at the identifier level. Since the accuracy of the relationship extraction model is positively correlated with the integrity of the entity relationship annotation at the identifier level, solving the above problems is crucial and is the first step in model training. Summary of the invention
[0003] The purpose of this application is to provide a labeling method, device, equipment and storage medium for triple relationship extraction tasks. In order to have a basic understanding of some aspects of the disclosed embodiments, a simple summary is given below. This summary is not a general review, nor is it intended to identify key / important components or describe the scope of protection of these embodiments. Its only purpose is to present some concepts in a simple form as a preface to the detailed description that follows.
[0004] According to a first aspect of an embodiment of the present application, a labeling method for a triple relationship extraction task is provided, comprising:
[0005] Obtain the corresponding highlighted text and highlighted entity index set according to the original text and the original text triple list;
[0006] Acquire a highlighted text triple list according to the highlighted text and the highlighted entity index set;
[0007] Segment the highlighted text and obtain an offset set;
[0008] According to the offset set and the highlighted text triple list, an entity relationship table with completed identifier level annotation is obtained.
[0009] In some embodiments, the step of obtaining the corresponding highlighted text and highlighted entity index set according to the original text and the original text triple list includes:
[0010] For the original text, a corresponding highlighted text is generated by using regular matching and highlighting annotation;
[0011] Get the highlighted entity index set of the highlighted text.
[0012] In some embodiments, the step of obtaining a highlighted text triple list according to the highlighted text and the highlighted entity index set includes:
[0013] The triple list of the original text is updated based on the highlighted text and the highlighted entity index set to obtain a highlighted text triple list.
[0014] In some embodiments, the generating corresponding highlighted text by using regular matching and highlighting for the original text includes:
[0015] Obtain an entity set according to the original text and a triple list of the original text;
[0016] Traversing the entity sets respectively, and processing the entity sets into regular matching patterns;
[0017] According to the regular matching pattern, the matched character string is highlighted to obtain the highlighted text.
[0018] In some embodiments, obtaining a set of highlighted entity indexes of the highlighted text includes:
[0019] Based on the highlighted text, the index of the highlighted annotation of the entity and the highlighted annotation are stored in a dictionary in the form of a key-value pair to obtain a corresponding highlighted annotation index dictionary;
[0020] The highlighted entity index set is obtained using a stack and the highlighted annotation index dictionary.
[0021] In some embodiments, the acquiring, according to the offset set and the highlighted text triple list, an entity relationship table annotated at the identifier level includes:
[0022] Convert the word segmentation result of the highlighted text into a token identifier;
[0023] Obtaining the start index and end index of the single or multiple characters corresponding to each token identifier in the semantic text according to the offset set;
[0024] According to the start index and the end index, a labeled entity relationship table is obtained.
[0025] In some embodiments, obtaining a labeled entity relationship table according to the start index and the end index includes:
[0026] By traversing the highlighted text triple list to annotate all element values in the entity relationship matrix, a labeled entity relationship matrix is obtained, and the labeled entity relationship matrix is the labeled entity relationship table.
[0027] In some embodiments, annotating one of the element values in the entity relationship matrix by traversing the highlighted text triple list includes:
[0028] Traverse the highlighted text triple list to obtain the start index of the highlighted subject and the start index of the highlighted object currently traversed;
[0029] Determine a smaller value and a larger value of a start index of the highlighted subject and a start index of the highlighted object;
[0030] Determine the position index of the smaller value and the position index of the larger value;
[0031] According to the position index of the smaller value and the position index of the larger value, the entity relationship index value of the currently traversed triple is marked as the corresponding element value in the entity relationship matrix, thereby completing the marking of one element value.
[0032] In some embodiments, determining the position index of the smaller value and the position index of the larger value includes:
[0033] Obtaining an ascending begin set and an ascending ends set according to the offset set, wherein the ascending begin set and the ascending ends set respectively represent the start index and the end index of the single or multiple characters corresponding to each token identifier in the highlighted text;
[0034] Obtain the position index of the smaller value according to the ascending ends set;
[0035] Obtain the position index of the larger value according to the ascending begin set;
[0036] In some embodiments, obtaining the position index of the smaller value according to the ascending ends set includes:
[0037] Find the position where the smaller value should be inserted in the ascending ends set to keep the ends set in ascending order. The position where the smaller value should be inserted is the position index of the smaller value. If the begin value already exists in the ascending ends set, the position where the smaller value should be inserted is to the left of the existing value in the ascending ends set.
[0038] The step of obtaining the position index of the larger value according to the ascending begin set includes:
[0039] Find the position where the larger value should be inserted in the ascending begins set to keep the begins set in ascending order. The position to be inserted is the position index of the larger value. If the larger value already exists in the ascending begins set, the position to be inserted is to the right of the existing value in the ascending begins set.
[0040] A second aspect of an embodiment of the present application provides a method for training a relationship extraction task model, the method comprising:
[0041] The entity relationship table obtained by any of the above-mentioned annotation methods is used to train the relationship extraction task model.
[0042] A third aspect of an embodiment of the present application provides a labeling device for a triple relationship extraction task, including:
[0043] A first acquisition module is used to acquire corresponding highlighted text and highlighted entity index set according to the original text and the original text triple list;
[0044] A second acquisition module, used for acquiring a highlighted text triple list according to the highlighted text and the highlighted entity index set;
[0045] A word segmentation module, used to segment the highlighted text and obtain an offset set;
[0046] The third acquisition module is used to acquire the entity relationship table marked at the identifier level according to the offset set and the highlighted text triple list.
[0047] The fourth aspect of an embodiment of the present application provides an electronic device, including a memory, a processor, and a computer program stored in the memory and executable on the processor, wherein the processor executes the program to implement the above-mentioned labeling method for the triple relationship extraction task.
[0048] A fifth aspect of an embodiment of the present application provides a computer-readable storage medium on which a computer program is stored, and the program is executed by a processor to implement the above-mentioned labeling method for the triple relationship extraction task.
[0049] The technical solution provided by one aspect of the embodiments of the present application may have the following beneficial effects:
[0050] The labeling method for the triple relationship extraction task provided in the embodiment of the present application obtains the corresponding highlighted text, highlighted entity index set and highlighted text triple list according to the original text, and obtains the entity relationship table with identifier level labeling based on the highlighted text, highlighted entity index set and highlighted text triple list, thereby achieving complete labeling of nested entities and multiple triples in the entity relationship table, ensuring accurate mapping of pre-segmentation index to post-segmentation index, solving the labeling problem of multiple triples or nested entities in the prior art, improving the completeness of entity labeling, and solving the problem of missing entities.
[0051] Other features and advantages of the present application will be described in the subsequent description, and some of them will become obvious from the description, or some of them can be inferred or determined unambiguously from the description, or can be understood by implementing the embodiments of the present application. BRIEF DESCRIPTION OF THE DRAWINGS
[0052] In order to more clearly illustrate the embodiments of the present application or the technical solutions in the prior art, the drawings required for use in the embodiments or the description of the prior art will be briefly introduced below. Obviously, the drawings described below are only some embodiments recorded in the present application. For ordinary technicians in this field, other drawings can be obtained based on these drawings without paying creative work.
[0053] Figure 1 A flowchart of a labeling method for a triple relationship extraction task in some implementation modes of the present application is shown;
[0054] Figure 2 Shows Figure 1 Flow chart of step S10;
[0055] Figure 3 Shows Figure 1 Flow chart of step S40;
[0056] Figure 4 A flowchart of obtaining a set of highlighted text and highlighted entity indexes in some embodiments of the present application is shown;
[0057] Figure 5 A flowchart of updating spo_lists based on a highlighted entity index set in some embodiments of the present application is shown;
[0058] Figure 6 A flowchart of obtaining an entity relationship table at the tokens level based on an offset set in some embodiments of the present application is shown;
[0059] Figure 7 A structural block diagram of a labeling device for a triple relationship extraction task in some embodiments of the present application is shown;
[0060] Figure 8 A structural block diagram of an electronic device according to some embodiments of the present application is shown;
[0061] Fig. 9 A schematic diagram of a computer-readable storage medium according to some embodiments of the present application is shown;
[0062] The realization of the purpose, functional features and advantages of this application will be further explained in conjunction with embodiments and with reference to the accompanying drawings. DETAILED DESCRIPTION
[0063] In order to make the purpose, technical solutions and advantages of the present application clearer, the present application is further described below in conjunction with the accompanying drawings and specific embodiments. It should be understood that the specific embodiments described herein are only used to explain the present application and are not intended to limit the present application. Based on the embodiments in the present application, all other embodiments obtained by ordinary technicians in the field without making creative work are within the scope of protection of the present application.
[0064] It will be understood by those skilled in the art that, unless otherwise defined, all terms (including technical and scientific terms) used herein have the same meaning as those generally understood by those skilled in the art to which this application belongs. It should also be understood that terms such as those defined in general dictionaries should be understood to have meanings consistent with the meanings in the context of the prior art, and will not be interpreted with idealized or overly formal meanings unless specifically defined as here.
[0065] Since the accuracy of the relation extraction model is positively correlated with the completeness of the named entity annotations in the tokens, it is crucial to solve the complex annotation of multiple triples and nested entities at the tokens level, which is the first step in model training. The inventor of the present application found that when training the relation extraction task model, it is necessary to use a word segmenter to convert the semantic text into identifier tokens, and then perform entity relationship annotation based on tokens, and finally input the model for training. However, since the word segmenter does not directly convert the semantic text with a single character as the granularity, it will not be possible to know the position of a character in the tokens according to the index of the original semantic text before the word segmentation after the word segmentation. In the existing processing method, for the problem, the tokens of the characters to be searched can be found in the tokens of the entire text. The defect of this method is that the same characters to be searched may appear repeatedly in the entire text, so that the position of the entity referred to in the triple relationship in the tokens cannot be accurately located. In addition to the obstacles caused by the inability to align the index after the word segmentation to the entity relationship annotation in the tokens, in actual scenarios, multiple triples often appear in a text, and there are a large number of nested entities. This makes the annotation of multiple triples and nested entities based on tokens more complicated. In another existing processing method, if there is a nested entity or an entity exists in multiple triples, the nearest annotation strategy is adopted, which directly leads to the omission of a large number of entity relationships and the inability to ensure the integrity of data annotation.
[0066] An embodiment of the present application provides a labeling method for complex triple relationship extraction tasks based on table filling, which is used to solve the problem in the prior art that the index position of the original text characters at the tokens level cannot be known after word segmentation. It is mainly aimed at the situation where there are nested entities and multiple triples in the text, so as to improve the completeness of data labeling and the efficiency of relationship extraction task model training.
[0067] In order to solve the above problems, the embodiment of the present application firstly uses highlight annotation to mark entities in the original text to obtain highlighted text, and uses a stack to obtain the position index of the highlighted entity in the highlighted text to solve the problem of missing labels for nested entities and multiple triples, and improve the efficiency of annotation and training. Secondly, the highlighted text is segmented to obtain tokens and offset sets offsets, and finally the offset set offsets is used to obtain an entity relationship table at the tokens level to solve the problem of difficulty in aligning indexes after segmentation.
[0068] An embodiment of the present application relates to a labeling method for complex triple relationship extraction tasks based on table filling, which solves the problem of complete labeling of nested entities and multiple triples in an entity relationship table, ensures accurate mapping of pre-segmentation index to post-segmentation index, and uses the entity relationship table for model training, which can greatly improve the efficiency and accuracy of model training.
[0069] like Figure 1 As shown, in some implementations, the labeling method for the triple relationship extraction task includes steps S10 to S40:
[0070] S10. Obtain the corresponding highlighted text and highlighted entity index set according to the original text and the original text triple list.
[0071] For example, Figure 2 As shown, step S10 may include steps S101 and S102:
[0072] S101, for the original text, generate corresponding highlighted text by using regular matching and highlighting;
[0073] S102: Obtain a set of highlighted entity indexes of the highlighted text.
[0074] Specifically, for the original text, the corresponding highlighted text is generated by using regular matching and highlighting annotation, which may include: obtaining an entity set based on the original text and the triple list of the original text; traversing the entity set separately and processing the entity set into a regular matching pattern; according to the regular matching pattern, highlighting and annotating the matched character string to obtain the highlighted text.
[0075] Specifically, obtaining the highlighted entity index set of the highlighted text may include: based on the highlighted text, storing the index of the highlighted annotation of the entity and the highlighted annotation in a dictionary in the form of a key-value pair to obtain a corresponding highlighted annotation index dictionary; and using a stack and the highlighted annotation index dictionary to obtain the highlighted entity index set.
[0076] S20. Obtain a highlighted text triple list according to the highlighted text and the highlighted entity index set.
[0077] Specifically, step S20 may include: updating the triple list of the original text based on the highlighted text and the highlighted entity index set to obtain a highlighted text triple list.
[0078] S30, segmenting the highlighted text and obtaining an offset set.
[0079] Specifically, S30 may include: using a word segmenter to segment the highlighted text, and obtaining a word segmentation result and an offset set.
[0080] S40: Obtain an entity relationship table annotated at the identifier level according to the offset set and the highlighted text triple list.
[0081] For example, Figure 3As shown, step S40 may include steps S401 to S403:
[0082] S401, converting the word segmentation result of the highlighted text into a token identifier;
[0083] S402, obtaining the start index and end index of the single or multiple characters corresponding to each token identifier in the semantic text according to the offset set;
[0084] S403: Obtain a labeled entity relationship table according to the start index and the end index.
[0085] The identifier is a token identifier, which may be referred to as a token in this embodiment, and a collection of multiple token identifiers may be referred to as tokens.
[0086] Specifically, according to the start index and the end index, a labeled entity relationship table is obtained, including: by traversing the highlighted text triple list to label all element values in the entity relationship matrix, a labeled entity relationship matrix is obtained, and the labeled entity relationship matrix is the labeled entity relationship table.
[0087] Specifically, labeling one of the element values in the entity relationship matrix by traversing the highlighted text triple list can include: traversing the highlighted text triple list to obtain the start index of the currently traversed highlighted subject and the start index of the highlighted object; determining the smaller value and the larger value of the start index of the highlighted subject and the start index of the highlighted object; determining the position index of the smaller value and the position index of the larger value; and labeling the entity relationship index value of the currently traversed triple as the corresponding element value in the entity relationship matrix according to the position index of the smaller value and the position index of the larger value, thereby completing the labeling of an element value.
[0088] Specifically, determining the position index of the smaller value and the position index of the larger value includes: obtaining an ascending begins set and an ascending ends set according to the offset set, the ascending begins set and the ascending ends set respectively representing the start index and end index of a single or multiple characters corresponding to each token identifier in the highlighted text; obtaining the position index of the smaller value according to the ascending ends set; and obtaining the position index of the larger value according to the ascending begins set.
[0089] Specifically, the position index of the larger value is obtained according to the ascending begins set, including: finding the position where the larger value should be inserted in the ascending begins set to keep the begins set in ascending order, and the position to be inserted is the position index of the larger value; if the larger value already exists in the ascending begins set, the position to be inserted is to the right of the value already existing in the ascending begins set.
[0090] Specifically, the position index of the smaller value is obtained according to the ascending ends set, including: finding the position where the smaller value should be inserted in the ascending ends set to keep the ends set in ascending order, and the position to be inserted is the position index of the smaller value; if the begin value already exists in the ascending ends set, the position to be inserted is to the left of the value already existing in the ascending ends set.
[0091] In some specific examples, obtaining the corresponding highlighted text and highlighted entity index set according to the original text and the original text triple list may specifically include:
[0092] (1) According to the original text and its corresponding triple list, the subject set and the object set are obtained, and the subject set and the object set are traversed respectively, and the currently traversed entity is processed into a regular matching pattern. The matched string is highlighted by using the text pattern matching method to obtain a new text to be matched, and finally the highlighted text is obtained. The original text can also be referred to as the original text.
[0093] (2) Based on the highlighted text, the highlighted annotation index and the highlighted annotation of the entity are stored in a dictionary in the form of key-value pairs to obtain a corresponding highlighted annotation index dictionary. The stack and dictionary are used to obtain a highlighted subject index set and a highlighted object index set.
[0094] (3) Update the triple list spo_lists based on the highlighted text and the highlighted entity index set to obtain spo_lists based on the highlighted text.
[0095] In some specific examples, methods of obtaining a tokens-level entity relationship matrix based on an offset set include:
[0096] (1) Combine the word segmenter to segment the highlighted text and obtain the word segmentation offset set offsets. According to the offset set offsets, obtain the begin set and ends set.
[0097] (2) Initialize the entity relationship table matrix, traverse the triple list, and record the smaller value of the starting index of the two entities involved in each pair of triples as the begin value and the larger value as the end value.
[0098] (3) Find the position where the end value should be inserted in the ascending begins set, recorded as row, and find the position where the begin value should be inserted in the ascending ends set, recorded as col. According to row and col, the value of the entity relationship matrix [row, col] is annotated as the entity relationship index value of the current traversed triple. Finally, the entity relationship matrix with complete tokens-level annotations is obtained for subsequent model training.
[0099] Regular matching and stacks can be used to completely annotate multiple triples and nested entities into the entity relationship table. Combining offset sets can effectively solve the problem of index changes before and after word segmentation.
[0100] In some implementations, the labeling method for the triple relationship extraction task includes the following implementation steps:
[0101] S1. Obtain a set of highlighted text and highlighted entity indexes based on regular expressions and stacks.
[0102] This step requires adding highlight annotations to the original text to obtain highlighted text, and based on the highlighted text, using the stack to obtain the highlighted entity. The process can be found in the attached Figure 4 .
[0103] S1.1. Generate highlighted text using highlight annotation and regular expression matching.
[0104] S1.1.1. Obtain the original text and its corresponding triple list spo_lists, spo_lists contains multiple triples: (subject index, object index, entity relationship index), and the entity relationship can be obtained according to the entity relationship dictionary. In the embodiment of the present application, spo_lists can be expressed as spo_lists = [{s_idx: [subject start index value, subject end index value], o_idx: [object start index value, object end index value], s_ne: first subject, o_ne: first object, p: entity relationship, p_idx: entity relationship index value},...]. Among them, the entity relationship dictionary can be expressed as {entity relationship index value: entity relationship,...}.
[0105] S1.1.2. According to the subjects and objects of the multiple triples in spo_lists, obtain a subject set and an object set. In the embodiment of the present application, the above two sets can be expressed as subject set = [first subject, second subject, ...], object set = [first object, second object, ...].
[0106] S1.1.3. Preset highlight symbols. The significance of highlight symbols is to mark the subject and object in the data so that the model can distinguish the subject and object in the text during training. In the embodiment of the present application,<s> and< / s> Marking symbols are used to mark the subject. <o> and< / o> Marking symbols are used to mark objects.
[0107] S1.1.4. Traverse the subject set: add ( between every two characters of the subject currently traversed <s>|< / s> | <o> |< / o> )*, get the regular matching pattern to match whether the text contains the pattern. If there is a match, add the two ends of the matched string in the text to be matched <s> and< / s> Mark the symbol and get the new text to be matched.
[0108] S1.1.5. Traversing the object set: The pattern matching method is the same as the previous one. If there is a match, add the two ends of the matched string in the text to be matched. <o> and< / o> Mark the symbol and get the new text to be matched.
[0109] S1.1.6. After completing steps S1.1.4-S1.1.5, a new text with multiple highlight annotations, namely, a highlighted text, is finally obtained.
[0110] The technical problem that can be solved by using regular expressions for entity matching instead of directly searching for entities in the text is that when two entities are nested, one of the nested entities will cause the text to be matched to change after adding a highlighted annotation, and the other nested entity will not be directly found in the changed text to be matched, which will cause the entity to be missed and reduce the integrity of the data annotation.
[0111] S1.2. Use the stack to get the index of the new entity with the highlighted annotation.
[0112] S1.2.1. According to S1.1, the highlighted text is obtained, and the index of the highlighted annotation of the subject is obtained, that is, the highlighted annotation <s> and< / s> The index of the highlighted annotation and the highlighted annotation are stored in a dictionary in the form of a key-value pair to obtain a highlighted annotation index dictionary, and the highlighted annotation index dictionary is sorted in ascending order according to the dictionary key. In an embodiment of the present application, the above dictionary can be represented as {highlighted annotation index value: highlighted annotation, highlighted annotation index value: highlighted annotation, ...}.
[0113] S1.2.2. Traverse the above dictionary, if the current value is <s> , then add the current key to the stack. If the current value is< / s> , a key is popped out from the stack, and the popped out key and the current key are added to the highlighted subject index set. The highlighted subject index set is obtained after the traversal is completed.
[0114] S1.2.3. Use the same operation method as steps S1.2.1-S1.2.2 to obtain a set of highlighted object indexes.
[0115] S2. Update the triple list spo_lists of the original text based on the highlighted entity index set.
[0116] This step requires obtaining spo_lists based on the highlighted text in S1.1 and the highlighted entity index set in S1.2. The process can be found in the attached Figure 5 .
[0117] S2.1. Get the original text spo_lists based on the highlighted text in S1.1.
[0118] S2.1.1. Traverse the highlighted subject index set of S1.2, obtain the highlighted subject string corresponding to the current traversal index according to the highlighted text of S1.1, and nested traverse the highlighted object index set of S1.2, and obtain the highlighted object string corresponding to the current nested traversal index according to the highlighted text of S1.1. Remove the highlighted annotations in the highlighted subject and object strings respectively. If the two have a triple relationship in spo_lists, update the s_idx and o_idx of the triple in spo_lists to s_idx: [current traversal highlighted subject start index value, current traversal highlighted subject end index value] and o_idx: [current traversal highlighted object start index value, current traversal highlighted object end index value] respectively, and update s_ne and o_ne to the corresponding highlighted entities.
[0119] S2.1.2. After the traversal is completed, obtain spo_lists based on the highlighted text in S1.1.
[0120] S3. Obtain the entity relationship table at the tokens level based on the offset set.
[0121] This step tokenizes the highlighted text in S1.1 and obtains the entity relationship table at the token level based on the offset set. The process can be found in the attached Figure 6 .
[0122] S3.1. Get a set of tokens and offsets.
[0123] S3.1.1. Use the tokenizer to tokenize the highlighted text in S1.1, and convert the tokenization results into identifier tokens according to the mapping relationship.
[0124] S3.1.2. When using the word segmenter, the word segmentation offset set offsets is obtained at the same time. The offset set offsets records the index of the single or multiple characters corresponding to each token in the semantic text. In the embodiment of the present application, the offset set offsets can be expressed as offsets = [(semantic text character start index value, semantic text character end index value), ...].
[0125] S3.1.3. Obtain the begins set and ends set according to the offset set offsets, which respectively represent the start index and end index of the single or multiple characters corresponding to each token in the semantic text. In the embodiment of the present application, the begins set and the ends set can be expressed as, begins = [semantic text character start index value, ...], ends = [semantic text character end index value -1, ...].
[0126] S3.2. Obtain the entity relationship matrix at the tokens level based on the offset set.
[0127] S3.2.1. Initialize the entity relationship matrix entity_relation for input model training. The length and width of the matrix are equal, and the size is the length of tokens obtained in S3.1, and the initialization value is preset. In this embodiment, the initialization value can be -100.
[0128] S3.2.2. According to the spo_lists obtained in S2.1, traverse the triples in it:
[0129] S3.2.2.1. Get the start index of the highlighted subject and the start index of the highlighted object of the current traversal. Record the smaller value of the two index values as the begin value, and the larger value as the end value.
[0130] S3.2.2.2. Find the position where the end value should be inserted in the ascending begin set to keep the begin set in ascending order, and record the position index as row. If the end value already exists in the begin set, the position to be inserted is to the right of the existing value in the begin set. It should be clarified here that this method can ensure that the index where the end value should be inserted in the tokens level is before the beginning of the tokens converted from the next one or more characters, and ensure that all the strings to be found are covered.
[0131] S3.2.2.3. Find the position where the begin value should be inserted in the ascending ends set to keep the ends set in ascending order, and record the position index as col. If the begin value already exists in the ends set, it should be inserted to the left of the existing value in the ends set. It should be clarified here that this method can ensure that the insertion of the begin value in the tokens level is after the end of the tokens converted from the previous one or more characters, and ensure that all the strings to be found are covered.
[0132] S3.2.2.4. Based on the obtained row and col, the value marked entity_relation[row,col] is the entity relationship index value of the current traversal triple.
[0133] S3.2.3. After the traversal is completed, the labeled entity relationship matrix entity_relation, i.e. the entity relationship table, is finally obtained and input into the model for training.
[0134] The following is a specific example of the present application, which is only used to illustrate the specific implementation process of the method provided in the embodiment of the present application:
[0135] A. Original text:
[0136] When the trachea is affected, acute bronchitis (acute bronchiolitis) is also called acute tracheobronchitis, and dilators can be used for wheezing and shortness of breath.
[0137] B. spo_lists based on original text:
[0138] 'spo_lists':[
[0139] {'s_idx':[6,11],'o_idx':[35,42],'s_ne':'Acute bronchitis','o_ne:'Acute tracheobronchitis','p':'Synonym','p_idx':2},
[0140] {'s_idx':[6,11],'o_idx':[13,31],'s_ne':'Acute bronchitis','o_ne':'acutebronchiolitis','p':'Synonym','p_idx':2},
[0141] {'s_idx':[8,11],'o_idx':[37,42],'s_ne':'Bronchitis','o_ne':'Tracheobronchitis','p':'Synonym','p_idx':2},
[0142] {'s_idx':[6,11],'o_idx':[44,45],'s_ne':'Acute bronchitis','o_ne':'Dyspnea','p':'Clinical manifestations','p_idx':1},
[0143] {'s_idx':[6,11],'o_idx':[48,50],'s_ne':'Acute bronchitis','o_ne':'Dilators','p':'Drug treatment','p_idx':3},
[0144] {'s_idx':[6,11],'o_idx':[8,10],'s_ne':'Acute bronchitis','o_ne':'Bronchi','p':'Site of disease','p_idx':0},
[0145] {'s_idx':[35,42],'o_idx':[37,41],'s_ne':'Acute tracheobronchitis','o_ne':'Tracheobronchus','p':'Site of disease','p_idx':0}]
[0146] C. Entity relationship dictionary:
[0147] {0:'site of disease',1:'clinical manifestations',2:'synonyms',3:'drug treatment'}
[0148] D. Based on A and B, obtain the subject set origin_s_entities and the object set origin_o_entities:
[0149] origin_s_entities = ['Bronchitis', 'Acute bronchitis', 'Acute tracheobronchitis']
[0150] origin_o_entities = ['asthma', 'relaxant', 'bronchial', 'tracheobronchial', 'tracheobronchitis', 'acute tracheobronchitis', 'acute bronchiolitis']
[0151] E. Regular matching pattern:
[0152] List only the entity 'Acute tracheobronchitis' converted into patterns:
[0153] Acute tracheobronchitis → 'acute <s>|< / s> | <o> |< / o> )*sex( <s>|< / s> | <o> |< / o> )*gas( <s>|< / s> | <o> |< / o> )*Tube( <s>|< / s> | <o> |< / o> )*branch( <s>|< / s> | <o> |< / o> )*gas( <s>|< / s> | <o> |< / o> )*Tube( <s>|< / s> | <o> |< / o> )*inflammation'
[0154] F. Highlight text:
[0155] When the trachea is affected, <s>acute <s> <o> Bronchial tube< / o> inflammation< / s> < / s> ( <o> acute bronchiolitis< / o> ) is also called <s> <o>acute <o> <o> Tracheobronchial< / o> inflammation< / o> < / o> < / s>, <o> Panting< / o> Available <o> Relaxants< / o> .
[0156] G. Index dictionary of highlighted entities:
[0157] The index dictionary of the highlighted annotations of the subject: {6:' <s>',11:' <s>',25:'< / s> ',29:'< / s> ',63:' <s>',95:'< / s> '}
[0158] The index dictionary of the object's highlight annotation: {14:' <o> ',20:'< / o> ',34:' <o> ',56:'< / o> ',66:' <o> ',71:' <o> ',74:' <o> ',82:'< / o> ',87:'< / o> ',91:'< / o> ',100:' <o> ',105:'< / o> ',111:' <o> ',117:'< / o> '}
[0159] H. Highlight entity index collection:
[0160] Highlight subject index set: [[11,25],[6,29],[63,95]]
[0161] Highlight object index set: [[14,20],[34,56],[74,82],[71,87],[66,91],[100,105],[111,117]]
[0162] I. spo_lists based on S1.1. new text:
[0163] 'spo_lists':[
[0164] {'s_idx':[6,29],'o_idx':[66,91],'s_ne':' <s>acute <s> <o> Bronchial tube< / o> inflammation< / s> ','o_ne:' <o>acute <o> <o> Tracheobronchial< / o> inflammation< / o> ','p':'Synonym','p_idx':2},
[0165] {'s_idx':[6,29],'o_idx':[34,56],'s_ne':' <s>acute <s> <o> Bronchial tube< / o> inflammation< / s> ','o_ne':' <o>acute bronchiolitis','p':'Synonym','p_idx':2},
[0166] {'s_idx':[11,25],'o_idx':[71,87],'s_ne':" <s> <o> Bronchial tube< / o> Inflammation', 'o_ne': ' <o> <o> Tracheobronchial< / o> 'inflammation', 'p':'synonym', 'p_idx': 2},
[0167] {'s_idx': [6, 29], 'o_idx': [100, 105],'s_ne': ' <s>acute <s> <o> Bronchial tube< / o> inflammation< / s> ','o_ne':' <o>Dyspnea','p':'Clinical manifestations','p_idx':1},
[0168] {'s_idx':[6,29],'o_idx':[111,117],'s_ne':' <s>acute <s> <o> Bronchial tube< / o> inflammation< / s> ','o_ne':' <o>diastolic agent','p':'drug therapy','p_idx':3},
[0169] {'s_idx':[6,29],'o_idx':[14,20],'s_ne':' <s>acute <s> <o> Bronchial tube< / o> inflammation< / s> ','o_ne':' <o>Bronchus','p':'Pathogenic site','p_idx':0},
[0170] {'s_idx':[63,95],'o_idx':[74,82],'s_ne':' <s> <o>acute <o> <o> Tracheobronchial< / o> inflammation< / o> < / o> ','o_ne':' <o>Trachea and bronchus','p':'Pathogenic site','p_idx':0}]
[0171] J. Tokenizer tokenization:
[0172] ['[CLS]','When','gas','pipe','suffer','tired',',',' <s>','acute',' <s>',' <o> ','branch','gas','tube','< / o> ','inflammation','< / s> ','< / s> ','(',' <o> ','ac','##ute','br','##on','##chi','##ol','##iti','##s','< / o> ',')','also','called',' <s>',' <o>','acute',' <o>',' <o> ','gas','pipe','branch','gas','pipe','< / o> ','inflammation','< / o> ','< / o> ','< / s> ',',',' <o> ','breathing','holding','< / o> ','can','use',' <o> ','Shu','Zhang','Jia','< / o> ','. ','[SEP]']
[0173] K.tokens:
[0174] [101,2496,3698,5052,1358,5168,8024,21128,2593,2595,21128,21130,3118,3698,5052,21131,4142,21129,21129,113,21130,9226,9710,8575,8224,10525,8798,12644,8118,21131,114,738 ,4917,21128,21130,2593,2595,21130,21130,3698,5052,3118,3698,5052,21131,4142,21131,21131,21129,8024,21130,1596,2728,21131,1377,4500,21130,5653,2476,1177,21131,511,102]
[0175] L. Offset set offsets:
[0176] [(0,0),(0,1),(1,2),(2,3),(3,4),(4,5),(5,6),(6,9),(9,10),(10,11),(11,14),(14,17),(17,18),(18,19),(19,20),(20,24),(24,25),(25,29),(29,33),(33,34),(34,37),(37,39),(39,42),(43,45),(45,47),(47,50),(50,52),(52,55),(55,56),(56,60),(60,61),(61,62),(62,63),(63,66) ,(66,69),(69,70),(70,71),(71,74),(74,77),(77,78),(78,79),(79,80),(80,81),(81,82),(82,86),(86,87),(87,91),(91,95),(95,99),(99,100),(100,103),(103,104),(104,105),(105,109),(109,110),(110,111),(111,114),(114,115),(115,116),(116,117),(117,121),(121,122),(0,0)]
[0177] M.begins collection and ends collection:
[0178] begins collection: [0,1,2,3,4,5,6,9,10,11,14,17,18,19,20,24,25,29,33,34,37,39,43,45,47,50,52,55,56,60,61,62, 63,66,69,70,71,74,77,78,79,80,81,82,86,87,91,95,99,100,103,104,105,109,110,111,114,115,116,117,121]
[0179] Ends set: [0,1,2,3,4,5,8,9,10,13,16,17,18,19,23,24,28,32,33,36,38,41,44,46,49,51,54,55,59,60,61,62,65,68,69,70,73,76,77,78,79,80,81,85,86,90,94,98,99,102,103,104,108,109,110,113,114,115,116,120,121]
[0180] N. Determine the entity relationship table based on offsets, the subject's start index, and the object's start index:
[0181] 1. The triple can be simplified to
[0182] 'spo_lists':[
[0183] {'s_start_idx:6','o_start_idx':66,'p_idx':2}
[0184] {'s_start_idx:6','o_start_idx':34,'p_idx':2}
[0185] {'s_start_idx:11','o_start_idx':71,'p_idx':2}
[0186] {'s_start_idx:6','o_start_idx':100,'p_idx':1}
[0187] {'s_start_idx:6','o_start_idx':111,'p_idx':3}
[0188] {'s_start_idx:6','o_start_idx':14,'p_idx':0}
[0189] {'s_start_idx:63','o_start_idx':74,'p_idx':0}]
[0190] 2. Taking the first pair of triples as an example, when the start index of the highlighted subject is 6 and the start index of the highlighted object is 66, the smaller value 6 of the two indexes is recorded as begin, and the larger value 66 is recorded as end. Find the position where begin should be inserted in the ends set to keep the ends set in ascending order, and the index of the position to be inserted is 7, recorded as row. Find the position where end should be inserted in the begins set to keep the begins set in ascending order, and the index of the position to be inserted is 34, recorded as col. That is, p_idx = 2, col = 34, row = 7, so entity_relation[7]
[34] = 2. And so on:
[0191] entity_relation[7]
[34] =2
[0192] entity_relation[7]
[20] =2
[0193] entity_relation
[10]
[37] =2
[0194] entity_relation[7]
[50] =1
[0195] entity_relation[7]
[56] =3
[0196] entity_relation[7]
[11] =0
[0197] entity_relation
[33]
[38] =0
[0198] 3. Finally, the entity relationship table entity_relation is obtained. Some results of entity_relation can be seen in the table below.
[0199]
[0200] It should be understood that the contents of the second and third rows and the contents of the second and third columns in the above table are only for explaining this example and do not actually exist in entity_relation. At the same time, the above table omits the display of some indexes.
[0201] The embodiment of the present application provides a method for accurately labeling complex nested entities and multiple triples in tokens. Compared with the prior art, the method has the following beneficial effects:
[0202] The method of the embodiment of the present application can simultaneously realize the labeling of nested entities and multiple triples, solves the labeling problem of multiple triples or nested entities in the prior art, improves the integrity of entity labeling, and solves the problem of missing entity labels.
[0203] In addition, the embodiment of the present application uses the offset set offsets to obtain the mapping of index changes before and after word segmentation. This method solves the problem in the prior art that the search results are not single and accurate because the characters to be searched may appear repeatedly when searching within the tokens of the entire text according to the tokens of the characters to be searched. The embodiment of the present application can accurately obtain the position of the characters before word segmentation within the tokens after word segmentation according to the offset set offsets, thereby improving the accuracy of entity relationship annotation.
[0204] In summary, the method of the embodiment of the present application can effectively solve the labeling of multiple triples and nested entities at the tokens level, and can achieve accurate mapping before and after word segmentation, thereby improving labeling accuracy and training efficiency.
[0205] The method of the embodiment of the present application obtains entity relationship annotation data at the tokens level, solves the annotation problem of nested entities and multiple triples at the tokens level, combines regular expressions and stacks to obtain highlighted text and highlighted entities, and uses a word segmenter to segment the highlighted text to obtain tokens and offset sets, and finally obtains a tokens-level entity relationship table based on the offset set for training the relationship extraction model.
[0206] Another embodiment of the present application provides a method for training a relationship extraction task model, the method comprising: training the relationship extraction task model using an entity relationship table obtained by the labeling method of any of the above-mentioned implementations.
[0207] Another embodiment of the present application provides a labeling device for a triple relationship extraction task, such as Figure 7 As shown, in some embodiments, the device includes:
[0208] A first acquisition module is used to acquire corresponding highlighted text and highlighted entity index set according to the original text and the original text triple list;
[0209] A second acquisition module, used for acquiring a highlighted text triple list according to the highlighted text and the highlighted entity index set;
[0210] A word segmentation module, used to segment the highlighted text and obtain an offset set;
[0211] The third acquisition module is used to acquire the entity relationship table marked at the identifier level according to the offset set and the highlighted text triple list.
[0212] In some implementations, the first acquisition module may include:
[0213] A highlighted text generating unit, used for generating corresponding highlighted text by using regular matching and highlighting annotation for the original text;
[0214] The highlight entity index set acquisition unit is used to acquire the highlight entity index set of the highlighted text.
[0215] In some implementations, the second acquisition module is further specifically configured to update the triple list of the original text based on the highlighted text and the highlighted entity index set to obtain the highlighted text triple list.
[0216] Specifically, the highlight text generation unit includes:
[0217] A first subunit, configured to obtain an entity set according to an original text and a triple list of the original text;
[0218] The second subunit is used to traverse the entity set respectively and process the entity set into a regular matching pattern;
[0219] The third subunit is used to highlight the matched character string according to the regular matching pattern to obtain the highlighted text.
[0220] Specifically, obtaining a set of highlighted entity indexes of the highlighted text includes:
[0221] Based on the highlighted text, the index of the highlighted annotation of the entity and the highlighted annotation are stored in a dictionary in the form of a key-value pair to obtain a corresponding highlighted annotation index dictionary;
[0222] The highlighted entity index set is obtained using a stack and the highlighted annotation index dictionary.
[0223] In some implementations, the third acquisition module may include:
[0224] A conversion unit, used to convert the word segmentation result of the highlighted text into a token identifier;
[0225] An index acquisition unit, used to obtain the start index and end index of the single or multiple characters corresponding to each token identifier in the semantic text according to the offset set;
[0226] The entity relationship table acquisition unit is used to obtain the marked entity relationship table according to the start index and the end index.
[0227] Exemplarily, the entity relationship table acquisition unit is further used to: obtain a labeled entity relationship matrix by traversing the highlighted text triple list to label all element values in the entity relationship matrix, where the labeled entity relationship matrix is the labeled entity relationship table.
[0228] Specifically, the entity relationship table acquisition unit performs the process of labeling one of the element values in the entity relationship matrix by traversing the highlighted text triple list, including:
[0229] Traverse the highlighted text triple list to obtain the start index of the highlighted subject and the start index of the highlighted object currently traversed;
[0230] Determine a smaller value and a larger value of a start index of the highlighted subject and a start index of the highlighted object;
[0231] Determine the position index of the smaller value and the position index of the larger value;
[0232] According to the position index of the smaller value and the position index of the larger value, the entity relationship index value of the currently traversed triple is marked as the corresponding element value in the entity relationship matrix, thereby completing the marking of one element value.
[0233] Another embodiment of the present application provides a relationship extraction task model training device for training the relationship extraction task model using the entity relationship table obtained by the labeling method of the triple relationship extraction task of any of the above-mentioned implementations.
[0234] Another embodiment of the present application provides an electronic device, including a memory, a processor, and a computer program stored in the memory and executable on the processor, wherein the processor executes the program to implement a labeling method for a triple relationship extraction task according to any of the above-mentioned embodiments.
[0235] like Figure 8 As shown, the electronic device 10 may include: a processor 100, a memory 101, a bus 102 and a communication interface 103, and the processor 100, the communication interface 103 and the memory 101 are connected via the bus 102; the memory 101 stores a computer program that can be run on the processor 100, and when the processor 100 runs the computer program, it executes the method provided in any of the aforementioned embodiments of the present application.
[0236] The memory 101 may include a high-speed random access memory (RAM), and may also include a non-volatile memory, such as at least one disk memory. The communication connection between the system network element and at least one other network element is realized through at least one communication interface 103 (which may be wired or wireless), and the Internet, wide area network, local area network, metropolitan area network, etc. may be used.
[0237] The bus 102 may be an ISA bus, a PCI bus, or an EISA bus, etc. The bus may be divided into an address bus, a data bus, a control bus, etc. The memory 101 is used to store a program, and the processor 100 executes the program after receiving an execution instruction. The method disclosed in any implementation of the aforementioned embodiment of the present application may be applied to the processor 100, or implemented by the processor 100.
[0238] The processor 100 may be an integrated circuit chip with signal processing capabilities. In the implementation process, each step of the above method can be completed by an integrated logic circuit of hardware in the processor 100 or an instruction in the form of software. The above processor 100 may be a general-purpose processor, which may include a central processing unit (CPU), a network processor (NP), etc.; it may also be a digital signal processor (DSP), an application-specific integrated circuit (ASIC), a field-programmable gate array (FPGA) or other programmable logic devices, discrete gates or transistor logic devices, discrete hardware components. The methods, steps and logic block diagrams disclosed in the embodiments of the present application can be implemented or executed. The general-purpose processor may be a microprocessor or the processor may also be any conventional processor, etc. The steps of the method disclosed in the embodiments of the present application can be directly embodied as a hardware decoding processor for execution, or a combination of hardware and software modules in the decoding processor for execution. The software module may be located in a mature storage medium in the field such as a random access memory, a flash memory, a read-only memory, a programmable read-only memory or an electrically erasable programmable memory, a register, etc. The storage medium is located in the memory 101, and the processor 100 reads the information in the memory 101 and completes the steps of the above method in combination with its hardware.
[0239] The electronic device provided in the embodiment of the present application and the method provided in the embodiment of the present application are based on the same inventive concept and have the same beneficial effects as the method adopted, operated or implemented by them.
[0240] A fourth aspect of an embodiment of the present application provides a computer-readable storage medium on which a computer program is stored, and the program is executed by a processor to implement the labeling method for the triple relationship extraction task of any of the above-mentioned implementation modes.
[0241] The present application also provides a computer-readable storage medium corresponding to the method provided in the above embodiment. Fig. 9 As shown, the computer-readable storage medium shown is a CD 20 on which a computer program (ie, a program product) is stored. When the computer program is run by a processor, the method provided by any of the aforementioned embodiments will be executed.
[0242] It should be noted that examples of computer-readable storage media may also include, but are not limited to, phase change memory (PRAM), static random access memory (SRAM), dynamic random access memory (DRAM), other types of random access memory (RAM), read-only memory (ROM), electrically erasable programmable read-only memory (EEPROM), flash memory or other optical or magnetic storage media, which are not listed here one by one.
[0243] The computer-readable storage medium provided in the above-mentioned embodiments of the present application and the method provided in the embodiments of the present application are based on the same inventive concept and have the same beneficial effects as the method adopted, run or implemented by the application program stored therein.
[0244] It should be noted that:
[0245] The term "module" is not intended to be limited to a specific physical form. Depending on the specific application, a module can be implemented as hardware, firmware, software, and / or a combination thereof. In addition, different modules can share common components or even be implemented by the same components. There may or may not be clear boundaries between different modules.
[0246] The algorithm and display provided herein are not inherently related to any specific computer, virtual device or other equipment. Various general devices can also be used together with examples based on this. According to the above description, it is obvious to construct the structure required for this type of device. In addition, the application is not directed to any specific programming language yet. It should be understood that various programming languages can be utilized to realize the content of the application described herein, and the description made to specific languages above is for the purpose of disclosing the best mode of implementation of the application.
[0247] It should be understood that, although the steps in the flowchart of the accompanying drawings are displayed in sequence as indicated by the arrows, these steps are not necessarily executed in sequence in the order indicated by the arrows. Unless otherwise specified herein, there is no strict order restriction on the execution of these steps, and they can be executed in other orders. Moreover, at least a part of the steps in the flowchart of the accompanying drawings may include multiple sub-steps or multiple stages, and these sub-steps or stages are not necessarily executed at the same time, but can be executed at different times, and their execution order is not necessarily sequential, but can be executed in turn or alternately with other steps or at least a part of the sub-steps or stages of other steps.
[0248] The above embodiments only express the implementation methods of the present application, and the descriptions thereof are relatively specific and detailed, but they cannot be understood as limiting the scope of the present application. It should be pointed out that, for a person of ordinary skill in the art, several modifications and improvements can be made without departing from the concept of the present application, and these all belong to the protection scope of the present application. Therefore, the protection scope of the present application shall be subject to the attached claims.< / o> < / s> < / o> < / s> < / o> < / s> < / o> < / s> < / o> < / s> < / o> < / s> < / o> < / s>
Claims
1. A labeling method for triple relationship extraction task, characterized in that: include: Obtain the corresponding highlighted text and highlighted entity index set according to the original text and the original text triple list; Acquire a highlighted text triple list according to the highlighted text and the highlighted entity index set; Segment the highlighted text and obtain an offset set; According to the offset set and the highlighted text triple list, an entity relationship table with completed identifier level annotation is obtained; The step of obtaining the corresponding highlighted text and highlighted entity index set according to the original text and the original text triple list includes: For the original text, a corresponding highlighted text is generated by using regular matching and highlighting annotation; Get the highlighted entity index set of the highlighted text; The step of obtaining an entity relationship table labeled at the identifier level according to the offset set and the highlighted text triple list includes: Convert the word segmentation result of the highlighted text into a token identifier; Obtaining the start index and end index of the single or multiple characters corresponding to each token identifier in the semantic text according to the offset set; Obtaining a labeled entity relationship table according to the start index and the end index; The step of obtaining a labeled entity relationship table according to the start index and the end index includes: By traversing the highlighted text triple list to annotate all element values in the entity relationship matrix, a labeled entity relationship matrix is obtained, where the labeled entity relationship matrix is the labeled entity relationship table; Traversing the highlighted text triple list to mark one of the element values in the entity relationship matrix includes: Traverse the highlighted text triple list to obtain the start index of the highlighted subject and the start index of the highlighted object currently traversed; Determine a smaller value and a larger value of a start index of the highlighted subject and a start index of the highlighted object; Determine the position index of the smaller value and the position index of the larger value; Determine the row and column of the entity relationship matrix according to the position index of the smaller value and the position index of the larger value, mark the entity relationship index value of the currently traversed triple as the element value corresponding to the row and column, and complete the marking of an element value; The determining the position index of the smaller value and the position index of the larger value includes: Obtaining an ascending begin set and an ascending ends set according to the offset set, wherein the ascending begin set and the ascending ends set respectively represent the start index and the end index of the single or multiple characters corresponding to each token identifier in the highlighted text; Get the position index of the smaller value in the ascending ends set; Get the index of the position of the larger value in the ascending begins set.
2. The method according to claim 1, characterized in that The step of obtaining a highlighted text triple list according to the highlighted text and the highlighted entity index set includes: The triple list of the original text is updated based on the highlighted text and the highlighted entity index set to obtain a highlighted text triple list.
3. The method according to claim 1, characterized in that The method of generating corresponding highlighted text by using regular matching and highlighting annotation for the original text includes: Obtain an entity set according to the original text and a triple list of the original text; Traversing the entity sets respectively, and processing the entity sets into regular matching patterns; According to the regular matching pattern, the matched character string is highlighted to obtain the highlighted text.
4. The method according to claim 1, characterized in that: The step of obtaining a set of highlighted entity indexes of the highlighted text includes: Based on the highlighted text, the index of the highlighted annotation of the entity and the highlighted annotation are stored in a dictionary in the form of a key-value pair to obtain a corresponding highlighted annotation index dictionary; The highlighted entity index set is obtained using a stack and the highlighted annotation index dictionary.
5. The method according to claim 1, characterized in that The step of obtaining the position index of the smaller value in the ascending ends set includes: Find the position where the smaller value should be inserted in the ascending ends set to keep the ends set in ascending order. The position where the smaller value should be inserted is the position index of the smaller value. If the smaller value already exists in the ascending ends set, the position where the smaller value should be inserted is to the left of the existing value in the ascending ends set. The obtaining of the position index of the larger value in the ascending begin set includes: Find the position where the larger value should be inserted in the ascending begins set to keep the begins set in ascending order. The position to be inserted is the position index of the larger value. If the larger value already exists in the ascending begins set, the position to be inserted is to the right of the existing value in the ascending begins set.
6. A method for training a relationship extraction task model, characterized in that: The method comprises: The relationship extraction task model is trained using the entity relationship table obtained by the labeling method described in any one of claims 1 to 5.
7. A labeling device for triple relationship extraction task, characterized in that: include: A first acquisition module is used to acquire corresponding highlighted text and highlighted entity index set according to the original text and the original text triple list; A second acquisition module, used for acquiring a highlighted text triple list according to the highlighted text and the highlighted entity index set; A word segmentation module, used to segment the highlighted text and obtain an offset set; A third acquisition module is used to acquire an entity relationship table annotated at the identifier level according to the offset set and the highlighted text triple list; The first acquisition module includes: A highlighted text generating unit, used for generating corresponding highlighted text by using regular matching and highlighting annotation for the original text; A highlight entity index set acquisition unit, used to acquire a highlight entity index set of the highlighted text; The third acquisition module includes: A conversion unit, used to convert the word segmentation result of the highlighted text into a token identifier; An index acquisition unit, used to obtain the start index and end index of the single or multiple characters corresponding to each token identifier in the semantic text according to the offset set; An entity relationship table acquisition unit, used to obtain a labeled entity relationship table according to the start index and the end index; The entity relationship table acquisition unit is further used to annotate all element values in the entity relationship matrix by traversing the highlighted text triple list to obtain an annotated entity relationship matrix, wherein the annotated entity relationship matrix is the annotated entity relationship table; The entity relationship table acquisition unit is further used to: traverse the highlighted text triple list to obtain the start index of the highlighted subject and the start index of the highlighted object currently traversed; determine the smaller value and the larger value of the start index of the highlighted subject and the start index of the highlighted object; determine the position index of the smaller value and the position index of the larger value; determine the row and column of the entity relationship matrix according to the position index of the smaller value and the position index of the larger value, and mark the entity relationship index value of the currently traversed triple as the element value corresponding to the row and column to complete the marking of an element value; The entity relationship table acquisition unit is further used to: obtain an ascending begins set and an ascending ends set according to the offset set, the ascending begins set and the ascending ends set respectively representing the start index and end index of a single or multiple characters corresponding to each token identifier in the highlighted text; obtain the position index of the smaller value in the ascending ends set; obtain the position index of the larger value in the ascending begins set.
8. An electronic device, characterized in that: The invention comprises a memory, a processor and a computer program stored in the memory and executable on the processor, wherein the processor executes the program to implement the method according to any one of claims 1 to 6.
9. A computer-readable storage medium having a computer program stored thereon, characterized in that: The program is executed by a processor to implement the method according to any one of claims 1 to 6.
