{"id":8570,"date":"2024-06-04T08:01:01","date_gmt":"2024-06-04T00:01:01","guid":{"rendered":""},"modified":"2024-06-04T08:01:01","modified_gmt":"2024-06-04T00:01:01","slug":"\u8de8\u8bed\u8a00\u4ea4\u6d41_recreational function\u8bed\u8a00\u5b66","status":"publish","type":"post","link":"https:\/\/mushiming.com\/8570.html","title":{"rendered":"\u8de8\u8bed\u8a00\u4ea4\u6d41_recreational function\u8bed\u8a00\u5b66"},"content":{"rendered":"
\n

 \ud83d\udd0e\u5927\u5bb6\u597d\uff0c\u6211\u662fSonhhxg_\u67d2\uff0c\u5e0c\u671b\u4f60\u770b\u5b8c\u4e4b\u540e\uff0c\u80fd\u5bf9\u4f60\u6709\u6240\u5e2e\u52a9\uff0c\u4e0d\u8db3\u8bf7\u6307\u6b63\uff01\u5171\u540c\u5b66\u4e60\u4ea4\u6d41\ud83d\udd0e<\/p>\n

\ud83d\udcdd\u4e2a\u4eba\u4e3b\u9875\uff0dSonhhxg_\u67d2\u7684\u535a\u5ba2_CSDN\u535a\u5ba2 \ud83d\udcc3<\/p>\n

\ud83c\udf81\u6b22\u8fce\u5404\u4f4d\u2192\u70b9\u8d5e\ud83d\udc4d + \u6536\u85cf\u2b50\ufe0f + \u7559\u8a00\ud83d\udcdd\u200b<\/p>\n

\ud83d\udce3\u7cfb\u5217\u4e13\u680f - \u673a\u5668\u5b66\u4e60\u3010ML\u3011 \u81ea\u7136\u8bed\u8a00\u5904\u7406\u3010NLP\u3011  \u6df1\u5ea6\u5b66\u4e60\u3010DL\u3011<\/p>\n

\"\u8de8\u8bed\u8a00\u4ea4\u6d41_recreational\u200b<\/p>\n

 \ud83d\udd8dforeword<\/h4>\n

\u2714\u8bf4\u660e\u21e2\u672c\u4eba\u8bb2\u89e3\u4e3b\u8981\u5305\u62ecPython\u3001\u673a\u5668\u5b66\u4e60\uff08ML\uff09\u3001\u6df1\u5ea6\u5b66\u4e60\uff08DL\uff09\u3001\u81ea\u7136\u8bed\u8a00\u5904\u7406\uff08NLP\uff09\u7b49\u5185\u5bb9\u3002<\/p>\n

\u5982\u679c\u4f60\u5bf9\u8fd9\u4e2a\u7cfb\u5217\u611f\u5174\u8da3\u7684\u8bdd\uff0c\u53ef\u4ee5\u5173\u6ce8\u8ba2\u9605\u54df\ud83d\udc4b<\/p>\n<\/blockquote>\n

\u6587\u7ae0\u76ee\u5f55<\/strong><\/p>\n

\n

\u6280\u672f\u8981\u6c42<\/p>\n

\u7ffb\u8bd1\u8bed\u8a00\u5efa\u6a21\u4e0e\u8de8\u8bed\u8a00\u77e5\u8bc6\u5171\u4eab<\/p>\n

XLM \u548c mBERT<\/p>\n

mBERT<\/p>\n

XLM<\/p>\n

\u8de8\u8bed\u8a00\u76f8\u4f3c\u5ea6\u4efb\u52a1<\/p>\n

\u8de8\u8bed\u8a00\u6587\u672c\u76f8\u4f3c\u5ea6<\/p>\n

\u53ef\u89c6\u5316\u8de8\u8bed\u8a00\u6587\u672c\u76f8\u4f3c\u6027<\/p>\n

\u8de8\u8bed\u8a00\u5206\u7c7b<\/p>\n

\u8de8\u8bed\u8a00\u96f6\u6837\u672c\u5b66\u4e60<\/p>\n

\u591a\u8bed\u8a00\u6a21\u578b\u7684\u57fa\u672c\u9650\u5236<\/p>\n

\u5fae\u8c03\u591a\u8bed\u8a00\u6a21\u578b\u7684\u6027\u80fd<\/p>\n

\u6982\u62ec<\/p>\n<\/blockquote>\n


\n

\u5230\u76ee\u524d\u4e3a\u6b62\uff0c\u60a8\u5df2\u7ecf\u4e86\u89e3\u4e86\u5f88\u591a\u5173\u4e8e\u57fa\u4e8e\u8f6c\u6362\u5668\u7684\u67b6\u6784\uff0c\u4ece\u4ec5\u7f16\u7801\u5668\u6a21\u578b\u5230\u4ec5\u89e3\u7801\u5668\u6a21\u578b\uff0c\u4ece\u9ad8\u6548\u8f6c\u6362\u5668\u5230\u957f\u4e0a\u4e0b\u6587\u8f6c\u6362\u5668\u3002\u60a8\u8fd8\u4e86\u89e3\u4e86\u57fa\u4e8e\u8fde\u4f53\u7f51\u7edc\u7684\u8bed\u4e49\u6587\u672c\u8868\u793a\u3002\u4f46\u662f\uff0c\u6211\u4eec\u6839\u636e\u5355\u8bed\u95ee\u9898\u8ba8\u8bba\u4e86\u6240\u6709\u8fd9\u4e9b\u6a21\u578b\u3002\u6211\u4eec\u5047\u8bbe\u8fd9\u4e9b\u6a21\u578b\u53ea\u7406\u89e3\u4e00\u79cd\u8bed\u8a00\uff0c\u5e76\u4e14\u4e0d\u80fd\u5bf9\u6587\u672c\u6709\u4e00\u822c\u7684\u7406\u89e3\uff0c\u65e0\u8bba\u8bed\u8a00\u672c\u8eab\u5982\u4f55\u3002\u4e8b\u5b9e\u4e0a\uff0c\u5176\u4e2d\u4e00\u4e9b\u6a21\u578b\u5177\u6709\u591a\u8bed\u8a00\u53d8\u4f53\uff1b\u6765\u81ea\u8f6c\u6362\u5668\u7684\u591a\u8bed\u8a00\u53cc\u5411\u7f16\u7801\u5668\u8868\u793a<\/strong>( mBERT<\/strong> )\u3001\u591a\u8bed\u8a00\u6587\u672c\u5230\u6587\u672c\u4f20\u8f93\u8f6c\u6362<\/strong>\u5668( mT5<\/strong> ) \u548c\u591a\u8bed\u8a00\u53cc\u5411\u548c\u81ea\u56de\u5f52\u8f6c\u6362<\/strong>\u5668( mBART<\/strong> )\uff0c\u4ec5\u4e3e\u51e0\u4f8b\u3002\u53e6\u4e00\u65b9\u9762\uff0c\u4e00\u4e9b\u6a21\u578b\u662f\u4e13\u95e8\u4e3a\u591a\u8bed\u8a00\u76ee\u7684\u800c\u8bbe\u8ba1\u7684\uff0c\u8bad\u7ec3\u6709\u8de8\u8bed\u8a00\u76ee\u6807\u3002\u4f8b\u5982\uff0c\u8de8\u8bed\u8a00\u8bed\u8a00\u6a21\u578b<\/strong>\uff08XLM<\/strong>\uff09\u5c31\u662f\u8fd9\u6837\u4e00\u79cd\u65b9\u6cd5\uff0c\u672c\u7ae0\u5c06\u5bf9\u6b64\u8fdb\u884c\u8be6\u7ec6\u4ecb\u7ecd\u3002<\/span><\/span><\/p>\n

\u5728\u672c\u7ae0\u4e2d\uff0c\u5c06\u4ecb\u7ecd\u8bed\u8a00\u4e4b\u95f4\u77e5\u8bc6\u5171\u4eab\u7684\u6982\u5ff5\uff0c\u5b57\u8282\u5bf9\u7f16\u7801<\/strong>\uff08BPE<\/strong>\uff09\u5bf9\u6807\u8bb0\u5316\u90e8\u5206\u7684\u5f71\u54cd\u4e5f\u662f\u53e6\u4e00\u4e2a\u91cd\u8981\u7684\u4e3b\u9898\uff0c\u4ee5\u5b9e\u73b0\u66f4\u597d\u7684\u8f93\u5165\u3002\u5c06\u8be6\u7ec6\u4ecb\u7ecd\u4f7f\u7528\u8de8\u8bed\u8a00\u81ea\u7136\u8bed\u8a00\u63a8\u7406<\/strong>( XNLI<\/strong> ) \u8bed\u6599\u5e93\u7684\u8de8\u8bed\u8a00\u53e5\u5b50\u76f8\u4f3c\u5ea6\u3002\u8bf8\u5982\u8de8\u8bed\u8a00\u5206\u7c7b\u548c\u5229\u7528\u8de8\u8bed\u8a00\u53e5\u5b50\u8868\u793a\u6765\u8bad\u7ec3\u4e00\u79cd\u8bed\u8a00\u548c\u6d4b\u8bd5\u53e6\u4e00\u79cd\u8bed\u8a00\u7b49\u4efb\u52a1\u5c06\u901a\u8fc7\u81ea\u7136\u8bed\u8a00\u5904\u7406<\/strong>( NLP<\/strong> ) \u4e2d\u73b0\u5b9e\u751f\u6d3b\u95ee\u9898\u7684\u5177\u4f53\u793a\u4f8b\u6765\u5448\u73b0\uff0c\u4f8b\u5982\u591a\u8bed\u8a00\u610f\u56fe\u5206\u7c7b\u3002<\/span><\/span><\/p>\n

\u7b80\u800c\u8a00\u4e4b\uff0c\u60a8\u5c06\u5728\u672c\u7ae0\u4e2d\u5b66\u4e60\u4ee5\u4e0b\u4e3b\u9898\uff1a<\/span><\/span><\/p>\n

    \n
  • \u7ffb\u8bd1\u8bed\u8a00\u5efa\u6a21\u4e0e\u8de8\u8bed\u8a00\u77e5\u8bc6\u5171\u4eab<\/li>\n
  • XLM \u548c mBERT<\/li>\n
  • \u8de8\u8bed\u8a00\u76f8\u4f3c\u5ea6\u4efb\u52a1<\/li>\n
  • \u8de8\u8bed\u8a00\u5206\u7c7b<\/li>\n
  • \u8de8\u8bed\u8a00\u96f6\u6837\u672c\u5b66\u4e60<\/li>\n
  • \u591a\u8bed\u8a00\u6a21\u578b\u7684\u57fa\u672c\u9650\u5236<\/li>\n<\/ul>\n

    \u6280\u672f\u8981\u6c42<\/span><\/span><\/h2>\n

    \u6211\u4eec\u5c06\u4f7f\u7528 Jupyter Notebook \u8fd0\u884c\u9700\u8981 Python 3.6.0+ \u7684\u7f16\u7801\u7ec3\u4e60\uff0c\u5e76\u4e14\u9700\u8981\u5b89\u88c5\u4ee5\u4e0b\u8f6f\u4ef6\u5305\uff1a<\/span><\/span><\/p>\n

      \n
    • tensorflow<\/strong><\/li>\n
    • pytorch<\/strong><\/li>\n
    • transformers >=4.00<\/strong><\/li>\n
    • datasets<\/strong><\/li>\n
    • sentence-transformers<\/strong><\/li>\n
    • umap-learn<\/strong><\/li>\n
    • openpyxl<\/strong><\/li>\n<\/ul>\n

      \n

      \u7ffb\u8bd1\u8bed\u8a00\u5efa\u6a21\u4e0e\u8de8\u8bed\u8a00\u77e5\u8bc6\u5171\u4eab<\/span><\/span><\/h2>\n

      \u5230\u76ee\u524d\u4e3a\u6b62\uff0c\u4f60\u5df2\u7ecf\u5b66\u4f1a\u4e86\u5173\u4e8e\u63a9\u7801\u8bed\u8a00\u5efa\u6a21<\/strong>( MLM<\/strong> ) \u4f5c\u4e3a\u5b8c\u5f62\u586b\u7a7a\u4efb\u52a1\u3002\u7136\u800c\uff0c\u4f7f\u7528\u795e\u7ecf\u7f51\u7edc\u7684\u8bed\u8a00\u5efa\u6a21\u6839\u636e\u65b9\u6cd5\u672c\u8eab\u53ca\u5176\u5b9e\u9645\u7528\u9014\u5206\u4e3a\u4e09\u7c7b\uff0c\u5982\u4e0b\u6240\u793a\uff1a<\/span><\/span><\/p>\n

        \n
      • MLM<\/li>\n
      • \u56e0\u679c\u8bed\u8a00\u5efa\u6a21<\/strong>( CLM<\/strong> )<\/li>\n
      • \u7ffb\u8bd1\u8bed\u8a00\u5efa\u6a21<\/strong>( TLM<\/strong> )<\/li>\n<\/ul>\n

        \u4e5f\u662f\u9700\u8981\u6ce8\u610f\u7684\u662f\uff0c\u8fd8\u6709\u5176\u4ed6\u9884\u8bad\u7ec3\u65b9\u6cd5\uff0c\u4f8b\u5982Next Sentence Prediction<\/strong> ( NSP<\/strong> ) \u548cSentence Order Prediction<\/strong> ( SOP<\/strong> )\uff0c\u4f46\u662f\u6211\u4eec\u53ea\u8003\u8651\u4e86\u57fa\u4e8e\u6807\u8bb0\u7684\u8bed\u8a00\u5efa\u6a21\u3002\u8fd9\u4e09\u79cd\u662f\u6587\u732e\u4e2d\u4f7f\u7528\u7684\u4e3b\u8981\u65b9\u6cd5\u3002<\/span><\/span>MLM<\/strong>,\u63cf\u8ff0\u5e76\u5728\u524d\u51e0\u7ae0\u4e2d\u8be6\u7ec6\u4ecb\u7ecd\u8fc7\uff0c\u662f\u4e00\u4e2a\u975e\u5e38\u63a5\u8fd1\u8bed\u8a00\u5b66\u4e60\u4e2d\u7684\u5b8c\u5f62\u586b\u7a7a\u4efb\u52a1\u7684\u6982\u5ff5\u3002<\/span><\/span><\/p>\n

        CLM<\/strong>\u662f\u901a\u8fc7\u9884\u6d4b\u4e0b\u4e00\u4e2a\u6807\u8bb0\u6765\u5b9a\u4e49\uff0c\u7136\u540e\u662f\u4e00\u4e9b\u5148\u524d\u7684\u6807\u8bb0\u3002\u4f8b\u5982\uff0c\u5982\u679c\u60a8\u770b\u5230\u4ee5\u4e0b\u4e0a\u4e0b\u6587\uff0c\u60a8\u53ef\u4ee5\u8f7b\u677e\u9884\u6d4b\u4e0b\u4e00\u4e2a\u6807\u8bb0\uff1a<\/span><\/span><\/p>\n

        <s> \u53d8\u5f62\u91d1\u521a\u6539\u53d8\u4e86\u81ea\u7136\u8bed\u8a00\u2026\u2026<\/em><\/span><\/span><\/p>\n

        \u5982\u60a8\u6240\u89c1\uff0c\u53ea\u6709\u6700\u540e\u4e00\u4e2a\u6807\u8bb0\u88ab\u5c4f\u853d\uff0c\u5e76\u4e14\u4e4b\u524d\u7684\u6807\u8bb0\u88ab\u63d0\u4f9b\u7ed9\u6a21\u578b\u4ee5\u9884\u6d4b\u6700\u540e\u4e00\u4e2a\u6807\u8bb0\u3002\u6b64\u4ee4\u724c\u5c06\u88ab\u5904\u7406<\/em>\uff0c\u5982\u679c\u518d\u6b21\u5411\u60a8\u63d0\u4f9b\u5e26\u6709\u6b64\u4ee4\u724c\u7684\u4e0a\u4e0b\u6587\uff0c\u60a8\u53ef\u80fd\u4f1a\u4ee5\u201c<\/s>\u201d<\/em>\u4ee4\u724c\u7ed3\u675f\u5b83\u3002\u4e3a\u4e86\u5bf9\u8fd9\u79cd\u65b9\u6cd5\u8fdb\u884c\u826f\u597d\u7684\u8bad\u7ec3\uff0c\u4e0d\u9700\u8981\u63a9\u76d6\u7b2c\u4e00\u4e2a\u6807\u8bb0\uff0c\u56e0\u4e3a\u6a21\u578b\u5c06\u53ea\u6709\u4e00\u4e2a\u53e5\u5b50\u5f00\u59cb\u6807\u8bb0\u6765\u4ece\u4e2d\u751f\u6210\u4e00\u4e2a\u53e5\u5b50\u3002\u8fd9\u53e5\u8bdd\u53ef\u4ee5\u662f\u4efb\u4f55\u4e1c\u897f\uff01\u8fd9\u662f\u4e00\u4e2a\u4f8b\u5b50\uff1a<\/span><\/span><\/p>\n

        <s> \u2026<\/em><\/span><\/span><\/p>\n

        \u4f60\u4f1a\u4ece\u4e2d\u9884\u6d4b\u4ec0\u4e48\uff1f\u5b83\u53ef\u4ee5\u662f\u5b57\u9762\u4e0a\u7684\u4efb\u4f55\u4e1c\u897f\u3002\u4e3a\u4e86\u5f97\u5230\u66f4\u597d\u7684\u8bad\u7ec3\u548c\u66f4\u597d\u7684\u7ed3\u679c\uff0c\u81f3\u5c11\u9700\u8981\u7ed9\u51fa\u7b2c\u4e00\u4e2atoken\uff0c\u4f8b\u5982\uff1a<\/span><\/span><\/p>\n

        <s> \u53d8\u5f62\u91d1\u521a\u2026\u2026<\/em><\/span><\/span><\/p>\n

        \u5e76\u4e14\u9700\u8981\u6a21\u578b\u6765\u9884\u6d4b\u53d8\u5316<\/em>\uff1b\u7ed9\u5b83\u53d8\u5f62\u91d1\u521a\u6539\u53d8\u540e......<\/em>\u5b83\u9700\u8981\u9884\u6d4b\uff0c<\/em>\u7b49\u7b49\u3002\u8fd9\u79cd\u65b9\u6cd5\u975e\u5e38\u7c7b\u4f3c\u4e8e N-gram \u548c\u57fa\u4e8e\u957f\u77ed\u671f\u8bb0\u5fc6<\/strong>( LSTM<\/strong> ) \u7684\u65b9\u6cd5\uff0c\u56e0\u4e3a\u5b83\u662f\u57fa\u4e8e\u6982\u7387P(wn|wn-1, wn-2 ,\u2026,w0)<\/strong>\u5176\u4e2dwn<\/strong>\u662f\u8981\u9884\u6d4b\u7684\u6807\u8bb0\uff0c\u5176\u4f59\u7684\u662f\u5b83\u4e4b\u524d\u7684\u6807\u8bb0\u3002\u5177\u6709\u6700\u5927\u6982\u7387\u7684\u4ee4\u724c\u662f\u9884\u6d4b\u7684\u4ee4\u724c\u3002<\/span><\/span><\/p>\n

        \u8fd9\u4e9b\u662f\u7528\u4e8e\u5355\u8bed\u6a21\u578b\u7684\u76ee\u6807\u3002\u90a3\u4e48\uff0c\u8de8\u8bed\u8a00\u6a21\u578b\u53ef\u4ee5\u505a\u4ec0\u4e48\u5462\uff1f\u7b54\u6848\u662fTLM<\/strong>\uff0c\u5b83\u4e0e MLM \u975e\u5e38\u76f8\u4f3c\uff0c\u53ea\u662f\u6709\u4e00\u4e9b\u53d8\u5316\u3002\u4e0d\u662f\u4ece\u5355\u4e00\u8bed\u8a00\u7ed9\u51fa\u4e00\u4e2a\u53e5\u5b50\uff0c\u800c\u662f\u5c06\u4e00\u4e2a\u53e5\u5b50\u5bf9\u7528\u4e0d\u540c\u8bed\u8a00\u7684\u6a21\u578b\u7ed9\u51fa\uff0c\u7531\u4e00\u4e2a\u7279\u6b8a\u7684\u6807\u8bb0\u5206\u9694\u3002\u8be5\u6a21\u578b\u9700\u8981\u9884\u6d4b\u88ab\u5c4f\u853d\u7684\u6807\u8bb0\uff0c\u8fd9\u4e9b\u6807\u8bb0\u5728\u4efb\u4f55\u8fd9\u4e9b\u8bed\u8a00\u4e2d\u90fd\u88ab\u968f\u673a\u5c4f\u853d\u3002<\/span><\/span><\/p>\n

        \u4ee5\u4e0b\u53e5\u5b50\u5bf9\u662f\u6b64\u7c7b\u4efb\u52a1\u7684\u793a\u4f8b\uff1a<\/span><\/span><\/p>\n

        \n
        \n \"\u8de8\u8bed\u8a00\u4ea4\u6d41_recreational\n <\/div>\n<\/div>\n

        \u56fe 9.1 \u2013 \u571f\u8033\u5176\u8bed\u548c\u82f1\u8bed\u4e4b\u95f4\u7684\u8de8\u8bed\u8a00\u5173\u7cfb\u793a\u4f8b<\/span><\/span><\/p>\n

        \u7ed9\u5b9a\u8fd9\u4e24\u4e2a\u63a9\u7801\u53e5\u5b50\uff0c\u6a21\u578b\u9700\u8981\u9884\u6d4b\u4e22\u5931\u7684\u6807\u8bb0\u3002\u5728\u6b64\u4efb\u52a1\u4e2d\uff0c\u5728\u67d0\u4e9b\u60c5\u51b5\u4e0b\uff0c\u6a21\u578b\u53ef\u4ee5\u8bbf\u95ee\u8be5\u5bf9\u4e2d\u7684\u4e00\u79cd\u8bed\u8a00\u4e2d\u7f3a\u5c11\u7684\u6807\u8bb0\uff08\u4f8b\u5982\uff0c\u5206\u522b\u5728\u56fe 9.1\u4e2d\u7684\u53e5\u5b50\u5bf9\u4e2d\u7684<\/em>do\u011fal<\/strong>\u548clanguage<\/strong>\uff09\u3002<\/span><\/span><\/p>\n

        \u4f5c\u4e3a\u53e6\u4e00\u4e2a\u793a\u4f8b\uff0c\u60a8\u53ef\u4ee5\u4ece\u6ce2\u65af\u8bed\u548c\u571f\u8033\u5176\u8bed\u53e5\u5b50\u4e2d\u770b\u5230\u540c\u4e00\u5bf9\u3002\u5728\u7b2c\u4e8c\u53e5\u4e2d\uff0cde\u011fi\u015ftirdiler<\/strong>\u6807\u8bb0\u53ef\u4ee5\u5728\u7b2c\u4e00\u53e5\u4e2d\u51fa\u73b0\u591a\u4e2a\u6807\u8bb0\uff08\u4e00\u4e2a\u88ab\u5c4f\u853d\uff09\u3002\u5728\u4ee5\u4e0b\u793a\u4f8b\u4e2d\uff0c\u5355\u8bcd\u062a\u063a\u06cc\u06cc\u0631<\/strong>\u7f3a\u5931\uff0c\u4f46de\u011fi\u015ftirdiler<\/strong>\u7684\u542b\u4e49\u662f\u062a\u063a\u06cc\u06cc\u0631 \u062f\u0627\u062f\u0646\u062f <\/strong>\u3002<\/strong>\uff1a<\/span><\/span><\/p>\n

        \n
        \n

        \"\u8de8\u8bed\u8a00\u4ea4\u6d41_recreational<\/p>\n<\/p><\/div>\n<\/div>\n

        \u56fe 9.2 \u2013 \u6ce2\u65af\u8bed\u548c\u571f\u8033\u5176\u8bed\u4e4b\u95f4\u7684\u8de8\u8bed\u8a00\u5173\u7cfb\u793a\u4f8b<\/span><\/span><\/p>\n

        \u56e0\u6b64\uff0c\u6a21\u578b\u53ef\u4ee5\u5b66\u4e60\u8fd9\u4e9b\u542b\u4e49\u4e4b\u95f4\u7684\u6620\u5c04\u3002\u5c31\u50cf\u7ffb\u8bd1\u6a21\u578b\u4e00\u6837\uff0c\u6211\u4eec\u7684 TLM \u4e5f\u5fc5\u987b\u5b66\u4e60\u8bed\u8a00\u4e4b\u95f4\u7684\u8fd9\u4e9b\u590d\u6742\u6027\uff0c\u56e0\u4e3a\u673a\u5668\u7ffb\u8bd1<\/strong>( MT<\/strong> ) \u662f\u4e0d\u4ec5\u4ec5\u662f\u4ee4\u724c\u5230\u4ee4\u724c\u7684\u6620\u5c04\u3002<\/span><\/span><\/p>\n

        XLM \u548c mBERT<\/span><\/span><\/h2>\n

        \u6211\u4eec\u9009\u62e9\u4e86\u4e24\u4e2a\u6a21\u578b\u5728\u672c\u8282\u4e2d\u8fdb\u884c\u89e3\u91ca\uff1amBERT \u548c XLM\u3002\u6211\u4eec\u4e4b\u6240\u4ee5\u9009\u62e9\u8fd9\u4e9b\u6a21\u578b\uff0c\u662f\u56e0\u4e3a\u5b83\u4eec\u5bf9\u5e94\u4e8e\u64b0\u5199\u672c\u6587\u65f6\u7684\u4e24\u79cd\u6700\u4f73\u591a\u8bed\u8a00\u7c7b\u578b\u3002mBERT\u662f\u4f7f\u7528 MLM \u5728\u4e0d\u540c\u8bed\u8a00\u7684\u4e0d\u540c\u8bed\u6599\u5e93\u4e0a\u8bad\u7ec3\u7684\u591a\u8bed\u8a00\u6a21\u578b\u9020\u578b\u3002\u5b83\u53ef\u4ee5\u9488\u5bf9\u591a\u79cd\u8bed\u8a00\u5355\u72ec\u8fd0\u884c\u3002\u53e6\u4e00\u65b9\u9762\uff0cXLM \u4f7f\u7528 MLM\u3001CLM \u548c TLM \u8bed\u8a00\u5efa\u6a21\u5728\u4e0d\u540c\u7684\u8bed\u6599\u5e93\u4e0a\u8fdb\u884c\u8bad\u7ec3\uff0c\u5e76\u4e14\u53ef\u4ee5\u89e3\u51b3\u8de8\u8bed\u8a00\u4efb\u52a1\u3002\u4f8b\u5982\uff0c\u5b83\u53ef\u4ee5\u901a\u8fc7\u5c06\u4e24\u79cd\u4e0d\u540c\u8bed\u8a00\u7684\u53e5\u5b50\u6620\u5c04\u5230\u4e00\u4e2a\u516c\u5171\u5411\u91cf\u7a7a\u95f4\u6765\u6d4b\u91cf\u5b83\u4eec\u7684\u76f8\u4f3c\u6027\uff0c\u800c\u8fd9\u5bf9\u4e8e mBERT \u662f\u4e0d\u53ef\u80fd\u7684\u3002<\/span><\/span><\/p>\n

        mBERT<\/span><\/span><\/h3>\n

        \u4f60\u719f\u6089\u7684\u7b2c 3 \u7ae0\u4e2d\u7684 BERT \u81ea\u52a8\u7f16\u7801\u5668\u6a21\u578b\uff0c\u81ea\u52a8\u7f16\u7801\u8bed\u8a00\u6a21\u578b<\/em>\uff0c\u4ee5\u53ca\u5982\u4f55\u5728\u6307\u5b9a\u7684\u8bed\u6599\u5e93\u4e0a\u4f7f\u7528 MLM \u5bf9\u5176\u8fdb\u884c\u8bad\u7ec3\u3002\u60f3\u8c61\u4e00\u4e0b\u8fd9\u6837\u4e00\u79cd\u60c5\u51b5\uff0c\u4e0d\u662f\u4ece\u4e00\u79cd\u8bed\u8a00\u800c\u662f\u4ece 104 \u79cd\u8bed\u8a00\u63d0\u4f9b\u4e00\u4e2a\u5e7f\u6cdb\u800c\u5e9e\u5927\u7684\u8bed\u6599\u5e93\u3002\u5728\u8fd9\u6837\u7684\u8bed\u6599\u5e93\u4e0a\u8fdb\u884c\u8bad\u7ec3\u5c06\u4ea7\u751f\u591a\u8bed\u8a00\u7248\u672c\u7684 BERT\u3002\u7136\u800c\uff0c\u5728\u5982\u6b64\u5e7f\u6cdb\u7684\u8bed\u8a00\u4e0a\u8fdb\u884c\u8bad\u7ec3\u4f1a\u589e\u52a0\u6a21\u578b\u7684\u5927\u5c0f\uff0c\u8fd9\u5728 BERT \u7684\u60c5\u51b5\u4e0b\u662f\u4e0d\u53ef\u907f\u514d\u7684\u3002\u8bcd\u6c47\u91cf\u4f1a\u589e\u52a0\uff0c\u56e0\u6b64\uff0c\u7531\u4e8e\u8bcd\u6c47\u91cf\u66f4\u591a\uff0c\u5d4c\u5165\u5c42\u7684\u5927\u5c0f\u4f1a\u66f4\u5927\u3002<\/span><\/span><\/p>\n

        \u4e0e\u5355\u8bed\u9884\u8bad\u7ec3\u7684 BERT \u76f8\u6bd4\uff0c\u8fd9\u4e2a\u65b0\u7248\u672c\u80fd\u591f\u5728\u5355\u4e2a\u6a21\u578b\u4e2d\u5904\u7406\u591a\u79cd\u8bed\u8a00\u3002\u7136\u800c\uff0c\u8fd9\u79cd\u5efa\u6a21\u7684\u7f3a\u70b9\u662f\u8fd9\u79cd\u6a21\u578b\u4e0d\u80fd\u5728\u8bed\u8a00\u4e4b\u95f4\u8fdb\u884c\u6620\u5c04\u3002\u8fd9\u610f\u5473\u7740\u8be5\u6a21\u578b\u5728\u9884\u8bad\u7ec3\u9636\u6bb5\u5e76\u6ca1\u6709\u5b66\u4e60\u4efb\u4f55\u5173\u4e8e\u8fd9\u4e9b\u6765\u81ea\u4e0d\u540c\u8bed\u8a00\u7684\u6807\u8bb0\u7684\u8bed\u4e49\u542b\u4e49\u4e4b\u95f4\u7684\u6620\u5c04\u3002\u4e3a\u4e86\u4e3a\u8be5\u6a21\u578b\u63d0\u4f9b\u8de8\u8bed\u8a00\u6620\u5c04\u548c\u7406\u89e3\uff0c\u6709\u5fc5\u8981\u5728\u4e00\u4e9b\u8de8\u8bed\u8a00\u76d1\u7763\u4efb\u52a1\u4e0a\u5bf9\u5176\u8fdb\u884c\u8bad\u7ec3\uff0c\u4f8b\u5982XNLI<\/strong>\u6570\u636e\u96c6\u4e2d\u53ef\u7528\u7684\u90a3\u4e9b\u3002<\/span><\/span><\/p>\n

        \u4f7f\u7528\u6b64\u6a21\u578b\u5c31\u50cf\u4f7f\u7528\u60a8\u5728\u524d\u51e0\u7ae0\u4e2d\u4f7f\u7528\u7684\u6a21\u578b\u4e00\u6837\u7b80\u5355\uff08\u6709\u5173\u66f4\u591a\u8be6\u7ec6\u4fe1\u606f\uff0c\u8bf7\u53c2\u9605bert-base-multilingual-uncased \u00b7 Hugging Face\uff09\u3002\u8fd9\u662f\u60a8\u9700\u8981\u5f00\u59cb\u7684\u4ee3\u7801\uff1a<\/span><\/span><\/p>\n

        from transformers import pipeline\n\nunmasker = pipeline('fill-mask', model='bert-base-multilingual-uncased')\n\nsentences = [\n\"Transformers changed the [MASK] language processing\",\n\"Transformerlar [MASK] dil i\u015flemeyi de\u011fi\u015ftirdiler\",\n\"\u062a\u0631\u0646\u0633\u0641\u0631\u0645\u0631\u0647\u0627 \u067e\u0631\u062f\u0627\u0632\u0634 \u0632\u0628\u0627\u0646 [MASK] \u0631\u0627 \u062a\u063a\u06cc\u06cc\u0631 \u062f\u0627\u062f\u0646\u062f\"\n]\n\nfor sentence in sentences:\n    print(sentence)\n    print(unmasker(sentence)[0][\"sequence\"])\n    print(\"=\"*50)<\/code><\/pre>\n

        \u7136\u540e\u8f93\u51fa\u5c06\u662f\u5448\u73b0\uff0c\u5982\u4ee5\u4e0b\u4ee3\u7801\u7247\u6bb5\u6240\u793a\uff1a<\/span><\/span><\/p>\n

        Transformers changed the [MASK] language processing\ntransformers changed the english language processing\n==================================================\nTransformerlar [MASK] dil i\u015flemeyi de\u011fi\u015ftirdiler\ntransformerlar bu dil islemeyi degistirdiler\n==================================================\n\u062a\u0631\u0646\u0633\u0641\u0631\u0645\u0631\u0647\u0627 \u067e\u0631\u062f\u0627\u0632\u0634 \u0632\u0628\u0627\u0646 [MASK] \u0631\u0627 \u062a\u063a\u06cc\u06cc\u0631 \u062f\u0627\u062f\u0646\u062f\n\u062a\u0631\u0646\u0633\u0641\u0631\u0645\u0631\u0647\u0627 \u067e\u0631\u062f\u0627\u0632\u0634 \u0632\u0628\u0627\u0646\u06cc \u0631\u0627 \u062a\u063a\u06cc\u06cc\u0631 \u062f\u0627\u062f\u0646\u062f\n==================================================<\/code><\/pre>\n

        \u5982\u60a8\u6240\u89c1\uff0c\u5b83\u53ef\u4ee5\u4e3a\u5404\u79cd\u8bed\u8a00\u6267\u884c\u586b\u5145\u63a9\u7801<\/strong>\u3002<\/span><\/span><\/p>\n

        XLM<\/span><\/span><\/h3>\n

        \u8de8\u8bed\u8a00\u9884\u8bad\u7ec3\u8bed\u8a00\u6a21\u578b\u7684\u6570\u91cf\uff0c\u4f8b\u5982 XLM \u65b9\u6cd5\u6240\u793a\u7684\u6a21\u578b\uff0c\u662f\u57fa\u4e8e\u4e09\u4e2a\u4e0d\u540c\u7684\u9884\u8bad\u7ec3\u76ee\u6807\u3002MLM\u3001CLM \u548c TLM \u7528\u4e8e\u9884\u8bad\u7ec3 XLM \u6a21\u578b\u3002\u8fd9\u79cd\u9884\u8bad\u7ec3\u7684\u987a\u5e8f\u662f\u4f7f\u7528\u6240\u6709\u8bed\u8a00\u4e4b\u95f4\u7684\u5171\u4eab BPE \u6807\u8bb0\u5668\u6267\u884c\u7684\u3002\u5171\u4eab\u6807\u8bb0\u7684\u539f\u56e0\u662f\u5171\u4eab\u6807\u8bb0\u5728\u5177\u6709\u76f8\u4f3c\u6807\u8bb0\u6216\u5b50\u8bcd\u7684\u8bed\u8a00\u7684\u60c5\u51b5\u4e0b\u63d0\u4f9b\u7684\u6807\u8bb0\u8f83\u5c11\uff0c\u53e6\u4e00\u65b9\u9762\uff0c\u8fd9\u4e9b\u6807\u8bb0\u53ef\u4ee5\u5728\u9884\u8bad\u7ec3\u8fc7\u7a0b\u4e2d\u63d0\u4f9b\u5171\u4eab\u8bed\u4e49\u3002\u4f8b\u5982\uff0c\u4e00\u4e9b\u6807\u8bb0\u5728\u8bb8\u591a\u8bed\u8a00\u4e2d\u5177\u6709\u975e\u5e38\u76f8\u4f3c\u7684\u4e66\u5199\u548c\u542b\u4e49\uff0c\u56e0\u6b64\uff0c\u8fd9\u4e9b\u6807\u8bb0\u7531 BPE \u4e3a\u6240\u6709\u4eba\u5171\u4eab\u3002\u53e6\u4e00\u65b9\u9762\uff0c\u4e00\u4e9b\u5728\u4e0d\u540c\u8bed\u8a00\u4e2d\u62fc\u5199\u76f8\u540c\u7684\u6807\u8bb0\u53ef\u80fd\u6709\u4e0d\u540c\u7684\u542b\u4e49\u2014\u2014\u4f8b\u5982\uff0c<\/em>\u5728\u5fb7\u8bed\u548c\u82f1\u8bed\u73af\u5883\u4e2d\u5171\u4eab\u3002\u5e78\u8fd0\u7684\u662f<\/em>\uff0c\u81ea\u6211\u6ce8\u610f\u673a\u5236\u5e2e\u52a9\u6211\u4eec\u6d88\u9664\u4f7f\u7528\u5468\u56f4\u4e0a\u4e0b\u6587\u7684\u542b\u4e49\u3002<\/span><\/span><\/p>\n

        \u53e6\u4e00\u4e2a\u91cd\u5927\u6539\u8fdb\u8de8\u8bed\u8a00\u5efa\u6a21\u7684\u7279\u70b9\u662f\u5b83\u4e5f\u5728 CLM \u4e0a\u8fdb\u884c\u4e86\u9884\u8bad\u7ec3\uff0c\u8fd9\u4f7f\u5f97\u5b83\u5bf9\u4e8e\u9700\u8981\u53e5\u5b50\u9884\u6d4b\u6216\u5b8c\u6210\u7684\u63a8\u7406\u66f4\u52a0\u5408\u7406\u3002\u6362\u53e5\u8bdd\u8bf4\uff0c\u8fd9\u4e2a\u6a21\u578b\u5bf9\u8bed\u8a00\u6709\u7406\u89e3\uff0c\u80fd\u591f\u5b8c\u6210\u53e5\u5b50\uff0c\u9884\u6d4b\u4e22\u5931\u7684token\uff0c\u4ee5\u53ca\u4f7f\u7528\u5176\u4ed6\u8bed\u8a00\u6e90\u9884\u6d4b\u4e22\u5931\u7684token\u3002<\/span><\/span><\/p>\n

        \u4e0b\u56fe\u5c55\u793a\u4e86\u8de8\u8bed\u8a00\u5efa\u6a21\u7684\u6574\u4f53\u7ed3\u6784\u3002\u60a8\u53ef\u4ee5\u5728https:\/\/arxiv.org\/pdf\/1901.07291.pdf\u9605\u8bfb\u66f4\u591a\u5185\u5bb9\uff1a<\/span><\/span><\/p>\n

        \n
        \n \"\u8de8\u8bed\u8a00\u4ea4\u6d41_recreational<\/span><\/span><\/span><\/span>\n <\/div>\n<\/div>\n

        \u56fe 9.3 \u2013 \u8de8\u8bed\u8a00\u5efa\u6a21\u7684 MLM \u548c TLM \u9884\u8bad\u7ec3<\/span><\/span><\/p>\n

        \u8fd8\u53d1\u5e03\u4e86\u66f4\u65b0\u7248\u672c\u7684 XLM \u6a21\u578b\u5982XLM-R<\/strong>\uff0c\u5b83\u5728\u8bad\u7ec3\u548c\u4f7f\u7528\u7684\u8bed\u6599\u5e93\u4e0a\u6709\u5fae\u5c0f\u7684\u53d8\u5316\u3002XLM-R \u4e0e XLM \u6a21\u578b\u76f8\u540c\uff0c\u4f46\u63a5\u53d7\u4e86\u66f4\u591a\u8bed\u8a00\u548c\u66f4\u5927\u7684\u8bad\u7ec3\u8bed\u6599\u5e93\u3002\u805a\u5408 CommonCrawl<\/strong>\u548cWikipedia\u8bed\u6599\u5e93<\/strong>\uff0c\u5e76\u5728\u5176\u4e0a\u8bad\u7ec3 XLM-R \u8fdb\u884c MLM\u3002\u4f46\u662f\uff0c\u4e5f\u4f7f\u7528\u4e86 XNLI \u6570\u636e\u96c6\u5bf9\u4e8e TLM\u3002\u4e0b\u56fe\u663e\u793a\u4e86 XLM-R \u9884\u8bad\u7ec3\u4f7f\u7528\u7684\u6570\u636e\u91cf\uff1a<\/span><\/span><\/p>\n

        \n
        \n \"\u8de8\u8bed\u8a00\u4ea4\u6d41_recreational\n <\/div>\n<\/p>\n<\/div>\n

        \u56fe 9.4 \u2013 \u4ee5\u5343\u5146\u5b57\u8282 (GB) \u4e3a\u5355\u4f4d\u7684\u6570\u636e\u91cf\uff08\u5bf9\u6570\u523b\u5ea6\uff09<\/span><\/span><\/p>\n

        \u4e3a\u8bad\u7ec3\u6570\u636e\u6dfb\u52a0\u65b0\u8bed\u8a00\u65f6\u6709\u5f88\u591a\u597d\u5904\u548c\u574f\u5904\u2014\u2014\u4f8b\u5982\uff0c\u6dfb\u52a0\u65b0\u8bed\u8a00\u8bed\u8a00\u53ef\u80fd\u5e76\u4e0d\u603b\u80fd\u6539\u5584\u81ea\u7136\u8bed\u8a00\u63a8\u7406<\/strong>( NLI<\/strong> ) \u7684\u6574\u4f53\u6a21\u578b\u3002XNLI\u6570\u636e\u96c6<\/strong>\u662f\u901a\u5e38\u7528\u4e8e\u591a\u8bed\u8a00\u548c\u8de8\u8bed\u8a00 NLI\u3002\u4ece\u524d\u9762\u7684\u7ae0\u8282\u4e2d\uff0c\u4f60\u5df2\u7ecf\u770b\u5230\u82f1\u8bed\u7684Multi-Genre<\/strong> NLI ( MNLI<\/strong> ) \u6570\u636e\u96c6\uff1bXNLI \u6570\u636e\u96c6\u4e0e\u5b83\u51e0\u4e4e\u76f8\u540c\uff0c\u4f46\u6709\u66f4\u591a\u7684\u8bed\u8a00\uff0c\u5b83\u4e5f\u6709\u53e5\u5b50\u5bf9\u3002\u4f46\u662f\uff0c\u4ec5\u9488\u5bf9\u6b64\u4efb\u52a1\u8fdb\u884c\u8bad\u7ec3\u662f\u4e0d\u591f\u7684\uff0c\u5e76\u4e14\u4e0d\u4f1a\u6db5\u76d6 TLM \u9884\u8bad\u7ec3\u3002\u5bf9\u4e8e TLM \u9884\u8bad\u7ec3\uff0c\u66f4\u5e7f\u6cdb\u7684\u6570\u636e\u96c6\uff0c\u4f8b\u5982\u5e76\u884c\u4f7f\u7528\u4e86OPUS<\/strong>\u7684\u8bed\u6599\u5e93\uff08 Open Source Parallel Corpus<\/strong>\u7684\u7f29\u5199\uff09\u3002\u8be5\u6570\u636e\u96c6\u5305\u542b\u6765\u81ea\u4e0d\u540c\u8bed\u8a00\u7684\u5b57\u5e55\uff0c\u7ecf\u8fc7\u5bf9\u9f50\u548c\u6e05\u7406\uff0c\u7ffb\u8bd1\u7531\u8bb8\u591a\u8f6f\u4ef6\u6e90\uff08\u5982 Ubuntu \u7b49\uff09\u63d0\u4f9b\u3002<\/span><\/span><\/p>\n

        \u4ee5\u4e0b\u5c4f\u5e55\u622a\u56fe\u663e\u793a\u4e86 OPUS ( OPUS ) \u53ca\u5176\u7528\u4e8e\u641c\u7d22\u548c\u83b7\u53d6\u6709\u5173\u6570\u636e\u96c6\u7684\u4fe1\u606f\u7684\u7ec4\u4ef6\uff1a<\/span><\/span><\/p>\n

        \n
        \n \"\u8de8\u8bed\u8a00\u4ea4\u6d41_recreational\n <\/div>\n<\/p>\n<\/div>\n

        \u56fe 9.5 \u2013 \u5de5\u4f5c<\/span><\/span><\/p>\n

        \u4f7f\u7528\u8de8\u8bed\u8a00\u6a21\u578b\u7684\u6b65\u9aa4\u5728\u8fd9\u91cc\u63cf\u8ff0\uff1a<\/span><\/span><\/p>\n

          \n
        1. \u5bf9\u524d\u9762\u4ee3\u7801\u7684\u7b80\u5355\u66f4\u6539\u53ef\u4ee5\u5411\u60a8\u5c55\u793a XLM-R \u5982\u4f55\u6267\u884c\u63a9\u7801\u586b\u5145\u3002\u9996\u5148\uff0c\u60a8\u5fc5\u987b\u66f4\u6539\u6a21\u578b\uff0c\u5982\u4e0b\u6240\u793a\uff1a\n
          unmasker = pipeline('fill-mask', model='xlm-roberta-base')<\/code><\/pre>\n<\/li>\n
        2. \u4e4b\u540e\uff0c\u60a8\u9700\u8981\u5c06\u63a9\u7801\u6807\u8bb0\u4ece[MASK]<\/strong>\u66f4\u6539\u4e3a<mask><\/strong>\uff0c\u8fd9\u662f XLM-R \u7684\u7279\u6b8a\u6807\u8bb0\uff08\u6216\u7b80\u5355\u5730\u8c03\u7528tokenizer.mask_token<\/strong>\uff09\u3002\u8fd9\u662f\u5b8c\u6210\u6b64\u64cd\u4f5c\u7684\u4ee3\u7801\uff1a\n
          sentences = [\n\"Transformers changed the <mask> language processing\",\n\"Transformerlar <mask> dil i\u015flemeyi de\u011fi\u015ftirdiler\",\n\"\u062a\u0631\u0646\u0633\u0641\u0631\u0645\u0631\u0647\u0627 \u067e\u0631\u062f\u0627\u0632\u0634 \u0632\u0628\u0627\u0646 <mask\" \u0631\u0627 \u062a\u063a\u06cc\u06cc\u0631 \u062f\u0627\u062f\u0646\u062f\n]<\/code><\/pre>\n<\/li>\n
        3. \u7136\u540e\uff0c\u60a8\u53ef\u4ee5\u8fd0\u884c\u76f8\u540c\u7684\u4ee3\u7801\uff0c\u5982\u4e0b\u6240\u793a\uff1a\n
          for sentence in sentences:\n  print(sentence)\n  print(unmasker(sentence)[0][\"sequence\"])\n  print(\"=\"*50)<\/code><\/pre>\n<\/li>\n
        4. \u7ed3\u679c\u5c06\u51fa\u73b0\uff0c\u50cf\u8fd9\u6837\uff1a\n
          Transformers changed the <mask> language processing\nTransformers changed the human language processing\n==================================================\nTransformerlar <mask> dil i\u015flemeyi de\u011fi\u015ftirdiler\nTransformerlar, dil i\u015flemeyi de\u011fi\u015ftirdiler\n================================================== \n\u062a\u0631\u0646\u0633\u0641\u0631\u0645\u0631\u0647\u0627 \u067e\u0631\u062f\u0627\u0632\u0634 \u0632\u0628\u0627\u0646 [MASK] \u0631\u0627 \u062a\u063a\u06cc\u06cc\u0631 \u062f\u0627\u062f\u0646\u062f\n\u062a\u0631\u0646\u0633\u0641\u0631\u0645\u0631\u0647\u0627 \u067e\u0631\u062f\u0627\u0632\u0634 \u0632\u0628\u0627\u0646\u06cc \u0631\u0627 \u062a\u063a\u06cc\u06cc\u0631 \u062f\u0627\u062f\u0646\u062f\n==================================================<\/code><\/pre>\n<\/li>\n
        5. \u4f46\u6b63\u5982\u4f60\u4ece\u571f\u8033\u5176\u8bed\u548c\u6ce2\u65af\u8bed\u7684\u4f8b\u5b50\u4e2d\u770b\u5230\u7684\u90a3\u6837\uff0c\u8be5\u6a21\u578b\u4ecd\u7136\u72af\u4e86\u9519\u8bef\u3002\u4f8b\u5982\uff0c\u5728\u6ce2\u65af\u8bed\u6587\u672c\u4e2d\uff0c\u5b83\u53ea\u662f\u6dfb\u52a0\u4e86\u06cc<\/strong>\uff0c\u800c\u5728\u571f\u8033\u5176\u8bed\u6587\u672c\u4e2d\uff0c\u5b83\u6dfb\u52a0\u4e86,<\/strong>\u3002\u5bf9\u4e8e\u82f1\u6587\u53e5\u5b50\uff0c\u5b83\u6dfb\u52a0\u4e86human<\/strong>\uff0c\u8fd9\u4e0d\u662f\u9884\u671f\u7684\u3002\u53e5\u5b50\u6ca1\u6709\u9519\uff0c\u4f46\u4e0d\u662f\u6211\u4eec\u6240\u671f\u671b\u7684\u3002\u4f46\u662f\uff0c\u8fd9\u4e00\u6b21\uff0c\u6211\u4eec\u6709\u4e00\u4e2a\u4f7f\u7528 TLM \u8bad\u7ec3\u7684\u8de8\u8bed\u8a00\u6a21\u578b\uff1b\u6240\u4ee5\uff0c\u8ba9\u6211\u4eec\u901a\u8fc7\u8fde\u63a5\u4e24\u4e2a\u53e5\u5b50\u5e76\u7ed9\u6a21\u578b\u4e00\u4e9b\u989d\u5916\u7684\u63d0\u793a\u6765\u4f7f\u7528\u5b83\u3002\u5f00\u59cb\u4e86\uff1a\n
          print(unmasker(\"Transformers changed the natural language processing. <\/s> Transformerlar <mask> dil i\u015flemeyi de\u011fi\u015ftirdiler.\")[0][\"sequence\"])<\/code><\/pre>\n<\/li>\n
        6. \u7ed3\u679c\u5c06\u663e\u793a\u5982\u4e0b\uff1a\n

          Transformers changed the natural language processing. Transformerlar do\u011fal dil i\u015flemeyi de\u011fi\u015ftirdiler.<\/p>\n<\/li>\n

        7. \u800c\u5df2\uff01\u8fd9\u6a21\u578b\u73b0\u5728\u505a\u51fa\u4e86\u6b63\u786e\u7684\u9009\u62e9\u3002\u8ba9\u6211\u4eec\u591a\u73a9\u4e00\u70b9\uff0c\u770b\u770b\u5b83\u7684\u8868\u73b0\u5982\u4f55\uff0c\u5982\u4e0b\uff1a\n
          print(unmasker(\"Earth is a great place to live in. <\/s> \u0632\u0645\u06cc\u0646 \u062c\u0627\u06cc \u062e\u0648\u0628\u06cc \u0628\u0631\u0627\u06cc <mask> \u06a9\u0631\u062f\u0646 \u0627\u0633\u062a.\")[0][\"sequence\"])<\/code><\/pre>\n

          \u7ed3\u679c\u5982\u4e0b\uff1a<\/p>\n

          Earth is a great place to live in. \u0632\u0645\u06cc\u0646 \u062c\u0627\u06cc \u062e\u0648\u0628\u06cc \u0628\u0631\u0627\u06cc \u0632\u0646\u062f\u06af\u06cc \u06a9\u0631\u062f\u0646 \u0627\u0633\u062a<\/p>\n<\/li>\n<\/ol>\n

          \u505a\u5f97\u597d\uff01\u5230\u76ee\u524d\u4e3a\u6b62\uff0c\u60a8\u5df2\u7ecf\u4e86\u89e3\u4e86 mBERT \u548c XLM \u7b49\u591a\u8bed\u8a00\u548c\u8de8\u8bed\u8a00\u6a21\u578b\u3002\u5728\u4e0b\u4e00\u8282\u4e2d\uff0c\u60a8\u5c06\u5b66\u4e60\u5982\u4f55\u4f7f\u7528\u6b64\u7c7b\u6a21\u578b\u8fdb\u884c\u591a\u8bed\u8a00\u6587\u672c\u76f8\u4f3c\u6027\u3002\u60a8\u8fd8\u5c06\u770b\u5230\u4e00\u4e9b\u7528\u4f8b\uff0c\u4f8b\u5982\u591a\u8bed\u8a00\u6284\u88ad\u68c0\u6d4b\u3002<\/span><\/span><\/p>\n

          \u8de8\u8bed\u8a00\u76f8\u4f3c\u5ea6\u4efb\u52a1<\/span><\/span><\/h2>\n

          \u8de8\u8bed\u8a00\u6a21\u578b\u662f\u80fd\u591f\u4ee5\u7edf\u4e00\u7684\u5f62\u5f0f\u8868\u793a\u6587\u672c\uff0c\u5176\u4e2d\u53e5\u5b50\u6765\u81ea\u4e0d\u540c\u7684\u8bed\u8a00\uff0c\u4f46\u610f\u4e49\u76f8\u8fd1\u7684\u53e5\u5b50\u88ab\u6620\u5c04\u5230\u5411\u91cf\u7a7a\u95f4\u4e2d\u7684\u76f8\u4f3c\u5411\u91cf\u3002\u5982\u4e0a\u4e00\u8282\u6240\u8ff0\uff0cXLM-R \u662f\u8be5\u8303\u56f4\u5185\u7684\u6210\u529f\u6a21\u578b\u4e4b\u4e00\u3002\u73b0\u5728\uff0c\u8ba9\u6211\u4eec\u770b\u4e00\u4e0b\u8fd9\u65b9\u9762\u7684\u4e00\u4e9b\u5e94\u7528\u3002<\/span><\/span><\/p>\n

          \u8de8\u8bed\u8a00\u6587\u672c\u76f8\u4f3c\u5ea6<\/span><\/span><\/h3>\n

          \u5728\u4ee5\u4e0b\u793a\u4f8b\u4e2d\uff0c\u60a8\u5c06\u4e86\u89e3\u5982\u4f55\u4f7f\u7528\u5728 XNLI \u6570\u636e\u96c6\u4e0a\u9884\u8bad\u7ec3\u7684\u8de8\u8bed\u8a00\u8bed\u8a00\u6a21\u578b\u6765\u67e5\u627e\u6765\u81ea\u4e0d\u540c\u8bed\u8a00\u7684\u76f8\u4f3c\u6587\u672c\u3002\u7528\u4f8b\u573a\u666f\u662f\u6b64\u4efb\u52a1\u9700\u8981\u527d\u7a83\u68c0\u6d4b\u7cfb\u7edf\u3002\u6211\u4eec\u5c06\u4f7f\u7528\u963f\u585e\u62dc\u7586\u8bed\u7684\u53e5\u5b50\uff0c\u770b\u770b XLM-R \u662f\u5426\u4ece\u82f1\u8bed\u4e2d\u627e\u5230\u7c7b\u4f3c\u7684\u53e5\u5b50\u2014\u2014\u5982\u679c\u6709\u7684\u8bdd\u3002\u4e24\u79cd\u8bed\u8a00\u7684\u53e5\u5b50\u662f\u76f8\u540c\u7684\u3002\u4ee5\u4e0b\u662f\u8981\u91c7\u53d6\u7684\u6b65\u9aa4\uff1a<\/span><\/span><\/p>\n

            \n
          1. \u9996\u5148\uff0c\u60a8\u9700\u8981\u4e3a\u6b64\u4efb\u52a1\u52a0\u8f7d\u6a21\u578b\uff0c\u5982\u4e0b\u6240\u793a\uff1a\n
            from sentence_transformers import SentenceTransformer, util\n\nmodel = SentenceTransformer(\"stsb-xlm-r-multilingual\")<\/code><\/pre>\n<\/li>\n
          2. \u4e4b\u540e\uff0c\u6211\u4eec\u5047\u8bbe\u6211\u4eec\u4ee5\u4e24\u4e2a\u5355\u72ec\u7684\u5217\u8868\u7684\u5f62\u5f0f\u51c6\u5907\u597d\u4e86\u53e5\u5b50\uff0c\u5982\u4e0b\u9762\u7684\u4ee3\u7801\u7247\u6bb5\u6240\u793a\uff1a\n
            azeri_sentences = ['Pi\u015fik \u00e7\u00f6ld\u0259 oturur',\n              'Bir adam gitara \u00e7al\u0131r',\n              'M\u0259n makaron sevir\u0259m',\n              'Yeni film m\u00f6ht\u0259\u015f\u0259mdir',\n              'Pi\u015fik ba\u011fda oynay\u0131r',\n              'Bir qad\u0131n televizora bax\u0131r',\n              'Yeni film \u00e7ox m\u00f6ht\u0259\u015f\u0259mdir',\n              'Pizzan\u0131 sevirs\u0259n?']\n\nenglish_sentences = ['The cat sits outside',\n             'A man is playing guitar',\n             'I love pasta',\n             'The new movie is awesome',\n             'The cat plays in the garden',\n             'A woman watches TV',\n             'The new movie is so great',\n             'Do you like pizza?']<\/code><\/pre>\n<\/li>\n
          3. \u4e0b\u4e00\u6b65\u662f\u4f7f\u7528 XLM-R \u6a21\u578b\u5728\u5411\u91cf\u7a7a\u95f4\u4e2d\u8868\u793a\u8fd9\u4e9b\u53e5\u5b50\u3002\u60a8\u53ef\u4ee5\u901a\u8fc7\u7b80\u5355\u5730\u4f7f\u7528\u6a21\u578b\u7684\u7f16\u7801<\/strong>\u529f\u80fd\u6765\u505a\u5230\u8fd9\u4e00\u70b9\uff0c\u5982\u4e0b\u6240\u793a\uff1a\n
            azeri_representation = model.encode(azeri_sentences)\n\nenglish_representation = model.encode(english_sentences)<\/code><\/pre>\n<\/li>\n
          4. \u5728\u6700\u540e\u4e00\u6b65\uff0c\u6211\u4eec\u5c06\u5728\u53e6\u4e00\u79cd\u8bed\u8a00\u7684\u8868\u793a\u4e0a\u641c\u7d22\u7b2c\u4e00\u79cd\u8bed\u8a00\u7684\u8bed\u4e49\u76f8\u4f3c\u7684\u53e5\u5b50\uff0c\u5982\u4e0b\u6240\u793a\uff1a\n
            results = []\n\nfor azeri_sentence, query in zip(azeri_sentences, azeri_representation):\n    id_, score = util.semantic_search(query,english_representation)[0][0].values()\n    results.append({\n      \"azeri\": azeri_sentence,\n      \"english\": english_sentences[id_],\n      \"score\": round(score, 4)\n    })<\/code><\/pre>\n<\/li>\n
          5. \u4e3a\u4e86\u770b\u5230\u4e00\u4e2a\u6e05\u6670\u7684\u5f62\u5f0f\u8fd9\u4e9b\u7ed3\u679c\uff0c\u53ef\u4ee5\u4f7f\u7528pandas DataFrame\uff0c\u5982\u4e0b\uff1a\n
            import pandas as pd\n\npd.DataFrame(results)<\/code><\/pre>\n

            \u60a8\u5c06\u770b\u5230\u5339\u914d\u5206\u6570\u7684\u7ed3\u679c\uff0c\u5982\u4e0b\u6240\u793a\uff1a<\/p>\n<\/li>\n<\/ol>\n

            \n
            \n \"\u8de8\u8bed\u8a00\u4ea4\u6d41_recreational\n <\/div>\n<\/div>\n

            \u56fe 9.6 \u2013 \u6284\u88ad\u68c0\u6d4b\u7ed3\u679c (XLM-R)<\/span><\/span><\/p>\n

            \u5982\u679c\u6211\u4eec\u63a5\u53d7\u8981\u89e3\u91ca\u6216\u7ffb\u8bd1\u7684\u6700\u9ad8\u5f97\u5206\u53e5\u5b50\uff0c\u6a21\u578b\u5728\u4e00\u79cd\u60c5\u51b5\u4e0b\uff08\u7b2c4<\/em>\u884c\uff09\u4f1a\u51fa\u9519\uff0c\u4f46\u6709\u4e00\u4e2a\u9608\u503c\u5e76\u63a5\u53d7\u9ad8\u4e8e\u5b83\u7684\u503c\u662f\u6709\u7528\u7684\u3002\u6211\u4eec\u5c06\u5728\u4ee5\u4e0b\u90e8\u5206\u5c55\u793a\u66f4\u5168\u9762\u7684\u5b9e\u9a8c\u3002<\/span><\/span><\/p>\n

            \u53e6\u4e00\u65b9\u9762\uff0c\u4e5f\u6709\u53ef\u7528\u7684\u66ff\u4ee3\u53cc\u7f16\u7801\u5668\u3002\u8fd9\u79cd\u65b9\u6cd5\u63d0\u4f9b\u4e86\u4e00\u5bf9\u7f16\u7801\u4e24\u4e2a\u53e5\u5b50\u5e76\u5bf9\u7ed3\u679c\u8fdb\u884c\u5206\u7c7b\u4ee5\u8bad\u7ec3\u6a21\u578b\u3002\u5728\u8fd9\u79cd\u60c5\u51b5\u4e0b\uff0c\u4e0e\u8bed\u8a00\u65e0\u5173\u7684 BERT \u53e5\u5b50\u5d4c\u5165<\/strong>( LaBSE<\/strong> ) \u4e5f\u53ef\u80fd\u662f\u4e00\u4e2a\u4e0d\u9519\u7684\u9009\u62e9\uff0c\u5b83\u53ef\u4ee5\u5728\u53e5\u5b50\u8f6c\u6362\u5668<\/strong>\u5e93\u548c\u5728TensorFlow Hub<\/strong>\u4e2d\u4e5f\u662f\u5982\u6b64\u3002LaBSE \u662f\u57fa\u4e8e Transformers \u7684\u53cc\u7f16\u7801\u5668\uff0c\u7c7b\u4f3c\u4e8e Sentence-BERT\uff0c\u5c06\u4e24\u4e2a\u5177\u6709\u76f8\u540c\u53c2\u6570\u7684\u7f16\u7801\u5668\u4e0e\u57fa\u4e8e\u4e24\u4e2a\u53e5\u5b50\u7684\u53cc\u91cd\u76f8\u4f3c\u6027\u3002<\/span><\/span><\/p>\n

            \u4f7f\u7528\u76f8\u540c\u7684\u793a\u4f8b\uff0c\u60a8\u53ef\u4ee5\u901a\u8fc7\u975e\u5e38\u7b80\u5355\u7684\u65b9\u5f0f\u5c06\u6a21\u578b\u66f4\u6539\u4e3a LaBSE\uff0c\u7136\u540e\u91cd\u65b0\u8fd0\u884c\u4e4b\u524d\u7684\u4ee3\u7801\uff08\u6b65\u9aa4 1<\/em>\uff09\uff0c\u5982\u4e0b\u6240\u793a\uff1a<\/span><\/span><\/p>\n

            model = SentenceTransformer(\"LaBSE\")<\/code><\/pre>\n

             \u7ed3\u679c\u663e\u793a\u5728\u4ee5\u4e0b\u5c4f\u5e55\u622a\u56fe\u4e2d\uff1a<\/span><\/span><\/p>\n

            \n
            \n \"\u8de8\u8bed\u8a00\u4ea4\u6d41_recreational\n <\/div>\n<\/p>\n<\/div>\n

            \u56fe 9.7 \u2013 \u6284\u88ad\u68c0\u6d4b\u7ed3\u679c (LaBSE)<\/span><\/span><\/p>\n

            \u5982\u60a8\u6240\u89c1\uff0cLaBSE \u5728\u8fd9\u79cd\u60c5\u51b5\u4e0b\u8868\u73b0\u66f4\u597d\uff0c\u8fd9\u6b21\u7b2c4<\/em>\u884c\u7684\u7ed3\u679c\u662f\u6b63\u786e\u7684\u3002LaBSE \u4f5c\u8005\u58f0\u79f0\u5b83\u5728\u67e5\u627e\u53e5\u5b50\u7684\u7ffb\u8bd1\u65b9\u9762\u6548\u679c\u5f88\u597d\uff0c\u4f46\u5728\u67e5\u627e\u4e0d\u5b8c\u5168\u76f8\u540c\u7684\u53e5\u5b50\u65b9\u9762\u5e76\u4e0d\u90a3\u4e48\u597d\u3002\u4e3a\u6b64\uff0c\u5728\u4f7f\u7528\u7ffb\u8bd1\u7a83\u53d6\u77e5\u8bc6\u6750\u6599\u7684\u60c5\u51b5\u4e0b\uff0c\u5b83\u662f\u4e00\u79cd\u975e\u5e38\u6709\u7528\u7684\u5de5\u5177\uff0c\u53ef\u4ee5\u7528\u6765\u53d1\u73b0\u6284\u88ad\u3002\u4f46\u662f\uff0c\u8fd8\u6709\u8bb8\u591a\u5176\u4ed6\u56e0\u7d20\u4f1a\u6539\u53d8\u7ed3\u679c\u540c\u6837\u2014\u2014\u4f8b\u5982\uff0c\u6bcf\u79cd\u8bed\u8a00\u7684\u9884\u8bad\u7ec3\u6a21\u578b\u7684\u8d44\u6e90\u5927\u5c0f\u548c\u8bed\u8a00\u5bf9\u7684\u6027\u8d28\u4e5f\u5f88\u91cd\u8981\u3002\u4e3a\u4e86\u5408\u7406\u7684\u6bd4\u8f83\uff0c\u6211\u4eec\u9700\u8981\u66f4\u5168\u9762\u7684\u5b9e\u9a8c\uff0c\u8981\u8003\u8651\u5f88\u591a\u56e0\u7d20\u3002<\/span><\/span><\/p>\n

            \u53ef\u89c6\u5316\u8de8\u8bed\u8a00\u6587\u672c\u76f8\u4f3c\u6027<\/span><\/span><\/h3>\n

            \u73b0\u5728\uff0c\u6211\u4eec\u5c06\u6d4b\u91cf\u548c\u53ef\u89c6\u5316\u4e24\u4e2a\u53e5\u5b50\u4e4b\u95f4\u7684\u6587\u672c\u76f8\u4f3c\u7a0b\u5ea6\uff0c\u5176\u4e2d\u4e00\u4e2a\u662f\u53e6\u4e00\u4e2a\u53e5\u5b50\u7684\u7ffb\u8bd1\u3002Tatoeba<\/strong>\u662f\u514d\u8d39\u7684\u8fd9\u4e9b\u53e5\u5b50\u548c\u7ffb\u8bd1\u7684\u96c6\u5408\uff0c\u5b83\u662f XTREME \u57fa\u51c6\u7684\u4e00\u90e8\u5206\u3002\u793e\u533a\u65e8\u5728\u5728\u4f17\u591a\u53c2\u4e0e\u8005\u7684\u652f\u6301\u4e0b\u83b7\u5f97\u9ad8\u8d28\u91cf\u7684\u53e5\u5b50\u7ffb\u8bd1\u3002\u6211\u4eec\u73b0\u5728\u5c06\u91c7\u53d6\u4ee5\u4e0b\u6b65\u9aa4\uff1a<\/span><\/span><\/p>\n

              \n
            1. \u6211\u4eec\u5c06\u4ece\u8fd9\u4e2a\u96c6\u5408\u4e2d\u5f97\u5230\u4fc4\u8bed\u548c\u82f1\u8bed\u53e5\u5b50\u3002\u5728\u5f00\u59cb\u5de5\u4f5c\u4e4b\u524d\uff0c\u8bf7\u786e\u4fdd\u5df2\u5b89\u88c5\u4ee5\u4e0b\u5e93\uff1a\n
              !pip install sentence_transformers datasets transformers umap-learn<\/code><\/pre>\n<\/li>\n
            2. \u52a0\u8f7d\u53e5\u5b50\u5bf9\uff0c\u5982\u4e0b\uff1a\n
              from datasets import load_dataset\nimport pandas as pd\n\ndata=load_dataset(\"xtreme\",\"tatoeba.rus\",\n                   split=\"validation\")\n\npd.DataFrame(data)[[\"source_sentence\",\"target_sentence\"]]<\/code><\/pre>\n

              \u6211\u4eec\u770b\u4e00\u4e0b\u8f93\u51fa\uff0c\u5982\u4e0b\uff1a<\/p>\n

              \n \"\u8de8\u8bed\u8a00\u4ea4\u6d41_recreational\n <\/div>\n<\/p>\n

              \u56fe 9.8 \u2013 \u4fc4\u82f1\u53e5\u5b50\u5bf9<\/p>\n<\/li>\n

            3. \u9996\u5148\uff0c\u6211\u4eec\u5c06\u91c7\u53d6\u524dK=30 \u4e2a<\/em>\u53e5\u5b50\u5bf9\u7528\u4e8e\u53ef\u89c6\u5316\uff0c\u7a0d\u540e\uff0c\u6211\u4eec\u5c06\u5bf9\u6574\u4e2a\u96c6\u5408\u8fdb\u884c\u5b9e\u9a8c\u3002\u73b0\u5728\uff0c\u6211\u4eec\u5c06\u4f7f\u7528\u524d\u9762\u793a\u4f8b\u4e2d\u5df2\u7ecf\u4f7f\u7528\u7684\u53e5\u5b50\u8f6c\u6362\u5668\u5bf9\u5b83\u4eec\u8fdb\u884c\u7f16\u7801\u3002\u4e0b\u9762\u662f\u4ee3\u7801\u7684\u6267\u884c\uff1a\n
              from sentence_transformers import SentenceTransformer\n\nmodel = SentenceTransformer(\"stsb-xlm-r-multilingual\")\nK=30\nq=data[\"source_sentence\"][:K] + data[\"target_sentence\"][:K]\nemb=model.encode(q)\nlen(emb), len(emb[0])<\/code><\/pre>\n

              Output: (60, 768)<\/p>\n<\/li>\n

            4. \u6211\u4eec\u73b0\u5728\u6709 60 \u4e2a\u957f\u5ea6\u4e3a 768 \u7684\u5411\u91cf\u3002\u6211\u4eec\u5c06\u4f7f\u7528\u7edf\u4e00\u6d41\u5f62\u903c\u8fd1\u548c\u6295\u5f71<\/strong>( UMAP<\/strong> )\u5c06\u7ef4\u6570\u964d\u4f4e\u5230 2\uff0c\u6211\u4eec\u5c06\u5df2\u7ecf\u6709\u5728\u524d\u9762\u7684\u7ae0\u8282\u4e2d\u9047\u5230\u8fc7\u3002\u6211\u4eec\u5c06\u76f8\u4e92\u7ffb\u8bd1\u7684\u53e5\u5b50\u53ef\u89c6\u5316\uff0c\u7528\u76f8\u540c\u7684\u989c\u8272\u548c\u4ee3\u7801\u6807\u8bb0\u5b83\u4eec\u3002\u6211\u4eec\u8fd8\u5728\u5b83\u4eec\u4e4b\u95f4\u753b\u4e86\u4e00\u6761\u865a\u7ebf\uff0c\u4ee5\u4f7f\u94fe\u63a5\u66f4\u52a0\u660e\u663e\u3002\u4ee3\u7801\u5982\u4ee5\u4e0b\u7247\u6bb5\u6240\u793a\uff1a\n
              import matplotlib.pyplot as plt\nimport numpy as np\nimport umap\nimport pylab\n\nX= umap.UMAP(n_components=2, random_state=42).fit_transform(emb)\nidx= np.arange(len(emb))\nfig, ax = plt.subplots(figsize=(12, 12))\nax.set_facecolor('whitesmoke')\ncm = pylab.get_cmap(\"prism\")\ncolors = list(cm(1.0*i\/K) for i in range(K))\nfor i in idx:\n    if i<K:\n        ax.annotate(\"RUS-\"+str(i), # text\n                      (X[i,0], X[i,1]), # coordinates\n                      c=colors[i]) # color\n        ax.plot((X[i,0],X[i+K,0]),(X[i,1],X[i+K,1]),\"k:\")\n    else:\n        ax.annotate(\"EN-\"+str(i%K),\n                        (X[i,0], X[i,1]),\n                        c=colors[i%K])<\/code><\/pre>\n

              \u8fd9\u91cc\u662f\u4e0a\u8ff0\u4ee3\u7801\u7684\u8f93\u51fa\uff1a\"\u8de8\u8bed\u8a00\u4ea4\u6d41_recreational<\/p>\n<\/p>\n

              <\/div>\n

              \u56fe 9.9 \u2013 \u4fc4\u82f1\u53e5\u5b50\u76f8\u4f3c\u5ea6\u53ef\u89c6\u5316<\/p>\n

              \u6b63\u5982\u6211\u4eec\u6240\u6599\uff0c\u5927\u591a\u6570\u53e5\u5b50\u5bf9\u5f7c\u6b64\u9760\u8fd1\u3002\u4e0d\u53ef\u907f\u514d\u5730\uff0c\u67d0\u4e9b\u7279\u5b9a\u5bf9\uff08\u4f8b\u5982id 12<\/strong>\uff09\u575a\u6301\u4e0d\u9760\u8fd1\u3002<\/p>\n<\/li>\n

            5. \u4e3a\u4e86\u8fdb\u884c\u5168\u9762\u5206\u6790\uff0c\u73b0\u5728\u8ba9\u6211\u4eec\u6d4b\u91cf\u6574\u4e2a\u6570\u636e\u96c6\u3002\u6211\u4eec\u5bf9\u6240\u6709\u6e90\u8bed\u53e5\u548c\u76ee\u6807\u8bed\u53e5\uff081K \u5bf9\uff09\u8fdb\u884c\u7f16\u7801\uff0c\u5982\u4e0b\u6240\u793a\uff1a\n
              source_emb=model.encode(data[\"source_sentence\"])\n\ntarget_emb=model.encode(data[\"target_sentence\"])<\/code><\/pre>\n<\/li>\n
            6. \u6211\u4eec\u8ba1\u7b97\u6240\u6709\u5bf9\u4e4b\u95f4\u7684\u4f59\u5f26\u76f8\u4f3c\u5ea6\uff0c\u5c06\u5b83\u4eec\u4fdd\u5b58\u5728sims<\/strong> \u53d8\u91cf\u4e2d\uff0c\u5e76\u7ed8\u5236\u76f4\u65b9\u56fe\uff0c\u5982\u4e0b\u6240\u793a\uff1a\n
              from scipy import spatial\n\nsims=[ 1 - spatial.distance.cosine(s,t) \\\n        for s,t in zip(source_emb, target_emb)]\nplt.hist(sims, bins=100, range=(0.8,1))\nplt.show()<\/code><\/pre>\n

              \u8fd9\u662f\u8f93\u51fa\uff1a<\/p>\n

              \n \"\u8de8\u8bed\u8a00\u4ea4\u6d41_recreational\n <\/div>\n<\/p>\n

              \u56fe 9.10 \u2013 \u82f1\u8bed\u548c\u4fc4\u8bed\u53e5\u5b50\u5bf9\u7684\u76f8\u4f3c\u5ea6\u76f4\u65b9\u56fe<\/p>\n<\/li>\n

            7. \u53ef\u4ee5\u770b\u51fa\uff0c\u5206\u6570\u975e\u5e38\u63a5\u8fd1 1\u3002\u8fd9\u662f\u6211\u4eec\u5bf9\u826f\u597d\u7684\u8de8\u8bed\u8a00\u6a21\u578b\u7684\u671f\u671b\u3002\u6240\u6709\u76f8\u4f3c\u5ea6\u6d4b\u91cf\u7684\u5747\u503c\u548c\u6807\u51c6\u5dee\u4e5f\u652f\u6301\u8de8\u8bed\u8a00\u6a21\u578b\u6027\u80fd\uff0c\u5982\u4e0b\uff1a\n
              np.mean(sims), np.std(sims)<\/code><\/pre>\n

              (0.946, 0.082)<\/span><\/p>\n<\/li>\n

            8. \u60a8\u53ef\u4ee5\u81ea\u5df1\u4e3a\u4fc4\u8bed\u4ee5\u5916\u7684\u8bed\u8a00\u8fd0\u884c\u76f8\u540c\u7684\u4ee3\u7801\u3002\u5f53\u60a8\u4f7f\u7528\u6cd5\u8bed<\/strong>( fra<\/strong> )\u3001\u6cf0\u7c73\u5c14\u8bed<\/strong>( tam<\/strong> ) \u7b49\u8fd0\u884c\u5b83\u65f6\uff0c\u60a8\u5c06\u5f97\u5230\u4ee5\u4e0b\u7ed3\u679c\u8868\u3002\u8be5\u8868\u8868\u660e\uff0c\u60a8\u5c06\u5728\u5b9e\u9a8c\u4e2d\u770b\u5230\u8be5\u6a21\u578b\u5728\u8bb8\u591a\u8bed\u8a00\u4e2d\u8fd0\u884c\u826f\u597d\uff0c\u4f46\u5728\u5176\u4ed6\u8bed\u8a00\u4e2d\u5219\u5931\u8d25\uff0c\u4f8b\u5982\u5357\u975e\u8377\u5170\u8bed<\/strong>\u6216\u6cf0\u7c73\u5c14\u8bed<\/strong>\uff1a<\/li>\n<\/ol>\n
              \n
              \n \"\u8de8\u8bed\u8a00\u4ea4\u6d41_recreational\n <\/div>\n<\/p>\n<\/div>\n

              \u8868 1 \u2013 \u5176\u4ed6\u8bed\u8a00\u7684\u8de8\u8bed\u8a00\u6a21\u578b\u6027\u80fd<\/span><\/span><\/p>\n

              \u5728\u672c\u8282\u4e2d\uff0c\u6211\u4eec\u5e94\u7528\u4e86\u8de8\u8bed\u8a00\u6a21\u578b\u6765\u8861\u91cf\u4e0d\u540c\u8bed\u8a00\u4e4b\u95f4\u7684\u76f8\u4f3c\u6027\u3002\u5728\u4e0b\u4e00\u8282\u4e2d\uff0c\u6211\u4eec\u5c06\u4ee5\u76d1\u7763\u7684\u65b9\u5f0f\u4f7f\u7528\u8de8\u8bed\u8a00\u6a21\u578b\u3002<\/span><\/span><\/p>\n

              \u8de8\u8bed\u8a00\u5206\u7c7b<\/span><\/span><\/h2>\n

              \u5230\u76ee\u524d\u4e3a\u6b62\uff0c\u60a8\u5df2\u7ecf\u4e86\u89e3\u5230\u8de8\u8bed\u8a00\u6a21\u578b\u80fd\u591f\u7406\u89e3\u8bed\u4e49\u5411\u91cf\u7a7a\u95f4\u4e2d\u7684\u4e0d\u540c\u8bed\u8a00\uff0c\u5176\u4e2d\u76f8\u4f3c\u7684\u53e5\u5b50\uff0c\u65e0\u8bba\u5176\u8bed\u8a00\u5982\u4f55\uff0c\u5728\u5411\u91cf\u8ddd\u79bb\u65b9\u9762\u90fd\u5f88\u63a5\u8fd1\u3002\u4f46\u662f\uff0c\u5728\u6211\u4eec\u53ef\u7528\u7684\u6837\u672c\u5f88\u5c11\u7684\u7528\u4f8b\u4e2d\uff0c\u5982\u4f55\u4f7f\u7528\u6b64\u529f\u80fd\u5462\uff1f<\/span><\/span><\/p>\n

              \u4f8b\u5982\uff0c\u60a8\u6b63\u5728\u5c1d\u8bd5\u4e3a\u804a\u5929\u673a\u5668\u4eba\u5f00\u53d1\u610f\u56fe\u5206\u7c7b\uff0c\u5176\u4e2d\u7b2c\u4e8c\u8bed\u8a00\u7684\u6837\u672c\u5f88\u5c11\u6216\u6ca1\u6709\u53ef\u7528\u7684\u6837\u672c\uff1b\u4f46\u662f\u5bf9\u4e8e\u7b2c\u4e00\u8bed\u8a00\u2014\u2014\u6bd4\u5982\u8bf4\u82f1\u8bed\u2014\u2014\u4f60\u786e\u5b9e\u6709\u8db3\u591f\u7684\u6837\u672c\u3002\u5728\u8fd9\u79cd\u60c5\u51b5\u4e0b\uff0c\u53ef\u4ee5\u51bb\u7ed3\u8de8\u8bed\u8a00\u6a21\u578b\u672c\u8eab\uff0c\u53ea\u4e3a\u4efb\u52a1\u8bad\u7ec3\u4e00\u4e2a\u5206\u7c7b\u5668\u3002\u4e00\u4e2a\u8bad\u7ec3\u6709\u7d20\u7684\u5206\u7c7b\u5668\u53ef\u4ee5\u5728\u7b2c\u4e8c\u8bed\u8a00\u800c\u4e0d\u662f\u5b83\u6240\u8bad\u7ec3\u7684\u8bed\u8a00\u4e0a\u8fdb\u884c\u6d4b\u8bd5\u3002<\/span><\/span><\/p>\n

              \u5728\u672c\u8282\u4e2d\uff0c\u60a8\u5c06\u5b66\u4e60\u5982\u4f55\u7528\u82f1\u8bed\u8bad\u7ec3\u4e00\u4e2a\u8de8\u8bed\u8a00\u6a21\u578b\u8fdb\u884c\u6587\u672c\u5206\u7c7b\uff0c\u5e76\u7528\u5176\u4ed6\u8bed\u8a00\u5bf9\u5176\u8fdb\u884c\u6d4b\u8bd5\u3002\u6211\u4eec\u9009\u62e9\u4e86\u4e00\u79cd\u8d44\u6e90\u975e\u5e38\u5c11\u7684\u8bed\u8a00\u4f5c\u4e3a\u9ad8\u68c9\u8bed<\/strong>\uff08https:\/\/en.wikipedia.org\/wiki\/Khmer_language\uff09\uff0c\u5728\u67ec\u57d4\u5be8\u3001\u6cf0\u56fd\u548c\u8d8a\u5357\u6709 1600 \u4e07\u4eba\u4f7f\u7528\u3002\u5b83\u5728\u4e92\u8054\u7f51\u4e0a\u7684\u8d44\u6e90\u5f88\u5c11\uff0c\u800c\u4e14\u5f88\u96be\u627e\u5230\u597d\u7684\u6570\u636e\u96c6\u6765\u8bad\u7ec3\u4f60\u7684\u6a21\u578b\u3002\u4f46\u662f\uff0c\u6211\u4eec\u53ef\u4ee5\u8bbf\u95ee\u4e00\u4e2a\u5f88\u597d\u7684\u4e92\u8054\u7f51\u7535\u5f71\u6570\u636e\u5e93<\/strong>( IMDb<\/strong> ) \u7535\u5f71\u8bc4\u8bba\u60c5\u611f\u6570\u636e\u96c6\u4ee5\u83b7\u53d6\u60c5\u611f\u5206\u6790\u3002\u6211\u4eec\u5c06\u4f7f\u7528\u8be5\u6570\u636e\u96c6\u6765\u4e86\u89e3\u6211\u4eec\u7684\u6a21\u578b\u5728\u5b83\u6ca1\u6709\u53d7\u8fc7\u8bad\u7ec3\u7684\u8bed\u8a00\u3002<\/span><\/span><\/p>\n

              \u4e0b\u56fe\u5f88\u597d\u5730\u63cf\u8ff0\u4e86\u6211\u4eec\u5c06\u9075\u5faa\u7684\u6d41\u7a0b\u3002\u8be5\u6a21\u578b\u4f7f\u7528\u5de6\u4fa7\u7684\u8bad\u7ec3\u6570\u636e\u8fdb\u884c\u8bad\u7ec3\uff0c\u8be5\u6a21\u578b\u5e94\u7528\u4e8e\u53f3\u4fa7\u7684\u6d4b\u8bd5\u96c6\u3002\u8bf7\u6ce8\u610f\uff0c\u673a\u5668\u7ffb\u8bd1\u548c\u53e5\u5b50\u7f16\u7801\u5668\u6620\u5c04\u5728\u6d41\u7a0b\u4e2d\u8d77\u7740\u91cd\u8981\u4f5c\u7528\uff1a<\/span><\/span><\/p>\n

              \n
              \n \"\u8de8\u8bed\u8a00\u4ea4\u6d41_recreational\n <\/div>\n<\/p>\n<\/div>\n

              \u56fe 9.11 \u2013 \u8de8\u8bed\u8a00\u5206\u7c7b\u6d41\u7a0b<\/span><\/span><\/p>\n

              \u52a0\u8f7d\u6240\u9700\u7684\u6b65\u9aa4\u5e76\u8bad\u7ec3\u4e00\u4e2a\u7528\u4e8e\u8de8\u8bed\u8a00\u6d4b\u8bd5\u7684\u6a21\u578b\u662f\u6b64\u5904\u6982\u8ff0\uff1a<\/span><\/span><\/p>\n

                \n
              1. \u7b2c\u4e00\u6b65\u662f\u52a0\u8f7d\u6570\u636e\u96c6\uff0c\u5982\u4e0b\uff1a\n
                from datasets import load_dataset\n\nsms_spam = load_dataset(\"imdb\")<\/code><\/pre>\n<\/li>\n
              2. \u5728\u4f7f\u7528\u6837\u672c\u4e4b\u524d\uff0c\u60a8\u9700\u8981\u5bf9\u6570\u636e\u96c6\u8fdb\u884c\u6df7\u6d17\uff0c\u5982\u4e0b\u6240\u793a\uff1a\n
                imdb = imdb.shuffle()<\/code><\/pre>\n<\/li>\n
              3. \u4e0b\u4e00\u6b65\u662f\u4ece\u8fd9\u4e2a\u6570\u636e\u96c6\uff08\u4f7f\u7528\u9ad8\u68c9\u8bed\uff09\u4e2d\u62c6\u5206\u51fa\u4e00\u4e2a\u597d\u7684\u6d4b\u8bd5\u3002\u4e3a\u6b64\uff0c\u60a8\u53ef\u4ee5\u4f7f\u7528\u8c37\u6b4c\u7ffb\u8bd1\u7b49\u7ffb\u8bd1\u670d\u52a1\u3002\u9996\u5148\uff0c\u60a8\u5e94\u8be5\u5c06\u6b64\u6570\u636e\u96c6\u4fdd\u5b58\u4e3a Excel \u683c\u5f0f\uff0c\u5982\u4e0b\u6240\u793a\uff1a\n
                imdb_x = [x for x in imdb['train'][:1000]['text']]\nlabels = [x for x in imdb['train'][:1000]['label']]\nimport pandas as pd  \npd.DataFrame(imdb_x,\n             columns=[\"text\"]).to_excel(\n                                 \"imdb.xlsx\",\n                                  index=None)<\/code><\/pre>\n<\/li>\n
              4. \u4e4b\u540e\uff0c\u60a8\u53ef\u4ee5\u5c06\u5176\u4e0a\u4f20\u5230\u8c37\u6b4c\u7ffb\u8bd1\u5e76\u83b7\u53d6\u8be5\u6570\u636e\u96c6\u7684\u9ad8\u68c9\u8bed\u7ffb\u8bd1\uff08https:\/\/translate.google.com\/?sl=en&tl=km&op=docs\uff09\uff0c\u5982\u4e0b\u56fe\u6240\u793a\uff1a\n
                \n \"\u8de8\u8bed\u8a00\u4ea4\u6d41_recreational\n <\/div>\n<\/p>\n

                \u56fe 9.12 \u2013 \u8c37\u6b4c\u6587\u6863\u7ffb\u8bd1\u5668<\/p>\n<\/li>\n

              5. \u9009\u62e9\u540e\u5e76\u4e0a\u4f20\u6587\u4ef6\uff0c\u5b83\u5c06\u4e3a\u60a8\u63d0\u4f9b\u9ad8\u68c9\u8bed\u7684\u7ffb\u8bd1\u7248\u672c\uff0c\u60a8\u53ef\u4ee5\u5c06\u5176\u590d\u5236\u5e76\u7c98\u8d34\u5230 Excel \u6587\u4ef6\u4e2d\u3002\u8fd8\u9700\u8981\u518d\u6b21\u4ee5 Excel \u683c\u5f0f\u4fdd\u5b58\u3002\u7ed3\u679c\u5c06\u662f\u4e00\u4e2a Excel \u6587\u6863\uff0c\u5b83\u662f\u539f\u59cb spam\/ham \u82f1\u8bed\u6570\u636e\u96c6\u7684\u7ffb\u8bd1\u3002\u60a8\u53ef\u4ee5\u901a\u8fc7\u8fd0\u884c\u4ee5\u4e0b\u547d\u4ee4\u4f7f\u7528 pandas \u8bfb\u53d6\u5b83\uff1a\n
                pd.read_excel(\"KHMER.xlsx\")<\/code><\/pre>\n

                \u53ef\u4ee5\u770b\u5230\u7ed3\u679c\uff0c\u5982\u4e0b\uff1a<\/p>\n

                \n

                \"\u8de8\u8bed\u8a00\u4ea4\u6d41_recreational<\/p>\n<\/p><\/div>\n

                \u56fe 9.13 \u2013 \u9ad8\u68c9\u8bed IMDB \u6570\u636e\u96c6\u3002<\/p>\n<\/li>\n

              6. \u7136\u800c\uff0c\u5b83\u662f\u53ea\u9700\u8981\u83b7\u53d6\u6587\u672c\uff0c\u56e0\u6b64\u60a8\u5e94\u8be5\u4f7f\u7528\u4ee5\u4e0b\u4ee3\u7801\uff1a\n
                imdb_khmer = list(pd.read_excel(\"KHMER.xlsx\").text)<\/code><\/pre>\n<\/li>\n
              7. \u73b0\u5728\u60a8\u5df2\u7ecf\u62e5\u6709\u4e24\u79cd\u8bed\u8a00\u548c\u6807\u7b7e\u7684\u6587\u672c\uff0c\u60a8\u53ef\u4ee5\u62c6\u5206\u8bad\u7ec3\u548c\u6d4b\u8bd5\u9a8c\u8bc1\uff0c\u5982\u4e0b\u6240\u793a\uff1a\n
                from sklearn.model_selection import train_test_split\n\ntrain_x, test_x, train_y, test_y, khmer_train, khmer_test = train_test_split(imdb_x, labels, imdb_khmer, test_size = 0.2, random_state = 1)<\/code><\/pre>\n<\/li>\n
              8. \u4e0b\u4e00\u6b65\u662f\u4f7f\u7528 XLM-R \u8de8\u8bed\u8a00\u6a21\u578b\u63d0\u4f9b\u8fd9\u4e9b\u53e5\u5b50\u7684\u8868\u793a\u3002\u9996\u5148\uff0c\u60a8\u5e94\u8be5\u52a0\u8f7d\u6a21\u578b\uff0c\u5982\u4e0b\u6240\u793a\uff1a\n
                from sentence_transformers import SentenceTransformer\n\nmodel = SentenceTransformer(\"stsb-xlm-r-multilingual\")<\/code><\/pre>\n<\/li>\n
              9. \u73b0\u5728\uff0c\u60a8\u53ef\u4ee5\u83b7\u5f97\u8fd9\u4e9b\u8868\u793a\uff0c\u5982\u4e0b\u6240\u793a\uff1a\n
                encoded_train = model.encode(train_x)\nencoded_test = model.encode(test_x)\nencoded_khmer_test = model.encode(khmer_test)<\/code><\/pre>\n<\/li>\n
              10. \u4f46\u662f\u4f60\u4e0d\u8981\u5fd8\u8bb0\u5c06\u6807\u7b7e\u8f6c\u6362\u4e3anumpy<\/strong>\u683c\u5f0f\u56e0\u4e3a TensorFlow \u548c Keras \u5728\u4f7f\u7528 Keras \u6a21\u578b\u7684fit<\/strong>\u51fd\u6570\u65f6\u53ea\u5904\u7406numpy<\/strong>\u6570\u7ec4\u3002\u8fd9\u662f\u5982\u4f55\u505a\u5230\u7684\uff1a\n
                import numpy as np\n\ntrain_y = np.array(train_y)\ntest_y = np.array(test_y)<\/code><\/pre>\n<\/li>\n
              11. \u73b0\u5728\u4e00\u5207\u51c6\u5907\u5c31\u7eea\uff0c\u8ba9\u6211\u4eec\u5236\u4f5c\u4e00\u4e2a\u975e\u5e38\u7b80\u5355\u7684\u6a21\u578b\u6765\u5bf9\u8868\u793a\u8fdb\u884c\u5206\u7c7b\uff0c\u5982\u4e0b\u6240\u793a\uff1a\n
                import tensorflow as tf\n\ninput_ = tf.keras.layers.Input((768,))\nclassification = tf.keras.layers.Dense(\n                       1,\n                      activation=\"sigmoid\")(input_)\n\nclassification_model =  tf.keras.Model(input_, classification)\n\nclassification_model.compile(\n         loss=tf.keras.losses.BinaryCrossentropy(),\n         optimizer=\"Adam\",\n         metrics=[\"accuracy\", \"Precision\", \"Recall\"])<\/code><\/pre>\n<\/li>\n
              12. \u4f60\u53ef\u4ee5\u9002\u5408\u60a8\u7684\u6a21\u578b\u4f7f\u7528\u4ee5\u4e0b\u529f\u80fd\uff1a\n
                classification_model.fit(\n                     x = encoded_train,\n                     y = train_y,\n             validation_data=(encoded_test, test_y),\n                     epochs = 10)<\/code><\/pre>\n<\/li>\n
              13. \u5e76\u4e14\u663e\u793a\u4e8620 \u4e2a<\/strong>epoch \u7684\u8bad\u7ec3\u7ed3\u679c\uff0c\u5982\u4e0b\u6240\u793a\uff1a\n
                \n

                \"\u8de8\u8bed\u8a00\u4ea4\u6d41_recreational<\/p>\n<\/p><\/div>\n

                \u56fe 9.14 \u2013 IMDb \u6570\u636e\u96c6\u82f1\u6587\u7248\u7684\u8bad\u7ec3\u7ed3\u679c<\/p>\n<\/li>\n

              14. \u5982\u60a8\u6240\u89c1\uff0c\u6211\u4eec\u4f7f\u7528\u82f1\u8bed\u6d4b\u8bd5\u96c6\u6765\u67e5\u770b\u8de8\u65f6\u671f\u7684\u6a21\u578b\u6027\u80fd\uff0c\u5728\u6700\u7ec8\u65f6\u671f\u62a5\u544a\u5982\u4e0b\uff1a\n
                val_loss: 0.5226\nval_accuracy: 0.7150\nval_precision: 0.7600\nval_recall: 0.6972<\/code><\/pre>\n<\/li>\n
              15. \u73b0\u5728\u6211\u4eec\u5df2\u7ecf\u8bad\u7ec3\u4e86\u6211\u4eec\u7684\u6a21\u578b\u5e76\u5728\u82f1\u8bed\u4e0a\u5bf9\u5176\u8fdb\u884c\u4e86\u6d4b\u8bd5\uff0c\u8ba9\u6211\u4eec\u5728\u9ad8\u68c9\u8bed\u6d4b\u8bd5\u96c6\u4e0a\u5bf9\u5176\u8fdb\u884c\u6d4b\u8bd5\uff0c\u56e0\u4e3a\u6211\u4eec\u7684\u6a21\u578b\u4ece\u672a\u89c1\u8fc7\u4efb\u4f55\u82f1\u8bed\u6216\u9ad8\u68c9\u8bed\u6837\u672c\u3002\u8fd9\u662f\u5b8c\u6210\u6b64\u64cd\u4f5c\u7684\u4ee3\u7801\uff1a\n
                classification_model.evaluate(x = encoded_khmer_test, y = test_y)<\/code><\/pre>\n

                \u7ed3\u679c\u5982\u4e0b\uff1a<\/p>\n

                loss: 0.5949\naccuracy: 0.7250\nprecision: 0.7014\nrecall: 0.8623<\/code><\/pre>\n<\/li>\n<\/ol>\n

                \u5230\u76ee\u524d\u4e3a\u6b62\uff0c\u4f60\u5df2\u7ecf\u5b66\u4f1a\u4e86\u6211\u662f\u5982\u4f55t \u53ef\u4ee5\u5229\u7528\u4f4e\u8d44\u6e90\u8bed\u8a00\u7684\u8de8\u8bed\u8a00\u6a21\u578b\u3002\u5f53\u60a8\u53ef\u4ee5\u5728\u6837\u672c\u5f88\u5c11\u6216\u6ca1\u6709\u6837\u672c\u6765\u8bad\u7ec3\u6a21\u578b\u7684\u60c5\u51b5\u4e0b\u4f7f\u7528\u8fd9\u79cd\u529f\u80fd\u65f6\uff0c\u5b83\u4f1a\u4ea7\u751f\u5de8\u5927\u7684\u5f71\u54cd\u548c\u5dee\u5f02\u3002\u5728\u4e0b\u4e00\u8282\u4e2d\uff0c\u60a8\u5c06\u4e86\u89e3\u5982\u4f55\u5728\u6ca1\u6709\u53ef\u7528\u6837\u672c\u7684\u60c5\u51b5\u4e0b\u4f7f\u7528\u96f6\u6837\u672c\u5b66\u4e60\uff0c\u5373\u4f7f\u662f\u82f1\u8bed\u7b49\u8d44\u6e90\u4e30\u5bcc\u7684\u8bed\u8a00\u4e5f\u662f\u5982\u6b64\u3002<\/span><\/span><\/p>\n

                \u8de8\u8bed\u8a00\u96f6\u6837\u672c\u5b66\u4e60<\/span><\/span><\/h2>\n

                \u5728\u524d\u9762\u7684\u90e8\u5206\u4e2d\uff0c\u60a8\u5b66\u4e60\u4e86\u5982\u4f55\u4f7f\u7528\u5355\u8bed\u6a21\u578b\u6267\u884c\u96f6\u6837\u672c\u6587\u672c\u5206\u7c7b\u3002\u4f7f\u7528 XLM-R \u8fdb\u884c\u591a\u8bed\u8a00\u548c\u8de8\u8bed\u8a00\u96f6\u6837\u672c\u5206\u7c7b\u4e0e\u4e4b\u524d\u4f7f\u7528\u7684\u65b9\u6cd5\u548c\u4ee3\u7801\u76f8\u540c\uff0c\u56e0\u6b64\u6211\u4eec\u5c06\u5728\u8fd9\u91cc\u4f7f\u7528mT5<\/strong>\u3002<\/span><\/span><\/p>\n

                mT5 \u662f\u4e00\u79cd\u5927\u89c4\u6a21\u591a\u8bed\u8a00\u9884\u8bad\u7ec3\u8bed\u8a00\u6a21\u578b\uff0c\u57fa\u4e8e Transformers \u7684\u7f16\u7801\u5668-\u89e3\u7801\u5668\u67b6\u6784\uff0c\u4e5f\u4e0eT5<\/strong>\u76f8\u540c\u3002T5 \u662f\u9884\u8bad\u7ec3\u82f1\u8bed\u548c mT5 \u662f\u5bf9\u591a\u8bed\u8a00\u901a\u7528\u722c<\/strong>\u7f51( mC4<\/strong> )\u4e2d\u7684 101 \u79cd\u8bed\u8a00\u8fdb\u884c\u4e86\u57f9\u8bad\u3002<\/span><\/span><\/p>\n

                XNLI \u6570\u636e\u96c6\u4e0a\u7684 mT5 \u5fae\u8c03\u7248\u672c\u53ef\u4ece HuggingFace \u5b58\u50a8\u5e93 ( alan-turing-institute\/mt5-large-finetuned-mnli-xtreme-xnli \u00b7 Hugging Face ) \u83b7\u5f97\u3002<\/span><\/span><\/p>\n

                T5 \u6a21\u578b\u53ca\u5176\u53d8\u4f53 mT5 \u662f\u4e00\u4e2a\u5b8c\u5168\u6587\u672c\u5230\u6587\u672c\u7684\u6a21\u578b\uff0c\u8fd9\u610f\u5473\u7740\u5b83\u5c06\u4e3a\u7ed9\u5b9a\u7684\u4efb\u4f55\u4efb\u52a1\u751f\u6210\u6587\u672c\uff0c\u5373\u4f7f\u4efb\u52a1\u662f\u5206\u7c7b\u6216 NLI\u3002\u56e0\u6b64\uff0c\u5728\u63a8\u65ad\u6b64\u6a21\u578b\u7684\u60c5\u51b5\u4e0b\uff0c\u9700\u8981\u989d\u5916\u7684\u6b65\u9aa4\u3002\u6211\u4eec\u5c06\u91c7\u53d6\u4ee5\u4e0b\u6b65\u9aa4\uff1a<\/span><\/span><\/p>\n

                  \n
                1. \u7b2c\u4e00\u6b65\u662f\u52a0\u8f7d\u6a21\u578b\u548c\u5206\u8bcd\u5668\uff0c\u5982\u4e0b\uff1a\n
                  from torch.nn.functional import softmax\nfrom transformers import MT5ForConditionalGeneration, MT5Tokenizer\n\nmodel_name = \"alan-turing-institute\/mt5-large-finetuned-mnli-xtreme-xnli\"\ntokenizer = MT5Tokenizer.from_pretrained(model_name)\nmodel = MT5ForConditionalGeneration.from_pretrained(model_name)<\/code><\/pre>\n<\/li>\n
                2. \u5728\u4e0b\u4e00\u6b65\u4e2d\uff0c\u8ba9\u6211\u4eec\u63d0\u4f9b\u7528\u4e8e\u96f6\u6837\u672c\u5206\u7c7b\u7684\u6837\u672c\u2014\u2014\u4e00\u4e2a\u53e5\u5b50\u548c\u6807\u7b7e\uff0c\u5982\u4e0b\u6240\u793a\uff1a\n
                  sequence_to_classify = \"Wen werden Sie bei der n\u00e4chsten Wahl w\u00e4hlen? \"\n\ncandidate_labels = [\"spor\", \"ekonomi\", \"politika\"]\nhypothesis_template = \"Dieses Beispiel ist {}.\"<\/code><\/pre>\n

                  \u5982\u60a8\u6240\u89c1\uff0c\u5e8f\u5217\u672c\u8eab\u662f\u5fb7\u8bed\uff08\u201c\u4f60\u5c06\u5728\u4e0b\u6b21\u9009\u4e3e\u4e2d\u6295\u7968\u7ed9\u8c01\uff1f\u201d<\/strong>\uff09\uff0c\u4f46\u6807\u7b7e\u662f\u7528\u571f\u8033\u5176\u8bed\u5199\u7684\uff08\u201cspor\u201d<\/strong>\u3001\u201c<\/strong> ekonomi\u201d \u3001 \u201cpolitika \u201d<\/strong>\uff09\u3002\u5047\u8bbe<\/strong>\u6a21\u677f\u7528\u5fb7\u8bed\u8bf4\uff1a\u201c\u8fd9\u4e2a\u4f8b\u5b50\u662f\u2026\u2026\u201d<\/strong>\u3002<\/p>\n<\/li>\n

                3. \u4e0b\u4e00\u6b65\u662f\u8bbe\u7f6e\u8574\u6db5\u3001CONTRADICTS<\/strong>\u548cNEUTRAL\u7684\u6807\u7b7e<\/strong>\u6807\u8bc6\u7b26<\/strong>( IDs<\/strong> ) \uff0c\u7a0d\u540e\u5c06\u7528\u4e8e\u63a8\u65ad\u751f\u6210\u7684\u7ed3\u679c\u3002\u8fd9\u662f\u60a8\u9700\u8981\u6267\u884c\u6b64\u64cd\u4f5c\u7684\u4ee3\u7801\uff1a\n
                  ENTAILS_LABEL = \"_0\"\nNEUTRAL_LABEL = \"_1\"\nCONTRADICTS_LABEL = \"_2\"\n\nlabel_inds = tokenizer.convert_tokens_to_ids([\n                           ENTAILS_LABEL,\n                           NEUTRAL_LABEL,\n                           CONTRADICTS_LABEL])<\/code><\/pre>\n<\/li>\n
                4. \u4f60\u4f1a\u8bb0\u5f97\uff0cT5 \u6a21\u578b\u4f7f\u7528\u524d\u7f00\u6765\u4e86\u89e3\u5b83\u5e94\u8be5\u6267\u884c\u7684\u4efb\u52a1\u3002\u4ee5\u4e0b\u51fd\u6570\u63d0\u4f9b XNLI \u524d\u7f00\uff0c\u4ee5\u53ca\u6b63\u786e\u683c\u5f0f\u7684\u524d\u63d0\u548c\u5047\u8bbe\uff1a\n
                  def process_nli(premise, hypothesis):\n    return f'xnli: premise: {premise} hypothesis: {hypothesis}'<\/code><\/pre>\n<\/li>\n
                5. \u5728\u4e0b\u4e00\u6b65\u4e2d\uff0c\u5bf9\u4e8e\u6bcf\u4e2a\u6807\u7b7e\uff0c\u90fd\u4f1a\u751f\u6210\u4e00\u4e2a\u53e5\u5b50\uff0c\u5982\u4e0b\u9762\u7684\u4ee3\u7801\u7247\u6bb5\u6240\u793a\uff1a\n
                  pairs =[(sequence_to_classify,\\  \n      hypothesis_template.format(label)) for label in\n      candidate_labels]\n\nseqs = [process_nli(premise=premise,\n                    hypothesis=hypothesis)\n                    for premise, hypothesis in pairs]<\/code><\/pre>\n<\/li>\n
                6. \u60a8\u53ef\u4ee5\u901a\u8fc7\u6253\u5370\u5b83\u4eec\u6765\u67e5\u770b\u751f\u6210\u7684\u5e8f\u5217\uff0c\u5982\u4e0b\u6240\u793a\uff1a\n
                  print(seqs)<\/code><\/pre>\n

                  ['xnli: premise: Wen werden Sie bei der n\u00e4chsten Wahl w\u00e4hlen?  hypothesis: Dieses Beispiel ist spor.',<\/p>\n

                  'xnli: premise: Wen werden Sie bei der n\u00e4chsten Wahl w\u00e4hlen?  hypothesis: Dieses Beispiel ist ekonomi.',<\/p>\n

                  'xnli: premise: Wen werden Sie bei der n\u00e4chsten Wahl w\u00e4hlen?  hypothesis: Dieses Beispiel ist politika.']<\/p>\n

                  \u8fd9\u4e9b\u5e8f\u5217\u7b80\u5355\u5730\u8bf4\uff0c\u4efb\u52a1\u662f\u7531 xnli \u7f16\u7801\u7684XNLI:<\/strong> ; \u524d\u63d0\u53e5\u662f\u201c\u4f60\u5c06\u5728\u4e0b\u6b21\u9009\u4e3e\u4e2d\u6295\u7968\u7ed9\u8c01\uff1f\u201d <\/strong>\uff08\u5fb7\u8bed\uff09\uff0c\u5047\u8bbe\u662f\u201c\u8fd9\u4e2a\u4f8b\u5b50\u662f\u653f\u6cbb\u201d<\/strong>\u3001\u201c\u8fd9\u4e2a\u4f8b\u5b50\u662f\u8fd0\u52a8\u201d<\/strong>\u6216\u201c\u8fd9\u4e2a\u4f8b\u5b50\u662f\u7ecf\u6d4e\u201d<\/strong>\u3002<\/p>\n<\/li>\n

                7. \u5728\u4e0b\u4e00\u6b65\u4e2d\uff0c\u60a8\u53ef\u4ee5\u5bf9\u5e8f\u5217\u8fdb\u884c\u6807\u8bb0\uff0c\u5e76\u5c06\u5b83\u4eec\u4ea4\u7ed9\u6a21\u578b\u4ee5\u6839\u636e\u5b83\u751f\u6210\u6587\u672c\uff0c\u5982\u4e0b\u6240\u793a\uff1a\n
                  inputs = tokenizer.batch_encode_plus(seqs,  \n         return_tensors=\"pt\", padding=True)\n\nout = model.generate(**inputs, output_scores=True,\n        return_dict_in_generate=True,num_beams=1)<\/code><\/pre>\n<\/li>\n
                8. \u751f\u6210\u7684\u6587\u672c\u5b9e\u9645\u4e0a\u5bf9\u8bcd\u6c47\u8868\u4e2d\u7684\u6bcf\u4e2a\u6807\u8bb0\u90fd\u7ed9\u51fa\u4e86\u5206\u6570\uff0c\u800c\u6211\u4eec\u8981\u5bfb\u627e\u7684\u662f\u8574\u542b\u3001\u77db\u76fe\u548c\u4e2d\u6027\u5206\u6570\u3002\u60a8\u53ef\u4ee5\u4f7f\u7528\u4ed6\u4eec\u7684\u4ee4\u724c ID \u83b7\u5f97\u4ed6\u4eec\u7684\u5206\u6570\uff0c\u5982\u4e0b\u6240\u793a\uff1a\n
                  scores = out.scores[0]\nscores = scores[:, label_inds]<\/code><\/pre>\n<\/li>\n
                9. \u60a8\u53ef\u4ee5\u901a\u8fc7\u6253\u5370\u8fd9\u4e9b\u5206\u6570\u6765\u67e5\u770b\u5b83\u4eec\uff0c\u5982\u4e0b\u6240\u793a\uff1a\n
                  print(scores)<\/code><\/pre>\n

                  tensor([[-0.9851,  2.2550, -0.0783],<\/p>\n

                          [-5.1690, -0.7202, -2.5855],<\/p>\n

                          [ 2.7442,  3.6727,  0.7169]])<\/p>\n<\/li>\n

                10. \u4e2d\u6027\u5206\u6570\u4e0d\u662f\u4e3a\u6211\u4eec\u7684\u76ee\u7684\u6240\u5fc5\u9700\uff0c\u4e0e\u8574\u6db5\u76f8\u6bd4\uff0c\u6211\u4eec\u53ea\u9700\u8981\u77db\u76fe\u3002\u56e0\u6b64\uff0c\u60a8\u53ef\u4ee5\u4f7f\u7528\u4ee5\u4e0b\u4ee3\u7801\u4ec5\u83b7\u53d6\u8fd9\u4e9b\u5206\u6570\uff1a\n
                  entailment_ind = 0\ncontradiction_ind = 2\nentail_vs_contra_scores = scores[:, [entailment_ind, contradiction_ind]]<\/code><\/pre>\n<\/li>\n
                11. \u73b0\u5728\u60a8\u5df2\u7ecf\u4e3a\u6bcf\u4e2a\u6837\u672c\u5e8f\u5217\u83b7\u5f97\u4e86\u8fd9\u4e9b\u5206\u6570\uff0c\u60a8\u53ef\u4ee5\u5728\u5176\u4e0a\u5e94\u7528\u4e00\u4e2asoftmax<\/strong>\u5c42\u6765\u83b7\u5f97\u6982\u7387\uff0c\u5982\u4e0b\u6240\u793a\uff1a\n
                  entail_vs_contra_probas = softmax(entail_vs_contra_scores, dim=1)<\/code><\/pre>\n<\/li>\n
                12. \u8981\u67e5\u770b\u8fd9\u4e9b\u6982\u7387\uff0c\u60a8\u53ef\u4ee5\u4f7f\u7528print<\/strong>\uff0c\u5982\u4e0b\u6240\u793a\uff1a\n
                  print(entail_vs_contra_probas)<\/code><\/pre>\n

                  tensor([[0.2877, 0.7123],<\/p>\n

                          [0.0702, 0.9298],<\/p>\n

                          [0.8836, 0.1164]])<\/p>\n<\/li>\n

                13. \u73b0\u5728\uff0c\u60a8\u53ef\u4ee5\u901a\u8fc7\u9009\u62e9\u5b83\u4eec\u5e76\u5728\u5b83\u4eec\u4e0a\u5e94\u7528softmax<\/strong>\u5c42\u6765\u6bd4\u8f83\u8fd9\u4e09\u4e2a\u6837\u672c\u7684\u8574\u542b\u6982\u7387\uff0c\u5982\u4e0b\u6240\u793a\uff1a\n

                  entail_scores = scores[:, entailment_ind]<\/p>\n

                  entail_probas = softmax(entail_scores, dim=0)<\/p>\n<\/li>\n

                14. \u8981\u67e5\u770b\u503c\uff0c\u8bf7\u4f7f\u7528print<\/strong>\uff0c\u5982\u4e0b\u6240\u793a\uff1a\n
                  print(entail_probas)<\/code><\/pre>\n

                  tensor([2.3438e-02, 3.5716e-04, 9.7620e-01])<\/p>\n<\/li>\n

                15. \u7ed3\u679c\u610f\u5473\u7740\u6700\u9ad8\u6982\u7387\u5c5e\u4e8e\u7b2c\u4e09\u4e2a\u5e8f\u5217\u3002\u4e3a\u4e86\u66f4\u597d\u5730\u770b\u5230\u5b83\u5f62\u72b6\uff0c\u4f7f\u7528\u4ee5\u4e0b\u4ee3\u7801\uff1a\n
                  print(dict(zip(candidate_labels, entail_probas.tolist())))<\/code><\/pre>\n

                  {'ekonomi': 0.0003571564157027751,<\/p>\n

                  'politika': 0.9762046933174133,<\/p>\n

                  'spor': 0.023438096046447754}<\/p>\n<\/li>\n<\/ol>\n

                  \u6574\u4e2a\u8fc7\u7a0b\u53ef\u4ee5\u6982\u62ec\u4e3a\uff1a\u6bcf\u4e2a\u6807\u7b7e\u90fd\u8d4b\u4e88\u7ed9\u6a21\u578b\u6709\u524d\u63d0\uff0c\u6a21\u578b\u4e3a\u8bcd\u6c47\u8868\u4e2d\u7684\u6bcf\u4e2atoken\u751f\u6210\u5206\u6570\u3002\u6211\u4eec\u4f7f\u7528\u8fd9\u4e9b\u5206\u6570\u6765\u627e\u51fa\u8574\u542b\u4ee4\u724c\u5bf9\u77db\u76fe\u7684\u5206\u6570\u3002<\/span><\/span><\/p>\n

                  \u591a\u8bed\u8a00\u6a21\u578b\u7684\u57fa\u672c\u9650\u5236<\/span><\/span><\/h2>\n

                  \u867d\u7136\u591a\u8bed\u79cd\u548c\u8de8\u8bed\u8a00\u6a21\u578b\u5f88\u6709\u524d\u9014\uff0c\u4f1a\u5f71\u54cd NLP \u5de5\u4f5c\u7684\u65b9\u5411\uff0c\u4f46\u5b83\u4eec\u4ecd\u7136\u5b58\u5728\u4e00\u4e9b\u5c40\u9650\u6027\u3002\u6700\u8fd1\u7684\u8bb8\u591a\u4f5c\u54c1\u89e3\u51b3\u4e86\u8fd9\u4e9b\u9650\u5236\u3002\u76ee\u524d\uff0c\u4e0e\u5355\u8bed\u6a21\u578b\u76f8\u6bd4\uff0cmBERT \u6a21\u578b\u5728\u8bb8\u591a\u4efb\u52a1\u4e2d\u7684\u8868\u73b0\u7565\u900a\u4e00\u7b79\uff0c\u5e76\u4e14\u53ef\u80fd\u65e0\u6cd5\u66ff\u4ee3\u7ecf\u8fc7\u826f\u597d\u8bad\u7ec3\u7684\u5355\u8bed\u6a21\u578b\uff0c\u8fd9\u5c31\u662f\u4e3a\u4ec0\u4e48\u5355\u8bed\u6a21\u578b\u4ecd\u7136\u88ab\u5e7f\u6cdb\u4f7f\u7528\u7684\u539f\u56e0\u3002<\/span><\/span><\/p>\n

                  \u8be5\u9886\u57df\u7684\u7814\u7a76\u8868\u660e\uff0c\u591a\u8bed\u8a00\u6a21\u578b\u53d7\u5230\u6240\u8c13\u7684\u591a\u8bed\u8a00\u8bc5\u5492\uff0c<\/em>\u56e0\u4e3a\u5b83\u4eec\u8bd5\u56fe\u9002\u5f53\u5730\u4ee3\u8868\u6240\u6709\u8bed\u8a00\u3002\u5c06\u65b0\u8bed\u8a00\u6dfb\u52a0\u5230\u591a\u8bed\u8a00\u6a21\u578b\u53ef\u4ee5\u63d0\u9ad8\u5176\u6027\u80fd\uff0c\u8fbe\u5230\u4e00\u5b9a\u7a0b\u5ea6\u3002\u4f46\u662f\uff0c\u4e5f\u53ef\u4ee5\u770b\u51fa\uff0c\u5728\u8fd9\u4e00\u70b9\u4e4b\u540e\u6dfb\u52a0\u5b83\u4f1a\u964d\u4f4e\u6027\u80fd\uff0c\u8fd9\u53ef\u80fd\u662f\u7531\u4e8e\u5171\u4eab\u8bcd\u6c47\u8868\u9020\u6210\u7684\u3002\u4e0e\u5355\u8bed\u6a21\u578b\u76f8\u6bd4\uff0c\u591a\u8bed\u8a00\u6a21\u578b\u5728\u53c2\u6570\u9884\u7b97\u65b9\u9762\u660e\u663e\u53d7\u9650\u3002\u4ed6\u4eec\u9700\u8981\u5c06\u8bcd\u6c47\u5206\u914d\u5230 100 \u591a\u79cd\u8bed\u8a00\u4e2d\u7684\u6bcf\u4e00\u79cd\u3002<\/span><\/span><\/p>\n

                  \u5355\u8bed\u8a00\u6a21\u578b\u548c\u591a\u8bed\u8a00\u6a21\u578b\u4e4b\u95f4\u73b0\u6709\u7684\u6027\u80fd\u5dee\u5f02\u53ef\u5f52\u56e0\u4e8e\u6307\u5b9a\u6807\u8bb0\u5668\u7684\u80fd\u529b\u3002\u7814\u7a76\u4f60\u7684\u6807\u8bb0\u5668\u6709\u591a\u597d\uff1fRust \u7b49\u4eba\u7684\u5173\u4e8e\u591a\u8bed\u8a00\u6a21\u578b\u7684\u5355\u8bed\u6027\u80fd<\/em>\uff082021 \u5e74\uff09\u3002( https:\/\/arxiv.org\/abs\/2012.15613 ) \u8868\u660e\uff0c\u5f53\u5c06\u4e13\u7528\u7684\u7279\u5b9a\u8bed\u8a00\u6807\u8bb0\u5668\u800c\u4e0d\u662f\u901a\u7528\u6807\u8bb0\u5668\uff08\u5171\u4eab\u7684\u591a\u8bed\u8a00\u6807\u8bb0\u5668\uff09\u9644\u52a0\u5230\u591a\u8bed\u8a00\u6a21\u578b\u65f6\uff0c\u5b83\u4f1a\u63d0\u9ad8\u8be5\u8bed\u8a00\u7684\u6027\u80fd\u3002<\/span><\/span><\/p>\n

                  \u5176\u4ed6\u4e00\u4e9b\u53d1\u73b0\u8868\u660e\u7531\u4e8e\u4e0d\u540c\u8bed\u8a00\u7684\u8d44\u6e90\u5206\u5e03\u4e0d\u5e73\u8861\uff0c\u76ee\u524d\u4e0d\u53ef\u80fd\u5728\u4e00\u4e2a\u6a21\u578b\u4e2d\u4ee3\u8868\u4e16\u754c\u4e0a\u6240\u6709\u7684\u8bed\u8a00\u3002\u4f5c\u4e3a\u4e00\u79cd\u89e3\u51b3\u65b9\u6848\uff0c\u53ef\u4ee5\u5bf9\u4f4e\u8d44\u6e90\u8bed\u8a00\u8fdb\u884c\u8fc7\u91c7\u6837\uff0c\u800c\u5bf9\u9ad8\u8d44\u6e90\u8bed\u8a00\u8fdb\u884c\u6b20\u91c7\u6837\u3002\u53e6\u4e00\u4e2a\u89c2\u5bdf\u7ed3\u679c\u662f\uff0c\u5982\u679c\u4e24\u79cd\u8bed\u8a00\u76f8\u8fd1\uff0c\u4e24\u79cd\u8bed\u8a00\u4e4b\u95f4\u7684\u77e5\u8bc6\u8f6c\u79fb\u4f1a\u66f4\u6709\u6548\u3002\u5982\u679c\u5b83\u4eec\u662f\u9065\u8fdc\u7684\u8bed\u8a00\uff0c\u8fd9\u79cd\u8f6c\u79fb\u53ef\u80fd\u5f71\u54cd\u4e0d\u5927\u3002\u8fd9\u4e00\u89c2\u5bdf\u7ed3\u679c\u53ef\u4ee5\u89e3\u91ca\u4e3a\u4ec0\u4e48\u6211\u4eec\u5728\u4e4b\u524d\u7684\u8de8\u8bed\u8a00\u53e5\u5b50\u5bf9\u5b9e\u9a8c\u90e8\u5206\u4e2d\u5bf9\u5357\u975e\u8377\u5170\u8bed\u548c\u6cf0\u7c73\u5c14\u8bed\u7684\u7ed3\u679c\u66f4\u5dee\u3002<\/span><\/span><\/p>\n

                  \u7136\u800c\uff0c\u5728\u8fd9\u4e2a\u4e3b\u9898\u4e0a\u6709\u5f88\u591a\u5de5\u4f5c\uff0c\u8fd9\u4e9b\u9650\u5236\u53ef\u80fd\u968f\u65f6\u88ab\u514b\u670d\u3002\u5728\u64b0\u5199\u672c\u6587\u65f6\uff0cXML-R \u56e2\u961f\u6700\u8fd1\u63d0\u51fa\u4e86\u4e24\u4e2a\u65b0\u6a21\u578b\uff0c\u5373 XLM-R XL \u548c XLM-R XXL\uff0c\u5b83\u4eec\u5728 XNLI \u4e0a\u7684\u5e73\u5747\u51c6\u786e\u5ea6\u5206\u522b\u6bd4\u539f\u59cb XLM-R \u6a21\u578b\u9ad8 1.8% \u548c 2.4%\u3002<\/span><\/span><\/p>\n

                  \u5fae\u8c03\u591a\u8bed\u8a00\u6a21\u578b\u7684\u6027\u80fd<\/span><\/span><\/h3>\n

                  \u73b0\u5728\uff0c\u8ba9\u6211\u4eec\u68c0\u67e5\u4e00\u4e0b\u591a\u8bed\u8a00\u6a21\u578b\u7684\u5fae\u8c03\u6027\u80fd\u5b9e\u9645\u4e0a\u662f\u5426\u6bd4\u5355\u8bed\u6a21\u578b\u5dee\u578b\u53f7\u4e0e\u5426\u3002\u4f5c\u4e3a\u4e00\u4e2a\u4f8b\u5b50\uff0c\u8ba9\u6211\u4eec\u56de\u987e\u4e00\u4e0b\u7b2c 5 \u7ae0\u201c\u6587\u672c\u5206\u7c7b\u7684\u5fae\u8c03\u8bed\u8a00\u6a21\u578b\u201d<\/em>\u4e2d\u7684\u571f\u8033\u5176\u8bed\u6587\u672c\u5206\u7c7b\u7684\u4f8b\u5b50\uff0c\u5b83\u6709 7 \u4e2a\u7c7b\u3002\u5728\u90a3\u4e2a\u5b9e\u9a8c\u4e2d\uff0c\u6211\u4eec\u5fae\u8c03\u4e86\u4e00\u4e2a\u571f\u8033\u5176\u8bed\u7279\u6709\u7684\u5355\u8bed\u6a21\u578b\u5e76\u53d6\u5f97\u4e86\u5f88\u597d\u7684\u6548\u679c\u3002\u6211\u4eec\u5c06\u91cd\u590d\u76f8\u540c\u7684\u5b9e\u9a8c\uff0c\u4fdd\u6301\u4e00\u5207\u4e0d\u53d8\uff0c\u4f46\u5206\u522b\u7528 mBERT \u548c XLM-R \u6a21\u578b\u66ff\u6362\u571f\u8033\u5176\u5355\u8bed\u6a21\u578b\u3002\u6211\u4eec\u5c06\u8fd9\u6837\u505a\uff1a<\/span><\/span><\/p>\n

                    \n
                  1. \u8ba9\u6211\u4eec\u518d\u6b21\u56de\u5fc6\u4e00\u4e0b\u8be5\u793a\u4f8b\u4e2d\u7684\u4ee3\u7801\u3002\u6211\u4eec\u5bf9\u201cdbmdz\/bert-base-turkish-uncased\u201d<\/strong>\u6a21\u578b\u8fdb\u884c\u4e86\u5fae\u8c03\uff0c\u5982\u4e0b\u6240\u793a\uff1a\n
                    from transformers import BertTokenizerFast\n\ntokenizer = BertTokenizerFast.from_pretrained(\n                   \"dbmdz\/bert-base-turkish-uncased\")\n\nfrom transformers import BertForSequenceClassification\nmodel =  BertForSequenceClassification.from_pretrained(\"dbmdz\/bert-base-turkish-uncased\",num_labels=NUM_LABELS,\n                     id2label=id2label,\n                     label2id=label2id)<\/code><\/pre>\n

                    \u968f\u7740\u5355\u8bed\u6a21\u578b\uff0c\u6211\u4eec\u5f97\u5230\u4ee5\u4e0b\u6027\u80fd\u503c\uff1a<\/p>\n

                    \n \"\u8de8\u8bed\u8a00\u4ea4\u6d41_recreational\n <\/div>\n

                    \u56fe 9.15 \u2013 \u5355\u8bed\u6587\u672c\u5206\u7c7b\u6027\u80fd\uff08\u6765\u81ea\u7b2c 5 \u7ae0\uff0c\u6587\u672c\u5206\u7c7b\u7684\u5fae\u8c03\u8bed\u8a00\u6a21\u578b\uff09<\/p>\n<\/li>\n

                  2. \u8981\u4f7f\u7528 mBERT \u8fdb\u884c\u5fae\u8c03\uff0c\u6211\u4eec\u53ea\u9700\u8981\u66ff\u6362\u524d\u9762\u7684\u6a21\u578b\u5b9e\u4f8b\u5316\u884c\u3002\u73b0\u5728\uff0c\u6211\u4eec\u5c06\u4f7f\u7528\u201cbert-base-multilingual-uncased\u201d<\/strong>\u591a\u8bed\u8a00\u6a21\u578b\u3002\u6211\u4eec\u50cf\u8fd9\u6837\u5b9e\u4f8b\u5316\u5b83\uff1a\n

                    \u4ece\u53d8\u538b\u5668\u8fdb\u53e3\\ BertForSequenceClassification\uff0cAutoTokenizer<\/span><\/p>\n

                    from transformers import  BertForSequenceClassification, AutoTokenizer\n\ntokenizer = AutoTokenizer.from_pretrained(\n                   \"bert-base-multilingual-uncased\")\nmodel = BertForSequenceClassification.from_pretrained(\n                    \"bert-base-multilingual-uncased\",\n                     num_labels=NUM_LABELS,\n                     id2label=id2label,\n                     label2id=label2id)<\/code><\/pre>\n<\/li>\n
                  3. \u6709\u7f16\u7801\u5dee\u522b\u4e0d\u5927\u3002\u5f53\u6211\u4eec\u5728\u4fdd\u6301\u6240\u6709\u5176\u4ed6\u53c2\u6570\u548c\u8bbe\u7f6e\u76f8\u540c\u7684\u60c5\u51b5\u4e0b\u8fd0\u884c\u5b9e\u9a8c\u65f6\uff0c\u6211\u4eec\u5f97\u5230\u4ee5\u4e0b\u6027\u80fd\u503c\uff1a\n
                    \n

                    \"\u8de8\u8bed\u8a00\u4ea4\u6d41_recreational<\/p>\n<\/p><\/div>\n

                    \u56fe 9.16 \u2013 mBERT \u5fae\u8c03\u6027\u80fd<\/p>\n

                    \u5514\uff01\u4e0e\u5355\u8bed\u6a21\u578b\u76f8\u6bd4\uff0c\u591a\u8bed\u8a00\u6a21\u578b\u5728\u6240\u6709\u6307\u6807\u4e0a\u7684\u8868\u73b0\u90fd\u5dee\u4e86\u5927\u7ea6 2.2%\u3002<\/p>\n<\/li>\n

                  4. \u8ba9\u6211\u4eec\u9488\u5bf9\u76f8\u540c\u7684\u95ee\u9898\u5fae\u8c03\u201cxlm-roberta-base\u201d<\/strong> XLM-R \u6a21\u578b\u3002\u6211\u4eec\u5c06\u6267\u884c XLM-R \u6a21\u578b\u521d\u59cb\u5316\u4ee3\u7801\uff0c\u5982\u4e0b\u6240\u793a\uff1a\n
                    from transformers import AutoTokenizer, XLMRobertaForSequenceClassification\n\ntokenizer = AutoTokenizer.from_pretrained(\n                               \"xlm-roberta-base\")\n\nmodel = XLMRobertaForSequenceClassification.from_pretrained(\"xlm-roberta-base\",\n               num_labels=NUM_LABELS,\n              id2label=id2label,label2id=label2id)<\/code><\/pre>\n<\/li>\n
                  5. \u540c\u6837\uff0c\u6211\u4eec\u4fdd\u6301\u6240\u6709\u5176\u4ed6\u8bbe\u7f6e\u5b8c\u5168\u76f8\u540c\u3002\u6211\u4eec\u4f7f\u7528 XML-R \u6a21\u578b\u83b7\u5f97\u4ee5\u4e0b\u6027\u80fd\u503c\uff1a<\/li>\n<\/ol>\n
                    \n
                    \n

                    \"\u8de8\u8bed\u8a00\u4ea4\u6d41_recreational<\/p>\n<\/p><\/div>\n<\/div>\n

                    \u56fe 9.17 \u2013 XLM-R \u5fae\u8c03\u6027\u80fd<\/span><\/span><\/p>\n

                    \u4e0d\u9519\uff01\u8fd9XLM \u6a21\u578b\u786e\u5b9e\u7ed9\u51fa\u4e86\u53ef\u6bd4\u8f83\u7684\u7ed3\u679c\u3002\u5f97\u5230\u7684\u7ed3\u679c\u4e0e\u5355\u8bed\u6a21\u578b\u975e\u5e38\u63a5\u8fd1\uff0c\u76f8\u5dee\u7ea6 1.0%\u3002\u56e0\u6b64\uff0c\u5c3d\u7ba1\u5728\u67d0\u4e9b\u4efb\u52a1\u4e2d\u5355\u8bed\u7ed3\u679c\u53ef\u80fd\u4f18\u4e8e\u591a\u8bed\u8a00\u6a21\u578b\uff0c\u4f46\u6211\u4eec\u53ef\u4ee5\u4f7f\u7528\u591a\u8bed\u8a00\u6a21\u578b\u53d6\u5f97\u6709\u5e0c\u671b\u7684\u7ed3\u679c\u3002\u53ef\u4ee5\u8fd9\u6837\u60f3\uff1a\u6211\u4eec\u53ef\u80fd\u4e0d\u60f3\u8bad\u7ec3\u4e00\u4e2a\u5b8c\u6574\u7684\u5355\u8bed\u6a21\u578b\u6765\u83b7\u5f97\u6301\u7eed 10 \u5929\u6216\u66f4\u957f\u65f6\u95f4\u7684 1% \u6027\u80fd\u3002\u5982\u6b64\u5c0f\u7684\u6027\u80fd\u5dee\u5f02\u5bf9\u6211\u4eec\u6765\u8bf4\u53ef\u80fd\u53ef\u4ee5\u5ffd\u7565\u4e0d\u8ba1\u3002<\/span><\/span><\/p>\n

                    \u6982\u62ec<\/span><\/span><\/h2>\n

                    \u5728\u672c\u7ae0\u4e2d\uff0c\u60a8\u4e86\u89e3\u4e86\u591a\u8bed\u8a00\u548c\u8de8\u8bed\u8a00\u8bed\u8a00\u6a21\u578b\u9884\u8bad\u7ec3\u4ee5\u53ca\u5355\u8bed\u8a00\u548c\u591a\u8bed\u8a00\u9884\u8bad\u7ec3\u4e4b\u95f4\u7684\u533a\u522b\u3002\u8fd8\u6db5\u76d6\u4e86 CLM \u548c TLM\uff0c\u5e76\u4e14\u60a8\u83b7\u5f97\u4e86\u6709\u5173\u5b83\u4eec\u7684\u77e5\u8bc6\u3002\u60a8\u4e86\u89e3\u4e86\u5982\u4f55\u5728\u5404\u79cd\u7528\u4f8b\u4e2d\u4f7f\u7528\u8de8\u8bed\u8a00\u6a21\u578b\uff0c\u4f8b\u5982\u8bed\u4e49\u641c\u7d22\u3001\u6284\u88ad\u548c\u96f6\u6837\u672c\u6587\u672c\u5206\u7c7b\u3002\u60a8\u8fd8\u4e86\u89e3\u4e86\u5982\u4f55\u4f7f\u7528\u8de8\u8bed\u8a00\u6a21\u578b\u5bf9\u6765\u81ea\u4e00\u79cd\u8bed\u8a00\u7684\u6570\u636e\u96c6\u8fdb\u884c\u8bad\u7ec3\u5e76\u5728\u5b8c\u5168\u4e0d\u540c\u7684\u8bed\u8a00\u4e0a\u8fdb\u884c\u6d4b\u8bd5\u3002\u5bf9\u591a\u8bed\u8a00\u6a21\u578b\u7684\u6027\u80fd\u5fae\u8c03\u8fdb\u884c\u4e86\u8bc4\u4f30\uff0c\u6211\u4eec\u5f97\u51fa\u7684\u7ed3\u8bba\u662f\uff0c\u4e00\u4e9b\u591a\u8bed\u8a00\u6a21\u578b\u53ef\u4ee5\u66ff\u4ee3\u5355\u8bed\u8a00\u6a21\u578b\uff0c\u663e\u7740\u5730\u5c06\u6027\u80fd\u635f\u5931\u964d\u81f3\u6700\u4f4e\u3002<\/span><\/span><\/p>\n","protected":false},"excerpt":{"rendered":"\u8de8\u8bed\u8a00\u4ea4\u6d41_recreational function\u8bed\u8a00\u5b66\u5171\u4eab\u6807\u8bb0\u7684\u539f\u56e0\u662f\u5171\u4eab\u6807\u8bb0\u5728\u5177\u6709\u76f8\u4f3c\u6807\u8bb0\u6216\u5b50\u8bcd\u7684\u8bed\u8a00\u7684\u60c5\u51b5\u4e0b\u63d0\u4f9b\u7684\u6807\u8bb0\u8f83\u5c11\uff0c\u53e6\u4e00...","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[],"tags":[],"_links":{"self":[{"href":"https:\/\/mushiming.com\/wp-json\/wp\/v2\/posts\/8570"}],"collection":[{"href":"https:\/\/mushiming.com\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/mushiming.com\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/mushiming.com\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/mushiming.com\/wp-json\/wp\/v2\/comments?post=8570"}],"version-history":[{"count":0,"href":"https:\/\/mushiming.com\/wp-json\/wp\/v2\/posts\/8570\/revisions"}],"wp:attachment":[{"href":"https:\/\/mushiming.com\/wp-json\/wp\/v2\/media?parent=8570"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/mushiming.com\/wp-json\/wp\/v2\/categories?post=8570"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/mushiming.com\/wp-json\/wp\/v2\/tags?post=8570"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}