code: def _get_or_generate_vocab(tmp_dir, vocab_filename, vocab_size):
      """Read or create vocabulary."""
      vocab_filepath = os.path.join(tmp_dir, vocab_filename)
      print("Vocab file written to: " + vocab_filepath)
  
      if tf.gfile.Exists(vocab_filepath):
          gs = text_encoder.SubwordTextEncoder(vocab_filepath)
          return gs
      example_file = os.path.join(tmp_dir, _EXAMPLES_FILE)
      gs = text_encoder.SubwordTextEncoder()
      token_counts = tokenizer.corpus_token_counts(
          example_file, corpus_max_lines=1000000
      )
      gs = gs.build_to_target_size(
          vocab_size, token_counts, min_val=1, max_val=1e3
      )
      gs.store_to_file(vocab_filepath)
      return gs
  
file_path: tensor2tensor/tensor2tensor/data_generators/snli.py
imports: from __future__ import absolute_import
  from __future__ import division
  from __future__ import print_function
  import os
  import zipfile
  from tensor2tensor.data_generators import generator_utils
  from tensor2tensor.data_generators import text_encoder
  from tensor2tensor.data_generators import tokenizer
  import tensorflow.compat.v1
label_desc: Use image node_id 4 for calling a global function with example usage: _get_or_generate_vocab(tmp_dir, vocab_filename, vocab_size) and returns: gs, gs