600X t-SNE speedup with RAPIDS. RAPIDS GPU-accelerated t-SNE achieves a... | by Connor Shorten | Towards Data Science

GPU accelerations are commonly associated with Deep Learning. GPUs power Convolutional Neural Networks for Computer Vision and Transformers for Natural Language Processing. They do this through parallel computation, making them much faster for certain tasks compared to CPUs.
RAPIDS is expanding the utilization of GPUs by bringing traditional Machine Learning and Data Science algorithms, such as t-SNE or XGBoost, to GPUs.
Hardware: This experiment was run on the Data Science PC by Digital Storm
t-SNE is an algorithm for visualizing high-dimensional data. Shown above is an example of transforming the 512-dimensional vectors from intermediate CNN activations into 2-dimensional vectors. Each image in the CIFAR-10 dataset is passed through the image classifier. The activations right before the final classification layer are added to an array for visualization. This is done with the following line of code:
from tensorflow.keras.models import Modelintermediate_layer_model = Model(inputs = model.input,            outputs = model.get_layer('VisualizationLayer').output)
The final Dense layer is given the name ‘VisualizationLayer’ to index it in this way
t-SNE visualization is great for gaining intuition about the decision space. Another approach to this might be to use a confusion matrix. The t-SNE visualization shows errors such as the overlap between cars and airplanes. Whereas a confusion matrix would simply tell us something like ‘8’ cars have been misclassified as airplanes, the t-SNE visualization gives more information about what is happening here. We see that at least the misclassified cars are on the fringe of the airplane boundary, we might be able to solve this problem with some label smoothing / data augmentation.
Gaining intuition about our models is very useful for this kind of EDA (exploratory data analysis). This can help inform data-level decisions such as identifying the impact of class imbalance, data augmentation, or utility of gathering more data. This can also help compare loss functions with another.
In “GAN-based Synthetic Medical Image Augmentation for increased CNN Performance in Liver Lesion Classification”, Frid-adar et al. use t-SNE visualizations to show how adding GAN-generated data improves the decision boundaries for Medical Image classification (notice the improved disentanglement of the blue class in figure b compared to a).
In “Improving Adversarial Robustness via Guided Complement Entropy” by Chen et al. They show how their improvement on the cross-entropy loss function results in a smoother decision boundary with less overlap (compare the figure on the right to the figure on the left). They use this visualization to illustrate how their improved decision boundaries provide adversarial attack defense.
This example demonstrates > 600X speedup on t-SNE using RAPIDS vs. Sklearn
This example is running the Barnes-Hut (n log n) version of t-SNE on 50,000 CIFAR-10 images that have been processed through an image classifier (trained to 79% accuracy) to 512-dimensional vectors. The t-SNE algorithm converts these 512-d vectors to 2-d for visualization.
1918 seconds (~30 minutes) (Sklearn)
from sklearn.manifold import TSNEsklearn_embedded = TSNE(n_components=2).fit_transform(embeddings)
3 seconds (RAPIDS cuml)
from cuml.manifold import TSNE as cumlTSNEtsne = cumlTSNE(n_components=2, method='barnes_hut')tsne_embedding = tsne.fit_transform(embeddings)
Hardware: This experiment was run on the Data Science PC by Digital Storm
The t-SNE speedup enabled by RAPIDS makes high-dimensional data visualization much more practical. Embedding the 50K CIFAR-10 vectors took 30 minutes on the CPU implementation, trying to embed the 1.2 million ImageNet dataset would take at least 12 hours by extension if the t-SNE algorithm had O(n) time complexity (although the latter log n of the barnes-hut algorithm would be largely negligible at this scale).
Powered by RAPIDS, t-SNE visualization can enable visualization of the entire ImageNet dataset (explored in t-SNE-CUDA by Chan et al.).
GPU speedups on these kinds of vector representations are also enormously useful for Image similarity / retrieval applications. One of the best approaches for finding the most semantically similar image from a large image database is to compare the intermediate activations of an image classifier. This results in comparing a large set of k-dimensional vector embeddings from the classifier. RAPIDS can dramatically speed up this kind of operation for clustering algorithms such as K-Means.
t-SNE is a great technique to gain insight about datasets and the intermediate representations constructed by neural networks. RAPIDS is helping power t-SNE to new heights through GPU-acceleration, enabling a much larger volume of data to be visualized with this algorithm.
Thanks for reading! If you found this article interesting, you may also enjoy this video walking through the experiment step-by-step from the NGC docker container to setup the RAPIDS libraries to the final t-SNE visualization!