Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add ReLU to dense layers #160

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 18 additions & 9 deletions src/models/neural_networks/ealstm.py
Original file line number Diff line number Diff line change
Expand Up @@ -254,22 +254,31 @@ def __init__(
if dense_features[-1] != 1:
dense_features.append(1)

self.dense_layers = nn.ModuleList(
[
# add linear layer with nonlinear activation functions
dense_layers = []
for i in range(1, len(dense_features)):
dense_layers.append(
nn.Linear(
in_features=dense_features[i - 1], out_features=dense_features[i]
# in = size of previous dense layer
in_features=dense_features[i - 1],
# out = size of current dense layer
out_features=dense_features[i],
)
for i in range(1, len(dense_features))
]
)
)
if i < len(dense_features) - 1:
# add a ReLU to all layers except the final layer
dense_layers.append(nn.ReLU())

self.dense_layers = nn.ModuleList(dense_layers)

self.initialize_weights()

def initialize_weights(self):

for dense_layer in self.dense_layers:
nn.init.kaiming_uniform_(dense_layer.weight.data)
nn.init.constant_(dense_layer.bias.data, 0)
# initialise weights for all linear layers
if not isinstance(dense_layer, nn.ReLU):
nn.init.kaiming_uniform_(dense_layer.weight.data)
nn.init.constant_(dense_layer.bias.data, 0)

def forward(
self,
Expand Down