Is there any implementation of pointer network for transformers. I found an implementation in TF at https://github.com/xiongma/transformer-pointer-generator 24
I tried converting but not able to find a counter part of the following function in pytrorch.
The function is
loss = tf.map_fn(fn=lambda x: tf.gather_nd(x[1], x[0]), elems=(indices, final_dists), dtype=tf.float32)
It is at

  
      github.com
  
  
    xiongma/transformer-pointer-generator/blob/master/model.py#L152 11

        dec = tf.range(0, limit=dec_t) # [dec]
        dec = tf.expand_dims(dec, axis=-1) # [dec, 1]
        dec = tf.tile(dec, [1, attn_len]) # [dec, atten_len]
        dec = tf.expand_dims(dec, axis=0) # [1, dec, atten_len]
        dec = tf.tile(dec, [batch_size, 1, 1]) # [batch_size, dec, atten_len]

        x = tf.expand_dims(x, axis=1) # [batch_size, 1, atten_len]
        x = tf.tile(x, [1, dec_t, 1]) # [batch_size, dec, atten_len]
        x = tf.stack([dec, x], axis=3)

        attn_dists_projected = tf.map_fn(fn=lambda y: tf.scatter_nd(y[0], y[1], [dec_t, self.hp.vocab_size]),
                                         elems=(x, attn_dists), dtype=tf.float32)

        final_dists = attn_dists_projected + vocab_dists

    return final_dists

def _calc_loss(self, targets, final_dists):
    """
    calculate loss
    :param targets: reference