Pass Arguments to custom compute_metrics in Trainer
Hi everyone. I’m passing custom compute metric to the trainer. However I need to provide an additional argument besides the batch. How do I do that?My custom compute metric function:def compute_metrics(p, label_list):
...My trainer:trainer = Trainer(                                                                                                                                             
            model=model,                                                                                                                                       
            args=training_args,                                                                                                                                
            train_dataset=ds["train"],                                                                                                          
            eval_dataset=ds["val"],                                                                                                             
            tokenizer=tokenizer,                                                                                                                               
            data_collator=data_collator,                                                                                                                       
            compute_metrics=compute_metrics)How do I pass the argumentlabel_listat theTrainerto mycompute_metricsfunction? I couldn’t find any solutions to that.
2023-03-31T13:17:08Z
Hi, I thinkthisdiscussion could be useful for you:In a nutshelldef prepare_compute_metrics(label_list):
    def compute_metrics(p):
        nonlocal label_list
        ...
    return compute_metrics
    
compute_metrics = prepare_compute_metrics(label_list)
2023-04-10T13:39:43Z
thank you