Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/oop/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Pytorch ';b电子物流损失';对象没有属性';向后';PyToch错误_Pytorch_Text Classification_Loss Function_Backpropagation_Bert Language Model - Fatal编程技术网

Pytorch ';b电子物流损失';对象没有属性';向后';PyToch错误

Pytorch ';b电子物流损失';对象没有属性';向后';PyToch错误,pytorch,text-classification,loss-function,backpropagation,bert-language-model,Pytorch,Text Classification,Loss Function,Backpropagation,Bert Language Model,我正在尝试微调Bert模型,即,对于文本分类任务来说,Bert基是无基础的。我在丢失时调用backward()时遇到一个奇怪的错误,如下所示 torch.nn.modules.ModuleAttributeError:“BCEWithLogitsLoss”对象没有“backward”属性。 我找不到任何语法错误,还检查了loss函数的输入(输出和目标),即nn.BCEWithLogitsLoss(输出,目标),然后发现格式正确。我不知道是什么导致了这个错误。如果你们中有人能帮我做这件事,我将不胜

我正在尝试微调Bert模型,即,对于文本分类任务来说,Bert基是无基础的。我在丢失时调用backward()时遇到一个奇怪的错误,如下所示

torch.nn.modules.ModuleAttributeError:“BCEWithLogitsLoss”对象没有“backward”属性。

我找不到任何语法错误,还检查了loss函数的输入(输出和目标),即nn.BCEWithLogitsLoss(输出,目标),然后发现格式正确。我不知道是什么导致了这个错误。如果你们中有人能帮我做这件事,我将不胜感激……提前谢谢:)

这是密码

''def列车循环(数据加载器、模型、优化器、设备、调度程序=无): 模型列车() 对于bi,枚举中的d(数据加载器): ids=d[“ids”] 掩码=d[“掩码”] 令牌类型标识=d[“令牌类型标识”] 目标=d[“目标”]

''”

它应该是:

loss=nn.BCEWithLogitsLoss()(输出、目标)
或者更好的方法是:

criteria=nn.BCEWithLogitsLoss()
对于范围内的历元(历元):
对于dataloader中的批处理:
...
损失=标准(输出、目标)
...
另外,在发布问题之前,请仔细阅读文档。PyTorch文档提供了一个如何使用的简单示例。以下是火炬手网站上的一个例子:

    ids = ids.to(device, dtype=torch.long)
    mask = mask.to(device, dtype=torch.long)
    token_type_ids = token_type_ids.to(device, dtype=torch.long)
    targets = targets.to(device, dtype=torch.float)

    optimizer.zero_grad()
    outputs = model(ids=ids, mask = mask, token_type_ids = token_type_ids)
    outputs = outputs.reshape(1)
    print("here is the outputs")
    print(outputs)
    print("here is the targets")
    print(targets)
    loss = nn.BCEWithLogitsLoss(outputs, targets)
    print("this is the loss")
    print(loss)
    loss.backward()
    optimizer.step()
    if scheduler is not None:
        scheduler.step()