Problems
Loading...
Step 4 of 6
Output Gate
Easy

Compute the LSTM output gate and exposed hidden state.

ot=σ(Wo[ht−1,xt]+bo).o_t=\sigma\left(W_o[h_{t-1},x_t]+b_o\right). ht=ot⊙tanh⁡(Ct).h_t=o_t\odot\tanh(C_t).

Here, C_t is the already updated cell state. Return a dictionary containing output_gate and hidden_state as matching float64 NumPy arrays.

Loading visualization...

Examples

Input: h_prev = [0,0], x_t = [1,0.5], C_t = [0.5,-0.3], W_o = [[0.1,0.2,0.3,0.4],[0.5,0.1,0.2,0.3]], b_o = [0,0]

Output: {"output_gate":[0.622459,0.586618],"hidden_state":[0.287649,-0.170889]}

Explanation: The gate controls how much of the bounded cell state becomes visible as the hidden state.

Input: h_prev = [0.2,-0.1], x_t = [0.5,1], C_t = [1,-0.5], W_o = [[0.2,0.1,0.3,0.2],[0.1,0.4,0.2,0.3]], b_o = [0.1,-0.1]

Output: {"output_gate":[0.617748,0.569546],"hidden_state":[0.470473,-0.263197]}

Input: h_prev = [[0,0],[0.3,-0.2]], x_t = [[1,0.5],[0.5,1]], C_t = [[0.5,-0.3],[1,0.2]], W_o = [[0.1,0.2,0.3,0.4],[0.5,0.1,0.2,0.3]], b_o = [0,0]

Output: {"output_gate":[[0.622459,0.586618],[0.631812,0.629483]],"hidden_state":[[0.287649,-0.170889],[0.481185,0.124244]]}

Hint 1

Compute the gate from np.concatenate([h_prev, x_t], axis=-1).

Hint 2

The hidden state is output_gate * np.tanh(C_t).

Requirements

  • Compute the output gate from [h_prev, x_t].
  • Multiply the gate by tanh of the current cell state.
  • Return exactly the keys output_gate and hidden_state.

Constraints

  • Unbatched h_prev, C_t, and the output arrays have shape (H,); batched versions have shape (N, H).
  • x_t has shape (D,) or (N, D).
  • W_o has shape (H, H + D), and b_o has shape (H,).