name; $c2 = $comment["$setup-$id2"]->name; if (substr($c2,0,strlen($id)+1) == $id."+") { print "Run $id2 vs $id (".substr($c2,strlen($id)).")"; } else { print "Run $id2 ($c2) vs $id ($c)"; } print ""; ?>
(loading...)
Precision by Coverage"; print "The graphs display what ratio of words of a specific type are translated correctly (yellow), and what ratio is deleted (blue)."; print " The extend of the boxes is scaled on the x-axis by the number of tokens of the displayed type."; // load data $data = file(get_current_analysis_filename2("precision","precision-by-corpus-coverage")); $total = 0; $log_info = array(); for($i=0;$i0) { $log_count = (int) (log($item[0])/log(2)); } if (!array_key_exists($log_count,$log_info)) { $log_info[$log_count]["precision"] = 0; $log_info[$log_count]["delete"] = 0; $log_info[$log_count]["length"] = 0; $log_info[$log_count]["total"] = 0; } $log_info[$log_count]["precision"] += $item[1]; $log_info[$log_count]["delete"] += $item[2]; $log_info[$log_count]["length"] += $item[3]; $log_info[$log_count]["total"] += $item[4]; } $log_info_new = $log_info; // load base data $data = file(get_current_analysis_filename("precision","precision-by-corpus-coverage")); for($i=0;$i0) { $log_count = (int) (log($item[0])/log(2)); } $log_info[$log_count]["precision"] -= $item[1]; $log_info[$log_count]["delete"] -= $item[2]; $log_info[$log_count]["length"] -= $item[3]; } print "

By log2-count in the training corpus

"; precision_by_coverage_diff_graph("byCoverage",$log_info,$log_info_new,$total,$img_width,SORT_NUMERIC); precision_by_coverage_diff_matrix(); // load factored data $d = dir("$dir/evaluation/$set.analysis.".get_precision_analysis_version($dir,$set,$id)); while (false !== ($file = $d->read())) { if (preg_match('/precision-by-corpus-coverage.(.+)$/',$file, $match) && file_exists(get_current_analysis_filename2("precision","precision-by-corpus-coverage.$match[1]"))) { precision_by_coverage_diff_factored($img_width,$total,$file,$match[1]); } } } function precision_by_coverage_diff_factored($img_width,$total,$file,$factor_id) { global $dir,$set,$id,$id2; $data = file(get_current_analysis_filename2("precision",$file)); for($i=0;$i0) { $log_count = (int) (log($count)/log(2)); } $log_info_factored[$factor][$log_count]["precision"] += $item[2]; $log_info_factored[$factor][$log_count]["delete"] += $item[3]; $log_info_factored[$factor][$log_count]["length"] += $item[4]; $log_info_factored[$factor][$log_count]["total"] += $item[5]; } $info_factored_new = $info_factored; $info_factored_sum_new = $info_factored_sum; $log_info_factored_new = $log_info_factored; // baseline data $data = file(get_current_analysis_filename("precision",$file)); for($i=0;$i0) { $log_count = (int) (log($count)/log(2)); } $log_info_factored[$factor][$log_count]["precision"] -= $item[2]; $log_info_factored[$factor][$log_count]["delete"] -= $item[3]; $log_info_factored[$factor][$log_count]["length"] -= $item[4]; } print "

By factor ".factor_name("input",$factor_id)."

"; precision_by_coverage_diff_graph("byFactor",$info_factored_sum,$info_factored_sum_new,$total,$img_width,SORT_STRING); print "

For each factor, by log2-count in the corpus

