【问题标题】:LSTM with attention. TypeError: 'module' object is not callable. What's wrong with my implementation?关注 LSTM。 TypeError:“模块”对象不可调用。我的实施有什么问题?
【发布时间】:2020-10-24 09:10:55
【问题描述】:

1270个时间步长,每个时间步长为36; 10节课

max_length = 1270
step_dim = 36
_input = Input(shape=[max_length, step_dim])

activations = LSTM(128, return_sequences=True)(_input)

# compute importance for each step
attention = Dense(1, activation='tanh')(activations)
attention = Flatten()(attention)
attention = Activation('softmax')(attention)
attention = RepeatVector(1270)(attention)
attention = Permute([2, 1])(attention)


sent_representation = merge([activations, attention], mode='mul')
sent_representation = Lambda(lambda xin: K.sum(xin, axis=-2), output_shape=(64,))(sent_representation)

probabilities = Dense(10, activation='softmax')(sent_representation)

给予:

TypeError: 'module' 对象不可调用

这是什么意思,我该如何解决?

【问题讨论】:

  • 这是什么合并()。从您导入它的地方。请提供完整的脚本以及您在哪一行得到错误
  • @devSpartan merge() 是一个标准的 Keras 层。错误是指 merge() 行。
  • 对不起老兄,我没有找到名为merge的keras层。还有其他合并层,例如添加、连接、点、最小值等
  • @devSpartan 是的,现在使用乘法层。并将 RepeatVector() 的输入更改为 128。现在,它可以工作了。

标签: python keras deep-learning lstm attention-model


【解决方案1】:

没有更多的“合并”层,如您所见here。你应该改用Concatenate

这里有一个有用的guide,关于如何将旧的merge 代码转换为可运行的 Keras 代码。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2017-06-17
    • 2014-09-21
    • 2011-05-30
    • 2021-11-22
    相关资源
    最近更新 更多