# How to mask a particular value (-1) in LSTM for representing missing values

**URL:** https://community.konduit.ai/t/how-to-mask-a-particular-value-1-in-lstm-for-representing-missing-values/594
**Category:** DL4J
**Created:** [June 8, 2020, 4:18am UTC](https://community.konduit.ai/t/how-to-mask-a-particular-value-1-in-lstm-for-representing-missing-values/594 "2020-06-08T04:18:23Z")
**Posts on this page:** 3
**Page:** 1

<div class="post-metadata">

### Author: ![gopikrishna](https://avatars.discourse-cdn.com/v4/letter/g/dbc845/32.png) [@gopikrishna](https://community.konduit.ai/u/gopikrishna)
#### Post date: [June 8, 2020, 4:18am UTC](https://community.konduit.ai/t/how-to-mask-a-particular-value-1-in-lstm-for-representing-missing-values/594/1 "2020-06-08T04:18:23Z")

</div>

Hi, I am working with LSTM that uses irregularly spaced data and need to mask the missing values (represented by -1). In keras it is possible by  
model.add(Masking(mask\_value=-1, input\_shape=(n\_steps, n\_features)))  
Can I please know how this can be done?

---

<div class="post-metadata">

### Author: ![treo](https://yyz1.discourse-cdn.com/flex035/user_avatar/community.konduit.ai/treo/32/47_2.png) [@treo](https://community.konduit.ai/u/treo)
#### Post date: [June 8, 2020, 8:18am UTC](https://community.konduit.ai/t/how-to-mask-a-particular-value-1-in-lstm-for-representing-missing-values/594/2 "2020-06-08T08:18:56Z")

</div>

In DL4J it is done with explicit masking tensors. It is documented quite extensively here:  
[https://deeplearning4j.konduit.ai/models/recurrent#masking-one-to-many-many-to-one-and-sequence-classification](https://deeplearning4j.konduit.ai/models/recurrent#masking-one-to-many-many-to-one-and-sequence-classification)

As far as I’m aware of, we don’t have a direct input masking by value implementation that makes it easier to use, but I guess that it shouldn’t be too hard to implement it yourself as a [DataSetPreProcessor](https://deeplearning4j.org/api/latest/org/nd4j/linalg/dataset/api/DataSetPreProcessor.html).

---

<div class="post-metadata">

### Author: ![Foodyborris](https://avatars.discourse-cdn.com/v4/letter/f/9fc29f/32.png) [@Foodyborris](https://community.konduit.ai/u/Foodyborris)
#### Post date: [June 22, 2020, 5:56pm UTC](https://community.konduit.ai/t/how-to-mask-a-particular-value-1-in-lstm-for-representing-missing-values/594/3 "2020-06-22T17:56:16Z")

</div>

I’ve successfully used these masking capabilities with an LSTM. The main use always takes input, labels, inputsmask, labelsmask. Sometimes the input is masked and sometimes the output is masked (when that particular output can’t be trained for, for example). Can be slightly tedious remembering what each dimension of your arrays are, but slicing them as you get more specific really helps (eg when calculating masks for just one set of data within an MBS).

Good luck!
