Highway Network主要解决的问题是,网络深度加深,梯度信息回流受阻造成网络训练困难的问题。
假设定义一个非线性变换为,定义门函数
,携带函数
。对于门函数取极端的情况0/1会有
,而对应的门函数
使用sigmoid函数
,则极端的情况不会出现。
一个网络的输出最终变为。
具体的代码实现为:
def highway(input_, size, num_layers=1, bias=-2.0, f=tf.nn.relu, scope='Highway'):
"""Highway Network (cf. http://arxiv.org/abs/1505.00387).
t = sigmoid(Wy + b)
z = t * g(Wy + b) + (1 - t) * y
where g is nonlinearity, t is transform gate, and (1 - t) is carry gate.
"""
with tf.variable_scope(scope):
for idx in range(num_layers):
g = f(linear(input_, size, scope='highway_lin_%d' % idx))
t = tf.sigmoid(linear(input_, size, scope='highway_gate_%d' % idx) + bias)
output = t * g + (1. - t) * input_
input_ = output
return output