Advertisement
msaidov

Residual Connection Example

Feb 23rd, 2020
142
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.50 KB | None | 0 0
  1. class SublayerConnection(nn.Module):
  2. """
  3. A residual connection followed by a layer norm.
  4. Note for code simplicity the norm is first as opposed to last.
  5. """
  6. def __init__(self, size, dropout):
  7. super(SublayerConnection, self).__init__()
  8. self.norm = LayerNorm(size)
  9. self.dropout = nn.Dropout(dropout)
  10.  
  11. def forward(self, x, sublayer):
  12. "Apply residual connection to any sublayer with the same size."
  13. return x + self.dropout(sublayer(self.norm(x)))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement