Combined dropout for tuples (s, V). Takes tuples (s, V) as input and as output.
| 178 | |
| 179 | |
| 180 | class Dropout(nn.Module): |
| 181 | ''' |
| 182 | Combined dropout for tuples (s, V). |
| 183 | Takes tuples (s, V) as input and as output. |
| 184 | ''' |
| 185 | def __init__(self, drop_rate): |
| 186 | super().__init__() |
| 187 | self.sdropout = nn.Dropout(drop_rate) |
| 188 | self.vdropout = _VDropout(drop_rate) |
| 189 | |
| 190 | def forward(self, x): |
| 191 | ''' |
| 192 | :param x: tuple (s, V) of `torch.Tensor`, |
| 193 | or single `torch.Tensor` |
| 194 | (will be assumed to be scalar channels) |
| 195 | ''' |
| 196 | if type(x) is torch.Tensor: |
| 197 | return self.sdropout(x) |
| 198 | s, v = x |
| 199 | return self.sdropout(s), self.vdropout(v) |
| 200 | |
| 201 | |
| 202 | class GVPLayerNorm(nn.Module): |