PFEemp2024 commited on
Commit
0aa7102
·
1 Parent(s): f3621b6

addin DCWIR parameters

Browse files
Files changed (1) hide show
  1. app.py +19 -9
app.py CHANGED
@@ -46,10 +46,9 @@ def init():
46
  for attacker in ["pwws", "bae", "textfooler", "deepwordbug"]:
47
  for dataset in [
48
  "agnews10k",
49
- "amazon",
50
  "sst2",
51
- "yahoo",
52
- # 'imdb'
53
  ]:
54
  if "tad-{}".format(dataset) not in tad_classifiers:
55
  tad_classifiers[
@@ -75,7 +74,7 @@ def generate_adversarial_example(dataset, attacker, text=None, label=None):
75
  text, label = get_agnews_example()
76
  elif "sst2" in dataset.lower():
77
  text, label = get_sst2_example()
78
- elif "amazon" in dataset.lower():
79
  text, label = get_amazon_example()
80
  # elif "yahoo" in dataset.lower():
81
  # text, label = get_yahoo_example()
@@ -200,10 +199,9 @@ if __name__ == "__main__":
200
  gr.Markdown("<h1 align='center'>Detection and Correction based on Word Importance Ranking (DCWIR) </h1>")
201
  gr.Markdown("<h2 align='center'>Clarifications</h2>")
202
  gr.Markdown("""
203
- - This demo has no mechanism to ensure the adversarial example will be correctly repaired by Rapid. The repair success rate is actually the performance reported in the paper.
204
- - The adversarial example and repaired adversarial example may be unnatural to read, while it is because the attackers usually generate unnatural perturbations. Rapid does not introduce additional unnatural perturbations.
205
- - To our best knowledge, Reactive Perturbation Defocusing is a novel approach in adversarial defense. Rapid significantly (>10% defense accuracy improvement) outperforms the state-of-the-art methods.
206
- - The DeepWordBug is an unknown attacker to the adversarial detector and reactive defense module. DeepWordBug has different attacking patterns from other attackers and shows the generalizability and robustness of Rapid.
207
  """)
208
  gr.Markdown("<h2 align='center'>Natural Example Input</h2>")
209
  with gr.Group():
@@ -233,7 +231,19 @@ if __name__ == "__main__":
233
  gr.Markdown(
234
  "<h3 align='center'>To input an example, please select a dataset which the example belongs to or resembles.</h2>",
235
  )
236
-
 
 
 
 
 
 
 
 
 
 
 
 
237
  msg_text = gr.Textbox(
238
  label="Message",
239
  placeholder="This is a message box to show any error messages.",
 
46
  for attacker in ["pwws", "bae", "textfooler", "deepwordbug"]:
47
  for dataset in [
48
  "agnews10k",
 
49
  "sst2",
50
+ "MR",
51
+ 'imdb'
52
  ]:
53
  if "tad-{}".format(dataset) not in tad_classifiers:
54
  tad_classifiers[
 
74
  text, label = get_agnews_example()
75
  elif "sst2" in dataset.lower():
76
  text, label = get_sst2_example()
77
+ elif "MR" in dataset.lower():
78
  text, label = get_amazon_example()
79
  # elif "yahoo" in dataset.lower():
80
  # text, label = get_yahoo_example()
 
199
  gr.Markdown("<h1 align='center'>Detection and Correction based on Word Importance Ranking (DCWIR) </h1>")
200
  gr.Markdown("<h2 align='center'>Clarifications</h2>")
201
  gr.Markdown("""
202
+ - This demo has no mechanism to ensure the adversarial example will be correctly repaired by Rapid. The repair success rate is actually the performance reported in the paper.The user must know the resulted output for sake of demonstration.
203
+ - The adversarial example and corrected adversarial example may be unnatural to read, while it is because the attackers usually generate unnatural perturbations.
204
+ - All the proposed attacks are Black Box attack where the attacker has no access to the model parameters.
 
205
  """)
206
  gr.Markdown("<h2 align='center'>Natural Example Input</h2>")
207
  with gr.Group():
 
231
  gr.Markdown(
232
  "<h3 align='center'>To input an example, please select a dataset which the example belongs to or resembles.</h2>",
233
  )
234
+ with gr.Row():
235
+ wir_percentage = gr.Textbox(
236
+ placeholder="Enter percentage from WIR...",
237
+ label="Percentage from WIR",
238
+ )
239
+ frequency_threshold = gr.Textbox(
240
+ placeholder="Enter frequency threshold...",
241
+ label="Frequency Threshold",
242
+ )
243
+ max_candidates = gr.Textbox(
244
+ placeholder="Enter maximum number of candidates...",
245
+ label="Maximum Number of Candidates",
246
+ )
247
  msg_text = gr.Textbox(
248
  label="Message",
249
  placeholder="This is a message box to show any error messages.",