<commit_before>import numpy as np
from abc import ABCMeta, abstractmethod


class Attack:
    """
    Abstract base class for all attack classes.
    """
    __metaclass__ = ABCMeta

    def __init__(self, x, pred, y=None, backend='tf',
                 clip_min=None, clip_max=None, other_params={}):
        """
        :param x: A placeholder for the model inputs.
        :param pred: The model's symbolic output.
        :param y: A placeholder for the model inputs. Only provide this
                  parameter if you'd like to use the true labels when crafting
                  adversarial samples. Otherwise, model predictions are used as
                  labels to avoid the label leaking effect. Default is None.
        :param backend: A string indicating which backend to use. Must be
                        either 'tf' or 'th'. Default is 'tf'.
        :param clip_min: Optional float parameter that can be used to set a
                         minimum value for components of the example returned.
        :param clip_max: Optional float parameter that can be used to set a
                         maximum value for components of the example returned.
        :param other_params: Dictionary holding the other parameters needed for
                            various child classes
        """
        assert backend == 'tf' or backend == 'th'
        self.x = x
        self.pred = pred
        self.y = y
        self.backend = backend
        self.clip_min = clip_min
        self.clip_max = clip_max

    def generate_symbolic(self):
        """
        Generate symbolic graph for adversarial samples and return. This
        method should be overwritten in any child class which has a
        symbolic implementation available.
        """
        raise NotImplementedError("The symbolic version of this attack "
                                  "is not currently implemented.")

    @abstractmethod
    def generate_numpy(self, sess):
        """
        Generate adversarial samples and return them in a Numpy array.
        """
        if self.backend == 'tf':
            # Using TensorFlow backend; must pass a session argument.
            assert sess is not None
        else:
            # Using Theano backend; no session required.
            assert sess is None<commit_msg>updates to the Attack class docstring<commit_after>import numpy as np
from abc import ABCMeta, abstractmethod


class Attack:
    """
    Abstract base class for all attack classes. All attacks must override the
    generate_numpy method that returns the adversarial examples corresponding
    to the input data. However, the generate_symbolic method is optional.
    """
    __metaclass__ = ABCMeta

    def __init__(self, x, pred, y=None, backend='tf',
                 clip_min=None, clip_max=None, other_params={}):
        """
        :param x: A placeholder for the model inputs.
        :param pred: The model's symbolic output.
        :param y: A placeholder for the model labels. Only provide this
                  parameter if you'd like to use the true labels when crafting
                  adversarial samples. Otherwise, model predictions are used as
                  labels to avoid the label leaking effect. This phenomenon
                  is explained in this paper: https://arxiv.org/abs/1611.01236)
                  Default value is None.
        :param backend: A string indicating which backend to use. Must be
                        either 'tf' or 'th'. Default is 'tf'.
        :param clip_min: Optional float parameter that can be used to set a
                         minimum value for components of the example returned.
        :param clip_max: Optional float parameter that can be used to set a
                         maximum value for components of the example returned.
        :param other_params: Dictionary holding the other parameters needed for
                            various child classes
        """
        assert backend == 'tf' or backend == 'th', 'Backend must be tf or th'
        self.x = x
        self.pred = pred
        self.y = y
        self.backend = backend
        self.clip_min = clip_min
        self.clip_max = clip_max

    def generate_symbolic(self):
        """
        Generate symbolic graph for adversarial samples and return. This
        method should be overwritten in any child class which has a
        symbolic implementation available.
        """
        raise NotImplementedError("The symbolic version of this attack "
                                  "is not currently implemented.")

    @abstractmethod
    def generate_numpy(self, sess):
        """
        Generate adversarial samples and return them in a Numpy array.
        """
        if self.backend == 'tf':
            # Using TensorFlow backend; must pass a session argument.
            assert sess is not None
        else:
            # Using Theano backend; no session required.
            assert sess is None
{'fraction_non_alphanumeric': 0.05727491961414791, 'fraction_numerical': 0.0018086816720257234, 'mean_word_length': 1.931095406360424, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 1, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7280694', 'n_tokens_mistral': 1179, 'n_tokens_neox': 1124, 'n_words': 538}