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:
parent
d9015233f5
commit
d70b8ff291
2 changed files with 10 additions and 4 deletions
|
@ -186,7 +186,9 @@ int Ver4PatriciaTriePolicy::getProbabilityOfWord(const WordIdArrayView prevWordI
|
||||||
if (bigramsIt.getBigramPos() == ptNodePos
|
if (bigramsIt.getBigramPos() == ptNodePos
|
||||||
&& bigramsIt.getProbability() != NOT_A_PROBABILITY) {
|
&& bigramsIt.getProbability() != NOT_A_PROBABILITY) {
|
||||||
const int bigramConditionalProbability = getBigramConditionalProbability(
|
const int bigramConditionalProbability = getBigramConditionalProbability(
|
||||||
prevWordPtNodeParams.getProbability(), bigramsIt.getProbability());
|
prevWordPtNodeParams.getProbability(),
|
||||||
|
prevWordPtNodeParams.representsBeginningOfSentence(),
|
||||||
|
bigramsIt.getProbability());
|
||||||
return getProbability(ptNodeParams.getProbability(), bigramConditionalProbability);
|
return getProbability(ptNodeParams.getProbability(), bigramConditionalProbability);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -209,15 +211,19 @@ void Ver4PatriciaTriePolicy::iterateNgramEntries(const WordIdArrayView prevWordI
|
||||||
while (bigramsIt.hasNext()) {
|
while (bigramsIt.hasNext()) {
|
||||||
bigramsIt.next();
|
bigramsIt.next();
|
||||||
const int bigramConditionalProbability = getBigramConditionalProbability(
|
const int bigramConditionalProbability = getBigramConditionalProbability(
|
||||||
prevWordPtNodeParams.getProbability(), bigramsIt.getProbability());
|
prevWordPtNodeParams.getProbability(),
|
||||||
|
prevWordPtNodeParams.representsBeginningOfSentence(), bigramsIt.getProbability());
|
||||||
listener->onVisitEntry(bigramConditionalProbability,
|
listener->onVisitEntry(bigramConditionalProbability,
|
||||||
getWordIdFromTerminalPtNodePos(bigramsIt.getBigramPos()));
|
getWordIdFromTerminalPtNodePos(bigramsIt.getBigramPos()));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
int Ver4PatriciaTriePolicy::getBigramConditionalProbability(const int prevWordUnigramProbability,
|
int Ver4PatriciaTriePolicy::getBigramConditionalProbability(const int prevWordUnigramProbability,
|
||||||
const int bigramProbability) const {
|
const bool isInBeginningOfSentenceContext, const int bigramProbability) const {
|
||||||
if (mHeaderPolicy->hasHistoricalInfoOfWords()) {
|
if (mHeaderPolicy->hasHistoricalInfoOfWords()) {
|
||||||
|
if (isInBeginningOfSentenceContext) {
|
||||||
|
return bigramProbability;
|
||||||
|
}
|
||||||
// Calculate conditional probability.
|
// Calculate conditional probability.
|
||||||
return std::min(MAX_PROBABILITY - prevWordUnigramProbability + bigramProbability,
|
return std::min(MAX_PROBABILITY - prevWordUnigramProbability + bigramProbability,
|
||||||
MAX_PROBABILITY);
|
MAX_PROBABILITY);
|
||||||
|
|
|
@ -175,7 +175,7 @@ class Ver4PatriciaTriePolicy : public DictionaryStructureWithBufferPolicy {
|
||||||
const WordAttributes getWordAttributes(const int probability,
|
const WordAttributes getWordAttributes(const int probability,
|
||||||
const PtNodeParams &ptNodeParams) const;
|
const PtNodeParams &ptNodeParams) const;
|
||||||
int getBigramConditionalProbability(const int prevWordUnigramProbability,
|
int getBigramConditionalProbability(const int prevWordUnigramProbability,
|
||||||
const int bigramProbability) const;
|
const bool isInBeginningOfSentenceContext, const int bigramProbability) const;
|
||||||
};
|
};
|
||||||
} // namespace v402
|
} // namespace v402
|
||||||
} // namespace backward
|
} // namespace backward
|
||||||
|
|
Loading…
Reference in a new issue