docstr: Data object for loading a plain text file.
  
  Args:
      fpath, path to the text file.
      train_ratio, split the text file into train and test sets, where
          train_ratio of the characters are in the train set.
docstr_tok: ["Data","object","for","loading","a","plain","text","file",".","Args",":","fpath",",","path","to","the","text","file",".","train_ratio",",","split","the","text","file","into","train","and","test","sets",",","where","train_ratio","of","the","characters","are","in","the","train","set","."]
code: def __init__(
      self, fpath, batch_size=32, seq_length=100, train_ratio=0.8
  ):
      """Data object for loading a plain text file.
  
      Args:
          fpath, path to the text file.
          train_ratio, split the text file into train and test sets, where
              train_ratio of the characters are in the train set.
      """
      self.raw_data = open(
          fpath, "r", encoding="iso-8859-1"
      ).read()  # read text file
      chars = list(set(self.raw_data))
      self.vocab_size = len(chars)
      self.char_to_idx = {ch: i for i, ch in enumerate(chars)}
      self.idx_to_char = {i: ch for i, ch in enumerate(chars)}
      data = [self.char_to_idx[c] for c in self.raw_data]
      # seq_length + 1 for the data + label
      nsamples = len(data) // (1 + seq_length)
      data = data[0 : nsamples * (1 + seq_length)]
      data = np.asarray(data, dtype=np.int32)
      data = np.reshape(data, (-1, seq_length + 1))
      # shuffle all sequences
      np.random.shuffle(data)
      self.train_dat = data[0 : int(data.shape[0] * train_ratio)]
      self.num_train_batch = self.train_dat.shape[0] // batch_size
      self.val_dat = data[self.train_dat.shape[0] :]
      self.num_test_batch = self.val_dat.shape[0] // batch_size
      print("train dat", self.train_dat.shape)
      print("val dat", self.val_dat.shape)
  
imports: from __future__ import division
  from __future__ import print_function
  from builtins import range
  import numpy
  import sys
  import argparse
  from tqdm import tqdm
  from singa import device
  from singa import tensor
  from singa import autograd
  from singa import layer
  from singa import model
  from singa import opt
label_desc: Use image node_id 1 to create a new Data object from inherited base classes: object with example: obj = Data(fpath, batch_size, seq_length, train_ratio)