Download modules/weights.py from MatchLab/backup: direct link, hf CLI and curl.
- Browser
- Download file 813 Bytes
-
https://huggingface.co/datasets/MatchLab/backup/resolve/main/modules/weights.py
- Command line
-
hf download hf://datasets/MatchLab/backup/modules/weights.py
-
curl -L -o weights.py https://huggingface.co/datasets/MatchLab/backup/resolve/main/modules/weights.py
813 Bytes
| import torch.nn as nn | |
| def _init_weights_bert(module, std=0.02): | |
| """ | |
| Huggingface transformer weight initialization, | |
| most commonly for bert initialization | |
| """ | |
| if isinstance(module, nn.Linear): | |
| # Slightly different from the TF version which uses truncated_normal for initialization | |
| # cf https://github.com/pytorch/pytorch/pull/5617 | |
| module.weight.data.normal_(mean=0.0, std=std) | |
| if module.bias is not None: | |
| module.bias.data.zero_() | |
| elif isinstance(module, nn.Embedding): | |
| module.weight.data.normal_(mean=0.0, std=std) | |
| if module.padding_idx is not None: | |
| module.weight.data[module.padding_idx].zero_() | |
| elif isinstance(module, nn.LayerNorm): | |
| module.bias.data.zero_() | |
| module.weight.data.fill_(1.0) |