Huggingface Bert模型的预训练层是否冻结了?
我使用以下来自HuggingFace的分类模型:
model = AutoModelForSequenceClassification.from_pretrained("dbmdz/bert-base-german-cased", num_labels=2).to(device)
据我了解,这在具有2个输出节点的预训练模型的末尾增加了一个密集的层。但是,在冷冻之前,是否所有的预训练层?还是在微调时还会更新?我在文档中找不到有关此的信息...
所以我仍然必须做这样的事情吗?
for param in model.bert.parameters():
param.requires_grad = False
I use the following classification model from Huggingface:
model = AutoModelForSequenceClassification.from_pretrained("dbmdz/bert-base-german-cased", num_labels=2).to(device)
As I understand, this adds a dense layer at the end of the pre-trained model which has 2 output nodes. But are all the pre-trained layers before that frozen? Or are they also updated when fine-tuning? I can't find information about that in the docs...
So do I still have to do something like this?:
for param in model.bert.parameters():
param.requires_grad = False
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
他们不是冷冻的。默认情况下,所有参数均可训练。您也可以通过以下方式检查:
输出:
They are not frozen. All parameters are trainable by default. You can also check that with:
Output:
因此,如果您希望它们冻结,则需要自己冻结它们。
So you'll need to freeze them yourself if you want them frozen.