File size: 11,992 Bytes
22e4ecd |
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 331 332 333 334 335 336 337 338 |
#!/usr/bin/env perl
# Scans the folder with the evaluation results of a shared task submission.
# Collects all scores and creates a HTML page that presents them.
# Copyright © 2020 Dan Zeman <[email protected]>
# License: GNU GPL
use utf8;
use open ':utf8';
binmode(STDIN, ':utf8');
binmode(STDOUT, ':utf8');
binmode(STDERR, ':utf8');
my $system_unpacked_folder = '/home/zeman/iwpt2020/_private/data/sysoutputs';
# List of language codes and names.
my %languages =
(
'ar' => 'Arabic',
'bg' => 'Bulgarian',
'cs' => 'Czech',
'nl' => 'Dutch',
'en' => 'English',
'et' => 'Estonian',
'fi' => 'Finnish',
'fr' => 'French',
'it' => 'Italian',
'lv' => 'Latvian',
'lt' => 'Lithuanian',
'pl' => 'Polish',
'ru' => 'Russian',
'sk' => 'Slovak',
'sv' => 'Swedish',
'ta' => 'Tamil',
'uk' => 'Ukrainian'
);
my @languages = sort {$languages{$a} cmp $languages{$b}} (keys(%languages));
# List and ordering of treebanks for each language.
my %dev_treebanks =
(
'ar' => ['Arabic-PADT'],
'bg' => ['Bulgarian-BTB'],
'cs' => ['Czech-FicTree', 'Czech-CAC', 'Czech-PDT'],
'nl' => ['Dutch-Alpino', 'Dutch-LassySmall'],
'en' => ['English-EWT'],
'et' => ['Estonian-EDT'],
'fi' => ['Finnish-TDT'],
'fr' => ['French-Sequoia'],
'it' => ['Italian-ISDT'],
'lv' => ['Latvian-LVTB'],
'lt' => ['Lithuanian-ALKSNIS'],
'pl' => ['Polish-LFG', 'Polish-PDB'],
'ru' => ['Russian-SynTagRus'],
'sk' => ['Slovak-SNK'],
'sv' => ['Swedish-Talbanken'],
'ta' => ['Tamil-TTB'],
'uk' => ['Ukrainian-IU']
);
my %test_treebanks =
(
'ar' => ['Arabic-PADT'],
'bg' => ['Bulgarian-BTB'],
'cs' => ['Czech-FicTree', 'Czech-CAC', 'Czech-PDT', 'Czech-PUD'],
'nl' => ['Dutch-Alpino', 'Dutch-LassySmall'],
'en' => ['English-EWT', 'English-PUD'],
'et' => ['Estonian-EDT', 'Estonian-EWT'],
'fi' => ['Finnish-TDT', 'Finnish-PUD'],
'fr' => ['French-Sequoia', 'French-FQB'],
'it' => ['Italian-ISDT'],
'lv' => ['Latvian-LVTB'],
'lt' => ['Lithuanian-ALKSNIS'],
'pl' => ['Polish-LFG', 'Polish-PDB', 'Polish-PUD'],
'ru' => ['Russian-SynTagRus'],
'sk' => ['Slovak-SNK'],
'sv' => ['Swedish-Talbanken', 'Swedish-PUD'],
'ta' => ['Tamil-TTB'],
'uk' => ['Ukrainian-IU']
);
# Enhancement type selection for each treebank (only for information in the table).
my %enhancements =
(
'Arabic-PADT' => 'no xsubj',
'Bulgarian-BTB' => '', # all
'Czech-FicTree' => '', # all
'Czech-CAC' => '', # all
'Czech-PDT' => '', # all
'Czech-PUD' => 'no codepend',
'Dutch-Alpino' => '', # all
'Dutch-LassySmall' => '', # all
'English-EWT' => '', # all
'English-PUD' => '', # all
'Estonian-EDT' => 'no xsubj',
'Estonian-EWT' => 'no codepend, no xsubj',
'Finnish-TDT' => '', # all
'Finnish-PUD' => 'no codepend, no xsubj',
'French-Sequoia' => 'no gapping, relcl, case',
'French-FQB' => 'no gapping, relcl, case',
'Italian-ISDT' => '', # all
'Latvian-LVTB' => '', # all
'Lithuanian-ALKSNIS' => '', # all
'Polish-LFG' => 'no gapping', # no gapping
'Polish-PDB' => '', # all
'Polish-PUD' => '', # all
'Russian-SynTagRus' => '', # no coord depend
'Slovak-SNK' => '', # all
'Swedish-Talbanken' => '', # all
'Swedish-PUD' => '', # all
'Tamil-TTB' => 'no gapping, xsubj, relcl',
'Ukrainian-IU' => '', # all
);
if(scalar(@ARGV)!=3)
{
die("Three arguments expected: team name, submission id, and dev|test");
}
my $team = $ARGV[0];
my $submid = $ARGV[1];
my $portion = $ARGV[2];
if($team !~ m/^[a-z0-9_]+$/)
{
die("Invalid team name '$team': must be [a-z0-9_]+");
}
if($submid !~ m/^[a-z0-9_]+$/)
{
die("Invalid submission id '$submid': must be [a-z0-9_]+");
}
if($portion !~ m/^(dev|test)$/)
{
die("Unknown data portion '$portion', should be 'dev' or 'test'");
}
my $submission_folder = "$system_unpacked_folder/$team/$submid";
my %treebanks = $portion eq 'dev' ? %dev_treebanks : %test_treebanks;
foreach my $language (@languages)
{
# Read the evaluation scores.
my $file = "$submission_folder/$language.eval.log";
if(-f $file)
{
open(EVAL, $file) or die("Cannot read '$file': $!");
while(<EVAL>)
{
s/\r?\n$//;
if(m/^\w+.*\|.*\d+/)
{
my @f = split(/\s*\|\s*/, $_);
my $metric = shift(@f);
my $p = shift(@f);
my $r = shift(@f);
my $f = shift(@f);
my $a = shift(@f);
$score{language}{$language}{$metric} =
{
'p' => $p,
'r' => $r,
'f' => $f,
'a' => $a
};
}
}
close(EVAL);
}
}
my @treebanks;
my $doing_dev;
foreach my $language (@languages)
{
my $language_reliable = exists($score{language}{$language});
foreach my $treebank (@{$treebanks{$language}})
{
push(@treebanks, $treebank);
my $tcode = lc($treebank);
$tcode =~ s/^.+-//;
# Read the evaluation scores.
my $file = "$submission_folder/pertreebank/${language}_$tcode-ud";
if(-e "$file-dev.eval.log" && -e "$file-test.eval.log")
{
die("Both dev and test eval.log exist for '$file'");
}
elsif(-e "$file-dev.eval.log")
{
$file .= '-dev.eval.log';
if(!defined($doing_dev))
{
$doing_dev = 1;
}
elsif($doing_dev==0)
{
die("Both dev and test eval logs are present in the per-treebank folder.");
}
}
elsif(-e "$file-test.eval.log")
{
$file .= '-test.eval.log';
if(!defined($doing_dev))
{
$doing_dev = 0;
}
elsif($doing_dev==1)
{
die("Both dev and test eval logs are present in the per-treebank folder.");
}
}
# Score of a treebank is not reliable if the score for the language does not exist.
if(-f $file && $language_reliable)
{
open(EVAL, $file) or die("Cannot read '$file': $!");
while(<EVAL>)
{
s/\r?\n$//;
if(m/^\w+.*\|.*\d+/)
{
my @f = split(/\s*\|\s*/, $_);
my $metric = shift(@f);
my $p = shift(@f);
my $r = shift(@f);
my $f = shift(@f);
my $a = shift(@f);
$score{treebank}{$treebank}{$metric} =
{
'p' => $p,
'r' => $r,
'f' => $f,
'a' => $a
};
}
}
close(EVAL);
}
# For comparison, add a copy of (link to) the language coarse scores to each treebank.
$score{treebank}{$treebank}{language} = $score{language}{$language};
# Sum up (and average) the qualitative ELAS scores for each language.
$score{language}{$language}{QualitativeSUM}{ELAS}{f} += $score{treebank}{$treebank}{ELAS}{f};
$score{language}{$language}{QualitativeCNT}++;
}
}
my $html = "<html>\n";
$html .= "<head>\n";
$html .= " <title>IWPT Results of $team/$submid</title>\n";
$html .= "</head>\n";
$html .= "<body>\n";
$html .= " <h1>IWPT 2020 Shared Task Results of <span style='color:blue'>$team</span>/$submid</h1>\n";
my @metrics = qw(Tokens Words Sentences UPOS XPOS UFeats AllTags Lemmas UAS LAS CLAS MLAS BLEX EULAS ELAS);
$html .= " <h2>Coarse F<sub>1</sub> Scores</h2>\n";
$html .= " <p>Each score pertains to the combined test set of the language, without distinguishing individual treebanks and the enhancement types they annotate. The last line shows the macro-average over languages.</p>\n";
$html .= " <table>\n";
$html .= " <tr><td><b>Language</b></td>";
foreach my $metric (@metrics)
{
$html .= "<td><b>$metric</b></td>";
}
$html .= "</tr>\n";
foreach my $language (@languages)
{
my $lh = $score{language}{$language};
$html .= " <tr><td>$languages{$language}</td>";
foreach my $metric (@metrics)
{
$html .= "<td>$lh->{$metric}{f}</td>";
$score{language}{SUM}{$metric}{f} += $lh->{$metric}{f};
}
$html .= "</tr>\n";
}
my $n = scalar(@languages);
$html .= " <tr><td><b>Average</b></td>";
foreach my $metric (@metrics)
{
$score{language}{AVG}{$metric}{f} = sprintf("%.2f", $score{language}{SUM}{$metric}{f}/$n);
$html .= "<td><b>$score{language}{AVG}{$metric}{f}</b></td>";
}
$html .= "</tr>\n";
$html .= " </table>\n";
$html .= " <h2>Qualitative F<sub>1</sub> Scores</h2>\n";
$html .= " <p>The system output for each language was split into parts corresponding to individual source treebanks. ".
"The scores then ignore errors in enhancement types for which the treebank lacks gold-standard annotation. ".
"The column LAvgELAS shows the qualitative ELAS averaged over treebanks of the same language; ".
"the final average in bold is averaged over languages rather than treebanks. ".
"For comparison, the last column then shows the coarse ELAS F<sub>1</sub> for the given language.</p>\n";
$html .= " <table>\n";
$html .= " <tr><td><b>Treebank</b></td>";
foreach my $metric (@metrics)
{
$html .= "<td><b>$metric</b></td>";
}
# Inform about omitted enhancements in the treebank.
$html .= "<td><b>Enhancements</b></td>";
# Add a column for the average of the qualitative ELAS scores over the treebanks of one language.
$html .= "<td><b>LAvgELAS</b></td>";
# Add a column for comparison with language coarse ELAS.
$html .= "<td><b>cf.</b></td>";
$html .= "</tr>\n";
foreach my $treebank (@treebanks)
{
my $lh = $score{treebank}{$treebank};
$html .= " <tr><td>$treebank</td>";
foreach my $metric (@metrics)
{
$html .= "<td>$lh->{$metric}{f}</td>";
$score{treebank}{SUM}{$metric}{f} += $lh->{$metric}{f};
}
# Indicate which enhancements are missing in the treebank.
my $omitted = $enhancements{$treebank} ne '' ? "($enhancements{$treebank})" : '';
$html .= "<td>$omitted</td>";
# Average the qualitative ELAS scores for each language.
my $sum = $lh->{language}{QualitativeSUM}{ELAS}{f};
my $cnt = $lh->{language}{QualitativeCNT};
my $avg = $lh->{language}{QualitativeAVG}{ELAS}{f} = $cnt==0 ? 0 : sprintf("%.2f", $sum/$cnt);
$html .= "<td>$avg</td>";
# Add a column for comparison with language coarse ELAS.
$html .= "<td>$lh->{language}{ELAS}{f}</td>";
$html .= "</tr>\n";
}
$n = scalar(@treebanks);
$html .= " <tr><td><b>Average</b></td>";
foreach my $metric (@metrics)
{
$score{treebank}{AVG}{$metric}{f} = $n==0 ? 0 : sprintf("%.2f", $score{treebank}{SUM}{$metric}{f}/$n);
$html .= "<td><b>$score{treebank}{AVG}{$metric}{f}</b></td>";
}
# Inform about omitted enhancements in the treebank.
$html .= "<td></td>";
# Add a column for the average of the qualitative ELAS scores over the treebanks of one language.
# We want to average these averages over languages, not over treebanks!
my $sum = 0;
$n = scalar(@languages);
foreach my $language (@languages)
{
$sum += $score{language}{$language}{QualitativeAVG}{ELAS}{f};
}
$score{language}{QualitativeAVG}{ELAS}{f} = $n==0 ? 0 : sprintf("%.2f", $sum/$n);
$html .= "<td><b>$score{language}{QualitativeAVG}{ELAS}{f}</b></td>";
# Add a column for comparison with language coarse ELAS.
$html .= "<td></td>";
$html .= "</tr>\n";
$html .= " </table>\n";
$html .= "</body>\n";
$html .= "</html>\n";
print($html);
|