code: def testCreateVocabWithFrequency(self):
      input_data = [
          {"a": "hello", "b": "world", "c": "aaaaa"},
          {"a": "good", "b": "", "c": "hello"},
          {"a": "goodbye", "b": "hello", "c": "\n"},
          {"a": "_", "b": "aaaaa", "c": "bbbbb"},
      ]
      input_metadata = tft.DatasetMetadata.from_feature_spec(
          {
              "a": tf.io.FixedLenFeature([], tf.string),
              "b": tf.io.FixedLenFeature([], tf.string),
              "c": tf.io.FixedLenFeature([], tf.string),
          }
      )
      vocab_filename = "test_vocab_with_frequency"
  
      def preprocessing_fn(inputs):
          deferred_vocab_and_filename = tft.vocabulary(
              tf.concat([inputs["a"], inputs["b"], inputs["c"]], 0),
              vocab_filename=vocab_filename,
              store_frequency=True,
              file_format=self._VocabFormat(),
          )
  
          def _make_table_initializer(
              filename_tensor, is_frequency_value
          ):
              if self._VocabFormat() == "text":
                  return tf.lookup.TextFileInitializer(
                      filename=filename_tensor,
                      key_dtype=tf.string,
                      key_index=1,
                      value_dtype=tf.int64,
                      value_index=(
                          0
                          if is_frequency_value
                          else tf.lookup.TextFileIndex.LINE_NUMBER
                      ),
                      delimiter=" ",
                  )
              elif self._VocabFormat() == "tfrecord_gzip":
                  return tft.tf_utils.make_tfrecord_vocabulary_lookup_initializer(
                      filename_tensor,
                      return_indicator_as_value=is_frequency_value,
                      has_indicator=True,
                  )
  
          def _apply_vocab(y, deferred_vocab_filename_tensor):
              initializer = _make_table_initializer(
                  deferred_vocab_filename_tensor, False
              )
              table = tf.lookup.StaticHashTable(
                  initializer, default_value=-1
              )
              table_size = table.size()
              return table.lookup(y), table_size
  
          def _apply_frequency(y, deferred_vocab_filename_tensor):
              initializer = _make_table_initializer(
                  deferred_vocab_filename_tensor, True
              )
              table = tf.lookup.StaticHashTable(
                  initializer, default_value=-1
              )
              return table.lookup(y), table.size()
  
          return {
              "index_a": tft.apply_vocabulary(
                  inputs["a"],
                  deferred_vocab_and_filename,
                  lookup_fn=_apply_vocab,
                  file_format=self._VocabFormat(),
              ),
              "frequency_a": tft.apply_vocabulary(
                  inputs["a"],
                  deferred_vocab_and_filename,
                  lookup_fn=_apply_frequency,
                  file_format=self._VocabFormat(),
              ),
              "index_b": tft.apply_vocabulary(
                  inputs["b"],
                  deferred_vocab_and_filename,
                  lookup_fn=_apply_vocab,
                  file_format=self._VocabFormat(),
              ),
              "frequency_b": tft.apply_vocabulary(
                  inputs["b"],
                  deferred_vocab_and_filename,
                  lookup_fn=_apply_frequency,
                  file_format=self._VocabFormat(),
              ),
          }
  
      expected_vocab = [
          (b"hello", 3),
          (b"aaaaa", 2),
          (b"world", 1),
          (b"goodbye", 1),
          (b"good", 1),
          (b"bbbbb", 1),
          (b"_", 1),
          (b"\n", 1),
          (b"", 1),
      ]
      if self._VocabFormat() == "text":
          expected_vocab = expected_vocab[:-2]
          empty_index = -1
          empty_frequency = -1
      else:
          empty_index = 8
          empty_frequency = 1
      expected_data = [
          # For tied frequencies, larger (lexicographic) items come first.
          {
              "index_a": 0,
              "frequency_a": 3,
              "index_b": 2,
              "frequency_b": 1,
          },
          {
              "index_a": 4,
              "frequency_a": 1,
              "index_b": empty_index,
              "frequency_b": empty_frequency,
          },
          {
              "index_a": 3,
              "frequency_a": 1,
              "index_b": 0,
              "frequency_b": 3,
          },
          {
              "index_a": 6,
              "frequency_a": 1,
              "index_b": 1,
              "frequency_b": 2,
          },
      ]
      size = len(expected_vocab) - 1
      expected_metadata = tft.DatasetMetadata.from_feature_spec(
          {
              "index_a": tf.io.FixedLenFeature([], tf.int64),
              "index_b": tf.io.FixedLenFeature([], tf.int64),
              "frequency_a": tf.io.FixedLenFeature([], tf.int64),
              "frequency_b": tf.io.FixedLenFeature([], tf.int64),
          },
          {
              "index_a": schema_pb2.IntDomain(
                  min=-1, max=size, is_categorical=True
              ),
              "index_b": schema_pb2.IntDomain(
                  min=-1, max=size, is_categorical=True
              ),
              "frequency_a": schema_pb2.IntDomain(
                  min=-1, max=size, is_categorical=True
              ),
              "frequency_b": schema_pb2.IntDomain(
                  min=-1, max=size, is_categorical=True
              ),
          },
      )
  
      self.assertAnalyzeAndTransformResults(
          input_data,
          input_metadata,
          preprocessing_fn,
          expected_data,
          expected_metadata,
          expected_vocab_file_contents={vocab_filename: expected_vocab},
      )
  
imports: import os
  import apache_beam
  import tensorflow
  import tensorflow_transform
  from tensorflow_transform.beam import analyzer_impls
  from tensorflow_transform.beam import impl
  from tensorflow_transform.beam.tft_beam_io import transform_fn_io
  from tensorflow_transform.beam import tft_unit
  from tensorflow_metadata.proto.v0 import schema_pb2
label_desc: Use image node_id 10 for calling the VocabularyIntegrationTest obj's underlying member method code with example usage: obj.testCreateVocabWithFrequency() and returns: dict, table,  table_size, table,  table, tf, tft