Implement tf.nn.in_top_k in PyTorch

How to achieve this function in pytorch?

tf.math.in_top_k(
    targets, predictions, k, name=None
)

tf.nn.in_top_k

Try something similar.

top_k = torch.topk(targets, k)
if any([(targets == c_).all() for c_ in predictions]):
      print('targets in top_k predictions')