-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathembed_model.py
67 lines (56 loc) · 2 KB
/
embed_model.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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
"""Ideal words - run extensional W2V
Usage:
spearman.py [--att] [--rel] [--sit] [--ppmi] [--pca]
spearman.py (-h | --help)
spearman.py --version
Options:
-h --help Show this screen.
--version Show version.
--att Use attributes.
--rel Use relations.
--sit Use situtation cooccurrences.
--ppmi Uses PPMI version of predicate matrix.
--pca Uses PCA version of predicate matrix.
"""
import re
import sys
sys.path.append('./utils/')
import random
import numpy as np
from collections import defaultdict
from docopt import docopt
from utils import read_predicate_matrix
from ext2vec import ext2vec
from messaging import output_logo
subspace = "syn"
if __name__ == '__main__':
output_logo()
args = docopt(__doc__, version='Ideal Words 0.1')
if args["--att"] and not args["--rel"] and not args["--sit"]:
subspace = "synatt"
if args["--rel"] and not args["--att"] and not args["--sit"]:
subspace = "synrel"
if args["--sit"] and not args["--att"] and not args["--rel"]:
subspace = "synsit"
if args["--att"] and args["--rel"] and not args["--sit"]:
subspace = "synattrel"
if args["--att"] and args["--sit"] and not args["--rel"]:
subspace = "synattsit"
if not args["--att"] and args["--rel"] and args["--sit"]:
subspace = "synrelsit"
if args["--att"] and args["--rel"] and args["--sit"]:
subspace = "synattrelsit"
vocab, m = read_predicate_matrix(subspace)
print("Length of vocab:",len(vocab))
corpus = []
print("Running ext2vec...")
settings = {}
settings['n'] = 300 # dimension of word embeddings
settings['epochs'] = 30 # number of training epochs
settings['neg_samp'] = 1 # number of negative words to use during training
settings['learning_rate'] = 0.001 # learning rate
np.random.seed(0) # set the seed for reproducibility
# INITIALIZE E2V MODEL
e2v = ext2vec(vocab, subspace, settings)
e2v.train(m,vocab)
e2v.pretty_print(vocab)