diff options
author | Chris Dyer <cdyer@allegro.clab.cs.cmu.edu> | 2014-09-04 13:24:26 -0400 |
---|---|---|
committer | Chris Dyer <cdyer@allegro.clab.cs.cmu.edu> | 2014-09-04 13:24:26 -0400 |
commit | 5dfecf3ac4a0755255bb806f7d556f1f8e7dbc38 (patch) | |
tree | 592547d91748125b892e6ecd86de5ff2334a26aa /mteval/ns_wer.cc | |
parent | 969b00197fc41087f9eb808a7ebba293966f90de (diff) |
word error rate metric
Diffstat (limited to 'mteval/ns_wer.cc')
-rw-r--r-- | mteval/ns_wer.cc | 35 |
1 files changed, 35 insertions, 0 deletions
diff --git a/mteval/ns_wer.cc b/mteval/ns_wer.cc new file mode 100644 index 00000000..f9b2bbbb --- /dev/null +++ b/mteval/ns_wer.cc @@ -0,0 +1,35 @@ +#include "ns_wer.h" +#include "tdict.h" +#include "levenshtein.h" + +static const unsigned kNUMFIELDS = 2; +static const unsigned kEDITDISTANCE = 0; +static const unsigned kCHARCOUNT = 1; + +bool WERMetric::IsErrorMetric() const { + return true; +} + +unsigned WERMetric::SufficientStatisticsVectorSize() const { + return 2; +} + +void WERMetric::ComputeSufficientStatistics(const std::vector<WordID>& hyp, + const std::vector<std::vector<WordID> >& refs, + SufficientStats* out) const { + out->fields.resize(kNUMFIELDS); + float best_score = hyp.size(); + for (size_t i = 0; i < refs.size(); ++i) { + float score = cdec::LevenshteinDistance(hyp, refs[i]); + if (score < best_score) { + out->fields[kEDITDISTANCE] = score; + out->fields[kCHARCOUNT] = refs[i].size(); + best_score = score; + } + } +} + +float WERMetric::ComputeScore(const SufficientStats& stats) const { + return stats.fields[kEDITDISTANCE] / stats.fields[kCHARCOUNT]; +} + |