GitHub-HongweiZhang / prediction-flow

Deep-Learning based CTR models implemented by PyTorch
MIT License
251 stars 52 forks source link

通过nn.Embedding.from_pretrained()加入了自己预训练的embedding向量,请问怎样在模型训练过程中,保持embeding不会被改变? #26

Closed Qian-Hao closed 4 years ago

Qian-Hao commented 4 years ago

我在构建embedding的时候,通过nn.Embedding.from_pretrained()加入了自己预训练的embedding向量,请问怎样在模型训练过程中,保持embeding不会被改变? image

GitHub-HongweiZhang commented 4 years ago

模型的embeddings可以通过model.embeddings获得,然后用下面的方式把embeddings固定 requires_grad = False 具体看pytorch文档

https://github.com/GitHub-HongweiZhang/prediction-flow/blob/master/prediction_flow/pytorch/base.py#L23-L24

Qian-Hao commented 4 years ago

模型的embeddings可以通过model.embeddings获得,然后用下面的方式把embeddings固定 requires_grad = False 具体看pytorch文档

https://github.com/GitHub-HongweiZhang/prediction-flow/blob/master/prediction_flow/pytorch/base.py#L23-L24

谢谢