mosesdecoder/moses/LM/Base.h

98 lines
3.2 KiB
C
Raw Normal View History

// -*- mode: c++; indent-tabs-mode: nil; tab-width:2 -*-
// $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
***********************************************************************/
#ifndef moses_LanguageModel_h
#define moses_LanguageModel_h
#include <string>
#include <cstddef>
2013-05-24 22:11:15 +04:00
#include "moses/FF/StatefulFeatureFunction.h"
namespace Moses
{
2013-05-29 21:16:15 +04:00
namespace Incremental
{
class Manager;
}
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
{
protected:
LanguageModel(const std::string &line);
bool m_enableOOVFeature;
2013-05-29 21:16:15 +04:00
public:
static const LanguageModel &GetFirstLM();
virtual ~LanguageModel();
bool OOVFeatureEnabled() const {
return m_enableOOVFeature;
}
virtual void SetParameter(const std::string& key, const std::string& value);
virtual const FFState* EmptyHypothesisState(const InputType &input) const = 0;
Feature function overhaul. Each feature function is computed in one of three ways: 1) Stateless feature functions from the phrase table/generation table: these are computed when the TranslationOption is created. They become part of the ScoreBreakdown object contained in the TranslationOption and are added to the feature value vector when a hypothesis is extended. 2) Stateless feature functions that are computed during state exploration. Currently, only WordPenalty falls into this category, but these functions implement a method Evaluate which do does not receive a Hypothesis or any contextual information. 3) Stateful feature functions: these features receive the arc information (translation option), compute some value and then return some context information. The context information created by a particular feature function is passed back to it as the previous context when a hypothesis originating at the node where the previous edge terminates is created. States in the search space may be recombined if the context information is identical. The context information must be stored in an object implementing the FFState interface. TODO: 1) the command line interface / MERT interface needs to go to named parameters that are otherwise opaque 2) StatefulFeatureFunction's Evaluate method should just take a TranslationOption and a context object. It is not good that it takes a hypothesis, because then people may be tempted to access information about the "previous" hypothesis without "declaring" this dependency. 3) Future cost estimates should be handled using feature functions. All stateful feature functions need some kind of future cost estimate. 4) Philipp's poor-man's cube pruning is broken. git-svn-id: https://mosesdecoder.svn.sourceforge.net/svnroot/mosesdecoder/trunk@2087 1f5c12ca-751b-0410-a591-d2e778427230
2009-02-06 18:43:06 +03: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
*/
virtual void CalcScore(const Phrase &phrase, float &fullScore, float &ngramScore, std::size_t &oovCount) const = 0;
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) {
}
// KenLM only (others throw an exception): call incremental search with the model and mapping.
virtual void IncrementalCallback(Incremental::Manager &manager) const;
2013-10-13 09:59:05 +04:00
virtual void ReportHistoryOrder(std::ostream &out,const Phrase &phrase) const;
virtual void EvaluateInIsolation(const Phrase &source
2015-01-14 14:07:42 +03:00
, const TargetPhrase &targetPhrase
, ScoreComponentCollection &scoreBreakdown
2015-11-04 18:10:45 +03:00
, ScoreComponentCollection &estimatedScores) const;
2015-01-14 14:07:42 +03:00
};
}
#endif