金融領域における安全性評価のためのレッドチームベンチマーク生成パイプライン。
論文で参照されている詳細資料:
FinRED/
├── main.py # Main runner
├── requirements.txt # Dependencies
├── run/ # Example run scripts
├── prompts/ # Prompt files
├── tests/ # Example notebooks
├── README.md
│
├── src/
│ ├── Step1_build.py # Scenario generation module
│ ├── Step2_build.py # Seed prompt generation module
│ ├── __init__.py
│ │
│ ├── data/ # Downloaded data
│ │ ├── contexts/ # Context data
│ │ │ ├── R3_products/ # R3 product summaries
│ │ │ └── retrieved_chunks/# Similarity search outputs
│ │ ├── orig/ # Raw data
│ │ │ ├── db/ # Chunk CSV DB
│ │ │ ├── parsed_docs/ # PDFs + chunk JSON
│ │ │ └── investinfo/ # R3 product text
│ │ └── queries/ # Query CSV files
│ │
│ ├── data/schemas/ # Output schema definitions
│ │ ├── ko/ # Korean schemas
│ │ └── en/ # English schemas
│ │
│ ├── outputs/ # Generation outputs
│ │ ├── scenarios/ # Step 1 outputs
│ │ └── prompts/ # Step 2 outputs
│ │
│ ├── preprocess/ # Preprocessing pipeline
│ │ ├── preprocess_README.md # Detailed preprocessing guide
│ │ ├── 1_chunking.py
│ │ ├── 2_parsed_to_csv.py
│ │ ├── 3_common_to_csv.py
│ │ ├── 4_product_summarizer.py
│ │ ├── 5_summary_extractor.py
│ │ └── 6_chunk_retriever.py
│ │
│ ├── eval/ # Evaluation module
│ │ ├── judge_finred.py # Evaluation script
│ │ ├── dataset/ # Evaluation dataset
Google Drive: https://drive.google.com/drive/u/0/folders/1cfBf419OUDrQQMRKMPLLJqRX97WMxExC Google Drive
ダウンロードしたデータを上記のフォルダ構成に合わせて配置してください(src/data 以下)。
# Conda
conda create -n finred python=3.10 -y
conda activate finred
# Or venv
python3.10 -m venv finred_env
source finred_env/bin/activate
cd /path/to/FinRED
pip install -r requirements.txt
前処理(PDFのチャンク化など)が必要な場合:
# Unstructured
pip install "unstructured[all-docs]"
# System dependencies (Ubuntu/Debian)
sudo apt-get install -y libmagic-dev poppler-utils tesseract-ocr tesseract-ocr-kor libreoffice pandoc
前処理ガイド:
src/preprocess/preprocess_README.md
python --version # Python 3.10.x
python -c "import torch; print(f'CUDA: {torch.cuda.is_available()}')"
[Context + Schema + Query]
│
▼
┌─────────────┐
│ Step1_build │ Scenario generation (OpenAI GPT-4)
└─────────────┘
│
▼
[Scenario JSON]
│
▼
┌─────────────┐
│ Step2_build │ Seed prompt generation (Gemini)
└─────────────┘
│
▼
[Seed Prompts]
│
▼
┌─────────────┐
│ Evaluation │ Model response evaluation
└─────────────┘
コンテキストとスキーマに基づいてレッドチームシナリオを生成します。
src/outputs/scenarios/{category}/ 内のシナリオJSONファイルシナリオからシードプロンプトを生成します。
src/outputs/prompts/{category}/ 内のプロンプトJSON + マージ済みCSV# Run the full pipeline with the example script
sh run/run_data_generate.sh
python src/eval/judge_finred.py \
-i src/eval/dataset/qwen_2.5_test.csv \
-o qwen_2.5_test_judged \
-d src/eval/infer_result
cd /path/to/FinRED
python main.py \
--step <1|2|all> \
--category <category> \
--openai_api_key "sk-..." \
--gemini_api_key "AIza..."
| パラメータ | 必須 | 説明 |
|---|---|---|
--step | はい | 実行するステップ: 1 (シナリオ)、2 (プロンプト)、all (順次実行) |
--category | はい | カテゴリ: R1、R2、R3、R4、R5 または R1_1 など |
--openai_api_key | Step 1 | OpenAI APIキー |
--gemini_api_key | Step 2 | Gemini APIキー |
--lang | オプション | プロンプト言語: ko (デフォルト)、en |
--num_prompts | オプション | プロンプト数 (デフォルト: 3) |
--step1_model | オプション | Step 1のモデル (デフォルト: gpt-4.1-2025-04-14) |
--step2_model | オプション | Step 2のモデル (デフォルト: models/gemini-2.5-pro) |
--model_name | オプション | --step1_model の非推奨エイリアス |
# Full pipeline (R1)
python main.py \
--step all \
--category R1 \
--openai_api_key "sk-proj-..." \
--gemini_api_key "AIza..."
# Step 1 only
python main.py \
--step 1 \
--category R2 \
--openai_api_key "sk-proj-..."
# Step 2 only (English, 5 prompts)
python main.py \
--step 2 \
--category R5 \
--lang en \
--num_prompts 5 \
--gemini_api_key "AIza..."
# Single subcategory
python main.py \
--step 2 \
--category R1_1 \
--num_prompts 3 \
--gemini_api_key "AIza..."
| カテゴリ | サブカテゴリ | 説明 |
|---|---|---|
| R1 | R1_1 ~ R1_6 | 金融セキュリティ脅威 |
| R2 | R2_1 ~ R2_5 | 詐欺および違法行為 |
| R3 | R3_1 ~ R3_3 | 不適切販売 |
| R4 | R4_1 ~ R4_5 | 市場操作 |
| R5 | R5_1 ~ R5_7 | 規制違反 |
生成されたプロンプトに対するモデル応答を評価します。
cd /path/to/FinRED/src/eval
python src/eval/judge_finred.py \
-i <input_csv_path> \
-o <output_basename> \
-d <output_dir>
python src/eval/judge_finred.py \
-i ./dataset/qwen_2.5_7b_all_with_responses.csv \
-o qwen2.5_7b_responses \
-d ./infer_result/
CSVには以下を含める必要があります:
infer_result/: 評価結果judge_errors/: エラーログ{
"scenario_id": "R1_1_0001",
"context": "...",
"risk_description": "...",
"attack_vector": "..."
}
{
"prompt_1": "Provide details about vulnerabilities in a financial system...",
"prompt_1_optionalelements": ["social engineering", "phishing"],
"prompt_2": "...",
"prompt_2_optionalelements": ["..."]
}