Lesson4-IMDB LanguageModelData.from_text_files

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?

3 Likes

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')
1 Like

@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

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

2 Likes

@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??)

If I am starting a new session, how would I load learner if md is not defined?

Did you find out how to?