    def init_weights(self, layer):
        """ Initialization hook """
        """Initialize the weights"""
        if isinstance(layer, nn.Linear):
            # Slightly different from the TF version which uses truncated_normal for initialization
            # cf https://github.com/pytorch/pytorch/pull/5617
            layer.weight.data.normal_(mean=0.0, std=1.0)
            if layer.bias is not None:
                layer.bias.data.zero_()
        elif isinstance(layer, nn.Embedding):
            layer.weight.data.normal_(mean=0.0, std=1.0)
            if layer.padding_idx is not None:
                layer.weight.data[layer.padding_idx].zero_()
        elif isinstance(layer, nn.LayerNorm):
            layer.bias.data.zero_()
            layer.weight.data.fill_(1.0)
Initialization hook
ptstructure/vqa/pytorchnlp/transformers/layoutlm/modeling.py