PIXELBANKv9.1.0
Menu

Bidirectional RNN Concatenation

Problem Statement

Combine forward and backward hidden states from a Bidirectional RNN.

Background

In Bidirectional RNNs, we process the sequence in both directions:

  • Forward pass: left to right
  • Backward pass: right to left

The final output at each timestep is typically the concatenation of both directions' hidden states, doubling the feature dimension.

Your Task

Write a function combine_bidirectional(forward_states, backward_states) that concatenates the forward and backward hidden states along the last dimension.

Input Format

  • forward_states: numpy array of shape (batch_size, seq_len, hidden_dim)
  • backward_states: numpy array of shape (batch_size, seq_len, hidden_dim)

Output Format

Return a numpy array of shape (batch_size, seq_len, 2 * hidden_dim).

Example:

Input:
forward shape (2, 3, 4), backward shape (2, 3, 4)
Output:
Shape (2, 3, 8)
Reasoning:

Concatenate along the last dimension (axis=-1)

Constraints:

  • Both inputs have the same shape
  • 1 <= batch_size <= 64
  • 1 <= seq_len <= 512
  • 1 <= hidden_dim <= 256
solution.py

Test Results

0/0
Run code to see test results.
Bidirectional RNN Concatenation - Easy | PixelBank