-
Notifications
You must be signed in to change notification settings - Fork 100
Expand file tree
/
Copy pathstructure.py
More file actions
23 lines (21 loc) · 747 Bytes
/
structure.py
File metadata and controls
23 lines (21 loc) · 747 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
import numpy as np
import torch
class PointWiseFeedForward(torch.nn.Module):
def __init__(self, hidden_units, dropout_rate,activation='relu'):
super(PointWiseFeedForward, self).__init__()
act = None
if activation == 'relu':
act = torch.nn.ReLU()
elif activation == 'gelu':
act = torch.nn.GELU()
self.pwff = torch.nn.Sequential(
torch.nn.Linear(hidden_units, hidden_units),
#torch.nn.Dropout(p=dropout_rate),
act,
torch.nn.Linear(hidden_units, hidden_units),
torch.nn.Dropout(p=dropout_rate)
)
def forward(self, inputs):
outputs = self.pwff(inputs)
outputs += inputs
return outputs