做者|Bruce H. Cottman, Ph.D.
編譯|VK
來源|Towards Data Sciencepython
在過去兩年半的工做中,咱們開發和維護了幾個天然語言處理項目。咱們爲每一個項目中的每一個版本控制中心建立了Docker鏡像:Dev、Test和Stage。我將詳細介紹Docker解決方案來建立生產NLP項目。git
代碼開發、重構、bug修復和單元測試都是由Dev完成的。在提交Github Dev repo(sitory)以前,代碼必須經過單元測試。其餘開發團隊在合併到Test Github repo(sitory)以前執行代碼評審、集成測試。github
項目階段管理(Project stage management)觸發從開發人員到Test 存儲庫的推送。項目發佈管理(Project release management)觸發從Test 到Stage 存儲庫的推送。市場發佈管理(Marketing release management)觸發了從stage到Prod存儲庫的推送和半自動連續部署(CD)的推出。web
注意:雲擴展和故障轉移管理須要修改。咱們這裏不討論這些。
Docker是用於管理應用程序的單個容器鏡像。docker
Docker Compose用於同一應用程序同時管理多個容器。此工具提供與Docker相同的功能,但容許你有更復雜的應用程序。安全
根據上述說明,在上述文章中,spacy和nltk都是經過在Dev、Test和Stage的dockerfile的中間添加如下內容來導入的:服務器
. . . RUN python -m spacy download en RUN python -m spacy download en_core_web_sm RUN python -m spacy download en_core_web_lg RUN python -m nltk.downloader stopwords && python -m nltk.downloader punkt && \ python -m nltk.downloader averaged_perceptron_tagger && \ python -m nltk.downloader wordnet . . .
將Jupyter支持添加到Dev dockerfile中:機器學習
. . . RUN python -m pip install --upgrade --no-deps --force-reinstall notebook # RUN python -m pip install jupyterthemes RUN python -m pip install --upgrade jupyterthemes RUN python -m pip install jupyter_contrib_nbextensions RUN jupyter contrib nbextension install --user RUN jupyter nbextensions_configurator enable --user RUN jupyter nbextension enable jupyter-js-widgets/extension RUN jupyter nbextension enable jupyter-notebook-gist/notebook-extension RUN jupyter nbextension enable contrib_nbextensions_help_item/main RUN jupyter nbextension enable autosavetime/main RUN jupyter nbextension enable codefolding/main RUN jupyter nbextension enable code_font_size/code_font_size RUN jupyter nbextension enable code_prettify/code_prettify RUN jupyter nbextension enable collapsible_headings/main RUN jupyter nbextension enable comment-uncomment/main RUN jupyter nbextension enable equation-numbering/main RUN jupyter nbextension enable execute_time/ExecuteTime RUN jupyter nbextension enable gist_it/main RUN jupyter nbextension enable hide_input/main RUN jupyter nbextension enable spellchecker/main RUN jupyter nbextension enable toc2/main RUN jupyter nbextension enable toggle_all_line_numbers/main
Dev、Test和Stage的requirements.txt:ide
###### Requirements without Version Specifiers ###### numpy matplotlib progressbar2 Pillow keras nilearn==0.5.0 pandas xlrd plotly statsmodels prettytable requests seaborn joblib dask distributed==v2.22.0 bs4 spacy textacy nltk spacy-transformers spacymoji pdfminer urllib3==1.25.10
注:該要求.txt上面顯示的文件是爲咱們的Dev、Test和Stage準備的。你可能不須要全部這些軟件包,也可能須要其餘軟件包。。若是須要,能夠隨意刪除或添加軟件包。注意:Pycharm配置了開發和測試工具pytest、pylint、black、mypy等。Jupyter用戶可使用!pip install <package>進行安裝,而後安裝可能須要的重要的額外包或工具。工具
通常的存儲庫結構是
|-- <project--repo-name> |-- docker |-- dev |--- Dockerfile |--- docker-compose.yml |--- requirements.txt |-- test |--- Dockerfile |--- docker-compose.yml |--- requirements.txt |-- stage |--- Dockerfile |--- docker-compose.yml |--- requirements.txt |-- src |-- test |--- requirements.txt |--- README.md . .
支持Jupyter的簡要步驟:
volume:
- ./../../.
。,若有必要。jupyter的後續啓動使用./../../.
做爲其頂層目錄。當你使用updev命令(在本文後面描述)時,docker-compose命令volume:
- ./../../.
使<path-to-projects>
映射到/docker,該目錄是docker鏡像的內部目錄。jupyter的後續發佈版本使用<path-to-projects>
做爲其頂層目錄。請使用上面顯示的示例目錄結構,或將本地目錄結構替換爲- ./../../.
。!docker system prune
!docker stats => CONTAINER ID NAME CPU % MEM USAGE / LIMIT MEM % NET I/O BLOCK I/O PIDS 5d98fb8e8a66 dev_dev_1 0.11% 327.2MiB / 36.24GiB 0.88% 182MB / 9.62MB 0B / 0B 13
Cannot connect to the Docker daemon at unix:///var/run/docker.sock. Is the docker daemon running?
修復方法是等待2-3分鐘,等待Docker守護進程完成,而後再試一次。若是不是這樣,Docker守護進程的啓動就有問題,必須進行診斷和修復。一個可能的問題是檢查Docker鏡像內存或CPU分配是否適合底層主機硬件。
我詳細介紹了咱們如何爲生產NLP應用程序生命週期設計和實現Docker解決方案。我展現了Dev、Test和Stage的目錄結構和Docker代碼。
本文中顯示的全部代碼都在這裏:https://github.com/bcottman/N...
原文連接:https://towardsdatascience.co...
歡迎關注磐創AI博客站:
http://panchuang.net/
sklearn機器學習中文官方文檔:
http://sklearn123.com/
歡迎關注磐創博客資源彙總站:
http://docs.panchuang.net/