Example #1
0
 def update_lstm(input, hiddens, cells):
     change  = np.tanh(concat_and_multiply(params['change'], input, hiddens))
     forget  = sigmoid(concat_and_multiply(params['forget'], input, hiddens))
     ingate  = sigmoid(concat_and_multiply(params['ingate'], input, hiddens))
     outgate = sigmoid(concat_and_multiply(params['outgate'], input, hiddens))
     cells   = cells * forget + ingate * change
     hiddens = outgate * np.tanh(cells)
     return hiddens, cells
Example #2
0
 def update_lstm(input, hiddens, cells):
     change  = np.tanh(concat_and_multiply(params['change'], input, hiddens))
     forget  = sigmoid(concat_and_multiply(params['forget'], input, hiddens))
     ingate  = sigmoid(concat_and_multiply(params['ingate'], input, hiddens))
     outgate = sigmoid(concat_and_multiply(params['outgate'], input, hiddens))
     cells   = cells * forget + ingate * change
     hiddens = outgate * np.tanh(cells)
     return hiddens, cells
Example #3
0
 def update_gru(input, hiddens):
     update = sigmoid(
         concat_and_multiply(params['transion']['update'], input, hiddens))
     reset = sigmoid(
         concat_and_multiply(params['transion']['reset'], input, hiddens))
     hiddens = (1 - update) * hiddens + update * sigmoid(
         concat_and_multiply(params['transion']['hiddenOut'], input,
                             hiddens * reset))
     return hiddens
Example #4
0
 def hiddens_to_output_probs(hiddens):
     output = concat_and_multiply(params['predict'], hiddens)
     # Normalize log-probs.
     return output - logsumexp(output, axis=1, keepdims=True)
Example #5
0
 def update_rnn(input, hiddens):
     return np.tanh(
         concat_and_multiply(params['rnn']['change'], input, hiddens))
Example #6
0
 def hiddens_to_output_probs(hiddens):
     output = concat_and_multiply(params['predict'], hiddens)
     noise = npr.gumbel(loc=0.0, scale=1.0, size=output.shape)
     output = TEMP * (output + noise)
     return output - logsumexp(output, axis=1,
                               keepdims=True)  # Normalize log-probs.
Example #7
0
 def hiddens_to_output_probs(hiddens):
     output = concat_and_multiply(params['predict'], hiddens)
     return 1.0 / (1.0 + np.exp(-output))
Example #8
0
 def hiddens_to_output_probs(hiddens):
     output = concat_and_multiply(params['predict'], hiddens)
     return output - logsumexp(output, axis=1, keepdims=True) # Normalize log-probs.