Lesson4-IMDB LanguageModelData.from_text_files


(Sam) #1

After having generated datamodel md as:

md = LanguageModelData.from_text_files(PATH, TEXT, **FILES, bs=bs, bptt=bptt, min_freq=10)

I want to give myself and my computer a break.

Is there a way to save the md?
my TEXT object is saved as a pickle.
md happens to be a generator and hence can’t be pickled.
Can I build md from the pickled TEXT?


(Igor Kasianenko) #2

In Train part of the notebook


you can create learner

learner = md.get_model(opt_fn, em_sz, nh, nl,
                       dropouti=0.05, dropout=0.05, wdrop=0.1, dropoute=0.02, dropouth=0.05)
learner.reg_fn = partial(seq2seq_reg, alpha=2, beta=1)
learner.clip=0.3

and save/load it after training the model

learner.save_encoder('adam1_enc')
learner.load_encoder('adam1_enc')

(Sam) #3

@Kasianenko
Igor, I wanted to save the model data object after having spent long time in building the TEXT object.
I wanted to take a break before starting training the model.
After training I would save the model (learner object) and load it as you suggest


(Igor Kasianenko) #4

You may save learner before starting train, in will save initial model before training


(Sam) #5

@Kasianenko
Thank you. I also noticed that the execution of line:

md = LanguageModelData.from_text_files(PATH, TEXT, **FILES, bs=bs, bptt=bptt, min_freq=10)

does not take as long as it used to. So my question about saving the md is not critical for me any more. I am on pytorch 0.4 (which maybe why the execution time is better maybe??)