|
""" |
|
MORPHEUS2020 |
|
=============== |
|
(It’s Morphin’ Time! Combating Linguistic Discrimination with Inflectional Perturbations) |
|
|
|
|
|
""" |
|
from textattack import Attack |
|
from textattack.constraints.pre_transformation import ( |
|
RepeatModification, |
|
StopwordModification, |
|
) |
|
from textattack.goal_functions import MinimizeBleu |
|
from textattack.search_methods import GreedySearch |
|
from textattack.transformations import WordSwapInflections |
|
|
|
from .attack_recipe import AttackRecipe |
|
|
|
|
|
class MorpheusTan2020(AttackRecipe): |
|
"""Samson Tan, Shafiq Joty, Min-Yen Kan, Richard Socher. |
|
|
|
It’s Morphin’ Time! Combating Linguistic Discrimination with Inflectional Perturbations |
|
|
|
https://www.aclweb.org/anthology/2020.acl-main.263/ |
|
""" |
|
|
|
@staticmethod |
|
def build(model_wrapper): |
|
|
|
|
|
|
|
|
|
goal_function = MinimizeBleu(model_wrapper) |
|
|
|
|
|
transformation = WordSwapInflections() |
|
|
|
|
|
|
|
|
|
constraints = [RepeatModification(), StopwordModification()] |
|
|
|
|
|
|
|
|
|
search_method = GreedySearch() |
|
|
|
return Attack(goal_function, constraints, transformation, search_method) |
|
|