{"id":189,"date":"2025-07-02T11:23:47","date_gmt":"2025-07-02T03:23:47","guid":{"rendered":"https:\/\/mianka.xyz\/?p=189"},"modified":"2025-07-02T11:27:37","modified_gmt":"2025-07-02T03:27:37","slug":"pytorch","status":"publish","type":"post","link":"https:\/\/www.mianka.xyz\/?p=189","title":{"rendered":"PyTorch\u5b9e\u6218\uff1a\u4ece\u96f6\u6784\u5efa\u5e76\u8bad\u7ec3\u81ea\u5b9a\u4e49\u8bed\u6599\u5e93\u7684\u5b8c\u6574\u6307\u5357"},"content":{"rendered":"<h2 style=\"box-sizing: border-box; padding: 0px; -webkit-font-smoothing: antialiased; font-family: PingFangSC-Semibold; list-style: none; margin: 14px 0px 8px; scrollbar-width: none; color: rgb(5, 7, 59); font-size: 24px; border: none; line-height: 1.6; text-wrap-mode: wrap; background-color: rgb(253, 253, 254);\"><span style=\"box-sizing: border-box; padding: 0px; -webkit-font-smoothing: antialiased; font-family: -apple-system, BlinkMacSystemFont, &quot;Segoe UI&quot;, Roboto, Ubuntu, &quot;Helvetica Neue&quot;, Helvetica, Arial, &quot;PingFang SC&quot;, &quot;Hiragino Sans GB&quot;, &quot;Microsoft YaHei UI&quot;, &quot;Microsoft YaHei&quot;, &quot;Source Han Sans CN&quot;, sans-serif, &quot;Apple Color Emoji&quot;, &quot;Segoe UI Emoji&quot;; list-style: none; margin: 0px; scrollbar-width: none;\">\u4e00\u3001\u5f15\u8a00\uff1a\u4e3a\u4ec0\u4e48\u9700\u8981\u81ea\u5b9a\u4e49\u8bed\u6599\u5e93\uff1f<\/span><\/h2>\n<p id=\"\" style=\"box-sizing: border-box; padding: 0px; -webkit-font-smoothing: antialiased; font-family: PingFang-SC-Regular; list-style: none; margin-top: 0px; margin-bottom: 0px; scrollbar-width: none; font-size: 15px; line-height: 1.7; color: rgb(6, 7, 31); text-wrap-mode: wrap; background-color: rgb(253, 253, 254);\">\u5728NLP\u4efb\u52a1\u4e2d\uff0c\u516c\u5f00\u6570\u636e\u96c6\uff08\u5982IMDB\u5f71\u8bc4\u3001Wikipedia\uff09\u867d\u6613\u83b7\u53d6\uff0c\u4f46\u5f80\u5f80\u65e0\u6cd5\u6ee1\u8db3\u7279\u5b9a\u573a\u666f\u9700\u6c42\uff08\u5982\u884c\u4e1a\u672f\u8bed\u3001\u65b9\u8a00\u3001\u5782\u76f4\u9886\u57df\u77e5\u8bc6\uff09\u3002\u901a\u8fc7\u6784\u5efa\u81ea\u5b9a\u4e49\u8bed\u6599\u5e93\uff0c\u53ef\u4ee5\uff1a<\/p>\n<ul style=\"box-sizing: border-box; padding: 0px 0px 0px 30px; -webkit-font-smoothing: antialiased; font-family: PingFang-SC-Regular; list-style-position: outside; list-style-image: none; margin-top: 14px; margin-bottom: 1em; scrollbar-width: none; font-size: 15px; line-height: 1.7; color: rgb(6, 7, 31); text-wrap-mode: wrap; background-color: rgb(253, 253, 254);\" class=\" list-paddingleft-2\">\n<li>\n<p>\u8bad\u7ec3\u9488\u5bf9\u7279\u5b9a\u9886\u57df\u7684\u8bed\u8a00\u6a21\u578b\uff08\u5982\u533b\u7597\u3001\u6cd5\u5f8b\u6587\u672c\uff09\u3002<\/p>\n<\/li>\n<li>\n<p>\u89e3\u51b3\u6570\u636e\u9690\u79c1\u95ee\u9898\uff08\u5982\u4f01\u4e1a\u5185\u90e8\u6570\u636e\u65e0\u6cd5\u516c\u5f00\uff09\u3002<\/p>\n<\/li>\n<li>\n<p>\u63d0\u5347\u6a21\u578b\u5bf9\u5c0f\u4f17\u8bed\u8a00\u7684\u9002\u5e94\u6027\u3002<\/p>\n<\/li>\n<\/ul>\n<p id=\"\" style=\"box-sizing: border-box; padding: 0px; -webkit-font-smoothing: antialiased; font-family: PingFang-SC-Regular; list-style: none; margin-top: 14px; margin-bottom: 0px; scrollbar-width: none; font-size: 15px; line-height: 1.7; color: rgb(6, 7, 31); text-wrap-mode: wrap; background-color: rgb(253, 253, 254);\">\u672c\u6587\u4ee5<span style=\"box-sizing: border-box; padding: 0px; -webkit-font-smoothing: antialiased; font-family: -apple-system, BlinkMacSystemFont, &quot;Segoe UI&quot;, Roboto, Ubuntu, &quot;Helvetica Neue&quot;, Helvetica, Arial, &quot;PingFang SC&quot;, &quot;Hiragino Sans GB&quot;, &quot;Microsoft YaHei UI&quot;, &quot;Microsoft YaHei&quot;, &quot;Source Han Sans CN&quot;, sans-serif, &quot;Apple Color Emoji&quot;, &quot;Segoe UI Emoji&quot;; list-style: none; margin: 0px; scrollbar-width: none; font-weight: 600;\">\u60c5\u611f\u5206\u6790\u4efb\u52a1<\/span>\u4e3a\u4f8b\uff0c\u6f14\u793a\u5982\u4f55\u7528PyTorch\u8bad\u7ec3\u4e00\u4e2a\u57fa\u4e8e\u81ea\u5b9a\u4e49\u8bed\u6599\u5e93\u7684\u5206\u7c7b\u6a21\u578b\u3002<\/p>\n<hr style=\"box-sizing: content-box; padding: 0px; -webkit-font-smoothing: antialiased; font-family: -apple-system, BlinkMacSystemFont, &quot;Segoe UI&quot;, Roboto, Ubuntu, &quot;Helvetica Neue&quot;, Helvetica, Arial, &quot;PingFang SC&quot;, &quot;Hiragino Sans GB&quot;, &quot;Microsoft YaHei UI&quot;, &quot;Microsoft YaHei&quot;, &quot;Source Han Sans CN&quot;, sans-serif, &quot;Apple Color Emoji&quot;, &quot;Segoe UI Emoji&quot;; list-style: none; margin: 20px 0px; scrollbar-width: none; height: 0px; overflow: visible; border-right: 0px; border-bottom: 0px; border-left: 0px; border-image: initial; border-top-style: solid; border-top-color: rgb(230, 230, 235); color: rgb(6, 7, 31); font-size: 15px; text-wrap-mode: wrap; background-color: rgb(253, 253, 254);\"\/>\n<h2 style=\"box-sizing: border-box; padding: 0px; -webkit-font-smoothing: antialiased; font-family: PingFangSC-Semibold; list-style: none; margin: 14px 0px 8px; scrollbar-width: none; color: rgb(5, 7, 59); font-size: 24px; border: none; line-height: 1.6; text-wrap-mode: wrap; background-color: rgb(253, 253, 254);\"><span style=\"box-sizing: border-box; padding: 0px; -webkit-font-smoothing: antialiased; font-family: -apple-system, BlinkMacSystemFont, &quot;Segoe UI&quot;, Roboto, Ubuntu, &quot;Helvetica Neue&quot;, Helvetica, Arial, &quot;PingFang SC&quot;, &quot;Hiragino Sans GB&quot;, &quot;Microsoft YaHei UI&quot;, &quot;Microsoft YaHei&quot;, &quot;Source Han Sans CN&quot;, sans-serif, &quot;Apple Color Emoji&quot;, &quot;Segoe UI Emoji&quot;; list-style: none; margin: 0px; scrollbar-width: none;\">\u4e8c\u3001\u6784\u5efa\u81ea\u5b9a\u4e49\u8bed\u6599\u5e93\u7684\u5b8c\u6574\u6d41\u7a0b<\/span><\/h2>\n<h3 style=\"box-sizing: border-box; padding: 0px; -webkit-font-smoothing: antialiased; font-family: PingFangSC-Semibold; list-style: none; margin: 14px 0px 8px; scrollbar-width: none; color: rgb(5, 7, 59); font-size: 20px; border: none; line-height: 1.7; text-wrap-mode: wrap; background-color: rgb(253, 253, 254);\"><span style=\"box-sizing: border-box; padding: 0px; -webkit-font-smoothing: antialiased; font-family: -apple-system, BlinkMacSystemFont, &quot;Segoe UI&quot;, Roboto, Ubuntu, &quot;Helvetica Neue&quot;, Helvetica, Arial, &quot;PingFang SC&quot;, &quot;Hiragino Sans GB&quot;, &quot;Microsoft YaHei UI&quot;, &quot;Microsoft YaHei&quot;, &quot;Source Han Sans CN&quot;, sans-serif, &quot;Apple Color Emoji&quot;, &quot;Segoe UI Emoji&quot;; list-style: none; margin: 0px; scrollbar-width: none;\">1. \u6570\u636e\u6536\u96c6\u4e0e\u51c6\u5907<\/span><\/h3>\n<h4 style=\"box-sizing: border-box; padding: 0px; -webkit-font-smoothing: antialiased; font-family: PingFangSC-Semibold; list-style: none; margin: 14px 0px 8px; scrollbar-width: none; color: rgb(5, 7, 59); font-size: 18px; border: none; line-height: 1.7; text-wrap-mode: wrap; background-color: rgb(253, 253, 254);\"><span style=\"box-sizing: border-box; padding: 0px; -webkit-font-smoothing: antialiased; font-family: -apple-system, BlinkMacSystemFont, &quot;Segoe UI&quot;, Roboto, Ubuntu, &quot;Helvetica Neue&quot;, Helvetica, Arial, &quot;PingFang SC&quot;, &quot;Hiragino Sans GB&quot;, &quot;Microsoft YaHei UI&quot;, &quot;Microsoft YaHei&quot;, &quot;Source Han Sans CN&quot;, sans-serif, &quot;Apple Color Emoji&quot;, &quot;Segoe UI Emoji&quot;; list-style: none; margin: 0px; scrollbar-width: none;\">\u6570\u636e\u6765\u6e90<\/span><\/h4>\n<ul style=\"box-sizing: border-box; padding: 0px 0px 0px 30px; -webkit-font-smoothing: antialiased; font-family: PingFang-SC-Regular; list-style-position: outside; list-style-image: none; margin-top: 14px; margin-bottom: 1em; scrollbar-width: none; font-size: 15px; line-height: 1.7; color: rgb(6, 7, 31); text-wrap-mode: wrap; background-color: rgb(253, 253, 254);\" class=\" list-paddingleft-2\">\n<li>\n<p><span style=\"box-sizing: border-box; padding: 0px; -webkit-font-smoothing: antialiased; font-family: -apple-system, BlinkMacSystemFont, &quot;Segoe UI&quot;, Roboto, Ubuntu, &quot;Helvetica Neue&quot;, Helvetica, Arial, &quot;PingFang SC&quot;, &quot;Hiragino Sans GB&quot;, &quot;Microsoft YaHei UI&quot;, &quot;Microsoft YaHei&quot;, &quot;Source Han Sans CN&quot;, sans-serif, &quot;Apple Color Emoji&quot;, &quot;Segoe UI Emoji&quot;; list-style: none; margin: 0px; scrollbar-width: none; font-weight: 600;\">\u516c\u5f00\u6570\u636e<\/span>\uff1a\u722c\u53d6\u5782\u76f4\u9886\u57df\u7f51\u7ad9\uff08\u5982\u77e5\u4e4e\u884c\u4e1a\u8bdd\u9898\u3001\u8c46\u74e3\u4e66\u8bc4\uff09\u3002<\/p>\n<\/li>\n<li>\n<p><span style=\"box-sizing: border-box; padding: 0px; -webkit-font-smoothing: antialiased; font-family: -apple-system, BlinkMacSystemFont, &quot;Segoe UI&quot;, Roboto, Ubuntu, &quot;Helvetica Neue&quot;, Helvetica, Arial, &quot;PingFang SC&quot;, &quot;Hiragino Sans GB&quot;, &quot;Microsoft YaHei UI&quot;, &quot;Microsoft YaHei&quot;, &quot;Source Han Sans CN&quot;, sans-serif, &quot;Apple Color Emoji&quot;, &quot;Segoe UI Emoji&quot;; list-style: none; margin: 0px; scrollbar-width: none; font-weight: 600;\">\u79c1\u6709\u6570\u636e<\/span>\uff1a\u4f01\u4e1a\u65e5\u5fd7\u3001\u5ba2\u670d\u5bf9\u8bdd\u8bb0\u5f55\uff08\u9700\u8131\u654f\u5904\u7406\uff09\u3002<\/p>\n<\/li>\n<li>\n<p><span style=\"box-sizing: border-box; padding: 0px; -webkit-font-smoothing: antialiased; font-family: -apple-system, BlinkMacSystemFont, &quot;Segoe UI&quot;, Roboto, Ubuntu, &quot;Helvetica Neue&quot;, Helvetica, Arial, &quot;PingFang SC&quot;, &quot;Hiragino Sans GB&quot;, &quot;Microsoft YaHei UI&quot;, &quot;Microsoft YaHei&quot;, &quot;Source Han Sans CN&quot;, sans-serif, &quot;Apple Color Emoji&quot;, &quot;Segoe UI Emoji&quot;; list-style: none; margin: 0px; scrollbar-width: none; font-weight: 600;\">\u4eba\u5de5\u6807\u6ce8<\/span>\uff1a\u4f7f\u7528\u5de5\u5177\u5982<code class=\" inline\" style=\"box-sizing: border-box; padding: 1px 4px; -webkit-font-smoothing: antialiased; font-family: SFMono-Regular, Consolas, &quot;Liberation Mono&quot;, Menlo, Courier, monospace; list-style: none; margin: 0px 2px; scrollbar-width: none; font-size: 12.75px; tab-size: 4; background-color: rgba(27, 31, 35, 0.05); border-radius: 3px;\">Label Studio<\/code>\u6807\u6ce8\u60c5\u611f\u6807\u7b7e\uff08\u79ef\u6781\/\u6d88\u6781\uff09\u3002<\/p>\n<\/li>\n<\/ul>\n<h4 style=\"box-sizing: border-box; padding: 0px; -webkit-font-smoothing: antialiased; font-family: PingFangSC-Semibold; list-style: none; margin: 14px 0px 8px; scrollbar-width: none; color: rgb(5, 7, 59); font-size: 18px; border: none; line-height: 1.7; text-wrap-mode: wrap; background-color: rgb(253, 253, 254);\"><span style=\"box-sizing: border-box; padding: 0px; -webkit-font-smoothing: antialiased; font-family: -apple-system, BlinkMacSystemFont, &quot;Segoe UI&quot;, Roboto, Ubuntu, &quot;Helvetica Neue&quot;, Helvetica, Arial, &quot;PingFang SC&quot;, &quot;Hiragino Sans GB&quot;, &quot;Microsoft YaHei UI&quot;, &quot;Microsoft YaHei&quot;, &quot;Source Han Sans CN&quot;, sans-serif, &quot;Apple Color Emoji&quot;, &quot;Segoe UI Emoji&quot;; list-style: none; margin: 0px; scrollbar-width: none;\">\u6570\u636e\u683c\u5f0f<\/span><\/h4>\n<p id=\"\" style=\"box-sizing: border-box; padding: 0px; -webkit-font-smoothing: antialiased; font-family: PingFang-SC-Regular; list-style: none; margin-top: 0px; margin-bottom: 0px; scrollbar-width: none; font-size: 15px; line-height: 1.7; color: rgb(6, 7, 31); text-wrap-mode: wrap; background-color: rgb(253, 253, 254);\">\u5c06\u6587\u672c\u548c\u6807\u7b7e\u4fdd\u5b58\u4e3aCSV\u6587\u4ef6\uff0c\u793a\u4f8b\uff1a<\/p>\n<pre class=\"prism-highlight prism-language-python\">text,label\n&quot;\u8fd9\u4e2a\u4ea7\u54c1\u975e\u5e38\u597d\u7528&quot;,1\n&quot;\u670d\u52a1\u6001\u5ea6\u592a\u5dee\u4e86&quot;,0<\/pre>\n<h3 style=\"box-sizing: border-box; padding: 0px; -webkit-font-smoothing: antialiased; font-family: PingFangSC-Semibold; list-style: none; margin: 14px 0px 8px; scrollbar-width: none; color: rgb(5, 7, 59); font-size: 20px; border: none; line-height: 1.7; text-wrap-mode: wrap; background-color: rgb(253, 253, 254);\"><span style=\"box-sizing: border-box; padding: 0px; -webkit-font-smoothing: antialiased; font-family: -apple-system, BlinkMacSystemFont, &quot;Segoe UI&quot;, Roboto, Ubuntu, &quot;Helvetica Neue&quot;, Helvetica, Arial, &quot;PingFang SC&quot;, &quot;Hiragino Sans GB&quot;, &quot;Microsoft YaHei UI&quot;, &quot;Microsoft YaHei&quot;, &quot;Source Han Sans CN&quot;, sans-serif, &quot;Apple Color Emoji&quot;, &quot;Segoe UI Emoji&quot;; list-style: none; margin: 0px; scrollbar-width: none;\">2. \u6587\u672c\u9884\u5904\u7406<\/span><\/h3>\n<h4 style=\"box-sizing: border-box; padding: 0px; -webkit-font-smoothing: antialiased; font-family: PingFangSC-Semibold; list-style: none; margin: 14px 0px 8px; scrollbar-width: none; color: rgb(5, 7, 59); font-size: 18px; border: none; line-height: 1.7; text-wrap-mode: wrap; background-color: rgb(253, 253, 254);\"><span style=\"box-sizing: border-box; padding: 0px; -webkit-font-smoothing: antialiased; font-family: -apple-system, BlinkMacSystemFont, &quot;Segoe UI&quot;, Roboto, Ubuntu, &quot;Helvetica Neue&quot;, Helvetica, Arial, &quot;PingFang SC&quot;, &quot;Hiragino Sans GB&quot;, &quot;Microsoft YaHei UI&quot;, &quot;Microsoft YaHei&quot;, &quot;Source Han Sans CN&quot;, sans-serif, &quot;Apple Color Emoji&quot;, &quot;Segoe UI Emoji&quot;; list-style: none; margin: 0px; scrollbar-width: none;\">\u6b65\u9aa41\uff1a\u52a0\u8f7d\u6570\u636e<\/span><\/h4>\n<pre class=\"prism-highlight prism-language-python\">import&nbsp;pandas&nbsp;as&nbsp;pd\nfrom&nbsp;sklearn.model_selection&nbsp;import&nbsp;train_test_split\n\n#&nbsp;\u8bfb\u53d6\u6570\u636e\ndf&nbsp;=&nbsp;pd.read_csv(&quot;custom_corpus.csv&quot;)\ntexts&nbsp;=&nbsp;df[&quot;text&quot;].tolist()\nlabels&nbsp;=&nbsp;df[&quot;label&quot;].tolist()\n\n#&nbsp;\u5212\u5206\u8bad\u7ec3\u96c6\/\u9a8c\u8bc1\u96c6\/\u6d4b\u8bd5\u96c6\ntrain_texts,&nbsp;val_texts,&nbsp;train_labels,&nbsp;val_labels&nbsp;=&nbsp;train_test_split(\n&nbsp;&nbsp;&nbsp;&nbsp;texts,&nbsp;labels,&nbsp;test_size=0.2,&nbsp;random_state=42\n)<\/pre>\n<p><span style=\"box-sizing: border-box; padding: 0px; -webkit-font-smoothing: antialiased; font-family: -apple-system, BlinkMacSystemFont, &quot;Segoe UI&quot;, Roboto, Ubuntu, &quot;Helvetica Neue&quot;, Helvetica, Arial, &quot;PingFang SC&quot;, &quot;Hiragino Sans GB&quot;, &quot;Microsoft YaHei UI&quot;, &quot;Microsoft YaHei&quot;, &quot;Source Han Sans CN&quot;, sans-serif, &quot;Apple Color Emoji&quot;, &quot;Segoe UI Emoji&quot;; list-style: none; margin: 0px; scrollbar-width: none;\"><\/span><\/p>\n<h4 style=\"box-sizing: border-box; padding: 0px; -webkit-font-smoothing: antialiased; font-family: PingFangSC-Semibold; list-style: none; margin: 14px 0px 8px; scrollbar-width: none; color: rgb(5, 7, 59); font-size: 18px; border: none; line-height: 1.7; text-wrap-mode: wrap; background-color: rgb(253, 253, 254);\"><span style=\"box-sizing: border-box; padding: 0px; -webkit-font-smoothing: antialiased; font-family: -apple-system, BlinkMacSystemFont, &quot;Segoe UI&quot;, Roboto, Ubuntu, &quot;Helvetica Neue&quot;, Helvetica, Arial, &quot;PingFang SC&quot;, &quot;Hiragino Sans GB&quot;, &quot;Microsoft YaHei UI&quot;, &quot;Microsoft YaHei&quot;, &quot;Source Han Sans CN&quot;, sans-serif, &quot;Apple Color Emoji&quot;, &quot;Segoe UI Emoji&quot;; list-style: none; margin: 0px; scrollbar-width: none;\">\u6b65\u9aa42\uff1a\u6587\u672c\u6e05\u6d17<\/span><\/h4>\n<pre class=\"prism-highlight prism-language-python\">import&nbsp;re\nfrom&nbsp;nltk.tokenize&nbsp;import&nbsp;word_tokenize\nfrom&nbsp;nltk.corpus&nbsp;import&nbsp;stopwords\nimport&nbsp;string\n\ndef&nbsp;preprocess_text(text):\n&nbsp;&nbsp;&nbsp;&nbsp;#&nbsp;\u8f6c\u6362\u4e3a\u5c0f\u5199\n&nbsp;&nbsp;&nbsp;&nbsp;text&nbsp;=&nbsp;text.lower()\n&nbsp;&nbsp;&nbsp;&nbsp;#&nbsp;\u79fb\u9664\u7279\u6b8a\u5b57\u7b26\u548c\u6570\u5b57\n&nbsp;&nbsp;&nbsp;&nbsp;text&nbsp;=&nbsp;re.sub(r&quot;[^a-zA-Z\\s]&quot;,&nbsp;&quot;&quot;,&nbsp;text)\n&nbsp;&nbsp;&nbsp;&nbsp;#&nbsp;\u5206\u8bcd\u5e76\u79fb\u9664\u505c\u7528\u8bcd\n&nbsp;&nbsp;&nbsp;&nbsp;tokens&nbsp;=&nbsp;word_tokenize(text)\n&nbsp;&nbsp;&nbsp;&nbsp;stop_words&nbsp;=&nbsp;set(stopwords.words(&quot;english&quot;))\n&nbsp;&nbsp;&nbsp;&nbsp;tokens&nbsp;=&nbsp;[word&nbsp;for&nbsp;word&nbsp;in&nbsp;tokens&nbsp;if&nbsp;word&nbsp;not&nbsp;in&nbsp;stop_words&nbsp;and&nbsp;word&nbsp;not&nbsp;in&nbsp;string.punctuation]\n&nbsp;&nbsp;&nbsp;&nbsp;return&nbsp;&quot;&nbsp;&quot;.join(tokens)\n\n#&nbsp;\u5e94\u7528\u6e05\u6d17\ntrain_texts_clean&nbsp;=&nbsp;[preprocess_text(text)&nbsp;for&nbsp;text&nbsp;in&nbsp;train_texts]\nval_texts_clean&nbsp;=&nbsp;[preprocess_text(text)&nbsp;for&nbsp;text&nbsp;in&nbsp;val_texts]<\/pre>\n<p><span style=\"box-sizing: border-box; padding: 0px; -webkit-font-smoothing: antialiased; font-family: -apple-system, BlinkMacSystemFont, &quot;Segoe UI&quot;, Roboto, Ubuntu, &quot;Helvetica Neue&quot;, Helvetica, Arial, &quot;PingFang SC&quot;, &quot;Hiragino Sans GB&quot;, &quot;Microsoft YaHei UI&quot;, &quot;Microsoft YaHei&quot;, &quot;Source Han Sans CN&quot;, sans-serif, &quot;Apple Color Emoji&quot;, &quot;Segoe UI Emoji&quot;; list-style: none; margin: 0px; scrollbar-width: none;\"><\/span><\/p>\n<h4 style=\"box-sizing: border-box; padding: 0px; -webkit-font-smoothing: antialiased; font-family: PingFangSC-Semibold; list-style: none; margin: 14px 0px 8px; scrollbar-width: none; color: rgb(5, 7, 59); font-size: 18px; border: none; line-height: 1.7; text-wrap-mode: wrap; background-color: rgb(253, 253, 254);\"><span style=\"box-sizing: border-box; padding: 0px; -webkit-font-smoothing: antialiased; font-family: -apple-system, BlinkMacSystemFont, &quot;Segoe UI&quot;, Roboto, Ubuntu, &quot;Helvetica Neue&quot;, Helvetica, Arial, &quot;PingFang SC&quot;, &quot;Hiragino Sans GB&quot;, &quot;Microsoft YaHei UI&quot;, &quot;Microsoft YaHei&quot;, &quot;Source Han Sans CN&quot;, sans-serif, &quot;Apple Color Emoji&quot;, &quot;Segoe UI Emoji&quot;; list-style: none; margin: 0px; scrollbar-width: none;\">\u6b65\u9aa43\uff1a\u6784\u5efa\u8bcd\u6c47\u8868<\/span><\/h4>\n<pre class=\"prism-highlight prism-language-python\">from&nbsp;collections&nbsp;import&nbsp;Counter\n\n#&nbsp;\u7edf\u8ba1\u8bcd\u9891\u5e76\u6784\u5efa\u8bcd\u6c47\u8868\nvocab&nbsp;=&nbsp;Counter()\nfor&nbsp;text&nbsp;in&nbsp;train_texts_clean:\n&nbsp;&nbsp;&nbsp;&nbsp;vocab.update(text.split())\n\n#&nbsp;\u5b9a\u4e49\u8bcd\u6c47\u8868\u5927\u5c0f\u548c\u7279\u6b8a\u7b26\u53f7\nvocab_size&nbsp;=&nbsp;10000&nbsp;&nbsp;#&nbsp;\u4ec5\u4fdd\u7559\u524d10000\u4e2a\u9ad8\u9891\u8bcd\nUNK_TOKEN&nbsp;=&nbsp;&quot;&lt;UNK&gt;&quot;&nbsp;&nbsp;#&nbsp;\u672a\u77e5\u8bcd\nPAD_TOKEN&nbsp;=&nbsp;&quot;&lt;PAD&gt;&quot;&nbsp;&nbsp;#&nbsp;\u586b\u5145\u7b26\n\n#&nbsp;\u751f\u6210\u8bcd\u6c47\u8868\u5230\u7d22\u5f15\u7684\u6620\u5c04\nword2idx&nbsp;=&nbsp;{word:&nbsp;idx+2&nbsp;for&nbsp;idx,&nbsp;word&nbsp;in&nbsp;enumerate(list(vocab.keys())[:vocab_size-2])}\nword2idx[UNK_TOKEN]&nbsp;=&nbsp;0\nword2idx[PAD_TOKEN]&nbsp;=&nbsp;1\n\n#&nbsp;\u7d22\u5f15\u5230\u8bcd\u6c47\u8868\u7684\u6620\u5c04\nidx2word&nbsp;=&nbsp;{idx:&nbsp;word&nbsp;for&nbsp;word,&nbsp;idx&nbsp;in&nbsp;word2idx.items()}<\/pre>\n<p><span style=\"box-sizing: border-box; padding: 0px; -webkit-font-smoothing: antialiased; font-family: -apple-system, BlinkMacSystemFont, &quot;Segoe UI&quot;, Roboto, Ubuntu, &quot;Helvetica Neue&quot;, Helvetica, Arial, &quot;PingFang SC&quot;, &quot;Hiragino Sans GB&quot;, &quot;Microsoft YaHei UI&quot;, &quot;Microsoft YaHei&quot;, &quot;Source Han Sans CN&quot;, sans-serif, &quot;Apple Color Emoji&quot;, &quot;Segoe UI Emoji&quot;; list-style: none; margin: 0px; scrollbar-width: none;\"><\/span><\/p>\n<h4 style=\"box-sizing: border-box; padding: 0px; -webkit-font-smoothing: antialiased; font-family: PingFangSC-Semibold; list-style: none; margin: 14px 0px 8px; scrollbar-width: none; color: rgb(5, 7, 59); font-size: 18px; border: none; line-height: 1.7; text-wrap-mode: wrap; background-color: rgb(253, 253, 254);\"><span style=\"box-sizing: border-box; padding: 0px; -webkit-font-smoothing: antialiased; font-family: -apple-system, BlinkMacSystemFont, &quot;Segoe UI&quot;, Roboto, Ubuntu, &quot;Helvetica Neue&quot;, Helvetica, Arial, &quot;PingFang SC&quot;, &quot;Hiragino Sans GB&quot;, &quot;Microsoft YaHei UI&quot;, &quot;Microsoft YaHei&quot;, &quot;Source Han Sans CN&quot;, sans-serif, &quot;Apple Color Emoji&quot;, &quot;Segoe UI Emoji&quot;; list-style: none; margin: 0px; scrollbar-width: none;\">\u6b65\u9aa44\uff1a\u6587\u672c\u5411\u91cf\u5316<\/span><\/h4>\n<pre class=\"prism-highlight prism-language-python\">def&nbsp;text_to_sequence(text,&nbsp;word2idx,&nbsp;max_len=50):\n&nbsp;&nbsp;&nbsp;&nbsp;tokens&nbsp;=&nbsp;text.split()\n&nbsp;&nbsp;&nbsp;&nbsp;sequence&nbsp;=&nbsp;[word2idx.get(token,&nbsp;word2idx[UNK_TOKEN])&nbsp;for&nbsp;token&nbsp;in&nbsp;tokens]\n&nbsp;&nbsp;&nbsp;&nbsp;#&nbsp;\u586b\u5145\u6216\u622a\u65ad\u81f3\u56fa\u5b9a\u957f\u5ea6\n&nbsp;&nbsp;&nbsp;&nbsp;if&nbsp;len(sequence)&nbsp;&lt;&nbsp;max_len:\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;sequence&nbsp;+=&nbsp;[word2idx[PAD_TOKEN]]&nbsp;*&nbsp;(max_len&nbsp;-&nbsp;len(sequence))\n&nbsp;&nbsp;&nbsp;&nbsp;else:\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;sequence&nbsp;=&nbsp;sequence[:max_len]\n&nbsp;&nbsp;&nbsp;&nbsp;return&nbsp;sequence\n\n#&nbsp;\u8f6c\u6362\u6240\u6709\u6587\u672c\nmax_len&nbsp;=&nbsp;50\nX_train&nbsp;=&nbsp;[text_to_sequence(text,&nbsp;word2idx,&nbsp;max_len)&nbsp;for&nbsp;text&nbsp;in&nbsp;train_texts_clean]\nX_val&nbsp;=&nbsp;[text_to_sequence(text,&nbsp;word2idx,&nbsp;max_len)&nbsp;for&nbsp;text&nbsp;in&nbsp;val_texts_clean]\n\n#&nbsp;\u8f6c\u6362\u4e3aPyTorch\u5f20\u91cf\nimport&nbsp;torch\nX_train_tensor&nbsp;=&nbsp;torch.LongTensor(X_train)\nX_val_tensor&nbsp;=&nbsp;torch.LongTensor(X_val)\ny_train_tensor&nbsp;=&nbsp;torch.LongTensor(train_labels)\ny_val_tensor&nbsp;=&nbsp;torch.LongTensor(val_labels)<\/pre>\n<p><span style=\"box-sizing: border-box; padding: 0px; -webkit-font-smoothing: antialiased; font-family: -apple-system, BlinkMacSystemFont, &quot;Segoe UI&quot;, Roboto, Ubuntu, &quot;Helvetica Neue&quot;, Helvetica, Arial, &quot;PingFang SC&quot;, &quot;Hiragino Sans GB&quot;, &quot;Microsoft YaHei UI&quot;, &quot;Microsoft YaHei&quot;, &quot;Source Han Sans CN&quot;, sans-serif, &quot;Apple Color Emoji&quot;, &quot;Segoe UI Emoji&quot;; list-style: none; margin: 0px; scrollbar-width: none;\"><\/span><\/p>\n<h3 style=\"box-sizing: border-box; padding: 0px; -webkit-font-smoothing: antialiased; font-family: PingFangSC-Semibold; list-style: none; margin: 14px 0px 8px; scrollbar-width: none; color: rgb(5, 7, 59); font-size: 20px; border: none; line-height: 1.7; text-wrap-mode: wrap; background-color: rgb(253, 253, 254);\"><span style=\"box-sizing: border-box; padding: 0px; -webkit-font-smoothing: antialiased; font-family: -apple-system, BlinkMacSystemFont, &quot;Segoe UI&quot;, Roboto, Ubuntu, &quot;Helvetica Neue&quot;, Helvetica, Arial, &quot;PingFang SC&quot;, &quot;Hiragino Sans GB&quot;, &quot;Microsoft YaHei UI&quot;, &quot;Microsoft YaHei&quot;, &quot;Source Han Sans CN&quot;, sans-serif, &quot;Apple Color Emoji&quot;, &quot;Segoe UI Emoji&quot;; list-style: none; margin: 0px; scrollbar-width: none;\">3. \u5b9a\u4e49\u795e\u7ecf\u7f51\u7edc\u6a21\u578b<\/span><\/h3>\n<h4 style=\"box-sizing: border-box; padding: 0px; -webkit-font-smoothing: antialiased; font-family: PingFangSC-Semibold; list-style: none; margin: 14px 0px 8px; scrollbar-width: none; color: rgb(5, 7, 59); font-size: 18px; border: none; line-height: 1.7; text-wrap-mode: wrap; background-color: rgb(253, 253, 254);\"><span style=\"box-sizing: border-box; padding: 0px; -webkit-font-smoothing: antialiased; font-family: -apple-system, BlinkMacSystemFont, &quot;Segoe UI&quot;, Roboto, Ubuntu, &quot;Helvetica Neue&quot;, Helvetica, Arial, &quot;PingFang SC&quot;, &quot;Hiragino Sans GB&quot;, &quot;Microsoft YaHei UI&quot;, &quot;Microsoft YaHei&quot;, &quot;Source Han Sans CN&quot;, sans-serif, &quot;Apple Color Emoji&quot;, &quot;Segoe UI Emoji&quot;; list-style: none; margin: 0px; scrollbar-width: none;\">\u6a21\u578b\u67b6\u6784<\/span><\/h4>\n<p id=\"\" style=\"box-sizing: border-box; padding: 0px; -webkit-font-smoothing: antialiased; font-family: PingFang-SC-Regular; list-style: none; margin-top: 0px; margin-bottom: 0px; scrollbar-width: none; font-size: 15px; line-height: 1.7; color: rgb(6, 7, 31); text-wrap-mode: wrap; background-color: rgb(253, 253, 254);\">\u4f7f\u7528<span style=\"box-sizing: border-box; padding: 0px; -webkit-font-smoothing: antialiased; font-family: -apple-system, BlinkMacSystemFont, &quot;Segoe UI&quot;, Roboto, Ubuntu, &quot;Helvetica Neue&quot;, Helvetica, Arial, &quot;PingFang SC&quot;, &quot;Hiragino Sans GB&quot;, &quot;Microsoft YaHei UI&quot;, &quot;Microsoft YaHei&quot;, &quot;Source Han Sans CN&quot;, sans-serif, &quot;Apple Color Emoji&quot;, &quot;Segoe UI Emoji&quot;; list-style: none; margin: 0px; scrollbar-width: none; font-weight: 600;\">TextCNN<\/span>\uff08\u5377\u79ef\u795e\u7ecf\u7f51\u7edc\uff09\u8fdb\u884c\u6587\u672c\u5206\u7c7b\uff1a<\/p>\n<pre class=\"prism-highlight prism-language-python\">import&nbsp;torch.nn&nbsp;as&nbsp;nn\nimport&nbsp;torch.nn.functional&nbsp;as&nbsp;F\n\nclass&nbsp;TextCNN(nn.Module):\n&nbsp;&nbsp;&nbsp;&nbsp;def&nbsp;__init__(self,&nbsp;vocab_size,&nbsp;embed_dim,&nbsp;num_classes,&nbsp;kernel_sizes=[3,&nbsp;4,&nbsp;5]):\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;super(TextCNN,&nbsp;self).__init__()\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;self.embedding&nbsp;=&nbsp;nn.Embedding(vocab_size,&nbsp;embed_dim,&nbsp;padding_idx=1)\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;self.convs&nbsp;=&nbsp;nn.ModuleList([\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;nn.Conv2d(1,&nbsp;1,&nbsp;(k,&nbsp;embed_dim))&nbsp;for&nbsp;k&nbsp;in&nbsp;kernel_sizes\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;])\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;self.fc&nbsp;=&nbsp;nn.Linear(len(kernel_sizes),&nbsp;num_classes)\n\n&nbsp;&nbsp;&nbsp;&nbsp;def&nbsp;forward(self,&nbsp;x):\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;#&nbsp;x&nbsp;shape:&nbsp;[batch_size,&nbsp;seq_len]\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;x&nbsp;=&nbsp;self.embedding(x)&nbsp;&nbsp;#&nbsp;[batch_size,&nbsp;seq_len,&nbsp;embed_dim]\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;x&nbsp;=&nbsp;x.unsqueeze(1)&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;#&nbsp;[batch_size,&nbsp;1,&nbsp;seq_len,&nbsp;embed_dim]\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;#&nbsp;\u901a\u8fc7\u4e0d\u540c\u5377\u79ef\u6838\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;conv_outputs&nbsp;=&nbsp;[]\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;for&nbsp;conv&nbsp;in&nbsp;self.convs:\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;out&nbsp;=&nbsp;conv(x)&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;#&nbsp;[batch_size,&nbsp;1,&nbsp;seq_len-k+1,&nbsp;1]\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;out&nbsp;=&nbsp;F.relu(out.squeeze(3))&nbsp;&nbsp;#&nbsp;[batch_size,&nbsp;1,&nbsp;seq_len-k+1]\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;out&nbsp;=&nbsp;F.max_pool1d(out,&nbsp;out.size(2))&nbsp;&nbsp;#&nbsp;[batch_size,&nbsp;1,&nbsp;1]\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;conv_outputs.append(out.squeeze(2))\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;#&nbsp;\u62fc\u63a5\u6240\u6709\u5377\u79ef\u7ed3\u679c\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;x&nbsp;=&nbsp;torch.cat(conv_outputs,&nbsp;dim=1)&nbsp;&nbsp;#&nbsp;[batch_size,&nbsp;num_filters]\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;x&nbsp;=&nbsp;self.fc(x)&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;#&nbsp;[batch_size,&nbsp;num_classes]\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;return&nbsp;x<\/pre>\n<h4 style=\"box-sizing: border-box; padding: 0px; -webkit-font-smoothing: antialiased; font-family: PingFangSC-Semibold; list-style: none; margin: 14px 0px 8px; scrollbar-width: none; color: rgb(5, 7, 59); font-size: 18px; border: none; line-height: 1.7; text-wrap-mode: wrap; background-color: rgb(253, 253, 254);\"><span style=\"box-sizing: border-box; padding: 0px; -webkit-font-smoothing: antialiased; font-family: -apple-system, BlinkMacSystemFont, &quot;Segoe UI&quot;, Roboto, Ubuntu, &quot;Helvetica Neue&quot;, Helvetica, Arial, &quot;PingFang SC&quot;, &quot;Hiragino Sans GB&quot;, &quot;Microsoft YaHei UI&quot;, &quot;Microsoft YaHei&quot;, &quot;Source Han Sans CN&quot;, sans-serif, &quot;Apple Color Emoji&quot;, &quot;Segoe UI Emoji&quot;; list-style: none; margin: 0px; scrollbar-width: none;\">\u521d\u59cb\u5316\u6a21\u578b<\/span><\/h4>\n<pre style=\"box-sizing: border-box; padding: 0px; -webkit-font-smoothing: antialiased; font-family: SFMono-Regular, Consolas, &quot;Liberation Mono&quot;, Menlo, Courier, monospace; list-style: none; margin-top: 8px; margin-bottom: 8px; scrollbar-width: none; font-size: 15px; overflow: auto; position: relative; color: rgb(6, 7, 31); background-color: rgb(253, 253, 254);\">pythonvocab_size&nbsp;=&nbsp;len(word2idx)embed_dim&nbsp;=&nbsp;128num_classes&nbsp;=&nbsp;2&nbsp;&nbsp;#&nbsp;\u4e8c\u5206\u7c7bmodel&nbsp;=&nbsp;TextCNN(vocab_size,&nbsp;embed_dim,&nbsp;num_classes)<\/pre>\n<h3 style=\"box-sizing: border-box; padding: 0px; -webkit-font-smoothing: antialiased; font-family: PingFangSC-Semibold; list-style: none; margin: 14px 0px 8px; scrollbar-width: none; color: rgb(5, 7, 59); font-size: 20px; border: none; line-height: 1.7; text-wrap-mode: wrap; background-color: rgb(253, 253, 254);\"><span style=\"box-sizing: border-box; padding: 0px; -webkit-font-smoothing: antialiased; font-family: -apple-system, BlinkMacSystemFont, &quot;Segoe UI&quot;, Roboto, Ubuntu, &quot;Helvetica Neue&quot;, Helvetica, Arial, &quot;PingFang SC&quot;, &quot;Hiragino Sans GB&quot;, &quot;Microsoft YaHei UI&quot;, &quot;Microsoft YaHei&quot;, &quot;Source Han Sans CN&quot;, sans-serif, &quot;Apple Color Emoji&quot;, &quot;Segoe UI Emoji&quot;; list-style: none; margin: 0px; scrollbar-width: none;\">4. \u8bad\u7ec3\u6a21\u578b<\/span><\/h3>\n<h4 style=\"box-sizing: border-box; padding: 0px; -webkit-font-smoothing: antialiased; font-family: PingFangSC-Semibold; list-style: none; margin: 14px 0px 8px; scrollbar-width: none; color: rgb(5, 7, 59); font-size: 18px; border: none; line-height: 1.7; text-wrap-mode: wrap; background-color: rgb(253, 253, 254);\"><span style=\"box-sizing: border-box; padding: 0px; -webkit-font-smoothing: antialiased; font-family: -apple-system, BlinkMacSystemFont, &quot;Segoe UI&quot;, Roboto, Ubuntu, &quot;Helvetica Neue&quot;, Helvetica, Arial, &quot;PingFang SC&quot;, &quot;Hiragino Sans GB&quot;, &quot;Microsoft YaHei UI&quot;, &quot;Microsoft YaHei&quot;, &quot;Source Han Sans CN&quot;, sans-serif, &quot;Apple Color Emoji&quot;, &quot;Segoe UI Emoji&quot;; list-style: none; margin: 0px; scrollbar-width: none;\">\u5b9a\u4e49\u635f\u5931\u51fd\u6570\u548c\u4f18\u5316\u5668<\/span><\/h4>\n<pre class=\"prism-highlight prism-language-python\">import&nbsp;torch.optim&nbsp;as&nbsp;optim\n\ncriterion&nbsp;=&nbsp;nn.CrossEntropyLoss()\noptimizer&nbsp;=&nbsp;optim.Adam(model.parameters(),&nbsp;lr=0.001)<\/pre>\n<p><span style=\"box-sizing: border-box; padding: 0px; -webkit-font-smoothing: antialiased; font-family: -apple-system, BlinkMacSystemFont, &quot;Segoe UI&quot;, Roboto, Ubuntu, &quot;Helvetica Neue&quot;, Helvetica, Arial, &quot;PingFang SC&quot;, &quot;Hiragino Sans GB&quot;, &quot;Microsoft YaHei UI&quot;, &quot;Microsoft YaHei&quot;, &quot;Source Han Sans CN&quot;, sans-serif, &quot;Apple Color Emoji&quot;, &quot;Segoe UI Emoji&quot;; list-style: none; margin: 0px; scrollbar-width: none;\"><\/span><\/p>\n<h4 style=\"box-sizing: border-box; padding: 0px; -webkit-font-smoothing: antialiased; font-family: PingFangSC-Semibold; list-style: none; margin: 14px 0px 8px; scrollbar-width: none; color: rgb(5, 7, 59); font-size: 18px; border: none; line-height: 1.7; text-wrap-mode: wrap; background-color: rgb(253, 253, 254);\"><span style=\"box-sizing: border-box; padding: 0px; -webkit-font-smoothing: antialiased; font-family: -apple-system, BlinkMacSystemFont, &quot;Segoe UI&quot;, Roboto, Ubuntu, &quot;Helvetica Neue&quot;, Helvetica, Arial, &quot;PingFang SC&quot;, &quot;Hiragino Sans GB&quot;, &quot;Microsoft YaHei UI&quot;, &quot;Microsoft YaHei&quot;, &quot;Source Han Sans CN&quot;, sans-serif, &quot;Apple Color Emoji&quot;, &quot;Segoe UI Emoji&quot;; list-style: none; margin: 0px; scrollbar-width: none;\">\u8bad\u7ec3\u5faa\u73af<\/span><\/h4>\n<pre class=\"prism-highlight prism-language-python\">def&nbsp;train_model(model,&nbsp;X_train,&nbsp;y_train,&nbsp;X_val,&nbsp;y_val,&nbsp;epochs=10,&nbsp;batch_size=32):\n&nbsp;&nbsp;&nbsp;&nbsp;model.train()\n&nbsp;&nbsp;&nbsp;&nbsp;for&nbsp;epoch&nbsp;in&nbsp;range(epochs):\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;total_loss&nbsp;=&nbsp;0\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;for&nbsp;i&nbsp;in&nbsp;range(0,&nbsp;len(X_train),&nbsp;batch_size):\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;#&nbsp;\u83b7\u53d6\u6279\u6b21\u6570\u636e\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;batch_X&nbsp;=&nbsp;X_train[i:i+batch_size]\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;batch_y&nbsp;=&nbsp;y_train[i:i+batch_size]\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;#&nbsp;\u524d\u5411\u4f20\u64ad\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;outputs&nbsp;=&nbsp;model(batch_X)\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;loss&nbsp;=&nbsp;criterion(outputs,&nbsp;batch_y)\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;#&nbsp;\u53cd\u5411\u4f20\u64ad\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;optimizer.zero_grad()\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;loss.backward()\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;optimizer.step()\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;total_loss&nbsp;+=&nbsp;loss.item()\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;#&nbsp;\u9a8c\u8bc1\u96c6\u8bc4\u4f30\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;val_loss,&nbsp;val_acc&nbsp;=&nbsp;evaluate_model(model,&nbsp;X_val,&nbsp;y_val,&nbsp;batch_size)\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;print(f&quot;Epoch&nbsp;{epoch+1},&nbsp;Train&nbsp;Loss:&nbsp;{total_loss\/(len(X_train)\/batch_size):.4f},&nbsp;&quot;\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;f&quot;Val&nbsp;Loss:&nbsp;{val_loss:.4f},&nbsp;Val&nbsp;Acc:&nbsp;{val_acc:.4f}&quot;)\n\ndef&nbsp;evaluate_model(model,&nbsp;X_val,&nbsp;y_val,&nbsp;batch_size):\n&nbsp;&nbsp;&nbsp;&nbsp;model.eval()\n&nbsp;&nbsp;&nbsp;&nbsp;total_loss&nbsp;=&nbsp;0\n&nbsp;&nbsp;&nbsp;&nbsp;correct&nbsp;=&nbsp;0\n&nbsp;&nbsp;&nbsp;&nbsp;total&nbsp;=&nbsp;0\n&nbsp;&nbsp;&nbsp;&nbsp;with&nbsp;torch.no_grad():\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;for&nbsp;i&nbsp;in&nbsp;range(0,&nbsp;len(X_val),&nbsp;batch_size):\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;batch_X&nbsp;=&nbsp;X_val[i:i+batch_size]\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;batch_y&nbsp;=&nbsp;y_val[i:i+batch_size]\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;outputs&nbsp;=&nbsp;model(batch_X)\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;loss&nbsp;=&nbsp;criterion(outputs,&nbsp;batch_y)\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;total_loss&nbsp;+=&nbsp;loss.item()\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;_,&nbsp;predicted&nbsp;=&nbsp;torch.max(outputs.data,&nbsp;1)\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;total&nbsp;+=&nbsp;batch_y.size(0)\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;correct&nbsp;+=&nbsp;(predicted&nbsp;==&nbsp;batch_y).sum().item()\n&nbsp;&nbsp;&nbsp;&nbsp;\n&nbsp;&nbsp;&nbsp;&nbsp;accuracy&nbsp;=&nbsp;correct&nbsp;\/&nbsp;total\n&nbsp;&nbsp;&nbsp;&nbsp;return&nbsp;total_loss\/(len(X_val)\/batch_size),&nbsp;accuracy\n\n#&nbsp;\u542f\u52a8\u8bad\u7ec3\ntrain_model(model,&nbsp;X_train_tensor,&nbsp;y_train_tensor,&nbsp;X_val_tensor,&nbsp;y_val_tensor)<\/pre>\n<p><span style=\"box-sizing: border-box; padding: 0px; -webkit-font-smoothing: antialiased; font-family: -apple-system, BlinkMacSystemFont, &quot;Segoe UI&quot;, Roboto, Ubuntu, &quot;Helvetica Neue&quot;, Helvetica, Arial, &quot;PingFang SC&quot;, &quot;Hiragino Sans GB&quot;, &quot;Microsoft YaHei UI&quot;, &quot;Microsoft YaHei&quot;, &quot;Source Han Sans CN&quot;, sans-serif, &quot;Apple Color Emoji&quot;, &quot;Segoe UI Emoji&quot;; list-style: none; margin: 0px; scrollbar-width: none;\"><\/span><\/p>\n<h3 style=\"box-sizing: border-box; padding: 0px; -webkit-font-smoothing: antialiased; font-family: PingFangSC-Semibold; list-style: none; margin: 14px 0px 8px; scrollbar-width: none; color: rgb(5, 7, 59); font-size: 20px; border: none; line-height: 1.7; text-wrap-mode: wrap; background-color: rgb(253, 253, 254);\"><span style=\"box-sizing: border-box; padding: 0px; -webkit-font-smoothing: antialiased; font-family: -apple-system, BlinkMacSystemFont, &quot;Segoe UI&quot;, Roboto, Ubuntu, &quot;Helvetica Neue&quot;, Helvetica, Arial, &quot;PingFang SC&quot;, &quot;Hiragino Sans GB&quot;, &quot;Microsoft YaHei UI&quot;, &quot;Microsoft YaHei&quot;, &quot;Source Han Sans CN&quot;, sans-serif, &quot;Apple Color Emoji&quot;, &quot;Segoe UI Emoji&quot;; list-style: none; margin: 0px; scrollbar-width: none;\">5. \u6a21\u578b\u8bc4\u4f30\u4e0e\u4f18\u5316<\/span><\/h3>\n<h4 style=\"box-sizing: border-box; padding: 0px; -webkit-font-smoothing: antialiased; font-family: PingFangSC-Semibold; list-style: none; margin: 14px 0px 8px; scrollbar-width: none; color: rgb(5, 7, 59); font-size: 18px; border: none; line-height: 1.7; text-wrap-mode: wrap; background-color: rgb(253, 253, 254);\"><span style=\"box-sizing: border-box; padding: 0px; -webkit-font-smoothing: antialiased; font-family: -apple-system, BlinkMacSystemFont, &quot;Segoe UI&quot;, Roboto, Ubuntu, &quot;Helvetica Neue&quot;, Helvetica, Arial, &quot;PingFang SC&quot;, &quot;Hiragino Sans GB&quot;, &quot;Microsoft YaHei UI&quot;, &quot;Microsoft YaHei&quot;, &quot;Source Han Sans CN&quot;, sans-serif, &quot;Apple Color Emoji&quot;, &quot;Segoe UI Emoji&quot;; list-style: none; margin: 0px; scrollbar-width: none;\">\u8bc4\u4f30\u6307\u6807<\/span><\/h4>\n<ul style=\"box-sizing: border-box; padding: 0px 0px 0px 30px; -webkit-font-smoothing: antialiased; font-family: PingFang-SC-Regular; list-style-position: outside; list-style-image: none; margin-top: 14px; margin-bottom: 1em; scrollbar-width: none; font-size: 15px; line-height: 1.7; color: rgb(6, 7, 31); text-wrap-mode: wrap; background-color: rgb(253, 253, 254);\" class=\" list-paddingleft-2\">\n<li>\n<p><span style=\"box-sizing: border-box; padding: 0px; -webkit-font-smoothing: antialiased; font-family: -apple-system, BlinkMacSystemFont, &quot;Segoe UI&quot;, Roboto, Ubuntu, &quot;Helvetica Neue&quot;, Helvetica, Arial, &quot;PingFang SC&quot;, &quot;Hiragino Sans GB&quot;, &quot;Microsoft YaHei UI&quot;, &quot;Microsoft YaHei&quot;, &quot;Source Han Sans CN&quot;, sans-serif, &quot;Apple Color Emoji&quot;, &quot;Segoe UI Emoji&quot;; list-style: none; margin: 0px; scrollbar-width: none; font-weight: 600;\">\u51c6\u786e\u7387\uff08Accuracy\uff09<\/span>\uff1a\u6b63\u786e\u5206\u7c7b\u6837\u672c\u5360\u6bd4\u3002<\/p>\n<\/li>\n<li>\n<p><span style=\"box-sizing: border-box; padding: 0px; -webkit-font-smoothing: antialiased; font-family: -apple-system, BlinkMacSystemFont, &quot;Segoe UI&quot;, Roboto, Ubuntu, &quot;Helvetica Neue&quot;, Helvetica, Arial, &quot;PingFang SC&quot;, &quot;Hiragino Sans GB&quot;, &quot;Microsoft YaHei UI&quot;, &quot;Microsoft YaHei&quot;, &quot;Source Han Sans CN&quot;, sans-serif, &quot;Apple Color Emoji&quot;, &quot;Segoe UI Emoji&quot;; list-style: none; margin: 0px; scrollbar-width: none; font-weight: 600;\">F1\u5206\u6570<\/span>\uff1a\u5e73\u8861\u7cbe\u786e\u7387\u548c\u53ec\u56de\u7387\uff08\u9002\u7528\u4e8e\u7c7b\u522b\u4e0d\u5e73\u8861\u6570\u636e\uff09\u3002<\/p>\n<\/li>\n<\/ul>\n<h4 style=\"box-sizing: border-box; padding: 0px; -webkit-font-smoothing: antialiased; font-family: PingFangSC-Semibold; list-style: none; margin: 14px 0px 8px; scrollbar-width: none; color: rgb(5, 7, 59); font-size: 18px; border: none; line-height: 1.7; text-wrap-mode: wrap; background-color: rgb(253, 253, 254);\"><span style=\"box-sizing: border-box; padding: 0px; -webkit-font-smoothing: antialiased; font-family: -apple-system, BlinkMacSystemFont, &quot;Segoe UI&quot;, Roboto, Ubuntu, &quot;Helvetica Neue&quot;, Helvetica, Arial, &quot;PingFang SC&quot;, &quot;Hiragino Sans GB&quot;, &quot;Microsoft YaHei UI&quot;, &quot;Microsoft YaHei&quot;, &quot;Source Han Sans CN&quot;, sans-serif, &quot;Apple Color Emoji&quot;, &quot;Segoe UI Emoji&quot;; list-style: none; margin: 0px; scrollbar-width: none;\">\u4f18\u5316\u65b9\u5411<\/span><\/h4>\n<ol style=\"box-sizing: border-box; padding: 0px 0px 0px 30px; -webkit-font-smoothing: antialiased; font-family: PingFang-SC-Regular; list-style-position: outside; list-style-image: none; margin-top: 14px; margin-bottom: 1em; scrollbar-width: none; font-size: 15px; line-height: 1.7; color: rgb(6, 7, 31); text-wrap-mode: wrap; background-color: rgb(253, 253, 254);\" class=\" list-paddingleft-2\">\n<li>\n<p><span style=\"box-sizing: border-box; padding: 0px; -webkit-font-smoothing: antialiased; font-family: -apple-system, BlinkMacSystemFont, &quot;Segoe UI&quot;, Roboto, Ubuntu, &quot;Helvetica Neue&quot;, Helvetica, Arial, &quot;PingFang SC&quot;, &quot;Hiragino Sans GB&quot;, &quot;Microsoft YaHei UI&quot;, &quot;Microsoft YaHei&quot;, &quot;Source Han Sans CN&quot;, sans-serif, &quot;Apple Color Emoji&quot;, &quot;Segoe UI Emoji&quot;; list-style: none; margin: 0px; scrollbar-width: none; font-weight: 600;\">\u8d85\u53c2\u6570\u8c03\u4f18<\/span>\uff1a\u8c03\u6574\u5b66\u4e60\u7387\u3001\u6279\u6b21\u5927\u5c0f\u3001\u5377\u79ef\u6838\u5927\u5c0f\u3002<\/p>\n<\/li>\n<li>\n<p><span style=\"box-sizing: border-box; padding: 0px; -webkit-font-smoothing: antialiased; font-family: -apple-system, BlinkMacSystemFont, &quot;Segoe UI&quot;, Roboto, Ubuntu, &quot;Helvetica Neue&quot;, Helvetica, Arial, &quot;PingFang SC&quot;, &quot;Hiragino Sans GB&quot;, &quot;Microsoft YaHei UI&quot;, &quot;Microsoft YaHei&quot;, &quot;Source Han Sans CN&quot;, sans-serif, &quot;Apple Color Emoji&quot;, &quot;Segoe UI Emoji&quot;; list-style: none; margin: 0px; scrollbar-width: none; font-weight: 600;\">\u6a21\u578b\u6539\u8fdb<\/span>\uff1a\u5c1d\u8bd5LSTM\u3001BERT\u7b49\u66f4\u590d\u6742\u7684\u67b6\u6784\u3002<\/p>\n<\/li>\n<li>\n<p><span style=\"box-sizing: border-box; padding: 0px; -webkit-font-smoothing: antialiased; font-family: -apple-system, BlinkMacSystemFont, &quot;Segoe UI&quot;, Roboto, Ubuntu, &quot;Helvetica Neue&quot;, Helvetica, Arial, &quot;PingFang SC&quot;, &quot;Hiragino Sans GB&quot;, &quot;Microsoft YaHei UI&quot;, &quot;Microsoft YaHei&quot;, &quot;Source Han Sans CN&quot;, sans-serif, &quot;Apple Color Emoji&quot;, &quot;Segoe UI Emoji&quot;; list-style: none; margin: 0px; scrollbar-width: none; font-weight: 600;\">\u6570\u636e\u589e\u5f3a<\/span>\uff1a\u540c\u4e49\u8bcd\u66ff\u6362\u3001\u56de\u8bd1\uff08Back Translation\uff09\u6269\u5145\u6570\u636e\u96c6\u3002<\/p>\n<\/li>\n<\/ol>\n<hr style=\"box-sizing: content-box; padding: 0px; -webkit-font-smoothing: antialiased; font-family: -apple-system, BlinkMacSystemFont, &quot;Segoe UI&quot;, Roboto, Ubuntu, &quot;Helvetica Neue&quot;, Helvetica, Arial, &quot;PingFang SC&quot;, &quot;Hiragino Sans GB&quot;, &quot;Microsoft YaHei UI&quot;, &quot;Microsoft YaHei&quot;, &quot;Source Han Sans CN&quot;, sans-serif, &quot;Apple Color Emoji&quot;, &quot;Segoe UI Emoji&quot;; list-style: none; margin: 20px 0px; scrollbar-width: none; height: 0px; overflow: visible; border-right: 0px; border-bottom: 0px; border-left: 0px; border-image: initial; border-top-style: solid; border-top-color: rgb(230, 230, 235); color: rgb(6, 7, 31); font-size: 15px; text-wrap-mode: wrap; background-color: rgb(253, 253, 254);\"\/>\n<h2 style=\"box-sizing: border-box; padding: 0px; -webkit-font-smoothing: antialiased; font-family: PingFangSC-Semibold; list-style: none; margin: 14px 0px 8px; scrollbar-width: none; color: rgb(5, 7, 59); font-size: 24px; border: none; line-height: 1.6; text-wrap-mode: wrap; background-color: rgb(253, 253, 254);\"><span style=\"box-sizing: border-box; padding: 0px; -webkit-font-smoothing: antialiased; font-family: -apple-system, BlinkMacSystemFont, &quot;Segoe UI&quot;, Roboto, Ubuntu, &quot;Helvetica Neue&quot;, Helvetica, Arial, &quot;PingFang SC&quot;, &quot;Hiragino Sans GB&quot;, &quot;Microsoft YaHei UI&quot;, &quot;Microsoft YaHei&quot;, &quot;Source Han Sans CN&quot;, sans-serif, &quot;Apple Color Emoji&quot;, &quot;Segoe UI Emoji&quot;; list-style: none; margin: 0px; scrollbar-width: none;\">\u4e09\u3001\u603b\u7ed3\u4e0e\u6269\u5c55<\/span><\/h2>\n<h3 style=\"box-sizing: border-box; padding: 0px; -webkit-font-smoothing: antialiased; font-family: PingFangSC-Semibold; list-style: none; margin: 14px 0px 8px; scrollbar-width: none; color: rgb(5, 7, 59); font-size: 20px; border: none; line-height: 1.7; text-wrap-mode: wrap; background-color: rgb(253, 253, 254);\"><span style=\"box-sizing: border-box; padding: 0px; -webkit-font-smoothing: antialiased; font-family: -apple-system, BlinkMacSystemFont, &quot;Segoe UI&quot;, Roboto, Ubuntu, &quot;Helvetica Neue&quot;, Helvetica, Arial, &quot;PingFang SC&quot;, &quot;Hiragino Sans GB&quot;, &quot;Microsoft YaHei UI&quot;, &quot;Microsoft YaHei&quot;, &quot;Source Han Sans CN&quot;, sans-serif, &quot;Apple Color Emoji&quot;, &quot;Segoe UI Emoji&quot;; list-style: none; margin: 0px; scrollbar-width: none;\">\u5173\u952e\u70b9\u56de\u987e<\/span><\/h3>\n<ol style=\"box-sizing: border-box; padding: 0px 0px 0px 30px; -webkit-font-smoothing: antialiased; font-family: PingFang-SC-Regular; list-style-position: outside; list-style-image: none; margin-top: 14px; margin-bottom: 1em; scrollbar-width: none; font-size: 15px; line-height: 1.7; color: rgb(6, 7, 31); text-wrap-mode: wrap; background-color: rgb(253, 253, 254);\" class=\" list-paddingleft-2\">\n<li>\n<p><span style=\"box-sizing: border-box; padding: 0px; -webkit-font-smoothing: antialiased; font-family: -apple-system, BlinkMacSystemFont, &quot;Segoe UI&quot;, Roboto, Ubuntu, &quot;Helvetica Neue&quot;, Helvetica, Arial, &quot;PingFang SC&quot;, &quot;Hiragino Sans GB&quot;, &quot;Microsoft YaHei UI&quot;, &quot;Microsoft YaHei&quot;, &quot;Source Han Sans CN&quot;, sans-serif, &quot;Apple Color Emoji&quot;, &quot;Segoe UI Emoji&quot;; list-style: none; margin: 0px; scrollbar-width: none; font-weight: 600;\">\u6570\u636e\u9884\u5904\u7406<\/span>\uff1a\u6e05\u6d17\u3001\u5206\u8bcd\u3001\u6784\u5efa\u8bcd\u6c47\u8868\u662f\u57fa\u7840\u3002<\/p>\n<\/li>\n<li>\n<p><span style=\"box-sizing: border-box; padding: 0px; -webkit-font-smoothing: antialiased; font-family: -apple-system, BlinkMacSystemFont, &quot;Segoe UI&quot;, Roboto, Ubuntu, &quot;Helvetica Neue&quot;, Helvetica, Arial, &quot;PingFang SC&quot;, &quot;Hiragino Sans GB&quot;, &quot;Microsoft YaHei UI&quot;, &quot;Microsoft YaHei&quot;, &quot;Source Han Sans CN&quot;, sans-serif, &quot;Apple Color Emoji&quot;, &quot;Segoe UI Emoji&quot;; list-style: none; margin: 0px; scrollbar-width: none; font-weight: 600;\">\u6a21\u578b\u8bbe\u8ba1<\/span>\uff1aTextCNN\u9002\u5408\u77ed\u6587\u672c\u5206\u7c7b\uff0cLSTM\/Transformer\u9002\u5408\u957f\u6587\u672c\u3002<\/p>\n<\/li>\n<li>\n<p><span style=\"box-sizing: border-box; padding: 0px; -webkit-font-smoothing: antialiased; font-family: -apple-system, BlinkMacSystemFont, &quot;Segoe UI&quot;, Roboto, Ubuntu, &quot;Helvetica Neue&quot;, Helvetica, Arial, &quot;PingFang SC&quot;, &quot;Hiragino Sans GB&quot;, &quot;Microsoft YaHei UI&quot;, &quot;Microsoft YaHei&quot;, &quot;Source Han Sans CN&quot;, sans-serif, &quot;Apple Color Emoji&quot;, &quot;Segoe UI Emoji&quot;; list-style: none; margin: 0px; scrollbar-width: none; font-weight: 600;\">\u8bad\u7ec3\u6280\u5de7<\/span>\uff1a\u6279\u91cf\u8bad\u7ec3\u3001\u5b66\u4e60\u7387\u8c03\u5ea6\u3001\u65e9\u505c\uff08Early Stopping\uff09\u9632\u6b62\u8fc7\u62df\u5408\u3002<\/p>\n<\/li>\n<\/ol>\n<h3 style=\"box-sizing: border-box; padding: 0px; -webkit-font-smoothing: antialiased; font-family: PingFangSC-Semibold; list-style: none; margin: 14px 0px 8px; scrollbar-width: none; color: rgb(5, 7, 59); font-size: 20px; border: none; line-height: 1.7; text-wrap-mode: wrap; background-color: rgb(253, 253, 254);\"><span style=\"box-sizing: border-box; padding: 0px; -webkit-font-smoothing: antialiased; font-family: -apple-system, BlinkMacSystemFont, &quot;Segoe UI&quot;, Roboto, Ubuntu, &quot;Helvetica Neue&quot;, Helvetica, Arial, &quot;PingFang SC&quot;, &quot;Hiragino Sans GB&quot;, &quot;Microsoft YaHei UI&quot;, &quot;Microsoft YaHei&quot;, &quot;Source Han Sans CN&quot;, sans-serif, &quot;Apple Color Emoji&quot;, &quot;Segoe UI Emoji&quot;; list-style: none; margin: 0px; scrollbar-width: none;\">\u6269\u5c55\u5e94\u7528<\/span><\/h3>\n<ul style=\"box-sizing: border-box; padding: 0px 0px 0px 30px; -webkit-font-smoothing: antialiased; font-family: PingFang-SC-Regular; list-style-position: outside; list-style-image: none; margin-top: 14px; margin-bottom: 1em; scrollbar-width: none; font-size: 15px; line-height: 1.7; color: rgb(6, 7, 31); text-wrap-mode: wrap; background-color: rgb(253, 253, 254);\" class=\" list-paddingleft-2\">\n<li>\n<p><span style=\"box-sizing: border-box; padding: 0px; -webkit-font-smoothing: antialiased; font-family: -apple-system, BlinkMacSystemFont, &quot;Segoe UI&quot;, Roboto, Ubuntu, &quot;Helvetica Neue&quot;, Helvetica, Arial, &quot;PingFang SC&quot;, &quot;Hiragino Sans GB&quot;, &quot;Microsoft YaHei UI&quot;, &quot;Microsoft YaHei&quot;, &quot;Source Han Sans CN&quot;, sans-serif, &quot;Apple Color Emoji&quot;, &quot;Segoe UI Emoji&quot;; list-style: none; margin: 0px; scrollbar-width: none; font-weight: 600;\">\u591a\u8bed\u8a00\u652f\u6301<\/span>\uff1a\u4f7f\u7528<code class=\" inline\" style=\"box-sizing: border-box; padding: 1px 4px; -webkit-font-smoothing: antialiased; font-family: SFMono-Regular, Consolas, &quot;Liberation Mono&quot;, Menlo, Courier, monospace; list-style: none; margin: 0px 2px; scrollbar-width: none; font-size: 12.75px; tab-size: 4; background-color: rgba(27, 31, 35, 0.05); border-radius: 3px;\">sentencepiece<\/code>\u5206\u8bcd\u5668\u5904\u7406\u975e\u7a7a\u683c\u5206\u9694\u8bed\u8a00\uff08\u5982\u4e2d\u6587\uff09\u3002<\/p>\n<\/li>\n<li>\n<p><span style=\"box-sizing: border-box; padding: 0px; -webkit-font-smoothing: antialiased; font-family: -apple-system, BlinkMacSystemFont, &quot;Segoe UI&quot;, Roboto, Ubuntu, &quot;Helvetica Neue&quot;, Helvetica, Arial, &quot;PingFang SC&quot;, &quot;Hiragino Sans GB&quot;, &quot;Microsoft YaHei UI&quot;, &quot;Microsoft YaHei&quot;, &quot;Source Han Sans CN&quot;, sans-serif, &quot;Apple Color Emoji&quot;, &quot;Segoe UI Emoji&quot;; list-style: none; margin: 0px; scrollbar-width: none; font-weight: 600;\">\u90e8\u7f72\u4e0a\u7ebf<\/span>\uff1a\u5c06\u6a21\u578b\u5bfc\u51fa\u4e3a<code class=\" inline\" style=\"box-sizing: border-box; padding: 1px 4px; -webkit-font-smoothing: antialiased; font-family: SFMono-Regular, Consolas, &quot;Liberation Mono&quot;, Menlo, Courier, monospace; list-style: none; margin: 0px 2px; scrollbar-width: none; font-size: 12.75px; tab-size: 4; background-color: rgba(27, 31, 35, 0.05); border-radius: 3px;\">TorchScript<\/code>\u683c\u5f0f\uff0c\u96c6\u6210\u5230Flask\/FastAPI\u540e\u7aef\u3002<\/p>\n<\/li>\n<\/ul>\n","protected":false},"excerpt":{"rendered":"<h2 style=\"box-sizing: border-box; padding: 0px; -webkit-font-smoothing: antialiased; font-family: PingFangSC-Semibold; list-style: none; margin: 14px 0px 8px; scrollbar-width: none; color: rgb(5, 7, 59); font-size: 24px; border: none; line-height: 1.6; text-wrap-mode: wrap; background-color: rgb(253, 253, 254);\"><!--autointro--><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[3],"tags":[],"class_list":["post-189","post","type-post","status-publish","format-standard","hentry","category-pythonbiji"],"_links":{"self":[{"href":"https:\/\/www.mianka.xyz\/index.php?rest_route=\/wp\/v2\/posts\/189","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.mianka.xyz\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.mianka.xyz\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.mianka.xyz\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.mianka.xyz\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=189"}],"version-history":[{"count":0,"href":"https:\/\/www.mianka.xyz\/index.php?rest_route=\/wp\/v2\/posts\/189\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.mianka.xyz\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=189"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.mianka.xyz\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=189"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.mianka.xyz\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=189"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}