|
""" |
|
|
|
Input Reduction |
|
==================== |
|
(Pathologies of Neural Models Make Interpretations Difficult) |
|
|
|
""" |
|
from textattack import Attack |
|
from textattack.constraints.pre_transformation import ( |
|
RepeatModification, |
|
StopwordModification, |
|
) |
|
from textattack.goal_functions import InputReduction |
|
from textattack.search_methods import GreedyWordSwapWIR |
|
from textattack.transformations import WordDeletion |
|
|
|
from .attack_recipe import AttackRecipe |
|
|
|
|
|
class InputReductionFeng2018(AttackRecipe): |
|
"""Feng, Wallace, Grissom, Iyyer, Rodriguez, Boyd-Graber. (2018). |
|
|
|
Pathologies of Neural Models Make Interpretations Difficult. |
|
|
|
https://arxiv.org/abs/1804.07781 |
|
""" |
|
|
|
@staticmethod |
|
def build(model_wrapper): |
|
|
|
|
|
transformation = WordDeletion() |
|
|
|
constraints = [RepeatModification(), StopwordModification()] |
|
|
|
|
|
|
|
goal_function = InputReduction(model_wrapper, maximizable=True) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
search_method = GreedyWordSwapWIR(wir_method="delete") |
|
|
|
return Attack(goal_function, constraints, transformation, search_method) |
|
|