How to input mask value to Convolution1D layer

后端 未结 2 1972
一整个雨季
一整个雨季 2021-02-07 16:27

I need to feed variable length sequences into my model.

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

When I set mask_zero =

2条回答
  •  我在风中等你
    2021-02-07 17:15

    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=[...])
    

提交回复
热议问题