{"id":313,"date":"2024-02-18T10:12:03","date_gmt":"2024-02-18T02:12:03","guid":{"rendered":"https:\/\/my.oindalvi.eu.org\/?p=313"},"modified":"2024-04-05T01:40:47","modified_gmt":"2024-04-04T17:40:47","slug":"313","status":"publish","type":"post","link":"https:\/\/my.di.cloudns.asia\/index.php\/2024\/02\/18\/313.html","title":{"rendered":"\u77ed\u6587\u672c\u8bed\u4e49\u5339\u914d\/\u6587\u672c\u76f8\u4f3c\u5ea6\u6846\u67b6(SimilarityNet, SimNet)\uff0c\u57fa\u4e8ebow_pairwise\u6a21\u5f0f\u53ca\u6846\u67b6\u539f\u7406\u4ecb\u7ecd"},"content":{"rendered":"<blockquote>\n<p>\u672c\u6587\u7531 <a href=\"http:\/\/ksria.com\/simpread\/\">\u7b80\u60a6 SimpRead<\/a> \u8f6c\u7801\uff0c \u539f\u6587\u5730\u5740 <a href=\"https:\/\/blog.csdn.net\/qq_33187136\/article\/details\/106770431\">blog.csdn.net<\/a><\/p>\n<\/blockquote>\n<h2>\u4e00\u3001\u7b80\u4ecb<\/h2>\n<p>\u77ed\u6587\u672c\u8bed\u4e49\u5339\u914d (SimilarityNet, SimNet) \u662f\u767e\u5ea6\u4e00\u4e2a\u8ba1\u7b97\u77ed\u6587\u672c\u76f8\u4f3c\u5ea6\u7684<a href=\"https:\/\/so.csdn.net\/so\/search?q=%E6%A1%86%E6%9E%B6&spm=1001.2101.3001.7020\">\u6846\u67b6<\/a>\uff0c\u53ef\u4ee5\u6839\u636e\u7528\u6237\u8f93\u5165\u7684\u4e24\u4e2a\u6587\u672c\uff0c\u8ba1\u7b97\u51fa\u76f8\u4f3c\u5ea6\u5f97\u5206\u3002<\/p>\n<h4>1.1 \u793a\u4f8b<\/h4>\n<pre><code>\u53e5\u5b501                \u53e5\u5b502              \u76f8\u4f3c\u5ea6\n\u8f66\u5934 \u5982\u4f55 \u653e\u7f6e \u8f66\u724c \u524d \u724c\u7167 \u600e\u4e48\u88c5    0.8512318730354309\n\u8f66\u5934 \u5982\u4f55 \u653e\u7f6e \u8f66\u724c \u5982\u4f55 \u529e\u7406 \u5317\u4eac \u8f66\u724c 0.8042252361774445\n\u8f66\u5934 \u5982\u4f55 \u653e\u7f6e \u8f66\u724c \u540e \u724c\u7167 \u600e\u4e48\u88c5    0.8347993791103363\n<\/code><\/pre>\n<p>\u867d\u7136\u4e09\u4e2a\u53e5\u5b50\u7684\u76f8\u4f3c\u5ea6\u533a\u5206\u5ea6\u4e0d\u662f\u5f88\u5927\uff0c\u4f46\u7ed3\u679c\u8fd8\u662f\u6b63\u786e\u7684\uff0c\u4e09\u4e2a\u53e5\u5b50\u53ea\u6709 \u201c\u524d\u724c\u7167\u600e\u4e48\u88c5\u201d \u548c\u201c\u8f66\u5934\u5982\u4f55\u653e\u7f6e\u8f66\u724c\u201d\u662f\u6700\u76f8\u4f3c\u7684\uff0c\u6240\u4ee5\u76f8\u4f3c\u5ea6\u76f8\u5bf9\u8f83\u9ad8\u3002<\/p>\n<h4>1.2 \u5c0f\u7ed3<\/h4>\n<ul>\n<li>1.1 \u79cd\u7684\u793a\u4f8b\u662f\u6211\u7528\u767e\u5ea6\u57fa\u4e8e\u5927\u89c4\u6a21\u8bed\u6599\u8bad\u7ec3\u5e76\u5f00\u6e90\u7684\u6a21\u578b simnet_bow_pairwise_pretrained_model \u63a8\u7406\u7684\uff0c\u8fd9\u4e2a\u6a21\u578b\u53ef\u4ee5\u4f5c\u4e3a\u9884\u8bad\u7ec3\u6a21\u578b\u7528\u81ea\u5df1\u7684\u8bed\u6599\u5728\u5b83\u4e0a\u9762\u8fdb\u884c\u5fae\u8c03\u3002<\/li>\n<li>\u53ef\u4ee5\u770b\u5230\u8f93\u5165\u7684\u53e5\u5b50\u90fd\u662f\u5206\u8bcd\u540e\u7684\uff0c\u8fd9\u4e5f\u662f SimNet \u9884\u5904\u7406\u8981\u505a\u7684\u5de5\u4f5c\u2014\u2014\u5206\u8bcd\u3002<\/li>\n<\/ul>\n<h2>\u4e8c\u3001\u4f7f\u7528<\/h2>\n<p>\u8be6\u89c1 <a href=\"https:\/\/github.com\/PaddlePaddle\/models\/tree\/release\/1.7\/PaddleNLP\/similarity_net\">SimNet \u6e90\u7801<\/a>\uff0c\u5b98\u65b9\u7684 readme \u4ecb\u7ecd\u7684\u6bd4\u8f83\u6e05\u695a\u4e86\u3002\u8fd9\u91cc\u8865\u5145\u8bf4\u660e\u51e0\u70b9\uff08\u53ef\u4ee5\u5148\u770b\u5b8c\u518d\u53bb\u770b\u5b98\u65b9\u8bf4\u660e\uff09\uff1a<\/p>\n<ol>\n<li>\u73af\u5883\u4f9d\u8d56<\/li>\n<\/ol>\n<ul>\n<li>\u8981\u6c42 Python 2 \u7248\u672c\u662f 2.7.15+\u3001Python 3 \u7248\u672c\u662f 3.5.1+\/3.6\/3.7<br \/>\n\u6211\u6d4b\u8bd5\u7528\u7684\u7248\u672c\u662f 3.7.4<\/li>\n<li>\u8981\u6c42\u6df1\u5ea6\u5b66\u4e60\u6846\u67b6 paddlepaddle1.6+\uff0c\u53c2\u8003<a href=\"https:\/\/www.paddlepaddle.org.cn\/install\/quick\">\u5b89\u88c5\u6307\u5357<\/a><br \/>\n\u6211\u6d4b\u8bd5\u7528\u7684\u7248\u672c\u662f 1.7.2.post107\uff0c107 \u8868\u793a cuda10,cudnn7\u3002\u56e0\u6b64\u6211\u7528\u7684\u662f gpu \u7248\u7684 paddle \u6846\u67b6\uff0c\u5177\u4f53\u7248\u672c\u6839\u636e\u81ea\u5df1\u7684\u914d\u7f6e\u9009\u62e9\uff0c\u53c2\u8003 [\u5b89\u88c5\u6307\u5357]<\/li>\n<li>\u63a8\u8350\u4f7f\u7528 conda \u7ba1\u7406\u73af\u5883<br \/>\n<code>conda create -n paddle python==3.7.4<\/code><br \/>\n\u7136\u540e\u6fc0\u6d3b\uff0c\u5230\u865a\u62df\u73af\u5883\u4e2d\u5b89\u88c5\u5176\u4ed6\u5e93<br \/>\n<code>conda activate paddle<\/code><\/li>\n<\/ul>\n<ol start=\"2\">\n<li>\u8f93\u5165\u5fc5\u987b\u5206\u8bcd<br \/>\n\u6a21\u578b\u8bad\u7ec3 \/ \u63a8\u7406\u7684\u8f93\u5165\u8bed\u6599\u90fd\u5fc5\u987b\u662f\u5206\u5b8c\u8bcd\u7684\uff0c\u4e0d\u7136\u5c31\u6ca1\u6709\u6548\u679c\uff08\u6a21\u578b\u5185\u90e8\u662f\u57fa\u4e8e\u8bcd\u7684 emb\uff09\uff0c\u5206\u8bcd\u5de5\u5177\u5728 similarity_net \u540c\u7ea7\u7684 shared_modules\/preprocess\/tokenizer \u91cc\uff0c\u4e5f\u53ef\u4ee5\u4f7f\u7528\u5176\u4ed6\u5206\u8bcd\u5de5\u5177\u4f8b\u5982 jieba\u3001hanlp \u7b49\u3002<\/li>\n<\/ol>\n<h2>\u4e09\u3001pairwise \u6a21\u5f0f<\/h2>\n<p>\u672c\u6587\u6211\u4ecb\u7ecd\u7684\u7528\u6cd5\u3001\u539f\u7406\u4ee5\u53ca\u6700\u5f00\u59cb\u7684\u4f8b\u5b50\u90fd\u662f\u57fa\u4e8e pairwise \u6a21\u5f0f\u7684<\/p>\n<h4>3.1 \u8bad\u7ec3\u96c6\u6570\u636e\u683c\u5f0f<\/h4>\n<p>\u53e5\u5b50 Q\\t \u53e5\u5b50 D+\\t \u53e5\u5b50 D-\uff0c\u5176\u4e2d Q \u548c D + \u662f\u76f8\u4f3c\u53e5\uff0cQ \u548c D &#8211; \u662f\u4e0d\u76f8\u4f3c\u53e5<\/p>\n<pre><code>\u8fd9\u4e2a\u4e0d\u6536\u8d39\u5427     \u8fd9\u4e2a\u662f\u514d\u8d39\u7684\u5427      \u8fd9\u4e2a\u4e0d\u597d\u7528\u5427 \n<\/code><\/pre>\n<h4>3.2 \u635f\u5931\u51fd\u6570<\/h4>\n<p>\u635f\u5931\u51fd\u6570\u4f7f\u7528 HingeLoss\uff0cS(Q,D+) \u8868\u793a Q \u548c D + \u7684\u5339\u914d\u5f97\u5206\uff08\u76f8\u4f3c\u5ea6\uff09<br \/>\n<code>max\u2061{0,margin-(S(Q,D+)-S(Q,D-))}<\/code><br \/>\n\u56e0\u6b64\uff0c\u4f18\u5316\u76ee\u6807\u662f\u4f7f\u5f97 Q \u548c D + \u7684\u76f8\u4f3c\u5ea6\u4e0e Q \u548c D &#8211; \u7684\u76f8\u4f3c\u5ea6\u7684\u5dee\u5f02\u6700\u5927\uff0c\u4e5f\u5c31\u662f\u8ba9\u6b63\u4f8b\u548c\u8d1f\u4f8b\u7684\u5f97\u5206\u5dee\u5f02\u6700\u5927\u3002\u8d85\u53c2\u6570 margin \u7684\u503c\uff0c\u6839\u636e\u60c5\u51b5\u53ef\u4ee5\u9002\u5f53\u8c03\u6574\u3002<\/p>\n<h2>\u56db\u3001\u539f\u7406\uff08\u57fa\u4e8e bow \u8bcd\u888b\u6a21\u578b\uff09<\/h2>\n<p>\u5982\u679c\u5df2\u7ecf\u6bd4\u8f83\u719f\u6089 SimNet \u7684\u4f7f\u7528\u4e86\uff0c\u53ef\u4ee5\u8fdb\u4e00\u6b65\u4e86\u89e3\u5b83\u7684\u539f\u7406\uff0c\u4ee5\u6839\u636e\u81ea\u5df1\u7684\u9700\u6c42\u6539\u8fdb\u5177\u4f53\u7684\u7f51\u7edc\u5c42\u7ed3\u6784\u3002<\/p>\n<h4>4.1 \u539f\u7406\u7b80\u56fe<\/h4>\n<p><div class='fancybox-wrapper lazyload-container-unload' data-fancybox='post-images' href='https:\/\/my.di.cloudns.asia\/wp-content\/uploads\/2024\/02\/post-313-65d16777b0f47.png'><img class=\"lazyload lazyload-style-1\" src=\"data:image\/svg+xml;base64,PCEtLUFyZ29uTG9hZGluZy0tPgo8c3ZnIHdpZHRoPSIxIiBoZWlnaHQ9IjEiIHhtbG5zPSJodHRwOi8vd3d3LnczLm9yZy8yMDAwL3N2ZyIgc3Ryb2tlPSIjZmZmZmZmMDAiPjxnPjwvZz4KPC9zdmc+\"  decoding=\"async\" data-original=\"https:\/\/my.di.cloudns.asia\/wp-content\/uploads\/2024\/02\/post-313-65d16777b0f47.png\" src=\"data:image\/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAYAAAAfFcSJAAAAAXNSR0IArs4c6QAAAARnQU1BAACxjwv8YQUAAAAJcEhZcwAADsQAAA7EAZUrDhsAAAANSURBVBhXYzh8+PB\/AAffA0nNPuCLAAAAAElFTkSuQmCC\" alt=\"\" \/><\/div><br \/>\n\u6839\u636e SimNet(\u57fa\u4e8e bow \u8bcd\u888b\u6a21\u578b)\uff0c\u6211\u753b\u4e86\u4e00\u4e2a\u7b80\u56fe (\u5982\u4e0a\uff0c\u8f6f\u4ef6: XMind)\uff0c\u6846\u67b6\u4e3b\u8981\u6d41\u7a0b\u4e3a\uff1a<\/p>\n<ol>\n<li>\u8f93\u5165\u5c42\uff1a<br \/>\n\u5c06\u5206\u5b8c\u8bcd\u7684\u53e5\u5b50\uff0c\u9996\u5148\u67e5\u8bcd\u8868 (term2id)\uff0c\u5c06\u8bcd\u8f6c\u6362\u4e3a\u552f\u4e00\u7684 id\uff08\u5b58\u50a8\u5728\u5f20\u91cf tensor \u91cc\uff09<br \/>\n\u4f8b\u5982\uff1a<code>[&quot;\u4f60\u597d \u540c\u5b66&quot;]<\/code>\u2013&gt; <code>[12345 23456]<\/code><\/li>\n<li>\u8bcd\u5d4c\u5165\u5c42\uff1a<br \/>\n\u5c06\u5b58\u50a8 id \u7684\u5f20\u91cf tensor \u901a\u8fc7\u8bcd\u5d4c\u5165\uff0c\u6620\u5c04\u4e3a\u8bcd\u5411\u91cf emb<\/li>\n<li>\u8868\u793a\u5c42\uff1a<br \/>\n\u5c06\u8bcd\u5411\u91cf emb \u901a\u8fc7\u6c60\u5316\u5c42\u538b\u7f29\u5230\u6700\u540e\u4e00\u7ef4\uff08sum \u52a0\u548c\u7684\u65b9\u5f0f\uff09\uff0c\u7136\u540e\u518d\u8fdb\u884c softsign \u6fc0\u6d3b\u51fd\u6570\u6fc0\u6d3b<\/li>\n<li>\u5339\u914d\u5c42\uff1a<br \/>\n\u4e0a\u4e00\u6b65\u7684\u6fc0\u6d3b\u540e\u7684\u5f20\u91cf tensor\uff0c\u9996\u5148\u901a\u8fc7\u4e00\u4e2a\u5168\u8fde\u63a5\u5c42\uff08\u5927\u6982\u662f\u7528\u6765\u589e\u5f3a\u8bed\u4e49\u8868\u793a\u5427\uff09\uff0c\u7136\u540e\u5c06\u7ecf\u5386\u540c\u6837\u8fc7\u7a0b\u7684\u4e24\u4e2a\u53e5\u5b50\u7684\u5411\u91cf\u8fdb\u884c cos_sim\uff08\u4f59\u5f26\u76f8\u4f3c\u5ea6\uff09\u8ba1\u7b97\uff0c\u5f97\u5230\u76f8\u4f3c\u5ea6<\/li>\n<\/ol>\n<h4>4.2 \u6539\u8fdb\u601d\u8def<\/h4>\n<p>\u4ece\u539f\u7406\u53ef\u4ee5\u770b\u51fa\u6765\uff0cSimNet(\u57fa\u4e8e bow \u8bcd\u888b\u6a21\u578b) \u7684\u7ed3\u6784\u662f\u6bd4\u8f83\u7b80\u5355\u7684\uff0c\u4f46\u6709\u767e\u5ea6\u5728\u8be5\u6846\u67b6\u4e0b\u5f00\u6e90\u7684\u9884\u8bad\u7ec3\u6a21\u578b\uff08\u57fa\u4e8e bow_pairwise\uff09+ \u9884\u5904\u7406<a href=\"https:\/\/so.csdn.net\/so\/search?q=%E5%88%86%E8%AF%8D&spm=1001.2101.3001.7020\">\u5206\u8bcd<\/a>\uff0c\u6700\u7ec8\u6548\u679c\u8fd8\u662f\u53ef\u4ee5\u7684\uff0c\u4f46\u53ef\u80fd\u4e0d\u9002\u5408\u9ad8\u7cbe\u5ea6\u7684\u5e94\u7528\u573a\u666f\u3002\u5982\u679c\u9700\u8981\u6539\u8fdb\uff0c\u53ef\u4ee5\u4ece\u4ee5\u4e0b\u51e0\u70b9\u8003\u8651\uff1a<\/p>\n<ul>\n<li>\u8868\u793a\u5c42\u4f7f\u7528 CNN\u3001LSTM \u7b49\uff0c\u5bf9\u8bed\u4e49\u7279\u5f81\u63d0\u53d6\u7684\u6548\u679c\u66f4\u597d\uff0c\u5b98\u65b9\u4e5f\u7ed9\u5199\u597d\u4e86\u8fd9\u51e0\u79cd\u65b9\u5f0f\uff0c\u76f4\u63a5\u6539\u53c2\u6570 config_path \u5c31\u53ef\u4ee5\u6362\u4e86<\/li>\n<li>\u5339\u914d\u5c42\u4e0d\u76f4\u63a5\u5bf9\u7279\u5f81\u5411\u91cf\u8fdb\u884c cos_sim\uff08\u4f59\u5f26\u76f8\u4f3c\u5ea6\uff09\u8ba1\u7b97\uff0c\u800c\u662f\u4f7f\u7528\u591a\u5c42\u611f\u77e5\u673a MLP \u62df\u5408\u51fa\u4e00\u4e2a\u76f8\u4f3c\u5ea6<\/li>\n<li>\u81ea\u5b9a\u4e49\u7f51\u7edc\u5c42\uff0c\u4e3b\u8981\u662f\u9488\u5bf9\u8868\u793a\u5c42<\/li>\n<\/ul>\n<h2>\u603b\u7ed3<\/h2>\n<p>SimNet \u662f\u4e00\u4e2a\u77ed\u6587\u672c\u8bed\u4e49\u76f8\u4f3c\u5ea6\u6846\u67b6\uff0c\u6a21\u578b\u6bd4\u8f83\u7b80\u5355\u5bb9\u6613\u7406\u89e3\uff0c\u53ef\u4ee5\u5728\u719f\u6089\u4f7f\u7528\u65b9\u5f0f\u7684\u57fa\u7840\u4e0a\u8fdb\u884c\u5fae\u8c03 \/ \u6539\u8fdb\u3002<br \/>\nSimNet \u7684\u8ba8\u8bba\u8fd8\u662f\u6bd4\u8f83\u5c11\u7684\uff0c\u53ef\u80fd\u662f\u4f7f\u7528\u7684\u4eba\u6bd4\u8f83\u5c11\u5427\u3002\u60f3\u4e86\u89e3\u66f4\u591a SimNet \u7684\u4ecb\u7ecd\u53ef\u4ee5\u53c2\u8003 <a href=\"https:\/\/www.jiqizhixin.com\/articles\/2017-06-15-5\">SimNet \u4f18\u79c0\u535a\u5ba2<\/a>\u3002<br \/>\n\u5bf9\u7cbe\u5ea6\u8981\u6c42\u66f4\u9ad8\u7684\u573a\u666f\u53ef\u4ee5\u8003\u8651\u4f7f\u7528 BERT(\u6216\u8005 ERNIE) \u8fd9\u79cd\u9884\u8bad\u7ec3\u8bed\u8a00\u6a21\u578b\uff0c\u6548\u679c\u63d0\u5347\u663e\u8457\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u672c\u6587\u7531 \u7b80\u60a6 SimpRead \u8f6c\u7801\uff0c \u539f\u6587\u5730\u5740 blog.csdn.net \u4e00\u3001\u7b80\u4ecb \u77ed\u6587\u672c\u8bed\u4e49\u5339\u914d (Si [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[8],"tags":[],"class_list":["post-313","post","type-post","status-publish","format-standard","hentry","category-deeplearning"],"_links":{"self":[{"href":"https:\/\/my.di.cloudns.asia\/index.php\/wp-json\/wp\/v2\/posts\/313","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/my.di.cloudns.asia\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/my.di.cloudns.asia\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/my.di.cloudns.asia\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/my.di.cloudns.asia\/index.php\/wp-json\/wp\/v2\/comments?post=313"}],"version-history":[{"count":3,"href":"https:\/\/my.di.cloudns.asia\/index.php\/wp-json\/wp\/v2\/posts\/313\/revisions"}],"predecessor-version":[{"id":326,"href":"https:\/\/my.di.cloudns.asia\/index.php\/wp-json\/wp\/v2\/posts\/313\/revisions\/326"}],"wp:attachment":[{"href":"https:\/\/my.di.cloudns.asia\/index.php\/wp-json\/wp\/v2\/media?parent=313"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/my.di.cloudns.asia\/index.php\/wp-json\/wp\/v2\/categories?post=313"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/my.di.cloudns.asia\/index.php\/wp-json\/wp\/v2\/tags?post=313"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}