tSNE is a dimension reduction and vector projection method. It's main use is in visualizing high-dimensional vectors, such as text embeddings, in 2D or 3D plots.
npm install msvana-tsneThis packages provides the JavaScript/TypeScript version of the t-SNE algorithm for projecting
high-dimensional data into a lower number of dimensions. T-SNE is often used to visualize
embeddings. At its core tSNE attempt to preserve distances between close points.
Check out the original paper
to learn more.
One of the main benefits of this implementation is that it doesn't require any external
dependencies.
``js
import {TSNE} from "TSNE";
const embeddings: number[][] = {
{0.123, 0.456, ...},
{0.123, 0.456, ...},
...
}
const tsne = new TSNE({ nIter: 200, perplexity: 30, learningRate: 10 });
const projectedEmbeddings: number[][] = tsne.transform(embeddings);
`
You can find a simple MNIST visualization demo at https://github.com/msvana/tsne-demo
The TSNE constructor accepts a configuration object. All properties of this object are optional and have default values:
- nDims (default 2): number of output dimensionsperplexity
- (default 30): Roughly equivalent to the number of neighboring points nIter
to consider for distance preservation. A value between 10 and 50 is recommended.
- (default 100)learningRate
- (default 1`): recommended values are 1, 10, or even 100