| 121 | |
| 122 | |
| 123 | class T5FeedForward(nn.Module): |
| 124 | |
| 125 | def __init__(self, dim, dim_ffn, dropout=0.1): |
| 126 | super(T5FeedForward, self).__init__() |
| 127 | self.dim = dim |
| 128 | self.dim_ffn = dim_ffn |
| 129 | |
| 130 | # layers |
| 131 | self.gate = nn.Sequential(nn.Linear(dim, dim_ffn, bias=False), GELU()) |
| 132 | self.fc1 = nn.Linear(dim, dim_ffn, bias=False) |
| 133 | self.fc2 = nn.Linear(dim_ffn, dim, bias=False) |
| 134 | self.dropout = nn.Dropout(dropout) |
| 135 | |
| 136 | def forward(self, x): |
| 137 | x = self.fc1(x) * self.gate(x) |
| 138 | x = self.dropout(x) |
| 139 | x = self.fc2(x) |
| 140 | x = self.dropout(x) |
| 141 | return x |
| 142 | |
| 143 | |
| 144 | class T5SelfAttention(nn.Module): |