将模型预测发送到模型时,我在 PyTorch 中得到以下错误输出。有谁知道发生了什么事吗?
以下是我创建的架构模型,在错误输出中,它显示问题存在于 x = self.fc1(cls_hs) 行中。
class BERT_Arch(nn.Module):
def __init__(self, bert):
super(BERT_Arch, self).__init__()
self.bert = bert
# dropout layer
self.dropout = nn.Dropout(0.1)
# relu activation function
self.relu = nn.ReLU()
# dense layer 1
self.fc1 = nn.Linear(768,512)
# dense layer 2 (Output layer)
self.fc2 = nn.Linear(512,2)
#softmax activation function
self.softmax = nn.LogSoftmax(dim=1)
#define the forward pass
def forward(self, sent_id, mask):
#pass the inputs to the model
_, cls_hs = self.bert(sent_id, attention_mask=mask)
print(mask)
print(type(mask))
x = self.fc1(cls_hs)
x = self.relu(x) …Run Code Online (Sandbox Code Playgroud) python machine-learning python-3.x tensorflow bert-language-model