courses/machine_learning/deepdive/09_sequence/word2vec/word2vec.py
def build_graph(self):
    """Build the graph for the full model."""
    opts = self._options
    # The training data. A text file.
    (words, counts, words_per_epoch, self._epoch, self._words, examples,
     labels) = word2vec.skipgram_word2vec(filename=opts.train_data,
                                          batch_size=opts.batch_size,
                                          window_size=opts.window_size,
                                          min_count=opts.min_count,
                                          subsample=opts.subsample)
    (opts.vocab_words, opts.vocab_counts,
     opts.words_per_epoch) = self._session.run([words, counts, words_per_epoch])
    opts.vocab_size = len(opts.vocab_words)
    print("Data file: ", opts.train_data)
    print("Vocab size: ", opts.vocab_size - 1, " + UNK")
    print("Words per epoch: ", opts.words_per_epoch)
    self._examples = examples
    self._labels = labels
    self._id2word = opts.vocab_words
    for i, w in enumerate(self._id2word):
      self._word2id[w] = i
    true_logits, sampled_logits = self.forward(examples, labels)
    loss = self.nce_loss(true_logits, sampled_logits)
    tf.summary.scalar("NCE loss", loss)
    self._loss = loss
    self.optimize(loss)

    # Properly initialize all variables.
    tf.global_variables_initializer().run()

    self.saver = tf.train.Saver()
Build the graph for the full model.
Build the graph for the full model.
Build the graph for the full model .
def build_graph(self):
    opts = self._options
    (words, counts, words_per_epoch, self._epoch, self._words, examples,
     labels) = word2vec.skipgram_word2vec(filename=opts.train_data,
                                          batch_size=opts.batch_size,
                                          window_size=opts.window_size,
                                          min_count=opts.min_count,
                                          subsample=opts.subsample)
    (opts.vocab_words, opts.vocab_counts,
     opts.words_per_epoch) = self._session.run([words, counts, words_per_epoch])
    opts.vocab_size = len(opts.vocab_words)
    print("Data file: ", opts.train_data)
    print("Vocab size: ", opts.vocab_size - 1, " + UNK")
    print("Words per epoch: ", opts.words_per_epoch)
    self._examples = examples
    self._labels = labels
    self._id2word = opts.vocab_words
    for i, w in enumerate(self._id2word):
      self._word2id[w] = i
    true_logits, sampled_logits = self.forward(examples, labels)
    loss = self.nce_loss(true_logits, sampled_logits)
    tf.summary.scalar("NCE loss", loss)
    self._loss = loss
    self.optimize(loss)
    tf.global_variables_initializer().run()
    self.saver = tf.train.Saver()
def build_graph ( self ) : opts = self . _options ( words , counts , words_per_epoch , self . _epoch , self . _words , examples , labels ) = word2vec . skipgram_word2vec ( filename = opts . train_data , batch_size = opts . batch_size , window_size = opts . window_size , min_count = opts . min_count , subsample = opts . subsample ) ( opts . vocab_words , opts . vocab_counts , opts . words_per_epoch ) = self . _session . run ( [ words , counts , words_per_epoch ] ) opts . vocab_size = len ( opts . vocab_words ) print ( "Data file: " , opts . train_data ) print ( "Vocab size: " , opts . vocab_size - 1 , " + UNK" ) print ( "Words per epoch: " , opts . words_per_epoch ) self . _examples = examples self . _labels = labels self . _id2word = opts . vocab_words for i , w in enumerate ( self . _id2word ) : self . _word2id [ w ] = i true_logits , sampled_logits = self . forward ( examples , labels ) loss = self . nce_loss ( true_logits , sampled_logits ) tf . summary . scalar ( "NCE loss" , loss ) self . _loss = loss self . optimize ( loss ) tf . global_variables_initializer ( ) . run ( ) self . saver = tf . train . Saver ( )
Build the graph for the full model.
Build the graph for the full model .
"""Build the graph for the full model.""" # The training data. A text file. # Properly initialize all variables.
self