Keras TimeDistributed Conv1D Error

末鹿安然 提交于 2019-12-06 10:36:28

Recommended solution: There is no need to use TimeDistributed in this case. You can fix the issue with following piece of code:

output = Convolution1D(filters=128, kernel_size=4, activation='relu')(emb_output)

Just in case, if you like to use TimeDistributed you can do something like:

output = TimeDistributed(Dense(100,activation='relu'))(emb_output)

Not recommended: According to docs:

This wrapper applies a layer to every temporal slice of an input.

The input to the TimeDistributed is something like batch_size * seq_len * emb_size. When Conv1D apply to each sequence, it needs 2 dimensions but found only one.

You can fix the problem by adding one dimension to your sequences:

TimeDistributed(Conv1D(100, 1))(keras.backend.reshape(emb, [-1, sequence_len, embeding_dim, 1]))
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!