code: def get_allowed_chars(all_counts, max_unique_chars):
      """Get the top max_unique_chars characters within our wordcounts.
  
      We want each character to be in the vocabulary so that we can keep splitting
      down to the character level if necessary. However, in order not to inflate
      our vocabulary with rare characters, we only keep the top max_unique_chars
      characters.
  
      Args:
        all_counts: list of (string, int) tuples
        max_unique_chars: int, maximum number of unique single-character tokens
  
      Returns:
        set of strings containing top max_unique_chars characters in all_counts
      """
  
      char_counts = collections.defaultdict(int)
  
      for word, count in all_counts:
          for char in word:
              char_counts[char] += count
  
      # Sort by count, then alphabetically.
      sorted_counts = sorted(
          sorted(char_counts.items(), key=lambda x: x[0]),
          key=lambda x: x[1],
          reverse=True,
      )
  
      allowed_chars = set()
      for i in range(min(len(sorted_counts), max_unique_chars)):
          allowed_chars.add(sorted_counts[i][0])
      return allowed_chars
  
file_path: text/tensorflow_text/tools/wordpiece_vocab/wordpiece_tokenizer_learner_lib.py
imports: from __future__ import absolute_import
  from __future__ import division
  from __future__ import print_function
  import collections
  from typing import List, Optional
  import numpy
label_desc: Use image node_id 6 for calling a global function with example usage: get_allowed_chars(all_counts, max_unique_chars) and returns: allowed_chars