Dataset

OpenBackdoor integrates 5 tasks and 11 datasets, which can be downloaded from bash scripts in datasets. We list the tasks and datasets below:

  • Sentiment Analysis: SST-2, IMDB

  • Toxic Detection: Offenseval, Jigsaw, HSOL, Twitter

  • Topic Classification: AG’s News, DBpedia

  • Spam Detection: Enron, Lingspam

  • Natural Language Inference: MNLI

APIs

Base class of data processor

class openbackdoor.DataProcessor(labels: Optional[Sequence[Any]] = None, labels_path: Optional[str] = None)[source]

Base class for data processor.

Parameters:
  • labels (Sequence[Any], optional) – class labels of the dataset. Defaults to None.

  • labels_path (str, optional) – Defaults to None. If set and labels is None, load labels from labels_path.

get_dev_examples(data_dir: Optional[str] = None, shuffle: Optional[bool] = True)[source]

get dev examples from the development file under data_dir

abstract get_examples(data_dir: Optional[str] = None, split: Optional[str] = None)[source]

get the split of dataset under data_dir

data_dir is the base path of the dataset, for example:

training file could be located in data_dir/train.txt

Parameters:
  • data_dir (str) – the base path of the dataset

  • split (str) – train / dev / test / unlabeled

Returns:

return a list of tuples`

Return type:

List

get_label_id(label: Any) int[source]

get label id of the corresponding label

Parameters:

label – label in dataset

Returns:

the index of label

Return type:

int

get_labels() List[Any][source]

get labels of the dataset

Returns:

labels of the dataset

Return type:

List[Any]

get_num_labels()[source]

get the number of labels in the dataset

Returns:

number of labels in the dataset

Return type:

int

get_test_examples(data_dir: Optional[str] = None, shuffle: Optional[bool] = True)[source]

get test examples from the test file under data_dir

get_train_examples(data_dir: Optional[str] = None, shuffle: Optional[bool] = True)[source]

get train examples from the training file under data_dir

get_unlabeled_examples(data_dir: Optional[str] = None)[source]

get unlabeled examples from the unlabeled file under data_dir