More informative error message about <s> errors

This commit is contained in:
Kenneth Heafield 2011-11-01 10:24:40 +00:00
parent 314313ad89
commit 1c72f79698
2 changed files with 8 additions and 1 deletions

View File

@ -99,7 +99,10 @@ void LanguageModelImplementation::CalcScore(const Phrase &phrase, float &fullSco
if (word == GetSentenceStartArray()) {
// do nothing, don't include prob for <s> unigram
assert(currPos == 0);
if (currPos != 0) {
std::cerr << "Your data contains <s> in a position other than the first word." << std::endl;
abort();
}
} else {
LMResult result = GetValueGivenState(contextFactor, *state);
fullScore += result.score;

View File

@ -198,6 +198,10 @@ template <class Model> void LanguageModelKen<Model>::CalcScore(const Phrase &phr
*state0 = m_ngram->NullContextState();
} else {
lm::WordIndex index = TranslateID(word);
if (index == m_ngram->GetVocabulary().BeginSentence()) {
std::cerr << "Your data contains <s> in a position other than the first word." << std::endl;
abort();
}
float score = TransformLMScore(m_ngram->Score(*state0, index, *state1));
std::swap(state0, state1);
if (position >= ngramBoundary) ngramScore += score;