INNER CODE UNIT · Python
sentiment_acc
yya518/FinBERT · archive/train_bert.py:84
sentiment_acc = sentiment_corrects.double() / dataset_sizes[phase]
assert(len(actual) == len(pred))
assert(len(actual) == dataset_sizes[phase])
f1 = f1_score(actual.cpu().numpy(), pred.cpu().numpy(), average='weighted')
print('{} total loss (avg): {:.4f} '.format(phase,epoch_loss ))
wo.write('{} total loss: {:.4f} \n'.format(phase,epoch_loss ))
print('{} sentiment_acc: {:.4f}'.format(phase, sentiment_acc))
wo.write('{} sentiment_acc: {:.4f} \n'.format(phase, sentiment_acc))
print('{} f1-score: {:.4f}'.format(phase, f1))
wo.write('{} f1-score:: {:.4f} \n'.format(phase, f1))
if phase == 'val' and epoch_loss < best_loss:
print('saving with loss of {}'.format(epoch_loss),
'improved over previous {}'.format(best_loss))
wo.write('saving with loss of {} \n'.format(epoch_loss))
wo.write('improved over previous {} \n'.format(best_loss))
wo.write("\n")