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
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
def hiddens_to_output_probs(hiddens): output = concat_and_multiply(params['predict'], hiddens) # Normalize log-probs. return output - logsumexp(output, axis=1, keepdims=True)
def update_rnn(input, hiddens): return np.tanh( concat_and_multiply(params['rnn']['change'], input, hiddens))
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.
def hiddens_to_output_probs(hiddens): output = concat_and_multiply(params['predict'], hiddens) return 1.0 / (1.0 + np.exp(-output))
def hiddens_to_output_probs(hiddens): output = concat_and_multiply(params['predict'], hiddens) return output - logsumexp(output, axis=1, keepdims=True) # Normalize log-probs.