<jupyter_start><jupyter_text>Direct projection of latent space<jupyter_code>y_train = y_train[:N]
z_train = z_train[:N]

fig = plt.figure(figsize=(12, 10))
plots = []
markers = ['o', ',', 'x', '+', 'v', '^', '<', '>', 's', 'd']
for i, c in enumerate(classes):
    ind = (y_train == i).tolist() or ([j < N // len(classes) for j in range(len(y_train))])
    color = cm.jet([i / len(classes)] * sum(ind))
    plots.append(plt.scatter(z_train[ind, 1], z_train[ind, 2], marker=markers[i], c=color, s=8, label=i))

plt.axis('off')
plt.legend(plots, classes, fontsize=14, loc='upper right')
plt.title('{} (direct projection: {}-dim -> 2-dim)'.format(exp, z_train.shape[1]), fontsize=14)
plt.savefig("./ResNetVAE_{}_direct_plot.png".format(exp), bbox_inches='tight', dpi=600)
plt.show()<jupyter_output><empty_output><jupyter_text>Use t-SNE for dimension reduction  compressed to 2-dimension<jupyter_code>z_embed = TSNE(n_components=2, n_iter=12000).fit_transform(z_train[:N])
fig = plt.figure(figsize=(12, 10))
plots = []
markers = ['o', ',', 'x', '+', 'v', '^', '<', '>', 's', 'd']  # select different markers
for i, c in enumerate(classes):
    ind = (y_train[:N] == i).tolist()
    color = cm.jet([i / len(classes)] * sum(ind))
    # plot each category one at a time 
    plots.append(plt.scatter(z_embed[ind, 0], z_embed[ind, 1], c=color, marker=markers[i], s=8, label=i))

plt.axis('off')
plt.xlim(-150, 150)
plt.ylim(-150, 150)
plt.legend(plots, classes, fontsize=14, loc='upper right')
plt.title('{} (t-SNE: {}-dim -> 2-dim)'.format(exp, z_train.shape[1]), fontsize=14)
plt.savefig("./ResNetVAE_{}_embedded_plot.png".format(exp), bbox_inches='tight', dpi=600)
plt.show()<jupyter_output><empty_output><jupyter_text>compressed to 3-dimension<jupyter_code>z_embed3D = TSNE(n_components=3, n_iter=12000).fit_transform(z_train[:N])
fig = plt.figure(figsize=(12, 10))
ax = fig.add_subplot(111, projection='3d')

plots = []
markers = ['o', ',', 'x', '+', 'v', '^', '<', '>', 's', 'd']  # select different markers
for i, c in enumerate(classes):
    ind = (y_train[:N] == i).tolist()
    color = cm.jet([i / len(classes)] * sum(ind))
    # plot each category one at a time 
    ax.scatter(z_embed3D[ind, 0], z_embed3D[ind, 1], c=color, marker=markers[i], s=8, label=i)

ax.axis('on')

r_max = 20
r_min = -r_max

ax.set_xlim(r_min, r_max)
ax.set_ylim(r_min, r_max)
ax.set_zlim(r_min, r_max)
ax.set_xlabel('z-dim 1')
ax.set_ylabel('z-dim 2')
ax.set_zlabel('z-dim 3')
ax.set_title('{} (t-SNE: {}-dim -> 3-dim)'.format(exp, z_train.shape[1]), fontsize=14)
ax.legend(plots, classes, fontsize=14, loc='upper right')
plt.savefig("./ResNetVAE_{}_embedded_3Dplot.png".format(exp), bbox_inches='tight', dpi=600)
plt.show()<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.22136845956824003, 'fraction_numerical': 0.031833150384193196, 'mean_word_length': 5.700980392156863, 'pattern_counts': {'":': 0, '<': 17, '<?xml version=': 0, '>': 19, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 3, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '3', 'dir': 'jupyter-structured-clean-dedup', 'id': '642861', 'license': 'MIT', 'n_tokens_mistral': 1234, 'n_tokens_neox': 1136, 'n_words': 211, 'path': '004_plot_latent.ipynb', 'repo_name': 'chnghia/pytorch-lightning-gan', 'size': '2733'}