{"id":4183,"date":"2024-11-11T11:37:34","date_gmt":"2024-11-11T03:37:34","guid":{"rendered":"https:\/\/fwq.ai\/blog\/4183\/"},"modified":"2024-11-11T11:37:34","modified_gmt":"2024-11-11T03:37:34","slug":"%e6%9e%84%e5%bb%ba%e4%b8%80%e4%b8%aa%e6%96%87%e6%9c%ac%e6%91%98%e8%a6%81%e5%ba%94%e7%94%a8%e7%a8%8b%e5%ba%8f","status":"publish","type":"post","link":"https:\/\/fwq.ai\/blog\/4183\/","title":{"rendered":"\u6784\u5efa\u4e00\u4e2a\u6587\u672c\u6458\u8981\u5e94\u7528\u7a0b\u5e8f"},"content":{"rendered":"<h1>\u6784\u5efa\u4e00\u4e2a\u6587\u672c\u6458\u8981\u5e94\u7528\u7a0b\u5e8f<\/h1>\n<h2><\/h2>\n<p>\u5728\u672c\u6307\u5357\u4e2d\uff0c\u60a8\u5c06\u5b66\u4e60\u5982\u4f55\u6784\u5efa\u548c\u8fd0\u884c\u6587\u672c\u6458\u8981\u5e94\u7528\u7a0b\u5e8f\u3002\u60a8\u5c06\u4f7f\u7528 Python \u548c Bert Extractive Summarizer \u6784\u5efa\u5e94\u7528\u7a0b\u5e8f\uff0c\u7136\u540e\u8bbe\u7f6e\u73af\u5883\u5e76\u4f7f\u7528 Docker \u8fd0\u884c\u5e94\u7528\u7a0b\u5e8f\u3002<\/p>\n<p>\u793a\u4f8b\u6587\u672c\u6458\u8981\u5e94\u7528\u7a0b\u5e8f\u4f7f\u7528 Bert Extractive Summarizer\u3002\u8be5\u5de5\u5177\u5229\u7528 HuggingFace Pytorch \u8f6c\u6362\u5668\u5e93\u6765\u8fd0\u884c\u63d0\u53d6\u6458\u8981\u3002\u5176\u5de5\u4f5c\u539f\u7406\u662f\u9996\u5148\u5d4c\u5165\u53e5\u5b50\uff0c\u7136\u540e\u8fd0\u884c\u805a\u7c7b\u7b97\u6cd5\uff0c\u627e\u5230\u6700\u63a5\u8fd1\u805a\u7c7b\u8d28\u5fc3\u7684\u53e5\u5b50\u3002<\/p>\n<h2><\/h2>\n<ul>\n<li>\u60a8\u5df2\u5b89\u88c5\u6700\u65b0\u7248\u672c\u7684 \u3002 Docker \u5b9a\u671f\u6dfb\u52a0\u65b0\u529f\u80fd\uff0c\u672c\u6307\u5357\u7684\u67d0\u4e9b\u90e8\u5206\u53ef\u80fd\u4ec5\u9002\u7528\u4e8e\u6700\u65b0\u7248\u672c\u7684 Docker Desktop\u3002<\/li>\n<li>\u60a8\u6709\u4e00\u4e2a \u3002\u672c\u8282\u4e2d\u7684\u793a\u4f8b\u4f7f\u7528\u57fa\u4e8e\u547d\u4ee4\u884c\u7684 Git \u5ba2\u6237\u7aef\uff0c\u4f46\u60a8\u53ef\u4ee5\u4f7f\u7528\u4efb\u4f55\u5ba2\u6237\u7aef\u3002<\/li>\n<\/ul>\n<h2><\/h2>\n<ol>\n<li>\n<p>\u6253\u5f00\u7ec8\u7aef\uff0c\u7136\u540e\u4f7f\u7528\u4ee5\u4e0b\u547d\u4ee4\u514b\u9686\u793a\u4f8b\u5e94\u7528\u7a0b\u5e8f\u7684\u5b58\u50a8\u5e93\u3002<\/p>\n<p> <span> <\/span> <span> <\/span> <\/p>\n<pre><code><span><span><span>$<\/span> git clone https:\/\/github.com\/harsh4870\/Docker-NLP.git <\/span><\/span><\/code><\/pre>\n<\/li>\n<li>\n<p>\u9a8c\u8bc1\u60a8\u662f\u5426\u514b\u9686\u4e86\u5b58\u50a8\u5e93\u3002<\/p>\n<p>\u60a8\u5e94\u8be5\u5728\u76ee\u5f55\u4e2d\u770b\u5230\u4ee5\u4e0b\u6587\u4ef6<code>Docker-NLP<\/code>\u3002<\/p>\n<p> <span> <\/span> <span> <\/span> <\/p>\n<pre><code><span><span>01_sentiment_analysis.py <\/span><\/span><span><span>02_name_entity_recognition.py <\/span><\/span><span><span>03_text_classification.py <\/span><\/span><span><span>04_text_summarization.py <\/span><\/span><span><span>05_language_translation.py <\/span><\/span><span><span>entrypoint.sh <\/span><\/span><span><span>requirements.txt <\/span><\/span><span><span>Dockerfile <\/span><\/span><span><span>README.md<\/span><\/span><\/code><\/pre>\n<\/li>\n<\/ol>\n<h2><\/h2>\n<p>\u6587\u672c\u6458\u8981\u5e94\u7528\u7a0b\u5e8f\u7684\u6e90\u4ee3\u7801\u4f4d\u4e8e\u8be5<code>Docker-NLP\/04_text_summarization.py<\/code>\u6587\u4ef6\u4e2d\u3002\u5728\u6587\u672c\u6216\u4ee3\u7801\u7f16\u8f91\u5668\u4e2d\u6253\u5f00<code>04_text_summarization.py<\/code>\uff0c\u6309\u4ee5\u4e0b\u6b65\u9aa4\u63a2\u7d22\u5176\u5185\u5bb9\u3002<\/p>\n<ol>\n<li>\n<p>\u5bfc\u5165\u6240\u9700\u7684\u5e93\u3002<\/p>\n<p> <span> <\/span> <span> <\/span> <\/p>\n<pre><code><span><span><span>from<\/span> <span>summarizer<\/span> <span>import<\/span> <span>Summarizer<\/span><\/span><\/span><\/code><\/pre>\n<p>\u8fd9\u884c\u4ee3\u7801<code>Summarizer<\/code>\u4ece<code>summarizer<\/code> \u5305\u4e2d\u5bfc\u5165\u7c7b\uff0c\u8fd9\u5bf9\u4e8e\u6587\u672c\u6458\u8981\u5e94\u7528\u7a0b\u5e8f\u81f3\u5173\u91cd\u8981\u3002\u6458\u8981\u5668\u6a21\u5757\u5229\u7528\u5728 NLP\uff08\u81ea\u7136\u8bed\u8a00\u5904\u7406\uff09\u9886\u57df\u4eab\u6709\u76db\u8a89\u7684 HuggingFace Pytorch \u8f6c\u6362\u5668\u5e93\u5b9e\u73b0\u4e86 Bert Extractive Summarizer\u3002\u8be5\u5e93\u63d0\u4f9b\u5bf9 BERT \u7b49\u9884\u8bad\u7ec3\u6a21\u578b\u7684\u8bbf\u95ee\uff0c\u5b83\u5f7b\u5e95\u6539\u53d8\u4e86\u8bed\u8a00\u7406\u89e3\u4efb\u52a1\uff0c\u5305\u62ec\u6587\u672c\u6458\u8981\u3002<\/p>\n<p>BERT \u6a21\u578b\uff08\u5373 Transformers \u7684\u53cc\u5411\u7f16\u7801\u5668\u8868\u793a\uff09\u64c5\u957f\u7406\u89e3\u8bed\u8a00\u4e0a\u4e0b\u6587\uff0c\u4f7f\u7528\u79f0\u4e3a\u201c\u6ce8\u610f\u529b\u201d\u7684\u673a\u5236\u6765\u786e\u5b9a\u53e5\u5b50\u4e2d\u5355\u8bcd\u7684\u91cd\u8981\u6027\u3002\u4e3a\u4e86\u8fdb\u884c\u6982\u62ec\uff0c\u8be5\u6a21\u578b\u5d4c\u5165\u53e5\u5b50\uff0c\u7136\u540e\u4f7f\u7528\u805a\u7c7b\u7b97\u6cd5\u6765\u8bc6\u522b\u5173\u952e\u53e5\u5b50\uff0c\u5373\u6700\u63a5\u8fd1\u8fd9\u4e9b\u805a\u7c7b\u8d28\u5fc3\u7684\u53e5\u5b50\uff0c\u4ece\u800c\u6709\u6548\u5730\u6355\u83b7\u6587\u672c\u7684\u4e3b\u8981\u601d\u60f3\u3002<\/p>\n<\/li>\n<li>\n<p>\u6307\u5b9a\u4e3b\u8981\u6267\u884c\u5757\u3002<\/p>\n<p> <span> <\/span> <span> <\/span> <\/p>\n<pre><code><span><span><span>if<\/span> <span>__name__<\/span> <span>==<\/span> <span>\"__main__\"<\/span><span>:<\/span><\/span><\/span><\/code><\/pre>\n<p>\u8fd9\u4e2a Python \u4e60\u60ef\u7528\u6cd5\u786e\u4fdd\u4ec5\u5f53\u8be5\u811a\u672c\u662f\u4e3b\u7a0b\u5e8f\u65f6\u4ee5\u4e0b\u4ee3\u7801\u5757\u624d\u8fd0\u884c\u3002\u5b83\u63d0\u4f9b\u4e86\u7075\u6d3b\u6027\uff0c\u5141\u8bb8\u811a\u672c\u65e2\u4f5c\u4e3a\u72ec\u7acb\u7a0b\u5e8f\u53c8\u4f5c\u4e3a\u5bfc\u5165\u6a21\u5757\u8fd0\u884c\u3002<\/p>\n<\/li>\n<li>\n<p>\u521b\u5efa\u65e0\u9650\u5faa\u73af\u4ee5\u8fdb\u884c\u8fde\u7eed\u8f93\u5165\u3002<\/p>\n<p> <span> <\/span> <span> <\/span> <\/p>\n<pre><code><span><span> <span>while<\/span> <span>True<\/span><span>:<\/span> <\/span><\/span><span><span> <span>input_text<\/span> <span>=<\/span> <span>input<\/span><span>(<\/span><span>\"Enter the text for summarization (type 'exit' to end): \"<\/span><span>)<\/span> <\/span><\/span><span><span> <\/span><\/span><span><span> <span>if<\/span> <span>input_text<\/span><span>.<\/span><span>lower<\/span><span>()<\/span> <span>==<\/span> <span>'exit'<\/span><span>:<\/span> <\/span><\/span><span><span> <span>print<\/span><span>(<\/span><span>\"Exiting...\"<\/span><span>)<\/span> <\/span><\/span><span><span> <span>break<\/span><\/span><\/span><\/code><\/pre>\n<p>\u65e0\u9650\u5faa\u73af\u4e0d\u65ad\u63d0\u793a\u60a8\u8f93\u5165\u6587\u672c\uff0c\u786e\u4fdd\u4ea4\u4e92\u6027\u3002\u5f53\u60a8\u952e\u5165 \u65f6\uff0c\u5faa\u73af\u5c31\u4f1a\u4e2d\u65ad<code>exit<\/code>\uff0c\u4ece\u800c\u4f7f\u60a8\u80fd\u591f\u6709\u6548\u5730\u63a7\u5236\u5e94\u7528\u7a0b\u5e8f\u6d41\u7a0b\u3002<\/p>\n<\/li>\n<li>\n<p>\u521b\u5efa Summarizer \u7684\u5b9e\u4f8b\u3002<\/p>\n<p> <span> <\/span> <span> <\/span> <\/p>\n<pre><code><span><span> <span>bert_model<\/span> <span>=<\/span> <span>Summarizer<\/span><span>()<\/span><\/span><\/span><\/code><\/pre>\n<p>\u5728\u8fd9\u91cc\uff0c\u60a8\u521b\u5efa\u4e00\u4e2a\u540d\u4e3a \u7684 Summarizer \u7c7b\u7684\u5b9e\u4f8b<code>bert_model<\/code>\u3002\u8be5\u5b9e\u4f8b\u73b0\u5728\u5df2\u51c6\u5907\u597d\u4f7f\u7528 BERT \u6a21\u578b\u6267\u884c\u6458\u8981\u4efb\u52a1\uff0c\u4ece\u800c\u7b80\u5316\u5c06\u53e5\u5b50\u5d4c\u5165\u548c\u805a\u7c7b\u5230\u53ef\u8bbf\u95ee\u754c\u9762\u7684\u590d\u6742\u8fc7\u7a0b\u3002<\/p>\n<\/li>\n<li>\n<p>\u751f\u6210\u5e76\u6253\u5370\u6458\u8981\u3002<\/p>\n<p> <span> <\/span> <span> <\/span> <\/p>\n<pre><code><span><span><span>summary<\/span> <span>=<\/span> <span>bert_model<\/span><span>(<\/span><span>input_text<\/span><span>)<\/span> <\/span><\/span><span><span><span>print<\/span><span>(<\/span><span>summary<\/span><span>)<\/span><\/span><\/span><\/code><\/pre>\n<p>\u60a8\u7684\u8f93\u5165\u6587\u672c\u7531 bert_model \u5b9e\u4f8b\u5904\u7406\uff0c\u7136\u540e\u8fd4\u56de\u6458\u8981\u7248\u672c\u3002\u8fd9\u5c55\u793a\u4e86 Python \u9ad8\u7ea7\u5e93\u5728\u7528\u6700\u5c11\u7684\u4ee3\u7801\u5b9e\u73b0\u590d\u6742\u64cd\u4f5c\u65b9\u9762\u7684\u5f3a\u5927\u529f\u80fd\u3002<\/p>\n<\/li>\n<li>\n<p>\u521b\u9020<code>requirements.txt<\/code>\u3002\u793a\u4f8b\u5e94\u7528\u7a0b\u5e8f\u5df2\u5305\u542b <code>requirements.txt<\/code>\u7528\u4e8e\u6307\u5b9a\u5e94\u7528\u7a0b\u5e8f\u5bfc\u5165\u7684\u5fc5\u8981\u6a21\u5757\u7684\u6587\u4ef6\u3002<code>requirements.txt<\/code>\u5728\u4ee3\u7801\u6216\u6587\u672c\u7f16\u8f91\u5668\u4e2d\u6253\u5f00\u4ee5\u63a2\u7d22\u5176\u5185\u5bb9\u3002<\/p>\n<p> <span> <\/span> <span> <\/span> <\/p>\n<pre><code><span><span>... <\/span><\/span><span><span> <\/span><\/span><span><span># 04 text_summarization <\/span><\/span><span><span>bert-extractive-summarizer==0.10.1 <\/span><\/span><span><span> <\/span><\/span><span><span>... <\/span><\/span><span><span> <\/span><\/span><span><span>torch==2.1.2<\/span><\/span><\/code><\/pre>\n<p>\u6587\u672c\u6458\u8981\u5e94\u7528\u7a0b\u5e8f\u9700\u8981<code>bert-extractive-summarizer<\/code>\u548c\u6a21\u5757\u3002<code>torch<\/code>\u6458\u8981\u5668\u6a21\u5757\u751f\u6210\u8f93\u5165\u6587\u672c\u7684\u6458\u8981\u3002\u8fd9\u9700\u8981 PyTorch\uff0c\u56e0\u4e3a\u7528\u4e8e\u751f\u6210\u6458\u8981\u7684\u5e95\u5c42 BERT \u6a21\u578b\u662f\u5728 PyTorch \u4e2d\u5b9e\u73b0\u7684\u3002<\/p>\n<\/li>\n<\/ol>\n<h2><\/h2>\n<p>\u60a8\u5c06\u4f7f\u7528 Docker \u5728\u5bb9\u5668\u4e2d\u8fd0\u884c\u5e94\u7528\u7a0b\u5e8f\u3002 Docker \u5141\u8bb8\u60a8\u5bf9\u5e94\u7528\u7a0b\u5e8f\u8fdb\u884c\u5bb9\u5668\u5316\uff0c\u4e3a\u8fd0\u884c\u5b83\u63d0\u4f9b\u4e00\u81f4\u4e14\u9694\u79bb\u7684\u73af\u5883\u3002\u8fd9\u610f\u5473\u7740\u5e94\u7528\u7a0b\u5e8f\u5c06\u5728\u5176 Docker \u5bb9\u5668\u5185\u6309\u9884\u671f\u8fd0\u884c\uff0c\u65e0\u8bba\u5e95\u5c42\u7cfb\u7edf\u6709\u4f55\u5dee\u5f02\u3002<\/p>\n<p>\u8981\u5728\u5bb9\u5668\u4e2d\u8fd0\u884c\u5e94\u7528\u7a0b\u5e8f\uff0c\u9700\u8981 Dockerfile\u3002 Dockerfile \u662f\u4e00\u4e2a\u6587\u672c\u6587\u6863\uff0c\u5176\u4e2d\u5305\u542b\u60a8\u5728\u547d\u4ee4\u884c\u4e0a\u8c03\u7528\u4ee5\u7ec4\u88c5\u6620\u50cf\u7684\u6240\u6709\u547d\u4ee4\u3002\u955c\u50cf\u662f\u4e00\u4e2a\u53ea\u8bfb\u6a21\u677f\uff0c\u5305\u542b\u521b\u5efa Docker \u5bb9\u5668\u7684\u8bf4\u660e\u3002<\/p>\n<p>\u793a\u4f8b\u5e94\u7528\u7a0b\u5e8f\u5df2\u5305\u542b\u4e00\u4e2a<code>Dockerfile<\/code>.<code>Dockerfile<\/code>\u5728\u4ee3\u7801\u6216\u6587\u672c\u7f16\u8f91\u5668\u4e2d\u6253\u5f00\u4ee5\u6d4f\u89c8\u5176\u5185\u5bb9\u3002<\/p>\n<p>\u4ee5\u4e0b\u6b65\u9aa4\u89e3\u91ca\u4e86 \u7684\u6bcf\u4e2a\u90e8\u5206<code>Dockerfile<\/code>\u3002\u6709\u5173\u66f4\u591a\u8be6\u7ec6\u4fe1\u606f\uff0c\u8bf7\u53c2\u9605 \u3002<\/p>\n<ol>\n<li>\n<p>\u6307\u5b9a\u57fa\u7840\u56fe\u50cf\u3002<\/p>\n<p> <span> <\/span> <span> <\/span> <\/p>\n<pre><code><span><span><span>FROM<\/span><span> python:3.8-slim<\/span><\/span><\/span><\/code><\/pre>\n<p>\u8be5\u547d\u4ee4\u4e3a\u6784\u5efa\u5960\u5b9a\u4e86\u57fa\u7840\u3002<code>python:3.8-slim<\/code>\u662f Python 3.8 \u6620\u50cf\u7684\u8f7b\u91cf\u7ea7\u7248\u672c\uff0c\u9488\u5bf9\u5927\u5c0f\u548c\u901f\u5ea6\u8fdb\u884c\u4e86\u4f18\u5316\u3002\u4f7f\u7528\u8fd9\u4e2a\u7ea4\u8584\u7684\u955c\u50cf\u53ef\u4ee5\u51cf\u5c11 Docker \u955c\u50cf\u7684\u6574\u4f53\u5927\u5c0f\uff0c\u4ece\u800c\u52a0\u5feb\u4e0b\u8f7d\u901f\u5ea6\u5e76\u51cf\u5c11\u5b89\u5168\u6f0f\u6d1e\u7684\u8868\u9762\u79ef\u3002\u8fd9\u5bf9\u4e8e\u57fa\u4e8e Python \u7684\u5e94\u7528\u7a0b\u5e8f\u7279\u522b\u6709\u7528\uff0c\u60a8\u53ef\u80fd\u4e0d\u9700\u8981\u5b8c\u6574\u7684\u6807\u51c6 Python \u6620\u50cf\u3002<\/p>\n<\/li>\n<li>\n<p>\u8bbe\u7f6e\u5de5\u4f5c\u76ee\u5f55\u3002<\/p>\n<p> <span> <\/span> <span> <\/span> <\/p>\n<pre><code><span><span><span>WORKDIR<\/span><span> \/app<\/span><\/span><\/span><\/code><\/pre>\n<p><code>WORKDIR<\/code>\u8bbe\u7f6e Docker \u6620\u50cf\u4e2d\u7684\u5f53\u524d\u5de5\u4f5c\u76ee\u5f55\u3002\u901a\u8fc7\u5c06\u5176\u8bbe\u7f6e\u4e3a<code>\/app<\/code>\uff0c\u53ef\u4ee5\u786e\u4fdd Dockerfile \u4e2d\u7684\u6240\u6709\u540e\u7eed\u547d\u4ee4\uff08\u4f8b\u5982<code>COPY<\/code>\u548c<code>RUN<\/code>\uff09\u90fd\u5728\u6b64\u76ee\u5f55\u4e2d\u6267\u884c\u3002\u8fd9\u4e5f\u6709\u52a9\u4e8e\u7ec4\u7ec7 Docker \u6620\u50cf\uff0c\u56e0\u4e3a\u6240\u6709\u4e0e\u5e94\u7528\u7a0b\u5e8f\u76f8\u5173\u7684\u6587\u4ef6\u90fd\u5305\u542b\u5728\u7279\u5b9a\u76ee\u5f55\u4e2d\u3002<\/p>\n<\/li>\n<li>\n<p>\u5c06\u9700\u6c42\u6587\u4ef6\u590d\u5236\u5230\u6620\u50cf\u4e2d\u3002<\/p>\n<p> <span> <\/span> <span> <\/span> <\/p>\n<pre><code><span><span><span>COPY<\/span> requirements.txt \/app<\/span><\/span><\/code><\/pre>\n<p>\u8be5<code>COPY<\/code>\u547d\u4ee4\u5c06<code>requirements.txt<\/code>\u6587\u4ef6\u4ece\u672c\u5730\u8ba1\u7b97\u673a\u4f20\u8f93\u5230 Docker \u6620\u50cf\u4e2d\u3002\u8be5\u6587\u4ef6\u5217\u51fa\u4e86\u5e94\u7528\u7a0b\u5e8f\u6240\u9700\u7684\u6240\u6709 Python \u4f9d\u8d56\u9879\u3002\u5c06\u5176\u590d\u5236\u5230\u5bb9\u5668\u4e2d\u53ef\u4ee5\u8ba9\u4e0b\u4e00\u4e2a\u547d\u4ee4 ( <code>RUN pip install<\/code>) \u5728\u6620\u50cf\u73af\u5883\u4e2d\u5b89\u88c5\u8fd9\u4e9b\u4f9d\u8d56\u9879\u3002<\/p>\n<\/li>\n<li>\n<p>\u5728\u6620\u50cf\u4e2d\u5b89\u88c5 Python \u4f9d\u8d56\u9879\u3002<\/p>\n<p> <span> <\/span> <span> <\/span> <\/p>\n<pre><code><span><span><span>RUN<\/span> pip install --no-cache-dir -r requirements.txt<\/span><\/span><\/code><\/pre>\n<p>\u6b64\u884c\u4f7f\u7528<code>pip<\/code>Python \u7684\u8f6f\u4ef6\u5305\u5b89\u88c5\u7a0b\u5e8f\u6765\u5b89\u88c5 \u4e2d\u5217\u51fa\u7684\u8f6f\u4ef6\u5305<code>requirements.txt<\/code>\u3002\u8be5<code>--no-cache-dir<\/code>\u9009\u9879\u7981\u7528\u7f13\u5b58\uff0c\u4ece\u800c\u901a\u8fc7\u4e0d\u5b58\u50a8\u4e0d\u5fc5\u8981\u7684\u7f13\u5b58\u6570\u636e\u6765\u51cf\u5c0f Docker \u6620\u50cf\u7684\u5927\u5c0f\u3002<\/p>\n<\/li>\n<li>\n<p>\u8fd0\u884c\u9644\u52a0\u547d\u4ee4\u3002<\/p>\n<p> <span> <\/span> <span> <\/span> <\/p>\n<pre><code><span><span><span>RUN<\/span> python -m spacy download en_core_web_sm<\/span><\/span><\/code><\/pre>\n<p>\u6b64\u6b65\u9aa4\u7279\u5b9a\u4e8e\u9700\u8981 spaCy \u5e93\u7684 NLP \u5e94\u7528\u7a0b\u5e8f\u3002\u5b83\u4e0b\u8f7d<code>en_core_web_sm<\/code>\u6a21\u578b\uff0c\u8fd9\u662f spaCy \u7684\u5c0f\u578b\u82f1\u8bed\u6a21\u578b\u3002\u867d\u7136\u6b64\u5e94\u7528\u7a0b\u5e8f\u4e0d\u9700\u8981\u5b83\uff0c\u4f46\u5305\u542b\u5b83\u662f\u4e3a\u4e86\u4e0e\u53ef\u80fd\u4f7f\u7528\u6b64 Dockerfile \u7684\u5176\u4ed6 NLP \u5e94\u7528\u7a0b\u5e8f\u517c\u5bb9\u3002<\/p>\n<\/li>\n<li>\n<p>\u5c06\u5e94\u7528\u7a0b\u5e8f\u4ee3\u7801\u590d\u5236\u5230\u56fe\u50cf\u4e2d\u3002<\/p>\n<p> <span> <\/span> <span> <\/span> <\/p>\n<pre><code><span><span><span>COPY<\/span> *.py \/app<span> <\/span><\/span><\/span><span><span><span><\/span><span>COPY<\/span> entrypoint.sh \/app<\/span><\/span><\/code><\/pre>\n<p>\u8fd9\u4e9b\u547d\u4ee4\u5c06\u60a8\u7684 Python \u811a\u672c\u548c<code>entrypoint.sh<\/code>\u811a\u672c\u590d\u5236\u5230\u56fe\u50cf\u7684<code>\/app<\/code>\u76ee\u5f55\u4e2d\u3002\u8fd9\u5f88\u91cd\u8981\uff0c\u56e0\u4e3a\u5bb9\u5668\u9700\u8981\u8fd9\u4e9b\u811a\u672c\u6765\u8fd0\u884c\u5e94\u7528\u7a0b\u5e8f\u3002\u8be5<code>entrypoint.sh<\/code>\u811a\u672c\u7279\u522b\u91cd\u8981\uff0c\u56e0\u4e3a\u5b83\u6307\u793a\u5e94\u7528\u7a0b\u5e8f\u5982\u4f55\u5728\u5bb9\u5668\u5185\u542f\u52a8\u3002<\/p>\n<\/li>\n<li>\n<p>\u8bbe\u7f6e<code>entrypoint.sh<\/code>\u811a\u672c\u7684\u6743\u9650\u3002<\/p>\n<p> <span> <\/span> <span> <\/span> <\/p>\n<pre><code><span><span><span>RUN<\/span> chmod +x \/app\/entrypoint.sh<\/span><\/span><\/code><\/pre>\n<p>\u6b64\u547d\u4ee4\u4fee\u6539 \u7684\u6587\u4ef6\u6743\u9650<code>entrypoint.sh<\/code>\uff0c\u4f7f\u5176\u53ef\u6267\u884c\u3002\u6b64\u6b65\u9aa4\u662f\u786e\u4fdd Docker \u5bb9\u5668\u53ef\u4ee5\u8fd0\u884c\u6b64\u811a\u672c\u6765\u542f\u52a8\u5e94\u7528\u7a0b\u5e8f\u6240\u5fc5\u9700\u7684\u3002<\/p>\n<\/li>\n<li>\n<p>\u8bbe\u7f6e\u5165\u53e3\u70b9\u3002<\/p>\n<p> <span> <\/span> <span> <\/span> <\/p>\n<pre><code><span><span><span>ENTRYPOINT<\/span> <span>[<\/span><span>\"\/app\/entrypoint.sh\"<\/span><span>]<\/span><\/span><\/span><\/code><\/pre>\n<p>\u8be5<code>ENTRYPOINT<\/code>\u6307\u4ee4\u5c06\u5bb9\u5668\u914d\u7f6e<code>entrypoint.sh<\/code> \u4e3a\u4f5c\u4e3a\u9ed8\u8ba4\u53ef\u6267\u884c\u6587\u4ef6\u8fd0\u884c\u3002\u8fd9\u610f\u5473\u7740\u5f53\u5bb9\u5668\u542f\u52a8\u65f6\uff0c\u5b83\u4f1a\u81ea\u52a8\u6267\u884c\u811a\u672c\u3002<\/p>\n<p>\u60a8\u53ef\u4ee5<code>entrypoint.sh<\/code>\u901a\u8fc7\u5728\u4ee3\u7801\u6216\u6587\u672c\u7f16\u8f91\u5668\u4e2d\u6253\u5f00\u811a\u672c\u6765\u63a2\u7d22\u8be5\u811a\u672c\u3002\u7531\u4e8e\u793a\u4f8b\u5305\u542b\u591a\u4e2a\u5e94\u7528\u7a0b\u5e8f\uff0c\u56e0\u6b64\u8be5\u811a\u672c\u5141\u8bb8\u60a8\u6307\u5b9a\u5728\u5bb9\u5668\u542f\u52a8\u65f6\u8fd0\u884c\u54ea\u4e2a\u5e94\u7528\u7a0b\u5e8f\u3002<\/p>\n<\/li>\n<\/ol>\n<h2><\/h2>\n<p>\u8981\u4f7f\u7528 Docker \u8fd0\u884c\u5e94\u7528\u7a0b\u5e8f\uff1a<\/p>\n<ol>\n<li>\n<p>\u5efa\u7acb\u5f62\u8c61\u3002<\/p>\n<p>\u5728\u7ec8\u7aef\u4e2d\uff0c\u5728\u6240\u5728\u76ee\u5f55\u4e2d\u8fd0\u884c\u4ee5\u4e0b\u547d\u4ee4<code>Dockerfile<\/code>\u3002<\/p>\n<p> <span> <\/span> <span> <\/span> <\/p>\n<pre><code><span><span><span>$<\/span> docker build -t basic-nlp . <\/span><\/span><\/code><\/pre>\n<p>\u4ee5\u4e0b\u662f\u8be5\u547d\u4ee4\u7684\u7ec6\u5206\uff1a<\/p>\n<ul>\n<li><code>docker build<\/code>\uff1a\u8fd9\u662f\u7528\u4e8e\u4ece Dockerfile \u548c\u4e0a\u4e0b\u6587\u6784\u5efa Docker \u6620\u50cf\u7684\u4e3b\u8981\u547d\u4ee4\u3002\u4e0a\u4e0b\u6587\u901a\u5e38\u662f\u6307\u5b9a\u4f4d\u7f6e\u7684\u4e00\u7ec4\u6587\u4ef6\uff0c\u901a\u5e38\u662f\u5305\u542b Dockerfile \u7684\u76ee\u5f55\u3002<\/li>\n<li><code>-t basic-nlp<\/code>\uff1a\u8fd9\u662f\u4e00\u4e2a\u7528\u4e8e\u6807\u8bb0\u56fe\u50cf\u7684\u9009\u9879\u3002\u65d7\u5e1c<code>-t<\/code>\u4ee3\u8868\u6807\u7b7e\u3002\u5b83\u4e3a\u56fe\u50cf\u5206\u914d\u4e00\u4e2a\u540d\u79f0\uff0c\u5728\u672c\u4f8b\u4e2d\u4e3a <code>basic-nlp<\/code>.\u6807\u7b7e\u662f\u7a0d\u540e\u5f15\u7528\u56fe\u50cf\u7684\u4fbf\u6377\u65b9\u6cd5\uff0c\u5c24\u5176\u662f\u5728\u5c06\u5b83\u4eec\u63a8\u9001\u5230\u6ce8\u518c\u8868\u6216\u8fd0\u884c\u5bb9\u5668\u65f6\u3002<\/li>\n<li><code>.<\/code>\uff1a\u8fd9\u662f\u547d\u4ee4\u7684\u6700\u540e\u4e00\u90e8\u5206\uff0c\u6307\u5b9a\u6784\u5efa\u4e0a\u4e0b\u6587\u3002\u53e5\u70b9 ( <code>.<\/code>) \u8868\u793a\u5f53\u524d\u76ee\u5f55\u3002 Docker \u5c06\u5728\u6b64\u76ee\u5f55\u4e2d\u67e5\u627e Dockerfile\u3002\u6784\u5efa\u4e0a\u4e0b\u6587\uff08\u5728\u672c\u4f8b\u4e2d\u4e3a\u5f53\u524d\u76ee\u5f55\uff09\u88ab\u53d1\u9001\u5230 Docker \u5b88\u62a4\u8fdb\u7a0b\u4ee5\u542f\u7528\u6784\u5efa\u3002\u5b83\u5305\u62ec\u6307\u5b9a\u76ee\u5f55\u4e2d\u7684\u6240\u6709\u6587\u4ef6\u548c\u5b50\u76ee\u5f55\u3002<\/li>\n<\/ul>\n<p>\u6709\u5173\u66f4\u591a\u8be6\u7ec6\u4fe1\u606f\uff0c\u8bf7\u53c2\u9605 \u3002<\/p>\n<p>Docker \u5728\u6784\u5efa\u955c\u50cf\u65f6\u4f1a\u5411\u63a7\u5236\u53f0\u8f93\u51fa\u591a\u4e2a\u65e5\u5fd7\u3002\u60a8\u5c06\u770b\u5230\u5b83\u4e0b\u8f7d\u5e76\u5b89\u88c5\u4f9d\u8d56\u9879\u3002\u6839\u636e\u60a8\u7684\u7f51\u7edc\u8fde\u63a5\uff0c\u8fd9\u53ef\u80fd\u9700\u8981\u51e0\u5206\u949f\u7684\u65f6\u95f4\u3002 Docker \u786e\u5b9e\u5177\u6709\u7f13\u5b58\u529f\u80fd\uff0c\u56e0\u6b64\u540e\u7eed\u6784\u5efa\u53ef\u4ee5\u66f4\u5feb\u3002\u5b8c\u6210\u540e\u63a7\u5236\u53f0\u5c06\u8fd4\u56de\u5230\u63d0\u793a\u7b26\u3002<\/p>\n<\/li>\n<li>\n<p>\u5c06\u56fe\u50cf\u4f5c\u4e3a\u5bb9\u5668\u8fd0\u884c\u3002<\/p>\n<p>\u5728\u7ec8\u7aef\u4e2d\uff0c\u8fd0\u884c\u4ee5\u4e0b\u547d\u4ee4\u3002<\/p>\n<p> <span> <\/span> <span> <\/span> <\/p>\n<pre><code><span><span><span>$<\/span> docker run -it basic-nlp 04_text_summarization.py <\/span><\/span><\/code><\/pre>\n<p>\u4ee5\u4e0b\u662f\u8be5\u547d\u4ee4\u7684\u7ec6\u5206\uff1a<\/p>\n<ul>\n<li><code>docker run<\/code>\uff1a\u8fd9\u662f\u7528\u4e8e\u4ece Docker \u6620\u50cf\u8fd0\u884c\u65b0\u5bb9\u5668\u7684\u4e3b\u8981\u547d\u4ee4\u3002<\/li>\n<li><code>-it<\/code>\uff1a\u8fd9\u662f\u4e24\u4e2a\u9009\u9879\u7684\u7ec4\u5408\uff1a\n<ul>\n<li><code>-i<\/code>\u6216<code>--interactive<\/code>\uff1a\u5373\u4f7f\u672a\u8fde\u63a5\uff0c\u8fd9\u4e5f\u4f1a\u4f7f\u6807\u51c6\u8f93\u5165 (STDIN) \u4fdd\u6301\u6253\u5f00\u72b6\u6001\u3002\u5b83\u8ba9\u5bb9\u5668\u4fdd\u6301\u5728\u524d\u53f0\u8fd0\u884c\u5e76\u5177\u6709\u4ea4\u4e92\u6027\u3002<\/li>\n<li><code>-t<\/code>or <code>--tty<\/code>\uff1a\u8fd9\u4f1a\u5206\u914d\u4e00\u4e2a\u4f2a TTY\uff0c\u672c\u8d28\u4e0a\u662f\u6a21\u62df\u7ec8\u7aef\uff0c\u5982\u547d\u4ee4\u63d0\u793a\u7b26\u6216 shell\u3002\u5b83\u53ef\u4ee5\u8ba9\u60a8\u4e0e\u5bb9\u5668\u5185\u7684\u5e94\u7528\u7a0b\u5e8f\u8fdb\u884c\u4ea4\u4e92\u3002<\/li>\n<\/ul>\n<\/li>\n<li><code>basic-nlp<\/code>\uff1a\u6307\u5b9a\u7528\u4e8e\u521b\u5efa\u5bb9\u5668\u7684 Docker \u6620\u50cf\u7684\u540d\u79f0\u3002\u5728\u672c\u4f8b\u4e2d\uff0c\u5b83\u662f<code>basic-nlp<\/code>\u60a8\u4f7f\u7528\u547d\u4ee4\u521b\u5efa\u7684\u540d\u4e3a\u7684\u56fe\u50cf<code>docker build<\/code>\u3002<\/li>\n<li><code>04_text_summarization.py<\/code>\uff1a\u8fd9\u662f\u60a8\u8981\u5728 Docker \u5bb9\u5668\u5185\u8fd0\u884c\u7684\u811a\u672c\u3002\u5b83\u88ab\u4f20\u9012\u7ed9<code>entrypoint.sh<\/code>\u811a\u672c\uff0c\u811a\u672c\u5728\u5bb9\u5668\u542f\u52a8\u65f6\u8fd0\u884c\u5b83\u3002<\/li>\n<\/ul>\n<p>\u6709\u5173\u66f4\u591a\u8be6\u7ec6\u4fe1\u606f\uff0c\u8bf7\u53c2\u9605 \u3002<\/p>\n<blockquote>\n<p><strong>\u7b14\u8bb0<\/strong><\/p>\n<p>\u5bf9\u4e8e Windows \u7528\u6237\uff0c\u8fd0\u884c\u5bb9\u5668\u65f6\u53ef\u80fd\u4f1a\u51fa\u73b0\u9519\u8bef\u3002\u9a8c\u8bc1\u884c\u7ed3\u5c3e\u662f<code>entrypoint.sh<\/code>( <code>LF<\/code>)<code>\\n<\/code>\u800c\u4e0d\u662f<code>CRLF<\/code>( <code>\\r\\n<\/code>)\uff0c\u7136\u540e\u91cd\u5efa\u56fe\u50cf\u3002\u6709\u5173\u66f4\u591a\u8be6\u7ec6\u4fe1\u606f\uff0c\u8bf7\u53c2\u9605 \u3002<\/p>\n<\/blockquote>\n<p>\u5bb9\u5668\u542f\u52a8\u540e\uff0c\u60a8\u5c06\u5728\u63a7\u5236\u53f0\u4e2d\u770b\u5230\u4ee5\u4e0b\u5185\u5bb9\u3002<\/p>\n<p> <span> <\/span> <span> <\/span> <\/p>\n<pre><code><span><span><span>Enter the text for summarization (type 'exit' to end): <\/span><\/span><\/span><\/code><\/pre>\n<\/li>\n<li>\n<p>\u6d4b\u8bd5\u5e94\u7528\u7a0b\u5e8f\u3002<\/p>\n<p>\u8f93\u5165\u4e00\u4e9b\u6587\u672c\u4ee5\u83b7\u53d6\u6587\u672c\u6458\u8981\u3002<\/p>\n<p> <span> <\/span> <span> <\/span> <\/p>\n<pre><code><span><span><span>Enter the text for summarization (type 'exit' to end): Artificial intelligence (AI) is a branch of computer science that aims to create machines capable of intelligent behavior. These machines are designed to mimic human cognitive functions such as learning, problem-solving, and decision-making. AI technologies can be classified into two main types: narrow or weak AI, which is designed for a particular task, and general or strong AI, which possesses the ability to understand, learn, and apply knowledge across various domains. One of the most popular approaches in AI is machine learning, where algorithms are trained on large datasets to recognize patterns and make predictions. <\/span><\/span><\/span><span><span><span><\/span><span> <\/span><\/span><\/span><span><span><span><\/span><span>Artificial intelligence (AI) is a branch of computer science that aims to create machines capable of intelligent behavior. These machines are designed to mimic human cognitive functions such as learning, problem-solving, and decision-making. <\/span><\/span><\/span><\/code><\/pre>\n<\/li>\n<\/ol>\n<h2><\/h2>\n<p>\u5728\u672c\u6307\u5357\u4e2d\uff0c\u60a8\u5b66\u4e60\u4e86\u5982\u4f55\u6784\u5efa\u548c\u8fd0\u884c\u6587\u672c\u6458\u8981\u5e94\u7528\u7a0b\u5e8f\u3002\u60a8\u5b66\u4e60\u4e86\u5982\u4f55\u4f7f\u7528 Python \u548c Bert Extractive Summarizer \u6784\u5efa\u5e94\u7528\u7a0b\u5e8f\uff0c\u7136\u540e\u8bbe\u7f6e\u73af\u5883\u5e76\u4f7f\u7528 Docker \u8fd0\u884c\u5e94\u7528\u7a0b\u5e8f\u3002<\/p>\n<p>\u76f8\u5173\u4fe1\u606f\uff1a<\/p>\n<ul>\n<li><\/li>\n<li><\/li>\n<li><\/li>\n<li><\/li>\n<li><\/li>\n<\/ul>\n<h2><\/h2>\n<p>\u63a2\u7d22\u66f4\u591a \u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u6784\u5efa\u4e00\u4e2a\u6587\u672c\u6458\u8981\u5e94\u7528\u7a0b\u5e8f \u5728\u672c\u6307\u5357\u4e2d\uff0c\u60a8\u5c06\u5b66\u4e60\u5982\u4f55\u6784\u5efa\u548c\u8fd0\u884c\u6587\u672c\u6458\u8981\u5e94\u7528\u7a0b\u5e8f\u3002\u60a8\u5c06\u4f7f\u7528 Python \u548c Bert Extractive Summarizer \u6784\u5efa\u5e94\u7528\u7a0b\u5e8f\uff0c\u7136\u540e\u8bbe\u7f6e\u73af\u5883\u5e76\u4f7f\u7528 Docker \u8fd0\u884c\u5e94\u7528\u7a0b\u5e8f\u3002 \u793a\u4f8b\u6587\u672c\u6458\u8981\u5e94\u7528\u7a0b\u5e8f\u4f7f\u7528 Bert Extractive Summarizer\u3002\u8be5\u5de5\u5177\u5229\u7528 HuggingFace Pytorch \u8f6c\u6362\u5668\u5e93\u6765\u8fd0\u884c\u63d0\u53d6\u6458\u8981\u3002\u5176\u5de5\u4f5c\u539f\u7406\u662f\u9996\u5148\u5d4c\u5165\u53e5\u5b50\uff0c\u7136\u540e\u8fd0\u884c\u805a\u7c7b\u7b97\u6cd5\uff0c\u627e\u5230\u6700\u63a5\u8fd1\u805a\u7c7b\u8d28\u5fc3\u7684\u53e5\u5b50\u3002 \u60a8\u5df2\u5b89\u88c5\u6700\u65b0\u7248\u672c\u7684 \u3002 Docker \u5b9a\u671f\u6dfb\u52a0\u65b0\u529f\u80fd\uff0c\u672c\u6307\u5357\u7684\u67d0\u4e9b\u90e8\u5206\u53ef\u80fd\u4ec5\u9002\u7528\u4e8e\u6700\u65b0\u7248\u672c\u7684 Docker Desktop\u3002 \u60a8\u6709\u4e00\u4e2a \u3002\u672c\u8282\u4e2d\u7684\u793a\u4f8b\u4f7f\u7528\u57fa\u4e8e\u547d\u4ee4\u884c\u7684 Git \u5ba2\u6237\u7aef\uff0c\u4f46\u60a8\u53ef\u4ee5\u4f7f\u7528\u4efb\u4f55\u5ba2\u6237\u7aef\u3002 \u6253\u5f00\u7ec8\u7aef\uff0c\u7136\u540e\u4f7f\u7528\u4ee5\u4e0b\u547d\u4ee4\u514b\u9686\u793a\u4f8b\u5e94\u7528\u7a0b\u5e8f\u7684\u5b58\u50a8\u5e93\u3002 $ git clone https:\/\/github.com\/harsh4870\/Docker-NLP.git \u9a8c\u8bc1\u60a8\u662f\u5426\u514b\u9686\u4e86\u5b58\u50a8\u5e93\u3002 \u60a8\u5e94\u8be5\u5728\u76ee\u5f55\u4e2d\u770b\u5230\u4ee5\u4e0b\u6587\u4ef6Docker-NLP\u3002 01_sentiment_analysis.py 02_name_entity_recognition.py 03_text_classification.py 04_text_summarization.py 05_language_translation.py entrypoint.sh requirements.txt Dockerfile README.md \u6587\u672c\u6458\u8981\u5e94\u7528\u7a0b\u5e8f\u7684\u6e90\u4ee3\u7801\u4f4d\u4e8e\u8be5Docker-NLP\/04_text_summarization.py\u6587\u4ef6\u4e2d\u3002\u5728\u6587\u672c\u6216\u4ee3\u7801\u7f16\u8f91\u5668\u4e2d\u6253\u5f0004_text_summarization.py\uff0c\u6309\u4ee5\u4e0b\u6b65\u9aa4\u63a2\u7d22\u5176\u5185\u5bb9\u3002 \u5bfc\u5165\u6240\u9700\u7684\u5e93\u3002 from summarizer import Summarizer \u8fd9\u884c\u4ee3\u7801Summarizer\u4ecesummarizer \u5305\u4e2d\u5bfc\u5165\u7c7b\uff0c\u8fd9\u5bf9\u4e8e\u6587\u672c\u6458\u8981\u5e94\u7528\u7a0b\u5e8f\u81f3\u5173\u91cd\u8981\u3002\u6458\u8981\u5668\u6a21\u5757\u5229\u7528\u5728 NLP\uff08\u81ea\u7136\u8bed\u8a00\u5904\u7406\uff09\u9886\u57df\u4eab\u6709\u76db\u8a89\u7684 HuggingFace Pytorch \u8f6c\u6362\u5668\u5e93\u5b9e\u73b0\u4e86 [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[17],"tags":[],"class_list":["post-4183","post","type-post","status-publish","format-standard","hentry","category-docker"],"_links":{"self":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/4183","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/comments?post=4183"}],"version-history":[{"count":0,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/4183\/revisions"}],"wp:attachment":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/media?parent=4183"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/categories?post=4183"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/tags?post=4183"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}