code: def get_categorical_features_to_sampling(examples, top_k):
      """Returns categorical features and a sampling of their most-common values.
  
      The results of this slow function are used by the visualization repeatedly,
      so the results are cached.
  
      Args:
        examples: Examples to read to get feature samples.
        top_k: Max number of samples to return per feature.
  
      Returns:
        A dict of feature_name -> {'samples': ['Married-civ-spouse',
          'Never-married', 'Divorced']}.
  
        There is one key for each categorical feature.
  
        Currently, the inner dict just has one key, but this structure leaves room
        for further expansion, and mirrors the structure used by
        `get_numeric_features_to_observed_range`.
      """
      observed_features = collections.defaultdict(
          list
      )  # name -> [value, ]
      for example in examples:
          for feature_name in get_categorical_feature_names(example):
              original_feature = parse_original_feature_from_example(
                  example, feature_name
              )
              observed_features[feature_name].extend(
                  original_feature.original_value
              )
  
      result = {}
      for feature_name, feature_values in sorted(
          iteritems(observed_features)
      ):
          samples = [
              word
              for word, count in collections.Counter(
                  feature_values
              ).most_common(top_k)
              if count > 1
          ]
          if samples:
              result[feature_name] = {"samples": samples}
      return result
  
imports: from __future__ import division
  from __future__ import print_function
  import collections
  import copy
  import json
  import math
  from absl import logging
  import numpy
  import tensorflow
  from google.protobuf import json_format
  from six import binary_type, string_types, integer_types
  from six import iteritems
  from six.moves import zip
  from inspect import signature
  from utils import common_utils
  from utils import platform_utils
  from tensorflow_serving.apis import classification_pb2
  from tensorflow_serving.apis import inference_pb2
  from tensorflow_serving.apis import regression_pb2
label_desc: Use image node_id 8 for calling a global function with example usage: get_categorical_features_to_sampling(examples, top_k) and returns: result