Provides inference scripts specifically for text modules

LMLearner.get_preds[source]

LMLearner.get_preds(x:LMLearner, ds_idx=1, dl=None, raw_outs=False, decoded_loss=True, fully_decoded=False, concat_dim=0, **kwargs)

Get predictions with possible decoding

TextLearner.get_preds[source]

TextLearner.get_preds(x:TextLearner, ds_idx=1, dl=None, raw_outs=False, decoded_loss=True, fully_decoded=False, **kwargs)

Get predictions with possible decoding

LMLearner.predict[source]

LMLearner.predict(x:LMLearner, text, n_words=1, no_unk=True, temperature=1.0, min_p=None, decoder='decode_spec_tokens', only_last_word=False)

Predict n_words from text

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)
'my name is not always'
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
(['negative'], array([[0.5106333 , 0.48936665]], dtype=float32))
full_dec
(#1) [("xxbos xxmaj un - xxunk - believable ! xxmaj meg xxmaj ryan does n't even look her usual xxunk lovable self in this , which normally makes me forgive her shallow xxunk acting xxunk . xxmaj hard to believe she was the producer on this dog . xxmaj plus xxmaj kevin xxmaj kline : what kind of suicide trip has his career been on ? xxmaj xxunk … xxmaj xxunk xxrep 3 ! xxmaj finally this was directed by the guy who did xxmaj big xxmaj xxunk ? xxmaj must be a replay of xxmaj jonestown - hollywood style . w xxrep 3 o xxrep 3 f !", 'negative')]

TextLearner.intrinsic_attention[source]

TextLearner.intrinsic_attention(x:TextLearner, text:str, class_id:int=None, **kwargs)

Shows the intrinsic attention fortext, optionalclass_id`

learn.intrinsic_attention('Batman is rich')
xxbos xxmaj batman is rich