-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgraph_plotter.py
33 lines (26 loc) · 1.03 KB
/
graph_plotter.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
import os
import numpy as np
import matplotlib.pyplot as plt
# Ordner zum Speichern der Graphen
PLOTS_DIR = "./results"
def plot_logits(xs, ys, top_neurons):
for n in top_neurons:
plot_logit_and_save(xs, ys, n)
def plot_logit_and_save(xs, ys, index_neuron):
sentiment_unit = xs[:, index_neuron]
plt.ylabel('Anzahl der Phrasen')
plt.xlabel('Wert des Gefühls-Neuron')
plt.hist(sentiment_unit[ys == -1], bins=50, alpha=0.5, label='Negative Phrase')
plt.hist(sentiment_unit[ys == 1], bins=50, alpha=0.5, label='Positive Phrase')
plt.legend()
plt.savefig(os.path.join(PLOTS_DIR, "neuron_" + str(index_neuron) + '.png'))
plt.clf()
def plot_weight_contribs(coef):
plt.title('Werte der Gewichtungen')
plt.tick_params(axis='both', which='major')
norm = np.linalg.norm(coef)
coef = coef/norm
plt.plot(range(len(coef[0])), coef.T)
plt.xlabel('Index des Neurons')
plt.ylabel('Gewichtung des Neuron')
plt.savefig(os.path.join(PLOTS_DIR, "gewichtungen.png"))