SforAiDl/decepticonlp

Adding a transforms class [check details]

Closed this issue · 5 comments

  • To add a transforms class (similar to PyTorch transforms)
  • Should be able to compose various transforms (ex: char perturbations) and apply them to a text sample
  • An analogy can be drawn:
#Torchvision
transform = transforms.compose([rotate, crop, resize, grayscale])
transformed_image = transfrom.apply(image)
#AdvNLP
transform = transforms.compose([add, swap, delete, visually_similar])
transformed_text = transfrom.apply(text)

Where add, swap, delete etc are the object instances of their respective classes
This enhancement needs a lot of discussion before actually starting with the implementation. So plz do let us know if you have any ideas

The user can input anything, like a word/sentence/document, right? So, for character perturbations, what we can do is:

  1. Make subclasses of the transforms class where we call the functions from perturbations.py. These act on one word alone. For example, classes like transforms.Add, transforms.Delete, etc.
  2. Now, since a text sample will contain multiple words, we can use functions from extractor.py to extract the important words' indices (I think the RandomWordExtractor class has been implemented) and apply the above mentioned transforms to those words only.

@abheesht17 That's exactly what we need to do. Are you willing to take this up?

Yep, I'll do it.

Resolved in #69 by @abheesht17