torch.nn.Embedding 값 설정

이성범·2022년 4월 26일
0

Development

목록 보기
1/7
# 초기 임베딩 설정을 위한 코드 예시

emb = nn.Embedding(3, 5, padding_idx = 0)
pre_emb = np.random.rand(2, 5)
with torch.no_grad():
    for idx in range(len(pre_emb)):
        emb.weight[idx + 1] = torch.tensor(pre_emb[idx])
  • 초기 임베딩 값에 따라 모델 학습 속도 및 성능에 큰 차이가 존재함 (관련 자료)
  • 따라서 초기 임베딩 값을 올바르게 초기화 하는 것이 매우 중요함
  • 위 코드는 padding(업데이트 X)을 제외한 초기 임베딩을 설정하는 code의 예시임
profile
Machine Learning Engineer at Konan Technology

0개의 댓글