# Trainer.predict() does not return values in optuna search

**URL:** <https://discuss.huggingface.co/t/trainer-predict-does-not-return-values-in-optuna-search/14020>\
**Category:** 🤗Transformers\
**Created:** [January 23, 2022, 3:58pm UTC](https://discuss.huggingface.co/t/trainer-predict-does-not-return-values-in-optuna-search/14020 "2022-01-23T15:58:55Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![louisa-s-e](https://avatars.discourse-cdn.com/v4/letter/l/3ec8ea/32.png) [@louisa-s-e](https://discuss.huggingface.co/u/louisa-s-e)\
**Post date:** [January 23, 2022, 3:58pm UTC](https://discuss.huggingface.co/t/trainer-predict-does-not-return-values-in-optuna-search/14020/1 "2022-01-23T15:58:55Z")

</div>

I am trying to train some models on question answering mostly following this [course](https://huggingface.co/course/chapter7/7?fw=pt).  
However, instead of taking the default hyperparameters given in the course, I am trying to perform hyperparameter search using the optuna backend.

Without hp search this code runs perfectly fine for me:  
_predictions=trainer.predict(validation\_dataset)_  
_start\_logits,end\_logits=predictions[0]_  
_metrics=compute\_metrics(start\_logits, end\_logits, validation\_dataset, dataset[“test”])_  
_em=metrics[“exact\_match”]_  
_f1=metrics[“f1”]_

but once I include it into the hyperparameter search it is throwing an error.  
My code looks like this:

 ![grafik](https://us1.discourse-cdn.com/hellohellohello/original/2X/7/7a2e8e903203c61e5bae2b6109c84434bdd59571.png)

and I get the following error for the line where I am extracting the logits.  
_33 predictions=trainer.predict(validation\_dataset)_  
_—\> 34 start\_logits,end\_logits=predictions[0]_  
_35 metrics=compute\_metrics(start\_logits, end\_logits, validation\_dataset,dataset[“test”])_  
_36 em=metrics[“exact\_match”]_  
_TypeError: cannot unpack non-iterable NoneType object_

I think that the trainer.predict() is not returning anything when I am using it in the objective function and I have no ides why since it is working if I use it outside.

Thank you in advance!
