syuoni / eznlp

Easy Natural Language Processing
Apache License 2.0
130 stars 21 forks source link

将Boundary Smoothing应用于其他模型的问题 #49

Closed happyZew closed 4 months ago

happyZew commented 4 months ago

老师您好,想将Boundary Smoothing应用于其他模型,模型计算交叉熵时traget是一维张量代表若干个span的类别,Boundary Smoothing得到的label_ids怎么用于计算loss呢,请问老师这部分在源码的哪里,恳请老师解惑,不胜感激。

syuoni commented 4 months ago

Boundary Smoothing 的 label_ids 是在实体类别上的一个 概率分布。 Loss 计算是 soft cross entropy loss:https://github.com/syuoni/eznlp/blob/master/eznlp/nn/functional.py#L189-L209

happyZew commented 4 months ago

非常感谢您的回复,最先我想自己写函数去计算交叉熵,在您的源码中也找到了这一函数,后来我发现可以使用CrossEntropyLoss去做同样shape的两个二维张量的交叉熵,解决了这个问题,于是关闭了issue,再次感谢您的回复