yandex-research / tabular-dl-tabr

The implementation of "TabR: Unlocking the Power of Retrieval-Augmented Tabular Deep Learning"
https://arxiv.org/abs/2307.14338
MIT License
261 stars 27 forks source link

Expected 2d tensor for the single feature of such type, got 1d #3

Open susie-ku opened 1 year ago

susie-ku commented 1 year ago

Hi! Thank you for your interesting work. I faced some problems because of this function (https://github.com/yandex-research/tabular-dl-tabr/blob/d628ec7e1c0a66011473021034e7dd4a77740112/lib/data.py#L117). I have dataset with only one binary feature, it is flattened to 1d tensor, but later 2d tensor expected. Writing torch.atleast_2d(torch.as_tensor(value)).to(device) instead of torch.as_tensor(value).to(device) solved this problem.

Yura52 commented 1 year ago

Hi! Thank you for sharing your experience! I will keep this issue open and fix it a bit later. I think the best way to fix the issue is to specify here that 2-dimensional data is expected and/or add assert somewhere. I am afraid that supporting dynamic shapes and performing implicit transformations can be dangerous long-term.

susie-ku commented 1 year ago

Thank you for the response! Do you mean that for now we should pass only 2d data as input? Btw my solution isn't so good, because later it produces errors with target's shape XD

Yura52 commented 1 year ago

Do you mean that for now we should pass only 2d data as input?

Yes, all feature arrays (X_*_{train|val|test}.npy) must have the shape (n_objects, n_features), even if any of the two dimensions is equal to 1.

Minhvt34 commented 4 months ago

Excellent work Yura!

FYI @susie-ku working with Transformer you usually encounter matrix multiplication. I always keep my eyes on whether a vector with shape (x,) or (x,y). Reshape (x,) to (1, x) or (x, 1) is necessary.