batch_size = 48
train_data = TensorDataset(train_inputs, train_masks, train_labels)
#Training
train_loss_set = []
iterate = 4
for _ in trange(iterate, desc="Iterate"):
model.train()
train_loss = 0
nu_train_examples, nu_train_steps = 0, 0
for step, batch in enumerate(train_dataloader):
batch = tuple(t.to(device) for t in batch)
batch_input_ids, batch_input_mask, batch_labels = batch
optimizer.zero_grad()
output = model(batch_input_ids, attention_mask=batch_input_mask)
logits = output[0]
logittt = logits[0]
print(logittt[0],"\n")
和输出的一部分:
tensor(-0.4331, device='cuda:0', grad_fn=<SelectBackward>)
tensor(-0.4924, device='cuda:0', grad_fn=<SelectBackward>)
tensor(-0.4356, device='cuda:0', grad_fn=<SelectBackward>)
tensor(-0.8334, device='cuda:0', grad_fn=<SelectBackward>)
tensor(-0.6026, device='cuda:0', grad_fn=<SelectBackward>)
tensor(-0.3859, device='cuda:0', grad_fn=<SelectBackward>)
这是我的分类代码的一部分。logittt 拥有一个 11x 数组。我只想要每个号码分别。例如 -0.4331 在第一个输出行中,以便添加到数组中。