code: def get_categorical_features_to_sampling(examples, top_k):
    
    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
docs: 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`.