Extend a self-attention mechanism to handle batched 3D inputs and apply a causal mask so each token can only attend to itself and previous tokens.
Implement the function batched_causal_self_attention(X, W_query, W_key, W_value) where:
X is a 3D input of shape (B, T, d_in) representing a batch of B token sequences, each of length T, with d_in-dimensional features.W_query, W_key, W_value are projection matrices of shape (d_in, d_out).Steps:
X with the three weight matrices, giving tensors of shape (B, T, d_out).(B, T, T) using Q @ K^T divided by sqrt(d_out).attn @ V of shape (B, T, d_out).Return the resulting context tensor as a nested Python list (use .tolist()).