作者热门文章
- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
背景:
如果我没记错的话,在训练网络时,我们前馈对每一层执行 sigmoid(sum(W*x)),然后在反向传播中计算误差和增量(变化),然后计算梯度和更新权重。
假设我们在其中一层没有激活,keras 如何计算梯度?它只是取 sum(W*x)*next_layer_delta*weights
的值吗?获取当前层的增量并用它来计算梯度?</p>
代码:
我编写了这段代码来创建 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 如何优化权重?在隐藏层中没有激活函数会产生什么影响?
最佳答案
通常,对于某些回归问题,线性激活函数仅应用于最后一层。当然,您仍然可以将其用作多层网络中的隐藏层。但是,如果您将多个线性层彼此相邻堆叠,它将充当 1 个线性层,因此您无法用它构建大型模型。线性激活函数的局部梯度=1,因此,完整节点的局部梯度就是权重本身。
关于python - Keras 如何优化没有激活的层上的权重?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51623082/
我是一名优秀的程序员,十分优秀!