inputs_bedding = Input(shape=(it.shape))
embedding = Embedding(9488, 512, trainable=False)(inputs_bedding)


keras嵌入层中没有name参数。如何设置图层名称?

最佳答案

您可以像其他任何图层一样设置嵌入图层的名称。

from keras.layers import Embedding, Input
from keras import Model


inputs_bedding = Input(shape=(32,))
embedding = Embedding(9488, 512, trainable=False, name="test")(inputs_bedding)

model = Model(inputs=inputs_bedding, outputs=embedding)


model.summary()为您提供:

_________________________________________________________________
Layer (type)                 Output Shape              Param #
=================================================================
input_3 (InputLayer)         (None, 32)                0
_________________________________________________________________
test (Embedding)             (None, 32, 512)           4857856
=================================================================
Total params: 4,857,856
Trainable params: 0
Non-trainable params: 4,857,856
_________________________________________________________________

10-08 17:21