def _lstm_init_params(self, params):
   input_size = hidden_size = output_size = self.word_img_embed_hidden_dim
   # Recurrent weights: take x_t, h_{t-1}, and bias unit
   # and produce the 3 gates and the input to cell signal
   params['WLSTM'] = initw(input_size + hidden_size, 4 * hidden_size).astype(config.floatX)
   params['bLSTM'] = np.zeros(4 * hidden_size).astype(config.floatX)
   # Decoder weights (e.g. mapping to vocabulary)
   params['Wd'] = initw(hidden_size, self.vocab_size).astype(config.floatX)
   params['bd'] = np.zeros(self.vocab_size).astype(config.floatX)
예제 #2
0
    def init(input_size, hidden_size, output_size):

        model = {}

        model['WLSTM'] = initw(input_size + hidden_size + 1, 4 * hidden_size)
        model['Wd'] = initw(hidden_size, output_size)
        model['bd'] = np.zeros((1, output_size))

        update = ['WLSTM', 'Wd', 'bd']

        return {'model': model, 'update': update}
 def init_params(self, model_options):
   self.image_size = 4096  # size of CNN vectors hardcoded here
   self.word_img_embed_hidden_dim = model_options['word_img_embed_hidden_dim']
   self.vocab_size = model_options['vocab_size']
   
   # Dict name (string) -> numpy ndarray
   params = OrderedDict()
   # Ws -> word encoder
   params['Ws'] = initw(self.vocab_size, self.word_img_embed_hidden_dim).astype(config.floatX)
   # We, be -> image encoder
   params['We'] = initw(self.image_size, self.word_img_embed_hidden_dim).astype(config.floatX)
   params['be'] = initw(self.word_img_embed_hidden_dim).astype(config.floatX)    
   self._lstm_init_params(params)
  
   return params