\section{B\+L\+EU$<$ Elem\+Type, Precision\+Type $>$ Class Template Reference}
\label{classmlpack_1_1metric_1_1BLEU}\index{B\+L\+E\+U$<$ Elem\+Type, Precision\+Type $>$@{B\+L\+E\+U$<$ Elem\+Type, Precision\+Type $>$}}


\doxyref{B\+L\+EU}{p.}{classmlpack_1_1metric_1_1BLEU}, or the Bilingual Evaluation Understudy, is an algorithm for evaluating the quality of text which has been machine translated from one natural language to another.  


\subsection*{Public Member Functions}
\begin{DoxyCompactItemize}
\item 
\textbf{ B\+L\+EU} (const size\+\_\+t max\+Order=4)
\begin{DoxyCompactList}\small\item\em Create an instance of \doxyref{B\+L\+EU}{p.}{classmlpack_1_1metric_1_1BLEU} class. \end{DoxyCompactList}\item 
Elem\+Type \textbf{ B\+L\+E\+U\+Score} () const
\begin{DoxyCompactList}\small\item\em Get the \doxyref{B\+L\+EU}{p.}{classmlpack_1_1metric_1_1BLEU} Score. \end{DoxyCompactList}\item 
Elem\+Type \textbf{ Brevity\+Penalty} () const
\begin{DoxyCompactList}\small\item\em Get the brevity penalty. \end{DoxyCompactList}\item 
{\footnotesize template$<$typename Reference\+Corpus\+Type , typename Translation\+Corpus\+Type $>$ }\\Elem\+Type \textbf{ Evaluate} (const Reference\+Corpus\+Type \&reference\+Corpus, const Translation\+Corpus\+Type \&translation\+Corpus, const bool smooth=false)
\begin{DoxyCompactList}\small\item\em Computes the \doxyref{B\+L\+EU}{p.}{classmlpack_1_1metric_1_1BLEU} Score. \end{DoxyCompactList}\item 
size\+\_\+t \textbf{ Max\+Order} () const
\begin{DoxyCompactList}\small\item\em Get the value of maximum length of tokens in n-\/grams. \end{DoxyCompactList}\item 
size\+\_\+t \& \textbf{ Max\+Order} ()
\begin{DoxyCompactList}\small\item\em Modify the value of maximum length of tokens in n-\/grams. \end{DoxyCompactList}\item 
Precision\+Type const  \& \textbf{ Precisions} () const
\begin{DoxyCompactList}\small\item\em Get the precisions for corresponding order. \end{DoxyCompactList}\item 
Elem\+Type \textbf{ Ratio} () const
\begin{DoxyCompactList}\small\item\em Get the ratio of translation to reference length ratio. \end{DoxyCompactList}\item 
size\+\_\+t \textbf{ Reference\+Length} () const
\begin{DoxyCompactList}\small\item\em Get the value of reference length. \end{DoxyCompactList}\item 
{\footnotesize template$<$typename Archive $>$ }\\void \textbf{ serialize} (Archive \&ar, const unsigned int)
\begin{DoxyCompactList}\small\item\em Serialize the metric. \end{DoxyCompactList}\item 
size\+\_\+t \textbf{ Translation\+Length} () const
\begin{DoxyCompactList}\small\item\em Get the value of translation length. \end{DoxyCompactList}\end{DoxyCompactItemize}


\subsection{Detailed Description}
\subsubsection*{template$<$typename Elem\+Type = float, typename Precision\+Type = std\+::vector$<$\+Elem\+Type$>$$>$\newline
class mlpack\+::metric\+::\+B\+L\+E\+U$<$ Elem\+Type, Precision\+Type $>$}

\doxyref{B\+L\+EU}{p.}{classmlpack_1_1metric_1_1BLEU}, or the Bilingual Evaluation Understudy, is an algorithm for evaluating the quality of text which has been machine translated from one natural language to another. 

It can also be used to evaluate text generated for a suite of natural language processing tasks.

The \doxyref{B\+L\+EU}{p.}{classmlpack_1_1metric_1_1BLEU} score is calculated using the following formula\+:

\begin{eqnarray*} \text{B} &=& bp \cdot \exp \left(\sum_{n=1}^{N} w \log p_n \right) \\ \text{where,} \\ bp &=& \text{brevity penalty} = \begin{cases} 1 & \text{if ratio} > 1 \\ \exp \left(1-\frac{1}{ratio}\right) & \text{otherwise} \end{cases} \\ p_n &=& \text{modified precision for n-gram,} \\ w &=& \frac {1}{maxOrder}, \\ ratio &=& \text{translation to reference length ratio,} \\ maxOrder &=& \text{maximum length of tokens in n-grams.} \end{eqnarray*}

The value of \doxyref{B\+L\+EU}{p.}{classmlpack_1_1metric_1_1BLEU} Score lies in between 0 and 1.


