I’m using my own loss function with the Trainer
. I need to pass a custom criterion
I wrote that will be used in the loss function to compute the loss. I have the following setup:
from transformers import Trainer, TrainingArguments
class MyTrainer(Trainer):
def compute_loss(self, model, inputs, return_outputs=False):
# I compute the loss here and I need my `criterion`
return loss
training_args = TrainingArguments(# the arguments...
)
# model = my model...
trainer = MyTrainer(model=model,
args=training_args,
# rest of the arguments...
)
I wonder if there is any way I can pass my custom criterion
object to the Trainer
either through the Trainer
or TrainingArguments
? Or, what is the best way to use my criterion without changing the Trainer
?