Efficient negative sample sampling method and system for contrastive learning integrated with EM algorithm
By integrating the EM algorithm to select high-confidence negative samples, the problem of insufficient quality of negative samples in contrastive learning is solved, the learning performance is improved, it is applicable to a variety of tasks and frameworks, and efficient negative sample utilization is achieved.
Patent Information
- Application Number
- CN202210687172.5
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2022-06-17
- Publication Date
- 2025-09-09
- Estimated Expiration
- 2042-06-17
AI Technical Summary
Existing contrastive learning methods cannot guarantee the quality of negative samples in the absence of labels, resulting in insufficient utilization of negative samples and affecting learning effects.
The fusion EM algorithm is used to select high-confidence negative samples. The vector representation of anchor samples, positive samples and negative samples is obtained through the pre-training model and mapped to the contrastive learning space. The fusion EM algorithm is used to select high-confidence negative samples and add them to the positive sample set. The contrastive loss function is constructed to optimize the parameters and the loop is executed until the model converges.
It improves the quality of negative samples in the unlabeled case and enhances the performance of contrastive learning. It is suitable for various task scenarios and contrastive learning frameworks and has good generalization performance and applicability.
Smart Images

Figure CN115221943B_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to the technical field of contrastive learning, and in particular to a method, system, storage medium and electronic device for efficiently sampling negative samples of contrastive learning integrated with an EM algorithm. Background Art
[0002] As a representative method in self-supervised learning, contrastive learning achieves accurate representation of input data without labels by narrowing the distance between positive samples and anchor samples and widening the distance between negative samples and anchor samples. This allows efficient transfer to downstream tasks and is therefore attracting increasing attention. One of the key research topics in contrastive learning today is how to better utilize negative samples without labels.
[0003] The current work in this direction can be summarized as follows: 1. Directly use other samples in the same training batch as negative samples. This method is a typical contrastive learning method. The positive samples are obtained through data augmentation, and the negative samples are directly selected from other samples in the same training batch as negative samples. This training method is also called instance-level contrastive learning; 2. Use existing labels to determine valid negative samples based on existing labels. This type of method mainly selects correct negative samples from all negative samples through existing labels and eliminates false negative samples (that is, samples with the same semantics or labels as the input data); 3. Use clustering to label pseudo-labels for negative samples, and improve the credibility of negative samples in the form of pseudo-labels. This type of method mainly focuses on how to improve the credibility of negative samples in the absence of labels.
[0004] However, existing solutions still have many limitations or defects in the use of negative samples, making it impossible to guarantee the quality of negative samples in the absence of labels. Summary of the Invention
[0005] (1) Technical problems solved
[0006] In response to the shortcomings of the existing technology, the present invention provides a method, system, storage medium and electronic device for efficient sampling of negative samples in contrastive learning that integrates the EM algorithm, which solves the technical problem that the quality of negative samples cannot be guaranteed in the absence of labels.
[0007] (2) Technical solution
[0008] To achieve the above objectives, the present invention is implemented through the following technical solutions:
[0009] An efficient negative sample sampling method for contrastive learning that integrates the EM algorithm includes:
[0010] S1. Determine anchor samples, positive samples, and negative samples in the current training batch, and use a pre-training model to obtain vector representations of the anchor samples, positive samples, and negative samples, respectively;
[0011] S2. Mapping the vector representations of the anchor samples, positive samples, and negative samples to a contrastive learning space;
[0012] S3. Based on the mapping output, the EM algorithm is integrated to select high-confidence negative samples and add them to the positive sample set; based on the adjusted positive sample set, the contrast loss function is constructed to optimize the parameters;
[0013] S4. Loop through S3 until the model converges, and output the final vector representation of the anchor point sample.
[0014] Preferably, in S1: a data enhancement method is used to obtain positive samples of the anchor point samples; and other non-anchor point samples in the same training batch are selected as negative samples of the anchor point samples.
[0015] Preferably, if the data type is an image, data enhancement is performed by rotation, cropping or color replacement; if the data type is text, data enhancement is performed by synonym replacement, order shuffling or random deletion.
[0016] Preferably, in S1: if the data type is image, the pre-trained model is a pre-trained ResNet network; if the data type is text, the pre-trained model is a pre-trained BERT network.
[0017] Preferably, in S2, the sample representation is mapped to the contrastive learning space by the same multi-layer perceptron MLP.
[0018] z i =MLP(h i ),
[0019] Among them, h i Represents the vector representation of the i-th anchor point sample; The vector representation of the positive sample representing the anchor point sample; Represents the vector representation of the j-th negative sample of the anchor point sample; z i 、 The vectors representing the anchor sample, positive sample, and j-th negative sample represent the corresponding mapping output results.
[0020] Preferably, the S3 specifically includes:
[0021] S31. Execute step E in the EM algorithm:
[0022] According to the mapping output result, the similarity α between the anchor sample and the positive sample is calculated ii, and the similarity α between the anchor sample and the negative sample ij ,
[0023]
[0024] Among them, sim() represents the similarity calculation method;
[0025] S32, execute the M step in the EM algorithm:
[0026] Compare the similarity calculated in the above steps with the preset threshold, select high-confidence negative samples and add them to the positive sample set.
[0027] P(i)={k|α ik >θ},k=i or j
[0028] Where P(i) represents the set of positive samples after adding the negative samples with high confidence of the i-th anchor sample; the hyperparameter θ represents the threshold;
[0029] According to the adjusted positive sample set, the contrast loss function optimization parameters are constructed.
[0030]
[0031] Where L represents the comparative optimization loss function of multiple positive samples; the number of samples in the current training batch is K+1; τ is the temperature hyperparameter used to control the sensitivity of the model to negative samples; log represents the logarithmic function; and p represents any positive sample in the adjusted positive sample set.
[0032] Preferably, the Adam optimizer is used to optimize the loss function L.
[0033] An efficient negative sample sampling system for contrastive learning that integrates the EM algorithm, including:
[0034] An acquisition module, configured to execute S1, determine anchor samples, positive samples, and negative samples in the current training batch, and respectively obtain vector representations of the anchor samples, positive samples, and negative samples using a pre-trained model;
[0035] A mapping module, configured to execute S2, mapping the vector representations of the anchor samples, positive samples, and negative samples to a contrastive learning space;
[0036] The optimization module is used to execute S3, integrate the EM algorithm to select high-confidence negative samples and add them to the positive sample set according to the mapping output results; and construct the contrast loss function optimization parameters based on the adjusted positive sample set;
[0037] The output module is used to execute S4, loop through the optimization module to execute S3 until the model converges, and output the final vector representation of the anchor point sample.
[0038] A storage medium stores a computer program for efficient negative sample sampling for contrastive learning integrated with an EM algorithm, wherein the computer program enables a computer to execute the above-mentioned efficient negative sample sampling method for contrastive learning.
[0039] An electronic device, comprising:
[0040] one or more processors;
[0041] Memory; and
[0042] One or more programs, wherein the one or more programs are stored in the memory and configured to be executed by the one or more processors, the programs including instructions for executing the contrastive learning negative sample efficient sampling method as described above.
[0043] (3) Beneficial effects
[0044] The present invention provides a method, system, storage medium, and electronic device for efficient negative sample sampling in contrastive learning that integrates the EM algorithm. Compared with existing technologies, it has the following advantages:
[0045] The present invention includes determining anchor samples, positive samples, and negative samples in the current training batch, using a pre-trained model to obtain vector representations of the anchor samples, positive samples, and negative samples, respectively; mapping the vector representations of the anchor samples, positive samples, and negative samples to a contrastive learning space; integrating the EM algorithm based on the mapping output to select high-confidence negative samples and add them to the positive sample set; constructing the contrastive loss function optimization parameters based on the adjusted positive sample set; looping through the above steps until the model converges, and outputting the final vector representation of the anchor samples. By introducing the EM algorithm, the selection of high-confidence negative samples is achieved, ensuring the quality of negative samples in the absence of labels and improving the performance of contrastive learning; and because the design is only based on the optimization objective, the provided method is model-independent and can be applied to various task scenarios and contrastive learning frameworks. BRIEF DESCRIPTION OF THE DRAWINGS
[0046] In order to more clearly illustrate the embodiments of the present invention or the technical solutions in the prior art, the following briefly introduces the drawings required for use in the embodiments or the description of the prior art. Obviously, the drawings described below are only some embodiments of the present invention. For ordinary technicians in this field, other drawings can be obtained based on these drawings without paying any creative work.
[0047] Figure 1 A schematic diagram of a flow chart of an efficient negative sample sampling method for contrastive learning integrated with the EM algorithm provided by an embodiment of the present invention;
[0048] Figure 2 A structural block diagram of an efficient negative sample sampling system for contrastive learning integrated with the EM algorithm provided by an embodiment of the present invention. DETAILED DESCRIPTION
[0049] To make the objectives, technical solutions, and advantages of the embodiments of the present invention more clear, the technical solutions in the embodiments of the present invention are clearly and completely described. Obviously, the described embodiments are only part of the embodiments of the present invention, not all of them. All other embodiments derived by persons of ordinary skill in the art based on the embodiments of the present invention without inventive effort are within the scope of protection of the present invention.
[0050] The embodiments of the present application solve the technical problem of being unable to guarantee the quality of negative samples in the absence of labels by providing a method, system, storage medium and electronic device for efficient sampling of negative samples for contrastive learning that integrates the EM algorithm.
[0051] The technical solution in the embodiments of the present application is to solve the above technical problems, and the overall idea is as follows:
[0052] In an embodiment of the present invention, the method includes determining anchor samples, positive samples, and negative samples in the current training batch, using a pre-trained model to obtain vector representations of the anchor samples, positive samples, and negative samples, respectively; mapping the vector representations of the anchor samples, positive samples, and negative samples to a contrastive learning space; integrating the EM algorithm based on the mapping output to select high-confidence negative samples and add them to the positive sample set; constructing the contrastive loss function optimization parameters based on the adjusted positive sample set; looping through the above steps until the model converges, and outputting the final vector representation of the anchor samples. By introducing the EM algorithm, the selection of high-confidence negative samples is achieved, the quality of negative samples is guaranteed in the absence of labels, and the performance of contrastive learning is improved; and because the design is only based on the optimization objective, the provided method is model-independent and can be applied to various task scenarios and contrastive learning frameworks.
[0053] In order to better understand the above technical solution, the above technical solution will be described in detail below with reference to the accompanying drawings and specific implementation methods.
[0054] Example:
[0055] like Figure 1 As shown, the embodiment of the present invention provides an efficient negative sample sampling method for contrastive learning integrated with the EM algorithm, including:
[0056] S1. Determine anchor samples, positive samples, and negative samples in the current training batch, and use a pre-training model to obtain vector representations of the anchor samples, positive samples, and negative samples, respectively;
[0057] S2. Mapping the vector representations of the anchor samples, positive samples, and negative samples to a contrastive learning space;
[0058] S3. Based on the mapping output, the EM algorithm is integrated to select high-confidence negative samples and add them to the positive sample set; based on the adjusted positive sample set, the contrast loss function is constructed to optimize the parameters;
[0059] S4. Loop through S3 until the model converges, and output the final vector representation of the anchor point sample.
[0060] Compared with existing methods, the embodiment of the present invention introduces the EM algorithm, which can fully consider the quality of negative samples in the process of calculating contrastive learning loss. By continuously selecting high-confidence negative samples, the performance of the contrastive learning method is effectively improved. At the same time, the embodiment of the present invention is designed only on the optimization target, making the embodiment of the present invention model-independent and applicable to different task scenarios and various contrastive learning frameworks, with good generalization performance and applicability.
[0061] The following will introduce each step of the above technical solution in detail with specific content:
[0062] In step S1, anchor samples, positive samples and negative samples are determined in the current training batch, and vector representations of the anchor samples, positive samples and negative samples are respectively obtained using a pre-training model.
[0063] In this step, input data X is selected from the current training batch i , represents the i-th input sample, which is used as the anchor sample in the subsequent comparative text learning, and the number of samples in the current batch is K+1.
[0064] At the same time, considering that the embodiment of the present invention uses a contrastive learning framework, different data enhancement methods are used to obtain the positive samples of the anchor point samples.
[0065]
[0066] Among them, Aug() represents the enhancement method.
[0067] Specifically, if the data type is image, data enhancement is performed by rotation, cropping or color replacement; if the data type is text, data enhancement is performed by synonym replacement, order shuffling or random deletion.
[0068] Other non-anchor samples in the same training batch are selected as negative samples of the anchor samples.
[0069] In addition, in embodiments of the present invention, different typical pre-trained models can be flexibly selected based on the specific input data. Specifically, if the data type is image, the pre-trained model is a pre-trained ResNet network; if the data type is text, the pre-trained model is a pre-trained BERT network.
[0070] The process of obtaining the vector representation of the anchor sample, positive sample, and negative sample using the same pre-training model can be expressed as follows:
[0071] h i =f(X i )
[0072]
[0073]
[0074]
[0075] Where f() represents the pre-training model; K represents the number of negative samples.
[0076] In step S2, the vector representations of the anchor samples, positive samples, and negative samples are mapped to a contrastive learning space.
[0077] After obtaining the vector representation of the anchor sample, positive sample, and negative sample, this step maps the sample representation to the contrastive learning space through the same multi-layer perceptron MLP.
[0078] z i =MLP(h i ),
[0079] Among them, h i Represents the vector representation of the i-th anchor point sample; The vector representation of the positive sample representing the anchor point sample; Represents the vector representation of the j-th negative sample of the anchor point sample; z i 、 The vectors representing the anchor sample, positive sample, and j-th negative sample represent the corresponding mapping output results.
[0080] In step S3, based on the mapping output, the EM algorithm is integrated to select high-confidence negative samples and add them to the positive sample set. Based on the adjusted positive sample set, the contrast loss function optimization parameters are constructed. Specifically, the following steps are performed:
[0081] S31. Execute step E in the EM algorithm:
[0082] The contrast loss function optimized model that integrates the EM algorithm is selected. First, the similarity between the anchor sample and the positive sample, and the anchor sample and the negative sample is calculated to obtain the probability distribution in the contrastive learning process. That is, based on the mapping output, the similarity α between the anchor sample and the positive sample is calculated. ii , and the similarity α between the anchor sample and the negative sample ij ,
[0083]
[0084] Here, sim() represents a similarity calculation method; for example, cosine similarity can be used as a calculation function.
[0085] S32, execute the M step in the EM algorithm:
[0086] After obtaining the similarity between the anchor sample and all samples, the embodiment of the present invention sets a hyperparameter θ as a threshold. When the similarity is greater than the threshold, it is considered that the negative sample should actually be a positive sample. Therefore, these samples are regarded as positive samples, and then the model is optimized using the contrastive learning loss function. That is, the similarity calculated in the above steps is compared with the preset threshold, and the negative samples with high confidence are selected and added to the positive sample set.
[0087] P(i)={k|α ik >θ},k=i or j
[0088] Where P(i) represents the set of positive samples after adding the negative samples with high confidence of the i-th anchor sample; the hyperparameter θ represents the threshold;
[0089] According to the adjusted positive sample set, the contrast loss function optimization parameters are constructed.
[0090]
[0091] Where L represents the comparative optimization loss function of multiple positive samples; the number of samples in the current training batch is K+1; τ is the temperature hyperparameter used to control the sensitivity of the model to negative samples; log represents the logarithmic function; and p represents any positive sample in the adjusted positive sample set.
[0092] The above whole process is a high confidence contrast learning process that integrates the EM algorithm.
[0093] In step S4, S3 is executed repeatedly until the model converges, and the final vector representation of the anchor point sample is output.
[0094] After obtaining the loss function L, this embodiment of the present invention selects Adam as the optimizer and optimizes the entire training objective with a learning rate of 0.001. First, high-confidence negative samples are screened based on a set threshold θ and converted to positive samples. Then, the Adam optimizer is used to optimize the loss function L. This process is iterated repeatedly until the entire model converges, completing the model training process.
[0095] After the entire model converges, this project embodiment selects the input vector representation h i As the output of the entire model, it is then applied to specific downstream tasks.
[0096] like Figure 2 As shown, an embodiment of the present invention provides an efficient negative sample sampling system for contrastive learning integrated with the EM algorithm, including:
[0097] An acquisition module, configured to execute S1, determine anchor samples, positive samples, and negative samples in the current training batch, and respectively obtain vector representations of the anchor samples, positive samples, and negative samples using a pre-trained model;
[0098] A mapping module, configured to execute S2, mapping the vector representations of the anchor samples, positive samples, and negative samples to a contrastive learning space;
[0099] The optimization module is used to execute S3, integrate the EM algorithm to select high-confidence negative samples and add them to the positive sample set according to the mapping output results; and construct the contrast loss function optimization parameters based on the adjusted positive sample set;
[0100] The output module is used to execute S4, loop through the optimization module to execute S3 until the model converges, and output the final vector representation of the anchor point sample.
[0101] An embodiment of the present invention provides a storage medium storing a computer program for efficient negative sample sampling for contrastive learning integrated with the EM algorithm, wherein the computer program enables a computer to execute the above-described efficient negative sample sampling method for contrastive learning.
[0102] An electronic device, comprising:
[0103] one or more processors;
[0104] Memory; and
[0105] One or more programs, wherein the one or more programs are stored in the memory and configured to be executed by the one or more processors, the programs including instructions for executing the contrastive learning negative sample efficient sampling method as described above.
[0106] It is understandable that the contrastive learning negative sample efficient sampling system, storage medium and electronic device integrated with the EM algorithm provided in the embodiments of the present invention correspond to the contrastive learning negative sample efficient sampling method provided in the embodiments of the present invention. The explanation, examples and beneficial effects of the relevant contents can refer to the corresponding parts in the contrastive learning negative sample efficient sampling method, which will not be repeated here.
[0107] In summary, compared with the existing technology, the present invention has the following beneficial effects:
[0108] Compared with existing methods, the embodiment of the present invention introduces the EM algorithm, which can fully consider the quality of negative samples in the process of calculating contrastive learning loss. By continuously selecting high-confidence negative samples, the performance of the contrastive learning method is effectively improved. At the same time, the embodiment of the present invention is designed only on the optimization target, making the embodiment of the present invention model-independent and applicable to different task scenarios and various contrastive learning frameworks, with good generalization performance and applicability.
[0109] It should be noted that, in this document, relational terms such as first and second, etc., are used only to distinguish one entity or operation from another entity or operation, and do not necessarily require or imply the existence of any such actual relationship or order between these entities or operations. Moreover, the terms "comprises," "comprising," or any other variants thereof are intended to cover non-exclusive inclusion, so that a process, method, article, or device comprising a series of elements includes not only those elements, but also other elements not explicitly listed, or elements inherent to such process, method, article, or device. In the absence of further limitations, an element defined by the phrase "comprising a ..." does not exclude the presence of other identical elements in the process, method, article, or device comprising the element.
[0110] The above embodiments are only used to illustrate the technical solutions of the present invention, rather than to limit the same. Although the present invention has been described in detail with reference to the aforementioned embodiments, those skilled in the art should understand that they can still modify the technical solutions described in the aforementioned embodiments, or make equivalent replacements for some of the technical features therein. However, these modifications or replacements do not deviate the essence of the corresponding technical solutions from the spirit and scope of the technical solutions of the various embodiments of the present invention.
Claims
1. An efficient negative sample sampling method for contrastive learning integrated with the EM algorithm, characterized by: include: S1. Determine anchor samples, positive samples, and negative samples in the current training batch, and use a pre-trained model to obtain vector representations of the anchor samples, positive samples, and negative samples, respectively; wherein the data type of the samples includes images or text; S2. Mapping the vector representations of the anchor samples, positive samples, and negative samples to a contrastive learning space; S3. Based on the mapping output, the EM algorithm is integrated to select high-confidence negative samples and add them to the positive sample set; based on the adjusted positive sample set, the contrast loss function is constructed to optimize the parameters; S4, loop through S3 until the model converges, and output the final vector representation of the anchor point sample; In S2, the sample representation is mapped to the contrastive learning space through the same multi-layer perceptron MLP. With i =MLP(h i ), Among them, h i Represents the vector representation of the i-th anchor point sample; The vector representation of the positive sample representing the anchor point sample; Represents the vector representation of the j-th negative sample of the anchor point sample; z i 、 The vectors representing the anchor sample, positive sample, and j-th negative sample represent the corresponding mapping output results.
2. The efficient negative sample sampling method for contrastive learning according to claim 1, characterized in that In S1: a data enhancement method is used to obtain positive samples of the anchor point samples; and other non-anchor point samples in the same training batch are selected as negative samples of the anchor point samples.
3. The efficient negative sample sampling method for contrastive learning according to claim 2, characterized in that: If the data type is image, data enhancement is performed by rotation, cropping, or color replacement; if the data type is text, data enhancement is performed by synonym replacement, order shuffling, or random deletion.
4. The method for efficient negative sample sampling for contrastive learning according to any one of claims 1 to 3, wherein: In S1: if the data type is image, the pre-trained model is a pre-trained ResNet network; if the data type is text, the pre-trained model is a pre-trained BERT network.
5. The method for efficient negative sample sampling for contrastive learning according to claim 1, wherein: The S3 specifically includes: S31. Execute step E in the EM algorithm: According to the mapping output result, the similarity α between the anchor sample and the positive sample is calculated ii , and the similarity α between the anchor sample and the negative sample ij , Among them, sim() represents the similarity calculation method; S32, execute the M step in the EM algorithm: Compare the similarity calculated in the above steps with the preset threshold, select high-confidence negative samples and add them to the positive sample set. P(i)={k|α ik >θ}, k=i or j Where P(i) represents the set of positive samples after adding the negative samples with high confidence of the i-th anchor sample; the hyperparameter θ represents the threshold; According to the adjusted positive sample set, the contrast loss function optimization parameters are constructed. Where L represents the comparative optimization loss function of multiple positive samples; the number of samples in the current training batch is K+1; τ is the temperature hyperparameter used to control the sensitivity of the model to negative samples; log represents the logarithmic function; and p represents any positive sample in the adjusted positive sample set.
6. The method for efficient negative sample sampling for contrastive learning according to claim 5, wherein: The Adam optimizer is used to optimize the loss function L.
7. A contrastive learning negative sample efficient sampling system integrating EM algorithm, characterized by: The method for performing the efficient negative sample sampling method for contrastive learning according to claim 1 comprises: An acquisition module, configured to execute S1, determine anchor samples, positive samples, and negative samples in the current training batch, and respectively obtain vector representations of the anchor samples, positive samples, and negative samples using a pre-trained model; A mapping module, configured to execute S2, mapping the vector representations of the anchor samples, positive samples, and negative samples to a contrastive learning space; The optimization module is used to execute S3, integrate the EM algorithm to select high-confidence negative samples and add them to the positive sample set based on the mapping output results; and construct the contrast loss function optimization parameters based on the adjusted positive sample set; The output module is used to execute S4, loop through the optimization module to execute S3 until the model converges, and output the final vector representation of the anchor point sample.
8. A storage medium, characterized in that: It stores a computer program for efficient negative sample sampling for contrastive learning integrated with the EM algorithm, wherein the computer program enables a computer to execute the efficient negative sample sampling method for contrastive learning according to any one of claims 1 to 6.
9. An electronic device, characterized in that: include: one or more processors; Memory; as well as One or more programs, wherein the one or more programs are stored in the memory and configured to be executed by the one or more processors, the programs including instructions for executing the negative sample efficient sampling method for contrastive learning according to any one of claims 1 to 6.
Citation Information
Patent Citations
Friend attention measurement sorting method and system based on complex network graph embedding
CN113779385A
Image matching method and system based on optimization adaptive metric learning
CN114463569A