(Transformer : Attention is All You Need)
기계 번역 모델
컴퓨터 비전 쪽에서도 적용하려는 시도
멀티모달(Multi-Modal, 컴퓨터와 대화하는 환경) 분야에도 적용
트랜스포머는 RNN 기반 모델이 가진 구조적 단점을 해결
트랜스포머 구조

Multi-Head (Self) Attention, Feed Forward]Masked Multi-Head (Self) Attention, Multi-Head (Encoder-Decoder) Attention, Feed Forward]
$$ \begin{aligned} \text{PE}{\text{pos},2i} &= \sin \bigg(\frac{\text{pos}}{10000^{2i/d{\text{model}}}}\bigg) \\ \text{PE}{\text{pos},2i+1} &= \cos \bigg(\frac{\text{pos}}{10000^{2i/d{\text{model}}}}\bigg) \end{aligned} $$
def get_angles(pos, i, d_model):
"""
sin, cos 안에 들어갈 수치를 구하는 함수입니다.
"""
angle_rates = 1 / np.power(10000, (2 * (i//2)) / np.float32(d_model))
return pos * angle_rates
def positional_encoding(position, d_model):
"""
위치 인코딩(Positional Encoding)을 구하는 함수입니다.
"""
angle_rads= get_angles(np.arange(position)[:, np.newaxis],
np.arange(d_model)[np.newaxis, :],
d_model)
# apply sin to even indices in the array; 2iangle_rads[:, 0::2]= np.sin(angle_rads[:, 0::2])
# apply cos to odd indices in the array; 2i+1angle_rads[:, 1::2]= np.cos(angle_rads[:, 1::2])
pos_encoding= angle_rads[np.newaxis,...]
return tf.cast(pos_encoding, dtype=tf.float32)