AlexWorldD / NetEmbs

Framework for Representation Learning on Financial Statement Networks
Apache License 2.0
1 stars 1 forks source link

Tensorflow #6

Closed boersmamarcel closed 5 years ago

boersmamarcel commented 5 years ago

Hi Aleksei,

I couldn't find the Tensorflow code at first because in PyCharm the last cell of the notebook were not rendering correctly. Only while opening in jupyter notebook I could see the Tensorflow code.

However, I run into some problems

Average loss at step  0 :  8.046344757080078
Traceback (most recent call last):
  File "/Users/mboersma/Documents/phd/students/alex/NetEmbs-master/analysisMB.py", line 145, in <module>
    run(graph, num_steps, skip_grams, 128)
  File "/Users/mboersma/Documents/phd/students/alex/NetEmbs-master/analysisMB.py", line 134, in run
    final_embeddings = normalized_embeddings.eval()
NameError: name 'normalized_embeddings' is not defined

furthermore, I would like to render a simple t-sne plot. Could you combine this with:


import matplotlib.pyplot as plt
from sklearn.manifold import TSNE

viz_words = 500
tsne = TSNE()
embed_tsne = tsne.fit_transform(embed_mat[:viz_words, :])

fig, ax = plt.subplots(figsize=(14, 14))
for idx in range(viz_words):
    plt.scatter(*embed_tsne[idx, :], color='steelblue')
    plt.annotate(int_to_vocab[idx], (embed_tsne[idx, 0], embed_tsne[idx, 1]), alpha=0.7)
AlexWorldD commented 5 years ago

I don't know why, but I also had problems with tf via JupyterNotebook, hence, I'd marked these cells as "Raw" ones, that's why you could not see them in pyCharm. I used skip_gram Python file for preilementary testing.

boersmamarcel commented 5 years ago

@AlexWorldD thanks for pointing me to the correct file, I extracted old code from the notebook which contained errors. Will try to run the skipgram file now and see if it works.

boersmamarcel commented 5 years ago

it works!

boersmamarcel commented 5 years ago

here a code snippet for t-sne:

fsn_embs = pd.DataFrame(list(zip(enc_dec.original_bps, embs)), columns=["ID", "Emb"])
print("Done!")

import matplotlib.pyplot as plt
from sklearn.manifold import TSNE

viz_words = 500
tsne = TSNE()
embdf = pd.DataFrame(list(map(np.ravel, fsn_embs.iloc[:,1])))
embed_tsne = tsne.fit_transform(embdf)

plt.plot(embed_tsne, 'ro')
AlexWorldD commented 5 years ago

I guess we are getting a weird visual output for tsne because of wrong feeding argument to plt.plot(). plt.plot(embed_tsne, 'ro') vs. plt.plot(embed_tsne[:,0], embed_tsne[:,1], 'ro') for the second version I got the same picture as for vis with seaborn.

boersmamarcel commented 5 years ago

Excellent!!!

Kind regards,

Marcel Boersma

On Apr 12, 2019, at 3:17 PM, Alex Malyutin notifications@github.com wrote:

I guess we are getting a weird visual output for tsne because of wrong feeding argument to plt.plot(). plt.plot(embed_tsne, 'ro') vs. plt.plot(embed_tsne[:,0], embed_tsne[:,1], 'ro') for the second version I got the same picture as for vis with seaborn.

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub, or mute the thread.