LoginSignup
1
0

More than 5 years have passed since last update.

word2vecを試してみる[Ubuntu 16.04 LTS]

Last updated at Posted at 2018-04-07

かなり前から気になっていたけど、なかなか試せてなかったword2vecを試してみました。

前提

  • Ubuntu 16.04 LTS

ダウンロードとビルド

先日購入したO'REILLYの「word2vecによる自然言語処理」では、svnでダウンロードと記載があったが、gitに移っているみたい・・・

git cloneでダウンロードします。

terminal
$ git clone https://github.com/svn2github/word2vec.git

makeコマンドでビルドします。

terminal
$ cd word2vec
$ make

※makeは、demo-word.sh内で実行されるようです。ここでわざわざmakeしなくても良いです。

デモの実行

demo-word.shというデモのスクリプトがあるので実行します。

terminal
$ ./demo-word.sh 
make: 'all' に対して行うべき事はありません.
--2018-04-07 17:27:41--  http://mattmahoney.net/dc/text8.zip
mattmahoney.net (mattmahoney.net) をDNSに問いあわせています... 67.195.197.75
mattmahoney.net (mattmahoney.net)|67.195.197.75|:80 に接続しています... 接続しました。
HTTP による接続要求を送信しました、応答を待っています... 200 OK
長さ: 31344016 (30M) [application/zip]
`text8.gz' に保存中

text8.gz                            100%[=================================================================>]  29.89M   366KB/s    時間 84s   

2018-04-07 17:29:06 (362 KB/s) - `text8.gz' へ保存完了 [31344016/31344016]

Starting training using file text8
Vocab size: 71291
Words in train file: 16718843
Alpha: 0.000005  Progress: 100.10%  Words/thread/sec: 123.98k  
real    4m22.016s
user    33m43.717s
sys 0m3.275s
Enter word or sentence (EXIT to break):

サンプルデータのダウンロードが実行されます。ダウンロードが完了すると、学習が始まります。学習が完了したら、「Enter word or sentence (EXIT to break):」というプロンプトが表示されるので、英語のワードを入力してみます。
今回は、"obama"と入力してみました。

terminal
Enter word or sentence (EXIT to break): obama

Word: obama  Position in vocabulary: 59842

                                              Word       Cosine distance
------------------------------------------------------------------------
                                            barack      0.837348
                                           senator      0.568986
                                              bayh      0.509735
                                          democrat      0.475600
                                            durbin      0.455052
                                       congressman      0.454737
                                         goldwater      0.452451
                                        republican      0.451464
                                             stott      0.449625
                                           bentsen      0.446778
                                           despoja      0.445402
                                         statewide      0.444931
                                      jeffersonian      0.434419
                                          illinois      0.433336
                                            quayle      0.430311
                                             orrin      0.418546
                                       congressmen      0.418308
                                            rodham      0.415910
                                             adlai      0.411628
                                            caucus      0.411470
                                          kucinich      0.407380
                                         lieberman      0.405657
                                            dianne      0.405132
                                          klansman      0.404264
                                             lacey      0.402389
                                          senators      0.402182
                                         feinstein      0.399778
                                             jesse      0.398483
                                            junior      0.396396
                                        yarborough      0.394452
                                         primaries      0.394365
                                        jacksonian      0.393755
                                            senate      0.392431
                                           clinton      0.389318
                                          caucuses      0.385908
                                              burr      0.385312
                                             ginny      0.384196
                                             jenna      0.383016
                                     gubernatorial      0.381863
                                            peoria      0.381616
Enter word or sentence (EXIT to break):

"barack"が83.7%, "senator(上院議員)"が56.9%という結果になりました。
面白いですね・・・

以上、日本語にも挑戦してみたいと思います。

1
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
0