"; foreach ($log_info_factored as $factor => $info) { if ($total_factored[$factor]/$total > 0.01) { print "
$factor"; precision_by_coverage_diff_graph("byCoverageFactor$factor",$info,$log_info_factored_new[$factor],$total,10+2*$img_width*$total_factored[$factor]/$total,SORT_NUMERIC); print "
"; } } } function precision_by_word_diff($type) { global $dir,$set,$id,$id2; $byCoverage = -2; $byFactor = "false"; if ($type == "byCoverage") { $byCoverage = (int) $_GET["type"]; } else if ($type == "byFactor") { $byFactor = $_GET["type"]; } else if (preg_match("/byCoverageFactor(.+)/",$type,$match)) { $byCoverage = (int) $_GET["type"]; $byFactor = $match[1]; } $data = file(get_current_analysis_filename2("precision","precision-by-input-word")); $total = 0; $info = array(); for($i=0;$i0) { $log_count = (int) (log($count)/log(2)); } if ($byCoverage != -2 && $byCoverage != $log_count) { continue; } //# filter for factor $word = $item[5]; if ($byFactor != "false" && $byFactor != $item[6]) { continue; } if (!array_key_exists($word,$info)) { $info[$word]["precision"] = 0; $info[$word]["delete"] = 0; $info[$word]["length"] = 0; $info[$word]["total"] = 0; } $info[$word]["precision"] += $item[0]; $info[$word]["delete"] += $item[1]; $info[$word]["length"] += $item[2]; $info[$word]["total"] += $item[3]; } $info_new = $info; $data = file(get_current_analysis_filename("precision","precision-by-input-word")); for($i=0;$i0) { $log_count = (int) (log($count)/log(2)); } if ($byCoverage != -2 && $byCoverage != $log_count) { continue; } //# filter for factor $word = $item[5]; if ($byFactor != "false" && $byFactor != $item[6]) { continue; } if (!array_key_exists($word,$info)) { $info[$word]["precision"] = 0; $info[$word]["delete"] = 0; $info[$word]["length"] = 0; $info_new[$word]["length"] = 0; $info_new[$word]["delete"] = 0; $info_new[$word]["precision"] = 0; $info_new[$word]["total"] = 0; $info[$word]["total"] = -$item[3]; } $info[$word]["precision"] -= $item[0]; $info[$word]["delete"] -= $item[1]; $info[$word]["length"] -= $item[2]; } print "\n"; foreach ($info as $word => $wordinfo) { print ""; printf("",$info_new[$word]["precision"]/$wordinfo["total"]*100,"%",$wordinfo["precision"]/$wordinfo["total"]*100,"%",$wordinfo["precision"],$wordinfo["total"]); printf("",$wordinfo["precision"]/$total*100,"%",$wordinfo["precision"],$total); printf("",$info_new[$word]["delete"]/$wordinfo["total"]*100,"%",$wordinfo["delete"]/$wordinfo["total"]*100,"%",$wordinfo["delete"],$wordinfo["total"]); printf("",$wordinfo["delete"]/$total*100,"%",$wordinfo["delete"],$total); printf("",$wordinfo["length"]/$wordinfo["total"]); print ""; } print "
 PrecisionPrecision ImpactDeleteDelete ImpactLength
$word%.1f%s%+.1f%s%+.1f/%d%+.2f%s%+.1f/%d%.1f%s%+.1f%s%+d/%d%+.2f%s%+d/%d%+.3f
\n"; } function precision_by_coverage_diff_matrix() { global $id,$id2; print "

Impact of Change in Coverage

"; print "Coverage in run $id is the x-axis, change in coverage in run $id2 is the y-axis. Size of box reflects how many output words are produced, yellow is the number of correct translations, green indicates increase, green decrease. The bleu rectangle below each box indicates number of words dropped, and increase (cyan) or decrease (purple).

("; $scale = 30; for($i=1; $i<=5; $i++) { $size = (int)(sqrt($i*$scale)); $name = "size-$i"; print " = $i word"; if ($i>1) { print "s"; } if ($i<5) { print ", "; } } print ")

