Spaces:
Runtime error
Runtime error
Download bert_pytorch/model/utils/sublayer.py from MukeshKapoor25/logbert_processor: direct link, hf CLI and curl.
- Browser
- Download file 565 Bytes
-
https://huggingface.co/spaces/MukeshKapoor25/logbert_processor/resolve/main/bert_pytorch/model/utils/sublayer.py
- Command line
-
hf download hf://spaces/MukeshKapoor25/logbert_processor/bert_pytorch/model/utils/sublayer.py
-
curl -L -o sublayer.py https://huggingface.co/spaces/MukeshKapoor25/logbert_processor/resolve/main/bert_pytorch/model/utils/sublayer.py
565 Bytes
| import torch.nn as nn | |
| from .layer_norm import LayerNorm | |
| class SublayerConnection(nn.Module): | |
| """ | |
| A residual connection followed by a layer norm. | |
| Note for code simplicity the norm is first as opposed to last. | |
| """ | |
| def __init__(self, size, dropout): | |
| super(SublayerConnection, self).__init__() | |
| self.norm = LayerNorm(size) | |
| self.dropout = nn.Dropout(dropout) | |
| def forward(self, x, sublayer): | |
| "Apply residual connection to any sublayer with the same size." | |
| return x + self.dropout(sublayer(self.norm(x))) | |