T5-Finetuning-PyTorch icon indicating copy to clipboard operation
T5-Finetuning-PyTorch copied to clipboard

How to load T5 after fine tuning?

Open majd-alhafi opened this issue 4 years ago • 5 comments

Good morning.

This repo is so great, but I have a little problem after the model is saved how can I load them and generate a sequence?

Thank you.

majd-alhafi avatar Dec 15 '21 11:12 majd-alhafi

Hi Shivanandroy this was a great repo, please tell us the problem how to load the model to predict the text?

samareshyadav55 avatar Jan 25 '22 08:01 samareshyadav55

Hi Shivanand,

I'd also like to know how to load the model after training is done. Is it necessary to load it to HuggingFace? After I finish fine-tuning, my 'model' is no longer callable. Any advice is appreciated.

Thanks

timohromadka avatar Mar 11 '22 01:03 timohromadka

Hi @timohromadka , @samareshyadav55 - I have packaged this script into a python library for ease of use: SimpleT5 pip install simplet5

# import
from simplet5 import SimpleT5

# instantiate
model = SimpleT5()

# load (supports t5, mt5, byT5 models)
model.from_pretrained("t5","t5-base")

# train
model.train(train_df=train_df, # pandas dataframe with 2 columns: source_text & target_text
            eval_df=eval_df, # pandas dataframe with 2 columns: source_text & target_text
            source_max_token_len = 512, 
            target_max_token_len = 128,
            batch_size = 8,
            max_epochs = 5,
            use_gpu = True,
            outputdir = "outputs",
            early_stopping_patience_epochs = 0,
            precision = 32
            )

# load trained T5 model
model.load_model("t5","path/to/trained/model/directory", use_gpu=False)

# predict
model.predict("input text for prediction")

Shivanandroy avatar Mar 14 '22 08:03 Shivanandroy

thanks for your help shivanandroy 👍

samareshyadav55 avatar Apr 29 '22 10:04 samareshyadav55

Hi @Shivanandroy, thank you so much for this repo. I have made some modifications to the T5 model and would like to use the fine-trained model for inference (instead of simpleT5). It would be really helpful if you can explain how I can use the fine-tuned model for inference and also is there a way I can generate some kind confidence percentage for a prediction during inference.

VishalPallagani avatar Jul 26 '22 13:07 VishalPallagani