\begin{DoxyTemplParams}{Template Parameters}
{\em Elem\+Type} & Type of the quantities in \doxyref{B\+L\+EU}{p.}{classmlpack_1_1metric_1_1BLEU}, e.\+g. (long double, double, float). \\
\hline
{\em Precision\+Type} & Container type for precision for corresponding order. e.\+g. (std\+::vector$<$float$>$, std\+::vector$<$double$>$, or any such boost or armadillo container). \\
\hline
\end{DoxyTemplParams}


Definition at line 53 of file bleu.\+hpp.



\subsection{Constructor \& Destructor Documentation}
\mbox{\label{classmlpack_1_1metric_1_1BLEU_a07e247186e06bbb07ce43e4037a28109}} 
\index{mlpack\+::metric\+::\+B\+L\+EU@{mlpack\+::metric\+::\+B\+L\+EU}!B\+L\+EU@{B\+L\+EU}}
\index{B\+L\+EU@{B\+L\+EU}!mlpack\+::metric\+::\+B\+L\+EU@{mlpack\+::metric\+::\+B\+L\+EU}}
\subsubsection{B\+L\+E\+U()}
{\footnotesize\ttfamily \textbf{ B\+L\+EU} (\begin{DoxyParamCaption}\item[{const size\+\_\+t}]{max\+Order = {\ttfamily 4} }\end{DoxyParamCaption})}



Create an instance of \doxyref{B\+L\+EU}{p.}{classmlpack_1_1metric_1_1BLEU} class. 


\begin{DoxyParams}{Parameters}
{\em max\+Order} & The maximum length of tokens in n-\/grams. \\
\hline
\end{DoxyParams}


\subsection{Member Function Documentation}
\mbox{\label{classmlpack_1_1metric_1_1BLEU_a7dd39d40b744cfd6e159ae33424d5481}} 
\index{mlpack\+::metric\+::\+B\+L\+EU@{mlpack\+::metric\+::\+B\+L\+EU}!B\+L\+E\+U\+Score@{B\+L\+E\+U\+Score}}
\index{B\+L\+E\+U\+Score@{B\+L\+E\+U\+Score}!mlpack\+::metric\+::\+B\+L\+EU@{mlpack\+::metric\+::\+B\+L\+EU}}
\subsubsection{B\+L\+E\+U\+Score()}
{\footnotesize\ttfamily Elem\+Type B\+L\+E\+U\+Score (\begin{DoxyParamCaption}{ }\end{DoxyParamCaption}) const\hspace{0.3cm}{\ttfamily [inline]}}



Get the \doxyref{B\+L\+EU}{p.}{classmlpack_1_1metric_1_1BLEU} Score. 



Definition at line 113 of file bleu.\+hpp.

\mbox{\label{classmlpack_1_1metric_1_1BLEU_af43e97df37ec680d6fb20f6b7827c00b}} 
\index{mlpack\+::metric\+::\+B\+L\+EU@{mlpack\+::metric\+::\+B\+L\+EU}!Brevity\+Penalty@{Brevity\+Penalty}}
\index{Brevity\+Penalty@{Brevity\+Penalty}!mlpack\+::metric\+::\+B\+L\+EU@{mlpack\+::metric\+::\+B\+L\+EU}}
\subsubsection{Brevity\+Penalty()}
{\footnotesize\ttfamily Elem\+Type Brevity\+Penalty (\begin{DoxyParamCaption}{ }\end{DoxyParamCaption}) const\hspace{0.3cm}{\ttfamily [inline]}}



Get the brevity penalty. 



Definition at line 116 of file bleu.\+hpp.

\mbox{\label{classmlpack_1_1metric_1_1BLEU_a09c9eb1b36cb33697e35853217a06771}} 
\index{mlpack\+::metric\+::\+B\+L\+EU@{mlpack\+::metric\+::\+B\+L\+EU}!Evaluate@{Evaluate}}
\index{Evaluate@{Evaluate}!mlpack\+::metric\+::\+B\+L\+EU@{mlpack\+::metric\+::\+B\+L\+EU}}
\subsubsection{Evaluate()}
{\footnotesize\ttfamily Elem\+Type Evaluate (\begin{DoxyParamCaption}\item[{const Reference\+Corpus\+Type \&}]{reference\+Corpus,  }\item[{const Translation\+Corpus\+Type \&}]{translation\+Corpus,  }\item[{const bool}]{smooth = {\ttfamily false} }\end{DoxyParamCaption})}



Computes the \doxyref{B\+L\+EU}{p.}{classmlpack_1_1metric_1_1BLEU} Score. 


\begin{DoxyTemplParams}{Template Parameters}
{\em Reference\+Corpus\+Type} & Type of reference corpus. \\
\hline
{\em Translation\+Corpus\+Type} & Type of translation corpus. \\
\hline
\end{DoxyTemplParams}

