Learn.model input? (Tabular)

So, fairly basic question here. If I want to just do a raw prediction using the model input on a tensor, I should be able to do the following yes? (on a tabular model):

input = data.train_ds.x[0].data
learn.model(input[0], input[1])

But I get an error saying there’s too many indices for my embeddings… thoughts? Did I miss something?

/usr/local/lib/python3.6/dist-packages/fastai/tabular/models.py in <listcomp>(.0)
     29     def forward(self, x_cat:Tensor, x_cont:Tensor) -> Tensor:
     30         if self.n_emb != 0:
---> 31             x = [e(x_cat[:,i]) for i,e in enumerate(self.embeds)]
     32             x = torch.cat(x, 1)
     33             x = self.emb_drop(x)

IndexError: too many indices for tensor of dimension 1

You need to apply the mdoel to a batch, so unsqueeze the first dimension to have batch of size 1.


Got it!!! Thanks! For anyone else:

input = data.train_ds.x[0].data
cat = input[0].unsqueeze(dim=0).cuda()
cont = input[1].unsqueeze(dim=0).cuda()
learn.model(cat, cont)