Data enhancement method, device and electronic equipment
By performing syntactic analysis of text data sets and generating keyword sets, the problem of insufficient number of enhanced samples generated by existing back-translation methods is solved, and the data enhancement effect is improved, especially suitable for short texts.
Patent Information
- Application Number
- CN202110275285.X
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2021-03-15
- Publication Date
- 2024-11-26
- Estimated Expiration
- 2041-03-15
AI Technical Summary
When performing data augmentation on text data sets, existing back-translation methods are limited by translation tools, and the number of enhanced samples generated is small, especially for short texts, with a small number of short text features, resulting in poor data augmentation effect.
By syntactic analysis of multiple original samples under the target semantic label of the text dataset, we determine text templates and keyword collections, generate enhancement samples, and perform data enhancement on the dataset based on these templates and keywords, including sentence vector filtering processing and text transformation to increase sample quantity and quality.
Improve the effect of data enhancement, and is not limited to translation tools, especially for short texts, the number of enhancement samples increases, maintains the distribution of text structure, and reduces the workload of data enhancement.
Smart Images

Figure CN115081455B_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to the field of machine learning, and in particular to a data enhancement method, device and electronic device. Background Art
[0002] In the field of machine learning, data is a crucial link. In the process of training neural network models, lack of data often leads to poor prediction results due to overfitting of neural network models. Data augmentation is a means of increasing training samples, which can enhance the generalization ability of neural network models and reduce overfitting. When performing data augmentation on text datasets, back translation is usually used to increase samples. However, back translation is limited by translation tools, and the number of enhanced samples generated is small, especially for short texts. The number of features of short texts is small and the sequence is short. The number of enhanced samples generated by back translation is small, and the effect of data augmentation is poor. Summary of the invention
[0003] The embodiments of the present invention provide a data enhancement method, device and electronic device to solve the problem that in the existing data enhancement of a text data set, samples are increased by back translation, but the back translation is limited by the translation tool, and the number of enhanced samples generated is small. In particular, for short texts, the number of short text features is small and the sequence is short. The number of enhanced samples generated by back translation is small, and the effect of data enhancement is poor.
[0004] To solve the above technical problems, the present invention is achieved as follows:
[0005] In a first aspect, an embodiment of the present invention provides a data enhancement method, the method comprising:
[0006] Performing syntactic analysis on multiple original samples under a target semantic label in a text data set, determining a text template corresponding to the target semantic label, and obtaining at least one keyword set according to the multiple original samples, wherein each keyword set in the at least one keyword set includes multiple keywords with the same semantics, the target semantic label is any semantic label of the text data set, and the text template includes a part-of-speech structure and an abstract keyword, wherein the abstract keyword is used to represent the semantics of the keyword;
[0007] generating at least one enhanced sample based on the text template and the at least one keyword set;
[0008] Data enhancement is performed on the text dataset according to the at least one enhanced sample.
[0009] Optionally, performing data enhancement on the text dataset according to the at least one enhanced sample includes:
[0010] Obtaining a sentence vector for each original sample in the multiple original samples;
[0011] Obtaining a sentence vector of each enhanced sample in the at least one enhanced sample;
[0012] Based on the sentence vector of each original sample and the sentence vector of each enhanced sample, the at least one enhanced sample is screened to obtain an enhanced sample after the screening process;
[0013] The enhanced samples after the screening process are added to the text data set.
[0014] Optionally, the screening the at least one enhanced sample based on the sentence vector of each original sample and the sentence vector of each enhanced sample includes:
[0015] Calculating a first mean vector of sentence vectors of the multiple original samples and the at least one enhanced sample;
[0016] Determine a central sample sentence vector based on the first mean vector;
[0017] According to the distance between the sentence vector of each enhanced sample and the sentence vector of the central sample, K enhanced samples are removed from the at least one enhanced sample, where K is a positive integer;
[0018] The enhanced samples after the screening process are the enhanced samples remaining after removing K enhanced samples from the at least one enhanced sample.
[0019] Optionally, K is a rounded value of a target value, and the target value is: Among them, y is the number of original samples under the target semantic label, x is the preset enhancement multiple, and a1 and a2 are both preset coefficients.
[0020] Optionally, the sentence vector N of the enhanced sample after the screening process satisfies the following conditions:
[0021]
[0022] in, is the mean vector of the sentence vectors of the multiple original samples, is the mean vector of the sentence vector of the at least one enhanced sample, N j is the sentence vector of the jth enhanced sample in the at least one enhanced sample, n is the number of samples of the at least one enhanced sample, and a3 is a preset coefficient.
[0023] Optionally, generating at least one enhanced sample based on the text template and the at least one keyword set includes:
[0024] Transforming each of the multiple original samples according to the part-of-speech structure in the text template;
[0025] A target keyword is selected from a keyword set corresponding to the abstract keyword in the text template, and the target keyword replaces the word at the corresponding position in the transformed original sample to obtain at least one enhanced sample, wherein the semantics of the keywords in the keyword set corresponding to the abstract keyword are the same as the semantics represented by the abstract keyword.
[0026] Optionally, before performing data enhancement on the text dataset according to the at least one enhanced sample, the method further includes:
[0027] Segment the target original sample according to punctuation marks to obtain multiple clauses corresponding to the target original sample, where the target original sample is any one of the multiple original samples;
[0028] Randomly swapping multiple clauses corresponding to the target original sample to obtain a swapped original sample;
[0029] The exchanged original sample is added to the at least one enhanced sample.
[0030] In a second aspect, an embodiment of the present invention provides a data enhancement device, the device comprising:
[0031] A determination module, configured to perform syntactic analysis on a plurality of original samples under a target semantic label in a text data set, determine a text template corresponding to the target semantic label, and obtain at least one keyword set according to the plurality of original samples, wherein each keyword set in the at least one keyword set includes a plurality of keywords with the same semantics, the target semantic label is any semantic label of the text data set, the text template includes a part-of-speech structure and an abstract keyword, and the abstract keyword is used to represent the semantics of the keyword;
[0032] A generating module, configured to generate at least one enhanced sample based on the text template and the at least one keyword set;
[0033] An enhancement module is used to perform data enhancement on the text dataset according to the at least one enhanced sample.
[0034] Optionally, the enhancement module includes:
[0035] A first acquisition unit, configured to acquire a sentence vector of each original sample in the plurality of original samples;
[0036] A second acquisition unit, configured to acquire a sentence vector of each enhanced sample in the at least one enhanced sample;
[0037] a processing unit, configured to perform screening processing on the at least one enhanced sample based on the sentence vector of each original sample and the sentence vector of each enhanced sample to obtain a screened enhanced sample;
[0038] An adding unit is used to add the enhanced samples after the screening process to the text data set.
[0039] Optionally, the processing unit is specifically used for:
[0040] Calculating a first mean vector of sentence vectors of the multiple original samples and the at least one enhanced sample;
[0041] Determine a central sample sentence vector based on the first mean vector;
[0042] According to the distance between the sentence vector of each enhanced sample and the sentence vector of the central sample, K enhanced samples are removed from the at least one enhanced sample, where K is a positive integer;
[0043] The enhanced samples after the screening process are the enhanced samples remaining after removing K enhanced samples from the at least one enhanced sample.
[0044] Optionally, K is a rounded value of a target value, and the target value is: Among them, y is the number of original samples under the target semantic label, x is the preset enhancement multiple, and a1 and a2 are both preset coefficients.
[0045] Optionally, the sentence vector N of the enhanced sample after the screening process satisfies the following conditions:
[0046]
[0047] in, is the mean vector of the sentence vectors of the multiple original samples, is the mean vector of the sentence vector of the at least one enhanced sample, N j is the sentence vector of the jth enhanced sample in the at least one enhanced sample, n is the number of samples of the at least one enhanced sample, and a3 is a preset coefficient.
[0048] Optionally, the generating module is specifically used for:
[0049] Transforming each of the multiple original samples according to the part-of-speech structure in the text template;
[0050] A target keyword is selected from a keyword set corresponding to the abstract keyword in the text template, and the target keyword replaces the word at the corresponding position in the transformed original sample to obtain at least one enhanced sample, wherein the semantics of the keywords in the keyword set corresponding to the abstract keyword are the same as the semantics represented by the abstract keyword.
[0051] Optionally, the device further comprises:
[0052] A sentence segmentation module, configured to segment the target original sample according to punctuation marks to obtain a plurality of clauses corresponding to the target original sample, wherein the target original sample is any one of the plurality of original samples;
[0053] An exchange module, used for randomly exchanging multiple clauses corresponding to the target original sample to obtain an exchanged original sample;
[0054] An adding module is used to add the exchanged original sample to the at least one enhanced sample.
[0055] In a third aspect, an embodiment of the present invention provides an electronic device, comprising: a processor, a memory, and a program stored in the memory and executable on the processor, wherein the program, when executed by the processor, implements the steps of the data enhancement method described in the first aspect.
[0056] In a fourth aspect, an embodiment of the present invention provides a computer-readable storage medium, on which a computer program is stored. When the computer program is executed by a processor, the steps of the data enhancement method described in the first aspect are implemented.
[0057] In an embodiment of the present invention, syntactic analysis is performed on multiple original samples under a target semantic label in a text data set, a text template corresponding to the target semantic label is determined, and at least one keyword set is obtained based on the multiple original samples, each keyword set in the at least one keyword set includes multiple keywords with the same semantics, the target semantic label is any semantic label of the text data set, the text template includes a part-of-speech structure and an abstract keyword, and the abstract keyword is used to characterize the semantics of the keyword; at least one enhanced sample is generated based on the text template and the at least one keyword set; and data enhancement is performed on the text data set based on the at least one enhanced sample. In this way, data enhancement can be performed on the text data set through the text template and the at least one keyword set without being limited by the translation tool, thereby improving the effect of data enhancement. BRIEF DESCRIPTION OF THE DRAWINGS
[0058] In order to more clearly illustrate the technical solutions of the embodiments of the present invention, the accompanying drawings required for use in the description of the embodiments of the present invention will be briefly introduced below. Obviously, the accompanying drawings in the following description are only some embodiments of the present invention. For ordinary technicians in this field, other accompanying drawings can be obtained based on these accompanying drawings without paying creative labor.
[0059] Figure 1 is a flow chart of a data enhancement method provided by an embodiment of the present invention;
[0060] Figure 2 This is one of the structural schematic diagrams of a data enhancement device provided by an embodiment of the present invention;
[0061] Figure 3 This is a second structural schematic diagram of a data enhancement device provided by an embodiment of the present invention;
[0062] Figure 4 This is a third structural diagram of a data enhancement device provided by an embodiment of the present invention;
[0063] Figure 5 It is a structural schematic diagram of an electronic device provided by an embodiment of the present invention. DETAILED DESCRIPTION
[0064] The following will be combined with the drawings in the embodiments of the present invention to clearly and completely describe the technical solutions in the embodiments of the present invention. Obviously, the described embodiments are part of the embodiments of the present invention, not all of the embodiments. Based on the embodiments of the present invention, all other embodiments obtained by ordinary technicians in this field without creative work are within the scope of protection of the present invention.
[0065] In the embodiments of the present invention, a data enhancement method, device and electronic device are proposed to solve the problem that when performing data enhancement on a text data set, samples are increased by back translation, but back translation is limited by translation tools, and the number of enhanced samples generated is small. In particular, for short texts, the number of short text features is small and the sequence is short. The number of enhanced samples generated by back translation is small, and the effect of data enhancement is poor.
[0066] See also Figure 1 , Figure 1 is a flow chart of a data enhancement method provided by an embodiment of the present invention. Figure 1 As shown, the method comprises the following steps:
[0067] Step 101: perform syntactic analysis on multiple original samples under a target semantic label in a text data set, determine a text template corresponding to the target semantic label, and obtain at least one keyword set based on the multiple original samples, wherein each keyword set in the at least one keyword set includes multiple keywords with the same semantics, the target semantic label is any semantic label of the text data set, and the text template includes a part-of-speech structure and abstract keywords, and the abstract keywords are used to represent the semantics of the keywords.
[0068] The original samples in the text data set may be text samples. NLP (Natural Language Processing) tools may be used to segment and parse multiple original samples. The text template corresponding to the target semantic tag may be determined by determining the keywords of multiple original samples under the target semantic tag, abstracting each keyword into an abstract keyword, analyzing the part-of-speech structure of each original sample, and if there are at least two original samples with the same part-of-speech structure and the same abstract keyword, then the text template composed of the part-of-speech structure and abstract keyword of the at least two original samples is determined to be the text template corresponding to the target semantic tag. For example, the part-of-speech structure included in the text template may be: "subject + predicate + object", or may be: "noun + verb + noun + adjective"; the abstract keyword may be: animal (object), or may be: keyword 1 (object). Abstract keywords may be used as keyword placeholders, and if multiple keywords have the same abstract keyword, it can represent that the semantics of the multiple keywords are the same. Keywords of multiple original samples may be determined through an artificially constructed keyword library or through a TF-IDF (Term Frequency-Inverse Document Frequency) method.
[0069] In addition, the step of obtaining at least one keyword set based on the multiple original samples may be to obtain a word vector of a keyword of each original sample, determine whether multiple keywords have the same semantics through the word vector, and store the keywords with the same semantics in a keyword set. If the word vectors of multiple keywords are similar, it can be considered that the multiple keywords have the same semantics. Whether the word vectors are similar can be determined by the vector distance of the word vectors of multiple keywords. For example, two word vectors whose vector distance is less than a preset value can be determined as similar word vectors.
[0070] In addition, the original sample can be a short text, which has a small number of features and a short sequence, and the effect of data enhancement is better. For example, the original sample can be a short text with a length of less than 70 Chinese characters. Short text is usually text data with less than 160 characters. If converted into Chinese characters, a short text of 70 characters generally has less text content and sparse feature words, which is commonly seen in chats, text messages, and comments.
[0071] Step 102: Generate at least one enhanced sample based on the text template and the at least one keyword set.
[0072] Among them, the generating of at least one enhanced sample based on the text template and the at least one keyword set may be, each of the multiple original samples is transformed according to the part-of-speech structure in the text template, a target keyword is selected from the keyword set corresponding to the abstract keyword in the text template, and the target keyword is used to replace the words at the corresponding position in the transformed original sample to obtain at least one enhanced sample, wherein the semantics of the keywords in the keyword set corresponding to the abstract keyword are the same as the semantics represented by the abstract keyword; or it may be, each of the multiple original samples is transformed according to the part-of-speech structure in the text template, and the transformed original sample is used as the enhanced sample, and / or, the keyword of each of the multiple original samples is replaced by a randomly selected keyword from the corresponding keyword set to obtain the enhanced sample.
[0073] Step 103: Perform data enhancement on the text dataset according to the at least one enhanced sample.
[0074] Among them, the data enhancement of the text data set according to the at least one enhanced sample may be to add the at least one enhanced sample to the text data set; or it may be to obtain the sentence vector of each original sample in the multiple original samples, obtain the sentence vector of each enhanced sample in the at least one enhanced sample, screen the at least one enhanced sample based on the sentence vector of each original sample and the sentence vector of each enhanced sample to obtain the enhanced sample after the screening process, and add the enhanced sample after the screening process to the text data set.
[0075] Furthermore, before performing data enhancement on the text dataset according to the at least one enhanced sample, the method may also include: randomly performing one of clause exchange processing, synonym replacement processing, random insertion processing, random exchange processing or random deletion processing on the target original sample to obtain a processed original sample, wherein the target original sample is any one of the multiple original samples; and adding the processed original sample to the at least one enhanced sample. The clause exchange processing may be to divide the target original sample into sentences according to punctuation marks to obtain multiple clauses corresponding to the target original sample, wherein the target original sample is any one of the multiple original samples; and randomly exchange multiple clauses corresponding to the target original sample. The synonym replacement processing may be to randomly select a non-stop word from the target original sample and replace the non-stop word with a randomly selected synonym. The random insertion processing may be to randomly select a non-stop word from the target original sample, find a random synonym of the non-stop word, and insert the synonym into a random position in the target original sample. The random exchange process may be to randomly select two words from the target original sample and exchange the positions of the two words, repeating Q1 times, where Q1 is the number of words in the target original sample. The random deletion process may be to randomly delete each word in the target original sample with a probability P, and the keywords in the target original sample do not participate in the random deletion process. For example, P may be defined as 0.1, which means that each word has a 10% probability of being deleted.
[0076] In addition, a preset enhancement multiple can be set. After generating at least one enhanced sample based on the text template and the at least one keyword set, the sample number of the generated at least one enhanced sample can be calculated, and the current enhancement multiple can be determined based on the sample number of the at least one enhanced sample. The preset enhancement multiple can be subtracted from the current enhancement multiple to obtain the remaining enhancement multiple. The step of randomly performing clause exchange processing, synonym replacement processing, random insertion processing, random exchange processing or random deletion processing on the target original sample can be repeated until the processed original sample meets the condition of reaching the remaining enhancement multiple. For example, if the original samples are 100, the preset enhancement multiple is 3, and the current enhancement multiple is 2, then the remaining enhancement multiple is 1, and the processed original samples reach 100*1, that is, 100, and the condition of reaching the remaining enhancement multiple is met.
[0077] It should be noted that if the target original sample is randomly subjected to one of the clause exchange processing, synonym replacement processing, random insertion processing, random exchange processing or random deletion processing, and the processed original sample obtains an overlap with the enhanced sample or the original sample, then the step of randomly performing one of the clause exchange processing, synonym replacement processing, random insertion processing, random exchange processing or random deletion processing on the target original sample can be repeated.
[0078] In addition, in the embodiment of the present invention, the text data set is enhanced through the original samples in the text data set, and no external corpus data set is introduced, so there is no need to collect a large amount of external corpus, which reduces the workload of data enhancement. In each vertical field, there are usually special text templates that can be used as samples of text, and synonyms can bring a certain increment to the enhanced samples. If simple synonym replacement is used, there will be a lack of application of text templates, and the text structure distribution in the vertical field cannot be well maintained. In the embodiment of the present invention, the text template can be used as a schema (summary), and the sentence structure model of the text is obtained by automatically analyzing the sentence structure, and a simple schema of the text is automatically constructed and the text transformation result is obtained according to the text schema. The text template and synonyms are automatically obtained by corpus analysis, which optimizes the production process.
[0079] It should be noted that in the prior art, in addition to increasing samples by back-translation, text enhancement can also be achieved by text transformation or based on a language generation model. Text transformation is to transform text data based on a rule-based method to obtain increased samples. Text enhancement based on a language generation model is to perform pre-training on a large amount of text to obtain a pre-trained model that can generate coherent sentences, and then fine-tune the pre-trained model based on the data in the text data set, and use the fine-tuned model to generate increased samples. Text transformation to achieve text enhancement requires more manual participation in formulating rules, while text enhancement based on a language generation model requires the collection of a large amount of external corpus for model training. The embodiment of the present invention automatically analyzes the sentence pattern to obtain a structural model of the text, does not require much manual participation, and does not require the collection of a large amount of external corpus, thereby reducing the workload of data enhancement; especially for short texts, the number of short text features is small and the sequence is short, and the effect of automatically analyzing the sentence pattern is better, so the effect of data enhancement is better.
[0080] In an embodiment of the present invention, syntactic analysis is performed on multiple original samples under a target semantic label in a text data set, a text template corresponding to the target semantic label is determined, and at least one keyword set is obtained based on the multiple original samples, each keyword set in the at least one keyword set includes multiple keywords with the same semantics, the target semantic label is any semantic label of the text data set, the text template includes a part-of-speech structure and an abstract keyword, and the abstract keyword is used to characterize the semantics of the keyword; at least one enhanced sample is generated based on the text template and the at least one keyword set; and data enhancement is performed on the text data set based on the at least one enhanced sample. In this way, data enhancement can be performed on the text data set through the text template and the at least one keyword set without being limited by the translation tool, thereby improving the effect of data enhancement.
[0081] Optionally, performing data enhancement on the text dataset according to the at least one enhanced sample includes:
[0082] Obtaining a sentence vector for each original sample in the multiple original samples;
[0083] Obtaining a sentence vector of each enhanced sample in the at least one enhanced sample;
[0084] Based on the sentence vector of each original sample and the sentence vector of each enhanced sample, the at least one enhanced sample is screened to obtain an enhanced sample after the screening process;
[0085] The enhanced samples after the screening process are added to the text data set.
[0086] Among them, the original samples and enhanced samples under the target semantic label can be segmented respectively, and the word vector of each original sample under the target semantic label and the word vector of each enhanced sample can be obtained according to the segmentation result, and all the word vectors of each original sample are added to obtain the sentence vector of each original sample, and all the word vectors of each enhanced sample are added to obtain the sentence vector of each enhanced sample. The screening process can be to eliminate the enhanced samples whose sentence vectors are far away from the sentence vectors of the original samples. For example, the mean vector of the sentence vectors of multiple original samples can be calculated, and the vector distance between the sentence vector of the enhanced sample and the mean vector is calculated, and the enhanced samples whose vector distance is greater than the preset distance value are eliminated.
[0087] In this implementation, the at least one enhanced sample is screened based on the sentence vector of each original sample and the sentence vector of each enhanced sample, so that the introduction of noise data can be reduced.
[0088] Optionally, the screening the at least one enhanced sample based on the sentence vector of each original sample and the sentence vector of each enhanced sample includes:
[0089] Calculating a first mean vector of sentence vectors of the multiple original samples and the at least one enhanced sample;
[0090] Determine a central sample sentence vector based on the first mean vector;
[0091] According to the distance between the sentence vector of each enhanced sample and the sentence vector of the central sample, K enhanced samples are removed from the at least one enhanced sample, where K is a positive integer;
[0092] The enhanced samples after the screening process are the enhanced samples remaining after removing K enhanced samples from the at least one enhanced sample.
[0093] In addition, the first mean vector may be the mean of the sentence vectors of the multiple original samples and the sentence vector of the at least one enhanced sample. The sum of the sentence vectors of the multiple original samples may be calculated, the sum of the sentence vectors of the at least one enhanced sample may be calculated, the total number of samples of the multiple original samples and the at least one enhanced sample may be calculated, the sum of the sentence vectors of the multiple original samples and the sum of the sentence vectors of the at least one enhanced sample may be added, and the value obtained by the addition may be divided by the total number of samples to obtain the first mean vector.
[0094] Further, the central sample sentence vector is determined based on the first mean vector, which may be, determining the value of the first mean vector as the value of the central sample sentence vector; or, it may be, calculating the vector distance between the sentence vector of each original sample and the first mean vector, taking the original sample with the smallest vector distance as the central sample, and determining the central sample sentence vector from the sentence vector of the central sample; or, it may be, calculating the vector distance between the sentence vector of each original sample and the first mean vector, and the vector distance between the sentence vector of each enhanced sample and the first mean vector, taking the sample with the smallest vector distance as the central sample, and determining the central sample sentence vector from the sentence vector of the central sample. The central sample sentence vector is not limited in the embodiment of the present invention. The method for calculating the vector distance is not limited, and for example, it may be Euclidean distance, Manhattan distance, Chebyshev distance, angle cosine distance, etc.
[0095] In addition, the removing K enhanced samples from the at least one enhanced sample according to the distance between the sentence vector of each enhanced sample and the central sample sentence vector may be to sort the enhanced samples in descending order of distance and remove the K enhanced samples with the highest sorting. The distance between the sentence vector of each enhanced sample and the central sample sentence vector may be the vector distance between the sentence vector of each enhanced sample and the central sample sentence vector.
[0096] It should be noted that K may be a preset value, for example, K may be 5, 10, 50, etc.; or, K may be the product of the number of samples of the at least one enhanced sample and the elimination coefficient, and the elimination coefficient may be 0.1, 0.3, 0.5, etc.; or, K may be a rounded value of a target value, and the target value is: y is the number of original samples under the target semantic label, x is the preset enhancement multiple, and a1 and a2 are both preset coefficients.
[0097] In this implementation, K enhanced samples are removed from the at least one enhanced sample based on the distance between the sentence vector of each enhanced sample and the sentence vector of the central sample, thereby removing enhanced samples that have a large deviation from the overall sample and removing part of the introduced noise data.
[0098] Optionally, K is a rounded value of a target value, and the target value is: Among them, y is the number of original samples under the target semantic label, x is the preset enhancement multiple, and a1 and a2 are both preset coefficients.
[0099] Among them, a1 and a2 can be set according to actual needs. For example, a1 can be 0.1, a2 can be 0.2; or, a1 can be 0.15, a2 can be 0.2; or, a1 can be 0.05, a2 can be 0.3, and so on. The preset enhancement multiple x can be set according to actual needs. In order to achieve a better data enhancement effect, the preset enhancement multiple x can be an integer greater than 0 and less than 24. The target value can be rounded up or rounded down to obtain the K value, which is not limited in this embodiment. K is the rounded value of the target value. For example, K can be: Among them, [] is the rounding symbol.
[0100] It should be noted that in most cases, the semantic changes of the enhanced samples generated based on the original samples are small, but in some low-probability extreme cases, for example, the deletion of too many words causes a sharp change in semantics, which may cause the data enhancement effect to decrease. By removing K enhanced samples from the at least one enhanced sample based on the distance between the sentence vector of each enhanced sample and the sentence vector of the central sample, the screening process of the enhanced text can be dynamically adjusted according to the enhancement multiple, ensuring the data enhancement effect in some low-probability extreme cases.
[0101] In this implementation, K is set as the rounded value of the target value, so that more enhanced samples can be retained while eliminating enhanced samples with large deviations from the overall samples as much as possible.
[0102] Optionally, the sentence vector N of the enhanced sample after the screening process satisfies the following conditions:
[0103]
[0104] in, is the mean vector of the sentence vectors of the multiple original samples, is the mean vector of the sentence vector of the at least one enhanced sample, N j is the sentence vector of the jth enhanced sample in the at least one enhanced sample, n is the number of samples of the at least one enhanced sample, and a3 is a preset coefficient.
[0105] In addition, the sentence vector of each original sample in the multiple original samples can be calculated, and the mean of the sentence vectors of the multiple original samples can be calculated to obtain the mean vector of the sentence vectors of the multiple original samples: The sentence vector of each enhanced sample in the at least one enhanced sample can be calculated, and the mean of the sentence vector of the at least one enhanced sample is calculated to obtain the mean vector of the sentence vector of the at least one enhanced sample. a3 can be set according to actual needs. For example, a3 can be 1, or 1.3, or 1.5, or 2, etc. In order to achieve a better data enhancement effect, the sample number n of the at least one enhanced sample can satisfy the enhancement multiple to be an integer greater than 0 and less than 24.
[0106] In this implementation, when the at least one enhanced sample is screened, the noise data in the enhanced sample is removed by using the distance deviation between the sentence vector of the enhanced sample and the mean vector of the sentence vectors of the multiple original samples, which can better remove the introduced noise data.
[0107] Optionally, generating at least one enhanced sample based on the text template and the at least one keyword set includes:
[0108] Transforming each of the multiple original samples according to the part-of-speech structure in the text template;
[0109] A target keyword is selected from a keyword set corresponding to the abstract keyword in the text template, and the target keyword replaces the word at the corresponding position in the transformed original sample to obtain at least one enhanced sample, wherein the semantics of the keywords in the keyword set corresponding to the abstract keyword are the same as the semantics represented by the abstract keyword.
[0110] Among them, if the semantic label of the original sample corresponds to multiple text templates, a text template can be randomly selected and the original sample can be transformed according to the part-of-speech structure in the text template; if the semantic label of the original sample does not correspond to a text template, the original sample may not be operated. The target keyword can be a keyword randomly selected from a keyword set corresponding to an abstract keyword. For example, the original sample is "you are cute", the text template is "adjective + noun", then the transformed original sample is "cute you", the abstract keyword in the text template is keyword 1 (adjective), and the keywords in the keyword set corresponding to keyword 1 include "beautiful", then the enhanced sample can be "beautiful you".
[0111] In this implementation, each of the multiple original samples is transformed according to the part-of-speech structure in the text template, a target keyword is selected from a keyword set corresponding to the abstract keyword in the text template, and the target keyword replaces the word at the corresponding position in the transformed original sample to obtain at least one enhanced sample, thereby obtaining an enhanced sample that is significantly different from the original sample, and the enhanced sample has the same semantic label as the original sample, which can improve the effect of data enhancement.
[0112] Optionally, before performing data enhancement on the text dataset according to the at least one enhanced sample, the method further includes:
[0113] Segment the target original sample according to punctuation marks to obtain multiple clauses corresponding to the target original sample, where the target original sample is any one of the multiple original samples;
[0114] Randomly swapping multiple clauses corresponding to the target original sample to obtain a swapped original sample;
[0115] The exchanged original sample is added to the at least one enhanced sample.
[0116] Among them, the sentence segmentation of the target original sample according to punctuation marks may be to segment the target original sample according to periods, commas, semicolons, exclamation marks and question marks. The target original sample may be divided into multiple clauses by sentence segmentation. The random exchange of multiple clauses corresponding to the target original sample may be to randomly select one clause from the multiple clauses and exchange it with the adjacent clause in a random direction of the clause. The random direction may be the left or the right. Taking the second clause as an example, the adjacent clause in a random direction of the second clause may be the first clause or the third clause. Furthermore, the random exchange of multiple clauses corresponding to the target original sample may be to randomly select one clause from the multiple clauses and exchange it with the adjacent clause in a random direction of the clause, and repeat Q2 times, where Q2 is the number of clauses corresponding to the target original sample.
[0117] In this implementation, the target original sample is divided into sentences according to punctuation marks to obtain multiple clauses corresponding to the target original sample, and the target original sample is any one of the multiple original samples; the multiple clauses corresponding to the target original sample are randomly exchanged to obtain exchanged original samples; and the exchanged original samples are added to the at least one enhanced sample. In this way, by randomly exchanging clauses, the generated enhanced samples are more consistent with Chinese language expression, and the enhanced samples have the same semantic labels as the original samples, which can improve the effect of data enhancement.
[0118] See also Figure 2 , Figure 2 is a schematic diagram of the structure of a data enhancement device provided by an embodiment of the present invention, such as Figure 2 As shown, the data enhancement device 200 includes:
[0119] A determination module 201 is used to perform syntactic analysis on multiple original samples under a target semantic label in a text data set, determine a text template corresponding to the target semantic label, and obtain at least one keyword set according to the multiple original samples, wherein each keyword set in the at least one keyword set includes multiple keywords with the same semantics, the target semantic label is any semantic label of the text data set, and the text template includes a part-of-speech structure and an abstract keyword, wherein the abstract keyword is used to represent the semantics of the keyword;
[0120] A generating module 202, configured to generate at least one enhanced sample based on the text template and the at least one keyword set;
[0121] The enhancement module 203 is configured to perform data enhancement on the text dataset according to the at least one enhanced sample.
[0122] Optional, such as Figure 3As shown, the enhancement module 203 includes:
[0123] A first acquisition unit 2031 is used to acquire a sentence vector of each original sample in the multiple original samples;
[0124] A second acquisition unit 2032 is used to acquire a sentence vector of each enhanced sample in the at least one enhanced sample;
[0125] The processing unit 2033 is configured to perform screening processing on the at least one enhanced sample based on the sentence vector of each original sample and the sentence vector of each enhanced sample to obtain a screened enhanced sample;
[0126] The adding unit 2034 is used to add the enhanced sample after the screening process to the text data set.
[0127] Optionally, the processing unit 2033 is specifically configured to:
[0128] Calculating a first mean vector of sentence vectors of the multiple original samples and the at least one enhanced sample;
[0129] Determine a central sample sentence vector based on the first mean vector;
[0130] According to the distance between the sentence vector of each enhanced sample and the sentence vector of the central sample, K enhanced samples are removed from the at least one enhanced sample, where K is a positive integer;
[0131] The enhanced samples after screening are the remaining enhanced samples after removing K enhanced samples from the at least one enhanced sample.
[0132] Optionally, K is a rounded value of a target value, and the target value is: Among them, y is the number of original samples under the target semantic label, x is the preset enhancement multiple, and a1 and a2 are both preset coefficients.
[0133] Optionally, the sentence vector N of the enhanced sample after the screening process satisfies the following conditions:
[0134]
[0135] in, is the mean vector of the sentence vectors of the multiple original samples, is the mean vector of the sentence vector of the at least one enhanced sample, N j is the sentence vector of the jth enhanced sample in the at least one enhanced sample, n is the number of samples of the at least one enhanced sample, and a3 is a preset coefficient.
[0136] Optionally, the generating module 202 is specifically used for:
[0137] Transforming each of the multiple original samples according to the part-of-speech structure in the text template;
[0138] A target keyword is selected from a keyword set corresponding to the abstract keyword in the text template, and the target keyword replaces the word at the corresponding position in the transformed original sample to obtain at least one enhanced sample, wherein the semantics of the keywords in the keyword set corresponding to the abstract keyword are the same as the semantics represented by the abstract keyword.
[0139] Optional, such as Figure 4 As shown, the device 200 also includes:
[0140] A sentence segmentation module 204, configured to segment the target original sample according to punctuation marks to obtain a plurality of clauses corresponding to the target original sample, wherein the target original sample is any one of the plurality of original samples;
[0141] The exchange module 205 is used to randomly exchange multiple clauses corresponding to the target original sample to obtain an exchanged original sample;
[0142] The adding module 206 is configured to add the exchanged original sample to the at least one enhanced sample.
[0143] Data enhancement device can achieve Figure 1 The various processes implemented in the method embodiment can achieve the same technical effect, and to avoid repetition, they will not be described again here.
[0144] like Figure 5 As shown, an embodiment of the present invention further provides an electronic device 300, including: a processor 301, a memory 302, and a program stored in the memory 302 and executable on the processor 301. When the program is executed by the processor 301, each process of the above-mentioned data enhancement method embodiment is implemented, and the same technical effect can be achieved. To avoid repetition, it will not be described here.
[0145] The embodiment of the present invention further provides a computer-readable storage medium, on which a computer program is stored, and when the computer program is executed by a processor, each process of the above data enhancement method embodiment is implemented, and the same technical effect can be achieved. To avoid repetition, it is not described here. The computer-readable storage medium is, for example, a ROM, RAM, a magnetic disk, or an optical disk.
[0146] It should be noted that, in this article, the terms "include", "comprises" or any other variations thereof are intended to cover non-exclusive inclusion, so that a process, method, article or device including a series of elements includes not only those elements, but also other elements not explicitly listed, or also includes elements inherent to such process, method, article or device. In the absence of further restrictions, an element defined by the sentence "comprises a ..." does not exclude the existence of other identical elements in the process, method, article or device including the element.
[0147] Through the description of the above implementation methods, those skilled in the art can clearly understand that the above-mentioned embodiment methods can be implemented by means of software plus a necessary general hardware platform, and of course by hardware, but in many cases the former is a better implementation method. Based on such an understanding, the technical solution of the present invention, or the part that contributes to the prior art, can be embodied in the form of a software product, which is stored in a storage medium (such as ROM / RAM, a magnetic disk, or an optical disk), and includes a number of instructions for enabling a terminal (which can be a mobile phone, a computer, a server, an air conditioner, or a network device, etc.) to execute the methods described in each embodiment of the present invention.
[0148] The embodiments of the present invention are described above in conjunction with the accompanying drawings, but the present invention is not limited to the above-mentioned specific implementation methods. The above-mentioned specific implementation methods are merely illustrative and not restrictive. Under the enlightenment of the present invention, ordinary technicians in this field can also make many forms without departing from the scope of protection of the present invention and the claims, all of which are within the protection of the present invention.
Claims
1. A data enhancement method, characterized in that: The method comprises: Performing syntactic analysis on multiple original samples under a target semantic label in a text data set, determining a text template corresponding to the target semantic label, and obtaining at least one keyword set according to the multiple original samples, wherein each keyword set in the at least one keyword set includes multiple keywords with the same semantics, the target semantic label is any semantic label of the text data set, and the text template includes a part-of-speech structure and an abstract keyword, wherein the abstract keyword is used to represent the semantics of the keyword; generating at least one enhanced sample based on the text template and the at least one keyword set; Performing data enhancement on the text dataset according to the at least one enhanced sample; The generating at least one enhanced sample based on the text template and the at least one keyword set comprises: Transforming each of the multiple original samples according to the part-of-speech structure in the text template; Selecting a target keyword from a keyword set corresponding to the abstract keyword in the text template, replacing the word at the corresponding position in the transformed original sample with the target keyword, to obtain at least one enhanced sample, wherein the semantics of the keywords in the keyword set corresponding to the abstract keyword are the same as the semantics represented by the abstract keyword; If the semantic label of the original sample corresponds to multiple text templates, one of the text templates is randomly selected, and the original sample is transformed according to the part-of-speech structure in the randomly selected text template.
2. The method according to claim 1, characterized in that The step of performing data enhancement on the text dataset according to the at least one enhanced sample comprises: Obtaining a sentence vector for each original sample in the multiple original samples; Obtaining a sentence vector of each enhanced sample in the at least one enhanced sample; Based on the sentence vector of each original sample and the sentence vector of each enhanced sample, the at least one enhanced sample is screened to obtain an enhanced sample after the screening process; The enhanced samples after the screening process are added to the text data set.
3. The method according to claim 2, characterized in that The screening process of the at least one enhanced sample based on the sentence vector of each original sample and the sentence vector of each enhanced sample includes: Calculating a first mean vector of sentence vectors of the multiple original samples and the at least one enhanced sample; Determine a central sample sentence vector based on the first mean vector; According to the distance between the sentence vector of each enhanced sample and the sentence vector of the central sample, K enhanced samples are removed from the at least one enhanced sample, where K is a positive integer; The enhanced samples after the screening process are the enhanced samples remaining after removing K enhanced samples from the at least one enhanced sample.
4. The method according to claim 3, characterized in that: The K is the rounded value of the target value, and the target value is: Among them, y is the number of original samples under the target semantic label, x is the preset enhancement multiple, and a1 and a2 are both preset coefficients.
5. The method according to claim 2, characterized in that: The sentence vector N of the enhanced sample after the screening process satisfies the following conditions: in, is the mean vector of the sentence vectors of the multiple original samples, is the mean vector of the sentence vector of the at least one enhanced sample, N j is the sentence vector of the jth enhanced sample in the at least one enhanced sample, n is the number of samples of the at least one enhanced sample, and a3 is a preset coefficient.
6. The method according to claim 1, characterized in that Before performing data enhancement on the text dataset according to the at least one enhanced sample, the method further includes: Segment the target original sample according to punctuation marks to obtain multiple clauses corresponding to the target original sample, where the target original sample is any one of the multiple original samples; Randomly swapping multiple clauses corresponding to the target original sample to obtain a swapped original sample; The exchanged original sample is added to the at least one enhanced sample.
7. A data enhancement device, characterized in that: The device comprises: A determination module, configured to perform syntactic analysis on a plurality of original samples under a target semantic label in a text data set, determine a text template corresponding to the target semantic label, and obtain at least one keyword set according to the plurality of original samples, wherein each keyword set in the at least one keyword set includes a plurality of keywords with the same semantics, the target semantic label is any semantic label of the text data set, the text template includes a part-of-speech structure and an abstract keyword, and the abstract keyword is used to represent the semantics of the keyword; A generating module, configured to generate at least one enhanced sample based on the text template and the at least one keyword set; An enhancement module, configured to perform data enhancement on the text dataset according to the at least one enhanced sample; The generation module is specifically used for: Transforming each of the multiple original samples according to the part-of-speech structure in the text template; Selecting a target keyword from a keyword set corresponding to the abstract keyword in the text template, replacing the word at the corresponding position in the transformed original sample with the target keyword, to obtain at least one enhanced sample, wherein the semantics of the keywords in the keyword set corresponding to the abstract keyword are the same as the semantics represented by the abstract keyword; If the semantic label of the original sample corresponds to multiple text templates, one of the text templates is randomly selected, and the original sample is transformed according to the part-of-speech structure in the randomly selected text template.
8. An electronic device, characterized in that: include: A processor, a memory, and a program stored in the memory and executable on the processor, wherein when the program is executed by the processor, the steps of the data enhancement method according to any one of claims 1 to 6 are implemented.
9. 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 steps of the data enhancement method according to any one of claims 1 to 6 are implemented.
