- AWS EC2;
- SSH;
- python
ããã3ã€ãã¹ãŠãåé¡ãåŒãèµ·ãããªãå Žå-ç«ããé¡ãããŸãã
ç¶è¡ããåã«ãç§ãæ¯ããŠãããåŸæŽè ã«ç¹å¥ãªæè¬ãè¡šæããããšæããŸãã
ãã§ã«è¿°ã¹ãããã«ãå æ¥ãAWS DeepLearningããŒã ã¯æ°ãããã¬ãŒã ã¯ãŒã¯ãsockeyeãããªãªãŒã¹ããŸããã å ¬åŒãŠã§ããµã€ãããåŒçšãããŠãã ããïŒ
... Sockeyeãããžã§ã¯ããMXNetã«åºã¥ããã¥ãŒã©ã«æ©æ¢°ç¿»èš³ã®ã·ãŒã±ã³ã¹éãã¬ãŒã ã¯ãŒã¯ã ããç¥ãããŠãããšã³ã³ãŒããŒãã³ãŒããŒã¢ãŒããã¯ãã£ãå®è£ ãã泚æãæã£ãŠããŸãã
ç¡æ翻蚳ïŒ
Sockeyeã¯ãæ©æ¢°ç¿»èš³ã§ãã¥ãŒã©ã«ãããã¯ãŒã¯ããã¬ãŒãã³ã°ããããã®ãã¬ãŒã ã¯ãŒã¯ã§ãããããç¥ãããŠãããšã³ã³ãŒããŒãã³ãŒããŒã¢ãŒããã¯ãã£ã«åºã¥ããŠããŸãã
å ¬åŒã«ã¯ããã®ãã¬ãŒã ã¯ãŒã¯ã¯ãã¬ãŒãã³ã°ãããã¯ãŒã¯çšãæ©æ¢°ç¿»èš³çšã«èšèšãããŠããŸãããæè¡çã«ã¯ã1ã€ã®ã·ãŒã±ã³ã¹ãå¥ã®ã·ãŒã±ã³ã¹ã«å€æããã¿ã¹ã¯ã®ããäžè¬çãªã¯ã©ã¹ïŒseq2seqïŒã®ãã¬ãŒãã³ã°ã«ã䜿çšã§ããŸãã æ©æ¢°ç¿»èš³ãšãã£ãããããã®äœæãšãã2ã€ã®ã¿ã¹ã¯ãšããŠã®å ±éç¹ãããã 以åã®èšäºã® 1ã€ã§åæ§ã®æ¹æ³ã§è§£æ±ºã§ããçç±ã«ã€ããŠã¯ãæ¢ã«è§ŠããŸããã ãããã£ãŠãç§ã¯èªåèªèº«ãç¹°ãè¿ããã奜å¥å¿readerçãªèªè ããªã³ã¯ããã©ãæ©äŒãæ®ãããã®éããã£ããããããçŽæ¥äœæããŸãã
ããã»ã¹ã®èª¬æ
äžè¬ã«ãããã»ã¹ã¯æ¬¡ã®æé ã§æ§æãããŸãã
- DeepLearning AMIã«åºã¥ãGPUã§EC2ãã·ã³ãæã¡äžããŸã
- EC2ãã¬ãŒãã³ã°ãã·ã³ãæºåãã
- ãã¬ãŒãã³ã°ãéå§
- åŸ ã£ãŠ
- å©ç
AWS DeepLearning AMIã«åºã¥ããŠãGPUã䜿çšããŠEC2è»ãäžãã
ãã®èšäºã§ã¯ã AWS DeepLearning AMI ïŒä»¥éïŒDLAMIïŒã䜿çšããŸãïŒã¡ãªã¿ã«ãAMIãããããªãå Žåã¯ã ãã¡ãã®å ¬åŒããã¥ã¡ã³ãã«ç²Ÿéããããšããå§ãããŸãïŒã ãã®ç¹å®ã®AMIã䜿çšããäž»ãªçç±ã¯æ¬¡ã®ãšããã§ãã
- Nvidia CUDAãã©ã€ããŒãå«ãŸããŠããŸãïŒå·çæãããŒãžã§ã³ïŒ7.5ïŒã
- GPUãµããŒãã§çµã¿ç«ãŠ-MXNet;
- å¿ èŠãªãã¹ãŠã®ïŒã»ãŒïŒãŠãŒãã£ãªãã£ãå«ãŸããŸããäŸïŒgit;
- é©ãããé©ãããGPUããããã·ã³ã§äœ¿çšã§ããŸãã
AMIããå¿ èŠãªè»ããã°ããäœæããã«ã¯ãAWââS Marketplaceã®DLAMIããŒãžã«ç§»åããŸã ã ããã§ã¯ã次ã®ããšã«æ³šæãã䟡å€ããããŸãã
1. AMIããŒãžã§ã³
å·çæç¹ã§ã¯ãã2017幎6æããææ°ããŒãžã§ã³ã§ãã£ãããããã®èšäºã®æ®ãã®éšåãšããã»ã¹ã®äžè²«æ§ãä¿ã¡ããå Žåã¯ãéžæããããšããå§ãããŸãã
2.äœæããå°å
GPUãæèŒãããã¹ãŠã®ã¿ã€ãã®ãã·ã³ããã¹ãŠã®å°åã§å©çšã§ããããã§ã¯ãªãããšã«æ³šæããŠãã ããã å®éãæ£åŒã«å©çšã§ããå Žåã§ããäœæã§ãããšã¯éããŸããã ãã®ãããããšãã°ã2016幎ã®åœŒããšã®NIPSäŒè°ã§ã¯ãéåžžã«åé¡ããããŸããã ã¿ã€ãp2ã®ãã·ã³ã«å ããŠãå·çæç¹ã§ã¯ãDLAMIã¯ãã®ã¿ã€ããå©çšå¯èœãªå°åã§ã®ã¿å©çšå¯èœã§ããã
3.ã€ã³ã¹ã¿ã³ã¹ã¿ã€ãã®éžæ
p2.xlarge-GPUã¡ã¢ãªã®èŠä»¶ãæºããæãå®äŸ¡ãªãã·ã³ã§ãïŒg2.2xlargeãè©ŠããŠã¿ãããšã¯ã§ããŸãããåŸã§èŠåãããªãã£ããšèšããªãã§ãã ããïŒã å·çæç¹ã§ã¯ãäŸ¡æ Œã¯1æéãããçŽ0.9ãã«ã§ããã ããããå ¬åŒãŠã§ããµã€ãã§äŸ¡æ Œã確èªããæ¹ãè¯ãã§ãããã
4. VPC
ããªãã¯ããã§äœããã¹ããããããªãå Žå-觊ããªãã§ãã ããã
5.ã»ãã¥ãªãã£ã°ã«ãŒã
VPCãšåæ§ã«ãããªãã¯ç¥ããªã-觊ããªãã§ãã ããã ãã ããæ¢åã®ã°ã«ãŒãã䜿çšããå Žåã¯ãããã§SSLãéããŠããããšã確èªããŠãã ããã
6.ããŒãã¢
èªè ãSSHã®çµéšãããããããäœã§ããããç解ããŠãããšä»®å®ããŸãã
7.ã¯ãªãã¯ããŠäœæããŸãïŒ
å®éããã·ã³ãäœæããŠæ¥ç¶ã§ããŸãã
ãããã¯ãŒã¯ãã¬ãŒãã³ã°ã®æºå
æ°ããäœæããããã·ã³ã«æ¥ç¶ããŸãã ããã«ãç»é¢ãéå§ããŸãã ãŸããæ¥ç¶æã«ubuntuãã°ã€ã³ã䜿çšããå¿ èŠããããšããäºå®ãå¿ããªãã§ãã ããïŒ
ãã®ç¹ã«é¢ããããã€ãã®ã³ã¡ã³ãïŒ
- DLAMIã«ã¯ããã«äœ¿ããtmuxãå«ãŸããŠããªãããããã¹ã¯ãªãŒã³ããšèšããŸããã ãããæ²ããã
- ç»é¢ãtmuxãããããªãå Žåã§ãåé¡ãããŸãããèªã¿ç¶ããã ãã§åé¡ãªãåäœããŸãã ãã ãã tmux ïŒç§ã®éžæïŒãšscreenã®ãããªåç©ã®çš®é¡ã«ã€ããŠã¯èªã¿ã«è¡ãæ¹ãè¯ãã§ãããã
1. sockeyeãã€ã³ã¹ããŒã«ãã
æåã«å¿ èŠãªã®ã¯ãsockeyeãã€ã³ã¹ããŒã«ããããšã§ãã DLAMIã䜿çšãããšãã€ã³ã¹ããŒã«ããã»ã¹ã¯éåžžã«ç°¡åã§ãã³ãã³ãã¯1ã€ã ãã§ãã
sudo pip3 install sockeye --no-deps
ããã§éèŠãªã®ã¯ãããã©ã«ãã§ã¯DLAMIã®pipãPython 2ã䜿çšãããããpipã ãã§ãªãpip3ã䜿çšããå¿ èŠããããšããããšã§ããããã¯ãsockeyeã§ã¯ãµããŒããããŠããŸããã ãŸããäŸåé¢ä¿ã¯ãã¹ãŠã€ã³ã¹ããŒã«ãããŠãããããã€ã³ã¹ããŒã«ããå¿ èŠããããŸããã
2.ãã¬ãŒãã³ã°çšã®ããŒã¿ïŒãã€ã¢ãã°ïŒã®æºå
ãã¬ãŒãã³ã°ã«ã¯ããCornell Movie Dialogs CorpusãïŒhttps://www.cs.cornell.edu/~cristian/Cornell_Movie-Dialogs_Corpus.htmlïŒã䜿çšããŸãã å®éãããã¯æ ç»ããã®èšå€§ãªå¯Ÿè©±ã§ãã ãã¬ãŒãã³ã°ã®ããã«ãããªãã¯ããããæºåãããå¿ èŠããããŸããå®éãç§ã¯ãã§ã«ã±ãŒã¹ãæºåããã¹ã¯ãªãããå®è£ ããŠããããããŸã§ã«ãªãããšã«ã€ããŠè©³ãã説æããŸããã
ããã§ã¯ããã¬ãŒãã³ã°çšã«ãããã®ããŒã¿ãååŸããŠæºåããŸãããã
# cd ~/src src# git clone https://github.com/b0noI/dialog_converter.git Cloning into 'dialog_converter'⊠remote: Counting objects: 59, done. remote: Compressing objects: 100% (49/49), done. remote: Total 59 (delta 33), reused 20 (delta 9), pack-reused 0 Unpacking objects: 100% (59/59), done. Checking connectivity⊠done. src# cd dialog_converter dialog_converter git:(master)# git checkout sockeye_chatbot Branch sockeye_chatbot set up to track remote branch sockeye_chatbot from origin. Switched to a new branch 'sockeye_chatbot' dialog_converter git:(sockeye_chatbot)# python converter.py dialog_converter git:(sockeye_chatbot)# ls LICENSE README.md converter.py movie_lines.txt train.a train.b test.a test.b
泚ç®ã«å€ããããã€ãã®ããšïŒ
- srcãã©ã«ããŒã¯æ¢ã«ååšãããããäœæããå¿ èŠã¯ãããŸããã
- ãã©ã³ããsockeye_chatbotãã«æ³šæããŠãã ããããã®èšäºã«ã¯ããã®èšäºãšæŽåæ§ã®ããã³ãŒããæ ŒçŽãããŠããŸãã ãã¹ã¿ãŒã¯èªå·±è²¬ä»»ã§äœ¿çšããŠãã ããã
ããã§ã¯ããã¬ãŒãã³ã°ãè¡ããã©ã«ããŒãäœæããŠãããã«ãã¹ãŠã®ããŒã¿ãã³ããŒããŸãããã
# cd ~ # mkdir training # cd training training# cp ~/src/dialog_converter/train.* . training# cp ~/src/dialog_converter/test.* .
ããŠããã¬ãŒãã³ã°ãéå§ããæºåãæŽããŸãã...
ãã¬ãŒãã³ã°
sockeyeã䜿çšãããšããã¬ãŒãã³ã°ããã»ã¹ã¯éåžžã«ç°¡åã§ãã1ã€ã®ã³ãã³ããå®è¡ããã ãã§æžã¿ãŸãã
python3 -m sockeye.train --source train.a --target train.b --validation-source train.a --validation-target train.b --output model
ãã¬ãŒãã³ã°ãšæ€èšŒã«åãããŒã¿ã䜿çšããªãã§ãã ããã ãã ããçŸæç¹ã®ã¹ã¯ãªããã§ã¯ãããŒã¿ã2ã€ã®ã°ã«ãŒãã«æ£ç¢ºã«åå²ããŠããªããããããè¯ãçµæïŒäž»èŠ³çãªè©äŸ¡ã«ã€ããŠè©±ããŠããïŒãåŸãããŸãã
æåŸã®èšäºãèªãã§ãããšãsockeyeãããªãã®ã¯ãŒã¯ã¢ãŠãã«é©ããèšå®ãèŠã€ããããšããŠããããšã«æ°ä»ããããããŸããïŒ
- èŸæžãµã€ãº;
- ãããã¯ãŒã¯èšå®ã
- ãªã©...
æé©ã«è¿ãæ§æã¯ãããé«éãªïŒå®äŸ¡ãªïŒãã¬ãŒãã³ã°ã«ã€ãªããå¯èœæ§ããããããããã¯ããªãè¯ãã§ãã ãŸã ãsockeyeããã©ã¡ãŒã¿ãŒãæ€çŽ¢ããæ¹æ³ãšããã®ããã»ã¹ã«è²»ãããããªãœãŒã¹ã®éãæ£ç¢ºã«ç¢ºèªããå¿ èŠããããŸãã
ãŸããsockeyeã¯ããã¬ãŒãã³ã°ããã»ã¹ãå®äºãã䟡å€ãããææãæ£ç¢ºã«å€æããŸãã ããã¯ãã¢ãã«ã®å質ãæåŸã®8ã€ã®ã³ã³ãããŒã«ãã€ã³ãã®æ€èšŒçšããŒã¿ã§æ¹åãããŠããªãå Žåã«çºçããŸãã
çµæãåŸ ã£ãŠããŸã
åŸ ã£ãŠããéããã¬ãŒãã³ã°äžã«MXNetãGPUãªãœââãŒã¹ãåãæ§åãèŠãããšãã§ããŸãã ãããè¡ãã«ã¯ãæ°ãããŠã£ã³ããŠã§æ¬¡ã®ã³ãã³ããå®è¡ããŸãã
watch -n 0.5 nvidia-smi
次ã®ãããªãã®ãåç §ããŠãã ããã
ã¡ãªã¿ã«ãæè¡çã«ã¯ãããããšã®éä¿¡ãéå§ããã«ã¯ãå°ãªããšãæåã«äœæãããã³ã³ãããŒã«ãã€ã³ããåŸ ã€å¿ èŠããããŸãã ãããçºçãããšã次ã®ãããªãã®ã衚瀺ãããŸãã
ããã§éä¿¡ãéå§ã§ããŸãã
ãã£ãã...
ãã®ããã»ã¹ã§ã¯ããã¬ãŒãã³ã°ãåæ¢ããå¿ èŠã¯ãããŸãããæ°ãããŠã£ã³ããŠïŒãŸãã¯ãæ°ããSSHæ¥ç¶ïŒãéãããã¬ãŒãã³ã°ãè¡ãããŠããåããã©ã«ããŒã«ç§»åããŠã³ãã³ããå®è¡ããã ãã§ãã
python3 -m sockeye.translate --models model --use-cpu --checkpoints 0005
泚ç®ãããããã€ãã®èŠçŽ ïŒ
- python3-åœç¶;
- model-åŠç¿ããã»ã¹ãã¢ãã«ãä¿åãããã©ã«ããŒã®ååããã¬ãŒãã³ã°äžã«æå®ãããååãšäžèŽããå¿ èŠããããŸãã
- --use-cpu-ããããªããšãMXNetã¯GPUã䜿çšããããšããŸãããåŠç¿ããã»ã¹ã§ãŸã 䜿çšãããŠããããã倱æããå¯èœæ§ãæãé«ããªããŸãã
- --checkpoints 0005-ãã§ãã¯ãã€ã³ããä¿åããããšãã«ã³ã³ãœãŒã«åºåããååŸããããã§ãã¯ãã€ã³ãçªå·ã
ã³ãã³ãã®å®è¡åŸãsockeyeã¯STDINããå ¥åãèªã¿åããSTDOUTã«å¿çãåºåããŸãã 以äžã«äŸã瀺ããŸãã
1æéã®ãã¬ãŒãã³ã°åŸïŒ
2æéã®ãã¬ãŒãã³ã°ã®åŸ
3æéã®ãã¬ãŒãã³ã°ã®åŸãç§ãè ããå§ããŸãã=ïŒ
ãããã«
sockeyeã§ãããããã«ããã¬ãŒãã³ã°ããã»ã¹ã¯éåžžã«ç°¡åã§ãã å®éãããããæãé£ããããšã¯ãé©åãªãã·ã³ãéžæããŠæ¥ç¶ããããšã§ã=ïŒç§ã¯ãŸã èªè ã®äžäººã次ã®ããšãããã®ãåŸ ã£ãŠããŸãïŒ
- ãã¹ã¿ãŒãšãŒãïŒãŸãããŸãã¯ãã€ããŒïŒã«ãã£ãŠããããäœæããŸããã
- ããŒããªãã¶ãªã³ã°ãŠãããŒã¹ããããããäœæããŸããã
- StarWarsãŠãããŒã¹ããããããäœæããŸããã
PSïŒã¢ãã«ãããŠã³ããŒãããåæ¥åŸã«è»ãæã¡è² ããããšãå¿ããªãã§ãã ããã
èšç·Žãããã¢ãã«
ãã㧠ããã¬ãŒãã³ã°ãããã¢ãã«ãããŠã³ããŒãã§ããŸãïŒãã¬ãŒãã³ã°ã¯4æéã®ã¿ïŒã ç¬èªã®ãã¬ãŒãã³ã°ãè¡ããªãå Žåã¯ãããŒã«ã«ãã·ã³ã§äœ¿çšããŠããããšéã¶ããšãã§ããŸãã