\begin{DoxyParams}{Parameters}
{\em reference\+Corpus} & It is an array of various references or documents. So, the $ referenceCorpus = \{reference_1, reference_2, \ldots \} $ and each reference is an array of paragraphs. So, $ reference_i = \{paragraph_1, paragraph_2, \ldots \} $ and then each paragraph is an array of tokenized words/string. Like, $ paragraph_i = \{word_1, word_2, \ldots \} $. For ex. 
\begin{DoxyCode}
refCorpus = \{\{\{\textcolor{stringliteral}{"this"}, \textcolor{stringliteral}{"is"}, \textcolor{stringliteral}{"paragraph"}, \textcolor{stringliteral}{"1"}, \textcolor{stringliteral}{"from"}, \textcolor{stringliteral}{"document"}, \textcolor{stringliteral}{"1"}\},
              \{\textcolor{stringliteral}{"this"}, \textcolor{stringliteral}{"is"}, \textcolor{stringliteral}{"paragraph"}, \textcolor{stringliteral}{"2"}, \textcolor{stringliteral}{"from"}, \textcolor{stringliteral}{"document"}, \textcolor{stringliteral}{"1"}\}\},

             \{\{\textcolor{stringliteral}{"this"}, \textcolor{stringliteral}{"is"}, \textcolor{stringliteral}{"paragraph"}, \textcolor{stringliteral}{"1"}, \textcolor{stringliteral}{"from"}, \textcolor{stringliteral}{"document"}, \textcolor{stringliteral}{"2"}\},
              \{\textcolor{stringliteral}{"this"}, \textcolor{stringliteral}{"is"}, \textcolor{stringliteral}{"paragraph"}, \textcolor{stringliteral}{"2"}, \textcolor{stringliteral}{"from"}, \textcolor{stringliteral}{"document"}, \textcolor{stringliteral}{"2"}\}\}\}
\end{DoxyCode}
 \\
\hline
{\em translation\+Corpus} & It is an array of paragraphs which has been machine translated or generated for any natural language processing task. Like, $ translationCorpus = \{paragraph_1, paragraph_2, \ldots \} $. And then, each paragraph is an array of words. The ith paragraph from the corpus is $ paragraph_i = \{word_1, word_2, \ldots \} $. For ex. 
\begin{DoxyCode}
transCorpus = \{\{\textcolor{stringliteral}{"this"}, \textcolor{stringliteral}{"is"}, \textcolor{stringliteral}{"generated"}, \textcolor{stringliteral}{"paragraph"}, \textcolor{stringliteral}{"1"}\},
               \{\textcolor{stringliteral}{"this"}, \textcolor{stringliteral}{"is"}, \textcolor{stringliteral}{"generated"}, \textcolor{stringliteral}{"paragraph"}, \textcolor{stringliteral}{"2"}\}\}
\end{DoxyCode}
 \\
\hline
{\em smooth} & Whether or not to apply Lin et al. 2004 smoothing. \\
\hline
\end{DoxyParams}
\begin{DoxyReturn}{Returns}
The Evaluate method returns the \doxyref{B\+L\+EU}{p.}{classmlpack_1_1metric_1_1BLEU} Score. This method also calculates other \doxyref{B\+L\+EU}{p.}{classmlpack_1_1metric_1_1BLEU} metrics (brevity penalty, translation length, reference length, ratio and precisions) which can be accessed by their corresponding accessor methods. 
\end{DoxyReturn}
\mbox{\label{classmlpack_1_1metric_1_1BLEU_a1c5368db109f081a335168612037d1cb}} 
\index{mlpack\+::metric\+::\+B\+L\+EU@{mlpack\+::metric\+::\+B\+L\+EU}!Max\+Order@{Max\+Order}}
\index{Max\+Order@{Max\+Order}!mlpack\+::metric\+::\+B\+L\+EU@{mlpack\+::metric\+::\+B\+L\+EU}}
\subsubsection{Max\+Order()\hspace{0.1cm}{\footnotesize\ttfamily [1/2]}}
{\footnotesize\ttfamily size\+\_\+t Max\+Order (\begin{DoxyParamCaption}{ }\end{DoxyParamCaption}) const\hspace{0.3cm}{\ttfamily [inline]}}



Get the value of maximum length of tokens in n-\/grams. 



Definition at line 108 of file bleu.\+hpp.

