class_docstr: Generates statistics for number unique and top-k item counts.
  
  Uses mergeable K-Minimum Values (KMV) and Misra-Gries sketches to estimate
  statistics.
class_docstr_tok: ["Generates","statistics","for","number","unique","and","top-k","item","counts",".","Uses","mergeable","K-Minimum","Values","(","KMV",")","and","Misra-Gries","sketches","to","estimate","statistics","."]
docstr: Initializes a top-k and uniques sketch combiner statistics generator.
  
  Args:
    name: An optional unique name associated with the statistics generator.
    schema: An optional schema for the dataset.
    example_weight_map: an ExampleWeightMap that maps a FeaturePath to its
      corresponding weight column.
    num_top_values: The number of most frequent feature values to keep for
      string features.
    num_rank_histogram_buckets: The number of buckets in the rank histogram
      for string features.
    frequency_threshold: An optional minimum number of examples the most
      frequent values must be present in (defaults to 1).
    weighted_frequency_threshold: An optional minimum weighted number of
      examples the most frequent weighted values must be present in (defaults
      to 1.0).
    num_misragries_buckets: Number of buckets to use for MisraGries sketch.
    num_kmv_buckets: Number of buckets to use for KMV sketch.
    store_output_in_custom_stats: Boolean to indicate if the output stats need
      to be stored in custom stats. If False, the output is stored in
      `uniques` and `rank_histogram` fields.
    length_counter_sampling_rate: The sampling rate to update the byte length
      counter.
docstr_tok: ["Initializes","a","top-k","and","uniques","sketch","combiner","statistics","generator",".","Args",":","name",":","An","optional","unique","name","associated","with","the","statistics","generator",".","schema",":","An","optional","schema","for","the","dataset",".","example_weight_map",":","an","ExampleWeightMap","that","maps","a","FeaturePath","to","its","corresponding","weight","column",".","num_top_values",":","The","number","of","most","frequent","feature","values","to","keep","for","string","features",".","num_rank_histogram_buckets",":","The","number","of","buckets","in","the","rank","histogram","for","string","features",".","frequency_threshold",":","An","optional","minimum","number","of","examples","the","most","frequent","values","must","be","present","in","(","defaults","to","1",")",".","weighted_frequency_threshold",":","An","optional","minimum","weighted","number","of","examples","the","most","frequent","weighted","values","must","be","present","in","(","defaults","to","1.0",")",".","num_misragries_buckets",":","Number","of","buckets","to","use","for","MisraGries","sketch",".","num_kmv_buckets",":","Number","of","buckets","to","use","for","KMV","sketch",".","store_output_in_custom_stats",":","Boolean","to","indicate","if","the","output","stats","need","to","be","stored","in","custom","stats",".","If","False",",","the","output","is","stored","in","`","uniques","`","and","`","rank_histogram","`","fields",".","length_counter_sampling_rate",":","The","sampling","rate","to","update","the","byte","length","counter","."]
code: def __init__(
      self,
      name: Text = "TopKUniquesSketchStatsGenerator",
      schema: Optional[schema_pb2.Schema] = None,
      example_weight_map: ExampleWeightMap = ExampleWeightMap(),
      num_top_values: int = 2,
      num_rank_histogram_buckets: int = 128,
      frequency_threshold: int = 1,
      weighted_frequency_threshold: float = 1.0,
      num_misragries_buckets: int = 128,
      num_kmv_buckets: int = 128,
      store_output_in_custom_stats: bool = False,
      length_counter_sampling_rate: float = 0.01,
  ):
      """Initializes a top-k and uniques sketch combiner statistics generator.
  
      Args:
        name: An optional unique name associated with the statistics generator.
        schema: An optional schema for the dataset.
        example_weight_map: an ExampleWeightMap that maps a FeaturePath to its
          corresponding weight column.
        num_top_values: The number of most frequent feature values to keep for
          string features.
        num_rank_histogram_buckets: The number of buckets in the rank histogram
          for string features.
        frequency_threshold: An optional minimum number of examples the most
          frequent values must be present in (defaults to 1).
        weighted_frequency_threshold: An optional minimum weighted number of
          examples the most frequent weighted values must be present in (defaults
          to 1.0).
        num_misragries_buckets: Number of buckets to use for MisraGries sketch.
        num_kmv_buckets: Number of buckets to use for KMV sketch.
        store_output_in_custom_stats: Boolean to indicate if the output stats need
          to be stored in custom stats. If False, the output is stored in
          `uniques` and `rank_histogram` fields.
        length_counter_sampling_rate: The sampling rate to update the byte length
          counter.
      """
      super(
          TopKUniquesSketchStatsGenerator,
          self,
      ).__init__(name, schema)
      self._num_misragries_buckets = num_misragries_buckets
      self._num_kmv_buckets = num_kmv_buckets
      self._num_top_values = num_top_values
      self._example_weight_map = example_weight_map
      self._num_rank_histogram_buckets = num_rank_histogram_buckets
      self._categorical_numeric_types = (
          schema_util.get_categorical_numeric_feature_types(schema)
          if schema
          else {}
      )
      self._bytes_features = frozenset(
          schema_util.get_bytes_features(schema) if schema else []
      )
      self._byte_feature_is_categorical_values = (
          schema_util.get_bytes_features_categorical_value(schema)
      )
      self._frequency_threshold = frequency_threshold
      self._weighted_frequency_threshold = weighted_frequency_threshold
      self._store_output_in_custom_stats = store_output_in_custom_stats
      self._length_counter_sampling_rate = length_counter_sampling_rate
      # They should be gauges, but not all runners support gauges so they are
      # made distributions.
      # TODO(b/130840752): support gauges in the internal runner.
      self._num_top_values_gauge = beam.metrics.Metrics.distribution(
          constants.METRICS_NAMESPACE, "num_top_values"
      )
      self._num_rank_histogram_buckets_gauge = (
          beam.metrics.Metrics.distribution(
              constants.METRICS_NAMESPACE, "num_rank_histogram_buckets"
          )
      )
      self._num_mg_buckets_gauge = beam.metrics.Metrics.distribution(
          constants.METRICS_NAMESPACE, "num_mg_buckets"
      )
      self._num_kmv_buckets_gauge = beam.metrics.Metrics.distribution(
          constants.METRICS_NAMESPACE, "num_kmv_buckets"
      )
  
imports: import collections
  from typing import Dict, Iterable, Optional, Text
  import apache_beam
  import numpy
  import pyarrow
  from tensorflow_data_validation import constants
  from tensorflow_data_validation import types
  from tensorflow_data_validation.arrow import arrow_util
  from tensorflow_data_validation.statistics.generators import stats_generator
  from tensorflow_data_validation.utils import schema_util
  from tensorflow_data_validation.utils import stats_util
  from tensorflow_data_validation.utils import top_k_uniques_stats_util
  from tensorflow_data_validation.utils.example_weight_map import ExampleWeightMap
  from tfx_bsl.arrow import array_util
  from tfx_bsl.sketches import KmvSketch
  from tfx_bsl.sketches import MisraGriesSketch
  from tensorflow_metadata.proto.v0 import schema_pb2
  from tensorflow_metadata.proto.v0 import statistics_pb2
label_desc: Use image node_id 1 to create a new TopKUniquesSketchStatsGenerator object from inherited base classes: stats_generator with example: obj = TopKUniquesSketchStatsGenerator(name, schema, example_weight_map, num_top_values, num_rank_histogram_buckets, frequency_threshold, weighted_frequency_threshold, num_misragries_buckets, num_kmv_buckets, store_output_in_custom_stats, length_counter_sampling_rate)