NMF, Semi-NMF, Sparse NMF, Dictionary learning

NMF 계열은 최근 Mechanistic Interpretability에서도 SAE(Sparse Autoencoder)의 대안 또는 보완 기법으로 많이 주목받고 있습니다. 특히 최근의 SNMF (Sparse NMF, Semi-NMF) 기반 Circuit Discovery 논문들이 나오면서 구분이 중요해졌습니다.


1. NMF (Non-negative Matrix Factorization)

기본 아이디어

주어진 데이터 행렬 Xn×dX \in \mathbb{R}^{n\times d} 를 두 개의 저차원 행렬로 분해한다.

XWHX \approx WH

여기서 Wn×kW \in \mathbb{R}^{n\times k}, Hk×dH \in \mathbb{R}^{k\times d} 이며 W0,H0W \ge 0,\quad H \ge 0

즉, 모든 원소가 non-negative이다.


최적화 문제

일반적으로

minW,HXWHF2\min_{W,H}\|X-WH\|_F^2

subject to W0,H0W\ge0,\quad H\ge0


의미

각 데이터 벡터 xix_ixij=1kWijHjx_i \approx \sum_{j=1}^{k}W_{ij} H_j로 표현된다.

  • HjH_j: latent feature
  • WijW_{ij}: feature activation

예시

얼굴 이미지:

X=[face1face2...]X=\begin{bmatrix}\text{face}_1\\ \text{face}_2\\…\end{bmatrix}

NMF 결과:

H={,,,}H=\{\text{눈},\text{코},\text{입},\text{턱}\} 처럼 part-based decomposition이 나온다.


왜 해석 가능한가?

PCA는

x=+a1v1a2v2+...x = +a_1 v_1 – a_2 v_2 + … 처럼 양/음 방향이 섞인다.

반면 NMF는

x=a1f1+a2f2+...x = a_1 f_1 + a_2 f_2 + … 모든 계수가 양수.

즉, “feature의 조합”으로 해석 가능하다.


2. Semi-NMF

NMF의 가장 큰 문제는 X0X\ge0 이어야 한다는 점이다.


하지만 Transformer activation은

XX \in \mathbb{R} 양수/음수가 모두 존재한다.

그래서 나온 것이

Semi-NMF

XWHX \approx WH 인데

W0W\ge0 만 강제하고, H는 자유롭게 둔다.


즉,

W+n×kW \in \mathbb{R}^{n\times k}_{+}

Hk×dH \in \mathbb{R}^{k\times d}


최적화

minW0,HXWHF2\min_{W\ge0,H}\|X-WH\|_F^2


의미

activation coefficient는 양수

feature vector는 양/음 허용


Transformer activation에 적합.


3. Sparse NMF (SNMF)

최근 interpretability 논문에서 가장 많이 사용하는 버전.


기존 NMF XWHX \approx WH 는 dense하다.

예를 들어,

Wi=[0.3,0.5,0.2,0.1,0.4]W_i=[0.3,0.5,0.2,0.1,0.4]

모든 feature가 조금씩 활성화된다.

해석하기 어렵다.


Sparse NMF는 W 또는 H에 sparsity를 추가한다.


목적함수

가장 흔한 형태

minW,HXWHF2+λW1\min_{W,H}\|X-WH\|_F^2+\lambda \|W\|_1

subject to W,H0W,H\ge0


또는

minXWHF2+λWW1+λHH1\min\|X-WH\|_F^2+\lambda_W\|W\|_1+\lambda_H\|H\|_1


효과

Wi=[0,0,0.9,0,0]W_i=[0,0,0.9,0,0]

처럼 된다.


즉, 하나의 데이터가 몇 개의 feature만 사용.


4. SAE와의 관계

SAE는 xzx \rightarrow z, z sparsez \text{ sparse} 를 학습한다.


목적함수

xx^2+λz1\|x-\hat{x}\|^2+\lambda \|z\|_1


SNMF는 XWHX\approx WH, W sparseW \text{ sparse}


비슷해 보인다.

실제로 최근 논문들은 Sparse NMF ≈ Linear SAE 라고 본다.


5. 최근 Mechanistic Interpretability에서의 사용

예를 들어 최근

Constructing Interpretable Features from Compositional Neuron Groups (2025)에서는

Transformer activation matrix

AN×DA \in \mathbb{R}^{N\times D} 에 대해 SNMF 수행

AWHA \approx WH


결과

  • H → feature dictionary
  • W → feature activation

그리고 feature 간 계층구조 FeatureAFeatureBFeature_A\rightarrow Feature_B 를 구성한다.


6. NMF vs Semi-NMF vs Sparse NMF 비교

방법입력 데이터FeatureActivationSparse
NMFnon-negativenon-negativenon-negativeX
Semi-NMFsigned 가능signednon-negativeX
Sparse NMFnon-negativenon-negativesparse non-negativeO
Sparse Semi-NMFsigned 가능signedsparse non-negativeO

