Colab Error: "AttributeError: 'PosixPath' object has no attribute 'load'."

The following code in Google Colab

!pip install fastai==2.0.13
from fastai.text.all import *

path = untar_data(URLs.IMDB_SAMPLE)
imdb = pd.read_csv(path/'texts.csv')
imdb_lm = TextDataLoaders.from_df(imdb, text_col='text', is_lm=True)
learn = language_model_learner(imdb_lm, AWD_LSTM)

show the following error:

AttributeError                            Traceback (most recent call last)
<ipython-input-3-d30d5800447c> in <module>()
      2 imdb = pd.read_csv(path/'texts.csv')
      3 imdb_lm = TextDataLoaders.from_df(imdb, text_col='text', is_lm=True)
----> 4 learn = language_model_learner(imdb_lm, AWD_LSTM)

2 frames
/usr/local/lib/python3.6/dist-packages/fastcore/ in _f(*args, **kwargs)
     50         log_dict = {**func_args.arguments, **{f'{k} (not in signature)':v for k,v in xtra_kwargs.items()}}
     51         log = {f'{f.__qualname__}.{k}':v for k,v in log_dict.items() if k not in but}
---> 52         inst = f(*args, **kwargs) if to_return else args[0]
     53         init_args = getattr(inst, 'init_args', {})
     54         init_args.update(log)

/usr/local/lib/python3.6/dist-packages/fastai/text/ in language_model_learner(dls, arch, config, drop_mult, backwards, pretrained, pretrained_fnames, **kwargs)
    210             try: fnames = [list(model_path.glob(f'*.{ext}'))[0] for ext in ['pth', 'pkl']]
    211             except IndexError: print(f'The model in {model_path} is incomplete, download again'); raise
--> 212         learn = learn.load_pretrained(*fnames)
    213     return learn

/usr/local/lib/python3.6/dist-packages/fastai/text/ in load_pretrained(self, wgts_fname, vocab_fname, model)
    110     def load_pretrained(self, wgts_fname, vocab_fname, model=None):
    111         "Load a pretrained model and adapt it to the data vocabulary."
--> 112         old_vocab = Path(vocab_fname).load()
    113         new_vocab = _get_text_vocab(self.dls)
    114         distrib_barrier()

AttributeError: 'PosixPath' object has no attribute 'load'

I executed this same code two weeks ago and everything was fine, can anyone tell me why is it happening?

@arnau this was adjusted in fastcore to work with pickles instead. You should either downgrade your fastcore version or upgrade your fastai version

Thanks with fastai==2.0.16 is working

1 Like