class_docstr: A text dataset with one sequence as input and a label.
class_docstr_tok: ["A","text","dataset","with","one","sequence","as","input","and","a","label","."]
docstr: Initializes the SST2 data source.
docstr_tok: ["Initializes","the","SST2","data","source","."]
code: def __init__(
      self,
      tfds_name: str = "glue/sst2",
      vocab_path: str = "vocab.txt",
      tokenizer: text.Tokenizer = text.WhitespaceTokenizer(),
      split="train",
  ):
      """Initializes the SST2 data source."""
      self.dataset, self.info = tfds.load(
          tfds_name, split=split, with_info=True
      )
  
      # Look up the feature name of the text and label in the dataset.
      # We assume there is one text input and one label.
      text_fields = filter(_is_text_field, self.info.features.items())
      label_fields = filter(_is_class_label, self.info.features.items())
      self.text_feature_name, _ = next(text_fields)
      self.label_feature_name, _ = next(label_fields)
  
      # Load the vocabulary.
      self.vocab = vocabulary.Vocabulary(vocab_path=vocab_path)
  
      # Convert the sentences to sequences of token IDs and compute length.
      self.tokenizer = tokenizer
      self.tf_vocab = vocab_to_hashtable(
          self.vocab, unk_idx=self.vocab.unk_idx
      )
      self.examples = self.dataset.map(
          self.prepare_example, num_parallel_calls=AUTOTUNE
      ).cache()
  
imports: from typing import Any, Dict, Optional
  from absl import logging
  import numpy
  import tensorflow
  import tensorflow_datasets
  import tensorflow_text
  import vocabulary
label_desc: Use image node_id 1 to create a new TextDataset object  with example: obj = TextDataset(tfds_name, vocab_path, tokenizer, split)