MCPcopy Create free account
hub / github.com/awslabs/gap-text2sql / SublayerConnection

Class SublayerConnection

rat-sql-gap/seq2struct/models/transformer.py:282–294  ·  view source on GitHub ↗

A residual connection followed by a layer norm. Note for code simplicity the norm is first as opposed to last.

Source from the content-addressed store, hash-verified

280
281# Adapted from The Annotated Transformer
282class SublayerConnection(nn.Module):
283 """
284 A residual connection followed by a layer norm.
285 Note for code simplicity the norm is first as opposed to last.
286 """
287 def __init__(self, size, dropout):
288 super(SublayerConnection, self).__init__()
289 self.norm = nn.LayerNorm(size)
290 self.dropout = nn.Dropout(dropout)
291
292 def forward(self, x, sublayer):
293 "Apply residual connection to any sublayer with the same size."
294 return x + self.dropout(sublayer(self.norm(x)))
295
296
297# Adapted from The Annotated Transformer

Callers 1

__init__Method · 0.70

Calls

no outgoing calls

Tested by

no test coverage detected