AttributeError:“TFBERtModel”对象没有属性“parameters”

问题描述 投票:0回答:1

您好,我正在尝试为我训练过的分词器训练 Bert 模型。我导入了

from transformers import TFBertModel

model = TFBertModel.from_pretrained("bert-base-uncased")

现在我尝试通过像这样定义优化器来初始化训练

from transformers import AdamW

optimizer = AdamW(model.parameters(), lr=5e-5)

但是我收到以下错误


AttributeError Traceback(最近一次调用最后一次) 在 1从变形金刚导入AdamW 2 ----> 3 优化器 = AdamW(model.parameters(), lr=5e-5)

AttributeError:“TFBERTModel”对象没有属性“参数”

遵循 Youtube 上的教程

https://www.youtube.com/watch?v=04oZ2P0uvp0&t=1501s&ab_channel=code_your_own_AI

python nlp attributeerror bert-language-model transformer-model
1个回答
0
投票

AdamW
仅适用于 PyTorch 模型。 TF 等效项是 AdamWeightDecay

from transformers import AdamWeightDecay

optimizer = AdamWeightDecay(lr=5e-5)
© www.soinside.com 2019 - 2024. All rights reserved.