class_docstr: Generates statistics for sparse features.
class_docstr_tok: ["Generates","statistics","for","sparse","features","."]
code: def extract_composite_output(self, accumulator):
      stats = statistics_pb2.DatasetFeatureStatistics()
      for feature_path, (
          value,
          indices,
      ) in self._sparse_feature_components.items():
          required_paths = [value] + list(indices)
          feature_stats = stats.features.add(
              path=feature_path.to_proto()
          )
          feature_stats.custom_stats.add(
              name=_MISSING_VALUE_NAME,
              num=accumulator[
                  count_missing_generator.CountMissingGenerator.key(
                      value, required_paths
                  )
              ],
          )
          index_features_num_missing_histogram = (
              statistics_pb2.RankHistogram()
          )
          max_length_diff_histogram = statistics_pb2.RankHistogram()
          min_length_diff_histogram = statistics_pb2.RankHistogram()
          for index in sorted(indices):
              index_label = index.steps()[-1]
              missing_bucket = (
                  index_features_num_missing_histogram.buckets.add()
              )
              missing_bucket.label = index_label
              missing_bucket.sample_count = accumulator[
                  count_missing_generator.CountMissingGenerator.key(
                      index, required_paths
                  )
              ]
  
              min_diff, max_diff = accumulator[
                  length_diff_generator.LengthDiffGenerator.key(
                      index, value, required_paths
                  )
              ]
              max_length_bucket = (
                  max_length_diff_histogram.buckets.add()
              )
              max_length_bucket.label = index_label
              max_length_bucket.sample_count = max_diff
  
              min_length_bucket = (
                  min_length_diff_histogram.buckets.add()
              )
              min_length_bucket.label = index_label
              min_length_bucket.sample_count = min_diff
  
          feature_stats.custom_stats.add(
              name=_MISSING_INDEX_NAME,
              rank_histogram=index_features_num_missing_histogram,
          )
          feature_stats.custom_stats.add(
              name=_MAX_LENGTH_DIFF_NAME,
              rank_histogram=max_length_diff_histogram,
          )
          feature_stats.custom_stats.add(
              name=_MIN_LENGTH_DIFF_NAME,
              rank_histogram=min_length_diff_histogram,
          )
      return stats
  
file_path: data-validation/tensorflow_data_validation/statistics/generators/sparse_feature_stats_generator.py
imports: from __future__ import absolute_import
  from __future__ import division
  from __future__ import print_function
  from typing import Dict, Iterable, List, Text, Tuple, Union
  from tensorflow_data_validation import types
  from tensorflow_data_validation.statistics.generators import stats_generator
  from tensorflow_data_validation.statistics.generators.constituents import count_missing_generator
  from tensorflow_data_validation.statistics.generators.constituents import length_diff_generator
  from tensorflow_metadata.proto.v0 import schema_pb2
  from tensorflow_metadata.proto.v0 import statistics_pb2
  from tfx_bsl.types import tfx_namedtuple
label_desc: Use image node_id 2 for calling the SparseFeatureStatsGenerator obj's underlying member method code with example usage: obj.extract_composite_output(accumulator) and returns: stats