Lesson3-imdb - Loading Databunch fails

I’m running through the imdb notebook and the load_data method is not defined. Any idea what’s going on?

load_data(path, ‘data_lm.pkl’, bs=bs)
data_lm = load_data(path, ‘data_lm.pkl’, bs=bs)

NameError Traceback (most recent call last)
in ()
----> 1 data_lm = load_data(path, ‘data_lm.pkl’, bs=bs)

NameError: name ‘load_data’ is not defined

@bbiseda : As @neuradai suggested, TextDataBunch class and its descendants is deprecated so you need to update your fastai package via conda/pip and course notebook files via git pull. This should resolve your issue:

NameError: name ‘load_data’ is not defined

Please see Returning to Work Section in course v3 documentation for your platform or choice, for example, I am using AWS so i am following this guide
https://course.fast.ai/update_aws.html

1 Like

Thank you. This resolved the issue.

1 Like

Any time :slight_smile:

What import do I need for my jupyter notebook to find load_data? I have updated my fastai library, done a git pull, restarted my server, and it’s still not able to call load_data

1 Like

Perhaps you might want to check which version of FastAI are you on to ensure that you have updated to the lastest version which as of now is 1.0.48

Are you on GCP? If you do, I had the same issue which I resolved by following the instructions here.

1 Like

Need to use the following for GCP to work.

sudo /opt/anaconda3/bin/conda install fastai -c fastai -c pytorch -c conda-forge

2 Likes

Thank you @coral! My problem was that fastai wasn’t updating to the latest version, as you predicted.

thanks for the note… by the way, could you help me 'Like" the answer, as I’m trying to collect likes… to get into FastAI round 2

2 Likes

@coral
I also an issue when I ran load_data. My fastai is the latest version. Could you give me a hint too?

conda list fastai

Name Version Build Channel

fastai 1.0.50.post1 1 fastai

Below is the error details.
data_lm.save(LM_PATH/‘data_lm.pkl’)
data_lm.load_data(LM_PATH, ‘data_lm.pkl’, bs=bs)

AttributeError Traceback (most recent call last)
in
----> 1 data_lm.load_data(LM_PATH)

/home/application/anaconda/lib/python3.7/site-packages/fastai/basic_data.py in getattr(self, k)
120 return cls(*dls, path=path, device=device, dl_tfms=dl_tfms, collate_fn=collate_fn, no_check=no_check)
121
–> 122 def getattr(self,k:int)->Any: return getattr(self.train_dl, k)
123 def setstate(self,data:Any): self.dict.update(data)
124

/home/application/anaconda/lib/python3.7/site-packages/fastai/basic_data.py in getattr(self, k)
36
37 def len(self)->int: return len(self.dl)
—> 38 def getattr(self,k:str)->Any: return getattr(self.dl, k)
39 def setstate(self,data:Any): self.dict.update(data)
40

/home/application/anaconda/lib/python3.7/site-packages/fastai/basic_data.py in DataLoader___getattr__(dl, k)
18 torch.utils.data.DataLoader.init = intercept_args
19
—> 20 def DataLoader___getattr__(dl, k:str)->Any: return getattr(dl.dataset, k)
21 DataLoader.getattr = DataLoader___getattr__
22

/home/application/anaconda/lib/python3.7/site-packages/fastai/data_block.py in getattr(self, k)
624 res = getattr(y, k, None)
625 if res is not None: return res
–> 626 raise AttributeError(k)
627
628 def setstate(self,data:Any): self.dict.update(data)

AttributeError: load_data

LM_PATH is a PosixPath.
LM_PATH
PosixPath(’/home/workspace/nlpproject/data/lm’)

Try this:

data_lm.save(fname='data_lm.pkl')
data_lm = load_data(LM_PATH, fname='data_lm.pkl', bs=bs)
1 Like

I still have the same error. After run data_lm.save(fname='data_lm.pkl'), I saw file data_lm.pkl is saved under data/lm/. But load_data still have the same error output. I also tried data_lm.load_data(path=LM_PATH, fname='data_lm.pkl', bs=bs), but the error is consistent.

please post your detailed error message

Finally I found the solution. It’s found the keyword ‘path’ at load_data() function cannot be changed. I need to run as below. I also give the context of all of my scripts at this section so that other people may need it.

path = LM_PATH

data_lm = TextLMDataBunch.from_csv(path, 'all_texts.csv', text_cols=1, label_cols=0)

data_lm.save(data_lm_export.pkl)

data_lm = load_data(path, fname='data_lm.pkl')

Basically, we should assign the value of path before use it. We cannot set it at the function load_data.

1 Like

For anyone finding this thread down the road, “fname=” didn’t seem to work for me anymore, but just passing the filename as the second argument (after path) should still work.

Tip for others who may be running into this. You do need to check that your fastai version is up to date, e.g. use pip list | grep fastai to list the version you have installed. In my case it was outdated, and I had to run pip install --upgrade fastai to get the latest version.

Hi,
I have a problem with the file data_save.pkl file that does not appear. But it is file appear on notebook https://github.com/fastai/course-nlp/blob/master/8-translation-transformer.ipynb. Someone can say me what happens.

hi,I think this link https://s0docs0fast0ai.icopy.site/basic_data.html#load_datamight illutrate load_data is a classmathod of DataBunch,what do you think?:grin:

If the load() method of TextDataBunch is deprecated, and TextClasDataBunch is a subclass of TextDataBunch,TextClasDataBunch.load(path)should also be deprecated,and it turns out right.
if I run TextClasDataBunch.load(path),it will also cause error “FileNotFoundError: [Errno 2] No such file or directory: ‘/root/.fastai/data/imdb_sample/tmp/itos.pkl’”
I wanna ask if there is also a substitute for “TextClasDataBunch.load(path)”

Use following to save
data_lm.save()

Then load as
data_lm = load_data(path)