BILSTM input data length
Answers (1)
Hi @Walid,
Yes, you can input short feature vectors to BiLSTM networks, though this requires proper data formatting. BiLSTM layers expect sequence data with dimensions [batchSize, sequenceLength, numFeatures].
For health indicator parameters, reshape your feature vector accordingly:
% Example: 10 health parameters as features healthFeatures = [glucose, bp, cholesterol, ...]; % 1×10 vector % Reshape for BiLSTM: treat as single timestep inputData = reshape(healthFeatures, 1, 1, 10); % [1, 1, 10]
However, consider whether BiLSTM is optimal for non-sequential health indicators. Standard feedforward networks or classification layers may be more appropriate for static feature vectors, as BiLSTM's temporal modeling capabilities are underutilized without sequential dependencies.
References
BiLSTM Layer Documentation: https://www.mathworks.com/help/deeplearning/ref/bilstmlayer.html
Sequence Input Layer: https://www.mathworks.com/help/deeplearning/ref/sequenceinputlayer.html
Classification with LSTM Networks: https://www.mathworks.com/help/deeplearning/ug/classify-sequence-data-using-lstm-networks.html
If your health indicators have temporal relationships or you plan to extend to time-series analysis, BiLSTM remains suitable.
2 Comments
Hi @Walid,
Thanks to @Chuguang Pan for highlighting the MATLAB BiLSTM input format. MATLAB expects CBT (Channel, Batch, Time), unlike PyTorch which uses BTC. This distinction is crucial to avoid subtle bugs when porting ideas between frameworks.
MathWorks: Deep Learning Data Formats https://www.mathworks.com/help/deeplearning/ug/deep-learning-data-formats.html
% Example: 10 health indicators in a 1×10 row vector healthFeatures = [100, 120, 180, 5.5, 72, 95, 80, 1.2, 0.8, 6.4];
% Reshape to CBT: C=10 features, B=1 sample, T=1 timestep X = reshape(healthFeatures(:), [numel(healthFeatures), 1, 1]);
% Inspect the size and values size(X) % -> 10 1 1 disp(X(:,:,1)) % displays the 10 features
Please see attached.

Optional: Deep Learning Toolbox, if you have access to it.
Xdl = dlarray(X, "CBT"); % Channel, Batch, Time
- Explicit labeling of dimensions can help in *custom training loops* or more complex architectures. ([MathWorks: dlarray]( https://www.mathworks.com/help/deeplearning/ref/dlarray.html ))
Practical Notes
1. Static indicators: For single-timestep, non-sequential features, a feed-forward network or classification layers often suffice. BiLSTM is most effective for sequences with T > 1
([MathWorks: Classify Sequence Data Using LSTM Networks] ( <https://www.mathworks.com/help/deeplearning/ug/classify-sequence-data-using-lstm-networks.html> )
2. Multiple samples: To batch multiple single-timestep samples, concatenate along the B dimension:
X = cat(2, X1, X2, ...); % C × B × T
3. This ensures MATLAB BiLSTM layers receive correctly formatted data and avoids subtle dimensional errors.
Categories
Find more on AI for Signals and Images in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!