def plot_params(self, dir_name, d, plot_only=500):

	tsne = TSNE(perplexity=30, n_components=2, init='pca', n_iter=5000)
        low_dim_embs_alpha2 = tsne.fit_transform(self.alpha.eval()[:plot_only])
        plot_with_labels(low_dim_embs_alpha2[:plot_only], d.labels[:plot_only], dir_name + '/alpha.eps')

        tsne = TSNE(perplexity=30, n_components=2, init='pca', n_iter=5000)
        low_dim_embs_rho2 = tsne.fit_transform(self.rho.eval()[:plot_only])
        plot_with_labels(low_dim_embs_rho2[:plot_only], d.labels[:plot_only], dir_name + '/rho.eps')
    def plot_params(self, dir_name, d, plot_only=500):
	tsne = TSNE(perplexity=30, n_components=2, init='pca', n_iter=5000)
        low_dim_embs_alpha = tsne.fit_transform(self.alpha.eval()[:plot_only])
        plot_with_labels(low_dim_embs_alpha[:plot_only], d.labels[:plot_only], dir_name + '/alpha.eps')
        
        np_rho = self.rho.eval()

        for t in [0, int(self.T/2), self.T-1]:
            w_idx_t = range(plot_only)
            tsne = TSNE(perplexity=30, n_components=2, init='pca', n_iter=5000)
            low_dim_embs_rho = tsne.fit_transform(np_rho[t,w_idx_t,:])
            plot_with_labels(low_dim_embs_rho, d.labels[w_idx_t], dir_name + '/rho_' + str(t) + '.eps')
示例#3
0
# -*- coding: utf-8 -*-
"""
Created on Sun Jul 22 07:06:16 2018

@author: ashima.garg
"""

import config
import data
import model
import utils
import os

if __name__ == "__main__":
    # LOAD DATA
    train_data = data.DATA()
    train_data.build_dataset(os.path.join(config.DATA_DIR, config.TRAIN_FILE))
    print("Train data Loaded")
    #BUILD MODEL
    model = model.MODEL()
    model.build()
    print("model built")
    #TRAIN MODEL
    model.train(train_data)
    print("Model Trained")
    utils.plot_with_labels(model.embeddings, train_data)
示例#4
0
    HAS_SK = False
    print('Please install sklearn for layer visualization')

plot_only = len(data.y_test)
x = torch.from_numpy(np.array(data.X_test[0:plot_only],
                              dtype='float32')).cuda()
siamese_net(x, x)
intermediate_tensor = activation['fc1']
# Visualization of trained flatten layer (T-SNE)
tsne = TSNE(perplexity=30, n_components=2, init='pca', n_iter=5000)
low_dim_embs = tsne.fit_transform(intermediate_tensor.cpu())
p_data = pd.DataFrame(columns=['x', 'y', 'label'])
p_data.x = low_dim_embs[:, 0]
p_data.y = low_dim_embs[:, 1]
p_data.label = data.y_test[0:plot_only]
utils.plot_with_labels(p_data)  #画散点图
plt.savefig("%s/90-tsne-one-shot.pdf" % (settings["save_path"]))
plt.show()

# In[11]:

import numpy as np

plot_only = len(data.y_test)
x = torch.from_numpy(np.array(data.X_test[0:plot_only],
                              dtype='float32')).cuda()
wdcnn_net(x)
intermediate_tensor = activation['layer']
# Visualization of trained flatten layer (T-SNE)
tsne = TSNE(perplexity=30, n_components=2, init='pca', n_iter=5000)
low_dim_embs = tsne.fit_transform(intermediate_tensor.cpu())
示例#5
0
        for ind in rng:
            words_i = data_batch[ind, :, 0]
            words_o = [labl_batch[ind, :, wi] for wi in range(WINDOW_SIZE)]
            ph_feed = {i: d for i, d in zip(words_to_list, words_o)}
            ph_feed[words_from] = words_i
            _, lv = sess.run([optimizer, loss], feed_dict=ph_feed)
            if ind % 1000 == 0:
                print('\r  {}/{} - {}'.format(ind, len(rng), lv), end='\r')
            average_loss += lv
        average_loss /= len(rng)
        print('Average loss at step ', step, ': ', average_loss)
    final_embeddings = tf.transpose(h2o).eval()

# pylint: disable=g-import-not-at-top
import pickle
with open("word-embedding.mat", "wb") as fi:
    pickle.dump(final_embeddings, fi)

# pylint: disable=g-import-not-at-top
from sklearn.manifold import TSNE

tsne = TSNE(perplexity=30,
            n_components=2,
            init='pca',
            n_iter=5000,
            method='exact')
plot_only = min(500, vocabulary_size)
low_dim_embs = tsne.fit_transform(final_embeddings[:plot_only, :])
labels = [reverse_dictionary[i] for i in range(plot_only)]
plot_with_labels(low_dim_embs, labels)
示例#6
0
print('Missclassified points = {} / {}'.format(
    l.ClassificationLoss.loss(output, test_label)[0], nPoints))

# #Plot the predictions and the ill classified points
train_label = train_label.max(dim=0)[1].long()
test_label = test_label.max(dim=0)[1].long()
train_pred = model.forward(train).max(dim=0)[1].long().squeeze()
test_pred = output.max(dim=0)[1].long().squeeze()
train_miss = (torch.abs(train_pred.float() - train_label.float()) != 0).long()
test_miss = (torch.abs(test_pred.float() - test_label.float()) != 0).long()
""" PLOTTING """
plt.subplots_adjust(hspace=0.2)
plt.margins(0, 0)
# Plots for train
fig_train, axes = plt.subplots(nrows=3, ncols=1, figsize=(4, 14), sharex=True)
plot_with_labels(train, train_label, axes[0])
axes[0].set_title("Train labels")

plot_with_labels(train, train_pred, axes[1])
axes[1].set_title("Train predictions")

plot_with_labels(train, train_miss, axes[2])
axes[2].set_title("Train missclassification")

# Plots for test
fig_test, axes = plt.subplots(nrows=3, ncols=1, figsize=(4, 14), sharex=True)
plot_with_labels(test, test_label, axes[0])
axes[0].set_title("Test labels")

plot_with_labels(test, test_pred, axes[1])
axes[1].set_title("Test predictions")