class_docstr: An implementation of pointer-generator networks
  :cite:`DBLP:journals/corr/SeeLM17`.
  
  These networks consider copying words
  directly from the source sequence.
  
  The copy generator is an extended version of the standard
  generator that computes three values.
  
  * :math:`p_{softmax}` the standard softmax over `tgt_dict`
  * :math:`p(z)` the probability of copying a word from
    the source
  * :math:`p_{copy}` the probility of copying a particular word.
    taken from the attention distribution directly.
  
  The model returns a distribution over the extend dictionary,
  computed as
  
  :math:`p(w) = p(z=1)  p_{copy}(w)  +  p(z=0)  p_{softmax}(w)`
  
  Args:
     input_size (int): size of input representation
     output_size (int): size of output vocabulary
     pad_idx (int)
class_docstr_tok: ["An","implementation","of","pointer-generator","networks",":","cite",":","`","DBLP",":","journals\/corr\/SeeLM17","`",".","These","networks","consider","copying","words","directly","from","the","source","sequence",".","The","copy","generator","is","an","extended","version","of","the","standard","generator","that","computes","three","values",".","*",":","math",":","`","p_","{","softmax","}","`","the","standard","softmax","over","`","tgt_dict","`","*",":","math",":","`","p","(","z",")","`","the","probability","of","copying","a","word","from","the","source","*",":","math",":","`","p_","{","copy","}","`","the","probility","of","copying","a","particular","word",".","taken","from","the","attention","distribution","directly",".","The","model","returns","a","distribution","over","the","extend","dictionary",",","computed","as",":","math",":","`","p","(","w",")","=","p","(","z=1",")","p_","{","copy","}","(","w",")","+","p","(","z=0",")","p_","{","softmax","}","(","w",")","`","Args",":","input_size","(","int",")",":","size","of","input","representation","output_size","(","int",")",":","size","of","output","vocabulary","pad_idx","(","int",")"]
docstr: Compute a distribution over the target dictionary
  extended by the dynamic dictionary implied by copying
  source words.
  
  Args:
     hidden (FloatTensor): hidden output ``(batch x tlen, input_size)``
     attn (FloatTensor): attn for each ``(batch x tlen, slen)``
     src_map (FloatTensor):
         A sparse indicator matrix mapping each source word to
         its index in the "extended" vocab containing.
         ``(batch, src_len, extra_words)``
docstr_tok: ["Compute","a","distribution","over","the","target","dictionary","extended","by","the","dynamic","dictionary","implied","by","copying","source","words",".","Args",":","hidden","(","FloatTensor",")",":","hidden","output","``","(","batch","x","tlen",",","input_size",")","``","attn","(","FloatTensor",")",":","attn","for","each","``","(","batch","x","tlen",",","slen",")","``","src_map","(","FloatTensor",")",":","A","sparse","indicator","matrix","mapping","each","source","word","to","its","index","in","the","``","extended","''","vocab","containing",".","``","(","batch",",","src_len",",","extra_words",")","``"]
code: def forward(self, hidden, attn, src_map):
      """
      Compute a distribution over the target dictionary
      extended by the dynamic dictionary implied by copying
      source words.
  
      Args:
         hidden (FloatTensor): hidden output ``(batch x tlen, input_size)``
         attn (FloatTensor): attn for each ``(batch x tlen, slen)``
         src_map (FloatTensor):
             A sparse indicator matrix mapping each source word to
             its index in the "extended" vocab containing.
             ``(batch, src_len, extra_words)``
      """
      _, slen = attn.size()
      batch, _, cvocab = src_map.size()
  
      # Original probabilities.
      logits = self.linear(hidden)
      logits[:, self.pad_idx] = -float("inf")
      prob = torch.softmax(logits, 1)
  
      # Probability of copying p(z=1) batch.
      p_copy = torch.sigmoid(self.linear_copy(hidden))
      # Probability of not copying: p_{word}(w) * (1 - p(z))
      out_prob = torch.mul(prob, 1 - p_copy)
      mul_attn = torch.mul(attn, p_copy)
      copy_prob = torch.bmm(
          mul_attn.view(-1, batch, slen).transpose(0, 1), src_map
      )
      copy_prob = copy_prob.contiguous().view(-1, cvocab)
      return torch.cat([out_prob, copy_prob], 1)
  
file_path: OpenNMT-py/onmt/modules/copy_generator.py
imports: import torch
  import torch.nn
label_desc: Use image node_id 2 for calling the CopyGenerator obj's underlying member method code with example usage: obj.forward(hidden, attn, src_map) and returns: torch