| 110 | |
| 111 | |
| 112 | class T5FeedForward(nn.Module): |
| 113 | |
| 114 | def __init__(self, dim, dim_ffn, dropout=0.1): |
| 115 | super(T5FeedForward, self).__init__() |
| 116 | self.dim = dim |
| 117 | self.dim_ffn = dim_ffn |
| 118 | |
| 119 | # layers |
| 120 | self.gate = nn.Sequential(nn.Linear(dim, dim_ffn, bias=False), GELU()) |
| 121 | self.fc1 = nn.Linear(dim, dim_ffn, bias=False) |
| 122 | self.fc2 = nn.Linear(dim_ffn, dim, bias=False) |
| 123 | self.dropout = nn.Dropout(dropout) |
| 124 | |
| 125 | def forward(self, x): |
| 126 | x = self.fc1(x) * self.gate(x) |
| 127 | x = self.dropout(x) |
| 128 | x = self.fc2(x) |
| 129 | x = self.dropout(x) |
| 130 | return x |
| 131 | |
| 132 | |
| 133 | class T5SelfAttention(nn.Module): |