BILSTM input data length

조회 수: 3 (최근 30일)
Walid
Walid 2025년 9월 4일
댓글: Umar 2025년 9월 6일
Can I input a short length features vector as input data to BILSTM network (contrary to sequence data) ? this vector can include a parameters values of health indicators

답변 (1개)

Umar
Umar 2025년 9월 5일
편집: Umar 2025년 9월 5일

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
Chuguang Pan
Chuguang Pan 2025년 9월 5일
The desired data format of bilstmLayer should be "CBT"=[Channel, Batchsize, SequenceLength], not "BTC". The "BTC" is PyTorch Tensor data format.
Umar
Umar 2025년 9월 6일

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

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.

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 AI for Signals and Images에 대해 자세히 알아보기

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by