anonauthors commited on
Commit
200e1d7
β€’
1 Parent(s): 6c946b2

Update pages/2_😈_BlackBox_and_WhiteBox_Attacks.py

Browse files
pages/2_😈_BlackBox_and_WhiteBox_Attacks.py CHANGED
@@ -19,14 +19,14 @@ all_keys = [i.strip() for i in all_keys]
19
 
20
  set_seed(0)
21
  # sidebar instructions
22
- st.sidebar.markdown('On this page, we offer a tool for generating replacement words using secret languages.')
23
  st.sidebar.markdown('#### Require ')
24
  st.sidebar.markdown('`Input text`: a sentence or paragraph.')
25
- st.sidebar.markdown('`Number of replacements`: the number of secret language samples.')
26
  st.sidebar.markdown('`Steps for searching Secret Langauge`: the steps in the SecretFinding process.')
27
  st.sidebar.markdown('#### Two methods')
28
- st.sidebar.markdown('1. Searching secret languages based on models: this method calculates secret languages using [gpt2](https://huggingface.co/gpt2), [gpt-medium](https://huggingface.co/gpt2-medium), [EleutherAI/gpt-neo-1.3B](https://huggingface.co/EleutherAI/gpt-neo-1.3B)') #, [EleutherAI/gpt-neo-2.7B](https://huggingface.co/EleutherAI/gpt-neo-2.7B), [EleutherAI/gpt-neox-20b](https://huggingface.co/EleutherAI/gpt-neox-20b), or [EleutherAI/gpt-j-6B](https://huggingface.co/EleutherAI/gpt-j-6B).')
29
- st.sidebar.markdown('2. Use the secret language we found on ALBERT, DistillBERT, and Roberta: this method replaces words directly with the secret language dictionary derived from ALBERT, DistillBERT, and Roberta.')
30
 
31
  st.sidebar.markdown('#### Return')
