def forward(self, data: BatchHolder): if self.use_attention: output = data.hidden mask = data.masks attn = self.attention(data.seq, output, mask) if self.use_regulariser_attention: data.reg_loss = 5 * self.regularizer_attention.regularise( data.seq, output, mask, attn) if isTrue(data, 'detach'): attn = attn.detach() if isTrue(data, 'permute'): permutation = data.generate_permutation() attn = torch.gather(attn, -1, torch.LongTensor(permutation).to(device)) context = (attn.unsqueeze(-1) * output).sum(1) data.attn = attn else: context = data.last_hidden predict = self.decode(context) data.predict = predict
def forward(self, data: BatchHolder): if self.use_attention: output = data.hidden attn = data.generate_frozen_uniform_attn() context = (attn.unsqueeze(-1) * output).sum(1) data.attn = attn else: context = data.last_hidden predict = self.decode(context) data.predict = predict
def forward(self, data: BatchHolder): if self.use_attention: output = data.hidden attn = data.target_attn context = (attn.unsqueeze(-1) * output).sum(1) data.attn = attn else: context = data.last_hidden predict = self.decode(context) data.predict = predict
def forward(self, data: BatchHolder): if self.use_attention: output = data.hidden mask = data.masks attn = self.attention(data.seq, output, mask) context = (attn.unsqueeze(-1) * output).sum(1) data.attn = attn else: context = data.last_hidden predict = self.decode(context) data.predict = predict