TextList error 'NoneType' object has no attribute 'textify'

I am trying to create a data for a classifier, as in imdb notebook. But it shows 'NoneType' object has no attribute 'textify'. I already checked there is no NaN value in the dataframe:
data.isnull().any().sum() returns 0.

Here is the code with error:

data.to_csv('texts.csv', sep=';', encoding='utf-8')

TextList.from_csv('.', 'texts.csv', delimiter=";", cols='text')
---------------------------------------------------------------------------
AttributeError                            Traceback (most recent call last)
~/anaconda3/envs/fastai/lib/python3.7/site-packages/IPython/core/formatters.py in __call__(self, obj)
    700                 type_pprinters=self.type_printers,
    701                 deferred_pprinters=self.deferred_printers)
--> 702             printer.pretty(obj)
    703             printer.flush()
    704             return stream.getvalue()

~/anaconda3/envs/fastai/lib/python3.7/site-packages/IPython/lib/pretty.py in pretty(self, obj)
    400                         if cls is not object \
    401                                 and callable(cls.__dict__.get('__repr__')):
--> 402                             return _repr_pprint(obj, self, cycle)
    403 
    404             return _default_pprint(obj, self, cycle)

~/anaconda3/envs/fastai/lib/python3.7/site-packages/IPython/lib/pretty.py in _repr_pprint(obj, p, cycle)
    695     """A pprint that just redirects to the normal repr function."""
    696     # Find newlines and replace them with p.break_()
--> 697     output = repr(obj)
    698     for idx,output_line in enumerate(output.splitlines()):
    699         if idx:

~/Code/fastai/fastai/data_block.py in __repr__(self)
     64         return self.items[i]
     65     def __repr__(self)->str:
---> 66         items = [self[i] for i in range(min(5,len(self.items)))]
     67         return f'{self.__class__.__name__} ({len(self.items)} items)\n{show_some(items)}\nPath: {self.path}'
     68 

~/Code/fastai/fastai/data_block.py in <listcomp>(.0)
     64         return self.items[i]
     65     def __repr__(self)->str:
---> 66         items = [self[i] for i in range(min(5,len(self.items)))]
     67         return f'{self.__class__.__name__} ({len(self.items)} items)\n{show_some(items)}\nPath: {self.path}'
     68 

~/Code/fastai/fastai/data_block.py in __getitem__(self, idxs)
    102     def __getitem__(self,idxs:int)->Any:
    103         idxs = try_int(idxs)
--> 104         if isinstance(idxs, Integral): return self.get(idxs)
    105         else: return self.new(self.items[idxs], inner_df=index_row(self.inner_df, idxs))
    106 

~/Code/fastai/fastai/text/data.py in get(self, i)
    319     def get(self, i):
    320         o = super().get(i)
--> 321         return Text(o, self.vocab.textify(o))
    322 
    323     def label_for_lm(self, **kwargs):

AttributeError: 'NoneType' object has no attribute 'textify'

Any idea what might be wrong?

Looks like somehow your Vocab isn’t getting set. Did you pass one in?

1 Like

The csv created by pandas had an index. Saving .to_csv(index=False) did the trick

Still, I am struggling to run a classifier in my own language model. The class and notebook on the subject (imdb) does not cover it exactly as it assumes one wants to use english lm.

Hi there, I am also facing this same problem. Did you ever figure it out what caused this and how to solve it? Thanks.

I think the Vocab is created when the processor are called, and that happens at the creation of the label in the label_from_list call in the ItemLists in the data_block.py file. As a result, before passing your training and validation set and your labels, the vocab has not been created yet hence the error.

A way to solve this is just to ignore it and to proceed with your databunch creation, once the processors have been called everything should be working fine.

I submitted an issue on fastai’s Github regarding this : https://github.com/fastai/fastai/issues/2208