Method and device for selecting training samples
By filtering the similarity and editing distance of the training samples of the text classification model, the problem of too many similar samples in the training samples is solved, and the training speed and efficiency of the model are improved.
Patent Information
- Application Number
- CN202011225075.1
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2020-11-05
- Publication Date
- 2024-11-22
- Estimated Expiration
- 2040-11-05
AI Technical Summary
During the training process of text classification model, there are a large number of similar samples in the selected training samples, which leads to the long training time of the model and affects efficiency.
By obtaining seed text and alternative text, determining their similarity and editing distance, selecting alternative text with editing distances within the preset range as training samples to ensure the diversity of training samples and reduce the number of repeated samples.
On the basis of ensuring the diversity of training samples, the number of repeated samples is reduced, and the training speed and efficiency of the model is improved.
Smart Images

Figure CN112417147B_ABST
Abstract
Description
Technical Field
[0001] The embodiments of the present application relate to the field of machine learning technology, and in particular, to a method and device for selecting training samples. Background Art
[0002] With the rapid development of artificial intelligence technology, various network models have emerged. Before using the network model for prediction, the network model needs to be trained first.
[0003] In the process of training the network model, the selection of training sample data is directly related to the accuracy and efficiency of model training. Therefore, the training sample data must not only meet the diversity to achieve accurate training of the model, but also each type of sample data should not be too much to avoid too long model training time.
[0004] Taking a text classification model as an example, when training the text classification model, there are a large number of identical samples in the selected training sample data, which leads to an excessively long training time for the model. Summary of the invention
[0005] The embodiments of the present application provide a method and device for selecting training samples, which are used to accurately obtain training samples to achieve rapid training of a model.
[0006] In a first aspect, an embodiment of the present application provides a method for selecting a training sample, comprising:
[0007] Obtaining a seed text and N candidate texts, and determining the similarity between the seed text and each of the candidate texts, wherein the candidate texts are unlabeled samples to be selected and the seed texts are labeled samples;
[0008] Selecting M first candidate texts from the N candidate texts according to the similarity between the seed text and each of the candidate texts;
[0009] Determining the edit distance between each first candidate text and the seed text;
[0010] According to the edit distance between each of the first candidate texts and the seed text, K first candidate texts whose edit distance is within a first preset range are selected from the M first candidate texts as training samples;
[0011] Wherein, N, M, and K are all positive integers greater than or equal to 1.
[0012] In a second aspect, an embodiment of the present application provides a training sample selection device, comprising:
[0013] An acquisition unit, used to acquire a seed text and N candidate texts;
[0014] A first determination unit is used to determine the similarity between the seed text and each of the candidate texts, wherein the candidate texts are unlabeled samples to be selected and the seed texts are labeled samples;
[0015] A first selection unit, configured to select M first candidate texts from the N candidate texts according to the similarity between the seed text and each of the candidate texts;
[0016] A second determining unit, configured to determine an edit distance between each first candidate text and the seed text;
[0017] A second selection unit is used to select K first candidate texts whose edit distance is within a first preset range from the M first candidate texts as training samples according to the edit distance between each of the first candidate texts and the seed text;
[0018] Wherein, N, M, and K are all positive integers greater than or equal to 1.
[0019] In a possible implementation of the second aspect, the above-mentioned first selection unit is specifically used to select the first M alternative texts with the greatest similarity from the N alternative texts as the M first alternative texts based on the similarity between the seed text and each of the alternative texts.
[0020] In a possible implementation of the second aspect, the above-mentioned first selection unit is specifically used to select, from the N alternative texts, alternative texts whose similarity is within a second preset range as the M first alternative texts based on the similarity between the seed text and each of the alternative texts.
[0021] In a possible implementation of the second aspect, the first determination unit is specifically used to determine the feature vector of the title and the feature vector of the text of the seed text, as well as the feature vector of the title and the feature vector of the text of each of the alternative texts; and determine the feature vector of the seed text based on the feature vector of the title and the feature vector of the text; and determine the feature vector of each of the alternative texts based on the feature vector of the title and the feature vector of the text; for each of the alternative texts, determine the similarity between the seed text and the alternative text based on the feature vector of the seed text and the feature vector of the text.
[0022] In a possible implementation of the second aspect, the above-mentioned first determination unit is specifically used to search for a feature vector of each word in the title of the target text and a feature vector of each word in the body of the target text from a preset word set, the target text being the seed text or the alternative text, and the word set including feature vectors corresponding to multiple words; determine the feature vector of the title of the target text according to the feature vector of each word in the title of the target text; determine the feature vector of the body of the target text according to the feature vector of each word in the body of the target text.
[0023] In a possible implementation of the second aspect, the above-mentioned first determination unit is specifically used to accumulate the feature vectors of each word in the title of the target text, normalize the accumulated feature vectors, and use the normalized feature vectors as the characteristic vector of the title of the target text.
[0024] In a possible implementation of the second aspect, the above-mentioned first determination unit is specifically used to accumulate the feature vectors of each word in the main text of the target text, normalize the accumulated feature vectors, and use the normalized feature vectors as the feature vector of the main text of the target text.
[0025] In a possible implementation manner of the second aspect, the first determining unit is specifically configured to concatenate a feature vector of the title of the seed text and a feature vector of the body of the seed text, and use the concatenated feature vector as the feature vector of the seed text.
[0026] In a possible implementation of the second aspect, the above-mentioned first determination unit is specifically used to splice the feature vector of the title of the alternative text and the feature vector of the body of the alternative text for each of the alternative texts, and use the spliced feature vector as the feature vector of the alternative text.
[0027] In a third aspect, an embodiment of the present application provides an electronic device, including a processor and a memory;
[0028] The memory is used to store computer programs;
[0029] The processor is used to execute the computer program to implement the method for selecting training samples described in the first aspect above.
[0030] In a fourth aspect, an embodiment of the present application provides a computer-readable storage medium, wherein the storage medium includes computer instructions. When the instructions are executed by a computer, the computer implements the method for selecting training samples as described in the first aspect.
[0031] In a fifth aspect, an embodiment of the present application provides a computer program product, which includes a computer program, and the computer program is stored in a readable storage medium. At least one processor of a computer can read the computer program from the readable storage medium, and the at least one processor executes the computer program so that the computer implements the method for selecting training samples described in the first aspect.
[0032] The training sample selection method and device provided in the embodiment of the present application obtain a seed text and N candidate texts, and determine the similarity between the seed text and each candidate text; then, based on the similarity between the seed text and each candidate text, first select M first candidate texts from the N candidate texts, and determine the edit distance between each first candidate text and the seed text; then, based on the edit distance between each first candidate text and the seed text, select K first candidate texts with corresponding edit distances within a first preset range from the M first candidate texts as training sample data for the model, thereby reducing the number of repeated samples while ensuring the diversity of training samples, so that when the training samples are used to train the model, the training speed of the model can be improved. BRIEF DESCRIPTION OF THE DRAWINGS
[0033] The accompanying drawings, which are incorporated in and constitute a part of this specification, illustrate embodiments consistent with the present application and, together with the description, serve to explain the principles of the present application.
[0034] Figure 1 A schematic diagram of an application scenario involved in an embodiment of the present application;
[0035] Figure 2 A flowchart of a method for selecting training samples provided in an embodiment of the present application;
[0036] Figure 3 A flowchart of a method for selecting training samples provided in another embodiment of the present application;
[0037] Figure 4 A schematic diagram of a method for selecting training samples involved in an embodiment of the present application;
[0038] Figure 5 A flowchart of a method for selecting training samples provided in another embodiment of the present application;
[0039] Figure 6 A schematic diagram of the structure of a training sample selection device provided in an embodiment of the present application;
[0040] Figure 7 This is a block diagram of an electronic device involved in an embodiment of the present application. DETAILED DESCRIPTION
[0041] The technical solutions in the embodiments of the present application will be described below in conjunction with the drawings in the embodiments of the present application.
[0042] It should be understood that in the embodiment of the present invention, "B corresponding to A" means that B is associated with A. In one implementation, B can be determined based on A. However, it should also be understood that determining B based on A does not mean determining B based only on A, and B can also be determined based on A and / or other information.
[0043] In the description of the present application, unless otherwise specified, “plurality” means two or more than two.
[0044] In addition, in order to clearly describe the technical solutions of the embodiments of the present application, in the embodiments of the present application, words such as "first" and "second" are used to distinguish the same items or similar items with substantially the same functions and effects. Those skilled in the art can understand that words such as "first" and "second" do not limit the quantity and execution order, and words such as "first" and "second" do not necessarily limit the difference.
[0045] The embodiments of the present application are applied to the field of machine learning technology to obtain accurate training samples to achieve rapid training of the model.
[0046] In order to facilitate understanding of the embodiments of the present application, the relevant concepts involved in the embodiments of the present application are briefly introduced as follows:
[0047] Machine Learning (ML) is a multi-disciplinary subject that involves probability theory, statistics, approximation theory, convex analysis, algorithm complexity theory and other disciplines. It specializes in studying how computers simulate or implement human learning behavior to acquire new knowledge or skills and reorganize existing knowledge structures to continuously improve their performance. Machine learning is the core of artificial intelligence and the fundamental way to make computers intelligent. Its applications are spread across all areas of artificial intelligence. Machine learning and deep learning usually include artificial neural networks, belief networks, reinforcement learning, transfer learning, inductive learning, and self-learning.
[0048] Supervised training is to train an optimal model through existing training samples (that is, known data and its corresponding outputs) (this model belongs to a set of functions, and optimal means it is the best under a certain evaluation criterion), and then use this model to map all inputs to corresponding outputs, make simple judgments on the outputs to achieve the purpose of classification, and thus have the ability to classify unknown data.
[0049] Unsupervised training (or unsupervised training) is different from supervised training in that there are no training samples in advance, but the data is directly modeled. A typical example of unsupervised training is clustering. The embodiment of the present application only annotates a few seed texts, and other candidate texts are not annotated. Therefore, the model training involved in the embodiment of the present application can be understood as unsupervised training.
[0050] word2vec (word to vector) means that a word is represented by a vector. The word2vec tool mainly includes two models: skip-gram model and continuous bag of words (CBOW) model, as well as two efficient training methods: negative sampling and hierarchical softmax. word2vec word vectors can better express the similarity and analogy between different words. word2vec is a natural language processing (NLP) tool that can vectorize all words, so that the relationship between words can be quantitatively measured and the connection between words can be mined.
[0051] Edit distance, also known as Levenshtein distance, refers to the minimum number of edit operations required to convert two strings from one to another. Permitted edit operations include replacing one character with another, inserting a character, and deleting a character.
[0052] Figure 1 This is a schematic diagram of an application scenario involved in an embodiment of the present application, including: a user device 101, a data acquisition device 102, a training device 103, an execution device 104, a database 105 and a content library 106.
[0053] The user device 101 is used to receive the user's annotation operation on the seed sample, and send the annotated seed text to the database 105.
[0054] The data collection device 102 is used to select candidate texts that meet the requirements from the content library 106 according to the method of the embodiment of the present application, and store the selected candidate texts in the data volume. Among them, the training samples in the database 105 include a first sample set and a second sample set, wherein the first sample set includes multiple seed texts corresponding to each type of different types, and each seed text is a marked text. The second sample set is a plurality of candidate texts obtained from the content library 106 by the data collection device 102.
[0055] The training device 103 trains the text classification model based on the training samples maintained in the database 105, so that the trained text classification model can identify the category of the text. The text classification model obtained by the training device 103 can be applied to different systems or devices.
[0056] In the attached Figure 1 In the embodiment, the execution device 104 is configured with an I / O interface 107 to exchange data with external devices. For example, the text to be classified sent by the user device 101 is received through the I / O interface. The calculation module 109 in the execution device 104 uses the text classification model to process the input text to be classified, specifically, the text to be classified is input into the text classification model for classification to obtain the type corresponding to the text to be classified, and the type corresponding to the text to be classified is sent to the user device 101 through the I / O interface.
[0057] It is worth noting that Figure 1 It is only a schematic diagram of an application scenario provided by an embodiment of the present application. The positional relationship between the devices, components, modules, etc. shown in the figure does not constitute any limitation. In some embodiments, the data acquisition device 102 and the user device 101, the training device 103 and the execution device 104 can be the same device. The database 105 can be distributed on one server or on multiple servers, and the content library 106 can be distributed on one server or on multiple servers.
[0058] The method of the embodiment of the present application can be applied to the training process of various text classification models, and the text classification model can be applied to information flow platforms (such as reading platform 1, reading platform 2, etc.) to classify texts on the information flow platforms. At present, in the training process of the text classification model, there are a large number of identical samples in the selected training samples, which leads to a long training time for the model.
[0059] In order to solve the above technical problems, an embodiment of the present application provides a method for selecting training samples, by obtaining a seed text and N alternative texts, and determining the similarity between the seed text and each alternative text; then, based on the similarity between the seed text and each alternative text, firstly, M first alternative texts are selected from the N alternative texts, and the edit distance between each first alternative text and the seed text is determined; then, based on the edit distance between each first alternative text and the seed text, K first alternative texts with an edit distance within a first preset range are selected from the M first alternative texts as training samples for the model, thereby reducing the number of repeated samples while ensuring the diversity of the training samples, so that when the training samples are used to train the model, the training speed of the model can be improved.
[0060] The technical solutions of the embodiments of the present application are described in detail below through some embodiments. The following embodiments can be combined with each other, and the same or similar concepts or processes may not be repeated in some embodiments.
[0061] Figure 2 A flowchart of a method for selecting training samples provided in an embodiment of the present application. The execution subject of the embodiment of the present application is a device having a function of selecting training samples of a model, such as a device for selecting training samples, hereinafter referred to as a selection device. In some embodiments, the selection device is Figure 1 In some embodiments, the selection device is a unit in the data acquisition device having a data processing function, such as a processor in the data processing device. Figure 2 As shown, the method of the embodiment of the present application includes:
[0062] S201, obtaining a seed text and N candidate texts, and determining the similarity between the seed text and each candidate text.
[0063] The above N is a positive integer greater than or equal to 1.
[0064] The above seed text is a sample that has been annotated. Taking the above model as a text classification model as an example, the text classification model can classify texts on information flow platforms (such as reading platform 1, reading platform 2, etc.), and determine whether the type of text on the information flow platform is sports, entertainment, or military, etc. The type of the above seed text has been annotated by the user. It should be noted that if the above text classification model can identify P types of texts, multiple seed texts of each type can be obtained during the training process. For each seed text, the method of the embodiment of the present application is used to obtain the K first candidate texts corresponding to the seed text from the content library. Since the process of selecting the K first candidate texts corresponding to each seed text is consistent, the embodiment of the present application is explained by selecting the K first candidate texts corresponding to a seed text as an example. It should be noted that the method of the embodiment of the present application can be applied to other text processing models in addition to the text classification model, such as in the text recommendation model.
[0065] The above alternative texts are unlabeled samples to be selected. For details, Figure 1 As shown, the candidate texts are texts in a content library, where the content library includes various types of texts.
[0066] In the embodiment of the present application, the seed text may be input by a user, and the alternative texts may be stored in a content library, so the selection device may obtain the alternative texts from the content library.
[0067] After the selection device obtains the seed text and N candidate texts, the existing methods, such as the space vector method, the cosine distance method or the local Hash function, can be used to determine the similarity between the seed text and each candidate text. Among them, the process of using the space vector method to determine the text similarity is to segment the text and calculate the term frequency-inverse document frequency (Term Frequency-Inverse Document Frequency, TF-IDF) value of each word, where TF is the term frequency, that is, the ratio of the number of times a word appears in the text to the total number of words included in the text. IDF is the inverse text frequency, which can be determined specifically according to the total number of texts and the number of texts in which the word appears. In this way, the TF-IDF value of each word in the text can be obtained, and the TF-IDF value of each word in the text is composed of a space vector as the space vector of the text. Then, the similarity between the two texts can be determined by determining the spatial distance between the space vectors of the two texts. The smaller the spatial distance, the more similar the two texts are. Among them, the method of using the cosine distance method to determine the text similarity is to use the cosine distance of the space vectors of the two texts obtained by the above-mentioned space vector method to determine the similarity between the two texts. Among them, the method of using the local hash function method to determine the text similarity is to use a hash function to convert the spatial vector of the above text into a point in the N-dimensional space, so that the similarity between the two texts is determined according to the distance between the points corresponding to the two texts. The specific implementation process of any of the above methods for determining text similarity can refer to the specific description of the existing technology, which will not be repeated here.
[0068] In some embodiments, the following Figure 3 The method shown determines the similarity between the seed text and each candidate text, see Figure 3 Description of the illustrated embodiment.
[0069] S202: Select M first candidate texts from the N candidate texts according to the similarity between the seed text and each candidate text.
[0070] In the embodiment of the present application, according to the similarity between the seed text and each candidate text, the method of selecting M first candidate texts from N candidate texts includes but is not limited to the following:
[0071] Method 1: According to the similarity between the seed text and each candidate text, the first M candidate texts with the greatest similarity are selected from the N candidate texts as the first candidate texts of the M texts.
[0072] In one example, after obtaining the similarity between the seed text and each candidate text according to the method in S201 above, the similarities are sorted from large to small according to the magnitude of the similarities, as shown in Table 1:
[0073] Table 1
[0074]
[0075]
[0076] It should be noted that Table 1 shows that the similarities between the seed text and the candidate text are sorted from large to small according to the size of the similarities. Optionally, the similarities can also be sorted from small to large according to the size of the similarities.
[0077] Referring to Table 1, from the N candidate texts, the first M candidate texts with the greatest similarity are selected as the M first candidate texts.
[0078] Method 2: According to the similarity between the seed text and each candidate text, the candidate text with a similarity within a second preset range is selected from the N candidate texts as the M first candidate texts.
[0079] The above-mentioned second preset range can be set according to actual needs, and the embodiment of the present application does not impose any specific limitation on this.
[0080] Continuing to refer to Table 1, select the candidate texts whose similarities are within the second preset range from the N candidate texts as the first candidate texts of the M articles. Assume that the similarities in Table 1 are sorted from large to small to form Set 1: {0.99, 0.98, 0.96, 0.95, ..., 0.7, 0.6}, and assume that the second preset range is 0.96 to 0.65. In this way, select the similarities within the second preset range from Set 1 to obtain Set 2: {0.96, 0.95, ..., 0.7}, and use the candidate texts corresponding to the similarities in Set 2 as the first candidate texts.
[0081] S203: Determine the edit distance between each first candidate text and the seed text.
[0082] Among the M first candidate texts, the editing distance between each first candidate text and the seed text is determined in the same way. Here, one first candidate text is taken as an example.
[0083] As can be seen from the above, the edit distance refers to the minimum number of operations required to convert one string into another. The operations include the following three types: adding a character, deleting a character, and modifying a character.
[0084] Specifically, the first candidate text is taken as string A, whose length is LA, and the seed text is taken as string B, whose length is LB. The existing method of calculating the edit distance between two strings is used to determine the edit distance between string A and string B, and then the edit distance between the seed text and the first candidate text is obtained.
[0085] In one example, the edit distance between string A and string B can be obtained with reference to the following dynamic formula (1):
[0086] If i == 0 and j == 0, edit(i, j) = 0;
[0087] If i == 0 and j > 0, edit(i, j) = j;
[0088] If i > 0 and j == 0, edit(i, j) = 1;
[0089] If 0 < i ≤ 1 and 0 < j ≤ 1, edit(i, j) == min{edit(i - 1, j) + 1, edit(i, j - 1) + 1, edit(i - 1, j - 1) + f(i, j)},
[0090] where edit(i, j) represents the edit distance from the substring of length i of the first string A to the substring of length j of the second string B. When the i-th character of the first string is not equal to the j-th character of the second string, f(i, j) = 1; otherwise, f(i, j) = 0.
[0091] The smaller the edit distance, the higher the similarity between the two texts. In this way, the edit distance between each first alternative text and the seed text can be obtained, and they are sorted from largest to smallest according to the edit distance as shown in Table 2:
[0092] Table 2
[0093]
[0094] It should be noted that Table 2 shows the sorting of the edit distances from largest to smallest according to the magnitudes of the edit distances between the seed text and the first alternative texts. Optionally, the edit distances can also be sorted from smallest to largest according to their magnitudes.
[0095] S204. Select K first alternative texts with edit distances within a first preset range from the M first alternative texts as the training sample data of the model according to the edit distances between each first alternative text and the seed text.
[0096] The above first preset range can be determined according to actual needs, and the embodiments of the present application do not limit this.
[0097] Specifically, referring to Table 2 above, according to the size of the edit distance, K first candidate texts whose edit distance is within the first preset range are selected from the M first candidate texts, and these K first candidate texts are used as training samples of the model. In this way, the first candidate files that are basically the same as the seed text in the M first candidate files can be eliminated, and the remaining K first candidate files whose edit distance with the seed text meets the first preset range are used as training samples of the model, which can reduce the repeated samples in the training samples, thereby improving the training speed of the model.
[0098] Optionally, the first preset range is greater than 30, that is, the first candidate texts whose edit distance with the seed text is greater than 30 are selected from the M first candidate texts as training samples of the model.
[0099] An embodiment of the present application provides a method for selecting training samples, which obtains a seed text and N candidate texts, and determines the similarity between the seed text and each candidate text; then, based on the similarity between the seed text and each candidate text, first selects M first candidate texts from the N candidate texts, and determines the edit distance between each first candidate text and the seed text; then, based on the edit distance between each first candidate text and the seed text, selects K first candidate texts whose corresponding edit distance is within a first preset range from the M first candidate texts as training sample data for the model, thereby reducing the number of repeated samples while ensuring the diversity of the training samples, so that when the training samples are used to train the model, the training speed of the model can be improved.
[0100] Based on the above embodiments, Figure 3 and Figure 4 The specific process of determining the similarity between the seed text and each candidate text in the above S201 is described in detail.
[0101] like Figure 4 As shown, the text includes a title and a body. The feature vector of the title and the feature vector of the body can be obtained, and the feature vector of the text can be finally obtained according to the feature vector of the title and the feature vector of the body. The specific implementation process is referred to Figure 3 The embodiment shown.
[0102] Figure 3 A flowchart of a method for selecting training samples provided in another embodiment of the present application is shown as follows: Figure 3 As shown, the above S201 may include:
[0103] S301: Determine a feature vector of the title and a feature vector of the text of the seed text, and a feature vector of the title and a feature vector of the text of each candidate text.
[0104] Specifically, for the seed text, a word segmentation tool is used to segment the title of the seed text, and the body of the seed text is segmented at the same time. A text feature vectorization method, such as TF-IDF encoding or one-hot encoding, is used to obtain a feature vector of the title of the seed text and a feature vector of the seed text.
[0105] In some embodiments, the embodiments of the present application may also adopt Figure 5 The method shown in the figure determines the feature vector of the title and the feature vector of the text of the seed text, as well as the feature vector of the title and the feature vector of the text of each candidate text, that is, the above S301 includes:
[0106] S3011. Searching for a feature vector of each word in the title of the target text and a feature vector of each word in the body of the target text from a preset word set.
[0107] The target text mentioned above is a seed text or an alternative text, and the word set includes feature vectors corresponding to a plurality of words.
[0108] It should be noted that the preset word set is pre-trained and includes feature vectors corresponding to multiple words. Assume that the size of the preset word set is 2 million and the dimension is 100. In other words, the preset word set includes 2 million words, each word is represented by a 100-dimensional vector, so it can be understood that the predicted word set is a matrix of 2 million rows and 100 columns, and each row of the matrix represents the feature vector of a word.
[0109] Optionally, the above-mentioned preset word set may be a word2vec word set, that is, the feature vector of each word in the word set is a word2vec vector.
[0110] S3012. Determine a feature vector of the title of the target text according to the feature vector of each word in the title of the target text.
[0111] When the target text is a seed text, the feature vector of the title of the seed text can be determined in the following ways:
[0112] Method 1: accumulate the feature vectors of each word in the title of the seed text, and use the accumulated feature vector A as the feature vector of the title of the seed text. For example, assuming that the seed text includes 10 words, and the feature vector of each word is 100-dimensional, these 10 100-dimensional feature vectors are accumulated, specifically, the first bit of the feature vector of each word in the title is added together as the first bit of feature vector A, the second bit of the feature vector of each word in the title is added together as the second bit of feature vector A, and so on, the 100th bit of the feature vector of each word in the title is added together as the 100th bit of feature vector A, and then a 100-dimensional feature vector A is obtained, and the feature vector A is used as the feature vector of the title of the seed text.
[0113] Method 2: Accumulate the feature vectors of each word in the title of the seed text, normalize the accumulated feature vectors, and use the normalized feature vectors as the feature vector of the title of the seed text.
[0114] For example, suppose the seed text includes two words, the first word and the second word, and the feature vector of the first word is {a1, a2, a3, ..., a100}, and the feature vector of the second word is {b1, b2, b3, ..., b100}. Adding these two 100-dimensional feature vectors, the resulting feature vector is {a1+b1, a2+b2, a3+b3, ..., a100+b100}. Next, the feature vector {a1+b1, a2+b2, a3+b3, ..., a100+b100} is normalized. Specifically, the feature vector {a1+b1, a2+b2, a3+b3, ..., a100+b100} is traversed to obtain the maximum value (assuming a3+b3) and the minimum value (assuming a1+b1) in the feature vector, the maximum value is set to 1, the minimum value is set to 0, and the other values in the feature vector are normalized based on the following formula (2):
[0115]
[0116] Wherein, xi is the i-th value in the feature vector, Max is the maximum value in the feature vector, Min is the minimum value in the feature vector, and xin is the normalized value of xi. It should be noted that the above formula (2) is only an example of a specific normalization, and the normalization method of the embodiment of the present application includes but is not limited to the above formula (2).
[0117] Similarly, when the target text is an alternative text, the feature vector of the title of the alternative text can be determined in the following ways:
[0118] Method 1: accumulate the feature vectors of each word in the title of the candidate text, and use the accumulated feature vector B as the feature vector of the title of the candidate text. For example, assuming that the candidate text includes 15 words, and the feature vector of each word is 100-dimensional, these 15 100-dimensional feature vectors are accumulated, specifically, the first bit of the feature vector of each word in the title is added as the first bit of feature vector B, the second bit of the feature vector of each word in the title is added as the second bit of feature vector B, and so on, the 100th bit of the feature vector of each word in the title is added as the 100th bit of feature vector B, and then a 100-dimensional feature vector B is obtained, and the feature vector B is used as the feature vector of the title of the candidate text.
[0119] Method 2: accumulate the feature vectors of each word in the title of the candidate text, normalize the accumulated feature vector B, and use the normalized feature vector B1 as the feature vector of the title of the candidate text. Continuing with the example in method 1, assume that the title of the candidate text includes 15 words, and the feature vector of each word is 100-dimensional. These 15 100-dimensional feature vectors are accumulated to obtain the feature vector B. Next, referring to the above formula (2), the 100-dimensional feature vector B is normalized to obtain the feature vector B1, and the normalized feature vector B1 is used as the feature vector of the title of the candidate text.
[0120] S3013. Determine a feature vector of the main body of the target text according to the feature vector of each word in the main body of the target text.
[0121] When the target text is a seed text, the methods for determining the feature vector of the body of the seed text include but are not limited to the following:
[0122] Method 1: accumulate the feature vectors of each word in the body of the seed text to obtain the accumulated feature vector D, and use the accumulated feature vector D as the feature vector of the body of the seed text. For example, assuming that the seed text includes 1,000 words, and the feature vector of each word is 100-dimensional, these 1,000 100-dimensional feature vectors are accumulated, specifically, the first bit of the feature vector of each word in the body is added together as the first bit of the feature vector D, the second bit of the feature vector of each word in the body is added together as the second bit of the feature vector D, and so on, the 100th bit of the feature vector of each word in the body is added together as the 100th bit of the feature vector D, and then a 100-dimensional feature vector D is obtained, and the feature vector D is used as the feature vector of the body of the seed text.
[0123] Method 2: The feature vectors of each word in the body of the seed text are accumulated, and the accumulated feature vector D is normalized, and the normalized feature vector D1 is used as the feature vector of the body of the seed text. Continuing with the example in method 1, assuming that the body of the seed text includes 1000 words, and the feature vector of each word is 100-dimensional, these 1000 100-dimensional feature vectors are accumulated to obtain the feature vector D. Next, referring to the above formula (2), the 100-dimensional feature vector D is normalized to obtain the feature vector D1, and the normalized feature vector D1 is used as the feature vector of the title of the candidate text.
[0124] Similarly, when the target text is an alternative text, the methods for determining the feature vector of the main text of the alternative text include but are not limited to the following:
[0125] Method 1: accumulate the feature vectors of each word in the body of the candidate text to obtain the accumulated feature vector E, and use the accumulated feature vector E as the feature vector of the body of the candidate text. For example, assuming that the candidate text includes 1500 words, and the feature vector of each word is 100-dimensional, these 1500 100-dimensional feature vectors are accumulated, specifically, the first bit of the feature vector of each word in the body is added as the first bit of the feature vector E, the second bit of the feature vector of each word in the body is added as the second bit of the feature vector E, and so on, the 100th bit of the feature vector of each word in the body is added as the 100th bit of the feature vector E, and then a 100-dimensional feature vector E is obtained, and the feature vector E is used as the feature vector of the body of the candidate text.
[0126] Method 2, accumulate the feature vectors of each word in the body of the candidate text, normalize the accumulated feature vector E, and use the normalized feature vector E1 as the feature vector of the body of the candidate text. Continuing with the example in method 1, assume that the body of the candidate text includes 1500 words, and the feature vector of each word is 100-dimensional. These 1500 100-dimensional feature vectors are accumulated to obtain the feature vector E. Next, referring to the above formula (2), the 100-dimensional feature vector E is normalized to obtain the feature vector E1, and the normalized feature vector E1 is used as the feature vector of the title of the candidate text.
[0127] S302: Determine a feature vector of the seed text according to a feature vector of the title and a feature vector of the body of the seed text.
[0128] In the embodiment of the present application, referring to the above S301 method, the feature vector of the title of the seed text and the feature vector of the body of the seed text can be determined. Then, the feature vector of the seed text can be determined based on the feature vector of the title of the seed text and the feature vector of the body of the seed text.
[0129] In some embodiments, the feature vector of the title of the seed text is accumulated with the feature vector of the text, and the accumulated feature vector is used as the feature vector of the seed text. For example, referring to the example in S301 above, it is assumed that the feature vector of the title of the seed text is a 100-dimensional feature vector A, and the feature vector of the text of the seed text is a 100-dimensional feature vector D. The feature vector A is accumulated with the feature vector D to obtain a 100-dimensional feature vector F, and the feature vector F is used as the feature vector of the seed text.
[0130] In some embodiments, the feature vector of the title of the seed text and the feature vector of the body of the seed text are spliced, and the spliced feature vector is used as the feature vector of the seed text. Continuing to refer to the example in S301 above, assuming that the feature vector of the title of the seed text is a 100-dimensional feature vector A, and the feature vector of the body of the seed text is a 100-dimensional feature vector D, the 100-dimensional feature vector A and the 100-dimensional feature vector D are spliced to obtain a 200-dimensional feature vector F1, and the feature vector F1 is used as the feature vector of the seed text. It should be noted that when splicing, the feature vector A can be located in front of the feature vector D, or the feature vector A can be located behind the feature vector D, and the embodiments of the present application do not limit this.
[0131] S303: Determine a feature vector of each candidate text according to the feature vector of the title and the feature vector of the text of each candidate text.
[0132] The process of determining the feature vector of each candidate text in the embodiments of the present application is basically the same. For the sake of ease of explanation, the process of determining a candidate text is described as an example.
[0133] In the embodiment of the present application, the process of determining the feature vector of the candidate text is similar to the process of determining the feature vector of the seed text. Referring to the method of determining the feature vector of the seed text in S302 above, the method of determining the candidate text in this step may also include at least the following:
[0134] Method 1: Accumulate the feature vector of the title of the candidate text and the feature vector of the text, and use the accumulated feature vector as the feature vector of the candidate text. For example, referring to the example in S301 above, assume that the feature vector of the title of the candidate text is a 100-dimensional feature vector B, and the feature vector of the text of the candidate text is a 100-dimensional feature vector E. Accumulate the feature vector B and the feature vector E to obtain a 100-dimensional feature vector G, and use the feature vector G as the feature vector of the candidate text.
[0135] In some embodiments, the feature vector of the title of the alternative text and the feature vector of the body of the alternative text are spliced, and the spliced feature vector is used as the feature vector of the alternative text. Continuing to refer to the example in S301 above, assuming that the feature vector of the title of the alternative text is a 100-dimensional feature vector B, and the feature vector of the body of the alternative text is a 100-dimensional feature vector E, the 100-dimensional feature vector B is spliced with the 100-dimensional feature vector E to obtain a 200-dimensional feature vector G1, and the feature vector G1 is used as the feature vector of the alternative text. It should be noted that when splicing, the feature vector B can be located in front of the feature vector E, or the feature vector B can be located behind the feature vector E, and the embodiments of the present application do not limit this.
[0136] S304: For each candidate text, determine the similarity between the seed text and the candidate text according to the feature vector of the seed text and the feature vector of the candidate text.
[0137] Specifically, according to the above step S303, the feature vector of the seed text and the feature vector of each candidate text are determined. For each candidate text, the similarity between the seed text and each candidate text is determined based on the feature vector of the seed text and the feature vector of the candidate text.
[0138] The methods for determining the similarity between the seed text and the candidate text based on the feature vector of the seed text and the feature vector of the candidate text include but are not limited to the following:
[0139] Method 1: Calculate the Euclidean distance between the feature vector of the seed text and the feature vector of the candidate text, and use the Euclidean distance as the similarity between the seed text and the candidate text. The smaller the Euclidean distance, the more similar the seed text is to the candidate text.
[0140] Method 2: Calculate the cosine distance between the feature vector of the seed text and the feature vector of the candidate text, and use the cosine distance as the similarity between the seed text and the candidate text. The closer the cosine distance is to 1, the more similar the seed text is to the candidate text.
[0141] The method of the embodiment of the present application determines the feature vector of the title and the feature vector of the text of the seed text, as well as the feature vector of the title and the feature vector of the text of each alternative text; determines the feature vector of the seed text according to the feature vector of the title and the feature vector of the text of the seed text; and determines the feature vector of each alternative text according to the feature vector of the title and the feature vector of the text of each alternative text; for each alternative text, accurately determines the similarity between the seed text and the alternative text according to the feature vector of the seed text and the feature vector of the alternative text, so that based on the accurately determined similarity between the seed text and the alternative text, when the alternative files are screened, the accuracy of screening the alternative files can be improved.
[0142] Figure 6 A schematic diagram of a structure of a training sample selection device provided in an embodiment of the present application. The selection device may be an electronic device or a component of an electronic device (eg, an integrated circuit, a chip, etc.). The electronic device may be Figure 1 The data acquisition equipment shown. Figure 6 As shown, the selection device 300 may include: an acquisition unit 310, a first determination unit 320, a second determination unit 330, a first selection unit 340 and a second selection unit 350.
[0143] An acquisition unit 310 is used to acquire a seed text and N candidate texts;
[0144] A first determination unit 320 is used to determine the similarity between the seed text and each of the candidate texts, wherein the candidate texts are unlabeled samples to be selected and the seed texts are labeled samples;
[0145] A first selection unit 340 is used to select M first candidate texts from the N candidate texts according to the similarity between the seed text and each of the candidate texts;
[0146] A second determining unit 330 is used to determine the edit distance between each first candidate text and the seed text;
[0147] A second selection unit 350 is used to select K first candidate texts whose edit distance is within a first preset range from the M first candidate texts as training samples according to the edit distance between each of the first candidate texts and the seed text;
[0148] Wherein, N, M, and K are all positive integers greater than or equal to 1.
[0149] In a possible implementation, the first selection unit 340 is specifically configured to select the first M candidate texts with the greatest similarity from the N candidate texts as the M first candidate texts based on the similarity between the seed text and each of the candidate texts.
[0150] In a possible implementation, the first selection unit 340 is specifically configured to select, based on the similarity between the seed text and each of the candidate texts, candidate texts with similarities within a second preset range from the N candidate texts as the M first candidate texts.
[0151] In a possible implementation, the first determination unit 320 is specifically used to determine the feature vector of the title and the feature vector of the text of the seed text, as well as the feature vector of the title and the feature vector of the text of each of the alternative texts; and determine the feature vector of the seed text based on the feature vector of the title and the feature vector of the text of the seed text; and determine the feature vector of each of the alternative texts based on the feature vector of the title and the feature vector of the text of each of the alternative texts; for each of the alternative texts, determine the similarity between the seed text and the alternative text based on the feature vector of the seed text and the feature vector of the text.
[0152] In a possible implementation, the first determination unit 320 is specifically used to search for a feature vector of each word in the title of a target text and a feature vector of each word in the body of the target text from a preset word set, wherein the target text is the seed text or the alternative text, and the word set includes feature vectors corresponding to a plurality of words; determine the feature vector of the title of the target text according to the feature vector of each word in the title of the target text; determine the feature vector of the body of the target text according to the feature vector of each word in the body of the target text.
[0153] In a possible implementation, the first determination unit 320 is specifically used to accumulate the feature vectors of each word in the title of the target text, normalize the accumulated feature vectors, and use the normalized feature vectors as the characteristic vector of the title of the target text.
[0154] In a possible implementation, the first determination unit 320 is specifically used to accumulate the feature vectors of each word in the body of the target text, normalize the accumulated feature vectors, and use the normalized feature vectors as the feature vectors of the body of the target text.
[0155] In a possible implementation, the first determining unit 320 is specifically configured to concatenate the feature vector of the title of the seed text with the feature vector of the body of the seed text, and use the concatenated feature vector as the feature vector of the seed text.
[0156] In a possible implementation, the first determination unit 320 is specifically configured to concatenate, for each of the alternative texts, a feature vector of the title of the alternative text and a feature vector of the body of the alternative text, and use the concatenated feature vector as the feature vector of the alternative text.
[0157] The training sample selection device of the embodiment of the present application can be used to execute the technical solutions of the above-mentioned method embodiments. Its implementation principles and technical effects are similar and will not be repeated here.
[0158] Figure 7 is a block diagram of an electronic device involved in an embodiment of the present application, and the device may be Figure 1 The data acquisition device shown is used to execute the method for selecting training samples described in the above embodiment. For details, please refer to the description in the above method embodiment.
[0159] Figure 7 The electronic device 200 shown includes a memory 201, a processor 202, and a communication interface 203. The memory 201, the processor 202, and the communication interface 203 are connected to each other in communication. For example, the memory 201, the processor 202, and the communication interface 203 can be connected to each other in communication by a network connection. Alternatively, the electronic device 200 may further include a bus 204. The memory 201, the processor 202, and the communication interface 203 are connected to each other in communication via the bus 204. Figure 7 The electronic device 200 is a memory 201 , a processor 202 , and a communication interface 203 that are communicatively connected to each other via a bus 204 .
[0160] The memory 201 may be a read-only memory (ROM), a static storage device, a dynamic storage device or a random access memory (RAM). The memory 201 may store a program. When the program stored in the memory 201 is executed by the processor 202, the processor 202 and the communication interface 203 are used to execute the above selection method.
[0161] The processor 202 may be a general-purpose central processing unit (CPU), a microprocessor, an application specific integrated circuit (ASIC), a graphics processing unit (GPU), or one or more integrated circuits.
[0162] The processor 202 may also be an integrated circuit chip with signal processing capabilities. In the implementation process, the selection method of the present application may be completed by an integrated logic circuit of hardware in the processor 202 or an instruction in the form of software. The above-mentioned processor 202 may also be a general-purpose processor, a digital signal processor (digital signal processing, DSP), an application-specific integrated circuit (ASIC), a field programmable gate array (field programmable gate array, FPGA) or other programmable logic devices, discrete gates or transistor logic devices, discrete hardware components. The general-purpose processor may be a microprocessor or the processor may also be any conventional processor, etc. The software module may be located in a mature storage medium in the field such as a random access memory, a flash memory, a read-only memory, a programmable read-only memory or an electrically erasable programmable memory, a register, etc. The storage medium is located in the memory 201, and the processor 202 reads the information in the memory 201, and completes the selection method of the embodiment of the present application in combination with its hardware.
[0163] The communication interface 203 uses a transceiver module such as, but not limited to, a transceiver to implement communication between the electronic device 200 and other devices or a communication network. For example, a data set can be acquired through the communication interface 203 .
[0164] When the electronic device 200 includes the bus 204 , the bus 204 may include a path for transmitting information between various components of the electronic device 200 (eg, the memory 201 , the processor 202 , and the communication interface 203 ).
[0165] In the above embodiments, it can be implemented in whole or in part by software, hardware, firmware or any combination thereof. When implemented using software, it can be implemented in whole or in part in the form of a computer program product. The computer program product includes one or more computer instructions. When the computer program instructions are loaded and executed on a computer, the process or function described in the embodiment of the present application is generated in whole or in part. The computer may be a general-purpose computer, a special-purpose computer, a computer network, or other programmable device. The computer instructions may be stored in a computer-readable storage medium, or transmitted from one computer-readable storage medium to another computer-readable storage medium, for example, the computer instructions may be transmitted from a website site, computer, server or data center by wired (e.g., coaxial cable, optical fiber, digital subscriber line (DSL)) or wireless (e.g., infrared, wireless, microwave, etc.) mode to another website site, computer, server or data center. The computer-readable storage medium may be any available medium that a computer can access or a data storage device such as a server or data center that includes one or more available media integrated. The available medium may be a magnetic medium, (e.g., a floppy disk, a hard disk, a tape), an optical medium (e.g., a DVD), or a semiconductor medium (e.g., a solid-state drive Solid State Disk (SSD)), etc.
[0166] Those skilled in the art can clearly understand that, for the convenience and simplicity of description, the specific working processes of the systems, devices and units described above can refer to the corresponding processes in the aforementioned method embodiments, and will not be repeated here. In addition, the various method embodiments and the various device embodiments can also refer to each other, and the same or corresponding contents in different embodiments can be quoted from each other without repeated description.
Claims
1. A method for selecting training samples, characterized in that: include: Obtaining a seed text and N candidate texts, and determining the similarity between the seed text and each of the candidate texts, wherein the candidate texts are unlabeled samples to be selected and the seed texts are labeled samples; Selecting M first candidate texts from the N candidate texts according to the similarity between the seed text and each of the candidate texts; For each first candidate text, taking the first candidate text as a first string and the seed text as a second string, determining the minimum number of operations required to convert the first string into the second string as the edit distance between the first candidate text and the seed text; According to the edit distance between each of the first candidate texts and the seed text, K first candidate texts whose edit distance is greater than a preset value are selected from the M first candidate texts as training samples, wherein the K first candidate texts are first candidate texts that are different from the seed text among the M first candidate texts, and the smaller the edit distance is, the higher the similarity between the two texts is, and N, M, and K are all positive integers greater than or equal to 1; Wherein, determining the similarity between the seed text and each of the candidate texts includes: Determine a feature vector of the title and a feature vector of the text of the seed text, and a feature vector of the title and a feature vector of the text of each candidate text; Determine a feature vector of the seed text according to a feature vector of the title and a feature vector of the body of the seed text; Determine a feature vector of each candidate text according to a feature vector of a title and a feature vector of a body of each candidate text; For each of the candidate texts, the similarity between the seed text and the candidate text is determined according to the feature vector of the seed text and the feature vector of the candidate text.
2. The method according to claim 1, characterized in that The step of selecting M first candidate texts from the N candidate texts according to the similarity between the seed text and each candidate text comprises: According to the similarity between the seed text and each of the candidate texts, the first M candidate texts with the greatest similarity are selected from the N candidate texts as the M first candidate texts.
3. The method according to claim 1, characterized in that The step of selecting M first candidate texts from the N candidate texts according to the similarity between the seed text and each candidate text comprises: According to the similarity between the seed text and each of the candidate texts, the candidate texts whose similarity is within a second preset range are selected from the N candidate texts as the M first candidate texts.
4. The method according to claim 1, characterized in that The step of determining the feature vector of the title and the feature vector of the text of the seed text, and the feature vector of the title and the feature vector of the text of each candidate text, includes: Searching for a feature vector of each word in a title of a target text and a feature vector of each word in a body of the target text from a preset word set, wherein the target text is the seed text or the candidate text, and the word set includes feature vectors corresponding to a plurality of words; Determine a feature vector of the title of the target text according to the feature vector of each word in the title of the target text; The feature vector of the body of the target text is determined according to the feature vector of each word in the body of the target text.
5. The method according to claim 4, characterized in that The step of determining the feature vector of the title of the target text according to the feature vector of each word in the title of the target text comprises: The feature vectors of each word in the title of the target text are accumulated, and the accumulated feature vectors are normalized, and the normalized feature vectors are used as the characteristic vector of the title of the target text.
6. The method according to claim 4, characterized in that The step of determining the feature vector of the body of the target text according to the feature vector of each word in the body of the target text comprises: The feature vectors of each word in the body of the target text are accumulated, and the accumulated feature vectors are normalized, and the normalized feature vectors are used as the feature vector of the body of the target text.
7. The method according to any one of claims 4 to 6, characterized in that: The step of determining the feature vector of the seed text according to the feature vector of the title and the feature vector of the body of the seed text comprises: The feature vector of the title of the seed text and the feature vector of the body of the seed text are concatenated, and the concatenated feature vector is used as the feature vector of the seed text.
8. The method according to any one of claims 4 to 6, characterized in that: Determining the feature vector of each candidate text according to the feature vector of the title and the feature vector of the body of each candidate text comprises: For each of the candidate texts, the feature vector of the title of the candidate text and the feature vector of the body of the candidate text are concatenated, and the concatenated feature vector is used as the feature vector of the candidate text.
9. A device for selecting training samples, characterized in that: include: An acquisition unit, used to acquire a seed text and N candidate texts; A first determination unit is used to determine the similarity between the seed text and each of the candidate texts, wherein the candidate texts are unlabeled samples to be selected and the seed texts are labeled samples; A first selection unit, configured to select M first candidate texts from the N candidate texts according to the similarity between the seed text and each of the candidate texts; A second determining unit is used for, for each first candidate text, taking the first candidate text as a first string and the seed text as a second string, and determining a minimum number of operations required when the first string is converted into the second string as an edit distance between the first candidate text and the seed text; A second selection unit is used to select K first candidate texts whose edit distance is greater than a preset value from the M first candidate texts as training samples according to the edit distance between each of the first candidate texts and the seed text, wherein the K first candidate texts are first candidate texts that are different from the seed text among the M first candidate texts, and the smaller the edit distance is, the higher the similarity between the two texts is, and N, M, and K are all positive integers greater than or equal to 1; Among them, the first determination unit is specifically used to determine the feature vector of the title and the feature vector of the text of the seed text, as well as the feature vector of the title and the feature vector of the text of each of the alternative texts; determine the feature vector of the seed text according to the feature vector of the title and the feature vector of the text; determine the feature vector of each of the alternative texts according to the feature vector of the title and the feature vector of the text; for each of the alternative texts, determine the similarity between the seed text and the alternative text according to the feature vector of the seed text and the feature vector of the alternative text.