"; # get base data $data = file(get_current_analysis_filename("precision","precision-by-input-word")); $word = array(); $class = array(); for($i=0;$i $max_base_log_count) { $max_base_log_count = $log_count; } } # get alternative data $data = file(get_current_analysis_filename2("precision","precision-by-input-word")); for($i=0;$i $max_alt_log_count) { $max_alt_log_count = $alt; } if ($alt < $min_alt_log_count) { $min_alt_log_count = $alt; } if (!array_key_exists($alt,$matrix[$base])) { $matrix[$base][$alt] = array(); $matrix[$base][$alt]["precision1"] = 0; $matrix[$base][$alt]["delete1"] = 0; $matrix[$base][$alt]["total1"] = 0; $matrix[$base][$alt]["coverage1"] = 0; $matrix[$base][$alt]["precision2"] = 0; $matrix[$base][$alt]["delete2"] = 0; $matrix[$base][$alt]["total2"] = 0; $matrix[$base][$alt]["coverage2"] = 0; } # ignore mismatches in source words due to tokenization / casing if (array_key_exists($surface,$word)) { $matrix[$base][$alt]["precision1"] += $word[$surface]["precision"]; $matrix[$base][$alt]["delete1"] += $word[$surface]["delete"]; $matrix[$base][$alt]["total1"] += $word[$surface]["total"]; $matrix[$base][$alt]["coverage1"] += $word[$surface]["count"]; $matrix[$base][$alt]["precision2"] += $item[0]; $matrix[$base][$alt]["delete2"] += $item[1]; $matrix[$base][$alt]["total2"] += $item[2]; $matrix[$base][$alt]["coverage2"] += $item[4]; } } # make table print ""; for($base=-1;$base<=$max_base_log_count;$base++) { print ""; } print ""; for($alt=$max_alt_log_count;$alt>=$min_alt_log_count;$alt--) { print ""; for($base=-1;$base<=$max_base_log_count;$base++) { print ""; } print ""; } print ""; for($base=-1;$base<=$max_base_log_count;$base++) { print ""; } print "
 $base
$alt"; if (array_key_exists($base,$matrix) && array_key_exists($alt,$matrix[$base])) { #print $matrix[$base][$alt]["precision1"]."->". # $matrix[$base][$alt]["precision2"]."
"; #print $matrix[$base][$alt]["delete1"]."->". # $matrix[$base][$alt]["delete2"]."
"; #print $matrix[$base][$alt]["total1"]."->". # $matrix[$base][$alt]["total2"]."
"; $scale = 30; $total = $matrix[$base][$alt]["total1"]; if ($matrix[$base][$alt]["total2"] > $total) { $total = $matrix[$base][$alt]["total2"]; } $total = (int)(sqrt($total*$scale)); if ($total>0) { $prec1 = $matrix[$base][$alt]["precision1"]*$scale; $prec2 = $matrix[$base][$alt]["precision2"]*$scale; if ($prec1 > $prec2) { $prec_base = (int)(sqrt($prec1)); $prec_imp = (int)(sqrt($prec1-$prec2)); $prec_color = "255,100,100"; } else { $prec_base = (int)(sqrt($prec2)); $prec_imp = (int)(sqrt($prec2-$prec1)); $prec_color = "100,255,100"; } $prec_base_top = (int)(($total-$prec_base)/2); $prec_imp_top = (int)(($total-$prec_imp)/2); $del1 = $matrix[$base][$alt]["delete1"]*$scale; $del2 = $matrix[$base][$alt]["delete2"]*$scale; if ($del1 > $del2) { $del_base = $del1; $del_imp = $del1-$del2; $del_color = "150,100,255"; } else { $del_base = $del2; $del_imp = $del2-$del1; $del_color = "100,200,200"; } $del_base_height = (int)($del_base/$total); $del_imp_height = (int)($del_imp/$total); $name = "matrix-$base-$alt"; #print "$total/$prec1/$prec2 -> $prec_base/$prec_imp
"; print ""; print ""; print ""; } } print "
$alt
$base

