What the Savings Buy

Recurrent NetworksHard+30 XP+30

What the Savings Buy

A text classifier uses an LSTM over 120-dimensional embeddings, with a hidden state of 180 units.

Inside both an LSTM and a GRU, every gate and every candidate is computed the same way — from the current token and the previous hidden state:

ϕ ⁣(Wx xt+Wh ht−1+b)\phi\!\left(W_x\, x_t + W_h\, h_{t-1} + b\right)ϕ(Wx​xt​+Wh​ht−1​+b)

each with its own WxW_xWx​, its own WhW_hWh​ and its own bias bbb. (ϕ\phiϕ is the squashing function and holds no parameters.) Call one of these a block.

  • An LSTM has four blocks: forget, input, output, and the candidate.
  • A GRU has three: update, reset, and the candidate.

Nothing else in either cell holds parameters. So for input size xxx and hidden size hhh, one block holds h×xh \times xh×x numbers in WxW_xWx​, h×hh \times hh×h numbers in WhW_hWh​, and hhh biases.

You now replace the LSTM with a GRU and spend the entire saving on a wider hidden state: the GRU must use exactly the same total number of parameters as the LSTM it replaces.

What hidden size does the GRU get?

The answer is a whole number. (The embedding table and the output layer sit outside this count and are unchanged.)

Hints

Solve it to unlock the solution

Once you get it right, the reasoning behind the answer shows up here.