プログラミング初心者です。
PythonのFlaskを使って、word2vecを軽く体感できるWebアプリケーションを作ってみようと思っているのですが、詰まっています。
具体的には
http://eyepodtouch.net/?p=77
↑こちらのサイトを参考にして
from gensim.models import word2vec
sentences = word2vec.Text8Corpus("text8")
model = word2vec.Word2Vec(sentences, size=100)
model.save("sample.model")
model = word2vec.Word2Vec.load("sample.model")
(text8とは、シェル上でword2vecを動かす際に、デモ用にインストールされる分かち書き済みのテキストデータです。そのまま使用しています。)
と記述しているのですが、一向に結果を得られない(10分くらい後にエラーが出る)のでシェル上でPythonを起動させ
from gensim.models import word2vec
sentences = word2vec.Text8Corpus("text8")
model = word2vec.Word2Vec(sentences, size=100)
と直打ちしたところ
UserWarning: C extension not loaded for Word2Vec, training will be slow. Install a C compiler and reinstall gensim for fast training.
warnings.warn("C extension not loaded for Word2Vec, training will be slow. "
このようなエラー(?)が出て、やはり結果が得られませんでした。
gensimの再インストールも試しましたがダメでした。
text8は同じディレクトリの階層に置いています。
解決方法が分かる方、ぜひご教授ください。
〈追記〉
コーパスが悪いのかと思い、適当に都道府県名を入力した”todouhuken.txt”というテキストファイル(文字コードはutf-8)を作り、対話環境(ipython)で学習させてみたのですが、またしてもエラーが出ました。本当にわかりません。
from gensim.models import word2vec
sentences = word2vec.Text8Corpus("todouhuken.txt")
model = word2vec.Word2Vec(sentences, size=100)
RuntimeError Traceback (most recent call last)
<ipython-input-4-185bd86536f8> in <module>()
----> 1 model = word2vec.Word2Vec(sentences, size=100)
/Library/Python/2.7/site-packages/gensim/models/word2vec.pyc in init(self, sentences, size, alpha, window, min_count, max_vocab_size, sample, seed, workers, min_alpha, sg, hs, negative, cbow_mean, hashfxn, iter, null_word)
416 raise TypeError("You can't pass a generator as the sentences argument. Try an iterator.")
417 self.build_vocab(sentences)
--> 418 self.train(sentences)
419
420 def make_cum_table(self, power=0.75, domain=2**31 - 1):
/Library/Python/2.7/site-packages/gensim/models/word2vec.pyc in train(self, sentences, total_words, word_count, chunksize, total_examples, queue_factor, report_delay)
664
665 if not self.vocab:
--> 666 raise RuntimeError("you must first build vocabulary before training the model")
667 if not hasattr(self, 'syn0'):
668 raise RuntimeError("you must first finalize vocabulary before training the model")
〈環境〉
OSX Yosemite ver10.10.4
Python ver2.7.10
gensim ver0.12.1
回答1件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2015/08/12 02:44