Hadamard Product(Element-wise Product)

JAsmine_log·2025년 5월 1일

Hadamard Product(Element-wise Product)

  • 동일한 크기의 두 벡터 또는 행렬의 각 원소끼리 곱하는 연산으로, 딥러닝이나 벡터 계산에 자주 사용되는 개념

📌Definition

두 벡터(행렬) A, B가 있을때,

A=[a1a2a3],B=[b1b2b3]\mathbf{A} = \begin{bmatrix} a_1 \\ a_2 \\ a_3 \end{bmatrix}, \quad \mathbf{B} = \begin{bmatrix} b_1 \\ b_2 \\ b_3 \end{bmatrix}
ab=[a1b1a2b2a3b3]\mathbf{a} \odot \mathbf{b} = \begin{bmatrix} a_1 \cdot b_1 \\ a_2 \cdot b_2 \\ a_3 \cdot b_3 \end{bmatrix}

❗ Hadamard product ≠ Matrix multiplication

  • 행렬 곱 (dot product 또는 matrix product)은 행과 열의 내적을 수행하는 복잡한 연산
  • Hadamard product는 단순히 같은 위치 원소끼리 곱함 → broadcast가 가능하고 빠름

Applications

  • 딥러닝 attention 계산에서 query-key 간 similarity 후, 가중합에 사용됨
  • BERT 등에서 mask 벡터와 element-wise 곱하여 특정 위치 정보 제거
  • self-attention, bilinear interaction 등에서도 사용됨
profile
Everyday Research & Development

0개의 댓글