class_docstr: Loads a dataset from 🤗 Datasets and prepares it as a TextAttack dataset.
  
  Args:
      name_or_dataset (:obj:`Union[str, datasets.Dataset]`):
          The dataset name as :obj:`str` or actual :obj:`datasets.Dataset` object.
          If it's your custom :obj:`datasets.Dataset` object, please pass the input and output columns via :obj:`dataset_columns` argument.
      subset (:obj:`str`, `optional`, defaults to :obj:`None`):
          The subset of the main dataset. Dataset will be loaded as :obj:`datasets.load_dataset(name, subset)`.
      split (:obj:`str`, `optional`, defaults to :obj:`"train"`):
          The split of the dataset.
      dataset_columns (:obj:`tuple(list[str], str))`, `optional`, defaults to :obj:`None`):
          Pair of :obj:`list[str]` representing list of input column names (e.g. :obj:`["premise", "hypothesis"]`)
          and :obj:`str` representing the output column name (e.g. :obj:`label`). If not set, we will try to automatically determine column names from known designs.
      label_map (:obj:`dict[int, int]`, `optional`, defaults to :obj:`None`):
          Mapping if output labels of the dataset should be re-mapped. Useful if model was trained with a different label arrangement.
          For example, if dataset's arrangement is 0 for `Negative` and 1 for `Positive`, but model's label
          arrangement is 1 for `Negative` and 0 for `Positive`, passing :obj:`{0: 1, 1: 0}` will remap the dataset's label to match with model's arrangements.
          Could also be used to remap literal labels to numerical labels (e.g. :obj:`{"positive": 1, "negative": 0}`).
      label_names (:obj:`list[str]`, `optional`, defaults to :obj:`None`):
          List of label names in corresponding order (e.g. :obj:`["World", "Sports", "Business", "Sci/Tech"]` for AG-News dataset).
          If not set, labels will printed as is (e.g. "0", "1", ...). This should be set to :obj:`None` for non-classification datasets.
      output_scale_factor (:obj:`float`, `optional`, defaults to :obj:`None`):
          Factor to divide ground-truth outputs by. Generally, TextAttack goal functions require model outputs between 0 and 1.
          Some datasets are regression tasks, in which case this is necessary.
      shuffle (:obj:`bool`, `optional`, defaults to :obj:`False`): Whether to shuffle the underlying dataset.
  
          .. note::
              Generally not recommended to shuffle the underlying dataset. Shuffling can be performed using DataLoader or by shuffling the order of indices we attack.
