From c643ef361eea7ce43b4fc7a6e2461a01b3d0c3c6 Mon Sep 17 00:00:00 2001 From: austinma Date: Thu, 14 Jan 2016 21:22:56 -0500 Subject: Added character-level BLEU metric --- mteval/wer.cc | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) (limited to 'mteval/wer.cc') diff --git a/mteval/wer.cc b/mteval/wer.cc index c806b3be..b8cfd3d8 100644 --- a/mteval/wer.cc +++ b/mteval/wer.cc @@ -31,16 +31,17 @@ class WERScore : public ScoreBase { WERScore() : stats(0,kDUMMY_LAST_ENTRY) {} float ComputePartialScore() const { return 0.0;} float ComputeScore() const { + if (static_cast(stats[kCHARCOUNT]) < 0.5) + return 0; return static_cast(stats[kEDITDISTANCE]) / static_cast(stats[kCHARCOUNT]); } void ScoreDetails(string* details) const; void PlusPartialEquals(const Score& rhs, int oracle_e_cover, int oracle_f_cover, int src_len){} void PlusEquals(const Score& delta, const float scale) { - if (scale==1) - stats += static_cast(delta).stats; - if (scale==-1) - stats -= static_cast(delta).stats; - throw std::runtime_error("WERScore::PlusEquals with scale != +-1"); + const WERScore& delta_stats = static_cast(delta); + for (unsigned i = 0; i < kDUMMY_LAST_ENTRY; ++i) { + stats[i] += scale * static_cast(delta_stats.stats[i]); + } } void PlusEquals(const Score& delta) { stats += static_cast(delta).stats; @@ -88,7 +89,7 @@ void WERScore::ScoreDetails(std::string* details) const { } WERScorer::~WERScorer() {} -WERScorer::WERScorer(const vector >& refs) {} +WERScorer::WERScorer(const vector >& refs) {this->refs = refs;} ScoreP WERScorer::ScoreCCandidate(const vector& hyp) const { return ScoreP(); @@ -97,6 +98,9 @@ ScoreP WERScorer::ScoreCCandidate(const vector& hyp) const { float WERScorer::Calculate(const std::vector& hyp, const Sentence& ref, int& edits, int& char_count) const { edits = cdec::LevenshteinDistance(hyp, ref); char_count = ref.size(); + if (char_count == 0) { + return 0; + } return static_cast(edits) / static_cast(char_count); } -- cgit v1.2.3