小编Mat*_*len的帖子

dropout():将 XLNet 与 HuggingfCE 结合使用时,参数“输入”(位置 1)必须是张量,而不是元组

我收到一条错误消息,指出输入应该是张量类型,而不是元组类型。我不知道如何解决这个问题,因为我已经实现了迁移计划中所述的 return_dict=False 方法。

我的模型如下:

class XLNetClassifier(torch.nn.Module):
    def __init__(self, dropout_rate=0.1):
        super(XLNetClassifier, self).__init__()
        self.XLNet = XLNetModel.from_pretrained('xlnet-base-cased', return_dict=False)
        self.d1 = torch.nn.Dropout(dropout_rate)
        self.l1 = torch.nn.Linear(768, 64)
        self.bn1 = torch.nn.LayerNorm(64)
        self.d2 = torch.nn.Dropout(dropout_rate)
        self.l2 = torch.nn.Linear(64, 3)
        
    def forward(self, input_ids, attention_mask):
        x = self.XLNet(input_ids=input_ids, attention_masks = attention_mask)
        x = self.d1(x)
        x = self.l1(x)
        x = self.bn1(x)
        x = torch.nn.Tanh()(x)
        x = self.d2(x)
        x = self.l2(x)
        
        return x
Run Code Online (Sandbox Code Playgroud)

调用dropout时出现错误。

tensor huggingface-transformers

6
推荐指数
1
解决办法
1万
查看次数

标签 统计

huggingface-transformers ×1

tensor ×1