anonymousauthors commited on
Commit
3fd6a37
β€’
1 Parent(s): 8a8c82c

Update pages/2_😈_BlackBox_and_WhiteBox_Attacks.py

Browse files
pages/2_😈_BlackBox_and_WhiteBox_Attacks.py CHANGED
@@ -61,7 +61,7 @@ def run(model, tokenizer, embedidng_layer=None, _bar_text=None, bar=None, text='
61
 
62
  ori_output = model(**_input)
63
 
64
- ori_output = ori_output['logits']
65
 
66
  # get noise
67
  ori_embedding = embedidng_layer(_input['input_ids']).detach()
@@ -87,7 +87,7 @@ def run(model, tokenizer, embedidng_layer=None, _bar_text=None, bar=None, text='
87
  _input_['inputs_embeds'] = perturbed_embedding
88
  outputs_perturbed = model(**_input_)
89
 
90
- outputs_perturbed = outputs_perturbed['logits']
91
 
92
  loss = loss_funt(ori_output, outputs_perturbed)
93
  loss.backward()
 
61
 
62
  ori_output = model(**_input)
63
 
64
+ ori_output = ori_output['logits'][:, -1, :]
65
 
66
  # get noise
67
  ori_embedding = embedidng_layer(_input['input_ids']).detach()
 
87
  _input_['inputs_embeds'] = perturbed_embedding
88
  outputs_perturbed = model(**_input_)
89
 
90
+ outputs_perturbed = outputs_perturbed['logits'][:, -1, :]
91
 
92
  loss = loss_funt(ori_output, outputs_perturbed)
93
  loss.backward()