Deep Semantic Role Labeling のソースコードを動かすまでの手順
nvidia-docker2でコンテナを作成。 —runtime=nvidiaを忘れないこと。
$ docker run -it --runtime=nvidia nvidia/cuda:7.5-cudnn5-devel-ubuntu14.04ソースコードがtheano==0.9.0にしか対応しておらず、しかもtheano0.9.0はcuDNN5でしか動かない為、コンテナで新しい環境を作った。
作ったコンテナに入る。
$ docker start hoge$ docker attach hogeここから先の手順はコンテナ内で実行。
コンテナに標準搭載されていなかった必要パッケージを入れる
# apt update# apt install git# apt install unzipコンテナ内でのライブラリ管理が面倒なので、Anaconda2をインストールすることにした。
Anacondaに必要パッケージのインストール
# apt install -y make build-essential libssl-dev zlib1g-dev libbz2-dev libreadline-dev libsqlite3-dev wget curl llvm libncurses5-dev libncursesw5-dev libpng-devpyenvのインストール
# git clone git://github.com/yyuu/pyenv.git ~/.pyenv# git clone https://github.com/yyuu/pyenv-pip-rehash.git ~/.pyenv/plugins/pyenv-pip-rehash# echo 'export PYENV_ROOT="$HOME/.pyenv"' >> ~/.bashrc# echo 'export PATH="$PYENV_ROOT/bin:$PATH"' >> ~/.bashrc# echo 'eval "$(pyenv init -)"' >> ~/.bashrc# source ~/.bashrcまず、最新のAnaconda (Python2系)のバージョンを確認
# pyenv install -l | grep anaconda2anaconda2-2.4.0anaconda2-2.4.1anaconda2-2.5.0anaconda2-4.0.0anaconda2-4.1.0anaconda2-4.1.1anaconda2-4.2.0anaconda2-4.3.0anaconda2-4.3.1anaconda2-4.4.0anaconda2-5.0.0anaconda2-5.0.1anaconda2-5.1.0anaconda2-5.2.0最新のAnaconda2 (ここではanaconda2-2.4.0) をインストールし、デフォルトとして設定。
# pyenv install anaconda2-2.4.0# pyenv global anaconda2-2.4.0# echo 'export PATH="$PYENV_ROOT/versions/anaconda2-2.4.0/bin:$PATH"' >> ~/.bashrc# source ~/.bashrcPythonの環境を確認
# python --versionPython 2.7.10 :: Anaconda 2.4.0 (64-bit)ここから、SRLのソースコードのインストールに移る コンテナ内の適当なディレクトリで、git clone
# git clone https://github.com/luheng/deep_srl.gitコードを動かすため、パッケージをインストール
# conda install theano==0.9.0 pygpu protobuf nltk# apt install tcshGoogle ドライブのPretrainedファイル6つすべてダウンロードし、~/deep_srl/resources下に配置
https://drive.google.com/drive/folders/0B5zHXdvxrsjNZUx2YXJ5cEM0TW8?usp=sharing
先ほどダウンロードしたファイルの展開
# tar -zxvf conll05_ensemble.tar.gz# tar -zxvf conll05_model.tar.gz# tar -zxvf conll05_propid_model.tar.gz# tar -zxvf conll2012_ensemble.tar.gz# tar -zxvf conll2012_model.tar.gz# tar -zxvf conll2012_propid_model.tar.gzGloVe のインストール
以上でインストール終了。
サンプルコードを動かす前に、モデルのパスを指定
# vi run_end2end.sh#!/bin/bashexport PATH=/usr/local/cuda/bin:$PATHexport LD_LIBRARY_PATH=/usr/local/cuda:/usr/local/cuda/lib64:/opt/OpenBLAS/libMODEL_PATH="./resources/conll05_propid_model"('lstm_1_rdrop', 0.1, True)
('lstm_2_rdrop', 0.1, True)
('lstm_3_rdrop', 0.1, True)
('lstm_4_rdrop', 0.1, True)
('lstm_5_rdrop', 0.1, True)
('lstm_6_rdrop', 0.1, True)
('lstm_7_rdrop', 0.1, True)
32072 2Loaded model from: ./resources/conll05_ensemble/model4.npzModel building and loading duration was 0:00:04.Running model duration was 0:00:00.Decoding duration was 0:00:00.Accuracy: 38.750 (31.0/80.0)Printing results to temp file: /root/script/deep_srl/python/neural_srl/shared/../../../temp/srl_pred_5859.tmpNumber of Sentences : 5Number of Propositions : 8Percentage of perfect props : 0.00corr. excess missed prec. rec. F1------------------------------------------------------------Overall 0 19 0 0.00 0.00 0.00----------A0 0 6 0 0.00 0.00 0.00A1 0 8 0 0.00 0.00 0.00A2 0 2 0 0.00 0.00 0.00AM-DIR 0 2 0 0.00 0.00 0.00AM-TMP 0 1 0 0.00 0.00 0.00------------------------------------------------------------V 6 2 2 75.00 75.00 75.00------------------------------------------------------------Fscore=0.0Writing to human-readable file: temp/sample.out結果はテキストファイルとして、temp/sample.outに保存される
temp/sample.out
1 John told Pat to cut off the tree .Predicate: told(2)A0: 1 JohnV: toldA2: PatA1: to cut off the tree1 John told Pat to cut off the tree .Predicate: cut(5)A0: PatV: cut offA1: the tree4 John told Pat to cut off the tree .Predicate: told(2)A0: 4 JohnV: toldA2: PatA1: to cut off the tree4 John told Pat to cut off the tree .Predicate: cut(5)A0: PatV: cut offA1: the tree1 We saw the Grand Canyon flying to Chicago .Predicate: saw(2)A0: WeV: sawA1: the Grand Canyon flying to Chicago1 We saw the Grand Canyon flying to Chicago .Predicate: flying(6)A1: the Grand CanyonV: flyingAM-DIR: to Chicago5 We saw the Grand Canyon flying to Chicago .Predicate: saw(2)AM-TMP: 5A0: WeV: sawA1: the Grand Canyon flying to Chicago5 We saw the Grand Canyon flying to Chicago .Predicate: flying(6)A1: the Grand CanyonV: flyingAM-DIR: to Chicagoこんな感じで、動詞を中心とした係り受け解析ができる。