(self, hidden, attn, src_map)
return torch.cat([out_prob, copy_prob], 1)
Compute a distribution over the target dictionary
        extended by the dynamic dictionary implied by compying
        source words.

        Args:
           hidden (`FloatTensor`): hidden outputs `[batch*tlen, input_size]`
           attn (`FloatTensor`): attn for each `[batch*tlen, input_size]`
           src_map (`FloatTensor`):
             A sparse indicator matrix mapping each source word to
             its index in the "extended" vocab containing.
             `[src_len, batch, extra_words]`
Compute a distribution over the target dictionary
        extended by the dynamic dictionary implied by compying
        source words.
Compute a distribution over the target dictionary extended by the dynamic dictionary implied by compying source words .
def forward(self, hidden, attn, src_map):
        """
        Compute a distribution over the target dictionary
        extended by the dynamic dictionary implied by compying
        source words.

        Args:
           hidden (`FloatTensor`): hidden outputs `[batch*tlen, input_size]`
           attn (`FloatTensor`): attn for each `[batch*tlen, input_size]`
           src_map (`FloatTensor`):
             A sparse indicator matrix mapping each source word to
             its index in the "extended" vocab containing.
             `[src_len, batch, extra_words]`
        """
        # CHECKS
        batch_by_tlen, _ = hidden.size()
        batch_by_tlen_, slen = attn.size()
        slen_, batch, cvocab = src_map.size()
        aeq(batch_by_tlen, batch_by_tlen_)
        aeq(slen, slen_)

        # Original probabilities.
        logits = self.linear(hidden)
        logits[:, self.tgt_dict.stoi[inputters.PAD_WORD]] = -float('inf')
        prob = self.softmax(logits)

        # Probability of copying p(z=1) batch.
        p_copy = self.sigmoid(self.linear_copy(hidden))
        # Probibility of not copying: p_{word}(w) * (1 - p(z))
        out_prob = torch.mul(prob, 1 - p_copy.expand_as(prob))
        mul_attn = torch.mul(attn, p_copy.expand_as(attn))
        copy_prob = torch.bmm(mul_attn.view(-1, batch, slen)
                              .transpose(0, 1),
                              src_map.transpose(0, 1)).transpose(0, 1)
        copy_prob = copy_prob.contiguous().view(-1, cvocab)
        return torch.cat([out_prob, copy_prob], 1)
def forward ( self , hidden , attn , src_map ) : # CHECKS batch_by_tlen , _ = hidden . size ( ) batch_by_tlen_ , slen = attn . size ( ) slen_ , batch , cvocab = src_map . size ( ) aeq ( batch_by_tlen , batch_by_tlen_ ) aeq ( slen , slen_ ) # Original probabilities. logits = self . linear ( hidden ) logits [ : , self . tgt_dict . stoi [ inputters . PAD_WORD ] ] = - float ( 'inf' ) prob = self . softmax ( logits ) # Probability of copying p(z=1) batch. p_copy = self . sigmoid ( self . linear_copy ( hidden ) ) # Probibility of not copying: p_{word}(w) * (1 - p(z)) out_prob = torch . mul ( prob , 1 - p_copy . expand_as ( prob ) ) mul_attn = torch . mul ( attn , p_copy . expand_as ( attn ) ) copy_prob = torch . bmm ( mul_attn . view ( - 1 , batch , slen ) . transpose ( 0 , 1 ) , src_map . transpose ( 0 , 1 ) ) . transpose ( 0 , 1 ) copy_prob = copy_prob . contiguous ( ) . view ( - 1 , cvocab ) return torch . cat ( [ out_prob , copy_prob ] , 1 )