code: def testVocabularyWithKeyFnAndFrequency(self):
      def key_fn(string):
          return string.split(b"_X_")[1]
  
      outfile = "vocabulary_with_frequency"
  
      def preprocessing_fn(inputs):
          # Force the analyzer to be executed, and store the frequency file as a
          # side-effect.
  
          _ = tft.vocabulary(
              tf.compat.v1.strings.split(inputs["a"]),
              coverage_top_k=1,
              key_fn=key_fn,
              frequency_threshold=4,
              vocab_filename=outfile,
              store_frequency=True,
              file_format=self._VocabFormat(),
          )
  
          _ = tft.vocabulary(
              tf.compat.v1.strings.split(inputs["a"]),
              coverage_top_k=1,
              key_fn=key_fn,
              frequency_threshold=4,
              store_frequency=True,
              file_format=self._VocabFormat(),
          )
  
          a_int = tft.compute_and_apply_vocabulary(
              tf.compat.v1.strings.split(inputs["a"]),
              coverage_top_k=1,
              key_fn=key_fn,
              frequency_threshold=4,
              store_frequency=True,
              file_format=self._VocabFormat(),
          )
  
          # Return input unchanged, this preprocessing_fn is a no-op except for
          # computing uniques.
          return {"a_int": a_int}
  
      input_metadata = tft.DatasetMetadata.from_feature_spec(
          {"a": tf.io.FixedLenFeature([], tf.string)}
      )
  
      tft_tmp_dir = os.path.join(self.get_temp_dir(), "temp_dir")
      transform_fn_dir = os.path.join(
          self.get_temp_dir(), "export_transform_fn"
      )
  
      with beam_impl.Context(temp_dir=tft_tmp_dir):
          with self._makeTestPipeline() as pipeline:
              input_data = pipeline | beam.Create(
                  [
                      {"a": "1_X_a 1_X_a 2_X_a 1_X_b 2_X_b"},
                      {"a": "1_X_a 1_X_a 2_X_a 2_X_a"},
                      {"a": "2_X_b 3_X_c 4_X_c"},
                  ]
              )
              transform_fn = (
                  input_data,
                  input_metadata,
              ) | beam_impl.AnalyzeDataset(preprocessing_fn)
              _ = transform_fn | transform_fn_io.WriteTransformFn(
                  transform_fn_dir
              )
  
      self.assertTrue(os.path.isdir(tft_tmp_dir))
  
      tft_output = tft.TFTransformOutput(transform_fn_dir)
      assets_path = os.path.join(
          tft_output.transform_savedmodel_dir,
          tf.saved_model.ASSETS_DIRECTORY,
      )
      self.assertTrue(os.path.isdir(assets_path))
  
      self.assertEqual(
          [b"4 1_X_a", b"2 2_X_b", b"1 4_X_c"],
          tft_output.vocabulary_by_name(outfile),
      )
  
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 13 for calling the VocabularyIntegrationTest obj's underlying member method code with example usage: obj.testVocabularyWithKeyFnAndFrequency() and returns: string, dict