Decoder 전체(10) 부분에서 attn_weight output shape 관련 질문 드립니다.
315
작성한 질문수 13
sample_decoder = Decoder(num_layers=2, d_model=512, num_heads=8,
dff=2048, target_vocab_size=8000,
maximum_position_encoding=5000)
x = tf.random.uniform((64, 26), dtype=tf.int64, minval=0, maxval=200)
output, attn = sample_decoder(x,
enc_output=sample_encoder_output,
training=False,
look_ahead_mask=None,
padding_mask=None)
output.shape, attn['decoder_layer2_block2'].shape위 코드 결과 output은
(TensorShape([64, 26, 512]), TensorShape([64, 8, 26, 62]))
인데요.
atten output size 64 x 8 x 26 x 62는
batch x head num x seq_len x depth(=len_k) 의 사이즈일것 같은데요.
depth의 경우, d_model(512) / num_head(8) = 64 가 되야하는게 아닌지요? 62인 이유가 궁금합니다.
답변 2
1
62는 입력 시퀀스의 길이에 입니다.
sample_encoder = Encoder(num_layers=2, d_model=512, num_heads=8, dff=2048, input_vocab_size=8500, maximum_position_encoding=10000)
x = tf.random.uniform((64, 62), dtype=tf.int64, minval=0, maxval=200)
sample_encoder_output = sample_encoder(x, training=False, mask=None)
print (sample_encoder_output.shape) # (batch_size, input_seq_len, d_model)
----> (64, 62, 512) 출력
트랜스포머에서, Self-Attention의 output shape은 일반적으로 (batch_size, num_heads, sequence_length, depth)입니다. 여기서 'depth'는 주로 d_model/num_heads로 계산되는데, 이는 각 attention head가 처리하는 feature의 차원수입니다. (62 라는 숫자는 단순히 예제로 정한 숫자입니다.)
Self-Attention 메커니즘에서, attention score는 Query와 Key 사이의 dot product로 계산되므로, Query와 Key의 길이가 동일해야합니다. 이 경우, Key(즉, 입력 시퀀스)의 길이가 62라면, attention weight 행렬의 마지막 차원도 62가 될 것입니다.
좋은 질문 감사합니다.
트랜스포머 FeedForward 관련 질문
0
69
2
파라미터갯수에대한질문(030_IMDB_movie_reviews)
0
60
1
Transformer 번역기 분석 - Part1 따라치기 질문
0
69
2
Encoder-Decoder 질문 드립니다.
0
71
2
model 코드 부분을 따라하다가 전 값이 이상해서요
0
83
1
서적 추천
0
75
1
NLP와 LLM의 차이점
0
550
2
encoder-decoder model 질문입니다.
1
73
1
구글번역기에 대해서 궁금한점이 있습니다.
0
122
2
로드맵에대해서...
0
119
2
Bag of Word (BOW)와TF-IDF시 대명사인 I의행방
0
94
2
강의 교재 최신화 요청
0
142
4
self-attention에서 Wq, Wk, Wv weight matrix 학습과정 질문드립니다.
0
189
3
코랩 환경 설정할 때 질문이 있습니다.
0
248
1
transformer 훈련 마친 모델 공유 가능할까요?
0
216
2
130_Transformer.ipynb transformer.summary() 에러
0
182
2
강사님 궁금한게 있어 문의 드립니다.
0
128
1
강사님 Tensorflow 실습코드 중 궁금한 점이 있습니다.
0
124
1
패딩과 관련한 질문 드립니다.
0
171
1
Encoder Decoder 부터 Simple Chatbot까지 이상답변
0
218
1
seq2seq 모델
0
323
1
강의 내용중 질문있습니다.
0
197
1
Transformer 번역기 부분에 대해 질문 있습니다.
0
212
1
320_Custom_Sentiment_Analysis_navermovie.ipynb 실행 시 오류 납니다.
0
314
2