class_docstr_tok: ["Loads","a","dataset","from","\ud83e\udd17","Datasets","and","prepares","it","as","a","TextAttack","dataset",".","Args",":","name_or_dataset","(",":","obj",":","`","Union","[","str",",","datasets.Dataset","]","`",")",":","The","dataset","name","as",":","obj",":","`","str","`","or","actual",":","obj",":","`","datasets.Dataset","`","object",".","If","it","'s","your","custom",":","obj",":","`","datasets.Dataset","`","object",",","please","pass","the","input","and","output","columns","via",":","obj",":","`","dataset_columns","`","argument",".","subset","(",":","obj",":","`","str","`",",","`","optional","`",",","defaults","to",":","obj",":","`","None","`",")",":","The","subset","of","the","main","dataset",".","Dataset","will","be","loaded","as",":","obj",":","`","datasets.load_dataset","(","name",",","subset",")","`",".","split","(",":","obj",":","`","str","`",",","`","optional","`",",","defaults","to",":","obj",":","`","``","train","''","`",")",":","The","split","of","the","dataset",".","dataset_columns","(",":","obj",":","`","tuple","(","list","[","str","]",",","str",")",")","`",",","`","optional","`",",","defaults","to",":","obj",":","`","None","`",")",":","Pair","of",":","obj",":","`","list","[","str","]","`","representing","list","of","input","column","names","(","e.g",".",":","obj",":","`","[","``","premise","''",",","``","hypothesis","''","]","`",")","and",":","obj",":","`","str","`","representing","the","output","column","name","(","e.g",".",":","obj",":","`","label","`",")",".","If","not","set",",","we","will","try","to","automatically","determine","column","names","from","known","designs",".","label_map","(",":","obj",":","`","dict","[","int",",","int","]","`",",","`","optional","`",",","defaults","to",":","obj",":","`","None","`",")",":","Mapping","if","output","labels","of","the","dataset","should","be","re-mapped",".","Useful","if","model","was","trained","with","a","different","label","arrangement",".","For","example",",","if","dataset","'s","arrangement","is","0","for","`","Negative","`","and","1","for","`","Positive","`",",","but","model","'s","label","arrangement","is","1","for","`","Negative","`","and","0","for","`","Positive","`",",","passing",":","obj",":","`","{","0",":","1",",","1",":","0","}","`","will","remap","the","dataset","'s","label","to","match","with","model","'s","arrangements",".","Could","also","be","used","to","remap","literal","labels","to","numerical","labels","(","e.g",".",":","obj",":","`","{","``","positive","''",":","1",",","``","negative","''",":","0","}","`",")",".","label_names","(",":","obj",":","`","list","[","str","]","`",",","`","optional","`",",","defaults","to",":","obj",":","`","None","`",")",":","List","of","label","names","in","corresponding","order","(","e.g",".",":","obj",":","`","[","``","World","''",",","``","Sports","''",",","``","Business","''",",","``","Sci\/Tech","''","]","`","for","AG-News","dataset",")",".","If","not","set",",","labels","will","printed","as","is","(","e.g",".","``","0","''",",","``","1","''",",","...",")",".","This","should","be","set","to",":","obj",":","`","None","`","for","non-classification","datasets",".","output_scale_factor","(",":","obj",":","`","float","`",",","`","optional","`",",","defaults","to",":","obj",":","`","None","`",")",":","Factor","to","divide","ground-truth","outputs","by",".","Generally",",","TextAttack","goal","functions","require","model","outputs","between","0","and","1",".","Some","datasets","are","regression","tasks",",","in","which","case","this","is","necessary",".","shuffle","(",":","obj",":","`","bool","`",",","`","optional","`",",","defaults","to",":","obj",":","`","False","`",")",":","Whether","to","shuffle","the","underlying","dataset",".","..","note",":",":","Generally","not","recommended","to","shuffle","the","underlying","dataset",".","Shuffling","can","be","performed","using","DataLoader","or","by","shuffling","the","order","of","indices","we","attack","."]
code: def __init__(
      self,
      name_or_dataset,
      subset=None,
      split="train",
      dataset_columns=None,
      label_map=None,
      label_names=None,
      output_scale_factor=None,
      shuffle=False,
  ):
      if isinstance(name_or_dataset, datasets.Dataset):
          self._dataset = name_or_dataset
      else:
          self._name = name_or_dataset
          self._subset = subset
          self._dataset = datasets.load_dataset(self._name, subset)[
              split
          ]
          subset_print_str = f", subset {_cb(subset)}" if subset else ""
          textattack.shared.logger.info(
              f"Loading {_cb('datasets')} dataset {_cb(self._name)}{subset_print_str}, split {_cb(split)}."
          )
      # Input/output column order, like (('premise', 'hypothesis'), 'label')
      (
          self.input_columns,
          self.output_column,
      ) = dataset_columns or get_datasets_dataset_columns(self._dataset)
  
      if not isinstance(self.input_columns, (list, tuple)):
          raise ValueError(
              "First element of `dataset_columns` must be a list or a tuple."
          )
  
      self.label_map = label_map
      self.output_scale_factor = output_scale_factor
      if label_names:
          self.label_names = label_names
      else:
          try:
              self.label_names = self._dataset.features[
                  self.output_column
              ].names
          except (KeyError, AttributeError):
              # This happens when the dataset doesn't have 'features' or a 'label' column.
              self.label_names = None
  
      # If labels are remapped, the label names have to be remapped as well.
      if self.label_names and label_map:
          self.label_names = [
              self.label_names[self.label_map[i]]
              for i in self.label_map
          ]
  
      self.shuffled = shuffle
      if shuffle:
          self._dataset.shuffle()
  
file_path: TextAttack/textattack/datasets/huggingface_dataset.py
imports: import collections
  import datasets
  import textattack
  from .dataset import Dataset
label_desc: Use image node_id 1 to create a new HuggingFaceDataset object from inherited base classes: Dataset with example: obj = HuggingFaceDataset(name_or_dataset, subset, split, dataset_columns, label_map, label_names, output_scale_factor, shuffle)