class_docstr: ```
  Wrapper for Transformer datasets.
  ```
class_docstr_tok: ["``","`","Wrapper","for","Transformer","datasets",".","``","`"]
docstr: ```
  convert transformer features to tf.Dataset
  ```
docstr_tok: ["``","`","convert","transformer","features","to","tf.Dataset","``","`"]
code: def to_tfdataset(self, train=True):
      """
      ```
      convert transformer features to tf.Dataset
      ```
      """
      if train:
          shuffle = True
          repeat = True
      else:
          shuffle = False
          repeat = False
  
      if len(self.y.shape) == 1:
          yshape = []
          ytype = tf.float32
      else:
          yshape = [None]
          ytype = tf.int64
  
      if self.use_token_type_ids:
  
          def gen():
              for idx, data in enumerate(self.x):
                  yield (
                      {
                          "input_ids": data[0],
                          "attention_mask": data[1],
                          "token_type_ids": data[2],
                      },
                      self.y[idx],
                  )
  
          tfdataset = tf.data.Dataset.from_generator(
              gen,
              (
                  {
                      "input_ids": tf.int32,
                      "attention_mask": tf.int32,
                      "token_type_ids": tf.int32,
                  },
                  ytype,
              ),
              (
                  {
                      "input_ids": tf.TensorShape([None]),
                      "attention_mask": tf.TensorShape([None]),
                      "token_type_ids": tf.TensorShape([None]),
                  },
                  tf.TensorShape(yshape),
              ),
          )
      else:
  
          def gen():
              for idx, data in enumerate(self.x):
                  yield (
                      {
                          "input_ids": data[0],
                          "attention_mask": data[1],
                      },
                      self.y[idx],
                  )
  
          tfdataset = tf.data.Dataset.from_generator(
              gen,
              (
                  {
                      "input_ids": tf.int32,
                      "attention_mask": tf.int32,
                  },
                  ytype,
              ),
              (
                  {
                      "input_ids": tf.TensorShape([None]),
                      "attention_mask": tf.TensorShape([None]),
                  },
                  tf.TensorShape(yshape),
              ),
          )
  
      if shuffle:
          tfdataset = tfdataset.shuffle(self.x.shape[0])
      tfdataset = tfdataset.batch(self.batch_size)
      if repeat:
          tfdataset = tfdataset.repeat(-1)
      return tfdataset
  
file_path: ktrain/ktrain/text/dataset.py
imports: from ..dataset import SequenceDataset
  from ..imports import *
label_desc: Use image node_id 4 for calling the TransformerDataset obj's underlying member method code with example usage: obj.to_tfdataset(train) and returns: tfdataset