@@ -67,7 +67,7 @@ def atisfold(fold):
67
67
68
68
69
69
# metrics function using conlleval.pl
70
- def conlleval (p , g , w , filename ):
70
+ def conlleval (p , g , w , filename , script_path ):
71
71
'''
72
72
INPUT:
73
73
p :: predictions
@@ -79,6 +79,10 @@ def conlleval(p, g, w, filename):
79
79
are written. it will be the input of conlleval.pl script
80
80
for computing the performance in terms of precision
81
81
recall and f1 score
82
+
83
+ OTHER:
84
+ script_path :: path to the directory containing the
85
+ conlleval.pl script
82
86
'''
83
87
out = ''
84
88
for sl , sp , sw in zip (g , p , w ):
@@ -91,27 +95,26 @@ def conlleval(p, g, w, filename):
91
95
f .writelines (out )
92
96
f .close ()
93
97
94
- return get_perf (filename )
98
+ return get_perf (filename , script_path )
95
99
96
100
97
- def download (origin ):
101
+ def download (origin , destination ):
98
102
'''
99
103
download the corresponding atis file
100
104
from http://www-etud.iro.umontreal.ca/~mesnilgr/atis/
101
105
'''
102
106
print 'Downloading data from %s' % origin
103
- name = origin .split ('/' )[- 1 ]
104
- urllib .urlretrieve (origin , name )
107
+ urllib .urlretrieve (origin , destination )
105
108
106
109
107
- def get_perf (filename ):
110
+ def get_perf (filename , folder ):
108
111
''' run conlleval.pl perl script to obtain
109
112
precision/recall and F1 score '''
110
- _conlleval = 'conlleval.pl'
113
+ _conlleval = os . path . join ( folder , 'conlleval.pl' )
111
114
if not os .path .isfile (_conlleval ):
112
115
url = 'http://www-etud.iro.umontreal.ca/~mesnilgr/atis/conlleval.pl'
113
- download (url )
114
- os .chmod ('conlleval.pl' , stat .S_IRWXU ) # give the execute permissions
116
+ download (url , _conlleval )
117
+ os .chmod (_conlleval , stat .S_IRWXU ) # give the execute permissions
115
118
116
119
proc = subprocess .Popen (["perl" ,
117
120
_conlleval ],
@@ -333,11 +336,13 @@ def main(param=None):
333
336
res_test = conlleval (predictions_test ,
334
337
groundtruth_test ,
335
338
words_test ,
336
- folder + '/current.test.txt' )
339
+ folder + '/current.test.txt' ,
340
+ folder )
337
341
res_valid = conlleval (predictions_valid ,
338
342
groundtruth_valid ,
339
343
words_valid ,
340
- folder + '/current.valid.txt' )
344
+ folder + '/current.valid.txt' ,
345
+ folder )
341
346
342
347
if res_valid ['f1' ] > best_f1 :
343
348
0 commit comments