Dictionary Learning과의 관계

사실 최근 Mechanistic Interpretability에서 사용하는

  • SAE (Sparse Autoencoder)
  • Sparse Coding
  • Dictionary Learning
  • Sparse NMF
  • Sparse Semi-NMF

는 모두 본질적으로는

“데이터를 sparse한 feature들의 조합으로 표현한다”

는 동일한 문제를 서로 다른 제약조건(constraint) 하에서 푸는 방법들입니다.


1. Dictionary Learning의 기본 형태

데이터 Xn×dX \in \mathbb{R}^{n\times d}가 있을 때 XZAX \approx ZA로 분해한다.

여기서 Zn×kZ \in \mathbb{R}^{n\times k}는 sparse code, Ak×dA \in \mathbb{R}^{k\times d}는 dictionary이다.


최적화는

minZ,AXZAF2+λZ1\min_{Z,A}\|X-ZA\|_F^2+\lambda \|Z\|_1

subject to Ai2=1\|A_i\|_2=1

정도이다.


Interpretability 관점에서는

AiA_i가 feature.

ZijZ_{ij}가 activation.


2. Sparse Coding = Dictionary Learning

사실상 같은 말이다.

Olshausen & Field (1996)

x=iziaix=\sum_i z_i a_i

ziz_i는 sparse.


이것이 현대 SAE의 조상이다.


3. NMF를 Dictionary Learning 관점으로 보기

NMF

XWHX \approx WH를 쓰면 Dictionary Learning 형태와 완전히 동일하다.


대응 관계

Dictionary LearningNMF
Dictionary AH
Sparse code ZW

즉, XZAX \approx ZAXWHX \approx WH는 수학적으로 동일.


차이는 제약조건.


4. Dictionary Learning vs NMF

Dictionary Learning:

Z는 sparse, A는 부호 제한 없음


NMF:

W,H0W,H \ge 0


즉, NMF는 Nonnegative Dictionary Learning이라고 볼 수 있다.


5. Semi-NMF와의 관계

Semi-NMF:

XWHX \approx WH, W0W \ge 0, HH \in \mathbb{R}


Dictionary Learning으로 보면 Z=WZ=W, A=HA=H인데 sparse code가 nonnegative라는 추가 제약만 존재한다.


즉, Semi-NMF=Nonnegative Sparse Coding\text{Semi-NMF}=\text{Nonnegative Sparse Coding}에 가깝다.


6. SAE와의 관계

SAE는

Encoder: z=f(Wex)z=f(W_e x)

Decoder: x^=Wdz\hat{x}=W_d z


Loss: xx^2+λz1\|x-\hat{x}\|^2+\lambda \|z\|_1


Dictionary Learning으로 보면

decoder weight WdW_d가 dictionary.


Feature: ai=Wd[i]a_i=W_d[i]


Activation ziz_i가 sparse code.


따라서, SAE는 Neural-network parameterization을 사용한 Dictionary Learning

이다.


7. 왜 최근 MI에서 Dictionary Learning이 중요해졌는가?

Transformer activation x는 superposition 상태.


예:

Neuron 1523

=capital city+European country+politics=\text{capital city}+\text{European country}+\text{politics}


단일 neuron으로 해석 불가능.


Dictionary Learning은

x=z1a1+z2a2+z3a3x=z_1 a_1+z_2 a_2+z_3 a_3로 분해.


feature aia_i를 직접 해석 가능.


이것이

  • SAE
  • GemmaScope
  • Sparse NMF
  • Anthropic Dictionary Learning

의 핵심 아이디어이다.


8. 최근 MI 관점에서의 위치

최근 연구 흐름을 정리하면

Neuron\text{Neuron}

Dictionary Learning\text{Dictionary Learning}

Feature\text{Feature}

Circuit\text{Circuit}

이다.


구체적으로

1세대

Knowledge Neurons

단일 neuron 분석


2세대

SAE

xfeaturex \rightarrow \text{feature}


3세대

Sparse NMF / Semi-NMF

neuron groupfeature\text{neuron group}\rightarrow\text{feature}


4세대

Circuit Discovery

EAP, RelP, SNMF Circuit 등

featurecircuit\text{feature}\rightarrow\text{circuit}추출.


Mechanistic Interpretability 관점의 핵심 비교

방법DictionarySparse CodeNonnegativeEncoder
Dictionary LearningOOXX
Sparse CodingOOXX
NMFO부분적OX
Sparse NMFOOOX
Semi-NMFO부분적activation만 OX
SAEOO보통 ReLU로 OO


게시됨

카테고리

,

작성자

댓글

답글 남기기

이메일 주소는 공개되지 않습니다. 필수 필드는 *로 표시됩니다