code: def testGetOrGenerateTxtVocab(self):
      data_dir = tempfile.mkdtemp(dir=self.get_temp_dir())
      test_file = os.path.join(self.get_temp_dir(), "test.txt")
      with tf.gfile.Open(test_file, "w") as outfile:
          outfile.write("a b c\n")
          outfile.write("d e f\n")
      # Create a vocab over the test file.
      vocab1 = generator_utils.get_or_generate_txt_vocab(
          data_dir, "test.voc", 20, test_file
      )
      self.assertTrue(
          tf.gfile.Exists(os.path.join(data_dir, "test.voc"))
      )
      self.assertIsNotNone(vocab1)
  
      # Append a new line to the test file which would change the vocab if
      # the vocab were not being read from file.
      with tf.gfile.Open(test_file, "a") as outfile:
          outfile.write("g h i\n")
      vocab2 = generator_utils.get_or_generate_txt_vocab(
          data_dir, "test.voc", 20, test_file
      )
      self.assertTrue(
          tf.gfile.Exists(os.path.join(data_dir, "test.voc"))
      )
      self.assertIsNotNone(vocab2)
      self.assertEqual(vocab1.dump(), vocab2.dump())
  
imports: from __future__ import absolute_import
  from __future__ import division
  from __future__ import print_function
  import gzip
  import io
  import os
  import tempfile
  from builtins import bytes
  from tensor2tensor.data_generators import generator_utils
  import tensorflow.compat.v1
label_desc: Use image node_id 5 for calling the GeneratorUtilsTest obj's underlying member method code with example usage: obj.testGetOrGenerateTxtVocab() without return types