among them, industry id, month, day change from one hot encoding to embedding.
def emb_layer_dict(list_, dim_): # 인자로 변경할 리스트와 dimesion을 받음
emb_dict = dict()
if len(list_) > 31: # 산업분류코드는 널값처리 위해
emb_dict = {tkn: i+2 for i, tkn in enumerate(list_)}
emb_dict['<unk>'] = 0
emb_dict['<pad>'] = 1
else:
emb_dict = {tkn: i for i, tkn in enumerate(list_)}
emb_table = nn.Embedding(num_embeddings=len(emb_dict),
embedding_dim=dim_,
padding_idx=1)
return {list_[i]:emb_table[i] for i in range(len(list_))}
RunntimeError: Can't call numpy() on Variable that requires grad. Use var.detach().numpy() instead
The reason is
the tensor to another tensor that isn't requiring a gradient in addition to it's actual value definition. This other tensor can be converted to a numpy array.
So, I add this line after emb_table
emb_table = emb_table.weight.detach().numpy()