Search code examples
kerasbidirectionalgru

How to get sequence, hidden state and cell state for Bidirectional GRU?


encoder_gru = Bidirectional(GRU(nb_gru_cells,return_sequences=True, return_state=True))
encoder_outputs, encoder_state_fwd_h, encoder_state_fwd_c, encoder_state_bwd_h, encoder_state_bwd_c = encoder_gru1(encoder_inputs)

ValueError: not enough values to unpack (expected 5, got 3)

Why is it only 3? Does it internally concatenate the forward and backward states? So is it outputs, fwd_h, bwd_h or outputs, hidden states, cell states?


Solution

  • LSTM has three values at output (output, hidden and cell) whereas GRU has two values at output (output and hidden). There is no cell state in GRU therefore the forward and backward cell states should be removed from your code.

    encoder_gru = Bidirectional(GRU(nb_gru_cells,return_sequences=True, return_state=True))
    encoder_outputs, encoder_state_fwd_h, encoder_state_bkw_h = encoder_gru(encoder_inputs)