"; } function precision_by_coverage_diff_matrix_details() { $alt = $_GET["alt"]; $base = $_GET["base"]; $impact_total = 0; $data = file(get_current_analysis_filename("precision","precision-by-input-word")); $word = array(); $class = array(); for($i=0;$i PrecisionPrecision ImpactDeleteDelete Impact\n"; # get alternative data $data = file(get_current_analysis_filename2("precision","precision-by-input-word")); for($i=0;$i%.1f%s%+.1f%s%+.1f/%d", $precision/$total*100,"%", ($precision-$word[$surface]["precision"])/$total*100,"%", $precision-$word[$surface]["precision"],$total); $out .= sprintf("%+.2f%s%+.1f/%d", ($precision-$word[$surface]["precision"])/$impact_total*100,"%", $precision-$word[$surface]["precision"],$impact_total); $out .= sprintf("%.1f%s%+.1f%s%+.1f/%d", $delete/$total*100,"%", ($delete-$word[$surface]["delete"])/$total*100,"%", $delete-$word[$surface]["delete"],$total); $out .= sprintf("%+.2f%s%+.1f/%d", ($delete-$word[$surface]["delete"])/$impact_total*100,"%", $delete-$word[$surface]["delete"],$impact_total); $out .= ""; $all_out[] = $out; } } sort($all_out); foreach($all_out as $out) { $o = explode("\t",$out); print $o[1]; } print ""; } function precision_by_coverage_diff_graph($name,$log_info,$log_info_new,$total,$img_width,$sort_type) { $keys = array_keys($log_info); sort($keys,$sort_type); print "
(hide table)
\n"; print "
\n"; print "\n"; foreach ($keys as $i) { if (array_key_exists($i,$log_info)) { print ""; printf("",$log_info_new[$i]["precision"]/$log_info[$i]["total"]*100,"%",$log_info[$i]["precision"]/$log_info[$i]["total"]*100,"%",$log_info[$i]["precision"],$log_info[$i]["total"]); printf("",$log_info[$i]["precision"]/$total*100,"%",$log_info[$i]["precision"],$total); printf("",$log_info_new[$i]["delete"]/$log_info[$i]["total"]*100,"%",$log_info[$i]["delete"]/$log_info[$i]["total"]*100,"%",$log_info[$i]["delete"],$log_info[$i]["total"]); printf("",$log_info[$i]["delete"]/$total*100,"%",$log_info[$i]["delete"],$total); printf("",$log_info[$i]["length"]/$log_info[$i]["total"]); print ""; print ""; } } print "
 PrecisionPrecision ImpactDeleteDelete ImpactLength
$i%.1f%s%.1f%s%+.1f/%d%+.2f%s%+.1f/%d%.1f%s%+.1f%s%+d/%d%+.2f%s%+d/%d%+.3f
"; print "
"; print ""; } // stats on precision and recall function precision_recall_details_diff() { ?>
(loading...)
(loading...)
(loading...)
(loading...)
(loading...)
(loading...)
(loading...)
(loading...)
"; print "Precision of Output
"; //foreach (array("precision","recall") as $type) { $type = "precision"; print "\n"; printf("\n", $info[1]["$type-1-correct"],$info[1]["$type-1-correct"]-$info[0]["$type-1-correct"], $info[1]["$type-2-correct"],$info[1]["$type-2-correct"]-$info[0]["$type-2-correct"], $info[1]["$type-3-correct"],$info[1]["$type-3-correct"]-$info[0]["$type-3-correct"], $info[1]["$type-4-correct"],$info[1]["$type-4-correct"]-$info[0]["$type-4-correct"]); printf("\n", $info[1]["$type-1-correct"]/$info[1]["$type-1-total"]*100,'%',$info[1]["$type-1-correct"]/$info[1]["$type-1-total"]*100-$info[0]["$type-1-correct"]/$info[0]["$type-1-total"]*100,'%', $info[1]["$type-2-correct"]/$info[1]["$type-2-total"]*100,'%',$info[1]["$type-2-correct"]/$info[1]["$type-2-total"]*100-$info[0]["$type-2-correct"]/$info[0]["$type-2-total"]*100,'%', $info[1]["$type-3-correct"]/$info[1]["$type-3-total"]*100,'%',$info[1]["$type-3-correct"]/$info[1]["$type-3-total"]*100-$info[0]["$type-3-correct"]/$info[0]["$type-3-total"]*100,'%', $info[1]["$type-4-correct"]/$info[1]["$type-4-total"]*100,'%',$info[1]["$type-4-correct"]/$info[1]["$type-4-total"]*100-$info[0]["$type-4-correct"]/$info[0]["$type-4-total"]*100,'%'); printf("\n", $info[1]["$type-1-total"]-$info[1]["$type-1-correct"],($info[1]["$type-1-total"]-$info[1]["$type-1-correct"])-($info[0]["$type-1-total"]-$info[0]["$type-1-correct"]), $info[1]["$type-2-total"]-$info[1]["$type-2-correct"],($info[1]["$type-2-total"]-$info[1]["$type-2-correct"])-($info[0]["$type-2-total"]-$info[0]["$type-2-correct"]), $info[1]["$type-3-total"]-$info[1]["$type-3-correct"],($info[1]["$type-3-total"]-$info[1]["$type-3-correct"])-($info[0]["$type-3-total"]-$info[0]["$type-3-correct"]), $info[1]["$type-4-total"]-$info[1]["$type-4-correct"],($info[1]["$type-4-total"]-$info[1]["$type-4-correct"])-($info[0]["$type-4-total"]-$info[0]["$type-4-correct"])); print "
$type1-gram2-gram3-gram4-gram
correct%d (%+d)%d (%+d)%d (%+d)%d (%+d)
 %.1f%s (%+.1f%s)%.1f%s (%+.1f%s)%.1f%s (%+.1f%s)%.1f%s (%+.1f%s)
