docstr: See "A Simple, Fast Diverse Decoding Algorithm for Neural Generation"
  for details
docstr_tok: ["See","``","A","Simple",",","Fast","Diverse","Decoding","Algorithm","for","Neural","Generation","''","for","details"]
code: def diversity_sibling_rank(self, logprobs, gamma):
      """
      See "A Simple, Fast Diverse Decoding Algorithm for Neural Generation"
      for details
      """
      _, beam_size, vocab_size = logprobs.size()
      logprobs = logprobs.view(-1, vocab_size)
      # Keep consistent with beamsearch class in fairseq
      k = min(2 * beam_size, vocab_size)
      _, indices = torch.topk(logprobs, k)
      # Set diverse penalty as k for all words
      diverse_penalty = torch.ones_like(logprobs) * k
      diversity_sibling_rank = (
          torch.arange(0, k)
          .view(-1, 1)
          .expand(k, logprobs.size(0))
          .type_as(logprobs)
      )
      # Set diversity penalty accordingly for top-k words
      diverse_penalty[
          torch.arange(0, logprobs.size(0)).long(),
          indices.transpose(0, 1),
      ] = diversity_sibling_rank
      logprobs -= gamma * diverse_penalty
      return logprobs
  
imports: import math
  from typing import List, Tuple
  import torch
  from fairseq import search, utils
  from fairseq.models import FairseqIncrementalDecoder
  from pytorch_translate import utils
  from torch import Tensor
label_desc: Use image node_id 16 for calling the SequenceGenerator obj's underlying member method code with example usage: obj.diversity_sibling_rank(logprobs, gamma) and returns: logprobs