-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
25 changed files
with
4,958 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,141 @@ | ||
# Byte-compiled / optimized / DLL files | ||
__pycache__/ | ||
*.py[cod] | ||
*$py.class | ||
|
||
# C extensions | ||
*.so | ||
|
||
# Distribution / packaging | ||
.Python | ||
build/ | ||
develop-eggs/ | ||
dist/ | ||
downloads/ | ||
eggs/ | ||
.eggs/ | ||
lib/ | ||
lib64/ | ||
parts/ | ||
sdist/ | ||
var/ | ||
wheels/ | ||
pip-wheel-metadata/ | ||
share/python-wheels/ | ||
*.egg-info/ | ||
.installed.cfg | ||
*.egg | ||
MANIFEST | ||
|
||
# PyInstaller | ||
# Usually these files are written by a python script from a template | ||
# before PyInstaller builds the exe, so as to inject date/other infos into it. | ||
*.manifest | ||
*.spec | ||
|
||
# Installer logs | ||
pip-log.txt | ||
pip-delete-this-directory.txt | ||
|
||
# Unit test / coverage reports | ||
htmlcov/ | ||
.tox/ | ||
.nox/ | ||
.coverage | ||
.coverage.* | ||
.cache | ||
nosetests.xml | ||
coverage.xml | ||
*.cover | ||
*.py,cover | ||
.hypothesis/ | ||
.pytest_cache/ | ||
|
||
# Translations | ||
*.mo | ||
*.pot | ||
|
||
# Django stuff: | ||
*.log | ||
local_settings.py | ||
db.sqlite3 | ||
db.sqlite3-journal | ||
|
||
# Flask stuff: | ||
instance/ | ||
.webassets-cache | ||
|
||
# Scrapy stuff: | ||
.scrapy | ||
|
||
# Sphinx documentation | ||
docs/_build/ | ||
|
||
# PyBuilder | ||
target/ | ||
|
||
# Jupyter Notebook | ||
.ipynb_checkpoints | ||
|
||
# IPython | ||
profile_default/ | ||
ipython_config.py | ||
|
||
# pyenv | ||
.python-version | ||
|
||
# pipenv | ||
# According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control. | ||
# However, in case of collaboration, if having platform-specific dependencies or dependencies | ||
# having no cross-platform support, pipenv may install dependencies that don't work, or not | ||
# install all needed dependencies. | ||
#Pipfile.lock | ||
|
||
# PEP 582; used by e.g. github.com/David-OConnor/pyflow | ||
__pypackages__/ | ||
|
||
# Celery stuff | ||
celerybeat-schedule | ||
celerybeat.pid | ||
|
||
# SageMath parsed files | ||
*.sage.py | ||
|
||
# Environments | ||
.env | ||
.venv | ||
env/ | ||
venv/ | ||
ENV/ | ||
env.bak/ | ||
venv.bak/ | ||
|
||
# Spyder project settings | ||
.spyderproject | ||
.spyproject | ||
|
||
# Rope project settings | ||
.ropeproject | ||
|
||
# mkdocs documentation | ||
/site | ||
|
||
# mypy | ||
.mypy_cache/ | ||
.dmypy.json | ||
dmypy.json | ||
|
||
# Pyre type checker | ||
.pyre/ | ||
|
||
|
||
# specific dir to this project | ||
checkpoints/ | ||
finetune_data/* | ||
!finetune_data/ | ||
!finetune_data/process.py | ||
logs/ | ||
longformer-base-4096/ | ||
pretrain_ckpt/ | ||
results/ | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,54 @@ | ||
# RecTextAttack | ||
# Stealthy Attack on Large Language Model based Recommendation | ||
|
||
This repository contains the replication of the ACL 2024 paper [Stealthy Attack on Large Language Model based Recommendation](https://arxiv.org/abs/2402.14836). | ||
|
||
|
||
## Overview | ||
|
||
In this paper, we demonstrate that attackers can significantly boost an item's exposure by merely altering its textual content during the testing phase, without requiring direct interference with the model's training process. | ||
|
||
 | ||
|
||
|
||
## Dependencies | ||
|
||
Using the following main dependencies: | ||
- Python 3.9.0 | ||
- torch 2.0.1 | ||
- transformers 4.33.1 | ||
- textattack 0.3.9 | ||
|
||
|
||
|
||
## Usage | ||
### Data Preparation | ||
- Prepare data following [here](https://github.com/AaronHeee/RecFormer?tab=readme-ov-file#dataset). | ||
- Put the processed data in `./finetune_data/{dataset_name}/` folder. It should contain 'meta_data.json', 'smap.json', 'umap.json', 'train.json', 'valid.json', 'test.json'. | ||
|
||
### Download Pretrained Checkpoints | ||
- Download Longformer checkpoint from [here](https://huggingface.co/allenai/longformer-base-4096). Put the checkpoint to `./longformer-base-4096/`. | ||
- You can pretrain your model or download pretrained checkpoints from [here](https://github.com/AaronHeee/RecFormer?tab=readme-ov-file#pretrained-model). Put the checkpoints to `./pretrain_ckpt/recformer_seqrec_ckpt.bin`. | ||
- If you want to attack the finetuned models, you can finetune the model and save the checkpoints following [here](https://github.com/AaronHeee/RecFormer?tab=readme-ov-file#finetuning). Put the checkpoints to `./checkpoints/{dataset_name}/best_model.bin`. | ||
### Attack | ||
- Run the attack as: `python attack.py --attack textfooler --dataset beauty`. | ||
- Logs will be saved in `./logs` and the attack results will be saved in `./results`. | ||
- Run `python inference.py` to evaluate the influence of the attack on the recommendation performance. | ||
|
||
|
||
## Citation | ||
|
||
Please cite the paper if you use Recformer in your work: | ||
|
||
```bibtex | ||
@article{zhang2024stealthy, | ||
title={Stealthy Attack on Large Language Model based Recommendation}, | ||
author={Zhang, Jinghao and Liu, Yuting and Liu, Qiang and Wu, Shu and Guo, Guibing and Wang, Liang}, | ||
journal={arXiv preprint arXiv:2402.14836}, | ||
year={2024} | ||
} | ||
``` | ||
|
||
## Acknowledgement | ||
The code is based on [RecFormer](https://github.com/AaronHeee/RecFormer) and [PromptBench](https://github.com/microsoft/promptbench). We thank the authors for their wonderful work. | ||
|
||
|
Oops, something went wrong.