kamalkraj / BERT-NER

Pytorch-Named-Entity-Recognition-with-BERT
GNU Affero General Public License v3.0
1.21k stars 278 forks source link

Understanding the Evaluation Code #98

Open Vincent950129 opened 3 years ago

Vincent950129 commented 3 years ago

Thanks for the nice code.

I am confused with the evaluation code in runner.py L570. In particular, why "if j==0: continue" and what is variable "temp" for? It would be nice if someone can walk me through.

       for i, label in enumerate(label_ids):
            temp_1 = []
            temp_2 = []
            for j,m in enumerate(label):
                if j == 0:
                    continue
                elif label_ids[i][j] == len(label_map):
                    y_true.append(temp_1)
                    y_pred.append(temp_2)
                    break
                else:
                    temp_1.append(label_map[label_ids[i][j]])
                    temp_2.append(label_map[logits[i][j]])

Also, I got the report file as follows, which seems incorrect (the extra "SEP]"):

          precision    recall  f1-score   support

     LOC     0.9213    0.9329    0.9270      1668
    MISC     0.7756    0.8319    0.8027       702
     ORG     0.8867    0.9001    0.8933      1661
     PER     0.9521    0.9586    0.9553      1617
    SEP]     0.0000    0.0000    0.0000         0

micro avg 0.9005 0.9180 0.9092 5648 macro avg 0.7071 0.7247 0.7157 5648 weighted avg 0.9018 0.9180 0.9098 5648

Any help would be highly appreciated. Thank you for your time.

terminator123 commented 1 year ago

i met the same prob, have u solved it ?