class_docstr: Util class to build splits.
  
  Usage is as follow:
  
  ```py
  split_builder = SplitBuilder(...)
  
  with split_builder.maybe_beam_pipeline():
    split_info_future = split_builder.submit_split_generation(...)
  
  split_info = split_info_future.result()
  ```
  
  * submit_split_generation:
    * For generator based split: Generate the split
    * For Apache Beam based split: Create the `beam.PCollection` and returns
      a future.
  * `split_info_future.result()`: Called after all `beam.PCollection`s have
    finished. Finalize the `split_info` by collecting all pipeline results.
  
  `submit_split_generation` / `.result` should be called once per
  split.
class_docstr_tok: ["Util","class","to","build","splits",".","Usage","is","as","follow",":","``","`","py","split_builder","=","SplitBuilder","(","...",")","with","split_builder.maybe_beam_pipeline","(",")",":","split_info_future","=","split_builder.submit_split_generation","(","...",")","split_info","=","split_info_future.result","(",")","``","`","*","submit_split_generation",":","*","For","generator","based","split",":","Generate","the","split","*","For","Apache","Beam","based","split",":","Create","the","`","beam.PCollection","`","and","returns","a","future",".","*","`","split_info_future.result","(",")","`",":","Called","after","all","`","beam.PCollection","`","s","have","finished",".","Finalize","the","`","split_info","`","by","collecting","all","pipeline","results",".","`","submit_split_generation","`","\/","`",".result","`","should","be","called","once","per","split","."]
docstr: Split generator for example generators.
  
  Args:
    split_name: str,
    generator: Iterable[KeyExample],
    filename_template: Template to format the filename for a shard.
    disable_shuffling: Specifies whether to shuffle the examples,
  
  Returns:
    future: The future containing the `tfds.core.SplitInfo`.
docstr_tok: ["Split","generator","for","example","generators",".","Args",":","split_name",":","str",",","generator",":","Iterable","[","KeyExample","]",",","filename_template",":","Template","to","format","the","filename","for","a","shard",".","disable_shuffling",":","Specifies","whether","to","shuffle","the","examples",",","Returns",":","future",":","The","future","containing","the","`","tfds.core.SplitInfo","`","."]
code: def _build_from_generator(
      self,
      split_name: str,
      generator: Iterable[KeyExample],
      filename_template: naming.ShardedFileTemplate,
      disable_shuffling: bool,
  ) -> _SplitInfoFuture:
      """Split generator for example generators.
  
      Args:
        split_name: str,
        generator: Iterable[KeyExample],
        filename_template: Template to format the filename for a shard.
        disable_shuffling: Specifies whether to shuffle the examples,
  
      Returns:
        future: The future containing the `tfds.core.SplitInfo`.
      """
      if self._max_examples_per_split is not None:
          logging.warning(
              "Splits capped at %s examples max.",
              self._max_examples_per_split,
          )
          generator = itertools.islice(
              generator, self._max_examples_per_split
          )
          total_num_examples = self._max_examples_per_split
      else:
          # If dataset info has been pre-downloaded from the internet,
          # we can use the pre-computed number of example for the progression bar.
          split_info = self._split_dict.get(split_name)
          if split_info and split_info.num_examples:
              total_num_examples = split_info.num_examples
          else:
              total_num_examples = None
  
      serialized_info = self._features.get_serialized_info()
      writer = writer_lib.Writer(
          serializer=example_serializer.ExampleSerializer(
              serialized_info
          ),
          filename_template=filename_template,
          hash_salt=split_name,
          disable_shuffling=disable_shuffling,
          # TODO(weide) remove this because it's already in filename_template?
          file_format=self._file_format,
          shard_config=self._shard_config,
      )
      for key, example in utils.tqdm(
          generator,
          desc=f"Generating {split_name} examples...",
          unit=" examples",
          total=total_num_examples,
          leave=False,
          mininterval=1.0,
      ):
          try:
              example = self._features.encode_example(example)
          except Exception as e:  # pylint: disable=broad-except
              utils.reraise(
                  e, prefix=f"Failed to encode example:\n{example}\n"
              )
          writer.write(key, example)
      shard_lengths, total_size = writer.finalize()
  
      split_info = splits_lib.SplitInfo(
          name=split_name,
          shard_lengths=shard_lengths,
          num_bytes=total_size,
          filename_template=filename_template,
      )
      return _SplitInfoFuture(lambda: split_info)
  
imports: import collections.abc
  import contextlib
  import dataclasses
  import functools
  import itertools
  import sys
  from typing import Any, Callable, Dict, Iterable, Iterator, List, Optional, Tuple, Union
  from absl import logging
  import click
  import psutil
  from tensorflow_datasets.core import example_serializer
  from tensorflow_datasets.core import features
  from tensorflow_datasets.core import file_adapters
  from tensorflow_datasets.core import naming
  from tensorflow_datasets.core import splits
  from tensorflow_datasets.core import utils
  from tensorflow_datasets.core import writer
  from tensorflow_datasets.core.utils import shard_utils
  from tensorflow_datasets.core.utils.lazy_imports_utils import apache_beam
label_desc: Use image node_id 6 for calling the SplitBuilder obj's underlying member method code with example usage: obj._build_from_generator(split_name, generator, filename_template, disable_shuffling) and returns: _SplitInfoFuture