I'm fine-tuning the BERT model in Named Entity Recognition task using json file dataset, but when I run that code get an error:
with torch.no_grad():
token_classifier_output1 = model(b_input_ids,
token_type_ids=None,
attention_mask=b_input_mask,
labels=b_labels)
token_classifier_output2 = model(b_input_ids, token_type_ids=None,
attention_mask=b_input_mask)
logits = token_classifier_output2.detach().cpu().numpy()
label_ids = b_labels.to('cpu').numpy()
predictions.extend([list(p) for p in np.argmax(logits, axis=2)])
true_labels.append(label_ids)
tmp_eval_accuracy = flat_accuracy(logits, label_ids)
eval_loss += tmp_eval_loss.mean().item()
eval_accuracy += tmp_eval_accuracy
nb_eval_examples += b_input_ids.size(0)
nb_eval_steps += 1
when I run that code I get this error: AttributeError: 'TokenClassifierOutput' object has no attribute 'detach'