-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathMakefile
186 lines (152 loc) · 5.18 KB
/
Makefile
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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
PY = python
IR_ITERS = 3
IR_PARAMS = -t 0 -c 2.0 -h 0
RW_ALPHA = 0.1
RW_AXIS = 1
SRC_PATH = ./src
DATA_PATH = ./data
MAIN_SCRIPT_PATH = $(SRC_PATH)/main.py
RAW_DATA_PATH = $(DATA_PATH)/raw
GRAPH_DATA_PATH = $(DATA_PATH)/graph
SEED_DATA_PATH = $(DATA_PATH)/seeds
IR_DATA_PATH = $(DATA_PATH)/iterreg
RW_DATA_PATH = $(DATA_PATH)/randwalk
CERT_DATA_PATH = $(DATA_PATH)/certainty
TRUTH_DATA_PATH = $(DATA_PATH)/truth
RAW_CN5_PATH = $(RAW_DATA_PATH)/conceptnet5/conceptnet4_[0-4].csv
RAW_ANEW_PATH = $(RAW_DATA_PATH)/anew.csv
RAW_SN_PATH = $(RAW_DATA_PATH)/senticnet.rdf.xml
ANEW_PATH = $(SEED_DATA_PATH)/anew.txt
SN_PATH = $(SEED_DATA_PATH)/sn.txt
NODES_PATH = $(GRAPH_DATA_PATH)/nodes.txt
EDGES_PATH = $(GRAPH_DATA_PATH)/edges.txt
RELS_PATH = $(GRAPH_DATA_PATH)/rels.txt
IR_PRED_PATH_TMPL = $(IR_DATA_PATH)/r[i].txt
IR_PRED_PATHS = $(subst [i],{1..$(IR_ITERS)},$(IR_PRED_PATH_TMPL))
RW_PRED_PATH = $(RW_DATA_PATH)/r1.txt
IR_CERT_PATH = $(CERT_DATA_PATH)/iterreg.txt
RW_CERT_PATH = $(CERT_DATA_PATH)/randwalk.txt
IMPACT_PATH = $(CERT_DATA_PATH)/impact.txt
POL_TRUTH_1_PATH = $(TRUTH_DATA_PATH)/1.txt
POL_TRUTH_2_PATH = $(TRUTH_DATA_PATH)/2.txt
RANK_TRUTH_1_PATH = $(TRUTH_DATA_PATH)/pairs1.txt
RANK_TRUTH_2_PATH = $(TRUTH_DATA_PATH)/pairs2.txt
# $(call eval-pred,metric,pred,truth)
define eval-pred
$(PY) $(MAIN_SCRIPT_PATH) eval $1 --pred $2 --truth $3
endef
# $(call eval-pred-all,title,pred)
define eval-pred-all
echo [$1] \
Polarity Accuracy = \
`$(call eval-pred,polarity,$2,$(POL_TRUTH_1_PATH))` \
`$(call eval-pred,polarity,$2,$(POL_TRUTH_2_PATH))` \
Kendall-Tau = \
`$(call eval-pred,kendall,$2,$(RANK_TRUTH_1_PATH))` \
`$(call eval-pred,kendall,$2,$(RANK_TRUTH_2_PATH))`
endef
.PHONY: split seeds seeds-anew seeds-sn iterreg iterreg-certainty randwalk shift \
impact \
lookup eval eval-sn eval-iterreg eval-randwalk \
clean clean-graph clean-seeds clean-iterreg clean-randwalk clean-certainty
all: split seeds iterreg iterreg-certainty randwalk shift
split:
@echo "Parsing ConceptNet..."
@mkdir -p $(GRAPH_DATA_PATH)
@$(PY) $(MAIN_SCRIPT_PATH) split \
--graph $(RAW_CN5_PATH) \
--nodes $(NODES_PATH) \
--edges $(EDGES_PATH) \
--rels $(RELS_PATH)
seeds: seeds-anew seeds-sn
seeds-anew:
@echo "Parsing ANEW..."
@mkdir -p $(SEED_DATA_PATH)
@$(PY) $(MAIN_SCRIPT_PATH) seeds anew \
--raw $(RAW_ANEW_PATH) \
--seed $(ANEW_PATH) \
--nodes $(NODES_PATH)
seeds-sn:
@echo "Parsing SenticNet..."
@mkdir -p $(SEED_DATA_PATH)
@$(PY) $(MAIN_SCRIPT_PATH) seeds sn \
--raw $(RAW_SN_PATH) \
--seed $(SN_PATH) \
--nodes $(NODES_PATH)
iterreg:
@echo "Performing iterative regression..."
@mkdir -p $(IR_DATA_PATH)
@$(PY) $(MAIN_SCRIPT_PATH) iterreg \
--anew $(ANEW_PATH) \
--sn $(SN_PATH) \
--edges $(EDGES_PATH) \
--pred $(subst [i],1,$(IR_PRED_PATH_TMPL)) \
--param "$(IR_PARAMS)"
@for i in {2..$(IR_ITERS)}; do \
$(PY) $(MAIN_SCRIPT_PATH) iterreg \
--anew $(ANEW_PATH) \
--sn $(SN_PATH) \
--edges $(EDGES_PATH) \
--pis $(subst [i],$$((i - 1)),$(IR_PRED_PATH_TMPL)) \
--pred $(subst [i],$$i,$(IR_PRED_PATH_TMPL)) \
--param "$(IR_PARAMS)"; \
done
iterreg-certainty:
@echo "Generating certainty scores for iterative regression..."
@mkdir -p $(CERT_DATA_PATH)
@$(PY) $(MAIN_SCRIPT_PATH) ircert \
--preds $(IR_PRED_PATHS) \
--cert $(IR_CERT_PATH)
randwalk:
@echo "Performing random walk..."
@mkdir -p $(RW_DATA_PATH)
@$(PY) $(MAIN_SCRIPT_PATH) randwalk \
--edges $(EDGES_PATH) \
--seed $(subst [i],$(IR_ITERS),$(IR_PRED_PATH_TMPL)) \
--pred $(RW_PRED_PATH) \
--cin $(IR_CERT_PATH) \
--cout $(RW_CERT_PATH) \
--alpha $(RW_ALPHA) \
--axis $(RW_AXIS)
shift:
@echo "Shifting..."
@$(PY) $(MAIN_SCRIPT_PATH) shift mva \
--seed $(ANEW_PATH) \
--pred_in $(RW_PRED_PATH) \
--pred_out $(RW_PRED_PATH)
impact:
@echo "Calculating impacts..."
@mkdir -p $(RW_DATA_PATH)
@$(PY) $(MAIN_SCRIPT_PATH) impact \
--edges $(EDGES_PATH) \
--impact $(IMPACT_PATH) \
--alpha $(RW_ALPHA) \
--axis $(RW_AXIS)
lookup:
@$(PY) $(MAIN_SCRIPT_PATH) lookup \
--nodes $(NODES_PATH) \
--edges $(EDGES_PATH) \
--rels $(RELS_PATH) \
--anew $(ANEW_PATH) \
--sn $(SN_PATH) \
--pred $(RW_PRED_PATH)
eval: eval-iterreg eval-randwalk
eval-iterreg:
@echo --- IterReg ---
@for i in {1..$(IR_ITERS)}; do \
$(call eval-pred-all,iter $$i,$(subst [i],$$i,$(IR_PRED_PATH_TMPL))); \
done
eval-randwalk:
@echo --- RandWalk ---
@$(call eval-pred-all,alpha=$(RW_ALPHA),$(RW_PRED_PATH)); \
clean: clean-graph clean-seeds clean-iterreg clean-randwalk clean-certainty
clean-graph:
$(RM) -r $(GRAPH_DATA_PATH)
clean-seeds:
$(RM) -r $(SEED_DATA_PATH)
clean-iterreg:
$(RM) -r $(IR_DATA_PATH)
clean-randwalk:
$(RM) -r $(RW_DATA_PATH)
clean-certainty:
$(RM) -r $(CERT_DATA_PATH)