:param x: tuple (s, V) of `torch.Tensor`, or (if vectors_in is 0), a single `torch.Tensor` :return: tuple (s, V) of `torch.Tensor`, or (if vectors_out is 0), a single `torch.Tensor`
(self, x)
| 118 | self.scalar_act, self.vector_act = activations |
| 119 | |
| 120 | def forward(self, x): |
| 121 | ''' |
| 122 | :param x: tuple (s, V) of `torch.Tensor`, |
| 123 | or (if vectors_in is 0), a single `torch.Tensor` |
| 124 | :return: tuple (s, V) of `torch.Tensor`, |
| 125 | or (if vectors_out is 0), a single `torch.Tensor` |
| 126 | ''' |
| 127 | if self.input_dim_v: |
| 128 | s, v = x |
| 129 | v = torch.transpose(v, -1, -2) |
| 130 | vh = self.wh(v) |
| 131 | vn = _norm_no_nan(vh, axis=-2) |
| 132 | s = self.ws(torch.cat([s, vn], -1)) |
| 133 | if self.output_dim_v: |
| 134 | v = self.wv(vh) |
| 135 | v = torch.transpose(v, -1, -2) |
| 136 | if self.vector_gate: |
| 137 | if self.vector_act: |
| 138 | gate = self.wsv(self.vector_act(s)) |
| 139 | else: |
| 140 | gate = self.wsv(s) |
| 141 | v = v * torch.sigmoid(gate).unsqueeze(-1) |
| 142 | elif self.vector_act: |
| 143 | v = v * self.vector_act( |
| 144 | _norm_no_nan(v, axis=-1, keepdims=True)) |
| 145 | else: |
| 146 | s = self.ws(x) |
| 147 | if self.output_dim_v: |
| 148 | v = torch.zeros(s.shape[0], self.output_dim_v, 3, |
| 149 | device=self.device) |
| 150 | if self.scalar_act: |
| 151 | s = self.scalar_act(s) |
| 152 | |
| 153 | return (s, v) if self.output_dim_v else s |
| 154 | |
| 155 | |
| 156 | class _VDropout(nn.Module): |
nothing calls this directly
no test coverage detected