Skip to content

Commit

Permalink
re-add ElectraPreLoss to model module to keep compatibility with pret…
Browse files Browse the repository at this point in the history
…rained model
  • Loading branch information
sfluegel committed Nov 22, 2023
1 parent c73d0f8 commit 950b6f0
Showing 1 changed file with 15 additions and 0 deletions.
15 changes: 15 additions & 0 deletions chebai/models/electra.py
Original file line number Diff line number Diff line change
Expand Up @@ -404,3 +404,18 @@ def __call__(self, target, input):
memberships, target.unsqueeze(-1).expand(-1, -1, 20)
)
return loss

class ElectraPreLoss(torch.nn.Module):
def __init__(self):
super().__init__()
self.ce = torch.nn.CrossEntropyLoss()

def forward(self, input, target, **loss_kwargs):
t, p = input
gen_pred, disc_pred = t
gen_tar, disc_tar = p
gen_loss = self.ce(target=torch.argmax(gen_tar.int(), dim=-1), input=gen_pred)
disc_loss = self.ce(
target=torch.argmax(disc_tar.int(), dim=-1), input=disc_pred
)
return gen_loss + disc_loss

0 comments on commit 950b6f0

Please sign in to comment.