「word2vecによる自然言語処理」を読む

使用環境:RaspberryPi rape機

最初にword2vecが必要なので本に書いてあるsvnでコードをdownloadしようとしたが、svnはないとメッセージがでたので

sudo apt-get install subversion

と実行したがinstallできなかった。

RaspberryPiはDebian系のLinuxなのでこれではだめだったようで

wisdomtrees.net

を参考に

$ sudo apt-get install subversion subversion-tools libapache2-svn

でインストールを試みたが駄目だったがメッセージにapt-get updateとあったので

アップデート後再度上記コマンドを試行したところinstall完了した。

svn checkout http://word2vec.googlecode.com/svn/trunk

を実行後下記のようにメッセージが出た

A  trunk/word2phrase.c
A trunk/LICENSE
A trunk/word-analogy.c
A trunk/compute-accuracy.c
A trunk/demo-analogy.sh
A trunk/demo-classes.sh
A trunk/demo-train-big-model-v1.sh
A trunk/demo-word-accuracy.sh
A trunk/demo-phrases.sh
A trunk/questions-words.txt
A trunk/demo-phrase-accuracy.sh
A trunk/demo-word.sh
A trunk/distance.c
A trunk/README.txt
A trunk/questions-phrases.txt
A trunk/word2vec.c
A trunk/makefile

c言語のソースが5ファイル

スクリプトが7ファイル

テキストが3ファイル

ライセンス文書が1ファイル

README文書が1ファイル

revisionは42

ホームにtrunkフォルダーができていたのでこれをword2vecに名前変更

gccコンパイルする。makeコマンドを実行したところ

gcc word2vec.c -o word2vec -lm -pthread -O3 -march=native -Wall -funroll-loops -Wno-unused-result
cc1: error: bad value (native) for -march switch
make: *** [word2vec] Error 1

がでた。 

 -march=nativeはIA-32/x86-64のみの最適化オプションのようなのでオプションか外してmakeしたところ

gcc word2vec.c -o word2vec -lm -pthread -O3 -Wall -funroll-loops -Wno-unused-result -mcpu=arm1176jzf-s
word2vec.c: In function ‘TrainModelThread’:
word2vec.c:366:36: warning: cast from pointer to integer of different size [-Wpointer-to-int-cast]
word2vec.c:372:50: warning: cast from pointer to integer of different size [-Wpointer-to-int-cast]
word2vec.c:413:54: warning: cast from pointer to integer of different size [-Wpointer-to-int-cast]
gcc word2phrase.c -o word2phrase -lm -pthread -O3 -Wall -funroll-loops -Wno-unused-result -mcpu=arm1176jzf-s
gcc distance.c -o distance -lm -pthread -O3 -Wall -funroll-loops -Wno-unused-result -mcpu=arm1176jzf-s
distance.c: In function ‘main’:
distance.c:31:8: warning: unused variable ‘ch’ [-Wunused-variable]
gcc word-analogy.c -o word-analogy -lm -pthread -O3 -Wall -funroll-loops -Wno-unused-result -mcpu=arm1176jzf-s
word-analogy.c: In function ‘main’:
word-analogy.c:31:8: warning: unused variable ‘ch’ [-Wunused-variable]
gcc compute-accuracy.c -o compute-accuracy -lm -pthread -O3 -Wall -funroll-loops -Wno-unused-result -mcpu=arm1176jzf-s
compute-accuracy.c: In function ‘main’:
compute-accuracy.c:29:109: warning: unused variable ‘ch’ [-Wunused-variable]
chmod +x *.sh

とメッセージがでて

word2vec

word2phrase

distance

word-analogy

compute-accuracy

ができていた。