You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Issue with using AttackArgs class outside of the command line (in my Python script) #728
I am experiencing an issue when trying to use the AttackArgs class from the TextAttack library outside of the command line. I'm attempting to use the class programmatically in my Python script, but the arguments I provide are not correctly assigned.
When I run the code, the num_examples values are not updated and remain at their default values. However, it seems that other arguments like num_successful_examples or log_to_csv are being correctly assigned.
I suspect this might be related to the class implementation, specifically the _add_parser_args method, which seems to be designed for command-line usage. Is there a way to use the AttackArgs class programmatically in a Python script without relying on the command line interface? Any guidance or suggestions would be appreciated.
I discovered that the issue with num_examples being set to None is due to the following code snippet in the AttackArgs class:
def post_init(self):
if self.num_successful_examples:
self.num_examples = None
This is causing num_examples to be set to None when a value is assigned to num_successful_examples.
I would like to understand if this behavior is intentional and, if so, the rationale behind it. Is it to prevent users from specifying both num_examples and num_successful_examples simultaneously? If this is a design choice, could you please provide guidance on how to use these options properly in cases where we want to limit the total number of examples while also specifying the number of successful adversarial examples desired? If this is a bug, can you suggest a workaround or provide an update to fix the issue?
@sabrinahartung you diagnosed this exactly right — it's intentional (per the docstring: "If set, this argument overrides `num_examples`"), but silently dropping the value you passed with no explanation is a bad experience. Opened #831, which adds a warning when both are set together, so this is at least discoverable without reading the source. Will close automatically once that merges.
Activity
sabrinahartung commentedon Apr 14, 2023
I discovered that the issue with
num_examplesbeing set toNoneis due to the following code snippet in theAttackArgsclass:def post_init(self):
if self.num_successful_examples:
self.num_examples = None
This is causing
num_examplesto be set toNonewhen a value is assigned tonum_successful_examples.I would like to understand if this behavior is intentional and, if so, the rationale behind it. Is it to prevent users from specifying both
num_examplesandnum_successful_examplessimultaneously? If this is a design choice, could you please provide guidance on how to use these options properly in cases where we want to limit the total number of examples while also specifying the number of successful adversarial examples desired? If this is a bug, can you suggest a workaround or provide an update to fix the issue?qiyanjun commentedon Aug 13, 2026
@sabrinahartung you diagnosed this exactly right — it's intentional (per the docstring: "If set, this argument overrides `num_examples`"), but silently dropping the value you passed with no explanation is a bad experience. Opened #831, which adds a warning when both are set together, so this is at least discoverable without reading the source. Will close automatically once that merges.
Fix two more review findings from PR QData#831
Fix six more bugs from the unresolved-bugs triage list