\mbox{\label{classmlpack_1_1metric_1_1BLEU_a958dfaa4a95b695ada68723d66e4b547}} 
\index{mlpack\+::metric\+::\+B\+L\+EU@{mlpack\+::metric\+::\+B\+L\+EU}!Max\+Order@{Max\+Order}}
\index{Max\+Order@{Max\+Order}!mlpack\+::metric\+::\+B\+L\+EU@{mlpack\+::metric\+::\+B\+L\+EU}}
\subsubsection{Max\+Order()\hspace{0.1cm}{\footnotesize\ttfamily [2/2]}}
{\footnotesize\ttfamily size\+\_\+t\& Max\+Order (\begin{DoxyParamCaption}{ }\end{DoxyParamCaption})\hspace{0.3cm}{\ttfamily [inline]}}



Modify the value of maximum length of tokens in n-\/grams. 



Definition at line 110 of file bleu.\+hpp.

\mbox{\label{classmlpack_1_1metric_1_1BLEU_a1ba252ce96f897d8900d4a9e872c4a7b}} 
\index{mlpack\+::metric\+::\+B\+L\+EU@{mlpack\+::metric\+::\+B\+L\+EU}!Precisions@{Precisions}}
\index{Precisions@{Precisions}!mlpack\+::metric\+::\+B\+L\+EU@{mlpack\+::metric\+::\+B\+L\+EU}}
\subsubsection{Precisions()}
{\footnotesize\ttfamily Precision\+Type const\& Precisions (\begin{DoxyParamCaption}{ }\end{DoxyParamCaption}) const\hspace{0.3cm}{\ttfamily [inline]}}



Get the precisions for corresponding order. 



Definition at line 128 of file bleu.\+hpp.

\mbox{\label{classmlpack_1_1metric_1_1BLEU_ae58a8c932301f269b525cd11b62cad86}} 
\index{mlpack\+::metric\+::\+B\+L\+EU@{mlpack\+::metric\+::\+B\+L\+EU}!Ratio@{Ratio}}
\index{Ratio@{Ratio}!mlpack\+::metric\+::\+B\+L\+EU@{mlpack\+::metric\+::\+B\+L\+EU}}
\subsubsection{Ratio()}
{\footnotesize\ttfamily Elem\+Type Ratio (\begin{DoxyParamCaption}{ }\end{DoxyParamCaption}) const\hspace{0.3cm}{\ttfamily [inline]}}



Get the ratio of translation to reference length ratio. 



Definition at line 125 of file bleu.\+hpp.

\mbox{\label{classmlpack_1_1metric_1_1BLEU_a5f955b8787f98cecc888a835624caa46}} 
\index{mlpack\+::metric\+::\+B\+L\+EU@{mlpack\+::metric\+::\+B\+L\+EU}!Reference\+Length@{Reference\+Length}}
\index{Reference\+Length@{Reference\+Length}!mlpack\+::metric\+::\+B\+L\+EU@{mlpack\+::metric\+::\+B\+L\+EU}}
\subsubsection{Reference\+Length()}
{\footnotesize\ttfamily size\+\_\+t Reference\+Length (\begin{DoxyParamCaption}{ }\end{DoxyParamCaption}) const\hspace{0.3cm}{\ttfamily [inline]}}



Get the value of reference length. 



Definition at line 122 of file bleu.\+hpp.

\mbox{\label{classmlpack_1_1metric_1_1BLEU_af0dd9205158ccf7bcfcd8ff81f79c927}} 
\index{mlpack\+::metric\+::\+B\+L\+EU@{mlpack\+::metric\+::\+B\+L\+EU}!serialize@{serialize}}
\index{serialize@{serialize}!mlpack\+::metric\+::\+B\+L\+EU@{mlpack\+::metric\+::\+B\+L\+EU}}
\subsubsection{serialize()}
{\footnotesize\ttfamily void serialize (\begin{DoxyParamCaption}\item[{Archive \&}]{ar,  }\item[{const unsigned}]{int }\end{DoxyParamCaption})}



Serialize the metric. 

\mbox{\label{classmlpack_1_1metric_1_1BLEU_ab9e161d157ecb96ffc44ef3c17cf80af}} 
\index{mlpack\+::metric\+::\+B\+L\+EU@{mlpack\+::metric\+::\+B\+L\+EU}!Translation\+Length@{Translation\+Length}}
\index{Translation\+Length@{Translation\+Length}!mlpack\+::metric\+::\+B\+L\+EU@{mlpack\+::metric\+::\+B\+L\+EU}}
\subsubsection{Translation\+Length()}
{\footnotesize\ttfamily size\+\_\+t Translation\+Length (\begin{DoxyParamCaption}{ }\end{DoxyParamCaption}) const\hspace{0.3cm}{\ttfamily [inline]}}



Get the value of translation length. 



Definition at line 119 of file bleu.\+hpp.



The documentation for this class was generated from the following file\+:\begin{DoxyCompactItemize}
\item 
/var/www/mlpack.\+ratml.\+org/mlpack.\+org/\+\_\+src/mlpack-\/git/src/mlpack/core/metrics/\textbf{ bleu.\+hpp}\end{DoxyCompactItemize}
