MCPcopy Create free account
hub / github.com/dangf15/THLNet / forward

Method forward

nets/dfnet_block.py:68–89  ·  view source on GitHub ↗

r"""Pass the input through the encoder layer. Args: src: the sequnce to the encoder layer (required). src_mask: the mask for the src sequence (optional). src_key_padding_mask: the mask for the src keys per batch (optional). Shape:

(self, src, src_mask=None, src_key_padding_mask=None)

Source from the content-addressed store, hash-verified

66 super(TransformerEncoderLayer, self).__setstate__(state)
67
68 def forward(self, src, src_mask=None, src_key_padding_mask=None):
69 # type: (Tensor, Optional[Tensor], Optional[Tensor]) -> Tensor
70 r"""Pass the input through the encoder layer.
71 Args:
72 src: the sequnce to the encoder layer (required).
73 src_mask: the mask for the src sequence (optional).
74 src_key_padding_mask: the mask for the src keys per batch (optional).
75 Shape:
76 see the docs in Transformer class.
77 """
78 if self.bidirectional:
79 src2 = self.self_attn(src, src, src, attn_mask=src_mask,
80 key_padding_mask=src_key_padding_mask)[0]
81 src = src + self.dropout1(src2)
82
83 src = self.norm1(src)
84 out, h_n = self.gru(src)
85 del h_n
86 src2 = self.linear2(self.dropout(self.activation(out)))
87 src = src + self.dropout2(src2)
88 src = self.norm2(src)
89 return src
90
91
92def _get_clones(module, N):

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected