如何在keras中扩展嵌入层的输出
How to expand output of embedding layer in keras
我有以下网络:
model = Sequential()
model.add(Embedding(400000, 100, weights=[emb], input_length=12, trainable=False))
model.add(Conv2D(256,(2,2),activation='relu'))
嵌入层的输出形状为 (batchSize, 12, 100)。 conv2D 层需要输入形状 (batchSize, filter, 12, 100),我得到以下错误:
Input 0 is incompatible with layer conv2d_1: expected ndim=4, found ndim=3
那么,如何扩展嵌入层的输出以使其适合 Conv2D 层?
我使用 Keras 和 Tensorflow 作为后端。
添加重塑图层应该是正确的方法https://keras.io/layers/core/#reshape
看具体情况 Conv1D cold although work.
我设法使用以下代码添加了另一个维度:
model = Sequential()
model.add(Embedding(400000, 100, weights=[emb], input_length=12, trainable=False))
model.add(Lambda(lambda x: expand_dims(x, 3)))
model.add(Conv2D(256,(2,2),activation='relu'))
我有以下网络:
model = Sequential()
model.add(Embedding(400000, 100, weights=[emb], input_length=12, trainable=False))
model.add(Conv2D(256,(2,2),activation='relu'))
嵌入层的输出形状为 (batchSize, 12, 100)。 conv2D 层需要输入形状 (batchSize, filter, 12, 100),我得到以下错误:
Input 0 is incompatible with layer conv2d_1: expected ndim=4, found ndim=3
那么,如何扩展嵌入层的输出以使其适合 Conv2D 层?
我使用 Keras 和 Tensorflow 作为后端。
添加重塑图层应该是正确的方法https://keras.io/layers/core/#reshape 看具体情况 Conv1D cold although work.
我设法使用以下代码添加了另一个维度:
model = Sequential()
model.add(Embedding(400000, 100, weights=[emb], input_length=12, trainable=False))
model.add(Lambda(lambda x: expand_dims(x, 3)))
model.add(Conv2D(256,(2,2),activation='relu'))