Provides inference scripts specifically for text modules
path = untar_data(URLs.IMDB_SAMPLE)
df = pd.read_csv(path/'texts.csv')
data_lm = TextDataLoaders.from_csv(path, 'texts.csv', text_col='text', is_lm=True)
lm_learn = language_model_learner(data_lm, AWD_LSTM, drop_mult=0.3)
lm_learn.save_encoder('fine_tuned')
blocks = (TextBlock.from_df('text', seq_len=data_lm.seq_len, vocab=data_lm.vocab), CategoryBlock())
imdb_clas = DataBlock(blocks=blocks,
get_x=ColReader('text'),
get_y=ColReader('label'),
splitter=ColSplitter())
dls = imdb_clas.dataloaders(df, bs=64)
lm_learn.predict('my name is', n_words=2)
learn = text_classifier_learner(dls, AWD_LSTM, drop_mult=0.5, metrics=accuracy)
learn.path = path
learn.load_encoder('fine_tuned');
dl = learn.dls.test_dl(df.iloc[:1])
name, probs, full_dec = learn.get_preds(dl=dl, fully_decoded=True)
name, probs
full_dec
learn.intrinsic_attention('Batman is rich')