class_docstr: Wikipedia articles with labeled salient spans.
docstr: Build Pcollection of examples in text form.
code: def _build_pcollection(self, pipeline, split_sentences):
      """Build Pcollection of examples in text form."""
      beam = tfds.core.lazy_imports.apache_beam
  
      def _inc_counter(name, amt=1):
          beam.metrics.Metrics.counter(
              "salient_span_wikipedia", name
          ).inc(amt)
  
      def _emit_example(ex):
          _inc_counter("input-examples")
  
          def int_feat(key):
              return np.array(
                  ex.features.feature[key].int64_list.value, np.int32
              )
  
          def str_feat(key):
              return np.array(ex.features.feature[key].bytes_list.value)
  
          uid = str_feat("uid")
          title = str_feat("title")[0]
          text = str_feat("text")[0]
          span_start = int_feat("span_byte_start")
          span_limit = int_feat("span_byte_limit")
          span_type = str_feat("span_type")
          sent_start = int_feat("sentence_byte_start")
          sent_limit = int_feat("sentence_byte_limit")
  
          if not split_sentences:
              _inc_counter("output-examples")
              yield uid, {
                  "title": title,
                  "text": text,
                  "spans": {
                      "start": span_start,
                      "limit": span_limit,
                      "type": span_type,
                  },
                  "sentences": {
                      "start": sent_start,
                      "limit": sent_limit,
                  },
              }
          else:
              span_i = 0
              for sent_i, (sent_start, sent_limit) in enumerate(
                  zip(sent_start, sent_limit)
              ):
                  span_indices = []
                  while (
                      span_i < len(span_start)
                      and span_start[span_i] < sent_limit
                  ):
                      if span_limit[span_i] <= sent_limit:
                          span_indices.append(span_i)
                      else:
                          _inc_counter("cross-sentence-spans")
                      span_i += 1
  
                  if not span_indices:
                      _inc_counter("sentence-no-spans")
                      continue
                  _inc_counter("in-sentence-spans", len(span_indices))
  
                  _inc_counter("output-examples")
                  yield "%s:%d" % (uid, sent_i), {
                      "title": title,
                      "text": text[sent_start:sent_limit],
                      "spans": {
                          "start": span_start[span_indices]
                          - sent_start,
                          "limit": span_limit[span_indices]
                          - sent_start,
                          "type": span_type[span_indices],
                      },
                  }
  
      return (
          pipeline
          | beam.io.ReadFromTFRecord(
              _INPUT_FILE_PATTERN,
              coder=beam.coders.ProtoCoder(tf.train.Example),
          )
          | beam.FlatMap(_emit_example)
      )
  
file_path: datasets/tensorflow_datasets/datasets/salient_span_wikipedia/salient_span_wikipedia_dataset_builder.py
imports: from __future__ import annotations
  import numpy
  from tensorflow_datasets.core.utils.lazy_imports_utils import tensorflow
  import tensorflow_datasets.public_api
label_desc: Use image node_id 3 for calling the Builder obj's underlying member method code with example usage: obj._build_pcollection(pipeline, split_sentences) and returns: unknown, np, np