参考記事
https://blog.csdn.net/weixin_39228381/article/details/107896863
https://blog.csdn.net/weixin_39228381/article/details/107939602
-
BatchNormは、バッチ方向(各バッチの列方向)で正規化されます。
import torch.nn as nn import torch if __name__ == '__main__': norm = nn.BatchNorm1d(4, affine=False) inputs = torch.FloatTensor([[1,2,3,4], [5,6,7,8]]) print(inputs) output = norm(inputs) print(output) ''' tensor([[-1.0000, -1.0000, -1.0000, -1.0000], [ 1.0000, 1.0000, 1.0000, 1.0000]]) '''
-
LayerNormは、各バッチの行方向で正規化されます。
import torch.nn as nn import torch if __name__ == '__main__': norm = nn.LayerNorm(4) inputs = torch.FloatTensor([[1,2,3,4], [5,6,7,8]]) output = norm(inputs) print(output) ''' tensor([[-1.3416, -0.4472, 0.4472, 1.3416], [-1.3416, -0.4472, 0.4472, 1.3416]], grad_fn=<NativeLayerNormBackward>) '''
- 詳細な計算プロセスについては、上記のリンクを参照してください。計算プロセスでは、サンプル分散のバイアス推定とバイアス推定の違いに注意する必要があります。バイアスとバイアス
の違いは、バイアスの分母がN-1であるということです。バイアスされた分母はNです。
- 詳細な計算プロセスについては、上記のリンクを参照してください。計算プロセスでは、サンプル分散のバイアス推定とバイアス推定の違いに注意する必要があります。バイアスとバイアス