class_docstr: Shuffles / writes Examples beam collection to sharded TFRecord files.
  
  The given examples are not directly writen to the final tfrecord file, but to
  temporary files.
class_docstr_tok: ["Shuffles","\/","writes","Examples","beam","collection","to","sharded","TFRecord","files",".","The","given","examples","are","not","directly","writen","to","the","final","tfrecord","file",",","but","to","temporary","files","."]
docstr: Returns PTransform to write (key, example) PCollection to tfrecords.
docstr_tok: ["Returns","PTransform","to","write","(","key",",","example",")","PCollection","to","tfrecords","."]
code: def write_from_pcollection(self, examples_pcollection):
      """Returns PTransform to write (key, example) PCollection to tfrecords."""
      serialized_examples = (
          examples_pcollection
          | "Serialize" >> beam.Map(self._serialize_example)
          # (key, serialized_example)
      )
  
      largest_key = (
          serialized_examples
          | beam.Keys()
          | "LargestKey" >> beam.combiners.Top.Largest(1)
      )
      num_examples = (
          serialized_examples
          | "CountExamples" >> beam.combiners.Count.Globally()
          | "CheckValidNumExamples"
          >> beam.Map(self._check_num_examples)
      )
      total_size = beam.pvalue.AsSingleton(
          serialized_examples
          | beam.Values()
          | beam.Map(len)
          | "TotalSize" >> beam.CombineGlobally(sum)
      )
      ideal_num_shards = beam.pvalue.AsSingleton(
          num_examples
          | "NumberOfShards"
          >> beam.Map(self._number_of_shards, total_size=total_size)
      )
  
      examples_per_shard = (
          serialized_examples
          | "AssignShard"
          >> beam.Map(
              self._assign_shard,
              largest_key=beam.pvalue.AsSingleton(largest_key),
              num_shards=ideal_num_shards,
          )
          # (shard_id, serialized_example)
          | "GroupShards" >> beam.GroupByKey()
          # (shard_id, [serialized_example])
      )
  
      # There may be shards that did not get assigned any examples. We will ignore
      # those shards and for that we need the ids of shards that are non-empty.
      non_empty_shard_ids = beam.pvalue.AsSingleton(
          examples_per_shard
          | "GetIdsOfNonEmptyShards" >> beam.Keys()
          | "CollectIdsOfNonEmptyShards"
          >> beam.transforms.combiners.ToList()
          | "SortIdsOfNonEmptyShards"
          >> beam.Map(
              self._sort_shard_ids, ideal_num_shards=ideal_num_shards
          )
      )
  
      return (
          examples_per_shard
          # (shard_id, [serialized_example])
          | "WriteFinalShards"
          >> beam.Map(
              self._write_final_shard,
              non_empty_shard_ids=non_empty_shard_ids,
          )
          # (_ShardInfo)
          | "CollectShardInfo" >> beam.transforms.combiners.ToList()
          # [_ShardInfo]
          | "CalculateSplitInfo"
          >> beam.ParDo(self._store_split_info, total_size=total_size)
      )
  
imports: import dataclasses
  import functools
  import itertools
  import json
  import os
  from typing import Any, Iterable, List, Optional, Tuple
  from absl import logging
  from etils import epath
  from tensorflow_datasets.core import example_parser
  from tensorflow_datasets.core import example_serializer
  from tensorflow_datasets.core import file_adapters
  from tensorflow_datasets.core import hashing
  from tensorflow_datasets.core import lazy_imports_lib
  from tensorflow_datasets.core import naming
  from tensorflow_datasets.core import shuffle
  from tensorflow_datasets.core import utils
  from tensorflow_datasets.core.utils import file_utils
  from tensorflow_datasets.core.utils import shard_utils
  from tensorflow_datasets.core.utils import type_utils
  from tensorflow_datasets.core.utils.lazy_imports_utils import apache_beam
label_desc: Use image node_id 14 for calling the BeamWriter obj's underlying member method code with example usage: obj.write_from_pcollection(examples_pcollection) and returns: unknown