MCPcopy Create free account
hub / github.com/AkaliKong/MiniOneRec / PositionwiseFeedForward

Class PositionwiseFeedForward

SASRecModules_ori.py:7–22  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

5
6
7class PositionwiseFeedForward(nn.Module):
8 def __init__(self, d_in, d_hid, dropout=0.1):
9 super().__init__()
10 self.w_1 = nn.Conv1d(d_in, d_hid, 1)
11 self.w_2 = nn.Conv1d(d_hid, d_in, 1)
12 self.layer_norm = nn.LayerNorm(d_in)
13 self.dropout = nn.Dropout(dropout)
14
15 def forward(self, x):
16 residual = x
17 output = x.transpose(1, 2)
18 output = self.w_2(F.relu(self.w_1(output)))
19 output = output.transpose(1, 2)
20 output = self.dropout(output)
21 output = self.layer_norm(output + residual)
22 return output
23
24
25

Callers 1

__init__Method · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected