【问题标题】:Unable to add Embedding layer to a siamese network using keras无法使用 keras 将嵌入层添加到连体网络
【发布时间】:2016-04-10 00:11:02
【问题描述】:

我正在尝试更改连体网络的示例代码并添加一个嵌入层,如下所示:

data_dim = 16
timesteps = 8
nb_classes = 10

encoder = Sequential()
encoder.add(Embedding(data_dim, 4, input_length=timesteps))
encoder.add(LSTM(32))

model = Graph()
model.add_input(name='input_a', input_shape=(timesteps,))
model.add_input(name='input_b', input_shape=(timesteps,))
model.add_shared_node(encoder, 
                      name='shared_encoder', 
                      inputs=['input_a', 'input_b'],
                      merge_mode='concat')
model.add_node(Dense(64, activation='relu'), name='fc1', input='shared_encoder')
model.add_node(Dense(3, activation='softmax'), name='output', input='fc1', 
               create_output=True)

model.compile(optimizer='adam', loss={'output': 'categorical_crossentropy'})

紧跟他们文档中的last example

很遗憾,我不断收到错误消息:

TypeError: DataType float32 for attr 'Tindices' not in list of allowed values: int32, int64

谁能帮忙?

【问题讨论】:

标签: python neural-network conv-neural-network keras recurrent-neural-network


【解决方案1】:
model.add_input(name='input_a', input_shape=(timesteps,), dtype='int')
model.add_input(name='input_b', input_shape=(timesteps,), dtype='int')

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2022-06-13
    • 1970-01-01
    • 1970-01-01
    • 2021-12-12
    相关资源
    最近更新 更多