bleu.hpp
Go to the documentation of this file.
1 
12 #ifndef MLPACK_CORE_METRICS_BLEU_HPP
13 #define MLPACK_CORE_METRICS_BLEU_HPP
14 
15 #include <mlpack/prereqs.hpp>
16 
17 namespace mlpack {
18 namespace metric {
19 
50 template <typename ElemType = float,
51  typename PrecisionType = std::vector<ElemType>
52 >
53 class BLEU
54 {
55  public:
61  BLEU(const size_t maxOrder = 4);
62 
98  template <typename ReferenceCorpusType, typename TranslationCorpusType>
99  ElemType Evaluate(const ReferenceCorpusType& referenceCorpus,
100  const TranslationCorpusType& translationCorpus,
101  const bool smooth = false);
102 
104  template<typename Archive>
105  void serialize(Archive& ar, const uint32_t version);
106 
108  size_t MaxOrder() const { return maxOrder; }
110  size_t& MaxOrder() { return maxOrder; }
111 
113  ElemType BLEUScore() const { return bleuScore; }
114 
116  ElemType BrevityPenalty() const { return brevityPenalty; }
117 
119  size_t TranslationLength() const { return translationLength; }
120 
122  size_t ReferenceLength() const { return referenceLength; }
123 
125  ElemType Ratio() const { return ratio; }
126 
128  PrecisionType const& Precisions() const { return precisions; }
129 
130  private:
137  template <typename WordVector>
138  std::map<WordVector, size_t> GetNGrams(const WordVector& segment);
139 
141  size_t maxOrder;
142 
144  ElemType bleuScore;
145 
148  ElemType brevityPenalty;
149 
151  size_t translationLength;
152 
154  size_t referenceLength;
155 
157  ElemType ratio;
158 
160  PrecisionType precisions;
161 };
162 
163 } // namespace metric
164 } // namespace mlpack
165 
166 // Include implementation.
167 #include "bleu_impl.hpp"
168 
169 #endif
size_t TranslationLength() const
Get the value of translation length.
Definition: bleu.hpp:119
Linear algebra utility functions, generally performed on matrices or vectors.
The core includes that mlpack expects; standard C++ includes and Armadillo.
ElemType BLEUScore() const
Get the BLEU Score.
Definition: bleu.hpp:113
void serialize(Archive &ar, const uint32_t version)
Serialize the metric.
ElemType Evaluate(const ReferenceCorpusType &referenceCorpus, const TranslationCorpusType &translationCorpus, const bool smooth=false)
Computes the BLEU Score.
size_t MaxOrder() const
Get the value of maximum length of tokens in n-grams.
Definition: bleu.hpp:108
ElemType Ratio() const
Get the ratio of translation to reference length ratio.
Definition: bleu.hpp:125
BLEU(const size_t maxOrder=4)
Create an instance of BLEU class.
PrecisionType const & Precisions() const
Get the precisions for corresponding order.
Definition: bleu.hpp:128
size_t ReferenceLength() const
Get the value of reference length.
Definition: bleu.hpp:122
size_t & MaxOrder()
Modify the value of maximum length of tokens in n-grams.
Definition: bleu.hpp:110
BLEU, or the Bilingual Evaluation Understudy, is an algorithm for evaluating the quality of text whic...
Definition: bleu.hpp:53
ElemType BrevityPenalty() const
Get the brevity penalty.
Definition: bleu.hpp:116