This is the official repository for PETS 2023 paper "Towards Sentence Level Inference Attack Against Pre-trained Language Models" The goal is to let you train a decoder, which can invert embeddings and test its performances.
To use the code in this project, make sure your Python=3.6
All the codes are provided in notebook for interpretability
Please refer to environment.yml
Use the links below to access the datasets used in our paper. However, we found that CMS website has been updated and the original link doesn't work anymore.
Skytrax: https://github.com/quankiquanki/skytrax-reviews-dataset
Twitter US Airline: https://github.com/benhamner/crowdflower-airline-twitter-sentiment
CMS: https://data.cms.gov/search
MT: https://www.kaggle.com/datasets/tboyle10/medicaltranscription
We provide a sample preprocessing notebook for annotating medical datasets.
As for airline datasets, we refer to the word city dataset as a benchmark: https://github.com/datasets/world-cities
For example, to preprocess Skytrax dataset. We prepare two versions of dataset: the full dataset and a filtered dataset. We refer to the external word city dataset, and only keep the samples containing one of the cities. If the decoder is trained on the filtered dataset, we refer it as vanilla decoder as in the paper. If the decoder is pre-trained on the full dataset then finetuned on the filtered dataset, we refer it as pre-trained decoder.
The preprocessing pipeline is given for BERT. However, it can be adapted to other LMs.
Run preprocess_tokens.ipynb to generate input_ids etc. for LMs (Hint: Clean your own textual data before performing any preprocesses)
Run generate_embedding.ipynb to generate sentence embeddings for decoder
Follow the toy-decoder.ipynb to train and test the decoder
- The Decoder class is the model used in our experiment, and smooth entropy loss is used for training.
- The training epoch is set to be 20 with early stop.
- After training is done, use translate function to query the decoder and generate sentences. By default, top-k sampling is used and each sample is repeated 10 times.
- Finally, we can either count the keywords in the generation or measure the sentence similarity directly.
we provide a subset of mt with spacy annotations. You can prepare your own dataset in this fashion.
We provide a step by step notebook to help you perform data preprocessing and decoder training using the sample dataset. You are encouraged to run it on google colab and follow the instructions to train the decoder. After that, we should be able to experiment embedding inversion on your own data.