파트 1: 전체 모델 정의하기
이제 인코더-디코더 모델의 마지막 몇 개 레이어를 구현해 보겠습니다. 최종 예측값(즉, 예측된 프랑스어 단어 확률)을 얻기 위해 Dense와 TimeDistributed 레이어를 사용해요.
지금까지 구현한 인코더와 디코더(상단 레이어 제외)가 제공되어 있습니다. 디코더 GRU 레이어의 출력인 de_out도 제공돼요. 인코더 관련 항목에는 en(예: en_gru), 디코더 관련 항목에는 de(예: de_gru) 접두사를 사용합니다.
이 연습은 강의의 일부입니다
Keras로 배우는 Machine Translation
연습 안내
- Keras에서
Dense와TimeDistributed레이어를 임포트하세요. - 출력이
fr_vocab이고 활성화 함수가softmax인Dense레이어를 정의하세요. - 해당
Dense레이어를TimeDistributed레이어로 감싸세요. de_out을de_dense_time레이어에 전달하여 모델의 최종 예측을 얻으세요.
실습형 인터랙티브 연습
이 예제를 이 샘플 코드를 완성하여 풀어보세요.
# Import Dense and TimeDistributed layers
from tensorflow.keras.____ import ____, ____
# Define a softmax dense layer that has fr_vocab outputs
de_dense = ____(____, ____)
# Wrap the dense layer in a TimeDistributed layer
de_dense_time = ____(de_dense)
# Get the final prediction of the model
de_pred = ____(de_out)
print("Prediction shape: ", de_pred.shape)