Giter Club home page Giter Club logo

pat's Introduction

PAT

Core implementation of Paper: "Order-Disorder: Imitation Adversarial Attacks for Black-box Neural Ranking Models".

Requirements

  • Python 3.8
  • Pytorch==1.10.0
  • transformers==4.6.1
  • sentence-transformers==2.1.0
  • apex==0.1
  • tqdm
  • nltk
  • pytrec_eval
  • trectools

Environment

  • Tesla V100 32GB GPU x 8
  • CUDA 11.2
  • Memory 256GB

Datasets

Model Imitation

  • Data Processing Build Dev data into pickle file to speedup the evaluation.

    1. MSMARCO Passage Ranking Download MSMARCO Passage Ranking dataset. Download sub small dev set of MSMARCO, used for accerlating evaluation during training process
    python ./bert_ranker/dataloader/preprocess_pr.py
    1. TREC DL2019
    python ./bert_ranker/dataloader/preprocess_trec_dl.py
    1. TREC MB2014
    python ./bert_ranker/dataloader/preprocess_mb.py
    1. Natural Question
    python ./bert_ranker/dataloader.preprocess_nq.py
  • Train Pairwise-BERT Ranker from scratch

    python ./bert_ranker/run_pairwise_ranker.py
  • Get runs file (TREC Format) from the publicly available ranking model.

    python ./bert_ranker/dev_public_bert_ranker.py

    --mode determines which dataset to evaluate on --transformer_model determines which open source model to verify on. The default setting is "bert-large-uncased". There is an option, and we will also use the verification result later, which sets as "ms-marco-MiniLM-L-12-v2".

  • Sample training data from runs file of public model to train imitation model.

    python ./bert_ranker/dataloader/sample_runs.py
  • Train imitation model using sampled data.

    python ./bert_ranker/run_imitation_pairwise.py
  • Evaluate the similarity between imitation model and victim model using runs file.

    python imitation_agreement.py
  • Evaluate ranking performance using runs file Note that the evaluation metrics during training and development are not consistent with the official evaluation method. We get the standard ranking performance by official trec tools, which are implemented in trec_eval_tools.py

Text ranking attack via PAT

  • The data preprocessing is implemented in ./adv_ir/data_utils.py. We need extract the query, query id, scores (imitation model), and target candidate passages from runs file.

  • The Pairwise Anchor-based Trigger generation is implemented in ./adv_ir/attack_methods.py function name: pairwise_anchor_trigger()

  • For generating adversarial triggers for ranking attack.

    python pat_attack.py --target=mini --imitation_model=imitate.v2  --nsp --lamba_1=0.6 --lambda_2=0.1 --num_beams=10 --topk=128 --mode=train

Note that we adopted the fine-tuned BERT LM from Song et al.(2020)

  • Test the transferability of triggers
    python pat_attack.py --target=mini --imitation_model=imitate.v2  --nsp --lamba_1=0.6 --lambda_2=0.1 --num_beams=10 --topk=128 --mode=test

Reference

@inproceedings{liu2022order,
  title={Order-Disorder: Imitation Adversarial Attacks for Black-box Neural Ranking Models},
  author={Liu, Jiawei and Kang, Yangyang and Tang, Di and Song, Kaisong and Sun, Changlong and Wang, Xiaofeng and Lu, Wei and Liu, Xiaozhong},
  booktitle={Proceedings of the 2022 ACM SIGSAC Conference on Computer and Communications Security},
  pages={2025--2039},
  year={2022}
}

pat's People

Contributors

laujames avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar

pat's Issues

Undefined class in bert_lm.py

Hi, I have just cloned the repo, and I am trying to run the attack using the command specified in the readme:

python pat_attack.py --target=mini --imitation_model=imitate.v2  --nsp --lamba_1=0.6 --lambda_2=0.1 --num_beams=10 --topk=128 --mode=train

However, I soon get the following error:

Traceback (most recent call last):
  File "pat_attack.py", line 27, in <module>
    from bert_ranker.models.bert_lm import BertForLM
  File "bert_ranker/models/bert_lm.py", line 193, in <module>
    class MaskedMultiHeadSelfAttention(MultiHeadSelfAttention):
NameError: name 'MultiHeadSelfAttention' is not defined

The cause is the missing implementation of the class MultiHeadSelfAttention.
This was probably caused by an unfortunate refactoring of the code.
Could you add back the implementation of the class MultiHeadSelfAttention?

Sharing weights of imitation_models

Hello, thank you for the nice paper.

I was wondering if you could share the weights of the imitation models.
I am interested in reproducing some results, but I prefer to avoid retraining the imitation models.

I thank you in advance :)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.