Skip to content

Commit

Permalink
Merge pull request #563 from QData/Add-Docstrings-to-Back-Translation
Browse files Browse the repository at this point in the history
Add API docstrings for back translation
  • Loading branch information
qiyanjun committed Nov 5, 2021
2 parents e33f73b + be28758 commit d009b60
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 2 deletions.
4 changes: 2 additions & 2 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,11 @@
]

extras["tensorflow"] = [
"tensorflow>=2",
"tensorflow==2.5.0",
"tensorflow_hub",
"tensorflow_text>=2",
"tensorboardX",
"tensorflow-estimator==2.6.0",
"tensorflow-estimator==2.5.0",
]

extras["optional"] = [
Expand Down
11 changes: 11 additions & 0 deletions tests/test_augment_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -91,3 +91,14 @@ def test_deletion_augmenter():
augmented_text_list = augmenter.augment(s)
augmented_s = "United States"
assert augmented_s in augmented_text_list


def test_back_translation():
from textattack.augmentation import Augmenter
from textattack.transformations.sentence_transformations import BackTranslation

augmenter = Augmenter(transformation=BackTranslation())
s = "What on earth are you doing?"
augmented_text_list = augmenter.augment(s)
augmented_s = "What the hell are you doing?"
assert augmented_s in augmented_text_list
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,19 @@ class BackTranslation(SentenceTransformation):
src_model: translation model from huggingface that translates from source language to target language
target_model: translation model from huggingface that translates from target language to source language
chained_back_translation: run back translation in a chain for more perturbation (for example, en-es-en-fr-en)
Example::
>>> from textattack.transformations.sentence_transformations import BackTranslation
>>> from textattack.constraints.pre_transformation import RepeatModification, StopwordModification
>>> from textattack.augmentation import Augmenter
>>> transformation = BackTranslation
>>> constraints = [RepeatModification(), StopwordModification()]
>>> augmenter = Augmenter(transformation = transformation, constraints = constraints)
>>> s = 'What on earth are you doing here.'
>>> augmenter.augment(s)
"""

def __init__(
Expand Down

0 comments on commit d009b60

Please sign in to comment.