hycis / bidirectional_RNN

bidirectional lstm
MIT License
153 stars 52 forks source link

Masking? #7

Closed adamklec closed 5 years ago

adamklec commented 8 years ago

Hello. My sequences are of varying length so many of them are 0 padded. From what I understand the correct way to treat 0 padded sequences is with mask_zero=True on an embedding layer.

text_model = Sequential() text_model.add(Embedding(max_features, 64, mask_zero=True)) text_model.add(BiDirectionLSTM(64, 64, return_sequences=True))

The above code raises the following exception: "Exception: Cannot connect non-masking layer to layer with masked output"

Do you have any plans to support masking? It seems like an important feature for dealing with sequences.

hycis commented 8 years ago

that's definitely an important feature, I will look into it and see if i can add that in or if you are interested you can also try to look into adding that feature.

philipperemy commented 8 years ago

When you use mask_zero = True, you must use it on ALL your next layers.

BiDirectionLSTM(64, 64, return_sequences=True, mask_zero=True)

should work!