Problem using "ColumnarModelData" for classification

Trying to use ColumnarModelData for classification but running into some issues.

I converted y to be one-hot encoded and also set the learner to use F.cross_entropy. But when I attempt to fit the model
I get an exception:

multi-target not supported at /opt/conda/conda-bld/pytorch_1512386481460/work/torch/lib/THCUNN/generic/

Any ideas on what I need to change to get this thing working?


Your y should be an int - not dummy coded.

So if I have 3 possible classes that I want to get predictions for … I should

  1. LabelEncode the targets

  2. Change the output_size = 3

Sound right?

I think so, although I’d need to see the code. GIve It a go! And take a look at a minibatch from the dogs v cats notebook to see an example.

Debugging the file …

loss = raw_loss = self.crit(output, y)

The predictions (output) are coming back as expected, a 64x3 tensor. The target (y), however, is a 64x1 tensor.

Found the problem:

class ColumnarDataset(Dataset):
    def __init__(self, cats, conts, y):
        n = len(cats[0]) if cats else len(conts[0])
        self.cats = np.stack(cats, 1).astype(np.int64) if cats else np.zeros((n,1))
        self.conts = np.stack(conts, 1).astype(np.float32) if conts else np.zeros((n,1))
        self.y = np.zeros((n,1)) if y is None else y #y[:,None]

The last line … converts y to a vector, which works great for regression but not classification. Before I submit a PR, just want to make sure I’m not messing something up because I’m not understanding the implications of how this will affect code elsewhere.


thanks - wg

1 Like

Ah well spotted. I needed to make it a column vector since otherwise when it is indexed, it creates a scalar of the wrong type. So you should test any PR still works on the existing lessons.

Any lessons in particular?

I tested both a regression and multi-class classification example I worked up, and everything worked with just the “y”. If there are lessons that were blowing up without things as is, it would help me make sure to mitigate me blowing them up again.

Thanks much

Thanks for checking! Movielens and Rossmann are the main ones I can think of.