QData / TextAttack

TextAttack 🐙 is a Python framework for adversarial attacks, data augmentation, and model training in NLP https://textattack.readthedocs.io/en/master/
https://textattack.readthedocs.io/en/master/
MIT License
2.98k stars 397 forks source link

Could TextAttack only attack substring of input. #733

Open ludybupt opened 1 year ago

ludybupt commented 1 year ago

I would like to employ TextAttack for further research. does TextAttack support setting attack range of input text?

jxmorris12 commented 1 year ago

Yes, definitely. You can implement a PreTransformationConstraint that filters out transformations to the words that you don't want to alter. Here's an example, which we used to prevent modifying the premise (or hypothesis) in SNLI: https://github.com/QData/TextAttack/blob/master/textattack/constraints/pre_transformation/input_column_modification.py#L11