2008-06-11 14:52:57 +04:00
|
|
|
// $Id$
|
|
|
|
|
|
|
|
/***********************************************************************
|
|
|
|
Moses - factored phrase-based language decoder
|
|
|
|
Copyright (C) 2006 University of Edinburgh
|
|
|
|
|
|
|
|
This library is free software; you can redistribute it and/or
|
|
|
|
modify it under the terms of the GNU Lesser General Public
|
|
|
|
License as published by the Free Software Foundation; either
|
|
|
|
version 2.1 of the License, or (at your option) any later version.
|
|
|
|
|
|
|
|
This library is distributed in the hope that it will be useful,
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
Lesser General Public License for more details.
|
|
|
|
|
|
|
|
You should have received a copy of the GNU Lesser General Public
|
|
|
|
License along with this library; if not, write to the Free Software
|
|
|
|
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
|
|
|
***********************************************************************/
|
|
|
|
|
2010-02-24 14:15:44 +03:00
|
|
|
#ifndef moses_LanguageModel_h
|
|
|
|
#define moses_LanguageModel_h
|
2008-06-11 14:52:57 +04:00
|
|
|
|
|
|
|
#include <string>
|
2011-10-13 18:27:01 +04:00
|
|
|
#include <cstddef>
|
2012-10-08 00:47:24 +04:00
|
|
|
|
2013-05-24 22:11:15 +04:00
|
|
|
#include "moses/FF/StatefulFeatureFunction.h"
|
2008-06-11 14:52:57 +04:00
|
|
|
|
2008-10-09 03:51:26 +04:00
|
|
|
namespace Moses
|
|
|
|
{
|
|
|
|
|
2013-05-29 21:16:15 +04:00
|
|
|
namespace Incremental
|
|
|
|
{
|
|
|
|
class Manager;
|
|
|
|
}
|
2012-10-11 19:38:39 +04:00
|
|
|
|
2008-06-11 14:52:57 +04:00
|
|
|
class FactorCollection;
|
|
|
|
class Factor;
|
|
|
|
class Phrase;
|
|
|
|
|
|
|
|
//! Abstract base class which represent a language model on a contiguous phrase
|
2013-05-29 21:16:15 +04:00
|
|
|
class LanguageModel : public StatefulFeatureFunction
|
|
|
|
{
|
2011-02-24 16:14:42 +03:00
|
|
|
protected:
|
2013-02-07 00:05:00 +04:00
|
|
|
LanguageModel(const std::string& description, const std::string &line);
|
2011-10-13 16:33:05 +04:00
|
|
|
|
|
|
|
// This can't be in the constructor for virual function dispatch reasons
|
|
|
|
|
2011-09-09 22:03:00 +04:00
|
|
|
bool m_enableOOVFeature;
|
2013-05-29 21:16:15 +04:00
|
|
|
|
2010-11-17 17:06:21 +03:00
|
|
|
public:
|
2013-05-28 20:35:06 +04:00
|
|
|
static const LanguageModel &GetFirstLM();
|
|
|
|
|
2011-02-24 16:14:42 +03:00
|
|
|
virtual ~LanguageModel();
|
|
|
|
|
2011-10-11 17:50:44 +04:00
|
|
|
bool OOVFeatureEnabled() const {
|
|
|
|
return m_enableOOVFeature;
|
|
|
|
}
|
|
|
|
|
2011-02-24 16:14:42 +03:00
|
|
|
float GetWeight() const;
|
2011-09-09 22:03:00 +04:00
|
|
|
float GetOOVWeight() const;
|
2011-02-24 16:14:42 +03:00
|
|
|
|
|
|
|
|
2011-10-13 16:33:05 +04:00
|
|
|
virtual const FFState* EmptyHypothesisState(const InputType &input) const = 0;
|
2009-02-06 18:43:06 +03:00
|
|
|
|
2011-10-13 16:33:05 +04:00
|
|
|
/* calc total unweighted LM score of this phrase and return score via arguments.
|
|
|
|
* Return scores should always be in natural log, regardless of representation with LM implementation.
|
|
|
|
* Uses GetValue() of inherited class.
|
|
|
|
* \param fullScore scores of all unigram, bigram... of contiguous n-gram of the phrase
|
|
|
|
* \param ngramScore score of only n-gram of order m_nGramOrder
|
|
|
|
* \param oovCount number of LM OOVs
|
|
|
|
*/
|
2011-10-13 18:27:01 +04:00
|
|
|
virtual void CalcScore(const Phrase &phrase, float &fullScore, float &ngramScore, std::size_t &oovCount) const = 0;
|
2012-07-06 19:48:26 +04:00
|
|
|
virtual void CalcScoreFromCache(const Phrase &phrase, float &fullScore, float &ngramScore, std::size_t &oovCount) const {
|
|
|
|
}
|
2012-07-02 18:57:54 +04:00
|
|
|
|
|
|
|
virtual void IssueRequestsFor(Hypothesis& hypo,
|
|
|
|
const FFState* input_state) {
|
|
|
|
}
|
|
|
|
virtual void sync() {
|
|
|
|
}
|
|
|
|
virtual void SetFFStateIdx(int state_idx) {
|
|
|
|
}
|
|
|
|
|
2012-10-08 00:47:24 +04:00
|
|
|
// KenLM only (others throw an exception): call incremental search with the model and mapping.
|
2012-10-11 19:38:39 +04:00
|
|
|
virtual void IncrementalCallback(Incremental::Manager &manager) const;
|
2013-05-02 15:15:26 +04:00
|
|
|
|
2013-05-28 13:51:28 +04:00
|
|
|
virtual void Evaluate(const Phrase &source
|
2013-05-29 21:16:15 +04:00
|
|
|
, const TargetPhrase &targetPhrase
|
|
|
|
, ScoreComponentCollection &scoreBreakdown
|
|
|
|
, ScoreComponentCollection &estimatedFutureScore) const;
|
2013-08-30 18:49:00 +04:00
|
|
|
void Evaluate(const InputType &input
|
2013-09-27 12:35:24 +04:00
|
|
|
, const InputPath &inputPath
|
|
|
|
, const TargetPhrase &targetPhrase
|
|
|
|
, ScoreComponentCollection &scoreBreakdown) const
|
2013-08-30 18:49:00 +04:00
|
|
|
{}
|
2013-05-02 15:15:26 +04:00
|
|
|
|
2008-06-11 14:52:57 +04:00
|
|
|
};
|
|
|
|
|
2008-10-09 03:51:26 +04:00
|
|
|
}
|
|
|
|
|
2010-02-24 14:15:44 +03:00
|
|
|
#endif
|