#!/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 # 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() { 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() { 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 = "\n"; $html .= "\n"; $html .= " IWPT Results of $team/$submid\n"; $html .= "\n"; $html .= "\n"; $html .= "

IWPT 2020 Shared Task Results of $team/$submid

\n"; my @metrics = qw(Tokens Words Sentences UPOS XPOS UFeats AllTags Lemmas UAS LAS CLAS MLAS BLEX EULAS ELAS); $html .= "

Coarse F1 Scores

\n"; $html .= "

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.

\n"; $html .= " \n"; $html .= " "; foreach my $metric (@metrics) { $html .= ""; } $html .= "\n"; foreach my $language (@languages) { my $lh = $score{language}{$language}; $html .= " "; foreach my $metric (@metrics) { $html .= ""; $score{language}{SUM}{$metric}{f} += $lh->{$metric}{f}; } $html .= "\n"; } my $n = scalar(@languages); $html .= " "; foreach my $metric (@metrics) { $score{language}{AVG}{$metric}{f} = sprintf("%.2f", $score{language}{SUM}{$metric}{f}/$n); $html .= ""; } $html .= "\n"; $html .= "
Language$metric
$languages{$language}$lh->{$metric}{f}
Average$score{language}{AVG}{$metric}{f}
\n"; $html .= "

Qualitative F1 Scores

\n"; $html .= "

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 F1 for the given language.

\n"; $html .= " \n"; $html .= " "; foreach my $metric (@metrics) { $html .= ""; } # Inform about omitted enhancements in the treebank. $html .= ""; # Add a column for the average of the qualitative ELAS scores over the treebanks of one language. $html .= ""; # Add a column for comparison with language coarse ELAS. $html .= ""; $html .= "\n"; foreach my $treebank (@treebanks) { my $lh = $score{treebank}{$treebank}; $html .= " "; foreach my $metric (@metrics) { $html .= ""; $score{treebank}{SUM}{$metric}{f} += $lh->{$metric}{f}; } # Indicate which enhancements are missing in the treebank. my $omitted = $enhancements{$treebank} ne '' ? "($enhancements{$treebank})" : ''; $html .= ""; # 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 .= ""; # Add a column for comparison with language coarse ELAS. $html .= ""; $html .= "\n"; } $n = scalar(@treebanks); $html .= " "; foreach my $metric (@metrics) { $score{treebank}{AVG}{$metric}{f} = $n==0 ? 0 : sprintf("%.2f", $score{treebank}{SUM}{$metric}{f}/$n); $html .= ""; } # Inform about omitted enhancements in the treebank. $html .= ""; # 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 .= ""; # Add a column for comparison with language coarse ELAS. $html .= ""; $html .= "\n"; $html .= "
Treebank$metricEnhancementsLAvgELAScf.
$treebank$lh->{$metric}{f}$omitted$avg$lh->{language}{ELAS}{f}
Average$score{treebank}{AVG}{$metric}{f}$score{language}{QualitativeAVG}{ELAS}{f}
\n"; $html .= "\n"; $html .= "\n"; print($html);