Skip to content

Commit

Permalink
Adaptive perplexity in t-SNE plots
Browse files Browse the repository at this point in the history
  • Loading branch information
akutuzov committed Jan 18, 2020
1 parent b0720ab commit 3ac3c16
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions plotting.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ def singularplot(word, modelname, vector, fname):


def embed(words, matrix, classes, usermodel, fname):
perplexity = 6.0 # Should be smaller than the number of points!
perplexity = int(len(words) ** 0.5) # We set perplexity to a square root of the words number
embedding = TSNE(n_components=2, perplexity=perplexity, metric='cosine', n_iter=500, init='pca')
y = embedding.fit_transform(matrix)

Expand All @@ -57,7 +57,7 @@ def embed(words, matrix, classes, usermodel, fname):

lemma = word.split('_')[0].replace('::', ' ')
mid = len(lemma) / 2
mid *= 6 # TODO Should really think about how to adapt this variable to the real plot size
mid *= 4 # TODO Should really think about how to adapt this variable to the real plot size
plot.annotate(lemma, xy=(x - mid, y), size='x-large', weight='bold', fontproperties=font,
color=color)

Expand Down

0 comments on commit 3ac3c16

Please sign in to comment.