LayerNorm(Layer Normalization, 层归一化)是一种在深度神经网络中常用的技术,用于稳定训练过程。它是由Jimmy Ba和Geoffrey Hinton在2016年提出的,旨在解决深度网络训练中的梯度消失和梯度爆炸问题,以及使得网络能够更有效地学习更高阶的特征。
原理

源码
import torch
import torch.nn as nn
import torch.nn.functional as F
class LayerNorm(nn.Module):
def __init__(self, normalized_shape=5, eps=1e-6, data_format="channels_last"):
super(LayerNorm,self).__init__()
self.weight=nn.Parameter(torch.ones(normalized_shape)) # 缩放因子
self.bias=nn.Parameter(torch.zeros(normalized_shape)) # 偏移量
self.eps=eps # 为了防止分母等于0,分母加了一个很小的大于0的值
self.data_format=data_format
if self.data_format not in ["channels_last", "channels_first"]:
raise NotImplementedError
self.normalized_shape=(normalized_shape,)
def forward(self,x)

最低0.47元/天 解锁文章
4万+

被折叠的 条评论
为什么被折叠?



