Spaces:
Sleeping
Sleeping
Download models/bert_modules/utils/sublayer.py from mramazan/AnimeRecBERT: direct link, hf CLI and curl.
- Browser
- Download file 565 Bytes
-
https://huggingface.co/spaces/mramazan/AnimeRecBERT/resolve/main/models/bert_modules/utils/sublayer.py
- Command line
-
hf download hf://spaces/mramazan/AnimeRecBERT/models/bert_modules/utils/sublayer.py
-
curl -L -o sublayer.py https://huggingface.co/spaces/mramazan/AnimeRecBERT/resolve/main/models/bert_modules/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))) | |