Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Issue with using AttackArgs class outside of the command line (in my Python script) #728

Open
sabrinagoellner opened this issue Apr 14, 2023 · 1 comment

Comments

@sabrinagoellner
Copy link

sabrinagoellner commented Apr 14, 2023

Hello,

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.

Here's a code snippet demonstrating my problem:

from textattack.attack_args import AttackArgs

attack_args = AttackArgs(
num_examples=100, 
num_successful_examples=2, 
log_to_csv="text_attack_results.csv"
)

print(attack_args)

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.

Thank you for your assistance.

System Information:

  • OS: MacOS Ventura 13.1
  • Textattack version: 0.3.8
@sabrinagoellner
Copy link
Author

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?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant