Text data enhancement method and device, electronic device, and storage medium
By performing vectorized representation of word segmentation sequences and random selection operations on text data, the similarity filtering replacement words are calculated, and the problem of insufficient reliability and universality of existing text data enhancement methods is solved, and efficient text data generation is achieved .
Patent Information
- Application Number
- CN202111587717.7
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2021-12-23
- Publication Date
- 2024-12-13
- Estimated Expiration
- 2041-12-23
AI Technical Summary
The existing text data enhancement methods have insufficient reliability and universality, and consume a lot of resources. In particular, methods based on noise addition and generation of adversarial networks are prone to generate invalid data or localized data.
By obtaining text data and preprocessing, word participle sequence is generated, and word participle sequence is vectorized to construct an initial matrix, randomly select word participle operations to generate target and candidate word participle sequences, calculate the similarity filter replacement words, and generate enhanced text data.
It improves the reliability and universality of text data, avoids the problem of excessive resource consumption, and achieves more efficient text data generation.
Smart Images

Figure CN114298024B_ABST
Abstract
Description
Background Art
[0002] With the continuous development of Internet technology, data enhancement technology has become more and more diversified. In particular, the application of text data enhancement in the firewall field has become another hot spot in data enhancement technology research.
[0003] In related text enhancement schemes, either a noise-adding method is used, such as synonym replacement (SR: SynonymsReplace), random insertion (RI: Randomly Insert), random swap (RS: Randomly Swap), random deletion (RD: Randomly Delete), or a generative adversarial network is used to generate new data. However, the text data enhancement method based on the noise-adding method is prone to generate invalid data, making the generated enhanced text data unreliable; at the same time, the text data enhancement method based on the generative adversarial network not only needs to consume a lot of network resources to train the generator and discriminator according to the specific task, but also the trained generator and discriminator can only generate fixed types of data, which makes the generated enhanced text data have great limitations.
[0004] It should be noted that the information disclosed in the above background technology section is only used to enhance the understanding of the background of the present disclosure, and therefore may include information that does not constitute the prior art known to ordinary technicians in the field. Summary of the invention
[0005] The purpose of the embodiments of the present disclosure is to provide a text data enhancement method, a text data enhancement device, an electronic device and a computer-readable storage medium, thereby overcoming the problems of low reliability, large limitations and high resource consumption of new text data at least to a certain extent.
[0006] Other features and advantages of the present disclosure will become apparent from the following detailed description, or may be learned in part by the practice of the present disclosure.
[0007] According to a first aspect of an embodiment of the present disclosure, a text data enhancement method is provided, comprising: acquiring text data, and preprocessing the text data to generate a word segmentation sequence of the text data; vectorizing the word segmentation sequence to obtain a word vector of the word segmentation sequence, and constructing an initial matrix of the text data based on the word segmentation sequence and the word vector; based on the initial matrix, determining a target word segmentation sequence generated by performing a random word segmentation operation on the word segmentation sequence each time and a target matrix corresponding to the target word segmentation sequence, as well as a candidate word segmentation sequence corresponding to the target word segmentation sequence, and a candidate matrix corresponding to the candidate word segmentation sequence; calculating the similarity between the target matrix and the candidate matrix corresponding to each random word segmentation operation, and determining alternative words from the candidate word segmentation sequence based on the similarity to screen replacement words from the alternative words, and generating enhanced text data of the text data based on the replacement words.
[0008] In some example embodiments of the present disclosure, based on the aforementioned scheme, the preprocessing of the text data to generate a word segmentation sequence of the text data includes: generalizing the text data to determine a generalized string of the text data; and performing word segmentation on the text data based on the generalized string to generate a word segmentation sequence of the text data.
[0009] In some example embodiments of the present disclosure, based on the aforementioned scheme, the vectorizing the word segmentation sequence to obtain the word vector of the word segmentation sequence includes: obtaining a pre-built word embedding model, and performing text vectorization processing on the word segmentation sequence based on the word embedding model to obtain the word vector of the word segmentation sequence.
[0010] In some example embodiments of the present disclosure, based on the aforementioned scheme, the determining of a target word segmentation sequence generated by performing a random word selection operation on the word segmentation sequence each time and a target matrix corresponding to the target word segmentation sequence includes: reading a target number of random word selection operations, and performing the target number of random word selection operations on the word segmentation sequence; determining the first word randomly selected at that time when the random word selection operation is performed on the word segmentation sequence each time, and calculating the window text distance of the first word based on the position of the first word in the word segmentation sequence; and taking a sub-word segmentation sequence in the word segmentation sequence centered on the first word and satisfying the window text distance as a target word segmentation sequence, and generating a target matrix corresponding to the target word segmentation sequence based on the initial matrix.
[0011] In some example embodiments of the present disclosure, based on the aforementioned solution, the method further includes: when it is detected that the first word segmentation is the same as the generalized string, re-performing the random word segmentation operation on the word segmentation sequence.
[0012] In some example embodiments of the present disclosure, based on the aforementioned scheme, determining a candidate word segmentation sequence corresponding to the target word segmentation sequence and a candidate matrix corresponding to the candidate word segmentation sequence based on the initial matrix includes: randomly selecting a second word segmentation from the word segmentation sequence, and replacing the first word in the target word segmentation sequence with the second word segmentation to obtain a candidate word segmentation sequence; and generating a candidate matrix matching the candidate word segmentation sequence based on the initial matrix.
[0013] In some example embodiments of the present disclosure, based on the aforementioned scheme, the calculating the similarity between the target matrix and the candidate matrix corresponding to each random word segmentation operation, and determining the alternative word from the candidate word segmentation sequence based on the similarity, includes: normalizing the target matrix and the candidate matrix corresponding to each random word segmentation operation, respectively, to obtain a normalized target matrix and a normalized candidate matrix; calculating the average sum of the similarities of column vectors in the normalized target matrix and the normalized candidate matrix, and using the average sum as a standard similarity; obtaining a preset similarity threshold, and when it is detected that the standard similarity is greater than the similarity threshold, using the second word segmentation corresponding to the candidate matrix as an alternative word.
[0014] In some example embodiments of the present disclosure, based on the aforementioned scheme, the step of screening replacement words from the candidate words and generating enhanced text data of the text data based on the replacement words includes: arranging in order all the standard similarities greater than the similarity threshold to obtain a standard similarity sequence; reading a preset number of replacement words, and determining a sub-standard similarity sequence with a larger numerical value that matches the number of replacement words in the standard similarity sequence; using the respective alternative words of the sub-standard similarity sequence as replacement words, and generating enhanced text data of the text data based on the replacement words.
[0015] In some example embodiments of the present disclosure, based on the aforementioned scheme, the method further includes: determining the length of the standard similarity sequence, and when it is detected that the length is less than the number of replacement words, using all the alternative words corresponding to the standard similarity sequence as the replacement words.
[0016] According to a second aspect of an embodiment of the present disclosure, a text data enhancement device is provided, comprising: a word segmentation sequence generation module, used to obtain text data, and pre-process the text data to generate a word segmentation sequence of the text data; an initial matrix construction module, used to vectorize the word segmentation sequence to obtain a word vector of the word segmentation sequence, and construct an initial matrix of the text data based on the word segmentation sequence and the word vector; a random word segmentation operation module, used to determine, based on the initial matrix, a target word segmentation sequence and a target matrix corresponding to the target word segmentation sequence generated by performing a random word segmentation operation on the word segmentation sequence each time, as well as a candidate word segmentation sequence corresponding to the target word segmentation sequence, and a candidate matrix corresponding to the candidate word segmentation sequence; a replacement word determination module, used to calculate the similarity between the target matrix and the candidate matrix corresponding to each random word segmentation operation, and determine alternative words from the candidate word segmentation sequence based on the similarity, so as to screen replacement words from the alternative words, and generate enhanced text data of the text data based on the replacement words.
[0017] In some example embodiments of the present disclosure, based on the aforementioned scheme, the word segmentation sequence generation module includes a word segmentation sequence generation unit, and the word segmentation sequence generation unit is used to generalize the text data and determine the generalized string of the text data; perform word segmentation on the text data based on the generalized string to generate a word segmentation sequence for the text data.
[0018] In some example embodiments of the present disclosure, based on the aforementioned scheme, the initial matrix construction module includes a text vectorization processing unit, which is used to obtain a pre-built word embedding model, and perform text vectorization processing on the word segmentation sequence based on the word embedding model to obtain the word vector of the word segmentation sequence.
[0019] In some example embodiments of the present disclosure, based on the aforementioned scheme, the random word selection operation module includes a target matrix generation unit, the target matrix generation unit is used to read the target number of random word selection operations, and perform the target number of random word selection operations on the word segmentation sequence; each time the random word selection operation is performed on the word segmentation sequence, determine the first word randomly selected at that time, and calculate the window text distance of the first word based on the position of the first word in the word segmentation sequence; and take the sub-word segmentation sequence in the word segmentation sequence centered on the first word and satisfying the window text distance as the target word segmentation sequence, and generate a target matrix corresponding to the target word segmentation sequence based on the initial matrix.
[0020] In some example embodiments of the present disclosure, based on the aforementioned scheme, the random word selection operation module further includes a word segmentation detection unit, and the word segmentation detection unit is used to re-execute the random word selection operation on the word segmentation sequence when it is detected that the first word segmentation is the same as the generalized string.
[0021] In some example embodiments of the present disclosure, based on the aforementioned scheme, the random word selection operation module also includes a candidate matrix generation unit, and the candidate word vector generation unit is used to randomly select a second word from the word segmentation sequence, and replace the first word in the target word segmentation sequence with the second word to obtain a candidate word segmentation sequence; based on the initial matrix, a candidate matrix matching the candidate word segmentation sequence is generated.
[0022] In some example embodiments of the present disclosure, based on the aforementioned scheme, the replacement word determination module includes an alternative word determination unit, and the alternative word determination unit is used to normalize the target matrix and the candidate matrix corresponding to each random word segmentation operation, respectively, to obtain a normalized target matrix and a normalized candidate matrix; calculate the average sum of the similarities of the column vectors in the normalized target matrix and the normalized candidate matrix, and use the average sum as the standard similarity; obtain a preset similarity threshold, and when it is detected that the standard similarity is greater than the similarity threshold, use the second word segmentation corresponding to the candidate matrix as an alternative word.
[0023] In some example embodiments of the present disclosure, based on the aforementioned scheme, the replacement word determination module also includes a replacement word determination unit, which is used to arrange all the standard similarities greater than the similarity threshold in order to obtain a standard similarity sequence; read a preset number of replacement words, and determine a sub-standard similarity sequence with a larger numerical value that matches the number of replacement words in the standard similarity sequence; use the alternative words of each of the sub-standard similarity sequences as replacement words, and generate enhanced text data of the text data based on the replacement words.
[0024] In some example embodiments of the present disclosure, based on the aforementioned scheme, the replacement word determination module also includes a number detection unit, which is used to determine the length of the standard similarity sequence, and when it is detected that the length is less than the number of replacement words, all the alternative words corresponding to the standard similarity sequence are used as the replacement words.
[0025] According to a third aspect of an embodiment of the present disclosure, there is provided an electronic device, comprising: a processor; and a memory, wherein the memory stores computer-readable instructions, and when the computer-readable instructions are executed by the processor, the text data enhancement method described in any one of the above is implemented.
[0026] According to a fourth aspect of an embodiment of the present disclosure, a computer-readable storage medium is provided, on which a computer program is stored. When the computer program is executed by a processor, the text data enhancement method according to any one of the above items is implemented.
[0027] The technical solution provided by the embodiments of the present disclosure may have the following beneficial effects:
[0028] The text data enhancement method in the example embodiment of the present disclosure obtains text data, and preprocesses the text data to generate a word segmentation sequence of the text data; vectorizes the word segmentation sequence to obtain a word vector of the word segmentation sequence, and constructs an initial matrix of the text data based on the word segmentation sequence and the word vector; based on the initial matrix, determines a target word segmentation sequence and a target matrix corresponding to the target word segmentation sequence generated by performing a random word segmentation operation on the word segmentation sequence each time, as well as a candidate word segmentation sequence corresponding to the target word segmentation sequence, and a candidate matrix corresponding to the candidate word segmentation sequence; calculates the similarity between the target matrix and the candidate matrix corresponding to each random word segmentation operation, and determines alternative words from the candidate word segmentation sequence based on the similarity, so as to screen replacement words from the alternative words, and generates enhanced text data of the text data based on the replacement words. On the one hand, the text data can be preprocessed to generate a word segmentation sequence of the text data, and multiple random word segmentation operations can be performed on the word segmentation sequence to determine the target word segmentation sequence and the candidate word segmentation sequence corresponding to the word segmentation sequence, so as to screen replacement words from the candidate word segmentation sequence by connecting the context of the word segmentation sequence, and generate enhanced text data based on the replacement words, thereby improving the reliability of the enhanced text data; on the other hand, an initial matrix can be constructed, and a target matrix corresponding to each target word segmentation sequence and a candidate matrix corresponding to each candidate word segmentation sequence can be determined based on the initial matrix, and the similarity between the target matrix and the candidate matrix can be calculated, and then the candidate words can be determined from the candidate word segmentation sequence according to the similarity, so as to select the replacement words from the candidate word segmentation sequence. The enhanced text data that selects replacement words from the selected words and generates text data based on the replacement words avoids the limitations of generating enhanced text data by adding noise or training generators and discriminators for specific tasks, and improves the universality of generating enhanced text data; on the other hand, the word segmentation sequence can be vectorized, and the similarity between each vector in the target matrix and the candidate matrix is calculated, and then the candidate words are determined from the candidate word segmentation sequence according to the similarity, and the replacement words are selected from the candidate words, and the enhanced text data of text data is generated based on the replacement words. This avoids consuming more network resources to add noise or train generators and discriminators, saves network resources, and also improves the generation efficiency of enhanced text data.
[0029] It is to be understood that the foregoing general description and the following detailed description are exemplary and explanatory only and are not restrictive of the present disclosure. BRIEF DESCRIPTION OF THE DRAWINGS
[0030] The drawings herein are incorporated into the specification and constitute a part of the specification, showing embodiments consistent with the present disclosure, and together with the specification, are used to explain the principles of the present disclosure. Obviously, the drawings described below are only some embodiments of the present disclosure, and for ordinary technicians in this field, other drawings can be obtained based on these drawings without creative work. In the drawings:
[0031] Figure 1 A schematic diagram schematically illustrates a text data enhancement method process according to some embodiments of the present disclosure;
[0032] Figure 2 A schematic diagram schematically shows the flow of a method for generating a word segmentation sequence according to some embodiments of the present disclosure;
[0033] Figure 3 A schematic diagram schematically shows a target matrix generation method process according to some embodiments of the present disclosure;
[0034] Figure 4 A schematic diagram schematically shows a candidate matrix generation method process according to some embodiments of the present disclosure;
[0035] Figure 5 A schematic diagram schematically shows the flow of a method for determining candidate words according to some embodiments of the present disclosure;
[0036] Figure 6 A schematic diagram schematically illustrates a process of a method for generating enhanced text data according to some embodiments of the present disclosure;
[0037] Figure 7 A schematic diagram schematically illustrates another text data enhancement method process according to some embodiments of the present disclosure;
[0038] Figure 8 A schematic diagram schematically shows a text data enhancement device according to some embodiments of the present disclosure;
[0039] Fig. 9 A schematic diagram schematically shows a structure of a computer system of an electronic device according to some embodiments of the present disclosure;
[0040] Fig.10 A schematic diagram of a computer-readable storage medium according to some embodiments of the present disclosure is schematically shown.
[0041] In the drawings, the same or corresponding reference numerals represent the same or corresponding parts. DETAILED DESCRIPTION
[0042] Example embodiments will now be described more fully with reference to the accompanying drawings. However, example embodiments can be implemented in a variety of forms and should not be construed as limited to the examples set forth herein; rather, these embodiments are provided so that this disclosure will be more comprehensive and complete and will fully convey the concept of the example embodiments to those skilled in the art.
[0043] In addition, the described features, structures or characteristics may be combined in one or more embodiments in any suitable manner. In the following description, many specific details are provided to provide a full understanding of the embodiments of the present disclosure. However, those skilled in the art will appreciate that the technical solutions of the present disclosure may be practiced without one or more of the specific details, or other methods, components, devices, steps, etc. may be adopted. In other cases, known methods, devices, implementations or operations are not shown or described in detail to avoid blurring the various aspects of the present disclosure.
[0044] Furthermore, the drawings are only schematic illustrations and are not necessarily drawn to scale. The block diagrams shown in the drawings are only functional entities and do not necessarily correspond to physically separate entities. That is, these functional entities may be implemented in software form, or in one or more hardware modules or integrated circuits, or in different networks and / or processor devices and / or microcontroller devices.
[0045] In this example embodiment, a text data enhancement method is first provided. The text data enhancement method can be applied to terminal devices, such as mobile phones, computers and other electronic devices. Figure 1 The following is a schematic diagram of a text data enhancement method process according to some embodiments of the present disclosure. Figure 1 As shown, the text data enhancement method may include the following steps:
[0046] Step S110, acquiring text data, and preprocessing the text data to generate a word segmentation sequence of the text data;
[0047] Step S120, vectorizing the word segmentation sequence to obtain a word vector of the word segmentation sequence, and constructing an initial matrix of the text data based on the word segmentation sequence and the word vector;
[0048] Step S130, based on the initial matrix, determining a target word segmentation sequence generated by performing a random word segmentation operation on the word segmentation sequence each time and a target matrix corresponding to the target word segmentation sequence, as well as a candidate word segmentation sequence corresponding to the target word segmentation sequence and a candidate matrix corresponding to the candidate word segmentation sequence;
[0049] Step S140, calculating the similarity between the target matrix and the candidate matrix corresponding to each random word segmentation operation, and determining alternative words from the candidate word segmentation sequence based on the similarity, so as to screen replacement words from the alternative words, and generating enhanced text data of the text data based on the replacement words.
[0050] According to the text data enhancement method in this example embodiment, on the one hand, the text data can be preprocessed to generate a word segmentation sequence of the text data, and multiple random word segmentation operations can be performed on the word segmentation sequence to determine the target word segmentation sequence and the candidate word segmentation sequence corresponding to the word segmentation sequence, so as to screen replacement words from the candidate word segmentation sequence by connecting the context of the word segmentation sequence, and generate enhanced text data based on the replacement words, thereby improving the reliability of the enhanced text data; on the other hand, an initial matrix can be constructed, and a target matrix corresponding to each target word segmentation sequence and a candidate matrix corresponding to each candidate word segmentation sequence can be determined based on the initial matrix, and the similarity between the target matrix and the candidate matrix can be calculated, and then the candidate word segmentation sequence can be selected according to the similarity. Determine alternative words, select replacement words from the alternative words, and generate enhanced text data of text data based on the replacement words, avoid the limitations of generating enhanced text data by adding noise or training generators and discriminators for specific tasks, and improve the universality of generating enhanced text data; on the other hand, by vectorizing the word segmentation sequence, calculating the similarity between each vector in the target matrix and the candidate matrix, and then determining alternative words from the candidate word segmentation sequence according to the similarity, and selecting replacement words from the alternative words, and generating enhanced text data of text data based on the replacement words, avoids consuming more network resources to add noise or train generators and discriminators, saves network resources, and also improves the generation efficiency of enhanced text data.
[0051] The text data enhancement method in this example embodiment will be further described below.
[0052] In step S110, text data is acquired, and the text data is preprocessed to generate a word segmentation sequence of the text data.
[0053] In some example embodiments of the present disclosure, a word segmentation sequence may refer to a string sequence obtained after preprocessing text data. For example, the word segmentation sequence may be a word sequence obtained after generalizing and segmenting the text data. The word segmentation sequence may also be a single character sequence obtained after generalizing and segmenting the text data. Of course, the word segmentation sequence may also be a string sequence obtained by performing other preprocessing on the text data, and this example embodiment does not specifically limit this.
[0054] The text data can be generalized to determine the generalized string of the text data, and the text data can be segmented based on the generalized string to obtain the segmentation sequence of the text data. For example, the web request text can be generalized to generalize the variable names that meet certain characteristics into <ip> , <emial> , <num> , <date> , <time>Etc., and then perform word segmentation processing on all generalized text data to obtain the word segmentation sequence of the request text, which reduces the change of the distribution characteristics of the text data and enhances the generalization of the text data samples.
[0055] In step S120, the word segmentation sequence is vectorized to obtain a word vector of the word segmentation sequence, and an initial matrix of the text data is constructed based on the word segmentation sequence and the word vector.
[0056] In some example embodiments of the present disclosure, a word vector may refer to data obtained by vectorizing a word segmentation sequence. For example, a word vector may be feature point coordinates obtained by extracting features of a word segmentation sequence in a sample space composed of text data and vectorizing the extracted features. A word vector may also be a vector obtained by extracting the probability that a word segmentation sequence belongs to a generalized string in text data and vectorizing the extracted probability. Of course, a word vector may also be data obtained by performing other vectorization on a word segmentation sequence, and this example embodiment does not specifically limit this.
[0057] The features of the word segmentation sequence can be extracted by obtaining a pre-built word embedding model, and the extracted features can be vectorized to obtain the word vector of the word segmentation sequence. For example, the features of the word segmentation sequence can be extracted by a CBoW model (Continuous Bag-of-Words Model), and the extracted features can be vectorized to obtain the word vector of the word segmentation sequence. The Skip-gram model can also be used (a word is removed from the word window). Of course, the features of the word segmentation sequence can also be extracted by other models, and the extracted features can be vectorized to obtain the word vector of the word segmentation sequence. This embodiment does not make any special limitation to this.
[0058] Preferably, the word segmentation sequence can be vectorized to obtain the word vector of the word segmentation sequence, and an initial matrix can be constructed based on the word segmentation sequence and the word vector of the word segmentation sequence, so as to determine the target matrix and candidate matrix corresponding to each random word segmentation operation performed on the word segmentation sequence based on the initial matrix.
[0059] In step S130, based on the initial matrix, a target word segmentation sequence generated by performing a random word segmentation operation on the word segmentation sequence each time and a target matrix corresponding to the target word segmentation sequence, as well as a candidate word segmentation sequence corresponding to the target word segmentation sequence and a candidate matrix corresponding to the candidate word segmentation sequence are determined;
[0060] In some example embodiments of the present disclosure, a target word segmentation sequence may refer to a word segmentation sequence obtained by performing a random word sampling operation on a word segmentation sequence. For example, the target word segmentation sequence may be a word segmentation sequence obtained by performing a random word sampling operation on a word segmentation sequence, and then determining the window text distance of the selected word segmentation according to the position of the selected word segmentation in the word segmentation sequence. The selected word segmentation is taken as the center, and a sub-word segmentation sequence in the word segmentation sequence that satisfies the window text distance of the selected word segmentation is taken as the target word segmentation sequence. Of course, the target word segmentation sequence may also be a word segmentation sequence obtained by performing other random word sampling operations on the word segmentation sequence, and this example embodiment does not specifically limit this.
[0061] A candidate word segmentation sequence may refer to a word segmentation sequence obtained by performing a word segmentation replacement operation on a target word segmentation sequence. For example, a candidate word segmentation sequence may be a word segmentation sequence in which a central word in a target word segmentation sequence is replaced, while other word segmentations in the target word segmentation sequence remain unchanged. Of course, a candidate word segmentation sequence may also be a word segmentation sequence obtained by performing other word segmentation replacement operations on a target word segmentation sequence, and this embodiment does not make any special limitation to this.
[0062] The target number of random sampling operations performed on the word segmentation sequence can be read, and the target word segmentation sequence and the target matrix corresponding to the target word segmentation sequence generated by each random sampling operation on the word segmentation sequence can be determined based on the initial matrix, as well as the candidate word segmentation sequence corresponding to the target word segmentation sequence and the candidate matrix corresponding to the candidate word segmentation sequence.
[0063] In step S140, the similarity between the target matrix and the candidate matrix corresponding to each random word segmentation operation is calculated, and alternative words are determined from the candidate word segmentation sequence based on the similarity to screen replacement words from the alternative words, and enhanced text data of the text data is generated based on the replacement words.
[0064] In some example embodiments of the present disclosure, similarity may refer to a scalar value determined by calculating the distance between the target matrix and the candidate matrix, which is used to measure the similarity between each column vector in the target matrix and the candidate matrix. For example, the similarity may be a scalar value determined by calculating the cosine distance between the target matrix and the candidate matrix, which is used to measure the similarity between each column vector in the target matrix and the candidate matrix. The similarity may also be a scalar value determined by calculating the Euclidean distance between the target matrix and the candidate matrix, which is used to measure the similarity between each column vector in the target matrix and the candidate matrix. Of course, the similarity may also be a scalar value determined by calculating other distances between the target matrix and the candidate sentence, such as the Manhattan distance or the Chechebiev distance, which is used to measure the similarity between each column vector in the target matrix and the candidate matrix. This example embodiment does not specifically limit this.
[0065] Before calculating the similarity between the target matrix and the candidate matrix, the target matrix and the candidate matrix can be normalized respectively, and then the similarity between each column vector in the normalized target matrix and the candidate matrix is calculated, and the average sum of the similarities of each column vector is calculated. Then, a preset similarity threshold can be read, and the similarity threshold can be compared with the average sum of similarities of each target matrix and the candidate matrix, and the central participle in the candidate participle sequence corresponding to each candidate matrix with an average sum of similarities greater than the similarity threshold can be used as an alternative word, and the similarities with an average sum of similarities greater than the threshold are arranged in order from small to large, and a target number of average sums of similarities greater than the threshold are selected, so that the alternative word corresponding to the selected average sum of similarities is used as a replacement word, and enhanced text data corresponding to the text data is generated based on the replacement word.
[0066] In the process of generating enhanced text data of text data, the text data needs to be preprocessed first. In the process of finding replacement words, random extraction is used multiple times, which reduces the change of data distribution, enhances the generalization of samples, and thus improves the universality of enhanced text data; at the same time, in the process of performing multiple random extraction of word segmentation operations on the word segmentation sequence to generate the target word segmentation sequence, the influence of the context of the text data is considered, thereby improving the effectiveness of the enhanced text data; in addition, when calculating the similarity between the target matrix and the candidate matrix, the text similarity is not calculated directly, but starting from its vectorized representation, which reduces the computational complexity of the similarity between the target matrix and the candidate matrix, and also avoids training the generator and the discriminator, saving network resources, and improving the efficiency of generating incremental text data.
[0067] Figure 2 The following is a schematic diagram showing the flow of a method for generating a word segmentation sequence according to some embodiments of the present disclosure. Figure 2 As shown, the word segmentation sequence generation method may include the following steps:
[0068] In step S210, generalization processing is performed on the text data to determine a generalized character string of the text data;
[0069] In step S220, the text data is segmented based on the generalized character string to generate a segmentation sequence of the text data.
[0070] Among them, a generalized string may refer to a special string used to divide a string in text data according to specific rules to obtain a segmentation sequence. For example, a generalized string may be a special string used to divide a string in text data according to grammatical rules to obtain a segmentation sequence. A generalized string may also be a special string used to divide a string in text data according to semantic rules to obtain a segmentation sequence. Of course, a generalized string may also be a special string used to divide a string in text data according to other specific rules to obtain a segmentation sequence. This embodiment does not make any special limitation to this.
[0071] The text data can be generalized to determine the generalized string of the text data, and the text data can be segmented according to the generalized string to generate a segmentation sequence of the text data. For example, if there is data like 192.168.34.56 in the text data, in the process of generalizing the text data, the data like 192.168.34.56 can be directly used <ip>This character is replaced, that is, when determining the word segmentation sequence of text data, <ip>As the generalized string of text data is directly put into the dictionary, data such as 192.168.34.56 in the text data will not be split, and then the text data can be segmented according to the generalized string to obtain the segmentation sequence of the text data.
[0072] In some example embodiments of the present disclosure, a pre-built word embedding model may be obtained, and a text vectorization process may be performed on a word segmentation sequence based on the word embedding model to obtain a word vector of the word segmentation sequence.
[0073] Among them, the word embedding model may refer to a model used to perform text vectorization processing on a word segmentation sequence. For example, the word embedding model may be a CBoW model (Continuous Bag-of-Words Model) used to perform text vectorization processing on a word segmentation sequence. The word embedding model may be a Skip-gram model (removing a word from the word window) used to perform text vectorization processing on a word segmentation sequence. Of course, the word embedding model may also be other models used to perform text vectorization processing on a word segmentation sequence, and this embodiment does not specifically limit this.
[0074] You can obtain a pre-built word embedding model and use the word embedding model to perform text vectorization on the word segmentation sequence to vectorize the word segmentation sequence and obtain the word vector of the word segmentation sequence. Then, you can build an initial matrix based on the word segmentation sequence and the word vector of the word segmentation sequence.
[0075] Figure 3 The following is a schematic diagram showing the process of the target matrix generation method according to some embodiments of the present disclosure. Figure 3 As shown, the target matrix generation method may include the following steps:
[0076] In step S310, a target number of random word selection operations is read, and the target number of random word selection operations are performed on the word segmentation sequence;
[0077] In step S320, each time the random word selection operation is performed on the word sequence, a first word randomly selected at that time is determined, and a window text distance of the first word is calculated based on the position of the first word in the word sequence; and
[0078] In step S330, a sub-segmentation sequence in the segmentation sequence centered on the first segmentation and satisfying the window text distance is taken as a target segmentation sequence, and a target matrix corresponding to the target segmentation sequence is generated based on the initial matrix.
[0079] Among them, the window text distance can refer to a distance used to measure the length of a target word segmentation sequence. For example, the window text distance can be an initial distance between the first word and the first word of the word segmentation sequence determined based on the position of the first word in the word segmentation sequence, and a distance used to measure the length of the target word segmentation sequence determined based on the initial distance. The window text distance can also be an initial distance between the first word and the first word of the word segmentation sequence determined based on the position of the first word in the first word segmentation sequence, and a length of a sub-word segmentation sequence centered on the first word in the word segmentation sequence and with the initial distance as a reference radius determined based on the initial distance, and the length is used as a distance to measure the length of the target word segmentation sequence. Of course, the window text distance can also be other distances used to measure the length of the target word segmentation sequence calculated based on the position of the first word in the word segmentation sequence, and this embodiment is not particularly limited to this.
[0080] The preset target number of random word selection operations can be read, and the target number of random word selection operations can be performed on the word segmentation sequence, the first word randomly selected from the word segmentation sequence is determined, and the window text distance of the first word is calculated according to the position of the first word in the word segmentation sequence, and the sub-word segmentation sequence that satisfies the window text distance of the first word is determined from the word segmentation sequence with the first word as the center, and the sub-word segmentation sequence is used as the target word segmentation sequence. Furthermore, based on the initial matrix, a target matrix corresponding to the target word segmentation sequence can be generated. For example, a simple row transformation can be performed on the initial matrix according to the target word segmentation sequence, such as deleting the row vectors in the initial matrix that do not match the target word segmentation sequence, to obtain a target matrix that matches the target word segmentation sequence.
[0081] In some example embodiments of the present disclosure, when it is detected that the first randomly selected word segmentation is the same as the generalized string of the text data, the random selection word segmentation operation may be re-executed on the word segmentation sequence of the text data.
[0082] Each randomly selected word segmentation can be compared with the generalized string of the text data. When it is detected that the randomly selected word segmentation is the same as the generalized string of the text data, the word segmentation sequence is randomly selected again, and the word segmentation of the non-generalized string obtained by the random selection operation is used as the first word segmentation. The first word segmentation is used as the center, and a sub-word segmentation sequence that matches the window text distance calculated by the position of the first word segmentation in the word segmentation sequence is determined from the word segmentation sequence, and the sub-word segmentation sequence is used as the target word segmentation sequence.
[0083] Figure 4 The following is a schematic diagram of the candidate matrix generation method according to some embodiments of the present disclosure. Figure 4 As shown, the candidate matrix generation method may include the following steps:
[0084] In step S410, a second segmentation is randomly selected from the segmentation sequence, and the first segmentation in the target segmentation sequence is replaced by the second segmentation to obtain a candidate segmentation sequence;
[0085] In step S420, a candidate matrix matching the candidate word segmentation sequence is generated based on the initial matrix.
[0086] The second word segmentation may refer to a word segmentation randomly selected from the word segmentation sequence and different from the generalized character string of the text data and the first word segmentation.
[0087] For example, the word segmentation sequence obtained after preprocessing the text data is [T1, T2, T3, T4, T5, T6, T7, T8, T9, T10]. Assuming that the first word segmentation randomly selected from the word segmentation sequence is T3, the window text distance of the first word segmentation can be obtained as win=5, and then based on the word segmentation sequence, a target word segmentation sequence [T1, T2, T3, T4, T5] with sequence T3 and corresponding to the window text distance of the first word segmentation can be obtained; at the same time, after obtaining the target word segmentation sequence, assuming that the second word segmentation obtained by continuing to perform the random word segmentation operation on the word segmentation sequence is T8, the second word segmentation T8 can be used to replace the first word segmentation T3 in the target word segmentation sequence to obtain a candidate word segmentation sequence [T1, T2, T8, T4, T5].
[0088] The second word segmentation can be randomly selected from the word segmentation sequence, and when it is detected that the second word segmentation is different from the generalized string, the first word segmentation in the target word segmentation sequence can be replaced by the second word segmentation to obtain a candidate word segmentation sequence, and then a candidate matrix matching the candidate word segmentation sequence can be generated based on the initial matrix. For example, the row vectors in the initial matrix that do not correspond to the candidate word segmentation sequence are deleted to obtain a candidate matrix matching the candidate word segmentation sequence. In the process of generating the candidate word segmentation sequence and the candidate matrix, by randomly selecting words from the word segmentation sequence, the change to the text data structure is reduced, the generalization of the candidate word segmentation sequence and the candidate matrix is improved, and the limitations of generating enhanced text data by adding noise or training generators and discriminators are further reduced, and the flexibility and universality of generating enhanced text data are improved.
[0089] Figure 5 The following is a schematic diagram showing the flow of a method for determining candidate words according to some embodiments of the present disclosure. Figure 5 As shown, the candidate word determination method may include the following steps:
[0090] In step S510, the target matrix and the candidate matrix corresponding to each random word segmentation operation are normalized to obtain a normalized target matrix and a normalized candidate matrix;
[0091] In step S520, the average sum of similarities between the normalized target matrix and the column vectors in the normalized candidate matrix is calculated, and the average sum is used as the standard similarity;
[0092] In step S530, a preset similarity threshold is obtained, and when it is detected that the standard similarity is greater than the similarity threshold, the second participle corresponding to the candidate matrix is used as a candidate word.
[0093] Among them, after performing each random word segmentation operation on the word segmentation sequence to obtain the target matrix and the candidate matrix, the target matrix and the candidate matrix can be normalized to obtain the normalized target matrix and the normalized candidate matrix. Then, the similarity between each column vector in the normalized target matrix and each column vector in the normalized candidate matrix is calculated, and the average sum of the similarities of each column vector is calculated, so that the average sum of the similarities is used as the standard similarity between the target matrix and the candidate matrix obtained by each random word segmentation operation.
[0094] For example, after performing the random word selection operation on the word segmentation sequence to obtain the target matrix and the candidate matrix, the target matrix and the candidate matrix can be normalized to obtain the normalized target matrix and the normalized candidate matrix. Assume that the normalized target matrix and the normalized candidate matrix are both two-dimensional matrices, and the row vectors of the normalized target matrix and the normalized candidate matrix can be regarded as the vectorized representation of each word segmentation sequence, and the column vectors of the normalized target matrix and the normalized candidate matrix can be regarded as the values corresponding to the features of the vectorized representation of each word segmentation sequence. At the same time, the average sum of the similarities of the column vectors of the normalized target matrix and the normalized candidate matrix can be calculated using formula (1).
[0095]
[0096] Wherein, D can represent the standard similarity between the normalized target matrix and the normalized candidate matrix calculated after the target matrix and the candidate matrix obtained by performing the random segmentation operation on the segmentation sequence are normalized, m can represent the number of column vectors of the normalized target matrix and the normalized candidate matrix, f can represent the number of columns of the current column vector of the normalized target matrix and the normalized candidate matrix, win can represent the number of row vectors of the normalized target matrix and the normalized candidate matrix, i can represent the number of rows of the current row vector of the normalized target matrix and the normalized candidate matrix, and x can represent the number of rows of the current row vector of the normalized target matrix and the normalized candidate matrix. i It can represent the value of each column vector in the normalized target matrix, y i It can represent the value of each column vector in the normalized candidate matrix.
[0097] The target matrix and the candidate matrix obtained by each random word segmentation operation can be normalized to obtain a normalized target matrix and a normalized candidate matrix, and the average sum of the similarities of the column vectors of each normalized target matrix and the normalized candidate matrix is calculated, and the average sum of the similarities of the column vectors is used as the standard similarity. Furthermore, a preset similarity threshold can be read, and the standard similarity threshold can be compared with the similarity threshold. When it is detected that the standard similarity threshold is greater than the similarity threshold, the second word in the candidate word sequence of the candidate matrix corresponding to the standard similarity threshold is used as an alternative word. Thus, the replacement word can be screened from the alternative words, thereby improving the effectiveness of the enhanced text data.
[0098] Figure 6 The following is a schematic diagram of a method for generating enhanced text data according to some embodiments of the present disclosure. Figure 6 As shown, the enhanced text data generation method may include the following steps:
[0099] In step S610, all the standard similarities greater than the similarity threshold are arranged in order to obtain a standard similarity sequence;
[0100] In step S620, a preset number of replacement words is read, and a substandard similarity sequence with a larger value matching the number of replacement words in the standard similarity sequence is determined;
[0101] In step S630, the candidate words of each of the sub-standard similarity sequences are used as replacement words, and enhanced text data of the text data is generated based on the replacement words.
[0102] When it is detected that there is a value greater than the similarity threshold in the standard similarities of the target matrix and the candidate matrix obtained by performing a random selection operation on the segmentation sequence, the second segmentation in the candidate segmentation sequence corresponding to the candidate matrix with each standard similarity greater than the similarity threshold is used as an alternative word. Furthermore, the standard similarity sequence can be obtained by arranging the standard similarities greater than the similarity threshold in order from small to large, or the standard similarities greater than the similarity threshold are arranged in order from large to small to obtain the standard similarity sequence, and a target number of standard similarities with larger values are selected from the standard similarity sequence as a sub-standard similarity sequence, so that the alternative word corresponding to the sub-standard similarity sequence is used as a replacement word, thereby generating incremental text data corresponding to the text data based on the replacement word.
[0103] For example, assuming that the target number of random word selection operations on the word segmentation sequence is n, and after performing n random word selection operations on the word segmentation sequence to obtain the target matrix and the candidate matrix, among the standard similarities between the n normalized target matrices and the n normalized candidate matrices, k standard similarities are greater than the preset similarity threshold, and the second word in the candidate word segmentation sequence of the candidate matrix corresponding to the k standard similarities greater than the similarity threshold can be used as an alternative word. Furthermore, the k standard similarities greater than the similarity threshold are arranged in order from small to large to obtain a standard similarity sequence, and a standard similarity with a larger value matching the number of replacement words can be selected from the standard similarity sequence to generate a sub-standard similarity sequence, and the alternative word corresponding to the sub-standard similarity sequence is used as a replacement word.
[0104] First, the candidate matrices whose standard similarities are greater than the similarity threshold can be screened, and the second participles of the candidate participles corresponding to the candidate matrices whose standard similarities are greater than the similarity threshold can be determined, and the second participles of the candidate participles can be used as candidate words for the text data; secondly, all standard similarities greater than the similarity threshold can be sorted from small to large to obtain a standard similarity sequence, and the number of replacement words can be read to read the standard similarities with larger values that match the number of replacement words from the standard similarity sequence to form a sub-standard similarity sequence; finally, the candidate words corresponding to the sub-standard similarity sequence can be used as replacement words for the text data, and enhanced text data corresponding to the text data can be generated based on the replacement words. When calculating the similarity between the target matrix and the candidate matrix, the text similarity is not calculated directly, but starting from its vectorized representation, which reduces the computational complexity of the similarity between the target matrix and the candidate matrix, avoids training the generator and the discriminator, saves network resources, and improves the efficiency of generating incremental text data; at the same time, by determining the second participle of the candidate participle sequence corresponding to the candidate matrix whose standard similarity is greater than the similarity threshold, and using the second participle as an alternative word, selecting the participle with the highest similarity from the alternative words as the replacement word, and then generating enhanced text data corresponding to the text data based on the replacement word selected from the alternative words, the reliability of the enhanced text data is improved.
[0105] In some example embodiments of the present disclosure, the length of a standard similarity sequence consisting of all standard similarities greater than a similarity threshold may be determined, and when it is detected that the length of the standard similarity sequence is less than the number of replacement words, all alternative words corresponding to the standard similarities are used as replacement words for the text data.
[0106] After sorting all standard similarities greater than a similarity threshold from small to large to obtain a standard similarity sequence, the length of the standard similarity sequence can be determined, and when it is detected that the length of the standard similarity sequence is less than a preset number of replacement words, that is, when it is detected that the number of alternative words is less than the preset number of replacement words, the alternative words corresponding to the standard similarity sequence can all be used as replacement words for the text data.
[0107] Figure 7 The following is a schematic diagram of another text data enhancement method process according to some embodiments of the present disclosure. Figure 7 As shown, the schematic diagram of the text data enhancement method process may include the following steps:
[0108] In step S710, text data is acquired, and generalization and word segmentation processing is performed on the text data to obtain a word segmentation sequence of the text data;
[0109] In step S720, the word segmentation sequence is vectorized by a word embedding model to generate a word vector for the word segmentation sequence;
[0110] In step S730, an initial matrix is constructed based on the word segmentation sequence and the word vector of the word segmentation sequence;
[0111] In step S740, multiple random word selection operations are performed on the word segmentation sequence to determine a target word segmentation sequence corresponding to each random word selection operation and a candidate word segmentation for replacing the central word of the target word segmentation sequence;
[0112] In step S750, based on the initial matrix, each target matrix corresponding to each target word segmentation sequence is generated;
[0113] In step S760, each candidate segmentation sequence is obtained by replacing the central word of each target segmentation sequence with each candidate segmentation sequence;
[0114] In step S770, based on the initial matrix, each candidate matrix corresponding to each candidate word segmentation sequence is generated;
[0115] In step S780, based on the similarity between each target matrix and each candidate matrix, candidate words of the text data are determined, and replacement words are selected from the candidate words;
[0116] In step S790, enhanced text data corresponding to the text data is generated based on the replacement word.
[0117] Some samples can be randomly selected from the category to be data augmented as text data, and the text data can be generalized and segmented to obtain the segmentation sequence of the text data. The segmentation sequence can be vectorized through the word embedding model to obtain the word vector of the segmentation sequence, and then the text data can be represented as an initial matrix composed of the segmentation sequence and the word vector of the segmentation sequence.
[0118] After obtaining the word segmentation sequence, the word segmentation operation can be performed on the word segmentation sequence for a target number of times to determine the first word randomly selected each time, and determine the position of each first word in the word segmentation sequence, such as a serial number, and calculate the window text distance of the first word based on the position of the first word. Then, with the first word as the center, a sub-word segmentation sequence that satisfies the window text distance of the first word is determined from the word segmentation sequence, and the sub-word segmentation sequence is used as the target word segmentation sequence, and based on the initial matrix, a target matrix corresponding to the target word segmentation sequence is generated. Thus, the target word segmentation sequence and the target matrix corresponding to each random word segmentation operation performed on the word segmentation sequence can be obtained.
[0119] In the process of generating each target word segmentation sequence, the random selection operation can continue to be performed on the word segmentation sequence to determine the second word segmentation used to replace the first word segmentation in each target word segmentation sequence, and replace the first word segmentation in the target word segmentation sequence with the second word segmentation to obtain a candidate word segmentation sequence, and based on the initial matrix, obtain a candidate matrix corresponding to the candidate word segmentation sequence; further, the candidate word segmentation sequence corresponding to each target word segmentation sequence and the candidate matrix corresponding to each candidate word segmentation sequence can be obtained.
[0120] After obtaining each target matrix and candidate matrix, the idea of the knn (K-Nearest Neighbor) algorithm can be used to determine the replacement word of the text data. Specifically, each target matrix and the candidate matrix corresponding to each target matrix can be normalized to obtain each normalized target matrix and each normalized candidate matrix, and the average sum of the similarities of each column vector between each normalized target matrix and the normalized candidate matrix corresponding to each normalized target matrix is calculated, and the average sum of each similarity is used as the standard similarity between each target matrix and the candidate matrix corresponding to each target matrix, and then each standard similarity is compared with a similarity threshold, and a standard similarity greater than the similarity threshold is determined, and the second participle of the candidate participle sequence of the candidate matrix corresponding to the standard similarity greater than the similarity threshold is used as an alternative word. Furthermore, the standard similarities greater than the similarity threshold can be arranged in order from small to large or from large to small to obtain a standard similarity sequence, and the preset number of replacement words is read, and the standard similarities with larger values that match the number of replacement words are selected from the standard similarity sequence as a sub-standard similarity sequence, so that the alternative words corresponding to the sub-standard similarity sequence are used as replacement words for the text data; however, when it is detected that the length of the standard similarity sequence is less than the preset number of replacement words, that is, when it is detected that the number of alternative words is less than the number of replacement words, all the alternative words can be used as replacement words for the text data. Thus, based on the replacement words of the text data, enhanced text data corresponding to the text data is generated.
[0121] It should be noted that, although the steps of the method in the present disclosure are described in a specific order in the drawings, this does not require or imply that the steps must be performed in this specific order, or that all the steps shown must be performed to achieve the desired results. Additionally or alternatively, some steps may be omitted, multiple steps may be combined into one step, and / or one step may be decomposed into multiple steps, etc.
[0122] In addition, in this exemplary embodiment, a text data enhancement device is also provided. Figure 8 As shown, the text data enhancement device 800 includes: a word segmentation sequence generation module 810, an initial matrix construction module 820, a random word segmentation operation module 830, and a replacement word determination module 840. Among them: a word segmentation sequence generation module 810 is used to obtain text data and pre-process the text data to generate a word segmentation sequence of the text data; an initial matrix construction module 820 is used to vectorize the word segmentation sequence to obtain the word vector of the word segmentation sequence, and construct the initial matrix of the text data based on the word segmentation sequence and the word vector; a random word segmentation operation module 830 is used to determine, based on the initial matrix, a target word segmentation sequence and a target matrix corresponding to the target word segmentation sequence generated by performing a random word segmentation operation on the word segmentation sequence each time, as well as a candidate word segmentation sequence corresponding to the target word segmentation sequence and a candidate matrix corresponding to the candidate word segmentation sequence; a replacement word determination module 840 is used to calculate the similarity between the target matrix and the candidate matrix corresponding to each random word segmentation operation, and determine alternative words from the candidate word segmentation sequence based on the similarity, so as to screen replacement words from the alternative words, and generate enhanced text data of the text data based on the replacement words.
[0123] In some example embodiments of the present disclosure, based on the aforementioned scheme, the word segmentation sequence generation module 810 includes a word segmentation sequence generation unit, which is used to generalize the text data and determine the generalized string of the text data; perform word segmentation on the text data based on the generalized string to generate a word segmentation sequence for the text data.
[0124] In some example embodiments of the present disclosure, based on the aforementioned scheme, the initial matrix construction module 820 includes a text vectorization processing unit, which is used to obtain a pre-built word embedding model, and perform text vectorization processing on the word segmentation sequence based on the word embedding model to obtain the word vector of the word segmentation sequence.
[0125] In some example embodiments of the present disclosure, based on the aforementioned scheme, the random word selection operation module 830 includes a target matrix generation unit, which is used to read the target number of random word selection operations and perform the target number of random word selection operations on the word segmentation sequence; each time the random word selection operation is performed on the word segmentation sequence, determine the first word randomly selected at that time, and calculate the window text distance of the first word based on the position of the first word in the word segmentation sequence; and take the sub-word segmentation sequence in the word segmentation sequence centered on the first word and satisfying the window text distance as the target word segmentation sequence, and generate a target matrix corresponding to the target word segmentation sequence based on the initial matrix.
[0126] In some example embodiments of the present disclosure, based on the aforementioned scheme, the random word selection operation module 830 further includes a word segmentation detection unit, which is used to re-execute the random word selection operation on the word segmentation sequence when it is detected that the first word segmentation is the same as the generalized string.
[0127] In some example embodiments of the present disclosure, based on the aforementioned scheme, the random word selection operation module 830 also includes a candidate matrix generation unit, and the candidate word vector generation unit is used to randomly select a second word from the word segmentation sequence, and replace the first word in the target word segmentation sequence with the second word to obtain a candidate word segmentation sequence; based on the initial matrix, a candidate matrix matching the candidate word segmentation sequence is generated.
[0128] In some example embodiments of the present disclosure, based on the aforementioned scheme, the replacement word determination module 840 includes an alternative word determination unit, which is used to normalize the target matrix and the candidate matrix corresponding to each random word segmentation operation, respectively, to obtain a normalized target matrix and a normalized candidate matrix; calculate the average sum of the similarities of the column vectors in the normalized target matrix and the normalized candidate matrix, and use the average sum as the standard similarity; obtain a preset similarity threshold, and when it is detected that the standard similarity is greater than the similarity threshold, use the second word segmentation corresponding to the candidate matrix as an alternative word.
[0129] In some example embodiments of the present disclosure, based on the aforementioned scheme, the replacement word determination module 840 also includes a replacement word determination unit, which is used to arrange all the standard similarities greater than the similarity threshold in order to obtain a standard similarity sequence; read a preset number of replacement words, and determine a sub-standard similarity sequence with a larger numerical value that matches the number of replacement words in the standard similarity sequence; use the alternative words of each of the sub-standard similarity sequences as replacement words, and generate enhanced text data of the text data based on the replacement words.
[0130] In some example embodiments of the present disclosure, based on the aforementioned scheme, the replacement word determination module 840 also includes a number detection unit, which is used to determine the length of the standard similarity sequence, and when it is detected that the length is less than the number of replacement words, all the alternative words corresponding to the standard similarity sequence are used as the replacement words.
[0131] The specific details of each module of the above-mentioned Chinese text data enhancement device have been described in detail in the corresponding text data enhancement method, so they will not be repeated here.
[0132] It should be noted that although several modules or units of the text data enhancement device are mentioned in the above detailed description, this division is not mandatory. In fact, according to the embodiments of the present disclosure, the features and functions of two or more modules or units described above can be embodied in one module or unit. Conversely, the features and functions of one module or unit described above can be further divided into multiple modules or units to be embodied.
[0133] In addition, in an exemplary embodiment of the present disclosure, an electronic device capable of implementing the above-mentioned text data enhancement method is also provided.
[0134] Those skilled in the art will appreciate that various aspects of the present disclosure may be implemented as systems, methods or program products. Therefore, various aspects of the present disclosure may be specifically implemented in the following forms, namely: complete hardware embodiments, complete software embodiments (including firmware, microcode, etc.), or embodiments combining hardware and software aspects, which may be collectively referred to herein as "circuits", "modules" or "systems".
[0135] Refer to the following Fig. 9 hereinafter describes an electronic device 900 according to such an embodiment of the present disclosure. Fig. 9 The electronic device 900 shown is merely an example and should not bring any limitation to the functions and scope of use of the embodiments of the present disclosure.
[0136] like Fig. 9 As shown, the electronic device 900 is in the form of a general computing device. The components of the electronic device 900 may include, but are not limited to: the at least one processing unit 910, the at least one storage unit 920, a bus 930 connecting different system components (including the storage unit 920 and the processing unit 910), and a display unit 940.
[0137] The storage unit stores a program code, which can be executed by the processing unit 910, so that the processing unit 910 performs the steps according to various exemplary embodiments of the present disclosure described in the above "Exemplary Method" section of this specification. For example, the processing unit 910 can perform the following steps: Figure 1 In step S110 shown in the text data, text data is acquired, and the text data is preprocessed to generate a word segmentation sequence of the text data; in step S120, the word segmentation sequence is vectorized to obtain a word vector of the word segmentation sequence, and an initial matrix of the text data is constructed based on the word segmentation sequence and the word vector; in step S130, based on the initial matrix, a target word segmentation sequence and a target matrix corresponding to the target word segmentation sequence are determined each time a random word segmentation operation is performed on the word segmentation sequence, as well as a candidate word segmentation sequence corresponding to the target word segmentation sequence, and a candidate matrix corresponding to the candidate word segmentation sequence are determined; in step S140, the similarity between the target matrix and the candidate matrix corresponding to each random word segmentation operation is calculated, and alternative words are determined from the candidate word segmentation sequence based on the similarity to screen replacement words from the alternative words, and enhanced text data of the text data is generated based on the replacement words.
[0138] The storage unit 920 may include a readable medium in the form of a volatile storage unit, such as a random access memory unit (RAM) 921 and / or a cache memory unit 922 , and may further include a read-only memory unit (ROM) 923 .
[0139] The storage unit 920 may also include a program / utility 924 having a set (at least one) of program modules 925, such program modules 925 including but not limited to: an operating system, one or more application programs, other program modules, and program data, each of which or some combination may include an implementation of a network environment.
[0140] Bus 930 may represent one or more of several types of bus structures, including a memory unit bus or memory unit controller, a peripheral bus, an accelerated graphics port, a processing unit, or a local bus using any of a variety of bus architectures.
[0141] The electronic device 900 may also communicate with one or more external devices 970 (e.g., keyboards, pointing devices, Bluetooth devices, etc.), may also communicate with one or more devices that enable a user to interact with the electronic device 900, and / or communicate with any device that enables the electronic device 900 to communicate with one or more other computing devices (e.g., routers, modems, etc.). Such communication may be performed via an input / output (I / O) interface 950. In addition, the electronic device 500 may also communicate with one or more networks (e.g., local area networks (LANs), wide area networks (WANs), and / or public networks, such as the Internet) via a network adapter 960. As shown, the network adapter 960 communicates with other modules of the electronic device 900 via a bus 930. It should be understood that, although not shown in the figure, other hardware and / or software modules may be used in conjunction with the electronic device 900, including but not limited to: microcode, device drivers, redundant processing units, external disk drive arrays, RAID systems, tape drives, and data backup storage systems.
[0142] Through the description of the above embodiments, it is easy for those skilled in the art to understand that the example embodiments described here can be implemented by software, or by software combined with necessary hardware. Therefore, the technical solution according to the embodiment of the present disclosure can be embodied in the form of a software product, which can be stored in a non-volatile storage medium (which can be a CD-ROM, a USB flash drive, a mobile hard disk, etc.) or on a network, and includes several instructions to enable a computing device (which can be a personal computer, a server, a terminal device, or a network device, etc.) to execute the method according to the embodiment of the present disclosure.
[0143] In an exemplary embodiment of the present disclosure, a computer-readable storage medium is also provided, on which a program product capable of implementing the above method of the present specification is stored. In some possible embodiments, various aspects of the present disclosure can also be implemented in the form of a program product, which includes a program code, and when the program product is run on a terminal device, the program code is used to enable the terminal device to execute the steps according to various exemplary embodiments of the present disclosure described in the above "Exemplary Method" section of the present specification.
[0144] refer to Fig.10 As shown, a program product 1000 for implementing the above-mentioned text data enhancement method according to an embodiment of the present disclosure is described, which can adopt a portable compact disk read-only memory (CD-ROM) and include program code, and can be run on a terminal device, such as a personal computer. However, the program product of the present disclosure is not limited thereto. In this document, a readable storage medium can be any tangible medium containing or storing a program, which can be used by or in combination with an instruction execution system, an apparatus or a device.
[0145] The program product may use any combination of one or more readable media. The readable medium may be a readable signal medium or a readable storage medium. The readable storage medium may be, for example, but not limited to, an electrical, magnetic, optical, electromagnetic, infrared, or semiconductor system, device or device, or any combination of the above. More specific examples (non-exhaustive list) of readable storage media include: an electrical connection with one or more wires, a portable disk, a hard disk, a random access memory (RAM), a read-only memory (ROM), an erasable programmable read-only memory (EPROM or flash memory), an optical fiber, a portable compact disk read-only memory (CD-ROM), an optical storage device, a magnetic storage device, or any suitable combination of the above.
[0146] Computer readable signal media may include data signals propagated in baseband or as part of a carrier wave, in which readable program code is carried. Such propagated data signals may take a variety of forms, including but not limited to electromagnetic signals, optical signals, or any suitable combination of the above. Readable signal media may also be any readable medium other than a readable storage medium, which may send, propagate, or transmit a program for use by or in conjunction with an instruction execution system, apparatus, or device.
[0147] The program code embodied on the readable medium may be transmitted using any appropriate medium, including but not limited to wireless, wired, optical cable, RF, etc., or any suitable combination of the foregoing.
[0148] Program code for performing the operations of the present disclosure may be written in any combination of one or more programming languages, including object-oriented programming languages such as Java, C++, etc., and conventional procedural programming languages such as "C" or similar programming languages. The program code may be executed entirely on the user computing device, partially on the user device, as a separate software package, partially on the user computing device and partially on a remote computing device, or entirely on a remote computing device or server. In cases involving a remote computing device, the remote computing device may be connected to the user computing device through any type of network, including a local area network (LAN) or a wide area network (WAN), or may be connected to an external computing device (e.g., through the Internet using an Internet service provider).
[0149] In addition, the above-mentioned figures are only schematic illustrations of the processes included in the method according to the exemplary embodiments of the present disclosure, and are not intended to be limiting. It is easy to understand that the processes shown in the above-mentioned figures do not indicate or limit the time sequence of these processes. In addition, it is also easy to understand that these processes can be performed synchronously or asynchronously, for example, in multiple modules.
[0150] Through the description of the above embodiments, it is easy for those skilled in the art to understand that the example embodiments described here can be implemented by software, or by software combined with necessary hardware. Therefore, the technical solution according to the embodiment of the present disclosure can be embodied in the form of a software product, which can be stored in a non-volatile storage medium (which can be a CD-ROM, a USB flash drive, a mobile hard disk, etc.) or on a network, and includes several instructions to enable a computing device (which can be a personal computer, a server, a touch terminal, or a network device, etc.) to execute the method according to the embodiment of the present disclosure.
[0151] Those skilled in the art will readily appreciate other embodiments of the present disclosure after considering the specification and practicing the invention disclosed herein. This application is intended to cover any variations, uses, or adaptations of the present disclosure that follow the general principles of the present disclosure and include common knowledge or customary techniques in the art that are not disclosed in the present disclosure. The specification and examples are to be considered exemplary only, and the true scope and spirit of the present disclosure are indicated by the claims.
[0152] It should be understood that the present disclosure is not limited to the exact structures that have been described above and shown in the drawings, and that various modifications and changes may be made without departing from the scope thereof. The scope of the present disclosure is limited only by the appended claims.< / ip> < / ip> < / time> < / date> < / num> < / emial> < / ip>
Claims
1. A text data enhancement method, characterized in that: include: Acquire text data, and preprocess the text data to generate a word segmentation sequence of the text data; Vectorizing the word segmentation sequence to obtain a word vector of the word segmentation sequence, and constructing an initial matrix of the text data based on the word segmentation sequence and the word vector; Based on the initial matrix, determine a target word segmentation sequence generated by performing a random word segmentation operation on the word segmentation sequence each time and a target matrix corresponding to the target word segmentation sequence, and determine a candidate word segmentation sequence corresponding to the target word segmentation sequence and a candidate matrix corresponding to the candidate word segmentation sequence; Calculating the similarity between the target matrix and the candidate matrix corresponding to each random word segmentation operation, and determining candidate words from the candidate word segmentation sequence based on the similarity, so as to screen replacement words from the candidate words, and generating enhanced text data of the text data based on the replacement words; The step of determining, based on the initial matrix, a target word segmentation sequence generated by performing a random word segmentation operation on the word segmentation sequence each time and a target matrix corresponding to the target word segmentation sequence includes: Reading a target number of random word selection operations, and performing the target number of random word selection operations on the word segmentation sequence; Each time the random word selection operation is performed on the word sequence, a first word randomly selected at that time is determined, and a window text distance of the first word is calculated based on a position of the first word in the word sequence; and A sub-segmentation sequence in the segmentation sequence that is centered on the first segmentation and satisfies the window text distance is taken as a target segmentation sequence, and a target matrix corresponding to the target segmentation sequence is generated based on the initial matrix.
2. The text data enhancement method according to claim 1, characterized in that The preprocessing of the text data to generate a word segmentation sequence of the text data includes: Performing generalization processing on the text data to determine a generalized character string of the text data; The text data is segmented based on the generalized character string to generate a segmentation sequence of the text data.
3. The text data enhancement method according to claim 1, characterized in that: The vectorizing the word segmentation sequence to obtain a word vector of the word segmentation sequence includes: A pre-built word embedding model is obtained, and text vectorization processing is performed on the word segmentation sequence based on the word embedding model to obtain word vectors of the word segmentation sequence.
4. The text data enhancement method according to claim 1, characterized in that: The method further comprises: When it is detected that the first segmented word is identical to the generalized character string, the random segmentation operation is re-executed on the segmented word sequence.
5. The text data enhancement method according to claim 1, characterized in that: The determining of a candidate word segmentation sequence corresponding to the target word segmentation sequence and a candidate matrix corresponding to the candidate word segmentation sequence includes: Randomly selecting a second participle from the participle sequence, and replacing the first participle in the target participle sequence with the second participle to obtain a candidate participle sequence; A candidate matrix matching the candidate word segmentation sequence is generated based on the initial matrix.
6. The text data enhancement method according to claim 1 or 5, characterized in that: The calculating the similarity between the target matrix and the candidate matrix corresponding to each random word segmentation operation, and determining the candidate words from the candidate word segmentation sequence based on the similarity, comprises: Normalizing the target matrix and the candidate matrix corresponding to each random word segmentation operation to obtain a normalized target matrix and a normalized candidate matrix; Calculating an average sum of similarities between the normalized target matrix and the column vectors in the normalized candidate matrix, and using the average sum as a standard similarity; A preset similarity threshold is obtained, and when it is detected that the standard similarity is greater than the similarity threshold, the second participle corresponding to the candidate matrix is used as a candidate word.
7. The text data enhancement method according to claim 1, characterized in that: The step of selecting replacement words from the candidate words and generating enhanced text data of the text data based on the replacement words includes: For all standard similarities greater than the similarity threshold, arrange them in order to obtain a standard similarity sequence; Reading a preset number of replacement words, and determining a substandard similarity sequence with a larger value matching the number of replacement words in the standard similarity sequence; The candidate words of each of the sub-standard similarity sequences are used as replacement words, and enhanced text data of the text data is generated based on the replacement words.
8. The text data enhancement method according to claim 7, characterized in that: The method further comprises: The length of the standard similarity sequence is determined, and when it is detected that the length is less than the number of replacement words, all the candidate words corresponding to the standard similarity sequence are used as the replacement words.
9. A text data enhancement device, characterized in that: include: A word segmentation sequence generation module is used to obtain text data and preprocess the text data to generate a word segmentation sequence of the text data; An initial matrix construction module, used for vectorizing the word segmentation sequence to obtain the word vector of the word segmentation sequence, and constructing the initial matrix of the text data based on the word segmentation sequence and the word vector; A random word segmentation operation module is used to determine, based on the initial matrix, a target word segmentation sequence generated by performing a random word segmentation operation on the word segmentation sequence each time and a target matrix corresponding to the target word segmentation sequence, and determine a candidate word segmentation sequence corresponding to the target word segmentation sequence and a candidate matrix corresponding to the candidate word segmentation sequence; A replacement word determination module, used for calculating the similarity between the target matrix and the candidate matrix corresponding to each random word segmentation operation, and determining candidate words from the candidate word segmentation sequence based on the similarity, so as to screen replacement words from the candidate words, and generate enhanced text data of the text data based on the replacement words; The step of determining, based on the initial matrix, a target word segmentation sequence generated by performing a random word segmentation operation on the word segmentation sequence each time and a target matrix corresponding to the target word segmentation sequence includes: Reading a target number of random word selection operations, and performing the target number of random word selection operations on the word segmentation sequence; Each time the random word selection operation is performed on the word sequence, a first word randomly selected at that time is determined, and a window text distance of the first word is calculated based on a position of the first word in the word sequence; and A sub-segmentation sequence in the segmentation sequence that is centered on the first segmentation and satisfies the window text distance is taken as a target segmentation sequence, and a target matrix corresponding to the target segmentation sequence is generated based on the initial matrix.
10. An electronic device comprising: processor; as well as A memory having computer-readable instructions stored thereon, wherein the computer-readable instructions, when executed by the processor, implement the text data enhancement method according to any one of claims 1 to 8.
11. A computer-readable storage medium having a computer program stored thereon, wherein when the computer program is executed by a processor, the text data enhancement method according to any one of claims 1 to 8 is implemented.
Citation Information
Patent Citations
Commodity information classification method based on deep feature fusion model
CN110674305A
Method and apparatus for labeling core entity, and electronic device
US20210216712A1
Training of word vector embedding model
WO2021227935A1
