How to input mask value to Convolution1D layer

你说的曾经没有我的故事 提交于 2020-01-02 02:26:26

问题


I need to feed variable length sequences into my model.

My model is Embedding + LSTM + Conv1d + Maxpooling + softmax.

When I set mask_zero = True in Embedding, I fail to compile at Conv1d.

How can I input mask value in Conv1d or is there another solution?


回答1:


Conv1D layer does not support masking at this time. Here is an open issue on the keras repo.

Depending on the task you might be able to get away with embedding the mask_value just like the other values in the sequence and apply global pooling (as you're doing now).




回答2:


The Masking layer expects every downstream layer to support masking, which is not the case of the Conv1D layer. Fortunately, there is another way to apply masking, using the Functional API:

inputs = Input(...)
mask = Masking().compute_mask(inputs) # <= Compute the mask
embed = Embedding(...)(inputs)
lstm = LSTM(...)(embed, mask=mask) # <= Apply the mask
conv = Conv1D(...)(lstm)
...
model = Model(inputs=[inputs], outputs=[...])


来源:https://stackoverflow.com/questions/43392693/how-to-input-mask-value-to-convolution1d-layer

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!