2016-07-01 10 views
2

私はTFのword2vecモジュールを使用しています。私は、複数の行からなるデータファイルを読みたいと思います。各行は複数の単語で構成されています。 1つの行の各単語は、ソースまたはターゲットのいずれかの単語になります。word2vecのテンソルフローのデータ形式

私はtutorialに続くが、私はスキップ-グラムモデルの場合には

でカスタマイズされたデータを読み取るために、いわゆる例を見つけることができませんでした、我々は実際にすでにとしてあなたのためにこれをやりましたテンソルフロー/モデル/埋め込み/ word2vec.pyの例

word2vec_kernel.ccのコードを変更するか、tf.TextLineReaderを使用する必要があります。もしそうなら、どうですか?ありがとう!

答えて

0

入力ファイルの異なる行が異なるコンテキストを表す場合、テンソルフロー/モデル/埋め込み/ワード2vec.pyは、各行を単一の巨大文にラップするので、あなたのためには機能しません。あなたはここで、顧客のオペレータカーネルを書き換える必要があります。

以下https://github.com/tensorflow/models/blob/master/tutorials/embedding/word2vec_kernels.cc

を変更する必要がある機能の一つの例です。

void NextExample(int *label, int *example) { 
    while (true) { 
     if (label_pos_ >= label_limit_) { 
      ++total_words_processed_; 
      ++sentence_index_; 
      // check if we hit the end of the sentence 
      if (sentence_index_ >= sentence_size_) { 
       sentence_index_ = 0; 
       ++corpus_idx_; 
       // check if we hit the end of the corpus 
       if (corpus_idx_ >= nrows_) { 
        ++current_epoch_; 
        corpus_idx_ = 0; 
       } 
       sentence_ = corpus_[corpus_idx_]; 

      } 
      label_pos_ = std::max<int>(0, sentence_index_ - window_size_); 
      label_limit_ = 
        std::min<int>(sentence_.size(), sentence_index_ + window_size_ + 1); 
     } 
     if (sentence_index_ != label_pos_) // add constraint that tokens are different 
      break; 
     ++label_pos_; 
    } 
    *example = sentence_[sentence_index_]; 
    *label = sentence_[label_pos_++]; 
} 
関連する問題