{"id":2679,"date":"2025-01-25T10:52:36","date_gmt":"2025-01-25T02:52:36","guid":{"rendered":"https:\/\/www.gnn.club\/?p=2679"},"modified":"2025-03-12T15:06:46","modified_gmt":"2025-03-12T07:06:46","slug":"tutorial-05-%e6%98%8e%e8%be%a8%e6%98%af%e9%9d%9e%ef%bc%9a%e5%af%b9%e6%af%94%e5%ad%a6%e4%b9%a0%ef%bc%88contrastive-learning%ef%bc%89","status":"publish","type":"post","link":"http:\/\/gnn.club\/?p=2679","title":{"rendered":"Tutorial 05 &#8211; \u660e\u8fa8\u662f\u975e\uff1a\u5bf9\u6bd4\u5b66\u4e60\uff08Contrastive Learning\uff09"},"content":{"rendered":"<h1>Learning Methods of Deep Learning<\/h1>\n<hr \/>\n<p>create by Deepfinder<\/p>\n<h3><img decoding=\"async\" src=\"https:\/\/img.icons8.com\/bubbles\/50\/000000\/checklist.png\" style=\"height:50px;display:inline\"> Agenda<\/h3>\n<hr \/>\n<ol>\n<li>\u5e08\u5f92\u76f8\u6388\uff1a\u6709\u76d1\u7763\u5b66\u4e60\uff08Supervised Learning\uff09<\/li>\n<li>\u89c1\u5fae\u77e5\u8457\uff1a\u65e0\u76d1\u7763\u5b66\u4e60\uff08Un-supervised Learning\uff09<\/li>\n<li>\u65e0\u5e08\u81ea\u901a\uff1a\u81ea\u76d1\u7763\u5b66\u4e60\uff08Self-supervised Learning\uff09<\/li>\n<li>\u4ee5\u70b9\u5e26\u9762\uff1a\u534a\u76d1\u7763\u5b66\u4e60\uff08Semi-supervised learning\uff09<\/li>\n<li><strong>\u660e\u8fa8\u662f\u975e\uff1a\u5bf9\u6bd4\u5b66\u4e60\uff08Contrastive Learning\uff09<\/strong><\/li>\n<li>\u4e3e\u4e00\u53cd\u4e09\uff1a\u8fc1\u79fb\u5b66\u4e60\uff08Transfer Learning\uff09<\/li>\n<li>\u9488\u950b\u76f8\u5bf9\uff1a\u5bf9\u6297\u5b66\u4e60\uff08Adversarial Learning\uff09<\/li>\n<li>\u4f17\u5fd7\u6210\u57ce\uff1a\u96c6\u6210\u5b66\u4e60(Ensemble Learning) <\/li>\n<li>\u6b8a\u9014\u540c\u5f52\uff1a\u8054\u90a6\u5b66\u4e60\uff08Federated Learning\uff09<\/li>\n<li>\u767e\u6298\u4e0d\u6320\uff1a\u5f3a\u5316\u5b66\u4e60\uff08Reinforcement Learning\uff09<\/li>\n<li>\u6c42\u77e5\u82e5\u6e34\uff1a\u4e3b\u52a8\u5b66\u4e60\uff08Active Learning\uff09<\/li>\n<li>\u4e07\u6cd5\u5f52\u5b97\uff1a\u5143\u5b66\u4e60\uff08Meta-Learning\uff09<\/li>\n<\/ol>\n<h2>Tutorial 05 - \u660e\u8fa8\u662f\u975e\uff1a\u5bf9\u6bd4\u5b66\u4e60\uff08Contrastive Learning\uff09<\/h2>\n<h3><img decoding=\"async\" src=\"https:\/\/img.icons8.com\/plasticine\/100\/000000\/protect-from-magnetic-field.png\" style=\"height:50px;display:inline\"> \u5bf9\u6bd4\u5b66\u4e60<\/h3>\n<hr \/>\n<ul>\n<li>\u5bf9\u6bd4\u5b66\u4e60\u662f\u4e00\u79cd\u5236\u5b9a <strong>\u4e3a\u6df1\u5ea6\u5b66\u4e60\u6a21\u578b\u5bfb\u627e\u76f8\u4f3c\u548c\u4e0d\u76f8\u4f3c\u4e8b\u7269\uff08\u57fa\u672c\u4e0a\u5c31\u662f\u7ed9\u5b9a\u6807\u7b7e\u65f6\u5206\u7c7b\u6240\u505a\u7684\u4e8b\u60c5\uff09<\/strong> \u7684\u4efb\u52a1\u7684\u65b9\u6cd5\u3002<\/li>\n<li>\u5bf9\u6bd4\u65b9\u6cd5\uff0c\u987e\u540d\u601d\u4e49\uff0c\u901a\u8fc7\u5bf9\u6bd4<strong>\u6b63\u9762\u548c\u8d1f\u9762<\/strong>\u793a\u4f8b\u6765\u5b66\u4e60\u8868\u793a\u3002<\/li>\n<li>\u4f7f\u7528\u8fd9\u79cd\u65b9\u6cd5\uff0c\u53ef\u4ee5\u8bad\u7ec3\u673a\u5668\u5b66\u4e60\u6a21\u578b\u5bf9\u76f8\u4f3c\u548c\u4e0d\u76f8\u4f3c\u7684\u56fe\u50cf\u8fdb\u884c\u5206\u7c7b\u3002<\/li>\n<\/ul>\n<p>\u66f4\u6b63\u5f0f\u5730\u8bf4\uff0c\u5bf9\u4e8e\u4efb\u4f55\u6570\u636e\u70b9 $x$\uff0c\u5bf9\u6bd4\u65b9\u6cd5\u65e8\u5728\u5b66\u4e60\u7f16\u7801\u5668 $f$\uff0c\u4f7f\u5f97\uff1a<\/p>\n<ul>\n<li>$x^+$ \u662f\u4e0e $x$ \u76f8\u4f3c\u7684\u6570\u636e\u70b9\uff0c\u79f0\u4e3a <em>\u6b63<\/em> \u6837\u672c\u3002<\/li>\n<li>$x^\u2212$ \u662f\u4e0e $x$ \u4e0d\u76f8\u4f3c\u7684\u6570\u636e\u70b9\uff0c\u79f0\u4e3a <em>\u8d1f<\/em> \u6837\u672c\u3002<\/li>\n<li><strong>\u5f97\u5206\u51fd\u6570<\/strong> \u662f\u8861\u91cf\u4e24\u4e2a\u7279\u5f81\u4e4b\u95f4\u76f8\u4f3c\u5ea6\u7684\u6307\u6807\uff1a $$score(f(x), f(x^+)) &gt;&gt; score(f(x), f(x^-))$$<\/li>\n<\/ul>\n<p align=\"center\">\n  <img decoding=\"async\" src=\"https:\/\/gnnclub-1311496010.cos.ap-beijing.myqcloud.com\/wp-content\/uploads\/2025\/01\/20250125103437924.png\n\" style=\"height:400px\">\n<\/p>\n<p align=\"center\">\n  <img decoding=\"async\" src=\"https:\/\/gnnclub-1311496010.cos.ap-beijing.myqcloud.com\/wp-content\/uploads\/2025\/01\/20250125105158906.gif\n\" style=\"height:300px\">\n<\/p>\n<ul>\n<li>\n<p><a href=\"https:\/\/analyticsindiamag.com\/contrastive-learning-self-supervised-ml\">Image Source<\/a><\/p>\n<\/li>\n<li>\n<p>\u5b9e\u73b0\u5f97\u5206\u8303\u5f0f\u7684\u6700\u5e38\u89c1\u635f\u5931\u51fd\u6570\u662f <strong>InfoNCE<\/strong> \u635f\u5931\uff0c\u5b83\u770b\u8d77\u6765\u7c7b\u4f3c\u4e8e softmax\u3002<\/p>\n<\/li>\n<\/ul>\n<p align=\"center\">\n  <img decoding=\"async\" src=\"https:\/\/gnnclub-1311496010.cos.ap-beijing.myqcloud.com\/wp-content\/uploads\/2025\/01\/20250125103547973.png\n\" style=\"height:150px\">\n<\/p>\n<ul>\n<li>\u5206\u6bcd\u9879\u7531\u4e00\u4e2a\u6b63\u6837\u672c\u548c\u00a0$N\u22121$ \u4e2a\u8d1f\u6837\u672c\u7ec4\u6210\u3002<\/li>\n<\/ul>\n<h4><img decoding=\"async\" src=\"https:\/\/img.icons8.com\/?size=100&id=91CnU00i6HLv&format=png&color=000000\" style=\"height:50px;display:inline\"> \u4f46\u662f\uff0c\u5982\u679c\u6211\u4eec\u5904\u4e8e\u81ea\u76d1\u7763\u73af\u5883\u4e2d\uff0c\u6211\u4eec\u5982\u4f55\u83b7\u5f97\u8d1f\u6837\u672c\uff1f<\/h4>\n<ul>\n<li><a href=\"https:\/\/github.com\/RElbers\/info-nce-pytorch\">PyTorch \u4e2d\u7684 InfoNCE \u635f\u5931<\/a><\/li>\n<\/ul>\n<h3><img decoding=\"async\" src=\"https:\/\/img.icons8.com\/pastel-glyph\/64\/000000\/qr-code--v2.png\" style=\"height:50px;display:inline\"> \u5bf9\u6bd4\u9884\u6d4b\u7f16\u7801 ( Contrastive Predictive Coding)<\/h3>\n<hr \/>\n<ul>\n<li><a href=\"https:\/\/arxiv.org\/abs\/1807.03748\"><strong>\u5bf9\u6bd4\u9884\u6d4b\u7f16\u7801 (CPC)<\/strong><\/a> \u901a\u8fc7\u4f7f\u7528\u5f3a\u5927\u7684\u81ea\u56de\u5f52\u6a21\u578b\u5728\u5b66\u4e60\u5230\u7684 <em>\u6f5c\u5728\u7a7a\u95f4<\/em> \u4e2d<strong>\u9884\u6d4b\u672a\u6765<\/strong>\uff0c\u5b66\u4e60\u81ea\u76d1\u7763\u8868\u793a\u3002<\/li>\n<li>\u8be5\u6a21\u578b\u4f7f\u7528\u6982\u7387\u5bf9\u6bd4\u635f\u5931\uff0c\u8bf1\u5bfc\u6f5c\u5728\u7a7a\u95f4\u6355\u83b7<strong>\u5bf9\u9884\u6d4b\u672a\u6765\u6837\u672c\u6700\u6709\u7528<\/strong>\u7684\u4fe1\u606f\u3002<\/li>\n<\/ul>\n<p align=\"center\">\n  <img decoding=\"async\" src=\"https:\/\/gnnclub-1311496010.cos.ap-beijing.myqcloud.com\/wp-content\/uploads\/2025\/01\/20250125103616932.png\n\" style=\"height:350px\">\n<\/p>\n<ul>\n<li>\u9996\u5148\uff0c\u975e\u7ebf\u6027\u7f16\u7801\u5668 $g_{enc}$ \u5c06\u8f93\u5165\u7684\u89c2\u6d4b\u5e8f\u5217 $x_t$ \u6620\u5c04\u5230\u6f5c\u5728\u8868\u793a\u5e8f\u5217 $z_t = g_{enc}(x_t)$\uff0c\u53ef\u80fd\u5177\u6709\u8f83\u4f4e\u7684\u65f6\u95f4\u5206\u8fa8\u7387\uff08$g_{enc}$ \u7684\u67b6\u6784\u901a\u5e38\u53d6\u51b3\u4e8e\u6570\u636e\u7c7b\u578b\uff0c\u4f8b\u5982\u7528\u4e8e\u56fe\u50cf\u7684 CNN\uff09\u3002<\/li>\n<li>\u63a5\u4e0b\u6765\uff0c\u81ea\u56de\u5f52\u6a21\u578b $g_{ar}$ \u603b\u7ed3\u6f5c\u5728\u7a7a\u95f4\u4e2d\u7684\u6240\u6709 $z \\leq t$ \u5e76\u4ea7\u751f\u4e0a\u4e0b\u6587\u6f5c\u5728\u8868\u793a $c_t=g_{ar}(z \\leq t)$\u3002<\/li>\n<li>\u76f8\u4f3c\u5ea6 $f$ \u88ab\u5efa\u6a21\uff0c\u5b83\u4fdd\u7559\u4e86 $x_{t+k}$ \u548c $c_t$ \u4e4b\u95f4\u7684 <strong>\u76f8\u4e92\u4fe1\u606f<\/strong>\uff0c\u5982\u4e0b\u6240\u793a\uff1a $$ f_k(x_{t+k}, c_t) = \\exp(z_{t+k}^T W_k c_t) \\propto \\frac{p(x_{t+k} | c_t)}{p(x_{t+k})} $$<\/li>\n<\/ul>\n<p>\u4f60\u53ef\u4ee5\u8fd9\u4e48\u7406\u89e3\uff1a\u5728 CPC\uff08Contrastive Predictive Coding\uff09\u7684\u60c5\u5883\u4e0b\uff0c<\/p>\n<ol>\n<li>\u7f16\u7801\u5668 ( $g_{\\mathrm{enc}}$ ) \u7528\u4e8e\u628a\u6bcf\u4e2a\u65f6\u523b\u7684\u6587\u672c (\u6216\u5176\u4ed6\u6a21\u6001) \u8f93\u5165\u6620\u5c04\u5230\u4e00\u4e2a\u6f5c\u5728\u5411\u91cf\u8868\u793a $z_t$ \u3002<\/li>\n<li>\u81ea\u56de\u5f52\u6a21\u578b\uff08 $g_{\\mathrm{ar}}$ \uff09\u5219\u8d1f\u8d23\u5728\u65f6\u95f4\u5e8f\u5217\u7ef4\u5ea6\u4e0a&quot;\u805a\u5408\u8bed\u4e49&quot;\uff0c\u8f93\u51fa\u4e00\u4e2a&quot;\u4e0a\u4e0b\u6587&quot;\u5411\u91cf $c_t$ \uff0c\u8868\u793a\u6a21\u578b\u5bf9 &quot;\u622a\u6b62\u5230\u5f53\u524d\u65f6\u523b\u6240\u6709\u4fe1\u606f&quot;\u7684\u7406\u89e3\u3002<\/li>\n<li>\u5728\u8bad\u7ec3\u65f6:\n<ul>\n<li>\u53d6\u4e00\u4e2a\u65f6\u95f4\u6233 $t$ \uff0c\u7528\u4e0a\u4e0b\u6587 $c_t$ \u548c\u771f\u6b63\u7684\u672a\u6765 (\u4e0b\u4e00\u65f6\u523b) \u5bf9\u5e94\u7684\u6f5c\u5728\u5411\u91cf $z_{t+1}$ \u4f5c\u4e3a\u6b63\u4f8b\uff0c<\/li>\n<li>\u5e76\u5c06\u4e0a\u4e0b\u6587 $c_t$ \u4e0e\u5176\u4ed6\u65f6\u523b\uff08\u6216\u8005\u5176\u4ed6\u65e0\u5173\u6837\u672c\uff09\u7684\u6f5c\u5728\u5411\u91cf $z_{\\mathrm{neg}}$ \u4f5c\u4e3a\u8d1f\u4f8b\u3002<\/li>\n<li>\u901a\u8fc7 InfoNCE \u8fd9\u7c7b\u5bf9\u6bd4\u635f\u5931\uff0c\u8ba9\u6a21\u578b\u5c3d\u53ef\u80fd\u533a\u5206\u51fa\u6b63\u4f8b\u548c\u8d1f\u4f8b\uff0c\u4ece\u800c\u62c9\u8fd1\u771f\u6b63\u76f8\u5173\u7684\u65f6\u523b\u8868\u793a\u3001\u63a8\u8fdc\u4e0d\u76f8\u5173\u7684\u65f6\u523b\u8868\u793a\u3002<\/li>\n<\/ul>\n<\/li>\n<\/ol>\n<p>\u8fd9\u6837\u505a\u7684\u76f4\u89c2\u542b\u4e49\u662f:<\/p>\n<ul>\n<li>&quot;\u5982\u679c\u7ed9\u5b9a\u4e86\u8fc7\u53bb\u65f6\u523b\u7684\u8bed\u4e49\uff0c\u80fd\u4e0d\u80fd\u6b63\u786e\u8fa8\u8ba4\u51fa\u771f\u6b63\u7684\u4e0b\u4e00\u4e2a\u65f6\u523b?&quot;<\/li>\n<li>\u8fd9\u5728\u81ea\u76d1\u7763\u7684\u6846\u67b6\u4e0b\uff0c\u4f1a\u4fc3\u4f7f\u6a21\u578b\u5b66\u5230\u5177\u6709\u9884\u6d4b\u80fd\u529b\u3001\u5bf9&quot;\u4e0a\u4e0b\u6587\u4e00\u672a\u6765&quot;\u5173\u7cfb\u654f\u611f\u7684\u8868\u793a\u3002<\/li>\n<\/ul>\n<p>\u6240\u4ee5\uff0c&quot;\u7f16\u7801\u5668 + \u81ea\u56de\u5f52 + InfoNCE \u5bf9\u6bd4\u635f\u5931&quot; \u5c31\u6784\u6210\u4e86 CPC \u7684\u57fa\u672c\u601d\u8def\u3002\u6587\u672c\u4e0a\u53ef\u4ee5\u8fd9\u6837\u7b80\u5355\u8bb0\u5fc6:<\/p>\n<p>\u5148&quot;\u7f16\u7801&quot;\u6bcf\u4e2a\u65f6\u523b\uff0c<\/p>\n<p>\u518d\u7528&quot;\u81ea\u56de\u5f52&quot;\u6c47\u603b\u8fc7\u53bb\uff0c<\/p>\n<p>\u5229\u7528&quot;\u5bf9\u6bd4\u635f\u5931&quot;\u6765\u62c9\u8fd1\u6b63\u786e\u7684\u4e0b\u4e00\u4e2a\u65f6\u523b\u8868\u793a \u63a8\u8fdc\u4e0d\u6b63\u786e\u7684\u4e0b\u4e00\u4e2a\u65f6\u523b\u8868\u793a\u3002<\/p>\n<ul>\n<li><a href=\"https:\/\/github.com\/jefflai108\/Contrastive-Predictive-Coding-PyTorch\">PyTorch \u4ee3\u7801<\/a><\/li>\n<\/ul>\n<h4><img decoding=\"async\" src=\"https:\/\/img.icons8.com\/?size=100&id=91CnU00i6HLv&format=png&color=000000\" style=\"height:50px;display:inline\"> bert\u4e2d\u7684\u4e0a\u4e0b\u6587\u9884\u6d4b\u4efb\u52a1\u7b97\u5bf9\u6bd4\u5b66\u4e60\u5417\uff1f<\/h4>\n<h3><img decoding=\"async\" src=\"https:\/\/img.icons8.com\/nolan\/64\/collapse-arrow.png\" style=\"height:50px;display:inline\"> \u89c6\u89c9\u8868\u5f81\u5bf9\u6bd4\u5b66\u4e60\u7b80\u5355\u6846\u67b6 (Simple Framework for Contrastive Learning of Visual Representations)<\/h3>\n<hr \/>\n<ul>\n<li><a href=\"https:\/\/arxiv.org\/abs\/2002.05709\"><strong>\u89c6\u89c9\u8868\u5f81\u5bf9\u6bd4\u5b66\u4e60\u7b80\u5355\u6846\u67b6 (SimCLR)<\/strong><\/a> \u662f\u4e00\u4e2a\u7528\u4e8e\u5bf9\u6bd4\u5b66\u4e60 <em>\u89c6\u89c9<\/em> \u8868\u5f81\u7684\u6846\u67b6\u3002<\/li>\n<li>\u5b83\u901a\u8fc7\u6f5c\u5728\u7a7a\u95f4\u4e2d\u7684\u5bf9\u6bd4\u635f\u5931\uff0c\u6700\u5927\u5316\u540c\u4e00\u6570\u636e\u793a\u4f8b\u7684\u4e0d\u540c\u589e\u5f3a\u89c6\u56fe\u4e4b\u95f4\u7684\u4e00\u81f4\u6027\u6765\u5b66\u4e60\u8868\u5f81\u3002<\/li>\n<\/ul>\n<p><strong>\u6b63\u4f8b (Positive Pair) \u662f\u5982\u4f55\u5b9a\u4e49\u7684?<\/strong><\/p>\n<ol>\n<li>\n<p>\u968f\u673a\u6570\u636e\u589e\u5f3a\uff1a\u5bf9\u540c\u4e00\u5f20\u539f\u59cb\u56fe\u50cf $x$ \u8fdb\u884c\u4e24\u6b21\u968f\u673a\u589e\u5f3a\uff0c\u5f97\u5230\u4e24\u5f20\u589e\u5f3a\u540e\u7684\u56fe\u50cf\uff1a$\\tilde{x}_i \\quad \\text { \u548c } \\quad \\tilde{x}_j$\u3002<br \/>\n\u5b83\u4eec\u6765\u81ea\u540c\u4e00\u5f20\u56fe\uff0c\u53ea\u662f\u7531\u4e8e\u88c1\u526a\u3001\u989c\u8272\u6296\u52a8\u3001\u6a21\u7cca\u7b49\u589e\u5f3a\u8c03\u6574\u800c\u5f97\u5230\u7684\u4e24\u4e2a\u89c6\u56fe\u3002<\/p>\n<\/li>\n<li>\n<p>\u79f0\u4e3a&quot;\u6b63\u5bf9&quot;: \u8fd9\u4e24\u5f20\u89c6\u56fe\u5728\u8bed\u4e49\u4e0a\u662f\u76f8\u540c\u7684\uff0c\u90fd\u662f\u6765\u81ea\u540c\u4e00\u4e2a\u539f\u56fe\uff0c\u56e0\u6b64 $\\left(\\tilde{x}_i, \\tilde{x}_j\\right)$ \u88ab\u770b\u4f5c\u4e00\u5bf9 &quot;\u6b63\u4f8b (positive pair)&quot;\u3002<\/p>\n<\/li>\n<li>\n<p>\u5c0f\u6279\u91cf\u5185\u7684\u6240\u6709\u6b63\u4f8b\u5bf9\uff1a\u5728\u8bad\u7ec3\u65f6\uff0c\u4f1a\u62bd\u53d6\u4e00\u4e2a\u5305\u542b $N$ \u4e2a\u539f\u56fe\u7684\u5c0f\u6279\u91cf\uff0c\u4e3a\u5176\u4e2d\u6bcf\u4e2a\u539f\u56fe\u90fd\u751f\u6210\u4e24\u4efd\u589e\u5f3a\u89c6\u56fe\u3002\u6240\u4ee5\u5c0f\u6279\u91cf\u6700\u7ec8\u62e5\u6709 $2 N$ \u4e2a&quot;\u56fe\u50cf\u89c6\u56fe&quot;\u3002\u5bf9\u4e8e\u6bcf\u4e2a\u539f\u56fe $x$ \uff0c\u5b83\u7684\u4e24\u4efd\u89c6\u56fe\u5c31\u6784\u6210\u4e86\u4e00\u4e2a\u6b63\u4f8b\u5bf9\u3002<\/p>\n<\/li>\n<\/ol>\n<p><strong>\u8d1f\u4f8b (Negative Examples) \u53c8\u662f\u600e\u4e48\u6765\u7684?<\/strong><\/p>\n<ol>\n<li>\u663e\u5f0f&quot;\u8d1f\u4f8b&quot; vs. \u9690\u5f0f&quot;\u8d1f\u4f8b&quot;<\/li>\n<\/ol>\n<p>\u4f20\u7edf\u5bf9\u6bd4\u5b66\u4e60\u65b9\u6cd5\u5e38\u5e38\u9700\u8981\u663e\u5f0f\u5730\u627e\u4e00\u4e9b\u4e0d\u540c\u7684\u56fe\u50cf\u4f5c\u4e3a&quot;\u8d1f\u4f8b&quot;\uff0c\u6bd4\u5982\u4ece\u522b\u7684\u7c7b\u522b\u4e2d\u62bd\u53d6\u6837\u672c\u6765\u6784\u5efa\u8d1f\u4f8b\u3002SimCLR \u5219\u63d0\u51fa\u4e00\u4e2a\u975e\u5e38\u7b80\u5355\u4e14\u6709\u6548\u7684\u505a\u6cd5\uff1a\u4e0d\u7528\u663e\u5f0f\u5730\u6311\u9009\u8d1f\u4f8b\uff0c\u53ea\u8981\u628a\u5c0f\u6279\u91cf\u91cc\u7684\u5176\u4ed6\u6240\u6709\u89c6\u56fe\uff0c\u7edf\u7edf\u89c6\u4e3a\u672c\u89c6\u56fe\u7684\u8d1f\u4f8b\u5373\u53ef\u3002<\/p>\n<ol start=\"2\">\n<li>\u5177\u4f53\u5b9a\u4e49<\/li>\n<\/ol>\n<p>\u5047\u8bbe\u5c0f\u6279\u91cf\u91cc\u6709 $N$ \u4e2a\u539f\u56fe\uff0c\u4e00\u5171\u5f97\u5230 $2 N$ \u4e2a\u589e\u5f3a\u89c6\u56fe\uff082\u4e2a\u89c6\u56fe\/\u56fe $\\times N$ \u5f20\u539f\u56fe\uff09\u3002\u5982\u679c\u6211\u4eec\u5173\u6ce8\u5176\u4e2d\u67d0\u4e2a\u6b63\u5bf9 $\\left(\\tilde{x}_i, \\tilde{x}_j\\right)$ \uff0c\u90a3\u4e48\u5bf9\u4e8e $\\tilde{x}_i$ \u6765\u8bf4:<\/p>\n<ul>\n<li>\u5b83\u7684&quot;\u6b63\u4f8b&quot;\u5c31\u662f $\\tilde{x}_j$ (\u56e0\u4e3a\u4e8c\u8005\u90fd\u662f\u6765\u81ea\u540c\u4e00\u4e2a\u539f\u56fe)\u3002<\/li>\n<li>\u5c0f\u6279\u91cf\u4e2d\u5269\u4e0b\u7684 $2 N-2$ \u4e2a\u89c6\u56fe\uff08\u5305\u62ec\u522b\u7684\u56fe\u7247\u7684\u589e\u5f3a\u89c6\u56fe\uff0c\u4ee5\u53ca $\\tilde{x}_i$ \u81ea\u5df1\u90a3\u4e00\u5bf9\u7684\u53e6\u4e00\u4e2a\u6210\u5458\u5df2\u7ecf\u88ab\u7b97\u4f5c\u6b63\u4f8b\uff0c\u6240\u4ee5\u8981\u6392\u9664\uff09\u90fd\u88ab\u89c6\u4e3a\u8d1f\u4f8b\u3002<\/li>\n<\/ul>\n<ol start=\"3\">\n<li>\u597d\u5904<\/li>\n<\/ol>\n<p>\u8fd9\u6837\u505a\u663e\u8457\u964d\u4f4e\u4e86\u7ba1\u7406\u6b63\u8d1f\u4f8b\u7684\u590d\u6742\u5ea6\uff1a\u4e0d\u5fc5\u989d\u5916\u7ef4\u62a4\u4e00\u4e2a\u5927\u578b\u7684\u8d1f\u4f8b\u6c60\uff0c\u4e5f\u65e0\u9700\u5728\u7ebf\u6316\u6398\u8d1f\u4f8b\uff0c\u53ea\u8981\u5728\u4e00\u4e2a mini-batch \u5185\u6c42\u5bf9\u6bd4\u635f\u5931\uff0c\u5c31\u80fd\u628a\u5176\u5b83\u89c6\u56fe\u5f53\u4f5c\u8d1f\u4f8b\u4e86\u3002<\/p>\n<ul>\n<li><a href=\"https:\/\/github.com\/sthalles\/SimCLR\">PyTorch \u4ee3\u7801<\/a><\/li>\n<li><a href=\"https:\/\/colab.research.google.com\/github\/rll\/deepul\/blob\/master\/demos\/lecture7\\_selfsupervised\\_demos.ipynb#scrollTo=YB\\_cqJagEXbw\">Colab \u793a\u4f8b<\/a><\/li>\n<\/ul>\n<p align=\"center\">\n  <img decoding=\"async\" src=\"https:\/\/gnnclub-1311496010.cos.ap-beijing.myqcloud.com\/wp-content\/uploads\/2025\/01\/20250125103711463.gif\n\" style=\"height:400px\">\n<\/p>\n<ul>\n<li><a href=\"https:\/\/ai.googleblog.com\/2020\/04\/advancing-self-supervised-and-semi.html\">Image Source<\/a><\/li>\n<\/ul>\n<p>\u5bf9\u4e8e\u5c0f\u6279\u91cf\u4e2d\u7684\u4efb\u610f\u4e00\u4e2a\u589e\u5f3a\u89c6\u56fe\uff0c\u5728\u8ba1\u7b97\u5b83\u7684\u635f\u5931\u65f6\uff0c\u5b83\u201c\u5e94\u8be5\u201d\u53ea\u548c\u5b83\u90a3\u5bf9\u6b63\u4f8b\u89c6\u56fe\u76f8\u4f3c\uff0c\u800c\u548c\u4efb\u4f55\u5176\u4ed6\u89c6\u56fe\u90fd\u4e0d\u76f8\u4f3c\uff0c\u8fd9\u5c31\u81ea\u7136\u523b\u753b\u51fa\u4e86\u6b63\u4f8b\u548c\u8d1f\u4f8b\u7684\u533a\u5206\u3002\u901a\u8fc7\u5728\u5c0f\u6279\u91cf\u7ef4\u5ea6\u4e0a\u505a\u5bf9\u6bd4\u635f\u5931\uff0cSimCLR \u5c31\u80fd\u5728\u6ca1\u6709\u6807\u7b7e\u7684\u6761\u4ef6\u4e0b\uff0c\u5b66\u5230\u5f88\u6709\u5224\u522b\u529b\u7684\u89c6\u89c9\u8868\u793a\u3002<\/p>\n<h3><img decoding=\"async\" src=\"https:\/\/img.icons8.com\/external-gradients-pongsakorn-tan\/64\/null\/external-clip-gdpr-gradients-pongsakorn-tan.png\" style=\"height:50px;display:inline\"> CLIP - Contrastive Language\u2013Image Pre-training<\/h3>\n<hr \/>\n<ul>\n<li><strong>CLIP<\/strong> \u662f\u4e00\u79cd\u795e\u7ecf\u7f51\u7edc\uff0c\u53ef\u4ece\u81ea\u7136\u8bed\u8a00\u76d1\u7763\u4e2d\u9ad8\u6548\u5b66\u4e60\u89c6\u89c9\u6982\u5ff5\u3002<\/li>\n<li>CLIP \u53ef\u4ee5\u4ee5 <strong>\u96f6\u6837\u672c<\/strong> \u65b9\u5f0f\u5e94\u7528\u4e8e\u4efb\u4f55\u89c6\u89c9\u5206\u7c7b\u57fa\u51c6\uff0c\u53ea\u9700\u63d0\u4f9b\u8981\u8bc6\u522b\u7684\u89c6\u89c9\u7c7b\u522b\u7684\u540d\u79f0\u5373\u53ef\u3002<\/li>\n<li><strong>\u8bad\u7ec3\u6570\u636e<\/strong>\uff1a\u5728\u4e92\u8054\u7f51\u4e0a\u627e\u5230\u7684\u4e0e\u56fe\u50cf\u914d\u5bf9\u7684\u6587\u672c\u3002<\/li>\n<li><strong>\u81ea\u6211\u76d1\u7763\u4efb\u52a1<\/strong>\uff1a\u7ed9\u5b9a\u4e00\u5f20\u56fe\u50cf\uff0c\u9884\u6d4b\u5728\u200b\u200b\u4e00\u7ec4\u968f\u673a\u91c7\u6837\u7684\u6587\u672c\u7247\u6bb5\u4e2d\uff0c\u54ea\u4e00\u4e2a\u4e0e\u6570\u636e\u96c6\u4e2d\u7684\u56fe\u50cf\u5b9e\u9645\u914d\u5bf9\uff0c\u8fd9\u7c7b\u4f3c\u4e8e\u6211\u4eec\u4e4b\u524d\u4ecb\u7ecd\u7684\u5339\u914d\u8303\u4f8b\u3002<\/li>\n<li><strong>\u635f\u5931\u51fd\u6570<\/strong>\uff1a\u914d\u5bf9\u4e4b\u95f4\u7684\u4f59\u5f26\u76f8\u4f3c\u5ea6\u7b49\u7f29\u653e\u4ea4\u53c9\u71b5\u635f\u5931\u3002<\/li>\n<li>\u5728\u63a8\u7406\u65f6\uff0c\u6211\u4eec\u53ef\u4ee5\u901a\u8fc7\u68c0\u67e5\u6bcf\u5f20\u56fe\u7247\u7684 CLIP \u6a21\u578b\u9884\u6d4b\u6587\u672c\u63cf\u8ff0\u201c\u4e00\u5f20\u72d7\u7684\u7167\u7247\u201d\u6216\u201c\u4e00\u5f20\u732b\u7684\u7167\u7247\u201d\u662f\u5426\u66f4\u6709\u53ef\u80fd\u4e0e\u5176\u914d\u5bf9\uff0c\u5bf9\u72d7\u548c\u732b\u7684\u7167\u7247\u8fdb\u884c\u5206\u7c7b\u3002<\/li>\n<li><a href=\"https:\/\/github.com\/openai\/CLIP\">\u5b98\u65b9\u5b58\u50a8\u5e93 (PyTorch)<\/a><\/li>\n<li><a href=\"https:\/\/colab.research.google.com\/github\/openai\/CLIP\/blob\/main\/notebooks\/Interacting\\_with\\_CLIP.ipynb\">Colab \u793a\u4f8b - \u4e0e CLIP \u548c\u96f6\u6837\u672c\u5206\u7c7b\u7684\u4ea4\u4e92<\/a><\/li>\n<li>HuggingFace \u6f14\u793a\uff1a<\/li>\n<li><a href=\"https:\/\/huggingface.co\/openai\/clip-vit-large-patch14\">CLIP-ViT-Large<\/a><\/li>\n<li><a href=\"https:\/\/huggingface.co\/spaces\/taesiri\/CLIPScore\">CLIPScore<\/a><\/li>\n<\/ul>\n<pre><code class=\"language-python\"># clip usage example\nimport torch\nimport clip\nfrom PIL import Image\n\ndevice = &quot;cuda&quot; if torch.cuda.is_available() else &quot;cpu&quot;\nmodel, preprocess = clip.load(&quot;ViT-B\/32&quot;, device=device)\n\nimage = preprocess(Image.open(&quot;CLIP.png&quot;)).unsqueeze(0).to(device)\ntext = clip.tokenize([&quot;a diagram&quot;, &quot;a dog&quot;, &quot;a cat&quot;]).to(device)\n\nwith torch.no_grad():\n    image_features = model.encode_image(image)\n    text_features = model.encode_text(text)\n\n    logits_per_image, logits_per_text = model(image, text)\n    probs = logits_per_image.softmax(dim=-1).cpu().numpy()\n\nprint(&quot;Label probs:&quot;, probs)  # prints: [[0.9927937  0.00421068 0.00299572]]<\/code><\/pre>\n<h2><img decoding=\"async\" src=\"https:\/\/img.icons8.com\/dusk\/64\/000000\/prize.png\" style=\"height:50px;display:inline\"> Credits<\/h2>\n<hr \/>\n<ul>\n<li>Icons made by <a href=\"https:\/\/www.flaticon.com\/authors\/becris\" title=\"Becris\">Becris<\/a> from <a href=\"https:\/\/www.flaticon.com\/\" title=\"Flaticon\">www.flaticon.com<\/a><\/li>\n<li>Icons from <a href=\"https:\/\/icons8.com\/\">Icons8.com<\/a> - <a href=\"https:\/\/icons8.com\">https:\/\/icons8.com<\/a><\/li>\n<li>Datasets from <a href=\"https:\/\/www.kaggle.com\/\">Kaggle<\/a> - <a href=\"https:\/\/www.kaggle.com\/\">https:\/\/www.kaggle.com\/<\/a><\/li>\n<li><a href=\"https:\/\/machinelearningmastery.com\/why-initialize-a-neural-network-with-random-weights\/\">Jason Brownlee - Why Initialize a Neural Network with Random Weights?<\/a><\/li>\n<li><a href=\"https:\/\/openai.com\/blog\/deep-double-descent\/\">OpenAI - Deep Double Descent<\/a><\/li>\n<li><a href=\"https:\/\/taldatech.github.io\">Tal Daniel<\/a><\/li>\n<\/ul>\n","protected":false},"excerpt":{"rendered":"<p>Learning Methods of Deep Learning create by Deepfinder  [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":2681,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[18,28],"tags":[],"class_list":["post-2679","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-18","category-28"],"_links":{"self":[{"href":"http:\/\/gnn.club\/index.php?rest_route=\/wp\/v2\/posts\/2679","targetHints":{"allow":["GET"]}}],"collection":[{"href":"http:\/\/gnn.club\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/gnn.club\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/gnn.club\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/gnn.club\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=2679"}],"version-history":[{"count":9,"href":"http:\/\/gnn.club\/index.php?rest_route=\/wp\/v2\/posts\/2679\/revisions"}],"predecessor-version":[{"id":2694,"href":"http:\/\/gnn.club\/index.php?rest_route=\/wp\/v2\/posts\/2679\/revisions\/2694"}],"wp:featuredmedia":[{"embeddable":true,"href":"http:\/\/gnn.club\/index.php?rest_route=\/wp\/v2\/media\/2681"}],"wp:attachment":[{"href":"http:\/\/gnn.club\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=2679"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/gnn.club\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=2679"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/gnn.club\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=2679"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}