Spaces:
Runtime error
Runtime error
anonymousauthors
commited on
Commit
β’
b3aa6b8
1
Parent(s):
ef88f1b
Update pages/2_π_BlackBox_and_WhiteBox_Attacks.py
Browse files
pages/2_π_BlackBox_and_WhiteBox_Attacks.py
CHANGED
@@ -39,11 +39,10 @@ st.sidebar.markdown(
|
|
39 |
# title
|
40 |
st.title('Blackbox Attack')
|
41 |
|
42 |
-
|
43 |
-
They only use the last logit for text generation, so only using the last one would be fine.
|
44 |
-
https://github.com/huggingface/transformers/blob/ae54e3c3b18bac0832ad62ea9b896dfd52a09850/src/transformers/generation/utils.py#L2189
|
45 |
-
https://github.com/huggingface/transformers/blob/main/src/transformers/modeling_utils.py#L2189
|
46 |
-
'''
|
47 |
|
48 |
# online search
|
49 |
def run(model, tokenizer, embedidng_layer=None, _bar_text=None, bar=None, text='Which name is also used to describe the Amazon rainforest in English?',
|
@@ -56,9 +55,7 @@ def run(model, tokenizer, embedidng_layer=None, _bar_text=None, bar=None, text='
|
|
56 |
_input[k] = _input[k].to(device)
|
57 |
|
58 |
ori_output = model(**_input)
|
59 |
-
|
60 |
-
# ori_output = ori_output['last_hidden_state']
|
61 |
-
# else:
|
62 |
ori_output = ori_output['logits']
|
63 |
|
64 |
ori_embedding = embedidng_layer(_input['input_ids']).detach()
|
@@ -82,10 +79,8 @@ def run(model, tokenizer, embedidng_layer=None, _bar_text=None, bar=None, text='
|
|
82 |
|
83 |
_input_['inputs_embeds'] = perturbed_embedding
|
84 |
outputs_perturbed = model(**_input_)
|
85 |
-
|
86 |
-
|
87 |
-
else:
|
88 |
-
outputs_perturbed = outputs_perturbed['logits']
|
89 |
|
90 |
loss = loss_funt(ori_output, outputs_perturbed)
|
91 |
loss.backward()
|
|
|
39 |
# title
|
40 |
st.title('Blackbox Attack')
|
41 |
|
42 |
+
#
|
43 |
+
# They only use the last logit for text generation, so only using the last one would be fine.
|
44 |
+
# https://github.com/huggingface/transformers/blob/ae54e3c3b18bac0832ad62ea9b896dfd52a09850/src/transformers/generation/utils.py#L2189
|
45 |
+
# https://github.com/huggingface/transformers/blob/main/src/transformers/modeling_utils.py#L2189
|
|
|
46 |
|
47 |
# online search
|
48 |
def run(model, tokenizer, embedidng_layer=None, _bar_text=None, bar=None, text='Which name is also used to describe the Amazon rainforest in English?',
|
|
|
55 |
_input[k] = _input[k].to(device)
|
56 |
|
57 |
ori_output = model(**_input)
|
58 |
+
|
|
|
|
|
59 |
ori_output = ori_output['logits']
|
60 |
|
61 |
ori_embedding = embedidng_layer(_input['input_ids']).detach()
|
|
|
79 |
|
80 |
_input_['inputs_embeds'] = perturbed_embedding
|
81 |
outputs_perturbed = model(**_input_)
|
82 |
+
|
83 |
+
outputs_perturbed = outputs_perturbed['logits']
|
|
|
|
|
84 |
|
85 |
loss = loss_funt(ori_output, outputs_perturbed)
|
86 |
loss.backward()
|