# Loading finetuned model to generate text

**URL:** <https://discuss.huggingface.co/t/loading-finetuned-model-to-generate-text/892>\
**Category:** 🤗Transformers\
**Created:** [August 27, 2020, 5:08pm UTC](https://discuss.huggingface.co/t/loading-finetuned-model-to-generate-text/892 "2020-08-27T17:08:23Z")\
**Posts on this page:** 1\
**Showing post:** 8

<div class="post-metadata">

**Author:** ![mathor](https://sea2.discourse-cdn.com/hellohellohello/user_avatar/discuss.huggingface.co/mathor/32/480_2.png) [@mathor](https://discuss.huggingface.co/u/mathor)\
**Post date:** [October 17, 2020, 4:45am UTC](https://discuss.huggingface.co/t/loading-finetuned-model-to-generate-text/892/8 "2020-10-17T04:45:48Z")

</div>

thank you for your answer, but i have a question for you  
I validate the model as I train it, and save the model with the highest scores on the validation set using `torch.save(model.state_dict(), output_model_file)`. As shown in the figure below  
 ![](https://us1.discourse-cdn.com/hellohellohello/original/2X/3/338141beaa4a036aa2bbb5b1e95699bbad9c0f01.png)

Then I trained again and loaded the previously saved model instead of training from scratch, but it didn’t work well, which made me feel like it wasn’t saved or loaded successfully?  
`model.load_state_dict(torch.load(output_model_file))`  
 ![](https://us1.discourse-cdn.com/hellohellohello/original/2X/5/5a0ff85a2cd10e4e68d72987d2abf3117c571e6d.png)

My model code is [here](https://discuss.huggingface.co/t/how-to-save-and-load-fine-tune-model/1595)

---

_[View the full topic](https://discuss.huggingface.co/t/loading-finetuned-model-to-generate-text/892)._
