Skip to content

BackTranslationAugmenter produces an incorrect number of transformations #800

Closed

Description

@aemartinez

Describe the bug
Calling the augment function of a BackTranslationAugmenter produces a list with a length that appears to be non-deterministic, sometimes not matching the value of the transformations_per_example initialization parameter.

To Reproduce
Run the following code:

import textattack
augmenter = textattack.augmentation.recipes.BackTranslationAugmenter(transformations_per_example=5)
s = "You are in the kitchen."
ls = augmenter.augment(s)
print(len(ls))

Expected behavior
Expected output: 5
Actual output: 3

System Information (please complete the following information):

  • OS: MacOS Sonoma 14.6.1
  • Library versions: torch==2.3.1, transformers==4.42.4
  • Textattack version: textattack==0.3.10
  • Full pip freeze output: https://pastebin.com/VPt7JdRY

Activity

  1. qiyanjun commented on Aug 13, 2026

    @qiyanjun
    Member

    Root cause: Augmenter.augment accumulates results in a set() but only ever attempts exactly transformations_per_example outer-loop calls to the transformation. BackTranslationAugmenter defaults to chained_back_translation=5 (randomly chained through 5 languages), and for a short sentence like yours, two of those attempts can easily land on the identical final phrasing — the set silently collapses the duplicate, so you get fewer results than requested. It's not really about back-translation specifically; any transformation with limited output diversity for a given input hits this.

    Opened #831 with a bounded retry (up to 3x the requested count) so the loop backfills collisions instead of accepting a short result. Transformations with large search spaces (the common case) see zero behavior change. Will close automatically once that merges.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions