【发布时间】:2020-08-06 15:30:31
【问题描述】:
考虑以下网络sn-p:
def __init__(self, model, n_class, dropout_rate,device):
super(NewModel, self).__init__()
self.bert = model
self.linear = nn.Linear(self.bert.config.hidden_size, 2)
self.linear_1 = nn.Linear(self.bert.config.hidden_size, self.bert.config.hidden_size)
self.dropout_rate = dropout_rate
self.dropout_1 = nn.Dropout(p = self.dropout_rate)
self.activation = nn.LeakyReLU()
self.bn = nn.BatchNorm1d(num_features = self.bert.config.hidden_size)
def forward(self, batch):
outputs = self.bert(
input_ids = batch[0].to(self.device),
attention_mask = batch[1].to(self.device),
token_type_ids = None,
position_ids = None,
head_mask = None,
inputs_embeds = None,
)
output = outputs[0]
pooled_output=output[:,0]
pooled_output = pooled_output.unsqueeze(0)
pooled_output_1 = self.dropout_1(self.bn(pooled_output))
logits = self.linear(F.leaky_relu(self.linear_1(pooled_output_1)))
我的批量大小为 16,在训练期间出现此错误:
ValueError: Expected more than 1 value per channel when training, got input size torch.Size([1, 16])
我已经在DataLoader中设置了drop_last=True,但是错误仍然存在。
任何帮助将不胜感激。
【问题讨论】:
标签: deep-learning neural-network nlp pytorch batch-normalization