lonePatient / Bert-Multi-Label-Text-Classification

This repo contains a PyTorch implementation of a pretrained BERT model for multi-label text classification.
MIT License
862 stars 207 forks source link

Valid_f1 error #12

Open xyang70 opened 5 years ago

xyang70 commented 5 years ago

Epoch: 2 - loss: 0.2649 - valid_loss: 0.2187

Traceback (most recent call last): File "train_bert_multi_label.py", line 144, in main() File "train_bert_multi_label.py", line 138, in main trainer.train(train_data = train_loader,valid_data=valid_loader) File "/content/gdrive/My Drive/Bert/pybert/train/trainer.py", line 181, in train self.training_monitor.epoch_step(logs) File "/content/gdrive/My Drive/Bert/pybert/callback/trainingmonitor.py", line 62, in epochstep plt.plot(N, self.H[f"valid{key}"],label=f"valid_{key}") KeyError: 'valid_f1'

When I get to the 2nd epoch, I got this, the kernel crashes and the f1 score is not being calculated anymore. Do you know what the cause might be? Thanks.

maxware0715 commented 5 years ago

The problem happens in pybert\train\trainer.py in line 92 and 152: for metric in self.epoch_metrics: metric(logits=self.outputs, target=self.targets) value = metric.value() -> if value: change this to: if value is not None: original version judged score of 0 as null.