示例#1
0
def _reorg_lstm_parameters(ih, hh):
    hidden_size = len(ih) // 4
    return L.LSTMParameterSet(
        ih[0 * hidden_size:1 * hidden_size],  # W_input
        hh[0 * hidden_size:1 * hidden_size],  # U_input
        ih[2 * hidden_size:3 * hidden_size],  # W_cell
        hh[2 * hidden_size:3 * hidden_size],  # U_cell
        ih[1 * hidden_size:2 * hidden_size],  # W_forget
        hh[1 * hidden_size:2 * hidden_size],  # U_forget
        ih[3 * hidden_size:4 * hidden_size],  # W_output
        hh[3 * hidden_size:4 * hidden_size])  # U_output
示例#2
0
 def _make_bias(self, params):
     bias = []
     for i in range(params.num_layers):
         bias.append(
             L.LSTMParameterSet(
                 np.random.rand(params.hidden_size).astype(np.float32),
                 np.random.rand(params.hidden_size).astype(np.float32),
                 np.random.rand(params.hidden_size).astype(np.float32),
                 np.random.rand(params.hidden_size).astype(np.float32),
                 np.random.rand(params.hidden_size).astype(np.float32),
                 np.random.rand(params.hidden_size).astype(np.float32),
                 np.random.rand(params.hidden_size).astype(np.float32),
                 np.random.rand(params.hidden_size).astype(np.float32)))
     return bias
示例#3
0
 def _make_weights(self, params, skip=False):
     weights = []
     for i in range(params.num_layers):
         w_out = params.hidden_size
         w_in = params.hidden_size if i > 0 or skip else params.data_size
         weights.append(
             L.LSTMParameterSet(
                 np.random.rand(w_out, w_in).astype(np.float32),
                 np.random.rand(w_out, w_out).astype(np.float32),
                 np.random.rand(w_out, w_in).astype(np.float32),
                 np.random.rand(w_out, w_out).astype(np.float32),
                 np.random.rand(w_out, w_in).astype(np.float32),
                 np.random.rand(w_out, w_out).astype(np.float32),
                 np.random.rand(w_out, w_in).astype(np.float32),
                 np.random.rand(w_out, w_out).astype(np.float32)))
     return weights