Coder Social home page Coder Social logo

hijacking_text's Introduction

Two-in-One: A Model Hijacking Attack Against Text Generation Models (Usenix 2023)

arXiv PyTorch

This repository contains the PyTorch implementation of the paper "Two-in-One: A Model Hijacking Attack Against Text Generation Models" by Wai Man Si, Michael Backes, Yang Zhang, and Ahmed Salem.

Requirements

Our code depends on the following requirements:

  • Python 3.8
  • PyTorch 1.11.0
  • transformers==4.19.2

Prepare Transformed Data

# prepare hijacking token set
python pre_token_set.py

# prepare dataset
python prepare_data.py

# sentence transforming
python attack.py

Train translation model (adopted from huggingface-transformer)

python -m torch.distributed.launch --master_port=1233 --nproc_per_node=4 run_translation.py \
    --seed 42 \
    --model_name_or_path facebook/bart-base \
    --train_file ../transformed_data/sst2/train.json \
    --validation_file ../transformed_data/sst2/validation.json \
    --test_file ../transformed_data/sst2/validation.json \
    --do_train --do_eval --do_predict \
    --max_source_length 128 --max_target_length 128 \
    --preprocessing_num_workers 16 \
    --source_lang en --target_lang de \
    --num_beams 1 \
    --output_dir exps/sst2_bartbase \
    --per_device_train_batch_size=128 --per_device_eval_batch_size=64 \
    --num_train_epochs 10 \
    --logging_strategy steps --logging_steps 1000 --logging_first_step True \
    --evaluation_strategy epoch --save_strategy epoch \
    --predict_with_generate \
    --fp16

Acknowledgements

Our code is built upon the public code of the [CLARE] (https://github.com/cookielee77/CLARE/tree/master) and Transformers (https://github.com/huggingface/transformers).

Cite

Please cite our paper if you use this code in your own work:

@inproceedings{SBZS23,
  author       = {Wai Man Si and
                  Michael Backes and
                  Yang Zhang and
                  Ahmed Salem},
  title        = {Two-in-One: {A} Model Hijacking Attack Against Text Generation Models},
  booktitle    = {32nd {USENIX} Security Symposium, {USENIX} Security 2023, Anaheim,
                  CA, USA, August 9-11, 2023},
  pages        = {2223--2240},
  publisher    = {{USENIX} Association},
  year         = {2023}
}

hijacking_text's People

Contributors

raymondhehe avatar

Stargazers

 avatar  avatar

Watchers

 avatar

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.