【问题标题】:What are the shapes of beta and gamma parameters in layer normalization layer?层归一化层中 beta 和 gamma 参数的形状是什么?
【发布时间】:2019-11-03 23:31:47
【问题描述】:

在层标准化中,我们计算整个输入层的均值和方差(而不是我们在批量标准化中所做的跨批次)。然后根据均值和方差对输入层进行归一化,然后返回gamma乘以归一化层加上beta。

我的问题是,gamma 和 beta 标量的形状分别是 (1, 1) 和 (1, 1) 还是它们的形状分别是 (1, number of hidden units) 和 (1, number of hidden units)。

这是我实现层标准化的方法,对吗!

def layernorm(layer, gamma, beta):
    mean = np.mean(layer, axis = 1, keepdims = True)
    variance = np.mean((layer - mean) ** 2, axis=1, keepdims = True)
    layer_hat = (layer - mean) * 1.0 / np.sqrt(variance + 1e-8)
    outpus = gamma * layer_hat + beta
    return outpus

其中 gamma 和 beta 定义如下:

gamma = np.random.normal(1, 128)
beta = np.random.normal(1, 128)

【问题讨论】:

    标签: machine-learning neural-network deep-learning


    【解决方案1】:

    根据Tensorflow's implementation,假设输入的形状为[B, rest],gamma 和beta 的形状为restrest 可以是 (h, ) 用于 2 维输入或 (h, w, c) 用于 4 维输入。

    【讨论】:

      猜你喜欢
      • 2020-10-23
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-08-28
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多