Victims API

Classifier

class Classifier[source]

Classifier is the base class of all classifiers.


TransformersClassifier

class TransformersClassifier(OpenAttack.Classifier)
__init__(model, tokenizer, embedding_layer, device=None, max_length=128, batch_size=8, lang=None)
Parameters
  • model (transformers.PreTrainedModel) – Huggingface model for classification.

  • tokenizer (transformers.PreTrainedTokenizer) – Huggingface tokenizer for classification. Default: None

  • embedding_layer – The module of embedding_layer used in transformers models. For example, BertModel.bert.embeddings.word_embeddings. Default: None

  • device (Optional[torch.device]) – Device of pytorch model. Default: “cpu” if cuda is not available else “cuda”

  • max_len – Max length of input tokens. If input token list is too long, it will be truncated. Uses None for no truncation. Default: None

  • batch_size (int) – Max batch size of this classifier.

  • lang – Language of this classifier. If is None then TransformersClassifier will intelligently select the language based on other parameters.

  • max_length (int) –

to(device)
Parameters

device (torch.device) – Device that moves model to.