lvdmaaten / bhtsne

Barnes-Hut t-SNE
Other
894 stars 240 forks source link

Pytorch version? #73

Open antspy opened 6 years ago

antspy commented 6 years ago

Hi,

Since t-SNE is increasingly used to visualize neural networks outputs (and their layers), it would be extremely helpful to have an implementation of t-SNE in pytorch, in particular the barnes-hut version that runs in N log N.

Is this something you would be interested in doing? Thanks!

lvdmaaten commented 6 years ago

Given a PyTorch tensor, can't you simply run run_bh_tsne(tensor.numpy(), **kwargs)?

antspy commented 6 years ago

Thank you for your quick reply! You're right, I was a bit unclear.

The problem with that is that you need to save your whole dataset into memory; I was thinking of a version that uses a data loader instance that returns the batches, and instead of doing gradient descent you do SGD on every batch (and ideally, everything runs on GPU so you don't have to move the tensors back and forth from CPU and GPU).

lvdmaaten commented 6 years ago

@antspy I see. That is a non-trivial project for at least two reasons: (1) t-SNE is an non-parametric method, which makes getting SGD to work well less trivial (note an SGD update will only update part of the parameters) and (2) implementing an efficient Barnes-Hut algorithm on GPUs is non-trivial because the algorithm is presumably memory-bound rather than compute-bound. Efficient GPU implementations likely require further approximations; see, for instance, this.

antspy commented 6 years ago

@lvdmaaten I see. Thank your for the clarification!