# Loading finetuned model to generate text

**URL:** </static-proxy?url=https%3A%2F%2Fdiscuss.huggingface.co%2Ft%2Floading-finetuned-model-to-generate-text%2F892%3E%5C
**Category:** 🤗Transformers\
**Created:** [August 27, 2020, 5:08pm UTC](/static-proxy?url=https%3A%2F%2Fdiscuss.huggingface.co%2Ft%2Floading-finetuned-model-to-generate-text%2F892 "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](/static-proxy?url=https%3A%2F%2Fdiscuss.huggingface.co%2Fu%2Fmathor)%5C
**Post date:** [October 17, 2020, 4:45am UTC](/static-proxy?url=https%3A%2F%2Fdiscuss.huggingface.co%2Ft%2Floading-finetuned-model-to-generate-text%2F892%2F8 "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](/static-proxy?url=https%3A%2F%2Fdiscuss.huggingface.co%2Ft%2Fhow-to-save-and-load-fine-tune-model%2F1595)

---

_[View the full topic](/static-proxy?url=https%3A%2F%2Fdiscuss.huggingface.co%2Ft%2Floading-finetuned-model-to-generate-text%2F892)._
