diff --git a/java/src/com/android/inputmethod/latin/personalization/UserHistoryDictionary.java b/java/src/com/android/inputmethod/latin/personalization/UserHistoryDictionary.java
index 3916fc24c81551f8b87c08dd91106af0e43aa9aa..a6c6c7bac731fceaaab6438053b4efb1970e0691 100644
--- a/java/src/com/android/inputmethod/latin/personalization/UserHistoryDictionary.java
+++ b/java/src/com/android/inputmethod/latin/personalization/UserHistoryDictionary.java
@@ -75,7 +75,13 @@ public class UserHistoryDictionary extends DecayingExpandableBinaryDictionaryBas
             return;
         }
         if (null != prevWord) {
-            userHistoryDictionary.addNgramEntry(prevWordsInfo, word, frequency, timestamp);
+            if (prevWordsInfo.mIsBeginningOfSentence) {
+                // Beginning-of-Sentence n-gram entry is treated as a n-gram entry of invalid word.
+                userHistoryDictionary.addNgramEntry(prevWordsInfo, word,
+                        FREQUENCY_FOR_WORDS_NOT_IN_DICTS, timestamp);
+            } else {
+                userHistoryDictionary.addNgramEntry(prevWordsInfo, word, frequency, timestamp);
+            }
         }
     }
 }
diff --git a/native/jni/src/suggest/core/dictionary/bigram_dictionary.cpp b/native/jni/src/suggest/core/dictionary/bigram_dictionary.cpp
index 295e760d6da0a0f62e6634e26945cc3bd34e4141..56339fe48b169352783d066574ae5f9e76819b9e 100644
--- a/native/jni/src/suggest/core/dictionary/bigram_dictionary.cpp
+++ b/native/jni/src/suggest/core/dictionary/bigram_dictionary.cpp
@@ -57,6 +57,10 @@ void BigramDictionary::getPredictions(const PrevWordsInfo *const prevWordsInfo,
         if (bigramsIt.getBigramPos() == NOT_A_DICT_POS) {
             continue;
         }
+        if (prevWordsInfo->isNthPrevWordBeginningOfSentence(1 /* n */)
+                && bigramsIt.getProbability() == NOT_A_PROBABILITY) {
+            continue;
+        }
         const int codePointCount = mDictionaryStructurePolicy->
                 getCodePointsAndProbabilityAndReturnCodePointCount(bigramsIt.getBigramPos(),
                         MAX_WORD_LENGTH, bigramCodePoints, &unigramProbability);
diff --git a/tests/src/com/android/inputmethod/latin/InputLogicTests.java b/tests/src/com/android/inputmethod/latin/InputLogicTests.java
index 2709ecba63bdb5259195710cf825d8d97905b4ec..0552c221e16608c6c2e6e48f442e3221e375053d 100644
--- a/tests/src/com/android/inputmethod/latin/InputLogicTests.java
+++ b/tests/src/com/android/inputmethod/latin/InputLogicTests.java
@@ -517,15 +517,21 @@ public class InputLogicTests extends InputTestsBase {
                 suggestedWords.size() > 0 ? suggestedWords.getWord(0) : null);
     }
 
-    public void testNoPredictionsAfterPeriod() {
+    public void testPredictionsAfterPeriod() {
         mLatinIME.clearPersonalizedDictionariesForTest();
         final String WORD_TO_TYPE = "Barack. ";
         type(WORD_TO_TYPE);
         sleep(DELAY_TO_WAIT_FOR_PREDICTIONS);
         runMessages();
-        // Test the first prediction is not displayed
-        final SuggestedWords suggestedWords = mLatinIME.getSuggestedWordsForTest();
-        assertEquals("no prediction after period", 0, suggestedWords.size());
+        SuggestedWords suggestedWords = mLatinIME.getSuggestedWordsForTest();
+        assertEquals("No prediction after period after inputting once.", 0, suggestedWords.size());
+
+        type(WORD_TO_TYPE);
+        sleep(DELAY_TO_WAIT_FOR_PREDICTIONS);
+        runMessages();
+        suggestedWords = mLatinIME.getSuggestedWordsForTest();
+        assertEquals("Beginning-of-Sentence prediction after inputting 2 times.", "Barack",
+                suggestedWords.size() > 0 ? suggestedWords.getWord(0) : null);
     }
 
     public void testPredictionsAfterRecorrection() {