【发布时间】:2018-08-01 11:48:49
【问题描述】:
背景:
如果我没记错的话,在训练网络时,我们前馈对每一层执行 sigmoid(sum(W*x)),然后在反向传播中,我们计算误差和增量(变化),然后我们计算梯度和更新权重。
假设我们在其中一个层上没有激活,keras 如何计算梯度?是否只需要 sum(W*x)*next_layer_delta*weights 的值来获取当前层的增量并使用它来计算梯度?
代码:
我编写了这段代码来创建 word2vec 模型(skip-gram):
model = Sequential()
model.add(Dense(2, input_dim=len(tokens_enc)))#what does it mean for it not to have an activation here? This makes it linear because there is no non-linear function such as tanh!
model.add(Dense(len(tokens_enc), activation='softmax'))
model.compile(loss='categorical_crossentropy', optimizer='sgd', metrics=['accuracy'])
# Fit the model
model.fit(X, y, epochs=20000)
输入和输出是1个热向量。
问题:在这种情况下,keras 如何优化权重?在隐藏层中没有激活函数意味着什么?
【问题讨论】:
标签: python keras activation-function