code: def _get_ngram_counter(ids, n):
      """Get a Counter with the ngrams of the given ID list.
  
      Args:
        ids: np.array or a list corresponding to a single sentence
        n: n-gram size
  
      Returns:
        collections.Counter with ID tuples as keys and 1s as values.
      """
      # Remove zero IDs used to pad the sequence.
      ids = [token_id for token_id in ids if token_id != 0]
      ngram_list = [
          tuple(ids[i : i + n]) for i in range(len(ids) + 1 - n)
      ]
      ngrams = set(ngram_list)
      counts = collections.Counter()
      for ngram in ngrams:
          counts[ngram] = 1
      return counts
  
file_path: tensor2tensor/tensor2tensor/utils/sari_hook.py
imports: from __future__ import absolute_import
  from __future__ import division
  from __future__ import print_function
  import collections
  import numpy
  import tensorflow.compat.v1
label_desc: Use image node_id 1 for calling a global function with example usage: _get_ngram_counter(ids, n) and returns: counts