In part 1, we could generate predictions from a LM (in my case, get it to turn prompts into full sentences) using something like
def test(s): m=learner.model #m.bs = 1 t=TEXT.numericalize(s) res,*_ = m(t) i = 0 prnt = '' while prnt != '.' and i < bptt: n=res[-1].topk(2) n = n if n.data==0 else n prnt = TEXT.vocab.itos[n.data] print(prnt, end=' ') res,*_ = m(n.unsqueeze(0)) i += 1
However, that was using torchtext - I looked around the source code of text.py and couldn’t figure out how to do this with the new class. I’m not interested in a classifier, just in the language model.