# TMVA RNN with Variable Input

**URL:** <https://root-forum.cern.ch/t/tmva-rnn-with-variable-input/40688>\
**Category:** TMVA\
**Created:** [July 28, 2020, 6:31am UTC](https://root-forum.cern.ch/t/tmva-rnn-with-variable-input/40688 "2020-07-28T06:31:49Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![afyqazraei](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/afyqazraei/32/29688_2.png) [@afyqazraei](https://root-forum.cern.ch/u/afyqazraei)\
**Post date:** [July 28, 2020, 6:31am UTC](https://root-forum.cern.ch/t/tmva-rnn-with-variable-input/40688/1 "2020-07-28T06:31:49Z")

</div>

Hi, I am fairly new to TMVA but I have explored the tutorials a bit.

I want to ask on what is the proper way to implement RNN with TMVA, such that it can take a variable number of input. In my case, I want to classify between signal and background events, where the number of variables depends on the multiplicity of a physics object. I have gone through the tutorials, but I am still not clear on the proper implementation.

Any guidance would be greatly appreciated!

Thank you.

---

<div class="post-metadata">

**Author:** ![couet](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/couet/32/12037_2.png) [@couet](https://root-forum.cern.ch/u/couet)\
**Post date:** [July 28, 2020, 7:05am UTC](https://root-forum.cern.ch/t/tmva-rnn-with-variable-input/40688/2 "2020-07-28T07:05:13Z")

</div>

I guess @moneta can help you .

---

<div class="post-metadata">

**Author:** ![moneta](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/moneta/32/19423_2.png) [@moneta](https://root-forum.cern.ch/u/moneta)\
**Post date:** [August 11, 2020, 8:57am UTC](https://root-forum.cern.ch/t/tmva-rnn-with-variable-input/40688/3 "2020-08-11T08:57:15Z")

</div>

Hi,

If you need to provide to the RNN a variable input vector, I would pad the input vector with zero for the missing values.  
I would add the zero at the beginning of the sequence as suggested by other studies, for example this paper:

> **[Effects of padding on LSTMs and CNNs](https://arxiv.org/abs/1903.07288)**
>
> Long Short-Term Memory (LSTM) Networks and Convolutional Neural Networks
> (CNN) have become very common and are used in many fields as they were
> effective in solving many problems where the general neural networks were
> inefficient. They were applied...

Best regards

Lorenzo
