RishabhMaheshwary/hard-label-attack

target_model_path

Closed this issue · 13 comments

Hello!
When running the following command, is the specified'target_model_path' the'bert/snli' under the downloaded'Download pretrained target models for each dataset [bert]'?

python3 nli_attack.py
--dataset_path data/snli
--target_model bert
--counter_fitting_cos_sim_path mat.txt
--target_dataset snli
--target_model_path *BERT/results/snli *
--USE_cache_path "nli_cache"
--sim_score_window 40

Under the existing 'BERT' folder, there is no 'results' folder and I don't know how to specify it, so even running 'classification_attack.py' results are 'Not Found'.

Hi,
Yes the target_mode_path is <model_name>/<dataset_name>.
So, if you want to run bert trained on snli use bert/snli as the target model path.
It is a mistake in the documentation, thanks for pointing it out, I will correct it.

Thanks for your answer.

During the operation, I found that the printed results are all 'Not Found' . For the following code, I tried to print the value of 'pr' , but the output was all 'False' . What is the cause of this?
''''''''''''''''''''''''''''''''''
def get_attack_result(new_text, predictor, orig_label, batch_size):

new_probs = predictor(new_text, batch_size=batch_size)
pr=(orig_label!= torch.argmax(new_probs, dim=-1)).data.cpu().numpy()
return pr

''''''''''''''''''''''''''''''''''

Looking forward to your reply.

This happens when the adversarial example is not generated during the random initialisation step. You can increase the number of queries required in the random initialisation step. Change the value here from 2500 to a larger value. May I know which target model ar you currently attacking.

The target model I specified is 'bert' . This is the command I ran:
‘’‘’‘’‘’‘’‘’‘’‘’‘’‘’‘’‘’‘’‘’‘’‘’‘’‘’‘’‘’‘’‘’‘’‘’‘’‘’‘’‘’‘’‘’‘’‘’‘’
python3 classification_attack.py
--dataset_path data/imdb
--target_model bert
--counter_fitting_cos_sim_path mat.txt
--target_dataset imdb
--target_model_path hard-label-attack-main/bert/imdb
--USE_cache_path " "
--max_seq_length 256
--sim_score_window 40
--nclasses 2
‘’‘’‘’‘’‘’‘’‘’‘’‘’‘’‘’‘’‘’‘’‘’‘’‘’‘’‘’‘’‘’‘’‘’‘’‘’‘’‘’‘’‘’‘’‘’‘’‘’

The command is correct. Have you downloaded the counter-fitted vectors here? You need to download them and keep them in the hard-label-attack directory. I have tried with the command you mentioned and the attack is working.

I have updated the readme. I think you might have to download the counter-fitted vectors from here to run the attack.

Yes, I downloaded 'Counter-fitted Vectors. txt', and before that, I downloaded 'mat.txt'. And changed the "--counter_fitting_embeddings_path" in the code 'classification_attack.py' to 'mat.txt'.Whether the two TXT files have the same content?

Yes, I downloaded 'Counter-fitted Vectors. txt', and before that, I downloaded 'mat.txt'. And changed the "--counter_fitting_embeddings_path" in the code 'classification_attack.py' to 'mat.txt'.Whether the two TXT files have the same content?

No the two txt files have different content. The --counter_fitting_embeddings_path in the code should be the path to the counter-fitted-vectors.txt file.

Okay, I'll try to do it again.

My question has been solved, Thank you for your patience.
The problem is that I lacked the 'Counter-fitted Vectors. txt 'in my directory.

My question has been solved, Thank you for your patience.
The problem is that I lacked the 'Counter-fitted Vectors. txt 'in my directory.

My question has been solved, Thank you for your patience.
The problem is that I lacked the 'Counter-fitted Vectors. txt 'in my directory.