Lin-HQ/SAGS

Python

0

2 commits

updated Jun 1, 2026

See the code

README

SAGS: Towards Fine-grained Controlling of LLM Behaviors by Activation Steering with Sparse Semantic Feature Detection

Controlling LLM behavior using Sparse Autoencoders (SAEs). Two components: FAS (Feature Activation Steering) and SFD (Semantic Feature Detection) for semantic detection.

Project Structure

SAGS/
├── FAS/                    # Feature Activation Steering
│   ├── 1_extrat_sparse_activation.py
│   ├── 2_generate_steering_vector.py
│   └── 3_steering.py
├── SFD/                    # Semantic Feature Detection
│   ├── 1_extract_sae_post_orginal.py
│   ├── 2_sae_same_index.py
│   └── 3_classification_analysis.py
├── utils/                  # Evaluation tools
│   ├── I-F_LLM_eval.py
│   ├── Refusal_LLM_eval.py
│   └── Refusal_Rate.py
└── data/

Installation

pip install -r requirements.txt

Requires Python 3.8+, CUDA GPU (16GB+ for Gemma-2-2B).

Usage

FAS

cd FAS
python 1_extrat_sparse_activation.py   # Extract activations
python 2_generate_steering_vector.py   # Generate steering vectors
python 3_steering.py                   # Apply steering

SFD

cd SFD
python 1_extract_sae_post_orginal.py   # Extract activations
python 2_sae_same_index.py             # Generate detection vectors
python 3_classification_analysis.py    # Classification

Evaluation

cd utils
python I-F_LLM_eval.py      # Instruction-following eval
python Refusal_LLM_eval.py  # Refusal eval

Note: Evaluation requires OpenAI API. Set API_SECRET_KEY and BASE_URL in the scripts.

Lin-HQ/SAGS

Python

0

2 commits

updated Jun 1, 2026

See the code

README

SAGS: Towards Fine-grained Controlling of LLM Behaviors by Activation Steering with Sparse Semantic Feature Detection

Controlling LLM behavior using Sparse Autoencoders (SAEs). Two components: FAS (Feature Activation Steering) and SFD (Semantic Feature Detection) for semantic detection.

Project Structure

SAGS/
├── FAS/                    # Feature Activation Steering
│   ├── 1_extrat_sparse_activation.py
│   ├── 2_generate_steering_vector.py
│   └── 3_steering.py
├── SFD/                    # Semantic Feature Detection
│   ├── 1_extract_sae_post_orginal.py
│   ├── 2_sae_same_index.py
│   └── 3_classification_analysis.py
├── utils/                  # Evaluation tools
│   ├── I-F_LLM_eval.py
│   ├── Refusal_LLM_eval.py
│   └── Refusal_Rate.py
└── data/

Installation

pip install -r requirements.txt

Requires Python 3.8+, CUDA GPU (16GB+ for Gemma-2-2B).

Usage

FAS

cd FAS
python 1_extrat_sparse_activation.py   # Extract activations
python 2_generate_steering_vector.py   # Generate steering vectors
python 3_steering.py                   # Apply steering

SFD

cd SFD
python 1_extract_sae_post_orginal.py   # Extract activations
python 2_sae_same_index.py             # Generate detection vectors
python 3_classification_analysis.py    # Classification

Evaluation

cd utils
python I-F_LLM_eval.py      # Instruction-following eval
python Refusal_LLM_eval.py  # Refusal eval

Note: Evaluation requires OpenAI API. Set API_SECRET_KEY and BASE_URL in the scripts.