# Custom evaluate for Trainer Class

**URL:** <https://discuss.huggingface.co/t/custom-evaluate-for-trainer-class/29467>\
**Category:** Beginners\
**Created:** [January 12, 2023, 7:58pm UTC](https://discuss.huggingface.co/t/custom-evaluate-for-trainer-class/29467 "2023-01-12T19:58:13Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![Mari22](https://avatars.discourse-cdn.com/v4/letter/m/57b2e6/32.png) [@Mari22](https://discuss.huggingface.co/u/Mari22)\
**Post date:** [January 12, 2023, 7:58pm UTC](https://discuss.huggingface.co/t/custom-evaluate-for-trainer-class/29467/1 "2023-01-12T19:58:13Z")

</div>

From the official documentation it say that “You can also subclass and override this method to inject custom behavior.” for the **evaluate** function, but I have a question about how make this, it should be like this?

```auto
class NewTrainer(Trainer):
    def __init__ (self, *args, **kwargs):
        super(). __init__ (*args, **kwargs)
        self.model.eval()
    def create_optimizer_and_scheduler(self, num_training_steps: int):
        self.optimizer = AdamW(model.parameters(), lr=self.args.learning_rate, correct_bias=False)
        self.total_steps = self.args.per_device_train_batch_size * self.args.num_train_epochs
        self.lr_scheduler = get_linear_schedule_with_warmup(self.optimizer, num_warmup_steps = 0, num_training_steps = self.total_steps)
    def evaluate(self, test_batches): 
            model.eval()
            tmp_m, tmp_m_sentence = test_model(model, test_batches)

```

where test\_model is a function that evaluate the model in the test datasets, in this function I split the text in sub chuncks and make the attention mechanism for the classification.
