-
Notifications
You must be signed in to change notification settings - Fork 0
/
core_res_block.py
37 lines (25 loc) · 929 Bytes
/
core_res_block.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
# Copyright (c) 2021 Cognizant Digital Business, Cognizant AI Labs
# Issued under this Academic Public License: github.com/cognizant-ai-labs/tom-release/LICENSE.
"""
Class for skipinit residual blocks without FiLM, implemented using
Conv1D in order to maintain TOM implementation pattern.
"""
import torch
import torch.nn as nn
class CoreResBlock(nn.Module):
def __init__(self,
hidden_size,
dropout=0.0):
super(CoreResBlock, self).__init__()
self.conv_layer = nn.Conv1d(hidden_size,
hidden_size,
1)
self.dropout_layer = nn.Dropout(dropout)
self.alpha = nn.Parameter(torch.zeros(1))
def forward(self, x):
identity = x
x = torch.relu(x)
x = self.conv_layer(x)
x = self.dropout_layer(x)
x = self.alpha * x
return identity + x