このリポジトリには、VenomRecの実験で使用される最小限のVIP5/T5-smallコードパスが含まれています。ポイズンデータの生成、VIP5のファインチューニング、ERを用いた推薦メトリクスの評価、およびROUGEを用いたテキストのステルス性の評価に必要なソースコードのみを保持しています。
attack/ours/dcip_ieos/: DCIP-IEOSポイズニングの実装。src/: VIP5モデル、データ読み込み、トレーニング、およびアダプターのコード。scripts/: ファインチューニング、評価、候補キャッシュ生成、およびテキスト品質評価のためのコマンドラインエントリポイント。tools/export_competition_pool.py: 競合プールを再構築するためのヘルパー。analysis/results/{clothing,sports,toys,microlens}/: 実験で使用されるターゲットおよび高人気アイテムのリスト。お使いのマシンにCUDA対応のPyTorchビルドをインストールし、その後、残りの依存関係をインストールしてください:
pip install -r requirements.txt
コードはリポジトリのルートから実行することを想定しています:
export PYTHONPATH=.
データセットと特徴量ファイルを次のレイアウトで配置します:
data/
clothing/
sequential_data.txt
negative_samples.txt
datamaps.json
review_splits.pkl
exp_splits.pkl
user_id2idx.pkl
user_id2name.pkl
meta.json.gz
sports/
...
toys/
...
microlens/
...
features/
vitb32_features/
clothing/
<item>.npy
sports/
<item>.npy
toys/
<item>.npy
microlens/
<item>.npy
snap/
beauty/
0805/
NoAttack_0.0_beauty-vitb32-2-8-20/
BEST_EVAL_LOSS.pth
事前学習済みのVIP5チェックポイントが別の場所に保存されている場合は、--victim-ckpt を run_dcip_ieos.py に、--load を scripts/run_finetune.sh に渡してください。
同じスクリプトは、データセット名を置き換え、analysis/results/<dataset>/ 配下の対応するファイルを使用することで、toys と microlens にも使用できます。
ポイズンデータを生成します:
python -m attack.ours.dcip_ieos.run_dcip_ieos \
clothing 0.001 0 vitb32 2 8 12 \
--sequence-length 10 \
--interaction-rounds 4 \
--mask-vis-ratio 0.15 \
--mask-txt-ratio 0.18 \
--img-eps 0.05 \
--txt-ratio-max 0.20 \
--txt-embed-eps 0.01 \
--min-txt-replacements 2 \
--sim-threshold 0.92 \
--seed 2022 \
--victim-device cuda:0 \
--run-tag mr0p001_full \
--poison-subdir dcip_ieos_fc_mr0.001_ir4_img0.05_txt0.2
オプションで直接タスクの候補を事前計算します:
python scripts/precompute_candidates.py \
--dataset clothing \
--attack-mode NoAttack \
--mr 0.0 \
--candidate-num 99 \
--poison-subdir dcip_ieos_fc_mr0.001_ir4_img0.05_txt0.2
NoAttack インターフェースの下で、汚染されたデータを用いてファインチューニングします:
bash scripts/run_finetune.sh clothing NoAttack 0 0,1,2,3 vitb32 2 8 20 \
--poison_subdir dcip_ieos_fc_mr0.001_ir4_img0.05_txt0.2
レコメンデーション指標とERを評価する:
python scripts/evaluate_direct.py \
--ckpt snap/clothing/<timestamp>/NoAttack_0.0_clothing-vitb32-2-8-20/BEST_EVAL_LOSS.pth \
--task direct \
--prompts B-5 \
--batch-size 32 \
--num-workers 4 \
--device cuda:0 \
--attack-mode NoAttack \
--mr 0.0 \
--split clothing \
--poison-subdir dcip_ieos_fc_mr0.001_ir4_img0.05_txt0.2 \
--eval-er
テキストのステルス性を評価する:
python scripts/eval_text_quality.py \
--dataset clothing \
--poison-subdir dcip_ieos_fc_mr0.001_ir4_img0.05_txt0.2
スポーツ競技プールを再構築します:
python tools/export_competition_pool.py \
--dataset sports \
--pop-path analysis/results/sports/high_pop_items_sports_highcount_100.txt \
--targets-path analysis/results/sports/low_pop_items_sports_lowcount_1.txt \
--output-dir attack/ours/dcip_ieos/caches \
--c-size 8 \
--keywords-top 50 \
--min-keywords 50 \
--feat-root features \
--feat-backbone vitb32_features \
--no-kmeans
必要に応じて人気センターのプロトタイプを再生成します:
rm -f attack/ours/dcip_ieos/caches/prototypes/sports/c_pop.pkl
python - <<'PY'
from attack.ours.dcip_ieos.prototypes import build_or_load_pop_center
vec = build_or_load_pop_center(
split_dir='data/sports',
cache_dir='attack/ours/dcip_ieos/caches',
feat_root='features',
feat_backbone='vitb32_features',
pop_path='analysis/results/sports/high_pop_items_sports_highcount_100.txt',
fallback_anchors=None,
)
print(f'c_pop dim={len(vec)}, first3={vec[:3]}')
PY
ポイズンデータを生成する:
python -m attack.ours.dcip_ieos.run_dcip_ieos \
sports 0.001 0 vitb32 2 8 12 \
--sequence-length 10 \
--interaction-rounds 4 \
--mask-vis-ratio 0.15 \
--img-eps 0.05 \
--mask-txt-ratio 0.18 \
--txt-ratio-max 0.20 \
--txt-embed-eps 0.01 \
--min-txt-replacements 2 \
--sim-threshold 0.92 \
--seed 2022 \
--victim-device cuda:0 \
--run-tag mr0p001_full \
--poison-subdir dcip_ieos_ir4_mvisr0.15_imgeps0.05_mtxtr0.18_txtrmax0.20_txtembeps0.01_mintxtreplace2_simthres0.92
オプションで直接タスクの候補を事前計算します:
python scripts/precompute_candidates.py \
--dataset sports \
--attack-mode NoAttack \
--mr 0.0 \
--candidate-num 99 \
--poison-subdir dcip_ieos_ir4_mvisr0.15_imgeps0.05_mtxtr0.18_txtrmax0.20_txtembeps0.01_mintxtreplace2_simthres0.92
ファインチューニング:
bash scripts/run_finetune.sh sports NoAttack 0 0,1,2,3 vitb32 2 8 20 \
--poison_subdir dcip_ieos_ir4_mvisr0.15_imgeps0.05_mtxtr0.18_txtrmax0.20_txtembeps0.01_mintxtreplace2_simthres0.92
レコメンデーション指標とERを評価する:
python scripts/evaluate_direct.py \
--ckpt snap/sports/<timestamp>/NoAttack_0.0_sports-vitb32-2-8-20/BEST_EVAL_LOSS.pth \
--task direct \
--prompts B-5 \
--batch-size 32 \
--num-workers 4 \
--device cuda:0 \
--attack-mode NoAttack \
--mr 0.0 \
--split sports \
--poison-subdir dcip_ieos_ir4_mvisr0.15_imgeps0.05_mtxtr0.18_txtrmax0.20_txtembeps0.01_mintxtreplace2_simthres0.92 \
--eval-er
テキストのステルス性を評価する:
python scripts/eval_text_quality.py \
--dataset sports \
--poison-subdir dcip_ieos_ir4_mvisr0.15_imgeps0.05_mtxtr0.18_txtrmax0.20_txtembeps0.01_mintxtreplace2_simthres0.92
メインのスポーツポイズンサブディレクトリ:
dcip_ieos_ir4_mvisr0.15_imgeps0.05_mtxtr0.18_txtrmax0.20_txtembeps0.01_mintxtreplace2_simthres0.92