-
Notifications
You must be signed in to change notification settings - Fork 62
Expand file tree
/
Copy pathkie_loss.py
More file actions
33 lines (23 loc) · 826 Bytes
/
kie_loss.py
File metadata and controls
33 lines (23 loc) · 826 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
import mindspore as ms
from mindspore import nn
__all__ = ["VQASerTokenLayoutLMLoss", "VQAReTokenLayoutLMLoss"]
class VQASerTokenLayoutLMLoss(nn.LossBase):
"""
Loss for token classification task.
"""
def __init__(self, **kwargs):
super().__init__()
self.loss_fct = nn.CrossEntropyLoss()
def construct(self, predicts, labels):
loss = self.loss_fct(predicts.transpose(0, 2, 1), labels.astype(ms.int32))
return loss
class VQAReTokenLayoutLMLoss(nn.LossBase):
"""
Loss for relation extraction task.
"""
def __init__(self, **kwargs):
super().__init__()
self.loss_fct = nn.CrossEntropyLoss()
def construct(self, predicts, labels):
loss = self.loss_fct(predicts.transpose(0, 2, 1), labels.astype(ms.int32))
return loss