diff options
| author | Paul Baltescu <pauldb89@gmail.com> | 2013-02-21 14:13:55 +0000 | 
|---|---|---|
| committer | Paul Baltescu <pauldb89@gmail.com> | 2013-02-21 14:13:55 +0000 | 
| commit | bca26d953a774b8efca12f30407390b3f5eef9d0 (patch) | |
| tree | fe922de5c89b1844f677d550dcc24e87edd67a55 /mteval | |
| parent | 54a1c0e2bde259e3acc9c0a8ec8da3c7704e80ca (diff) | |
| parent | 95c364f2cb002241c4a62bedb1c5ef6f1e9a7f22 (diff) | |
Merge branch 'master' of https://github.com/pauldb89/cdec
Diffstat (limited to 'mteval')
| -rw-r--r-- | mteval/Makefile.am | 23 | ||||
| -rw-r--r-- | mteval/ns.cc | 3 | ||||
| -rw-r--r-- | mteval/ns_ssk.cc | 32 | ||||
| -rw-r--r-- | mteval/ns_ssk.h | 22 | ||||
| -rw-r--r-- | mteval/scorer_test.cc | 2 | 
5 files changed, 77 insertions, 5 deletions
| diff --git a/mteval/Makefile.am b/mteval/Makefile.am index 4444285f..681e798e 100644 --- a/mteval/Makefile.am +++ b/mteval/Makefile.am @@ -8,7 +8,21 @@ TESTS = scorer_test  noinst_LIBRARIES = libmteval.a +EXTRA_DIST = test_data +  libmteval_a_SOURCES = \ +  aer_scorer.h \ +  comb_scorer.h \ +  external_scorer.h \ +  ns.h \ +  ns_cer.h \ +  ns_comb.h \ +  ns_docscorer.h \ +  ns_ext.h \ +  ns_ssk.h \ +  ns_ter.h \ +  scorer.h \ +  ter.h \    aer_scorer.cc \    comb_scorer.cc \    external_scorer.cc \ @@ -18,17 +32,18 @@ libmteval_a_SOURCES = \    ns_comb.cc \    ns_docscorer.cc \    ns_ext.cc \ +  ns_ssk.cc \    ns_ter.cc \    scorer.cc \    ter.cc  fast_score_SOURCES = fast_score.cc -fast_score_LDADD = libmteval.a $(top_srcdir)/utils/libutils.a +fast_score_LDADD = libmteval.a ../utils/libutils.a  mbr_kbest_SOURCES = mbr_kbest.cc -mbr_kbest_LDADD = libmteval.a $(top_srcdir)/utils/libutils.a +mbr_kbest_LDADD = libmteval.a ../utils/libutils.a  scorer_test_SOURCES = scorer_test.cc -scorer_test_LDADD = libmteval.a $(top_srcdir)/utils/libutils.a $(BOOST_UNIT_TEST_FRAMEWORK_LDFLAGS) $(BOOST_UNIT_TEST_FRAMEWORK_LIBS) +scorer_test_LDADD = libmteval.a ../utils/libutils.a $(BOOST_UNIT_TEST_FRAMEWORK_LDFLAGS) $(BOOST_UNIT_TEST_FRAMEWORK_LIBS) -AM_CPPFLAGS = -DBOOST_TEST_DYN_LINK -W -Wall -Wno-sign-compare $(GTEST_CPPFLAGS) -I$(top_srcdir)/utils +AM_CPPFLAGS = -DTEST_DATA=\"$(top_srcdir)/mteval/test_data\" -DBOOST_TEST_DYN_LINK -W -Wall -Wno-sign-compare -I$(top_srcdir) -I$(top_srcdir)/utils 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 diff --git a/mteval/scorer_test.cc b/mteval/scorer_test.cc index 9b765d0f..da07f154 100644 --- a/mteval/scorer_test.cc +++ b/mteval/scorer_test.cc @@ -36,7 +36,7 @@ struct Stuff {  BOOST_FIXTURE_TEST_SUITE( s, Stuff );  BOOST_AUTO_TEST_CASE(TestCreateFromFiles) { -  std::string path(boost::unit_test::framework::master_test_suite().argc == 2 ? boost::unit_test::framework::master_test_suite().argv[1] : "test_data"); +  std::string path(boost::unit_test::framework::master_test_suite().argc == 2 ? boost::unit_test::framework::master_test_suite().argv[1] : TEST_DATA);    vector<string> files;    files.push_back(path + "/re.txt.0");    files.push_back(path + "/re.txt.1"); | 
