Obtaining predictions get_preds() for dictionary dataloaders

Hello,

I am attempting to run learn.get_preds(dl=valid_dl,with_input=True) on my fastai2 model.
I am getting the error TypeError: Expected tensor, tuple, list or L but got <class 'dict'>.

My valid_dl consists of dictionaries, since I am working with BERT transformers. Each element of the valid_dl consist of the format ({'input_ids': tensor([[ 101, 1996, 2162, ..., 0, 0, 0], [ 101, 1996, 2845, ..., 0, 0, 0]]), 'attention_mask': tensor([[1, 1, 1, ..., 0, 0, 0], [1, 1, 1, ..., 0, 0, 0]])}, tensor([0, 1]))

Is there any way to allow get_preds() to work with dictionary style data?

For reference, I am basing off the tutorial: https://colab.research.google.com/github/AmarSaini/Epoching-Blog/blob/master/_notebooks/2021-06-27-NLP-from-Scratch-with-PyTorch-FastAI-and-HuggingFace.ipynb

1 Like