| 100 | (vector_act will be used as sigma^+ in vector gating if `True`) |
| 101 | ''' |
| 102 | def __init__(self, in_dims, out_dims, h_dim=None, |
| 103 | activations=(F.relu, torch.sigmoid), vector_gate=False): |
| 104 | super().__init__() |
| 105 | self.input_dim_s, self.input_dim_v = in_dims |
| 106 | self.output_dim_s, self.output_dim_v = out_dims |
| 107 | self.vector_gate = vector_gate |
| 108 | if self.input_dim_v: |
| 109 | self.h_dim = h_dim or max(self.input_dim_v, self.output_dim_v) |
| 110 | self.wh = nn.Linear(self.input_dim_v, self.h_dim, bias=False) |
| 111 | self.ws = nn.Linear(self.h_dim + self.input_dim_s, self.output_dim_s) |
| 112 | if self.output_dim_v: |
| 113 | self.wv = nn.Linear(self.h_dim, self.output_dim_v, bias=False) |
| 114 | if self.vector_gate: self.wsv = nn.Linear(self.output_dim_s, self.output_dim_v) |
| 115 | else: |
| 116 | self.ws = nn.Linear(self.input_dim_s, self.output_dim_s) |
| 117 | |
| 118 | self.scalar_act, self.vector_act = activations |
| 119 | |
| 120 | def forward(self, x): |
| 121 | ''' |