使用gpt2,meanloss = loss.mean()的预训练模型时,却出现这个错误:AttributeError: 'str'对象没有属性“mean”;
在训练过程中,我试图找到平均损失,但是我犯了一个错误
loss, logits, _ = model(data1, labels=target1)
meanloss = loss.mean()
total_loss += meanloss
meanloss.backward()
optimizer.step()
,这就是错误
AttributeError: 'str' object has no attribute 'mean'
During the training, I tried to find the average loss, but I made a mistake
loss, logits, _ = model(data1, labels=target1)
meanloss = loss.mean()
total_loss += meanloss
meanloss.backward()
optimizer.step()
then,this is the error
AttributeError: 'str' object has no attribute 'mean'
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
这一定是你的模型造成的。你能展示你定义的模型吗?
这是一个例子:
That must be caused by your model. Can you show the model your defined?
Here is an example: