File size: 753 Bytes
0144345
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
import torch.nn as nn


class HeadProjectorResidual(nn.Module):
    def __init__(
        self,
        input_embedding_dim: int = 1000,
        output_embedding_dim: int = 512,
        dropout: float = 0.4
    ):
        super().__init__()
        self.projection = nn.Linear(input_embedding_dim, output_embedding_dim)
        self.gelu = nn.GELU()
        self.fc = nn.Linear(output_embedding_dim, output_embedding_dim)
        self.dropout = nn.Dropout(dropout)
        self.layer_norm = nn.LayerNorm(output_embedding_dim)
    
    def forward(self, x):
        projected = self.projection(x)
        x = self.gelu(projected)
        x = self.fc(x)
        x = self.dropout(x)
        x = x + projected
        x = self.layer_norm(x)
        return x