courses/machine_learning/deepdive/09_sequence/word2vec/word2vec.py
def nearby(self, words, num=20):
    """Prints out nearby words given a list of words."""
    ids = np.array([self._word2id.get(x, 0) for x in words])
    vals, idx = self._session.run(
        [self._nearby_val, self._nearby_idx], {self._nearby_word: ids})
    for i in xrange(len(words)):
      print("\n%s\n=====================================" % (words[i]))
      for (neighbor, distance) in zip(idx[i, :num], vals[i, :num]):
        print("%-20s %6.4f" % (self._id2word[neighbor], distance))
Prints out nearby words given a list of words.
Prints out nearby words given a list of words.
Prints out nearby words given a list of words .
def nearby(self, words, num=20):
    ids = np.array([self._word2id.get(x, 0) for x in words])
    vals, idx = self._session.run(
        [self._nearby_val, self._nearby_idx], {self._nearby_word: ids})
    for i in xrange(len(words)):
      print("\n%s\n=====================================" % (words[i]))
      for (neighbor, distance) in zip(idx[i, :num], vals[i, :num]):
        print("%-20s %6.4f" % (self._id2word[neighbor], distance))
def nearby ( self , words , num = 20 ) : ids = np . array ( [ self . _word2id . get ( x , 0 ) for x in words ] ) vals , idx = self . _session . run ( [ self . _nearby_val , self . _nearby_idx ] , { self . _nearby_word : ids } ) for i in xrange ( len ( words ) ) : print ( "\n%s\n=====================================" % ( words [ i ] ) ) for ( neighbor , distance ) in zip ( idx [ i , : num ] , vals [ i , : num ] ) : print ( "%-20s %6.4f" % ( self . _id2word [ neighbor ] , distance ) )
Prints out nearby words given a list of words.
Prints out nearby words given a list of words .
"""Prints out nearby words given a list of words."""
self
words
num