diff options
author | Patrick Simianer <simianer@cl.uni-heidelberg.de> | 2013-02-18 18:31:23 +0100 |
---|---|---|
committer | Patrick Simianer <simianer@cl.uni-heidelberg.de> | 2013-02-18 18:31:23 +0100 |
commit | 7deec52e8feb1c908a91224f308e8cbd9a170576 (patch) | |
tree | c8fb09523f5fef8873bd921da000d42ad5e59b6f /mteval | |
parent | b89fd90083b22e6d4ab469af001a1f15fbcd7da9 (diff) | |
parent | c17d9c23d023a5c08656376944f636180f0a437b (diff) |
Merge remote-tracking branch 'upstream/master'
Diffstat (limited to 'mteval')
-rw-r--r-- | mteval/Makefile.am | 2 | ||||
-rw-r--r-- | mteval/ns.cc | 3 | ||||
-rw-r--r-- | mteval/ns_ssk.cc | 32 | ||||
-rw-r--r-- | mteval/ns_ssk.h | 22 |
4 files changed, 59 insertions, 0 deletions
diff --git a/mteval/Makefile.am b/mteval/Makefile.am index 83adee17..681e798e 100644 --- a/mteval/Makefile.am +++ b/mteval/Makefile.am @@ -19,6 +19,7 @@ libmteval_a_SOURCES = \ ns_comb.h \ ns_docscorer.h \ ns_ext.h \ + ns_ssk.h \ ns_ter.h \ scorer.h \ ter.h \ @@ -31,6 +32,7 @@ libmteval_a_SOURCES = \ ns_comb.cc \ ns_docscorer.cc \ ns_ext.cc \ + ns_ssk.cc \ ns_ter.cc \ scorer.cc \ ter.cc diff --git a/mteval/ns.cc b/mteval/ns.cc index 7d73061c..d8214558 100644 --- a/mteval/ns.cc +++ b/mteval/ns.cc @@ -3,6 +3,7 @@ #include "ns_ext.h" #include "ns_comb.h" #include "ns_cer.h" +#include "ns_ssk.h" #include <cstdio> #include <cassert> @@ -252,6 +253,8 @@ EvaluationMetric* EvaluationMetric::Instance(const string& imetric_id) { m = new BleuMetric<4, NIST>; } else if (metric_id == "KOEHN_BLEU") { m = new BleuMetric<4, Koehn>; + } else if (metric_id == "SSK") { + m = new SSKMetric; } else if (metric_id == "TER") { m = new TERMetric; } else if (metric_id == "METEOR") { diff --git a/mteval/ns_ssk.cc b/mteval/ns_ssk.cc new file mode 100644 index 00000000..c94e62ca --- /dev/null +++ b/mteval/ns_ssk.cc @@ -0,0 +1,32 @@ +#include "ns_ssk.h" + +#include <vector> + +#include "kernel_string_subseq.h" +#include "tdict.h" + +static const unsigned kNUMFIELDS = 2; +static const unsigned kSIMILARITY = 0; +static const unsigned kCOUNT = 1; + +unsigned SSKMetric::SufficientStatisticsVectorSize() const { + return kNUMFIELDS; +} + +void SSKMetric::ComputeSufficientStatistics(const std::vector<WordID>& hyp, + const std::vector<std::vector<WordID> >& refs, + SufficientStats* out) const { + out->fields.resize(kNUMFIELDS); + out->fields[kCOUNT] = 1; + float bestsim = 0; + for (unsigned i = 0; i < refs.size(); ++i) { + float s = ssk<4>(hyp, refs[i], 0.8); + if (s > bestsim) bestsim = s; + } + out->fields[kSIMILARITY] = bestsim; +} + +float SSKMetric::ComputeScore(const SufficientStats& stats) const { + return stats.fields[kSIMILARITY] / stats.fields[kCOUNT]; +} + diff --git a/mteval/ns_ssk.h b/mteval/ns_ssk.h new file mode 100644 index 00000000..0d418770 --- /dev/null +++ b/mteval/ns_ssk.h @@ -0,0 +1,22 @@ +#ifndef _NS_SSK_H_ +#define _NS_SSK_H_ + +#include "ns.h" + +class SSKMetric : public EvaluationMetric { + friend class EvaluationMetric; + private: + unsigned EditDistance(const std::string& hyp, + const std::string& ref) const; + protected: + SSKMetric() : EvaluationMetric("SSK") {} + + public: + virtual unsigned SufficientStatisticsVectorSize() const; + virtual void ComputeSufficientStatistics(const std::vector<WordID>& hyp, + const std::vector<std::vector<WordID> >& refs, + SufficientStats* out) const; + virtual float ComputeScore(const SufficientStats& stats) const; +}; + +#endif |