All problems
Peephole LSTM
Problem
One peephole LSTM step. The forget and input gates see the previous cell state and the output gate sees the new cell state: f = sigmoid(Wf x + Uf h + pf * c_prev), i = sigmoid(Wi x + Ui h + pi * c_prev), g = tanh(Wg x + Ug h), c = f * c_prev + i * g, o = sigmoid(Wo x + Uo h + po * c), h = o * tanh(c).
The signature is peephole_lstm(x, h_prev, c_prev, W, U, b, p). W, U and b are lists of four matrices/vectors, and p is [pf, pi, po]. Return [h, c].
Hint
Peephole connections let the gates read the cell state directly; the output gate reads the updated c.
Test cases
case 1
in: [[1],[0],[0],[[[0]],[[0]],[[0]],[[0]]],[[[0]],[[0]],[[0]],[[0]]],[[0],[0],[0],[0]],[[0],[0],[0]]]
expected: [[0],[0]]
case 2
in: [[1],[0],[1],[[[5]],[[0]],[[0]],[[0]]],[[[0]],[[0]],[[0]],[[0]]],[[0],[0],[0],[0]],[[0],[0],[0]]]
expected: [[0.3793844859],[0.9933071491]]
case 3
in: [[2],[0],[1],[[[0]],[[0]],[[1]],[[0]]],[[[0]],[[0]],[[0]],[[0]]],[[0],[0],[0],[0]],[[1],[0],[0]]]
expected: [[0.4187993669],[1.2130723687]]
case 4
in: [[1],[0.5],[0.5],[[[1]],[[1]],[[1]],[[1]]],[[[0.5]],[[0.5]],[[0.5]],[[0.5]]],[[0.1],[0.1],[0.1],[0.1]],[[0.5],[0.5],[0.5]]]
expected: [[0.7113772528],[1.1432375977]]
Starter codePython
import math
def peephole_lstm(x, h_prev, c_prev, W, U, b, p):
# Your code here
pass4 test cases · run your code against them in the editor