Fix: BoS bigram from user history dictionary is too strong.

They can be always stronger than BoS predictions from the
contextual dictionary.

Bug: 17961731
Change-Id: I70297d82436c10c790bdfad6f3dfefdb4bb2f852
This commit is contained in:
Keisuke Kuroyanagi 2014-10-13 16:07:29 +09:00
parent d9015233f5
commit d70b8ff291
2 changed files with 10 additions and 4 deletions

View File

@ -186,7 +186,9 @@ int Ver4PatriciaTriePolicy::getProbabilityOfWord(const WordIdArrayView prevWordI
if (bigramsIt.getBigramPos() == ptNodePos
&& bigramsIt.getProbability() != NOT_A_PROBABILITY) {
const int bigramConditionalProbability = getBigramConditionalProbability(
prevWordPtNodeParams.getProbability(), bigramsIt.getProbability());
prevWordPtNodeParams.getProbability(),
prevWordPtNodeParams.representsBeginningOfSentence(),
bigramsIt.getProbability());
return getProbability(ptNodeParams.getProbability(), bigramConditionalProbability);
}
}
@ -209,15 +211,19 @@ void Ver4PatriciaTriePolicy::iterateNgramEntries(const WordIdArrayView prevWordI
while (bigramsIt.hasNext()) {
bigramsIt.next();
const int bigramConditionalProbability = getBigramConditionalProbability(
prevWordPtNodeParams.getProbability(), bigramsIt.getProbability());
prevWordPtNodeParams.getProbability(),
prevWordPtNodeParams.representsBeginningOfSentence(), bigramsIt.getProbability());
listener->onVisitEntry(bigramConditionalProbability,
getWordIdFromTerminalPtNodePos(bigramsIt.getBigramPos()));
}
}
int Ver4PatriciaTriePolicy::getBigramConditionalProbability(const int prevWordUnigramProbability,
const int bigramProbability) const {
const bool isInBeginningOfSentenceContext, const int bigramProbability) const {
if (mHeaderPolicy->hasHistoricalInfoOfWords()) {
if (isInBeginningOfSentenceContext) {
return bigramProbability;
}
// Calculate conditional probability.
return std::min(MAX_PROBABILITY - prevWordUnigramProbability + bigramProbability,
MAX_PROBABILITY);

View File

@ -175,7 +175,7 @@ class Ver4PatriciaTriePolicy : public DictionaryStructureWithBufferPolicy {
const WordAttributes getWordAttributes(const int probability,
const PtNodeParams &ptNodeParams) const;
int getBigramConditionalProbability(const int prevWordUnigramProbability,
const int bigramProbability) const;
const bool isInBeginningOfSentenceContext, const int bigramProbability) const;
};
} // namespace v402
} // namespace backward