【问题标题】:how to add tanh to one embedding layer in keras如何将tanh添加到keras中的一个嵌入层
【发布时间】:2018-12-17 07:01:31
【问题描述】:

我想用 keras 功能 api 在嵌入层中添加一个 tanh 层:

x=layers.Embedding(vocab_size, 8, input_length=max_length)(input)
output=keras.activations.tanh(x)

model = Model(inputs=input, outputs=output)
model.compile(optimizer='rmsprop',loss='categorical_crossentropy',metrics=['accuracy'])
model.fit(data, labels)

但系统告诉我必须使用 keras 层,而不是张量。我搜索了很多 keras 教程。解决这个问题的方法只有一种:

model.add(Activation('tanh'))

但它是我不想使用的顺序模型。有没有一些方法可以用函数式 api 解决这个问题?

【问题讨论】:

    标签: python tensorflow machine-learning keras


    【解决方案1】:

    使用函数式 api 几乎与顺序模型相同:

    output = Activation('tanh')(x)
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2020-11-13
      • 1970-01-01
      • 2018-09-23
      • 1970-01-01
      • 2019-03-21
      • 2023-03-08
      • 2021-07-28
      相关资源
      最近更新 更多