#392RNN output — project the hidden stateEasyRNN
RNN output — project the hidden state
Background
After updating the hidden state, an RNN reads out a prediction with a linear output projection:
(For classification you'd add a softmax; here it's the raw projection.) Following the lesson's code convention, with h_t a row vector this is h_t @ W_hy + b_y where W_hy has shape (H, O).
Problem statement
Implement output_projection(h, W_hy, b_y) returning .
Input
h— hidden state, lengthH.W_hy— shape(H, O).b_y— lengthO.
Output
Returns an np.ndarray of length O: the output vector.
Examples
Example 1 — identity readout
Input: h = [1, 2], W_hy = [[1, 0], [0, 1]], b_y = [0, 0]
Output: [1 2]
Example 2 — with bias
Input: h = [1], W_hy = [[2, 3]], b_y = [1, 1]
Output: [3 4]
Explanation: .
Constraints
- Compute
h @ W_hy + b_y. - Return shape
(O,).
Notes
- This is the only place the output dimension
Oenters; the hidden sizeHis decoupled from how many things you predict.
Python
Loading...
▶ Run executes the 3 visible sample tests below in your browser. Submit runs the full suite — including hidden tests — on the server for an official verdict.
- •Example -- projection with bias
- •Reference readout, 3 hidden to 2 out
- •Sample wide projection