wrong%d (%+d)%d (%+d)%d (%+d)%d (%+d)
"; //} print "details "; if (file_exists(get_current_analysis_filename("precision","precision-by-corpus-coverage")) && file_exists(get_current_analysis_filename2("precision","precision-by-corpus-coverage"))) { print "| precision of input by coverage "; } print ""; print "Metrics
\n"; for($idx=0;$idx<2;$idx++) { $each_score = explode(" ; ",$experiment[$idx?$id2:$id]->result[$set]); for($i=0;$i $value) { $header .= "$name"; $score_line .= "".$score[$name][1].""; $diff_line .= sprintf("%+.2f",$score[$name][1]-$score[$name][0]); } print "".$header."".$score_line."".$diff_line."
"; printf("length-diff
%d (%+d)",$info[1]["precision-1-total"]-$info[1]["recall-1-total"],$info[1]["precision-1-total"]-$info[0]["precision-1-total"]); print ""; } function bleu_diff() { $count = $_GET['count']; if ($count == 0) { $count = 5; } print "annotated sentences
"; print "sorted by "; if ($_GET['sort'] == "order" || $_GET['sort'] == "") { print "order "; } else { print "order "; } if ($_GET['sort'] == "better") { print "order "; } else { print "better "; } if ($_GET['sort'] == "worse") { print "order "; } else { print "worse "; } print "display fullscreen "; $count = $_GET['count']; if ($count == 0) { $count = 5; } print "showing $count "; print "more "; if ($count > 5) { print "less "; } print "all "; print "
\n"; bleu_diff_annotation(); print ""; print "more "; print "
\n"; } function bleu_diff_annotation() { global $set,$id,$id2,$dir; // load input $input_annotation = file(get_analysis_filename($dir,$set,$id,"coverage","input-annotation")); for($i=0;$i $annotation[$i]["bleu0"]) { $better++; } else { $worse++; } } print "
\n"; printf("\n", $identical, $same, $better, $worse); printf("
identicalsamebetterworse
%d%d%d%d
%d%s%d%s%d%s%d%s
\n", $identical*100/count($annotation)+.5, '%', $same*100/count($annotation)+.5, '%', $better*100/count($annotation)+.5, '%', $worse*100/count($annotation)+.5, '%'); // print "identical: $identical (%d), same: $same, better: $better, worse: $worse
\n"; // sort global $sort; $sort = $_GET['sort']; if ($sort == '') { $sort = "order"; } function cmp($a, $b) { global $sort; if ($sort == "worse") { $a_idx = $a["bleu1"]-$a["bleu0"]; $b_idx = $b["bleu1"]-$b["bleu0"]; } else if ($sort == "better") { $a_idx = -$a["bleu1"]+$a["bleu0"]; $b_idx = -$b["bleu1"]+$b["bleu0"]; } if ($a_idx == $b_idx) { return 0; } return ($a_idx < $b_idx) ? -1 : 1; } if ($sort != 'order') { usort($annotation, 'cmp'); } $count = $_GET['count']; if ($count == 0) { $count = 5; } // display for($i=0;$i<$count && $i[src] ".$input[$line["id"]]."
"; $word_with_score1 = split(" ",$line["system1"]); $word_with_score0 = split(" ",$line["system0"]); $word1 = split(" ",preg_replace("/\|\d/","",$line["system1"])); $word0 = split(" ",preg_replace("/\|\d/","",$line["system0"])); $matched_with_score = string_edit_distance($word_with_score0,$word_with_score1); $matched = string_edit_distance($word0,$word1); print "[".$id2."-".$line["id"].":".$line["bleu1"]."] "; $matched1 = preg_replace('/D/',"",$matched); $matched_with_score1 = preg_replace('/D/',"",$matched_with_score); bleu_line_diff( $word_with_score1, $matched1, $matched_with_score1 ); print "[".$id."-".$line["id"].":".$line["bleu0"]."] "; $matched0 = preg_replace('/I/',"",$matched); $matched_with_score0 = preg_replace('/I/',"",$matched_with_score); bleu_line_diff( $word_with_score0, $matched0, $matched_with_score0 ); print "[ref] ".$line["reference"]."
"; } } function bleu_line_diff( $word,$matched,$matched_with_score ) { $color = array("#FFC0C0","#FFC0FF","#C0C0FF","#C0FFFF","#C0FFC0"); $lcolor = array("#FFF0F0","#FFF0FF","#F0F0FF","#F0FFFF","#F0FFF0"); for($j=0;$j$surface "; } print "
"; } function ngram_diff($type) { global $set,$id,$id2,$dir; ini_set('memory_limit',1e9); // 1G for big files // load data $order = $_GET['order']; for($idx=0;$idx<2;$idx++) { $data = file(get_analysis_filename($dir,$set,$idx?$id2:$id,"basic","n-gram-$type.$order")); for($i=0;$i $value) { $item = $value; // $item["correct0"] += 0; // $item["correct1"] += 0; // $item["total0"] += 0; // $item["total1"] += 0; $item["ngram"] = $n; if ($sort == "abs_worse") { $item["index"] = (2*$item["correct1"] - $item["total1"]) - (2*$item["correct0"] - $item["total0"]); } else if ($sort == "abs_better") { $item["index"] = - (2*$item["correct1"] - $item["total1"]) + (2*$item["correct0"] - $item["total0"]); } else if ($sort == "ratio_worse") { $item["index"] = ($item["correct1"] + $smooth) / ($item["total1"] + $smooth) - ($item["correct0"] + $smooth) / ($item["total0"] + $smooth); } else if ($sort == "ratio_better") { $item["index"] = - ($item["correct1"] + $smooth) / ($item["total1"] + $smooth) + ($item["correct0"] + $smooth) / ($item["total0"] + $smooth); } $ngram[] = $item; unset($ngram_hash[$n]); } unset($ngram_hash); // sort function cmp($a, $b) { if ($a["index"] == $b["index"]) { return 0; } return ($a["index"] < $b["index"]) ? -1 : 1; } usort($ngram, 'cmp'); // display $count = $_GET['count']; if ($count == 0) { $count = 5; } print "$order-gram $type
sorted by
"; if ($sort == "ratio_worse") { print "ratio worse "; print "smooth-$smooth "; print "+ "; print "-,"; } else { print "ratio worse, "; } if ($sort == "abs_worse") { print "absolute worse, "; } else { print "absolute worse, "; } print "
"; if ($sort == "ratio_better") { print "ratio better "; print "smooth-$smooth "; print "+ "; print "-,"; } else { print "ratio better, "; } if ($sort == "abs_better") { print "absolute better, "; } else { print "absolute better, "; } print "
showing $count "; if ($count < 9999) { print "more "; if ($count > 5) { print "less "; } print "all "; } else { print "top5 "; } print "
\n"; print "\n"; print ""; if ($type == 'recall') { print "\n"; } else { print "\n"; } for($i=0;$i<$count && $i"; $ok = $line["correct1"]; $ok_diff = $ok - $line["correct0"]; $wrong = $line["total1"] - $line["correct1"]; $wrong_diff = $wrong - ($line["total0"]-$line["correct0"]); if ($type == 'recall') { printf("", $ok_diff,$ok,$wrong); } else { printf("", $ok_diff,$ok,$wrong_diff,$wrong); } } print "
$order-gramΔokx
ΔokΔx
".$line["ngram"]."%+d%d%d
%+d(%d)%+d(%d)
\n"; } function string_edit_distance($a,$b) { $cost = array( array( 0 ) ); $back = array( array( "" ) ); // init boundaries for($i=0;$i0 || $j>0) { if ($back[$i][$j] == "M" || $back[$i][$j] == "S") { $path = $back[$i][$j] . $path; $i--; $j--; } else if($i==0 || $back[$i][$j] == "I") { $path = "I".$path; $j--; } else { $path = "D".$path; $i--; } } return $path; }