When doing a categorical prediction:
imdb_clas = DataBlock(blocks=(TextBlock.from_df(['days','comments'], vocab=dbunch.vocab), CategoryBlock),
get_x=attrgetter('text'),
get_y=attrgetter('liked'),
splitter=TrainTestSplitter(test_size = 0.2, stratify=df_scores['liked'], random_state = 12))
dbunch_class = imdb_clas.dataloaders(df, bs=32, seq_len=80)
learn = text_classifier_learner(dbunch_class, AWD_LSTM, drop_mult=0.5, metrics=[accuracy, Perplexity()], wd=0.1).to_fp16()
learn = learn.load_encoder('finetuned6_208.pkl')
Iām able to iterate through, and get a mapping of all the categories, along with its index. For example, with index 0:
learn.dls.categorize.decode(0)
'happy'
When I change this to a multicategory datablock, and target a different column which has comma-separated values:
imdb_clas = DataBlock(blocks=(TextBlock.from_df(['days','comments'], vocab=dbunch.vocab), MultiCategoryBlock),
get_x=attrgetter('text'),
splitter=RandomSplitter(seed = 42),
get_y=ColReader(3, label_delim=','))
dbunch_class = imdb_clas.dataloaders(df, bs=32, seq_len=80)
learn = text_classifier_learner(dbunch_class, AWD_LSTM, drop_mult=0.5, metrics=[accuracy_multi, Perplexity()], wd = 0.1).to_fp16()
learn = learn.load_encoder('finetuned6_208.pkl')
The same command gives me an error:
learn.dls.categorize.decode(0)
---------------------------------------------------------------------------
AttributeError Traceback (most recent call last)
<ipython-input-213-cc679bf817bd> in <module>
----> 1 learn.dls.categorize.decode(0)
~/git_packages/fastcore/fastcore/foundation.py in __getattr__(self, k)
228 if self._component_attr_filter(k):
229 attr = getattr(self,self._default,None)
--> 230 if attr is not None: return getattr(attr,k)
231 raise AttributeError(k)
232 def __dir__(self): return custom_dir(self,self._dir())
~/git_packages/fastcore/fastcore/foundation.py in __getattr__(self, k)
228 if self._component_attr_filter(k):
229 attr = getattr(self,self._default,None)
--> 230 if attr is not None: return getattr(attr,k)
231 raise AttributeError(k)
232 def __dir__(self): return custom_dir(self,self._dir())
~/git_packages/fastai2/fastai2/data/core.py in __getattr__(self, k)
285 return res if is_indexer(it) else list(zip(*res))
286
--> 287 def __getattr__(self,k): return gather_attrs(self, k, 'tls')
288 def __dir__(self): return super().__dir__() + gather_attr_names(self, 'tls')
289 def __len__(self): return len(self.tls[0])
~/git_packages/fastcore/fastcore/transform.py in gather_attrs(o, k, nm)
151 att = getattr(o,nm)
152 res = [t for t in att.attrgot(k) if t is not None]
--> 153 if not res: raise AttributeError(k)
154 return res[0] if len(res)==1 else L(res)
155
AttributeError: categorize
So when I do a get_preds(), I canāt tell which predictions are for which categories:
learn.get_preds()
a[0]
tensor([0.8300, 0.1622, 0.4473, 0.2733, 0.0688, 0.0237, 0.0163, 0.0094, 0.0798,
0.4658, 0.0957, 0.0152, 0.0296, 0.1708])
In fastai version 1, I can do this with c2i:
learn.data.c2i
{'team1': 0, 'team2': 1, 'team3': 2}
Is there an equivalent for the MultiCategoryBlock in fastai version 2?