original_docstring:  assume vectors in embedding layer 2 are in vocab_list order already. 
docstring: assume vectors in embedding layer 2 are in vocab_list order already.
docstring_tokens: assume vectors in embedding layer 2 are in vocab_list order already .
code: def load_weights_to_matrix(self,embeddings_index=None):
          ''' assume vectors in embedding layer 2 are in vocab_list order already. '''
          if self.load_good:
              #print('stage: set embedding data after load.')
              if embeddings_index is None:
                  self.word_embeddings = self.model.get_layer('embedding_1').get_weights()
                  embeddings_index = {}
                  for i in range(len(self.vocab_list)):
                      word = self.vocab_list[i]
                      value = self.word_embeddings[0][i]
                      #print(value.shape, i, word)
                      embeddings_index[word] = value
              embed_size = int(hparams['embed_size'])
              self.embedding_matrix = np.zeros((len(self.vocab_list), embed_size))
              for i in range(len(self.vocab_list)):
                  word = self.vocab_list[i]
                  embedding_vector = embeddings_index.get(word)
                  if embedding_vector is not None:
                      # words not found in embedding index will be all random.
                      self.embedding_matrix[i] = embedding_vector[:embed_size]
                  else:
                      print('fill with random values', i, word)
                      self.embedding_matrix[i] = np.random.uniform(high=self.uniform_high, low=self.uniform_low,
                                                                   size=(embed_size,))
                      # self.embedding_matrix[i] = np.zeros((embed_size,))
          pass
code_tokens: def load_weights_to_matrix ( self , embeddings_index = None ) : if self . load_good : if embeddings_index is None : self . word_embeddings = self . model . get_layer ( 'embedding_1' ) . get_weights ( ) embeddings_index = { } for i in range ( len ( self . vocab_list ) ) : word = self . vocab_list [ i ] value = self . word_embeddings [ 0 ] [ i ] embeddings_index [ word ] = value embed_size = int ( hparams [ 'embed_size' ] ) self . embedding_matrix = np . zeros ( ( len ( self . vocab_list ) , embed_size ) ) for i in range ( len ( self . vocab_list ) ) : word = self . vocab_list [ i ] embedding_vector = embeddings_index . get ( word ) if embedding_vector is not None : self . embedding_matrix [ i ] = embedding_vector [ : embed_size ] else : print ( 'fill with random values' , i , word ) self . embedding_matrix [ i ] = np . random . uniform ( high = self . uniform_high , low = self . uniform_low , size = ( embed_size , ) ) pass
short_docstring: assume vectors in embedding layer 2 are in vocab_list order already.
short_docstring_tokens: assume vectors in embedding layer 2 are in vocab_list order already .
comment: ''' assume vectors in embedding layer 2 are in vocab_list order already. '''$SEP$#print('stage: set embedding data after load.')$SEP$#print(value.shape, i, word)$SEP$# words not found in embedding index will be all random.$SEP$# self.embedding_matrix[i] = np.zeros((embed_size,))