code: def _dump_chars_to_textfile(
      dataset: tf.data.Dataset,
      maxchars: int = int(1e7),
      data_keys=("inputs", "targets"),
  ) -> Tuple[str, int]:
      """Write part of a TFDS sentence dataset to lines in a text file.
  
      Args:
        dataset: tf.dataset containing string-data.
        maxchars: int: approximate number of characters to save from dataset.
        data_keys: Tuple[str]: what keys in dataset to dump from.
  
      Returns:
        name of temp file with dataset bytes, exact number of characters dumped.
      """
      char_count = 0
      ds_iter = dataset.as_numpy_iterator()
      with tempfile.NamedTemporaryFile(
          delete=False, prefix="/tmp/ds_chars"
      ) as outfp:
          while char_count < maxchars:
              example = next(ds_iter)
              for k in data_keys:
                  line = example[k] + b"\n"
                  char_count += len(line)
                  outfp.write(line)
      return outfp.name, char_count
  
file_path: flax/flax/experimental/nnx/examples/lm1b/tokenizer.py
imports: import dataclasses
  import os
  import tempfile
  import time
  from typing import Any, Dict, Iterable, Tuple
  import jax
  import tensorflow
  import tensorflow_text
  from absl import logging
  from sentencepiece import SentencePieceTrainer
label_desc: Use image node_id 1 for calling a global function with example usage: _dump_chars_to_textfile(dataset, maxchars, data_keys) and returns: outfp,  char_count