Unable to use intrinsic_attention for .pkl model

Hi @herrmann. First off, thank you for adding the interpret feature into the library.

At the moment i’m trying to use it for my use case. I’ve saved my text classification model as a .pkl, loaded it using below command:

model = load_learner(Path(f’…/{model_path}’), file=f’classifier.pkl’)
interp = TextClassificationInterpretation.from_learner(model)

However I’m current met with the following error message:


IndexError Traceback (most recent call last)
in
----> 1 interp = TextClassificationInterpretation.from_learner(model)

~/anaconda3/envs/ccs-ai-cfe/lib/python3.6/site-packages/fastai/train.py in from_learner(cls, learn, ds_type)
148 def from_learner(cls, learn: Learner, ds_type:DatasetType=DatasetType.Valid):
149 “Gets preds, y_true, losses to construct base class from a learner”
–> 150 preds_res = learn.get_preds(ds_type=ds_type, with_loss=True)
151 return cls(learn, *preds_res)
152

~/anaconda3/envs/ccs-ai-cfe/lib/python3.6/site-packages/fastai/text/learner.py in get_preds(self, ds_type, with_loss, n_batch, pbar, ordered)
84 self.model.reset()
85 if ordered: np.random.seed(42)
—> 86 preds = super().get_preds(ds_type=ds_type, with_loss=with_loss, n_batch=n_batch, pbar=pbar)
87 if ordered and hasattr(self.dl(ds_type), ‘sampler’):
88 np.random.seed(42)

~/anaconda3/envs/ccs-ai-cfe/lib/python3.6/site-packages/fastai/basic_train.py in get_preds(self, ds_type, with_loss, n_batch, pbar)
334 lf = self.loss_func if with_loss else None
335 return get_preds(self.model, self.dl(ds_type), cb_handler=CallbackHandler(self.callbacks),
–> 336 activ=_loss_func2activ(self.loss_func), loss_func=lf, n_batch=n_batch, pbar=pbar)
337
338 def pred_batch(self, ds_type:DatasetType=DatasetType.Valid, batch:Tuple=None, reconstruct:bool=False, with_dropout:bool=False) -> List[Tensor]:

~/anaconda3/envs/ccs-ai-cfe/lib/python3.6/site-packages/fastai/basic_train.py in get_preds(model, dl, pbar, cb_handler, activ, loss_func, n_batch)
42 “Tuple of predictions and targets, and optional losses (if loss_func) using dl, max batches n_batch.”
43 res = [torch.cat(o).cpu() for o in
—> 44 zip(*validate(model, dl, cb_handler=cb_handler, pbar=pbar, average=False, n_batch=n_batch))]
45 if loss_func is not None:
46 with NoneReduceOnCPU(loss_func) as lf: res.append(lf(res[0], res[1]))

~/anaconda3/envs/ccs-ai-cfe/lib/python3.6/site-packages/fastai/basic_train.py in validate(model, dl, loss_func, cb_handler, pbar, average, n_batch)
55 val_losses,nums = [],[]
56 if cb_handler: cb_handler.set_dl(dl)
—> 57 for xb,yb in progress_bar(dl, parent=pbar, leave=(pbar is not None)):
58 if cb_handler: xb, yb = cb_handler.on_batch_begin(xb, yb, train=False)
59 val_loss = loss_batch(model, xb, yb, loss_func, cb_handler=cb_handler)

~/anaconda3/envs/ccs-ai-cfe/lib/python3.6/site-packages/fastprogress/fastprogress.py in iter(self)
70 self.update(0)
71 try:
—> 72 for i,o in enumerate(self._gen):
73 if i >= self.total: break
74 yield o

~/anaconda3/envs/ccs-ai-cfe/lib/python3.6/site-packages/fastai/basic_data.py in iter(self)
73 def iter(self):
74 “Process and returns items from DataLoader.”
—> 75 for b in self.dl: yield self.proc_batch(b)
76
77 @classmethod

~/anaconda3/envs/ccs-ai-cfe/lib/python3.6/site-packages/torch/utils/data/dataloader.py in iter(self)
191
192 def iter(self):
–> 193 return _DataLoaderIter(self)
194
195 def len(self):

~/anaconda3/envs/ccs-ai-cfe/lib/python3.6/site-packages/torch/utils/data/dataloader.py in init(self, loader)
491 # prime the prefetch loop
492 for _ in range(2 * self.num_workers):
–> 493 self._put_indices()
494
495 def len(self):

~/anaconda3/envs/ccs-ai-cfe/lib/python3.6/site-packages/torch/utils/data/dataloader.py in _put_indices(self)
589 def _put_indices(self):
590 assert self.batches_outstanding < 2 * self.num_workers
–> 591 indices = next(self.sample_iter, None)
592 if indices is None:
593 return

~/anaconda3/envs/ccs-ai-cfe/lib/python3.6/site-packages/torch/utils/data/sampler.py in iter(self)
170 def iter(self):
171 batch = []
–> 172 for idx in self.sampler:
173 batch.append(idx)
174 if len(batch) == self.batch_size:

~/anaconda3/envs/ccs-ai-cfe/lib/python3.6/site-packages/fastai/text/data.py in iter(self)
103 def len(self) -> int: return len(self.data_source)
104 def iter(self):
–> 105 return iter(sorted(range_of(self.data_source), key=self.key, reverse=True))
106
107 class SortishSampler(Sampler):

IndexError: list index out of range

Any ideas why?

Note: I’m currently using fastai version 1.0.55