class_docstr: Preprocessor for a BERT-based classifier.
  
  Attributes:
    seq_len: Length of the input sequence to the model.
    vocab_file: File containing the BERT vocab.
    tokenizer: BERT tokenizer.
    model_name: Name of the model provided by the model_spec. Used to associate
      cached files with specific Bert model vocab.
    preprocessor: Which preprocessor to use. Must be one of the enum values of
      SupportedBertPreprocessors.
class_docstr_tok: ["Preprocessor","for","a","BERT-based","classifier",".","Attributes",":","seq_len",":","Length","of","the","input","sequence","to","the","model",".","vocab_file",":","File","containing","the","BERT","vocab",".","tokenizer",":","BERT","tokenizer",".","model_name",":","Name","of","the","model","provided","by","the","model_spec",".","Used","to","associate","cached","files","with","specific","Bert","model","vocab",".","preprocessor",":","Which","preprocessor","to","use",".","Must","be","one","of","the","enum","values","of","SupportedBertPreprocessors","."]
docstr: Preprocesses data into input for a BERT-based classifier.
  
  Args:
    dataset: Stores (text, label) data.
  
  Returns:
    Dataset containing (bert_features, label) data.
docstr_tok: ["Preprocesses","data","into","input","for","a","BERT-based","classifier",".","Args",":","dataset",":","Stores","(","text",",","label",")","data",".","Returns",":","Dataset","containing","(","bert_features",",","label",")","data","."]
code: def preprocess(
      self, dataset: text_classifier_ds.Dataset
  ) -> text_classifier_ds.Dataset:
      """Preprocesses data into input for a BERT-based classifier.
  
      Args:
        dataset: Stores (text, label) data.
  
      Returns:
        Dataset containing (bert_features, label) data.
      """
      ds_cache_files = dataset.tfrecord_cache_files
      # Get new tfrecord_cache_files by including preprocessor information.
      tfrecord_cache_files = self._get_tfrecord_cache_files(
          ds_cache_files
      )
      if not tfrecord_cache_files.is_cached():
          print(
              f"Writing new cache files to {tfrecord_cache_files.cache_prefix}"
          )
          writers = tfrecord_cache_files.get_writers()
          size = 0
          for index, (text, label) in enumerate(
              dataset.gen_tf_dataset()
          ):
              _validate_text_and_label(text, label)
              feature = self._tokenizer.process(text)
  
              def create_int_feature(values):
                  f = tf.train.Feature(
                      int64_list=tf.train.Int64List(value=values)
                  )
                  return f
  
              features = collections.OrderedDict()
              features["input_word_ids"] = create_int_feature(
                  feature["input_word_ids"]
              )
              features["input_mask"] = create_int_feature(
                  feature["input_mask"]
              )
              features["input_type_ids"] = create_int_feature(
                  feature["input_type_ids"]
              )
              features["label_ids"] = create_int_feature(
                  label.numpy().tolist()
              )
              tf_example = tf.train.Example(
                  features=tf.train.Features(feature=features)
              )
              writers[index % len(writers)].write(
                  tf_example.SerializeToString()
              )
              size = index + 1
          for writer in writers:
              writer.close()
          metadata = {"size": size, "label_names": dataset.label_names}
          tfrecord_cache_files.save_metadata(metadata)
      else:
          print(
              f"Using existing cache files at {tfrecord_cache_files.cache_prefix}"
          )
          metadata = tfrecord_cache_files.load_metadata()
      size = metadata["size"]
      label_names = metadata["label_names"]
      preprocessed_ds = _tfrecord_dataset(
          tfrecord_cache_files.tfrecord_files,
          self._get_name_to_features(),
      )
      return text_classifier_ds.Dataset(
          dataset=preprocessed_ds,
          size=size,
          label_names=label_names,
          tfrecord_cache_files=tfrecord_cache_files,
      )
  
imports: import collections
  import hashlib
  import os
  import re
  from typing import Mapping, Sequence, Tuple, Union
  import tensorflow
  import tensorflow_hub
  from mediapipe.model_maker.python.core.data import cache_files
  from mediapipe.model_maker.python.text.text_classifier import bert_tokenizer
  from mediapipe.model_maker.python.text.text_classifier import dataset
label_desc: Use image node_id 5 for calling the BertClassifierPreprocessor obj's underlying member method code with example usage: obj.preprocess(dataset) and returns: text_classifier_ds, f