def update_lstm(input, hiddens, cells, forget_weights, change_weights, ingate_weights, outgate_weights): """One iteration of an LSTM layer.""" change = np.tanh(activations(change_weights, input, hiddens)) forget = sigmoid(activations(forget_weights, input, cells, hiddens)) ingate = sigmoid(activations(ingate_weights, input, cells, hiddens)) cells = cells * forget + ingate * change outgate = sigmoid(activations(outgate_weights, input, cells, hiddens)) hiddens = outgate * np.tanh(cells) return hiddens, cells
def sigmoid(x): return 0.5*(np.tanh(x) + 1.0) # Output ranges from 0 to 1.
def sigmoid(x): return 0.5*(np.tanh(x) + 1)
def nonlinearity(self, x): return np.tanh(x)
def update(input, hiddens, change_weights): return np.tanh(activations(change_weights, input, hiddens))
def predictions(W_vect, inputs): for W, b in unpack_layers(W_vect): outputs = np.dot(inputs, W) + b inputs = np.tanh(outputs) return outputs - logsumexp(outputs, axis=1, keepdims=True)