Hi,
I tried an NLP transfer learning with fast ai version 2.2.5. But I got an AttributeError: ‘str’ object has no attribute ‘to’ error with LMLearner.
from fastai.data.external import URLs
from fastai.data.external import untar_data
from fastai.text.data import TextDataLoaders
from fastai.text.models.awdlstm import AWD_LSTM
from fastai.text.learner import language_model_learner
path = untar_data(URLs.IMDB)
data_loader = TextDataLoaders.from_folder(path, train='train', valid='test')
learn_lm = language_model_learner(data_loader, AWD_LSTM)
learn_lm.predict('Hello')
with error
AttributeError Traceback (most recent call last)
<ipython-input-16-c86f96a89a3b> in <module>
----> 1 learn_lm.predict('Hello')
/workspace/project/fastai/fastai/text/learner.py in predict(self, text, n_words, no_unk, temperature, min_p, no_bar, decoder, only_last_word)
156 "Return `text` and the `n_words` that come after"
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)):
AttributeError: 'str' object has no attribute 'to'
It seems self.dls.test_dl([text]).items[0]
returns str format rather than pytorch tensor.
is that line should be data_loader.test_dl('hello').do_item(0)[0].to(data_loader.device)
or I miss something?
Many thanks