forked from rujunhan/ConditionalEmbeddings
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathplot_weights.py
39 lines (28 loc) · 1.06 KB
/
plot_weights.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
34
35
36
37
38
39
import argparse
import gensim
import seaborn as sns
import os
import matplotlib
import matplotlib.pyplot as plt
matplotlib.use('pdf')
def main(args):
for decade in range(181, 200):
if args.decade:
if decade != args.decade:
continue
word_vecs = gensim.models.KeyedVectors.load_word2vec_format(
f"data/COHA/results/decade_embeddings_{args.file_stamp}_{args.run_id}_{decade}.txt", binary=False, no_header=True)
weights = word_vecs.vectors
weights = weights.reshape(-1, )
weights = list(weights)
plt.clf()
ax = sns.kdeplot(weights)
os.makedirs('results/weights', exist_ok=True)
ax.figure.savefig(f"results/weights/weightdist_{args.file_stamp}_{args.run_id}_{decade}.png")
if __name__ == "__main__":
parser = argparse.ArgumentParser()
parser.add_argument("-file_stamp", type=str, required=True)
parser.add_argument("-decade", type=int, default=None)
parser.add_argument("-run_id", type=str, required=True)
args = parser.parse_args()
main(args)