-
Notifications
You must be signed in to change notification settings - Fork 0
/
leaderboards.mk
330 lines (248 loc) · 10.1 KB
/
leaderboards.mk
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
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
# -*-makefile-*-
#
# recipes for updating and maintaining leaderboard files
#
#
METRICS ?= bleu spbleu chrf chrf++ comet
METRIC ?= $(firstword ${METRICS})
ifdef LANGPAIRDIR
LANGPAIR := $(lastword $(subst /, ,${LANGPAIRDIR}))
endif
MAKEDIR := $(dir $(lastword ${MAKEFILE_LIST}))
## SCORE_DIRS = directories that contains new scores
## LEADERBOARDS = list of leader boards that need to be updated
## - for all leaderboards with new scores if UPDATED_LEADERBOARDS is set
## - or for a selected LANGPAIR
ifdef LANGPAIR
SCORE_DIRS := $(shell find scores/${LANGPAIR} -mindepth 2 -name '*.unsorted.txt' | cut -f1-3 -d/ | sort -u)
LANGPAIRS := ${LANGPAIR}
else ifeq (${UPDATED_LEADERBOARDS},1)
SCORE_DIRS := $(shell find scores -mindepth 3 -name '*.unsorted.txt' | cut -f1-3 -d/ | sort -u)
LANGPAIRS := $(sort $(dir $(patsubst scores/%,%,${SCORE_DIRS})))
LANGPAIR ?= $(firstword ${LANGPAIRS})
else
LANGPAIRS := $(shell find scores -mindepth 1 -maxdepth 1 -name '*-*' -type d | cut -f2 -d/ | sort -u)
LANGPAIR := $(firstword ${LANGPAIRS})
SCORE_DIRS := $(shell find scores/${LANGPAIR} -mindepth 2 -name '*.unsorted.txt' | cut -f1-3 -d/ | sort -u)
endif
LEADERBOARDS := $(foreach m,${METRICS},$(patsubst %,%/$(m)-scores.txt,${SCORE_DIRS}))
LANGPAIR_LISTS := scores/langpairs.txt
BENCHMARK_LISTS := scores/benchmarks.txt
MODEL_LIST := models/modelsize.txt
#--------------------------------------------------
## fetch all evaluation zip file
.PHONY: fetch-zipfiles
fetch-zipfiles:
${MAKE} -C models download-all
.PHONY: all-topavg-scores
all-topavg-scores:
for m in ${METRICS}; do \
echo "extract top/avg scores for $$m scores"; \
${MAKE} -s METRIC=$$m top-langpair-scores avg-langpair-scores; \
done
.PHONY: all-avg-scores
all-avg-scores:
for m in ${METRICS}; do \
echo "extract avg scores for $$m scores"; \
${MAKE} -s METRIC=$$m avg-langpair-scores; \
done
.PHONY: all-top-scores
all-top-scores:
for m in ${METRICS}; do \
echo "extract top scores for $$m scores"; \
${MAKE} -s METRIC=$$m top-langpair-scores; \
done
.PHONY: update-leaderboards
update-leaderboards: ${LEADERBOARDS}
## update all updated leaderboards
## (the ones with new scores registered)
.PHONY: updated-leaderboards
updated-leaderboards:
${MAKE} UPDATED_LEADERBOARDS=1 update-leaderboards
${MAKE} all-topavg-scores
# ${MAKE} UPDATED_LEADERBOARDS=1 all-topavg-scores
## refresh all leaderboards using phony targets for each language pair
## this scales to large lists of language pairs
UPDATE_LEADERBOARD_TARGETS = $(sort $(patsubst %,%-update-leaderboard,${LANGPAIRS}))
.PHONY: refresh-leaderboards
refresh-leaderboards: $(UPDATE_LEADERBOARD_TARGETS)
${MAKE} -s all-topavg-scores
.PHONY: $(UPDATE_LEADERBOARD_TARGETS)
$(UPDATE_LEADERBOARD_TARGETS):
${MAKE} -s LANGPAIR=$(@:-update-leaderboard=) update-leaderboards
# refresh all leaderboards using find
.PHONY: refresh-leaderboards-find
refresh-leaderboards-find:
find scores -maxdepth 1 -mindepth 1 -type d \
-exec ${MAKE} LANGPAIRDIR={} update-leaderboards \;
${MAKE} -s all-topavg-scores
.PHONY: model-list model-lists
model-list: scores/${LANGPAIR}/model-list.txt
model-lists: $(foreach l,${LANGPAIRS},scores/${l}/model-list.txt)
scores/%/model-list.txt:
find ${dir $@} -mindepth 2 -name '*-scores.txt' | \
xargs cut -f2 | sed 's|https*://[^/]*/||' | sed 's|.zip$$||' | sort -u > $@
# @git add $@
released-models.txt: scores/bleu_scores.db
echo 'select distinct model from scores;' | sqlite3 $< | sort | grep . > $@
## TODO: release dates for HPLT models are now hard-coded for v1.0
release-history.txt: released-models.txt
cat $< | cut -f1 -d'/' > [email protected]
cat $< | cut -f2 -d'/' > [email protected]
cat $< | cut -f3 -d'/' > [email protected]
cat $< | sed 's/^.*\([0-9]\{4\}-[0-9]\{2\}-[0-9]\{2\}\)$$/\1/' \
| sed 's/.*v1.0-hplt.*$$/2024-03-14/' > [email protected]
paste [email protected] [email protected] [email protected] [email protected] | sort -k1,1r -k3,3 > $@
# @git add $@
# released-models.txt: scores/bleu_scores.db
# find scores -name 'bleu-scores.txt' | xargs cat | cut -f2 | sort -u > $@
# @git add $@
# release-history.txt: released-models.txt
# cat $< | rev | cut -f3 -d'/' | rev > [email protected]
# cat $< | rev | cut -f2 -d'/' | rev > [email protected]
# cat $< | rev | cut -f1 -d'/' | rev > [email protected]
# cat $< | sed 's/^.*\([0-9]\{4\}-[0-9]\{2\}-[0-9]\{2\}\)\.zip$$/\1/' > [email protected]
# paste [email protected] [email protected] [email protected] [email protected] | sort -r | sed 's/\.zip$$//' > $@
# # @git add $@
${MODEL_LIST}: models scores/bleu_scores.db
find models -name '*.info' \
| xargs grep parameters \
| sed 's|^models/||;s/\.info:/:/' \
| tr ':' "\t" > $@
.PHONY: top-score-file top-scores
top-score-file: scores/${LANGPAIR}/top-${METRIC}-scores.txt
top-scores: $(foreach m,${METRICS},scores/${LANGPAIR}/top-${m}-scores.txt)
top-langpair-scores: $(foreach l,${LANGPAIRS},scores/${l}/top-${METRIC}-scores.txt)
.PHONY: avg-score-file avg-scores
avg-score-file: scores/${LANGPAIR}/avg-${METRIC}-scores.txt
avg-scores: $(foreach m,${METRICS},scores/${LANGPAIR}/avg-${m}-scores.txt)
avg-langpair-scores: $(foreach l,${LANGPAIRS},scores/${l}/avg-${METRIC}-scores.txt)
## explicitely listing impict rules for each metric would make it possible
## to call it for all possible language pairs (don't have to loop over language pairs)
## disadvantages:
## * need to create new rules for new metrics
## * repeat the same recipe over and over again
## for the second problem: could use "define" to define a rule
## I don't know a principled solution for the first problem
## foreach does not work, e.g. this would be cool:
##
# $(foreach m,${METRICS},scores/%/avg-${m}-scores.txt): scores/%/model-list.txt
# @echo "update $@"
# @${MAKEDIR}tools/average-scores.pl $(sort $(wildcard $(dir $@)*/$(patsubst avg-%,%,$(notdir $@)))) > $@
scores/${LANGPAIR}/avg-%-scores.txt: scores/${LANGPAIR}/model-list.txt
@echo "update $@"
@${MAKEDIR}tools/average-scores.pl $(sort $(wildcard $(dir $@)*/$(patsubst avg-%,%,$(notdir $@)))) > $@
# @git add $@
scores/%/avg-${METRIC}-scores.txt: scores/%/model-list.txt
@echo "update $@"
@${MAKEDIR}tools/average-scores.pl $(sort $(wildcard $(dir $@)*/$(patsubst avg-%,%,$(notdir $@)))) > $@
# @git add $@
scores/${LANGPAIR}/top-%-scores.txt: scores/${LANGPAIR}/model-list.txt
@echo "update $@"
@rm -f $@
@for f in $(sort $(wildcard $(dir $@)*/$(patsubst top-%,%,$(notdir $@)))); do \
if [ -s $$f ]; then \
t=`echo $$f | cut -f3 -d/`; \
echo -n "$$t " >> $@; \
head -1 $$f >> $@; \
fi \
done
# @git add $@
.NOTINTERMEDIATE: scores/%/model-list.txt
scores/%/top-${METRIC}-scores.txt: scores/%/model-list.txt
@echo "update $@"
@rm -f $@
@for f in $(sort $(wildcard $(dir $@)*/$(patsubst top-%,%,$(notdir $@)))); do \
if [ -s $$f ]; then \
t=`echo $$f | cut -f3 -d/`; \
echo -n "$$t " >> $@; \
head -1 $$f >> $@; \
fi \
done
# @git add $@
${LEADERBOARDS}: ${SCORE_DIRS}
@echo "update $@"
@if [ -e $@ ]; then \
if [ $(words $(wildcard ${@:.txt=}*.unsorted.txt)) -gt 0 ]; then \
echo "merge and sort ${patsubst scores/%,%,$@}"; \
sort -k2,2 -k1,1nr $@ > [email protected]; \
cat $(wildcard ${@:.txt=}*.unsorted.txt) | \
grep '^[0-9\-]' | sort -k2,2 -k1,1nr > [email protected]; \
sort -m [email protected] [email protected] |\
sort -k2,2 | uniq -f1 | sort -k1,1nr > [email protected]; \
rm -f [email protected] [email protected]; \
rm -f $(wildcard ${@:.txt=}*.unsorted.txt); \
mv [email protected] $@; \
rm -f $(dir $<)model-list.txt; \
fi; \
else \
if [ $(words $(wildcard ${@:.txt=}*.txt)) -gt 0 ]; then \
echo "sort ${patsubst scores/%,%,$@}"; \
cat $(wildcard ${@:.txt=}*.txt) | grep '^[0-9\-]' |\
sort -k2,2 | uniq -f1 | sort -k1,1nr > [email protected]; \
rm -f $(wildcard ${@:.txt=}*.txt); \
mv [email protected] $@; \
rm -f $(dir $<)model-list.txt; \
fi; \
fi
# @git add $@
scores/${LANGPAIR}/%-scores.txt: scores/${LANGPAIR}
@echo "update $@"
if [ -e $@ ]; then \
if [ $(words $(wildcard ${@:.txt=}*.unsorted.txt)) -gt 0 ]; then \
echo "merge and sort ${patsubst scores/%,%,$@}"; \
sort -k2,2 -k1,1nr $@ > [email protected]; \
cat $(wildcard ${@:.txt=}*.unsorted.txt) | \
grep '^[0-9\-]' | sort -k2,2 -k1,1nr > [email protected]; \
sort -m [email protected] [email protected] |\
sort -k2,2 | uniq -f1 | sort -k1,1nr > [email protected]; \
rm -f [email protected] [email protected]; \
rm -f $(wildcard ${@:.txt=}*.unsorted.txt); \
mv [email protected] $@; \
rm -f $(dir $<)model-list.txt; \
fi; \
else \
if [ $(words $(wildcard ${@:.txt=}*.txt)) -gt 0 ]; then \
echo "sort ${patsubst scores/%,%,$@}"; \
cat $(wildcard ${@:.txt=}*.txt) | grep '^[0-9\-]' |\
sort -k2,2 | uniq -f1 | sort -k1,1nr > [email protected]; \
rm -f $(wildcard ${@:.txt=}*.txt); \
mv [email protected] $@; \
rm -f $(dir $<)model-list.txt; \
fi; \
fi
# @git add $@
%/langpairs.txt: %
find $(dir $@) -mindepth 1 -maxdepth 1 -type d | sed 's#${dir $@}/##' | sort > $@
# @git add $@
## printf does not exist on Mac OS
# find $(dir $@) -mindepth 1 -maxdepth 1 -type d -printf '%f\n' | sort > $@
scores/langpairs.txt: scores/bleu_scores.db
echo 'select distinct langpair from scores;' | sqlite3 $< | sort | grep . > $@
scores/benchmarks.txt: scores/bleu_scores.db
echo 'select distinct testset,langpair from scores;' \
| sqlite3 $< | sort | grep . \
| ${MAKEDIR}/tools/merge-benchmark-langpairs.pl > $@
# scores/benchmarks.txt: scores
# rm -f $@
# find $< -mindepth 2 -maxdepth 2 -type d | sort > [email protected]
# for b in `cut -f3 -d/ [email protected] | sort -u`; do \
# echo "find language pairs for $$b"; \
# echo -n "$$b " >> $@; \
# grep "/$$b$$" [email protected] | cut -f2 -d/ | sort -u | tr "\n" ' ' >> $@; \
# echo "" >> $@; \
# done
# rm -f [email protected]
# # @git add $@
## this is too slow:
##
# %/benchmarks.txt: %
# for b in $(sort $(notdir $(shell find $(dir $@) -mindepth 2 -maxdepth 2 -type d))); do \
# echo "find language pairs for $$b"; \
# echo -n "$$b " >> $@; \
# find $(dir $@) -name "$$b" -type d | xargs dirname | xargs basename | \
# sort -u | tr "\n" ' ' >> $@; \
# echo "" >> $@; \
# done