Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Can custom loss function be used for model.fit? #2562

Open
shangh1 opened this issue Mar 29, 2024 · 2 comments
Open

Can custom loss function be used for model.fit? #2562

shangh1 opened this issue Mar 29, 2024 · 2 comments

Comments

@shangh1
Copy link

shangh1 commented Mar 29, 2024

Hi, I'm using this git to run a cross encoder model, hope to use a customized function. The code is like below. The thing is that using model.fit, it does not specify which is the output.
In future, I'll also add another argument in this customized loss to compute lambdarank loss. Thanks!

def my_loss(output, label):
    loss = ... 
    return loss

model.fit(train_dataloader=train_dataloader,
              loss_fct = myloss)
@tomaarsen
Copy link
Collaborator

Hello!

Yes, this is totally possible. If you provide your loss function this way, then it'll be called right here:


i.e. with logits & labels.

  • Tom Aarsen

@shangh1
Copy link
Author

shangh1 commented Mar 29, 2024

Thanks for your quick reply! Got it! So the default arguments are logits and labels.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants