DeepKE icon indicating copy to clipboard operation
DeepKE copied to clipboard

如何固定预训练模型的参数

Open hihihe opened this issue 4 years ago • 1 comments

Describe the question

A clear and concise description of what the question is. 您好,我设置https://github.com/zjunlp/DeepKE/blob/main/example/re/standard/conf/model/lm.yaml 中lm_file: 'bert-base-chinese',num_hidden_layers: 3,意思是我使用bert-base-chinese模型的前3层hidden_layers来初始化,并进行训练。

但是我如果想使用bert-base模型的12层全部架构,想固定前11层参数,只放开最后一层参数进行训练,可以直接在您的deepke框架中实现吗?

Environment (please complete the following information):

  • OS: [e.g. mac / window]
  • Python Version [e.g. 3.6]

Screenshots

If applicable, add screenshots to help explain your problem.

Additional context

Add any other context about the problem here.

hihihe avatar May 02 '22 12:05 hihihe

您好,您可以将num_hidden_layers设置为12层,在run.py中模型训练前,将前11层参数的requires_grad属性设置为False来固定参数值。

GoooDte avatar May 02 '22 12:05 GoooDte