Skip to content
DeepForgeby svx
All problems
MediumDeep Learningdl-113

Bidirectional RNN Output Concat

Problem

Concatenate the forward and backward hidden states of a bidirectional RNN at each timestep, producing one vector of length forward_dim + backward_dim per step.

The signature is bidi_concat(forward_states, backward_states). Both inputs are lists with the same number of timesteps.

Hint

Forward reads left to right and backward reads right to left; concatenate them per position.

Test cases

case 1
in: [[[1,2],[3,4]],[[10,20],[30,40]]]
expected: [[1,2,10,20],[3,4,30,40]]
case 2
in: [[[1]],[[2]]]
expected: [[1,2]]
case 3
in: [[[1,2],[3,4],[5,6]],[[0],[0],[0]]]
expected: [[1,2,0],[3,4,0],[5,6,0]]
Starter codePython
def bidi_concat(forward_states, backward_states):
    # Your code here
    pass

3 test cases · run your code against them in the editor