32
  st.sidebar.markdown(
@@ -256,12 +256,12 @@ def clf_keys():
256
  # main page
257
  option = st.selectbox(
258
  'Which method you would like to use?',
259
- ('Searching secret languages based on models', 'Use the secret language we found on ALBERT, DistillBERT, and Roberta.')
260
  )
261
 
262
  title = st.text_area('Input text.', 'Which name is also used to describe the Amazon rainforest in English?', on_change=clf_keys)
263
 
264
- if option == 'Searching secret languages based on models':
265
  model_choice = st.selectbox(
266
  'Which model you would like to use?',
267
  # ('gpt2', "EleutherAI/gpt-neo-1.3B", "EleutherAI/gpt-neo-2.7B", "EleutherAI/gpt-neox-20b", "EleutherAI/gpt-j-6B")
@@ -274,7 +274,7 @@ else:
274
  restarts = st.number_input('Number of replacements.', value=10, min_value=1, step=1, format='%d')
275
 
276
  if button('Tokenize', key='tokenizer'):
277
- if option == 'Searching secret languages based on models':
278
  tokenizer = AutoTokenizer.from_pretrained(model_choice)
279
  else:
280
  tokenizer = AutoTokenizer.from_pretrained('gpt2')
@@ -292,7 +292,7 @@ if button('Tokenize', key='tokenizer'):
292
  _index = i * 6 + j
293
  if _index < _len:
294
  disable = False
295
- if option == 'Use the secret language we found on ALBERT, DistillBERT, and Roberta.':
296
  if subwords[_index].strip() not in all_keys:
297
  disable = True
298
  # if f'tokenizer_{_index}' in st.session_state:
@@ -312,7 +312,7 @@ if button('Tokenize', key='tokenizer'):
312
  if _index < len(input_ids):
313
  chose_indices.append(_index)
314
  if len(chose_indices):
315
- if option == 'Searching secret languages based on models':
316
  model = AutoModelForCausalLM.from_pretrained(model_choice)
317
  generator = pipeline('text-generation', model='gpt2')
318
  if not platform.system().lower() == 'darwin':
@@ -328,7 +328,7 @@ if button('Tokenize', key='tokenizer'):
328
  st.markdown(f'The response of [Codex](https://openai.com/blog/openai-codex/) with the prompt :blue[{title}]')
329
  st.markdown('<blockquote>' + output_openai + '</blockquote>', unsafe_allow_html=True)
330
 
331
- if option == 'Searching secret languages based on models':
332
  _bar_text = st.empty()
333
  bar = st.progress(0)
334
  outputs = run(model, tokenizer, model.transformer.wte,
 
19
 
20
  set_seed(0)
21
  # sidebar instructions
22
+ st.sidebar.markdown('On this page, we offer a tool for generating replacement words using obstinate adversarial substituitions.')
23
  st.sidebar.markdown('#### Require ')
24
  st.sidebar.markdown('`Input text`: a sentence or paragraph.')
25
+ st.sidebar.markdown('`Number of replacements`: the number of obstinate adversarial examples.')
26
  st.sidebar.markdown('`Steps for searching Secret Langauge`: the steps in the SecretFinding process.')
27
  st.sidebar.markdown('#### Two methods')
28
+ st.sidebar.markdown('1. Searching obstinate adversarial examples based on models: this method calculates obstinate adversarial examples using [gpt2](https://huggingface.co/gpt2), [gpt-medium](https://huggingface.co/gpt2-medium), [EleutherAI/gpt-neo-1.3B](https://huggingface.co/EleutherAI/gpt-neo-1.3B)') #, [EleutherAI/gpt-neo-2.7B](https://huggingface.co/EleutherAI/gpt-neo-2.7B), [EleutherAI/gpt-neox-20b](https://huggingface.co/EleutherAI/gpt-neox-20b), or [EleutherAI/gpt-j-6B](https://huggingface.co/EleutherAI/gpt-j-6B).')
29
+ st.sidebar.markdown('2. Use the obstinate adversarial substituitions we found on ALBERT, DistillBERT, and Roberta: this method replaces words directly with the obstinate adversarial substituitions dictionary derived from ALBERT, DistillBERT, and Roberta.')
30
 
31
  st.sidebar.markdown('#### Return')
32
  st.sidebar.markdown(
 
256
  # main page
257
  option = st.selectbox(
258
  'Which method you would like to use?',
259
+ ('Searching obstinate adversarial examples based on models', 'Use the obstinate adversarial substitutions we found on ALBERT, DistillBERT, and Roberta.')
260
  )
261
 
262
  title = st.text_area('Input text.', 'Which name is also used to describe the Amazon rainforest in English?', on_change=clf_keys)
263
 
264
+ if option == 'Searching obstinate adversarial examples based on models':
265
  model_choice = st.selectbox(
266
  'Which model you would like to use?',
267
  # ('gpt2', "EleutherAI/gpt-neo-1.3B", "EleutherAI/gpt-neo-2.7B", "EleutherAI/gpt-neox-20b", "EleutherAI/gpt-j-6B")
 
274
  restarts = st.number_input('Number of replacements.', value=10, min_value=1, step=1, format='%d')
275
 
276
  if button('Tokenize', key='tokenizer'):
277
+ if option == 'Searching obstinate adversarial examples based on models':
278
  tokenizer = AutoTokenizer.from_pretrained(model_choice)
279
  else:
280
  tokenizer = AutoTokenizer.from_pretrained('gpt2')
 
292
  _index = i * 6 + j
293
  if _index < _len:
294
  disable = False
295
+ if option == 'Use the obstinate adversarial substituitions we found on ALBERT, DistillBERT, and Roberta.':
296
  if subwords[_index].strip() not in all_keys:
297
  disable = True
298
  # if f'tokenizer_{_index}' in st.session_state:
 
312
  if _index < len(input_ids):
313
  chose_indices.append(_index)
314
  if len(chose_indices):
315
+ if option == 'Searching obstinate adversarial examples based on models':
316
  model = AutoModelForCausalLM.from_pretrained(model_choice)
317
  generator = pipeline('text-generation', model='gpt2')
318
  if not platform.system().lower() == 'darwin':
 
328
  st.markdown(f'The response of [Codex](https://openai.com/blog/openai-codex/) with the prompt :blue[{title}]')
329
  st.markdown('<blockquote>' + output_openai + '</blockquote>', unsafe_allow_html=True)
330
 
331
+ if option == 'Searching obstinate adversarial examples based on models':
332
  _bar_text = st.empty()
333
  bar = st.progress(0)
334
  outputs = run(model, tokenizer, model.transformer.wte,