Text segment recognition model training, text segment recognition method, device and medium
By using affiliation and peer relationships to generate training sample data sets, the problem of insufficient number of sample texts is solved, and the recognition performance and efficiency of text segment recognition model is improved.
Patent Information
- Application Number
- CN202210626309.6
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2022-06-02
- Publication Date
- 2024-12-31
- Estimated Expiration
- 2042-06-02
AI Technical Summary
The prior art is difficult to train a text segment recognition model with high recognition performance when the number of sample texts is small, because a large number of labeled sample texts are required for training.
By leveraging the subordinate relationship between each text segment in the sample text and the class to which it belongs and the peer relationship between different text segments of the same category, the training sample data set is generated, the training data of the model is enhanced, and the utilization rate of the sample text is improved.
Even when the number of sample texts is small, a text segment recognition model with high recognition performance can be trained, which improves the recognition ability and efficiency of the model.
Smart Images

Figure CN115033691B_ABST
Abstract
Description
Technical Field
[0001] The present application relates to the field of artificial intelligence technology, and in particular to a text segment recognition model training, text segment recognition method, device and medium. Background Art
[0002] Span Identification is a natural language processing task that aims to find text segments that belong to a certain category in the input text. The text segment category is determined according to the specific text segment identification task.
[0003] For a specific text segment recognition task, a text segment recognition model can be pre-trained, and then the text segment recognition model can be used to perform the text segment recognition task. Usually, the training method of the text segment recognition model is as follows: a large number of pre-annotated sample texts are obtained, and the sample texts are annotated with text segments and the categories to which the text segments belong. The training model is trained using the subordinate relationship between each text segment in the sample text and the category to which it belongs, so that the trained model has the ability to recognize text segments.
[0004] The above training method requires a large amount of labeled sample texts. However, in some scenarios, it may not be possible to obtain a large amount of labeled sample texts, and thus it is impossible to train a text segment recognition model with high recognition performance. Summary of the invention
[0005] The embodiments of the present application provide a text segment recognition model training, text segment recognition method, device and medium, which can train a text segment recognition model with high recognition performance even when the number of labeled sample texts is small.
[0006] In a first aspect, an embodiment of the present application provides a method for training a text segment recognition model, comprising:
[0007] Receiving multiple sample texts and annotation information of each sample text from a client, wherein the annotation information of one sample text includes: at least one annotated text segment in the sample text and an annotation category to which each annotated text segment belongs;
[0008] Generate a training sample data set according to the subordinate relationship between the annotated text segments in the plurality of sample texts and the annotated categories to which they belong, and the companion relationship between different annotated text segments belonging to the same annotated category in the plurality of sample texts;
[0009] The training sample data set is used to train the text segment recognition model to be trained to obtain a trained text segment recognition model.
[0010] In a possible implementation, generating a training sample data set according to the subordinate relationship between the annotated text segments in the plurality of sample texts and the annotated categories to which they belong, and the companion relationship between different annotated text segments belonging to the same annotated category in the plurality of sample texts includes:
[0011] generating a plurality of groups of first training samples according to the companion relationship between different annotated text segments belonging to the same annotated category in the plurality of sample texts;
[0012] generating a plurality of groups of second training samples according to the subordinate relationships between the annotated text segments in the plurality of sample texts and the annotated categories to which they belong;
[0013] The training sample data set is generated according to the multiple groups of first training samples and the multiple groups of second training samples.
[0014] In a possible implementation, generating a plurality of groups of first training samples according to the companion relationship between different annotated text segments belonging to the same annotated category in the plurality of sample texts includes:
[0015] Dividing each annotated text segment in the plurality of sample texts into at least one text segment set, wherein the annotated text segments in each text segment set belong to the same annotated category, and the annotated text segments in different text segment sets belong to different annotated categories;
[0016] Generate a plurality of companion relationship data pairs according to the at least one text segment set; each companion relationship data pair includes a first annotated text segment and a second annotated text segment, wherein the first annotated text segment and the second annotated text segment are two different annotated text segments in the same text segment set;
[0017] At least one set of first training samples is generated according to each companion relationship data pair to obtain the multiple sets of first training samples.
[0018] In a possible implementation, generating at least one set of first training samples according to each companion relationship data pair includes:
[0019] Generate a first query text according to the first annotated text segment in the companion relationship data pair, the first query text including the first annotated text segment, and the first query text is used to query a text segment having a companion relationship with the first annotated text segment;
[0020] According to the second annotated text segment in the companion relationship data pair, determining at least one first sample text from the plurality of sample texts, the first sample text including the second annotated text segment;
[0021] The at least one set of first training samples is generated according to the first query text, the at least one first sample text, and the second annotated text segment.
[0022] In a possible implementation, generating a plurality of peer relationship data pairs according to the at least one text segment set includes:
[0023] Arrange and combine any two different annotated text segments in each text segment set to obtain multiple candidate data pairs corresponding to the text segment set;
[0024] The plurality of candidate data pairs corresponding to at least a portion of the text segment set are sampled to obtain the plurality of companion relationship data pairs; the number of the companion relationship data pairs is less than the number of the candidate data pairs.
[0025] In a possible implementation, for any first text segment set in the at least one text segment set, sampling the plurality of candidate data pairs corresponding to the first text segment set includes:
[0026] Determining the number of samples corresponding to the first text segment set;
[0027] Performing sampling processing on the plurality of candidate data pairs corresponding to the first text segment set according to the sampling quantity;
[0028] Among them, the sampling quantity is related to one or more of the following: a preset sampling ratio, the difference between the number of annotated text segments included in the second text segment set and the number of annotated text segments included in the first text segment set; the second text segment set is the text segment set containing the largest number of annotated text segments among the at least one text segment set.
[0029] In a possible implementation, generating a plurality of groups of second training samples according to the subordinate relationship between the annotated text segments in the plurality of sample texts and the annotated categories to which they belong includes:
[0030] Deduplication processing is performed on the annotation categories to which each annotated text segment in the plurality of sample texts belongs, to obtain an annotation category set;
[0031] For each annotation category in the annotation category set, generate a second query text corresponding to the annotation category, the second query text includes the annotation category, and the second query text is used to query text segments belonging to the annotation category;
[0032] The plurality of groups of second training samples are generated according to the second query text corresponding to each annotation category in the annotation category set and the subordinate relationship between each annotation text segment in the plurality of sample texts and the annotation category to which it belongs.
[0033] In one possible implementation,
[0034] Generating the plurality of groups of second training samples according to the second query text corresponding to each annotation category in the annotation category set and the subordinate relationship between each annotation text segment in the plurality of sample texts and the annotation category to which it belongs, comprises:
[0035] For each annotation category in the annotation category set, traverse each sample text in the multiple sample texts respectively:
[0036] If there is an annotated text segment belonging to the annotated category in the sample text, a set of second training samples is generated according to a second query text corresponding to the annotated category, the sample text, and the annotated text segment belonging to the annotated category in the sample text; or,
[0037] If there is no annotated text segment belonging to the annotated category in the sample text, a group of second training samples is generated according to the second query text corresponding to the annotated category, the sample text, and an empty text segment.
[0038] In a second aspect, an embodiment of the present application provides a text segment recognition method, comprising:
[0039] Acquire a query text and a target text, wherein the query text is used to search for a text segment belonging to a preset category in the target text;
[0040] Processing the query text and the target text input by a trained text segment recognition model to obtain at least one target text segment in the target text, or to obtain an empty text segment, wherein the target text segment belongs to the preset category;
[0041] The text segment recognition model is trained by using the method described in any one of the first aspects.
[0042] In a third aspect, an embodiment of the present application provides a text segment recognition method, including:
[0043] Get the target text;
[0044] Processing the target text by using a trained text segment recognition model to obtain at least one target text segment in the target text and the category to which each target text segment belongs, or obtaining an empty text segment;
[0045] The text segment recognition model is trained by using the method described in any one of the first aspects.
[0046] In a fourth aspect, an embodiment of the present application provides a training device for a text segment recognition model, comprising:
[0047] A receiving module, used for receiving a plurality of sample texts and annotation information of each sample text from a client, wherein the annotation information of one sample text includes: at least one annotated text segment in the sample text and an annotation category to which each annotated text segment belongs;
[0048] A generating module, configured to generate a training sample data set according to the subordinate relationship between the annotated text segments in the plurality of sample texts and the annotated categories to which they belong, and the companion relationship between different annotated text segments belonging to the same annotated category in the plurality of sample texts;
[0049] The training module is used to train the text segment recognition model to be trained using the training sample data set to obtain the trained text segment recognition model.
[0050] In a fifth aspect, an embodiment of the present application provides a text segment recognition device, including:
[0051] An acquisition module, used to acquire a query text and a target text, wherein the query text is used to search for a text segment belonging to a preset category in the target text;
[0052] A processing module, used for processing the query text and the target text input by using a trained text segment recognition model to obtain at least one target text segment in the target text, or to obtain an empty text segment, wherein the target text segment belongs to the preset category;
[0053] Wherein, the text segment recognition model is trained using the device described in the third aspect.
[0054] In a sixth aspect, an embodiment of the present application provides a text segment recognition device, including:
[0055] An acquisition module is used to acquire the target text;
[0056] A processing module, used for processing the target text by using a trained text segment recognition model to obtain at least one target text segment in the target text and the category to which each target text segment belongs, or to obtain an empty text segment;
[0057] Wherein, the text segment recognition model is trained using the device described in the third aspect.
[0058] In the seventh aspect, an embodiment of the present application provides an electronic device, comprising: a memory and at least one processor, wherein the memory stores a computer program, and the computer program is configured to be executed by the processor to implement a method as described in any one of the first aspect, or the method as described in the second aspect, or the method as described in the third aspect.
[0059] In an eighth aspect, an embodiment of the present application provides a computer-readable storage medium, in which a computer program is stored. When the computer program is executed by a processor, it implements the method as described in any one of the first aspect, or the method as described in the second aspect, or the method as described in the third aspect.
[0060] In a ninth aspect, an embodiment of the present application provides a computer program product, comprising a computer program, wherein when the computer program is executed by a processor, the method described in any one of the first aspect, or the method described in the second aspect, or the method described in the third aspect is implemented.
[0061] The embodiment of the present application provides a training of a text segment recognition model, a text segment recognition method, a device and a medium, wherein the training method of the text segment recognition model includes: receiving multiple sample texts and annotation information of each sample text from a client, wherein the annotation information of a sample text includes: at least one annotated text segment in the sample text and the annotation category to which each annotated text segment belongs; generating a training sample data set according to the subordinate relationship between the annotated text segments in the multiple sample texts and the annotation category to which they belong, and the companion relationship between different annotated text segments belonging to the same annotation category in the multiple sample texts; using the training sample data set to train the text segment recognition model to be trained, and obtaining the trained text segment recognition model. In the above model training, not only the subordinate relationship between each text segment in the sample text and the category to which it belongs, but also the companion relationship between different text segments belonging to the same category in the sample text are used, so that the semantic features of the annotated text segment in the sample text can be better learned, the utilization rate of the sample text is improved, and even when the number of sample texts is small, a text segment recognition model with high recognition performance can be trained. BRIEF DESCRIPTION OF THE DRAWINGS
[0062] Figure 1 A schematic diagram of an application scenario provided in an embodiment of the present application;
[0063] Figure 2 A flowchart of a method for training a text segment recognition model provided in an embodiment of the present application;
[0064] Figure 3 A schematic diagram of affiliation and companionship provided for an embodiment of the present application;
[0065] Figure 4 A flowchart of another text segment recognition model training method provided in an embodiment of the present application;
[0066] Figure 5 A schematic diagram of a process for generating a first training sample provided in an embodiment of the application;
[0067] Figure 6 A schematic diagram of a process for generating a second training sample provided in an embodiment of the present application;
[0068] Figure 7 A schematic diagram of the input and output of the text segment recognition model provided in an embodiment of the present application;
[0069] Fig. 8A A flowchart of a text segment recognition method provided in an embodiment of the present application;
[0070] Figure 8B A flowchart of another text segment recognition method provided in an embodiment of the present application;
[0071] Fig. 9 A schematic diagram of the structure of a training device for a text segment recognition model provided in an embodiment of the present application;
[0072] Fig.10 A schematic diagram of the structure of a text segment recognition device provided in an embodiment of the present application;
[0073] Fig.11 A schematic diagram of the structure of an electronic device provided in an embodiment of the present application. DETAILED DESCRIPTION
[0074] In order to make the purpose, technical solution and advantages of the embodiments of the present application clearer, the technical solution in the embodiments of the present application will be clearly and completely described below in conjunction with the drawings in the embodiments of the present application. Obviously, the described embodiments are part of the embodiments of the present application, not all of the embodiments. Based on the embodiments in the present application, all other embodiments obtained by ordinary technicians in this field without creative work are within the scope of protection of this application.
[0075] The terms "first", "second", etc. in the specification, claims, and the above-mentioned drawings of the embodiments of the present application are used to distinguish similar objects, and are not necessarily used to describe a specific order or sequence. It should be understood that the terms used in this way can be interchangeable where appropriate, so that the embodiments of the present application described herein can be implemented in an order other than that illustrated or described herein.
[0076] It should be understood that the terms "including" and "having" and any variations thereof used herein are intended to cover non-exclusive inclusions. For example, a process, method, system, product or apparatus comprising a series of steps or units is not necessarily limited to those steps or units explicitly listed, but may include other steps or units not explicitly listed or inherent to these processes, methods, products or apparatuses.
[0077] In the description of the embodiments of the present application, the term "corresponding" may indicate a direct or indirect correspondence between two items, or an association relationship between the two items, or a relationship between indication and being indicated, configuration and being configured, and the like.
[0078] In order to facilitate understanding of the technical solution of the present application, the concepts and terms involved in the embodiments of the present application are first explained.
[0079] Span Identification is a type of natural language processing task, which aims to find text segments belonging to a certain category in the input text. Among them, the text segment category is formulated accordingly according to the specific text segment identification task. Through the text segment identification task, some important text segments can be quickly located and classified, so that users can quickly locate key information, greatly reducing the difficulty of users reading complex texts. In actual application scenarios, with the need for complex and specialized text processing, text segment identification has also emerged in a variety of task forms, including but not limited to: named entity recognition, sentiment type recognition, contract text clause extraction, etc.
[0080] Data augmentation is a technique that artificially expands the training data set by generating more equivalent data from limited data. It is an effective way to overcome the lack of training data and is currently widely used in various fields of deep learning.
[0081] Machine Reading Comprehension is a model framework for natural language processing. Its input includes a query and related context text, and its output is a text segment in the context text, so that the text segment can satisfy the input query.
[0082] Subordinate Relation: In text segment recognition, the relationship between a text segment and its category is called a subordinate relationship, that is, a text segment belongs to a certain category.
[0083] Peer Relation: In text segment recognition, two text segments of the same category have more similar semantics. The relationship between these two text segments is called a peer relationship.
[0084] Named Entity Recognition (NER) is a text segment recognition task used to identify text segments that belong to a certain entity type in the text. Entity types include but are not limited to names of people, places, organizations, proper nouns, etc.
[0085] Attribute-based sentiment analysis (ABS) is a text segment recognition task used to identify text segments that express a certain type of emotion in the text. Emotion types include but are not limited to: positive, negative, happy, sad, etc.
[0086] Contract Clause Extraction is a text segment recognition task used to identify certain types of clauses in a contract text, including but not limited to: time clauses, renewal term clauses, relevant legal clauses, etc.
[0087] Span Based Propaganda Detection is a text segment recognition task, which is used to identify the text segments corresponding to a certain type of propaganda technique in the text, including but not limited to: repetition, slogans, etc.
[0088] For the above-mentioned specific text segment recognition task, a text segment recognition model can be pre-trained, and then the text segment recognition model can be used to perform the text segment recognition task. Usually, the training method of the text segment recognition model is as follows: obtain a large number of pre-annotated sample texts, in which the sample texts are annotated with text segments and the categories to which the text segments belong. The subordinate relationship between each text segment in the sample text and the category to which it belongs is used to train the model to be trained, so that the trained model has the ability to recognize text segments. The above-mentioned training method requires a large number of sample texts to be pre-annotated. However, in some scenarios, it may not be possible to obtain a large number of annotated sample texts, and thus it is impossible to train a text segment recognition model with high recognition performance.
[0089] In view of the above technical problems, the technical solution of the present application not only utilizes the subordinate relationship between each text segment and its category in the sample text, but also utilizes the companion relationship between different text segments belonging to the same category in the sample text during the model training process. In this way, the model can not only learn the subordinate relationship between the text segment and its category, but also learn the companion relationship between different text segments of the same category, thereby improving the utilization rate of the sample text. Even when the number of sample texts is small, the recognition performance of the trained model can be improved.
[0090] Figure 1 A schematic diagram of an application scenario provided by an embodiment of the present application. Figure 1 As shown, the application scenario includes: a client and a model training platform. The model training platform is pre-configured with a text segment recognition model to be trained and a training algorithm for the text segment recognition model.
[0091] As an example, an enterprise user can access the model training platform through a client and upload the pre-collected sample text and its annotation information to the model training platform. Among them, the annotation information of the sample text includes: one or more annotated text segments in the sample text, and the annotation category to which each annotated text segment belongs. The model training platform generates a training sample data set based on the sample text and its annotation information. In the process of generating the training sample data set, not only the subordinate relationship between each annotated text segment in the annotated text and the annotation category to which it belongs is utilized, but also the companion relationship between different annotated text segments of the same annotation category is utilized. Furthermore, the model training platform trains the text segment recognition model to be trained based on the training sample data set and the training algorithm of the pre-configured text segment recognition model to obtain the trained text segment recognition model. Finally, the trained text segment recognition model is output to the client.
[0092] Furthermore, enterprise users can deploy the trained text segment recognition model to the execution device, and the execution device can use the trained text segment recognition model to complete the text segment recognition task.
[0093] Based on the above application scenarios, the technical solutions provided by the embodiments of the present application are described in detail below through specific embodiments. It should be noted that the technical solutions provided by the embodiments of the present application may include part or all of the following contents, and the following specific embodiments may be combined with each other, and the same or similar concepts or processes may not be repeated in some embodiments.
[0094] Figure 2 A flowchart of a method for training a text segment recognition model provided in an embodiment of the present application is provided. The method of this embodiment can be performed by Figure 1 The model training platform in is executed. Figure 2 As shown, the method of this embodiment includes:
[0095] S201: receiving a plurality of sample texts and annotation information of each sample text from a client, wherein the annotation information of one sample text includes: at least one annotated text segment in the sample text and an annotation category to which each annotated text segment belongs.
[0096] In the embodiment of the present application, a sample text may be a sentence or a paragraph. The annotation information of the sample text may include one or more annotated text segments. An annotated text segment refers to a number of language units that appear continuously in the sample text. For example, the language unit of Chinese may be a Chinese character, and the language unit of English may be a word. The annotation information of the sample text may also include the annotation category to which each annotated text segment belongs.
[0097] It should be understood that the annotation information of the sample text (i.e., each annotated text segment and the annotation category to which it belongs) is annotated according to the specific text segment recognition task. Assuming that the text segment recognition task is used to recognize entities in the text, the annotation information of the sample text includes: at least one entity text segment and the entity category to which each entity text segment belongs. Assuming that the text segment recognition task is used to recognize emotions in the text, the annotation information of the sample text includes: at least one emotion text segment and the emotion category to which each emotion text segment belongs. Assuming that the text segment recognition task is used to recognize clauses in a contract text, the annotation information of the sample text includes: at least one clause text segment and the clause category to which each clause text segment belongs.
[0098] For example, taking the entity recognition task as an example, assuming that the sample text is "Zhang San's ancestral home is in Shijiazhuang", the annotations of the sample text may include: {Zhang San, a person's name}, {Shijiazhuang, a place name}.
[0099] S202: Generate a training sample data set according to the subordinate relationship between the annotated text segments in the plurality of sample texts and the annotated categories to which they belong, and the companion relationship between different annotated text segments belonging to the same annotated category in the plurality of sample texts.
[0100] In the embodiment of the present application, based on the multiple sample texts input by the client and their annotation information, the model training platform can analyze and obtain the subordinate relationship between the annotated text segments in the multiple sample texts and the annotation categories to which they belong, and the companion relationship between different annotated text segments belonging to the same annotation category in the multiple sample text segments. Furthermore, the subordinate relationship between the annotated text segments in the multiple sample texts and the annotation categories to which they belong, and the companion relationship between different annotated text segments belonging to the same annotation category in the multiple sample text segments are used to construct a training sample data set.
[0101] Combine the following Figure 3 Give an example. Figure 3 The following is a schematic diagram of the subordinate relationship and the companion relationship provided in the embodiment of the present application. Figure 3 As shown, take the following three sample texts as examples:
[0102] Sample text 1: "Zhang San's ancestral home is in Shijiazhuang", its annotation information includes: {Zhang San, name}, {Shijiazhuang, place name}
[0103] Sample text 2: "Zhang San currently lives in Xi'an", its annotation information includes: {Zhang San, name}, {Xi'an, place name};
[0104] Sample text 3: "Li Si's workplace is in Luoyang", its annotation information includes: {Li Si, name}, {Luoyang, place name};
[0105] Based on the above three sample texts and their annotation information, we can sort out the following subordinate relationships: "Zhang San" and "person's name" are in a subordinate relationship, "Li Si" and "person's name" are in a subordinate relationship, "Shijiazhuang" and "place name" are in a subordinate relationship, "Xi'an" and "place name" are in a subordinate relationship, and "Luoyang" and "place name" are in a subordinate relationship.
[0106] Based on the above two sample texts and their annotation information, we can sort out the following companion relationships: "Zhang San" and "Li Si" are companion relationships, "Shijiazhuang" and "Xi'an" are companion relationships, "Xi'an" and "Luoyang" are companion relationships, and "Shijiazhuang" and "Luoyang" are companion relationships.
[0107] Furthermore, the obtained subordinate and companion relationships can be used to construct a training sample data set. For example, a part of the training samples can be constructed based on the subordinate relationship, and a part of the training samples can be constructed based on the companion relationship. The two parts of the training samples can be combined to obtain a training sample data set.
[0108] In an embodiment of the present application, each training sample in the training sample data set satisfies the following triple data structure: {query text, text to be queried, text segment that satisfies the query}. The sample text is the text to be queried, and the query text is used to indicate the query condition for querying the sample text. The annotated text segment is the text segment in the sample text that satisfies the query condition. In the above triples, the query text and the sample text serve as the input of the text segment recognition model, and the annotated text segment serves as the expected output of the text segment recognition model.
[0109] Exemplarily, for the above-mentioned subordinate relationship, the following training samples can be generated:
[0110] {"Search for text segments belonging to the category of names", "Zhang San's ancestral home is in Shijiazhuang", "Zhang San"};
[0111] {"Search for text segments belonging to the category of names", "Zhang San currently lives in Xi'an", "Zhang San"};
[0112] {"Search for text segments belonging to the category of names", "Li Si's workplace is in Luoyang", "Li Si"};
[0113] {"Search for text segments belonging to the place name category", "Zhang San's ancestral home is in Shijiazhuang", "Shijiazhuang"};
[0114] {"Search for text segments belonging to the place name category", "Zhang San currently lives in Xi'an", "Xi'an"};
[0115] {"Search for text segments belonging to the place name category", "Li Si's workplace is in Luoyang", "Luoyang"};
[0116] For the above peer relationship, the following training samples can be generated:
[0117] {"Search for text segments similar to Li Si", "Zhang San's ancestral home is in Shijiazhuang", "Zhang San"};
[0118] {"Search for text segments similar to Li Si", "Zhang San currently lives in Xi'an", "Zhang San"};
[0119] {"Search for text segments similar to Zhang San", "Li Si's workplace is in Luoyang", "Li Si"};
[0120] {"Search for text segments similar to Shijiazhuang", "Zhang San currently lives in Xi'an", "Xi'an"};
[0121] {"Search for text segments similar to Shijiazhuang", "Li Si's workplace is in Luoyang", "Luoyang"};
[0122] {"Search for text segments similar to Xi'an", "Zhang San's ancestral home is in Shijiazhuang", "Shijiazhuang"};
[0123] {"Search for text segments similar to Xi'an", "Li Si's workplace is in Luoyang", "Luoyang"};
[0124] {"Search for text segments similar to Luoyang", "Zhang San's ancestral home is in Shijiazhuang", "Shijiazhuang"};
[0125] {"Search for text segments similar to Luoyang", "Zhang San currently lives in Xi'an", "Xi'an"};
[0126] The above two parts of training samples constitute the training sample data set.
[0127] In the embodiment of the present application, the companion relationship is a by-product of the subordinate relationship. The companion relationship does not need additional annotation, and the number is very abundant, which is the square of the subordinate relationship, and can increase the number of training samples. For example, in the above example, if only the subordinate relationship is used, only 6 training samples can be constructed; and if both the subordinate relationship and the companion relationship are used, 14 training samples can be constructed. In addition, the companion relationship provides information about other text segments similar to the content of the text segment, enriching the semantics of the category to which the text segment belongs. That is to say, the training samples constructed using the companion relationship can be used to enhance the semantic representation of the annotated text segment, thereby improving the model training performance.
[0128] S203: Using the training sample data set to train the text segment recognition model to be trained, to obtain a trained text segment recognition model.
[0129] The embodiments of the present application do not limit the network structure of the text segment recognition model. In some possible implementations, the text segment recognition model can adopt a framework based on machine reading comprehension. Optionally, the text segment recognition model can be a multi-text segment extraction machine reading comprehension (Multi-span MRC) model based on Transformer, or it can also be other variant models based on Transformer. The Multi-span MRC model has the ability to query multiple text segments. Optionally, the text segment recognition model can be a sequence-to-sequence model based on a convolutional neural network (CNN) or a recurrent neural network (RNN).
[0130] The embodiments of the present application do not limit the training process of the text segment recognition model. Exemplarily, for each training sample {query text, text to be queried, text segment that satisfies the query}, the first two elements in the above triplet (i.e., query text, sample text) can be used as the input of the text segment recognition model to obtain the predicted text segment output by the text segment recognition model. According to the difference between the predicted text segment and the third element in the above triplet (i.e., the annotated text segment), the loss value is determined. With the goal of minimizing the loss value, the model parameters of the text segment recognition model are updated. Determine whether the updated text segment recognition model meets the preset convergence conditions. If so, the updated text segment recognition model is determined as the trained text segment recognition model; if not, repeat the above training process until the updated text segment recognition model meets the preset convergence conditions.
[0131] The training method of the text segment recognition model provided by the embodiment of the present application includes: receiving multiple sample texts and annotation information of each sample text from a client, wherein the annotation information of a sample text includes: at least one annotated text segment in the sample text and the annotation category to which each annotated text segment belongs; generating a training sample data set according to the subordinate relationship between the annotated text segments in the multiple sample texts and the annotation category to which they belong, and the companion relationship between different annotated text segments belonging to the same annotation category in the multiple sample texts; and training the text segment recognition model to be trained using the training sample data set to obtain a trained text segment recognition model. In the above model training, not only the subordinate relationship between each text segment in the sample text and the category to which it belongs, but also the companion relationship between different text segments belonging to the same category in the sample text are utilized, so that the semantic features of the annotated text segments in the sample text can be better learned, the utilization rate of the sample text is improved, and even when the number of sample texts is small, a text segment recognition model with high recognition performance can be trained.
[0132] Based on the above embodiments, the present application scheme is described in more detail below in conjunction with a specific embodiment.
[0133] Figure 4 A flowchart of another text segment recognition model training method provided in an embodiment of the present application. This embodiment provides a detailed description of the generation process of the training sample data set. Figure 4 As shown, the method of this embodiment includes:
[0134] S401: receiving a plurality of sample texts and annotation information of each sample text from a client, wherein the annotation information of one sample text includes: at least one annotated text segment in the sample text and an annotation category to which each annotated text segment belongs.
[0135] It should be understood that the specific implementation of S401 is different from Figure 2 S201 in the illustrated embodiment is similar and will not be described in detail here.
[0136] S402: Generate multiple groups of first training samples according to the companion relationship between different annotated text segments belonging to the same annotated category in the multiple sample texts.
[0137] In this embodiment, any two annotated text segments with a companion relationship can be formed into a data pair, which can be called a companion relationship data pair. Multiple companion relationship data pairs can be generated based on the companion relationship between different annotated text segments belonging to the same annotation category in multiple sample texts, and then multiple groups of first training samples can be generated based on the multiple companion relationship data pairs.
[0138] In some possible implementations, multiple groups of first training samples may be generated in the following manner:
[0139] (1) Each annotated text segment in the plurality of sample texts is divided into at least one text segment set, wherein the annotated text segments in each text segment set belong to the same annotated category, and the annotated text segments in different text segment sets belong to different annotated categories.
[0140] That is to say, each annotated text segment belonging to the same annotated category is divided into a text segment set. In this way, assuming that N annotated categories appear in a plurality of sample texts, N text segment sets are obtained by division.
[0141] Combine the following Figure 5 Give an example. Figure 5 The schematic diagram of the generation process of the first training sample provided in the application embodiment. Figure 5 As shown, take the following three sample texts as examples:
[0142] Sample text 1: "Zhang San's ancestral home is in Shijiazhuang", its annotation information includes: {Zhang San, name}, {Shijiazhuang, place name}
[0143] Sample text 2: "Zhang San currently lives in Xi'an", its annotation information includes: {Zhang San, name}, {Xi'an, place name};
[0144] Sample text 3: "Li Si's workplace is in Luoyang", its annotation information includes: {Li Si, name}, {Luoyang, place name};
[0145] The annotated text segments belonging to the "personal name" category in the above three sample texts are divided into a text segment set, and the annotated text segments belonging to the "place name" category in the above three sample texts are divided into a text segment set. In this way, two text segment sets are obtained, namely {Zhang San, Li Si} and {Shijiazhuang, Xi'an, Luoyang}.
[0146] (2) Based on the at least one text segment set, a plurality of companion relationship data pairs are generated, each companion relationship data pair includes a first annotated text segment and a second annotated text segment, and the first annotated text segment and the second annotated text segment are two different annotated text segments in the same text segment set.
[0147] Exemplarily, any two different annotated text segments in each text segment set may be arranged and combined to obtain a plurality of companion relationship data pairs.
[0148] Continue to see Figure 5 , for the text segment set {Zhang San, Li Si} corresponding to the “name” category, by arranging and combining any two annotated text segments in the text segment set, we can get two companion relationship data pairs, which are:
[0149] <Zhang San, Li Si>
[0150] <Li Si, Zhang San>
[0151] For the text segment set {Shijiazhuang, Xi'an, Luoyang} corresponding to the "place name" category, by arranging and combining any two different annotated text segments in the text segment set, 6 companion relationship data pairs can be obtained, which are:
[0152] <Shijiazhuang, Xi'an>
[0153] <Shijiazhuang, Luoyang>
[0154] <Xi'an, Luoyang>
[0155] <Xi'an, Shijiazhuang>
[0156] <Luoyang, Shijiazhuang>
[0157] <Luoyang, Xi'an>
[0158] (3) Generate at least one set of first training samples according to each companion relationship data pair to obtain the multiple sets of first training samples.
[0159] For each companion relationship data pair generated in step (2), one or more groups of first training samples can be generated, wherein each group of first training samples satisfies the following triple data structure: {query text, text to be queried, text segment satisfying the query}.
[0160] In one possible implementation, for each companion relationship data pair, one or more groups of first training samples can be generated in the following manner: a first query text is generated based on the first annotated text segment in the companion relationship data pair, the first query text includes the first annotated text segment, and the first query text is used to query text segments that have a companion relationship with the first annotated text segment; based on the second annotated text segment in the companion relationship data pair, at least one first sample text is determined from the multiple sample texts, the first sample text includes the second annotated text segment; based on the first query text, the at least one first sample text, and the second annotated text segment, at least one group of first training samples is generated.
[0161] Combine the following Figure 5 Give an example.
[0162] For the companion relationship data pair <Zhang San, Li Si>, "Zhang San" is used as the first annotated text segment, and "Li Si" is used as the second annotated text segment. A first query text "search for text segments similar to Zhang San" is generated based on "Zhang San", and a sample text containing "Li Si" is found in multiple sample texts as the first sample text. For example, the first sample text is "Li Si's work unit is in Luoyang". In this way, a set of first training samples is generated based on the above first query text, the first sample text and the second annotated text segment, as follows:
[0163] {"Search for text segments similar to Zhang San", "Li Si's workplace is in Luoyang", "Li Si"}.
[0164] For the companion relationship data pair <Li Si, Zhang San>, "Li Si" is used as the first annotated text segment, and "Zhang San" is used as the second annotated text segment. According to "Li Si", a first query text "search for text segments similar to Li Si" is generated, and a sample text containing "Zhang San" is found in multiple sample texts as the first sample text. For example, two first sample texts are found, namely "Zhang San's ancestral home is in Shijiazhuang" and "Zhang San currently lives in Xi'an". In this way, according to the above first query text, the above two first sample texts, and the second annotated text segment, two groups of first training samples can be generated, namely:
[0165] {"Search for text segments similar to Li Si", "Zhang San's ancestral home is in Shijiazhuang", "Zhang San"};
[0166] {"Search for text segments similar to Li Si", "Zhang San currently lives in Xi'an", "Zhang San"}.
[0167] By adopting the above-mentioned similar processing method, for other companion relationship data pairs, the following first training samples can be generated:
[0168] {"Search for text segments similar to Shijiazhuang", "Zhang San currently lives in Xi'an", "Xi'an"};
[0169] {"Search for text segments similar to Shijiazhuang", "Li Si's workplace is in Luoyang", "Luoyang"};
[0170] {"Search for text segments similar to Xi'an", "Li Si's workplace is in Luoyang", "Luoyang"};
[0171] {"Search for text segments similar to Xi'an", "Zhang San's native place is Shijiazhuang", "Shijiazhuang"};
[0172] {"Search for text segments similar to Luoyang", "Zhang San's native place is Shijiazhuang", "Shijiazhuang"};
[0173] {"Search for text segments similar to Luoyang", "Zhang San currently lives in Xi'an", "Xi'an"}
[0174] It should be understood that the processing process of other companion relationship data pairs is similar to the above, and this embodiment does not provide examples one by one.
[0175] See also Figure 5 ,According to the companion relationship between each annotated text segment in the three sample texts, a total of 9 groups of first training samples are generated.
[0176] Figure 5 In the example shown, for each text segment set, assuming that the text segment set includes M annotated text segments, M*(M-1) peer relationship data pairs can be obtained by arranging and combining the annotated text segments in the text segment set. Furthermore, the number of first training samples generated based on M*(M-1) peer relationship data is greater than or equal to M*(M-1). It can be seen that when the number of annotated text segments in multiple sample texts is large, the number of first training samples generated based on peer relationships is also large.
[0177] In the process of model training, when the number of training samples is too large, the model training process will take a long time, reducing the efficiency of model training. To this end, in some possible implementations of the embodiments of the present application, the above step (2) can be implemented in the following manner:
[0178] Arrange and combine any two different annotated text segments in each text segment set to obtain multiple candidate data pairs corresponding to the text segment set. Figure 5 In the example shown, for the text segment set {Zhang San, Li Si}, any two different annotated text segments are arranged and combined to obtain two candidate data pairs, namely: <Zhang San, Li Si> and <Li Si, Zhang San>; for the text segment set {Shijiazhuang, Xi'an, Luoyang}, any two different annotated text segments are arranged and combined to obtain six candidate data pairs, namely: <Shijiazhuang, Xi'an>, <Shijiazhuang, Luoyang>, <Xi'an, Luoyang>, <Xi'an, Shijiazhuang>, <Luoyang, Shijiazhuang>, <Luoyang, Xi'an>.
[0179] Further, the plurality of candidate data pairs corresponding to at least part of the text segment sets in the at least one text segment set are sampled to obtain the plurality of companion relationship data pairs; the number of the companion relationship data pairs is less than the number of the candidate data pairs. The sampling process means: selecting a part of the candidate data pairs corresponding to a certain text segment set / sets as companion relationship data pairs.
[0180] For example, combined with Figure 5 In the example shown, at least some of the candidate data pairs can be selected as companion relationship data pairs from the two candidate data pairs corresponding to the text segment set {Zhang San, Li Si}, and at least some of the candidate data pairs can be selected as companion relationship data pairs from the six candidate data pairs corresponding to the text segment set {Shijiazhuang, Xi'an, Luoyang}.
[0181] It should be noted that, in actual applications, sampling processing may be performed on candidate data pairs corresponding to all text segment sets, or sampling processing may be performed only on candidate data pairs corresponding to some text segment sets, and the embodiments of the present application do not limit this.
[0182] Optionally, for any first text segment set in the at least one text segment set, sampling processing can be performed on multiple candidate data pairs corresponding to the first text segment set in the following manner: determining the sampling number corresponding to the first text segment set, and sampling processing is performed on the multiple candidate data pairs corresponding to the first text segment set according to the sampling number; wherein the sampling number is related to one or more of the following: a preset sampling ratio, a difference between the number of annotated text segments included in the second text segment set and the number of annotated text segments included in the first text segment set; the second text segment set is the text segment set containing the largest number of annotated text segments in the at least one text segment set.
[0183] The following examples illustrate several ways to determine sampling data.
[0184] Method 1: Assuming that the number of annotated text segments included in the first text segment set is S1, the sampling number T can be determined by the following formula:
[0185] T=λ*S1
[0186] Among them, λ is the preset sampling ratio.
[0187] In this manner, the candidate data pairs corresponding to each text segment set are sampled based on a preset sampling ratio, so that the sampling process does not change the quantity distribution of the candidate data pairs corresponding to each text segment set.
[0188] Method 2: Assuming that the number of annotated text segments included in the first text segment set is S1, and the number of annotated text segments included in the second text segment set is S2, the sampling number T can be determined by the following formula:
[0189] T=S2-S1
[0190] In this method, the number of samples is determined based on the difference between the number of annotated text segments included in the second text segment set and the number of annotated text segments included in the first text segment set, so that the number of companion relationship data pairs corresponding to each text segment set after sampling is relatively balanced. In turn, the recognition performance of the model for various annotated categories is relatively balanced.
[0191] Method 3 is equivalent to the combination of the above methods 1 and 2. Assuming that the number of annotated text segments included in the first text segment set is S1, and the number of annotated text segments included in the second text segment set is S2, the sampling number T can be determined by the following formula:
[0192] T=λ*S1+(S2-S1)
[0193] Among them, λ is the preset sampling ratio.
[0194] It should be understood that by sampling the candidate data pairs corresponding to at least part of the text segment set, the number of companion relationship data pairs output in step (2) can be reduced, thereby reducing the number of first training samples generated in step (3), thereby avoiding affecting the model training efficiency and achieving a balance between model recognition performance and model training efficiency.
[0195] S403: Generate multiple groups of second training samples according to the subordinate relationship between the annotated text segments in the multiple sample texts and the annotated categories to which they belong.
[0196] In this embodiment, for each annotation category, each sample text in the multiple sample texts may be traversed respectively, and a group of second training samples may be generated based on the annotation category and the sample text, thereby obtaining multiple groups of second training samples.
[0197] In a possible implementation, multiple groups of second training samples may be generated in the following manner:
[0198] (1) Deduplication processing is performed on the annotation categories to which each annotated text segment in the plurality of sample texts belongs, to obtain an annotation category set.
[0199] That is, the annotation category set includes all the annotation categories that have appeared in the annotation information of the plurality of sample texts, and the annotation categories in the annotation category set are not repeated.
[0200] Combine the following Figure 6 Give an example. Figure 6 Schematic diagram of the generation process of the second training sample provided in the embodiment of the present application. Figure 6 As shown, take the following three sample texts as examples:
[0201] Sample text 1: "Zhang San's ancestral home is in Shijiazhuang", its annotation information includes: {Zhang San, name}, {Shijiazhuang, place name}
[0202] Sample text 2: "Zhang San currently lives in Xi'an", its annotation information includes: {Zhang San, name}, {Xi'an, place name};
[0203] Sample text 3: "Li Si's workplace is in Luoyang", its annotation information includes: {Li Si, name}, {Luoyang, place name};
[0204] The annotation information of the above three sample texts includes two annotation categories, namely "personal name" and "place name". Therefore, the obtained annotation category set is {personal name, place name}.
[0205] (2) For each annotation category in the annotation category set, generate a second query text corresponding to the annotation category, wherein the second query text includes the annotation category, and the second query text is used to query text segments belonging to the annotation category.
[0206] For example, for the marked category “personal name”, a second query text “query text segments belonging to the person name category” is generated. For the marked category “place name”, a second query text “query text segments belonging to the place name category” is generated.
[0207] (3) Generating the plurality of groups of second training samples according to the second query text corresponding to each annotation category in the annotation category set and the subordinate relationship between each annotation text segment in the plurality of sample texts and the annotation category to which it belongs.
[0208] In this embodiment, for each annotation category in the annotation category set, each sample text in the multiple sample texts can be traversed respectively, and a set of second training samples can be generated based on the annotation category and the sample text, thereby obtaining multiple sets of second training samples. Each set of second training samples satisfies the following triple data structure: {query text, text to be queried, text segment that satisfies the query}.
[0209] In a possible implementation, for each annotation category in the annotation category set, each sample text in the multiple sample texts is traversed respectively. If there is an annotation text segment belonging to the annotation category in the sample text, a group of second training samples is generated according to the second query text corresponding to the annotation category, the sample text, and the annotation text segment belonging to the annotation category in the sample text; or, if there is no annotation text segment belonging to the annotation category in the sample text, a group of second training samples is generated according to the second query text corresponding to the annotation category, the sample text, and an empty text segment.
[0210] Combine the following Figure 6 Give an example.
[0211] For the annotation category "name" in the annotation category set, traverse each sample text as follows:
[0212] For sample text 1, since there is a labeled text segment "Zhang San" belonging to the "name" category in sample text 1, a set of second training samples {"query text segments belonging to the name category", "Zhang San's ancestral home is in Shijiazhuang", "Zhang San"} is generated;
[0213] For sample text 2, since there is a labeled text segment "Zhang San" belonging to the "name" category in sample text 2, a set of second training samples {"query text segments belonging to the name category", "Zhang San currently lives in Xi'an", "Zhang San"} is generated;
[0214] For sample text 3, since there is a labeled text segment "Li Si" belonging to the "name" category in sample text 3, a set of second training samples {"query text segments belonging to the name category", "Li Si's work unit is in Luoyang", "Li Si"} is generated;
[0215] For the annotation category "place name" in the annotation category set, traverse each sample text segment as follows:
[0216] For sample text 1, since there is a labeled text segment "Shijiazhuang" belonging to the "place name" category in sample text 1, a set of second training samples {"query text segments belonging to the place name category", "Zhang San's ancestral home is in Shijiazhuang", "Shijiazhuang"} is generated;
[0217] For sample text 2, since there is a labeled text segment "Xi'an" belonging to the "place name" category in sample text 2, a set of second training samples {"query text segments belonging to the place name category", "Zhang San currently lives in Xi'an", "Xi'an"} is generated;
[0218] For sample text 3, since there is a labeled text segment "Luoyang" belonging to the "place name" category in sample text 3, a set of second training samples {"query text segments belonging to the place name category", "Li Si's work unit is in Luoyang", "Luoyang"} is generated;
[0219] See also Figure 6 ,According to the subordinate relationship between each annotated text segment in the three sample texts and its corresponding annotated category, a total of 6 groups of second training samples are generated.
[0220] It should be noted that in some scenarios, when a certain annotation category is combined with a sample text, there may not be an annotation text segment belonging to the annotation category in the sample text. For example, taking the annotation category "place name" as an example, assuming that there is a sample text 4 "Zhang San's is a boy", there is no annotation text segment belonging to the "place name" category in the sample text 4. At this time, a set of second training samples {"query for text segments belonging to the place name category", "Zhang San's is a boy", "empty"} is generated. It should be understood that through this type of second training samples, the model can accurately identify the situation where a text segment of a certain annotation category does not exist, thereby improving the model's text segment recognition ability.
[0221] S404: Generate the training sample data set according to the multiple groups of first training samples and the multiple groups of second training samples.
[0222] For example, according to Figure 5 The example shown generates 9 sets of first training samples and Figure 6 The example shown generates 6 sets of second training samples to generate a training sample data set, which includes 15 training samples in total.
[0223] In the embodiment of the present application, by constructing the first training sample based on the companion relationship between the annotated text segments, the number of training samples in the training sample data set is greatly increased, and the increased number of training samples is the square of the number of training samples based only on the subordinate relationship. Therefore, even in the case of only a small amount of annotated text, a high-quality training sample data set can be automatically constructed at a squared scale, and almost no noise is introduced.
[0224] S405: Using the training sample data set to train the text segment recognition model to be trained, to obtain a trained text segment recognition model.
[0225] In this embodiment, the first training sample and the second training sample have the same format and both satisfy the following triple data structure: {query text, text to be queried, text segment satisfying the query}. That is, each training sample in the training sample data set satisfies the above triple data structure.
[0226] For example, taking the first training sample {"Query text segments similar to Zhang San", "Li Si's work unit is in Luoyang", "Li Si"} as an example, "Query text segments similar to Zhang San" is the query text, "Li Si's work unit is in Luoyang" is the text to be queried, and "Li Si" is the text segment that meets the query.
[0227] Taking the second training sample {"Query the text segment belonging to the category of personal name", "Li Si's work unit is in Luoyang", "Li Si"} as an example, "Query the text segment belonging to the category of personal name" is the query text, "Li Si's work unit is in Luoyang" is the text to be queried, and "Li Si" is the text segment that satisfies the query.
[0228] When the text segment recognition model is trained using the training sample data set, the query text and the text to be queried in the first training sample / the second training sample are input into the text segment recognition model to obtain the predicted text segment output by the model.
[0229] Combination Figure 7 Give an example. Figure 7 Schematic diagram of the input and output of the text segment recognition model provided in the embodiment of the present application. Figure 7 As shown in FIG. 1 , it is assumed that the input format of the text segment recognition model is “[CLS] query text [SEP] to be queried text [SEP]”, and the output of the model is the predicted text segment. Among them, [CLS] and [SEP] are preset separator characters.
[0230] For the first training sample, taking {"Query text segments similar to Zhang San", "Li Si's workplace is in Luoyang", "Li Si"} as an example, the query text "Query text segments similar to Zhang San" and the text to be queried "Li Si's workplace is in Luoyang" are concatenated to obtain the model input text "[CLS] Query text segments similar to Zhang San [SEP] Li Si's workplace is in Luoyang [SEP]".
[0231] For the second training sample, taking {"Query text segments belonging to the category of names", "Li Si's workplace is in Luoyang", "Li Si"} as examples, the query text "Query text segments belonging to the category of names" and the text to be queried "Li Si's workplace is in Luoyang" are concatenated to obtain the model input text "[CLS]Query text segments belonging to the category of names[SEP]Li Si's workplace is in Luoyang[SEP]".
[0232] The above model input text is input into the text segment recognition model, and the text segment recognition model is processed by recognition and outputs a predicted text segment. Then, the loss function is determined based on the predicted text segment and the "text segment that meets the query" in the training sample. With the goal of minimizing the loss function, the model parameters of the text segment recognition model are updated. The above training process is repeated continuously until the text segment recognition model reaches the preset convergence condition, and a trained text segment recognition model is obtained. It should be understood that in the actual training process, one training sample or multiple training samples can be input into the model in each round of iteration, and this embodiment does not limit this. Figure 7 The example shows the case of inputting two training samples.
[0233] In this embodiment, since the format of the first training sample and the second training sample is the same, when the text segment recognition model is trained using the training sample data set, the first training sample and the second training sample can be not distinguished. In other words, the first training sample and the second training sample can be mixed together for model training. There is no need to distinguish the first training sample and the second training sample inside the model. Therefore, there is no need to modify the model structure and the processing process inside the model, so that the model can learn the subordinate relationship and the companion relationship at the same time, which reduces the difficulty of implementation.
[0234] Furthermore, in the technical solution of the embodiment of the present application, by constructing the training samples into a data structure of triplets of {query text, text to be queried, text segment that satisfies the query}, the training data of various types of text segment recognition tasks can be summarized into the same form of data format, so that one model can solve various types of text segment recognition tasks at the same time, and can also improve the model's portability and versatility.
[0235] In addition, the technical solution of the present application performs data enhancement based on the existing data itself without involving external resources and tools, and has wide applicability.
[0236] Combined with the above Figures 2 to 7 The training process of the text segment recognition model is described below. Fig. 8A and Figure 8B The process of using a text segment recognition model is described.
[0237] Fig. 8A A flowchart of a text segment recognition method provided in an embodiment of the present application is shown in FIG8 . As shown in FIG8 , the method of this embodiment includes:
[0238] S801: Acquire a query text and a target text, wherein the query text is used to search for a text segment belonging to a preset category in the target text.
[0239] S802: Processing the query text and the target text by using a trained text segment recognition model to obtain at least one target text segment in the target text, or to obtain an empty text segment, wherein the target text segment belongs to the preset category.
[0240] The text segment recognition model is obtained by training using the model training method provided by any of the above method embodiments.
[0241] Exemplarily, the query text and the target text are input into the text segment recognition model. If the text segment recognition model finds a target text segment belonging to a preset category in the target text, the target text segment is output. If the text recognition model does not find a target text segment belonging to a preset category in the target text, an empty text segment is output.
[0242] It should be understood that the text segment recognition method of this embodiment can be applied to various recognition tasks, including but not limited to: named entity recognition, attribute-based sentiment analysis, contract clause extraction, etc.
[0243] When applied to different recognition tasks, the query text of the input model is different. For example, when applied to named entity recognition, the query text is used to query the text segments belonging to the preset entity category in the target text; when applied to attribute-based sentiment analysis, the query text is used to query the text segments belonging to the preset sentiment category in the target text; when applied to contract clause extraction, the query text is used to query the text segments belonging to the preset clause category in the target text.
[0244] Figure 8B A flowchart of another text segment recognition method provided in an embodiment of the present application. Figure 8B As shown, the method of this embodiment includes:
[0245] S811: Obtain target text.
[0246] S812: Process the target text through the trained text segment recognition model to obtain at least one target text segment in the target text and the category to which each target text segment belongs, or obtain an empty text segment.
[0247] The text segment recognition model is obtained by training using the model training method provided by any of the above method embodiments.
[0248] Exemplarily, the target text is input into the text recognition model, and the text recognition model performs the following processing for each preset category in a plurality of preset categories: query processing is performed on the target text according to the query text corresponding to the preset category to determine whether there is a target text segment belonging to the preset category in the target text, and if so, the target text segment and the preset category are output. If there is no text segment belonging to any of the preset categories in the target text, an empty text segment is output. The plurality of preset categories may be categories trained during the model training process.
[0249] In this embodiment, since the text segment recognition model not only utilizes the subordinate relationship but also utilizes the companion relationship during the training process, the text segment recognition model has a higher recognition performance. Furthermore, in this embodiment, when the text segment recognition model is used to perform text segment recognition, the accuracy of the text segment recognition result can be improved.
[0250] The above describes the training method of the text segment recognition model and the text segment recognition method provided in the embodiments of the present application. The following describes the training device of the text segment recognition model and the text segment recognition device provided in the embodiments of the present application.
[0251] The embodiment of the present application can divide the functional modules of the training device of the text segment recognition model and the text segment recognition device according to the above method embodiment. For example, each functional module can be divided according to each function, or two or more functions can be integrated into one processing module. The above integrated module can be implemented in the form of hardware or software functional modules.
[0252] It should be noted that the division of modules in the embodiment of the present application is schematic and is only a logical function division. There may be other division methods in actual implementation. The following is an example of dividing each functional module using the corresponding functions.
[0253] Fig. 9 A structural diagram of a training device for a text segment recognition model provided in an embodiment of the present application. Fig. 9 As shown, the text segment recognition model training device 900 provided in this embodiment includes: a receiving module 901, a generating module 902 and a training module 903.
[0254] The receiving module 901 is used to receive multiple sample texts and annotation information of each sample text from a client, wherein the annotation information of one sample text includes: at least one annotated text segment in the sample text and the annotation category to which each annotated text segment belongs;
[0255] A generating module 902, configured to generate a training sample data set according to the subordinate relationship between the annotated text segments in the plurality of sample texts and the annotated categories to which they belong, and the companion relationship between different annotated text segments belonging to the same annotated category in the plurality of sample texts;
[0256] The training module 903 is used to train the text segment recognition model to be trained using the training sample data set to obtain a trained text segment recognition model.
[0257] In some possible implementations, the generating module 902 is specifically used for:
[0258] generating a plurality of groups of first training samples according to the companion relationship between different annotated text segments belonging to the same annotated category in the plurality of sample texts;
[0259] generating a plurality of groups of second training samples according to the subordinate relationships between the annotated text segments in the plurality of sample texts and the annotated categories to which they belong;
[0260] The training sample data set is generated according to the multiple groups of first training samples and the multiple groups of second training samples.
[0261] In some possible implementations, the generating module 902 is specifically used for:
[0262] Dividing each annotated text segment in the plurality of sample texts into at least one text segment set, wherein the annotated text segments in each text segment set belong to the same annotated category, and the annotated text segments in different text segment sets belong to different annotated categories;
[0263] Generate a plurality of companion relationship data pairs according to the at least one text segment set; each companion relationship data pair includes a first annotated text segment and a second annotated text segment, wherein the first annotated text segment and the second annotated text segment are two different annotated text segments in the same text segment set;
[0264] At least one set of first training samples is generated according to each companion relationship data pair to obtain the multiple sets of first training samples.
[0265] In some possible implementations, the generating module 902 is specifically used for:
[0266] Generate a first query text according to the first annotated text segment in the companion relationship data pair, the first query text including the first annotated text segment, and the first query text is used to query a text segment having a companion relationship with the first annotated text segment;
[0267] According to the second annotated text segment in the companion relationship data pair, determining at least one first sample text from the plurality of sample texts, the first sample text including the second annotated text segment;
[0268] The at least one set of first training samples is generated according to the first query text, the at least one first sample text, and the second annotated text segment.
[0269] In some possible implementations, the generating module 902 is specifically used for:
[0270] Arrange and combine any two different annotated text segments in each text segment set to obtain multiple candidate data pairs corresponding to the text segment set;
[0271] The plurality of candidate data pairs corresponding to at least a portion of the text segment set are sampled to obtain the plurality of companion relationship data pairs; the number of the companion relationship data pairs is less than the number of the candidate data pairs.
[0272] In some possible implementations, for any first text segment set in the at least one text segment set, the generating module 902 is specifically configured to:
[0273] Determining the number of samples corresponding to the first text segment set;
[0274] Performing sampling processing on the plurality of candidate data pairs corresponding to the first text segment set according to the sampling quantity;
[0275] Among them, the sampling quantity is related to one or more of the following: a preset sampling ratio, the difference between the number of annotated text segments included in the second text segment set and the number of annotated text segments included in the first text segment set; the second text segment set is the text segment set containing the largest number of annotated text segments among the at least one text segment set.
[0276] In some possible implementations, the generating module 902 is specifically used for:
[0277] Deduplication processing is performed on the annotation categories to which each annotated text segment in the plurality of sample texts belongs, to obtain an annotation category set;
[0278] For each annotation category in the annotation category set, generate a second query text corresponding to the annotation category, the second query text includes the annotation category, and the second query text is used to query text segments belonging to the annotation category;
[0279] The plurality of groups of second training samples are generated according to the second query text corresponding to each annotation category in the annotation category set and the subordinate relationship between each annotation text segment in the plurality of sample texts and the annotation category to which it belongs.
[0280] In some possible implementations, the generating module 902 is specifically used for:
[0281] For each annotation category in the annotation category set, traverse each sample text in the multiple sample texts respectively:
[0282] If there is an annotated text segment belonging to the annotated category in the sample text, a set of second training samples is generated according to a second query text corresponding to the annotated category, the sample text, and the annotated text segment belonging to the annotated category in the sample text; or,
[0283] If there is no annotated text segment belonging to the annotated category in the sample text, a group of second training samples is generated according to the second query text corresponding to the annotated category, the sample text, and an empty text segment.
[0284] The training device for the text segment recognition model provided in this embodiment can execute the training method for the text segment recognition model provided in any of the above method embodiments. The implementation principles and technical effects are similar and will not be repeated here.
[0285] Fig.10 The following is a schematic diagram of the structure of a text segment recognition device provided in an embodiment of the present application. Fig.10 As shown, the text segment recognition device 1000 provided in this embodiment includes: an acquisition module 1001 and a processing module 1002. Among them,
[0286] The acquisition module 1001 is used to acquire a query text and a target text, wherein the query text is used to search for a text segment belonging to a preset category in the target text; the processing module 1002 is used to process the query text and the target text input through a trained text segment recognition model to obtain at least one target text segment in the target text, or to obtain an empty text segment, wherein the target text segment belongs to the preset category.
[0287] or,
[0288] The acquisition module 1001 is used to acquire the target text; the processing module 1002 is used to process the target text through the trained text segment recognition model to obtain at least one target text segment in the target text and the category to which each target text segment belongs, or to obtain an empty text segment.
[0289] The text segment recognition model is as follows: Fig. 9The text segment recognition model shown is trained by a training device.
[0290] The text segment recognition device provided in this embodiment can execute the text segment recognition method provided in the above method embodiment. Its implementation principle and technical effect are similar and will not be described in detail here.
[0291] Fig.11 This is a schematic diagram of the structure of an electronic device provided in an embodiment of the present application. Fig.11 As shown, the electronic device 1100 provided in this embodiment includes: a memory 1101 and at least one processor 1102; the memory 1101 stores a computer program, and the computer program is configured to be executed by the processor 1102 to implement the training method of the text segment recognition model provided in any of the above method embodiments, or the text segment recognition method, the implementation principles and technical effects of which are similar and will not be repeated here.
[0292] Optionally, the memory 1101 may be independent or integrated with the processor 1102. When the memory 1101 is a device independent of the processor 1102, the electronic device 1100 further includes a bus 1103 for connecting the memory 1101 and the processor 1102.
[0293] An embodiment of the present application also provides a computer-readable storage medium on which a computer program is stored. The computer program is executed by a processor to implement a training method for a text segment recognition model or a text segment recognition method as provided in any of the aforementioned method embodiments. The implementation principles and technical effects are similar and will not be elaborated here.
[0294] An embodiment of the present application provides a computer program product, including a computer program. When the computer program is executed by a processor, it implements a training method for a text segment recognition model or a text segment recognition method as provided in any of the aforementioned method embodiments. The implementation principles and technical effects are similar and will not be elaborated here.
[0295] An embodiment of the present application also provides a chip, including: a memory and a processor, wherein a computer program is stored in the memory, and the processor runs the computer program to implement the training method of the text segment recognition model or the text segment recognition method provided in any of the above method embodiments, and the implementation principles and technical effects are similar and will not be repeated here.
[0296] It should be understood that the processor may be a central processing unit (CPU), other general-purpose processors, digital signal processors (DSP), application-specific integrated circuits (ASIC), etc. A general-purpose processor may be a microprocessor or any conventional processor. The steps of the method disclosed in the invention may be directly implemented by a hardware processor or implemented by a combination of hardware and software modules in the processor.
[0297] The memory may include a high-speed RAM memory, and may also include a non-volatile storage NVM, such as at least one disk memory, and may also be a USB flash drive, a mobile hard disk, a read-only memory, a magnetic disk or an optical disk, etc.
[0298] The bus may be an Industry Standard Architecture (ISA) bus, a Peripheral Component Interconnect (PCI) bus, or an Extended Industry Standard Architecture (EISA) bus, etc. The bus may be divided into an address bus, a data bus, a control bus, etc. For ease of representation, the bus in the drawings of the present application is not limited to only one bus or one type of bus.
[0299] The above storage medium can be implemented by any type of volatile or non-volatile storage device or a combination thereof, such as static random access memory (SRAM), electrically erasable programmable read-only memory (EEPROM), erasable programmable read-only memory (EPROM), programmable read-only memory (PROM), read-only memory (ROM), magnetic memory, flash memory, magnetic disk or optical disk. The storage medium can be any available medium that can be accessed by a general or special purpose computer.
[0300] An exemplary storage medium is coupled to a processor so that the processor can read information from the storage medium and write information to the storage medium. Of course, the storage medium can also be a component of the processor. The processor and the storage medium can be located in an application specific integrated circuit (ASIC). Of course, the processor and the storage medium can also exist as discrete components in an electronic device.
[0301] 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.
[0302] Finally, it should be noted that the above embodiments are only used to illustrate the technical solutions of the present application, rather than to limit it. Although the present application has been described in detail with reference to the aforementioned embodiments, those skilled in the art should understand that they can still modify the technical solutions described in the aforementioned embodiments, or replace some or all of the technical features therein with equivalents. However, these modifications or replacements do not cause the essence of the corresponding technical solutions to deviate from the scope of the technical solutions of the embodiments of the present application.
Claims
1. A training method for a text segment recognition model, characterized in that: include: Receiving multiple sample texts and annotation information of each sample text from a client, wherein the annotation information of one sample text includes: at least one annotated text segment in the sample text and an annotation category to which each annotated text segment belongs; Generate a training sample data set according to the subordinate relationship between the annotated text segments in the plurality of sample texts and the annotated categories to which they belong, and the companion relationship between different annotated text segments belonging to the same annotated category in the plurality of sample texts; The training sample data set is used to train the text segment recognition model to be trained to obtain a trained text segment recognition model.
2. The method according to claim 1, characterized in that: Generating a training sample data set according to the subordinate relationship between the annotated text segments in the plurality of sample texts and the annotated categories to which they belong, and the companion relationship between different annotated text segments belonging to the same annotated category in the plurality of sample texts, comprises: generating a plurality of groups of first training samples according to the companion relationship between different annotated text segments belonging to the same annotated category in the plurality of sample texts; generating a plurality of groups of second training samples according to the subordinate relationships between the annotated text segments in the plurality of sample texts and the annotated categories to which they belong; The training sample data set is generated according to the multiple groups of first training samples and the multiple groups of second training samples.
3. The method according to claim 2, characterized in that Generating a plurality of groups of first training samples according to the companion relationship between different annotated text segments belonging to the same annotated category in the plurality of sample texts, including: Dividing each annotated text segment in the plurality of sample texts into at least one text segment set, wherein the annotated text segments in each text segment set belong to the same annotated category, and the annotated text segments in different text segment sets belong to different annotated categories; Generate a plurality of companion relationship data pairs according to the at least one text segment set; each companion relationship data pair includes a first annotated text segment and a second annotated text segment, wherein the first annotated text segment and the second annotated text segment are two different annotated text segments in the same text segment set; At least one set of first training samples is generated according to each companion relationship data pair to obtain the multiple sets of first training samples.
4. The method according to claim 3, characterized in that At least one set of first training samples is generated according to each peer relationship data pair, including: Generate a first query text according to the first annotated text segment in the companion relationship data pair, the first query text including the first annotated text segment, and the first query text is used to query a text segment having a companion relationship with the first annotated text segment; According to the second annotated text segment in the companion relationship data pair, determining at least one first sample text from the plurality of sample texts, the first sample text including the second annotated text segment; The at least one set of first training samples is generated according to the first query text, the at least one first sample text, and the second annotated text segment.
5. The method according to claim 3 or 4, characterized in that: Generate a plurality of peer relationship data pairs according to the at least one text segment set, including: Arrange and combine any two different annotated text segments in each text segment set to obtain multiple candidate data pairs corresponding to the text segment set; The plurality of candidate data pairs corresponding to at least a portion of the text segment set are sampled to obtain the plurality of companion relationship data pairs; the number of the companion relationship data pairs is less than the number of the candidate data pairs.
6. The method according to claim 5, characterized in that For any first text segment set in the at least one text segment set, sampling the plurality of candidate data pairs corresponding to the first text segment set includes: Determining the number of samples corresponding to the first text segment set; Performing sampling processing on the plurality of candidate data pairs corresponding to the first text segment set according to the sampling quantity; Among them, the sampling quantity is related to one or more of the following: a preset sampling ratio, the difference between the number of annotated text segments included in the second text segment set and the number of annotated text segments included in the first text segment set; the second text segment set is the text segment set containing the largest number of annotated text segments among the at least one text segment set.
7. The method according to claim 2, characterized in that: Generating a plurality of groups of second training samples according to the subordinate relationship between the annotated text segments in the plurality of sample texts and the annotated categories to which they belong, comprising: Deduplication processing is performed on the annotation categories to which each annotated text segment in the plurality of sample texts belongs, to obtain an annotation category set; For each annotation category in the annotation category set, generate a second query text corresponding to the annotation category, the second query text includes the annotation category, and the second query text is used to query text segments belonging to the annotation category; The plurality of groups of second training samples are generated according to the second query text corresponding to each annotation category in the annotation category set and the subordinate relationship between each annotation text segment in the plurality of sample texts and the annotation category to which it belongs.
8. The method according to claim 7, characterized in that Generating the plurality of groups of second training samples according to the second query text corresponding to each annotation category in the annotation category set and the subordinate relationship between each annotation text segment in the plurality of sample texts and the annotation category to which it belongs, comprises: For each annotation category in the annotation category set, traverse each sample text in the multiple sample texts respectively: If there is an annotated text segment belonging to the annotated category in the sample text, a set of second training samples is generated according to a second query text corresponding to the annotated category, the sample text, and the annotated text segment belonging to the annotated category in the sample text; or, If there is no annotated text segment belonging to the annotated category in the sample text, a group of second training samples is generated according to the second query text corresponding to the annotated category, the sample text, and an empty text segment.
9. A text segment recognition method, characterized in that: include: Acquire a query text and a target text, wherein the query text is used to search for a text segment belonging to a preset category in the target text; Processing the query text and the target text by means of a trained text segment recognition model to obtain at least one target text segment in the target text, or to obtain an empty text segment, wherein the target text segment belongs to the preset category; Wherein, the text segment recognition model is trained by using the method described in any one of claims 1 to 8.
10. A text segment recognition method, characterized in that: include: Get the target text; Processing the target text by using a trained text segment recognition model to obtain at least one target text segment in the target text and the category to which each target text segment belongs, or obtaining an empty text segment; Wherein, the text segment recognition model is trained by using the method described in any one of claims 1 to 8.
11. An electronic device, characterized in that: include: memory and at least one processor; A computer program is stored in the memory, and the computer program is configured to be executed by the at least one processor to implement the method according to any one of claims 1 to 8, or the method according to claim 9 or 10.
12. A computer-readable storage medium, characterized in that: The computer-readable storage medium stores a computer program, and when the computer program is executed by a processor, the method according to any one of claims 1 to 8, or the method according to claim 9 or 10 is implemented.
13. A computer program product, characterized in that The method comprises a computer program, which implements the method according to any one of claims 1 to 8, or the method according to claim 9 or 10 when the computer program is executed by a processor.
