songyingxin / Bert-TextClassification

Implemention some Baseline Model upon Bert for Text Classification
Other
682 stars 149 forks source link

使用了新数据集 发现准确率奇高 模型的最后的激活函数用的liner可能有点问题 #17

Open xishuaidelin opened 4 years ago

xishuaidelin commented 4 years ago

之前自己也做过分类问题 多分类的错误地用了liner进行分类 今天使用仓库代码发现在几万的新数据集上准确率非常高 还是只是BERTorigin 因为是比赛数据集 去看了比赛第一名的准确率 低了5 6个点 看了代码发现classifier用的是liner 代码应该需要改成softmax才对

Fan9 commented 4 years ago

pytorch为了数值稳定性,使用了log-sum-exp的技巧,把log和sum-exp(也就是softmax的操作)放到一起计算。所以在分类问题中,torch使用两种方式:(1)模型最后一层直接用linear,softmax放到loss中计算(torch的BCEloss)。(2)使用log softmax替换softmax,在loss计算时去除log操作。可以去看torch的官方文档,如果你在linear层加上softmax很有可能你做了两次softmax操作