My Dataframe
id keyword location text target
0 1 NaN NaN Our Deeds are the Reason of this #earthquake M... 1
1 4 NaN NaN Forest fire near La Ronge Sask. Canada 1
2 5 NaN NaN All residents asked to 'shelter in place' are ... 1
3 6 NaN NaN 13,000 people receive #wildfires evacuation or... 1
4 7 NaN NaN Just got sent this photo from Ruby #Alaska as ... 1
I’m only interested in the “text” and “target” columns.
This is my DataBlock
class_lm = DataBlock(
blocks=(TextBlock.from_df('text', seq_len=15, is_lm=True), CategoryBlock),
get_x=ColReader('text'), get_y=ColReader('target'), splitter=RandomSplitter(0.1))
This is my dataloaders
dls = dls_lm.dataloaders(df2, bs=24)
This is my learner
learn = language_model_learner(
dls, AWD_LSTM, drop_mult=0.3,
metrics=[accuracy, Perplexity()]
)
learn.fine_tune(1, 2e-2)
epoch train_loss valid_loss accuracy perplexity time
0 3.496560 3.430030 0.419661 30.877579 17:33
epoch train_loss valid_loss accuracy perplexity time
0 2.915300 3.042652 0.471342 20.960751 25:20
When I want to make a prediction:
TEXT = “I was afraid that”
N_WORDS = 20
N_SENTENCES = 4
preds = [learn.predict(TEXT, N_WORDS, temperature=0.75) for _ in range(N_SENTENCES)]
I ve got this error:
---------------------------------------------------------------------------
ValueError Traceback (most recent call last)
in ()
2 N_WORDS = 20
3 N_SENTENCES = 4
----> 4 preds = [learn.predict(TEXT, N_WORDS, temperature=0.75) for _ in range(N_SENTENCES)]
1 frames
/usr/local/lib/python3.7/dist-packages/fastai/text/learner.py in predict(self, text, n_words, no_unk, temperature, min_p, no_bar, decoder, only_last_word)
157 self.model.reset()
158 idxs = idxs_all = self.dls.test_dl([text]).items[0].to(self.dls.device)
→ 159 if no_unk: unk_idx = self.dls.vocab.index(UNK)
160 for _ in (range(n_words) if no_bar else progress_bar(range(n_words), leave=False)):
161 with self.no_bar(): preds,_ = self.get_preds(dl=[(idxs[None],)])
ValueError: ‘xxunk’ is not in list