Googleの記事をみつけたところ
なんかおもしろそうなOSSがあるとか。
んで、今回これをインストールしてみたった
ソースだうんろーどしてきまーす。
$ mkdir tmp || cd tmp/ $ svn checkout http://word2vec.googlecode.com/svn/trunk/ word2vec-read-only $ cd word2vec-read-only $ make gcc word2vec.c -o word2vec -lm -pthread -O3 -march=native -Wall -funroll-loops -Wno-unused-result gcc word2phrase.c -o word2phrase -lm -pthread -O3 -march=native -Wall -funroll-loops -Wno-unused-result gcc distance.c -o distance -lm -pthread -O3 -march=native -Wall -funroll-loops -Wno-unused-result distance.c:18:10: fatal error: 'malloc.h' file not found #include <malloc.h> ^ 1 error generated. make: *** [distance] Error 1
おろ???
調べた所、どうやらライブラリの場所が変更になったとか
$ vim distance.c 18行目を変更 #include <malloc.h> ↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓ #include <malloc/malloc.h>
もっかいmake
$ make gcc word2vec.c -o word2vec -lm -pthread -O3 -march=native -Wall -funroll-loops -Wno-unused-result gcc word2phrase.c -o word2phrase -lm -pthread -O3 -march=native -Wall -funroll-loops -Wno-unused-result gcc distance.c -o distance -lm -pthread -O3 -march=native -Wall -funroll-loops -Wno-unused-result distance.c:46:19: warning: implicitly declaring library function 'malloc' with type 'void *(unsigned long)' vocab = (char *)malloc((long long)words * max_w * sizeof(char)); ^ distance.c:46:19: note: please include the header <stdlib.h> or explicitly provide a declaration for 'malloc' distance.c:31:8: warning: unused variable 'ch' [-Wunused-variable] char ch; ^ 2 warnings generated. gcc word-analogy.c -o word-analogy -lm -pthread -O3 -march=native -Wall -funroll-loops -Wno-unused-result word-analogy.c:18:10: fatal error: 'malloc.h' file not found #include <malloc.h> ^ 1 error generated. make: *** [word-analogy] Error 1
(´Д`;)
全部修正をやろうと思ったら、ちょっと気になる記事が
コンパイラのエラーメッセージで指摘されますが、「#include
」を使ってくださいとのこと
(´Д`;)ハヤクイエヨ
というわけで、修正
$ vim distance.c 18行目を変更 #include <malloc/malloc.h> ↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓ #include <stdlib.h> $ vim word-analogy.c 18行目を変更 $ vim compute-accuracy.c 19行目を変更
$ make gcc word2vec.c -o word2vec -lm -pthread -O3 -march=native -Wall -funroll-loops -Wno-unused-result gcc word2phrase.c -o word2phrase -lm -pthread -O3 -march=native -Wall -funroll-loops -Wno-unused-result gcc distance.c -o distance -lm -pthread -O3 -march=native -Wall -funroll-loops -Wno-unused-result distance.c:31:8: warning: unused variable 'ch' [-Wunused-variable] char ch; ^ 1 warning generated. gcc word-analogy.c -o word-analogy -lm -pthread -O3 -march=native -Wall -funroll-loops -Wno-unused-result word-analogy.c:31:8: warning: unused variable 'ch' [-Wunused-variable] char ch; ^ 1 warning generated. gcc compute-accuracy.c -o compute-accuracy -lm -pthread -O3 -march=native -Wall -funroll-loops -Wno-unused-result compute-accuracy.c:29:109: warning: unused variable 'ch' [-Wunused-variable] char st1[max_size], st2[max_size], st3[max_size], st4[max_size], bestw[N][max_size], file_name[max_size], ch; ^ 1 warning generated. chmod +x *.sh
うがぁああ・・・あれ?
warningは出力されているが、コンパイルできちゃった。。。
権限を変更し、試しに実行してみる
$ chmod +x *.sh
あれ?そういえば。。。
????
どやって実行すんのこれ?
ググってみる。
ε===\( ´Д`)ノ
\(´Д` )ノ ===3
ググってきた。
どうやら、コーパスが必要とのこと。
というわけで、データをダウンロード
$ curl http://mattmahoney.net/dc/text8.zip >text8.zip $ unzip text8.zip
OK
んじゃ、実行
$ bash demo-word.sh make: Nothing to be done for `all'. Starting training using file text8 Vocab size: 71291 Words in train file: 16718843 Alpha: 0.000005 Progress: 100.10% Words/thread/sec: 72.69k real 17m52.999s user 57m29.884s sys 0m21.275s Enter word or sentence (EXIT to break):
おうおうおうおう
すげぇCPUが熱い。熱いよ!
$ wc text8 0 17005207 100000000 text8
ではでは。コマンド実行後は「vectors.bin」というファイルが生成されるので
これと別途コマンドを使って、確認してみます。
$ ./distance vectors.bin
まずは「okinawa」を確認してみました。
Enter word or sentence (EXIT to break): okinawa Word: okinawa Position in vocabulary: 14109 Word Cosine distance ------------------------------------------------------------------------ honshu 0.624581 hokkaido 0.621520 ryukyu 0.588583 kyushu 0.573657 shikoku 0.567894
(°Д°;)すげぇ・・・
何も覚えさせていないのに、この精度・・・・?
じゃねぇ。精度よえぇ。
honshu -> 本州? なんで本州が1位なの?
よくわからなんまま次に色々試してみる。
- anime -> アニメ
Enter word or sentence (EXIT to break): anime Word: anime Position in vocabulary: 3613 Word Cosine distance ------------------------------------------------------------------------ manga 0.752264 hentai 0.604220 oshii 0.592165 toei 0.567943 otaku 0.564296
- robot -> ロボット
Enter word or sentence (EXIT to break): robot Word: robot Position in vocabulary: 5411 Word Cosine distance ------------------------------------------------------------------------ robotic 0.644809 robots 0.637811 robo 0.617181 humanoid 0.602430 android 0.586521
- windows -> MSのOS
Enter word or sentence (EXIT to break): windows Word: windows Position in vocabulary: 981 Word Cosine distance ------------------------------------------------------------------------ microsoft 0.608997 os 0.592433 bsod 0.583948 amigaos 0.583645 xp 0.580960
- linux -> ペンギンOS
Enter word or sentence (EXIT to break): linux Word: linux Position in vocabulary: 1845 Word Cosine distance ------------------------------------------------------------------------ linspire 0.655355 freebsd 0.637356 ubuntu 0.627402 unix 0.619037 minix 0.606087
なんかうまくいっているのか、いっていないのかよくわからん。
もうちょっと遊んでみようかなと思う。