2016-11-26 5 views
1

私は母国語のための訓練されたword2vecモデルをダウンロードしました。 それは「news.model.bin」ファイルを持っていたし、私はそれを解凍したとき、txtファイルまたはpickleを参照することが期待、しかし、私はこのようなカオスconsistatとそれに別の.binのファイルを見つけました:TheanoまたはTensorFlowに ".bin"をロードする

\09\b9\.,-;sdfkf %some really strange symbols and seem to be invalid symbols% 

Iそれをコピーすることはできません。なぜなら、私は普通にファイルを開くことができないからです。それは重くて、ラップトップはちょうど死にます。 問題は次のとおりです。この例証コードは事前トランジェントモデルかどうかですか?はいの場合 - 私はそれに対処する必要がありますか?

P.S.私はからモデルだリンク、(モデルは、ページの下部にある):http://ling.go.mail.ru/dsm/ru/about

+0

迅速Googleは(http://mccormickml.com/2016/04/12/googles-pretrained-word2vec- [これ]オンモデルイン・パイソン/)。私はword2vecのための特殊なフォーマットだと思う。それが役に立てば幸い。 – Kh40tiK

+0

[word2vec binファイルをテキストに変換]の複製が可能です(http://stackoverflow.com/questions/27324292/convert-word2vec-bin-file-to-text) –

答えて

0

2種類の溶液:

  1. が.txtに.binファイルを変換しますConvert word2vec bin file to text
  2. 直接読み取ります。以下のように表示されます。

https://gist.github.com/j314erre/b7c97580a660ead82022625ff7a644d8 .binファイルを読み込み、TensorFlow変数にそれをロードするためにいくつかのコードが含まれています

# Initialize all variables 
    sess.run(tf.initialize_all_variables()) 
    # Initialize all variables 
    sess.run(tf.initialize_all_variables()) 
    if FLAGS.word2vec: 
     # initial matrix with random uniform 
     initW = np.random.uniform(-0.25,0.25,(len(vocab_processor.vocabulary_), FLAGS.embedding_dim)) 
     # load any vectors from the word2vec 
     print("Load word2vec file {}\n".format(FLAGS.word2vec)) 
     with open(FLAGS.word2vec, "rb") as f: 
      header = f.readline() 
      vocab_size, layer1_size = map(int, header.split()) 
      binary_len = np.dtype('float32').itemsize * layer1_size 
      for line in xrange(vocab_size): 
       word = [] 
       while True: 
        ch = f.read(1) 
        if ch == ' ': 
         word = ''.join(word) 
         break 
        if ch != '\n': 
         word.append(ch) 
       idx = vocab_processor.vocabulary_.get(word) 
       if idx != 0: 
        initW[idx] = np.fromstring(f.read(binary_len), dtype='float32') 
       else: 
        f.read(binary_len)  

    sess.run(cnn.W.assign(initW)) 

あなたはこのtext classification example in TensorFlowでこのコードを使用することができます。

FYI:

関連する問題