def METHOD_NAME(self, tokens, lprobs, bsz: int, beam_size: int, step: int):
    """For each hypothesis generate a list of previous ngrams and set associated lprobs to -inf"""
    gen_ngrams: List[Dict[str, List[int]]] = [
        torch.jit.annotate(Dict[str, List[int]], {})
        for bbsz_idx in range(bsz * beam_size)
    ]
    cpu_tokens = tokens.cpu()
    for bbsz_idx in range(bsz * beam_size):
        gen_tokens: List[int] = cpu_tokens[bbsz_idx].tolist()
        for ngram in self.transpose_list(
            [gen_tokens[i:] for i in range(self.no_repeat_ngram_size)]
        ):
            key = ",".join([str(x) for x in ngram[:-1]])
            gen_ngrams[bbsz_idx][key] = gen_ngrams[bbsz_idx].get(
                key, torch.jit.annotate(List[int], [])
            ) + [ngram[-1]]
    if step + 2 - self.no_repeat_ngram_size >= 0:
        # no banned tokens if we haven't generated no_repeat_ngram_size tokens yet
        banned_tokens = [
            self.calculate_banned_tokens(
                tokens, step, gen_ngrams, self.no_repeat_ngram_size, bbsz_idx
            )
            for bbsz_idx in range(bsz * beam_size)
        ]
    else:
        banned_tokens = [
            torch.jit.annotate(List[int], []) for bbsz_idx in range(bsz * beam_size)
        ]
    for bbsz_idx in range(bsz * beam_size):
        lprobs[bbsz_idx][
            torch.tensor(banned_tokens[bbsz_idx], dtype=torch.int64)
        ] = torch.tensor(-math.inf).to(lprobs)
    return lprobs