title: Sentence generation from a normalized transition matrix in Python
body: <p>I am trying to train an algorithm to generate text based on input from a text file.
  So far I have created a dataframe which normalizes the counts of two words appearing together and displays them as probabilities (a normalized transition matrix).</p>
  <p><a href="https://i.stack.imgur.com/R9SnB.png" rel="nofollow noreferrer">A glimpse of the transition matrix</a></p>
  <p>I wanted to understand how i can pick a random word from a row in my df and generate sentences based on probabilities. In essence, sample all columns against one row (word) and pick the next word which has the greatest probability of appearing.</p>
  <ol>
  <li>For e.g. first word: &quot;A&quot;,</li>
  <li>Second word prob: &quot;long - 0.4&quot;, &quot;while - 0.3&quot;, &quot;night - 0.3&quot;</li>
  <li>Second word picked: long</li>
  <li>Sentence thus far: &quot;A long&quot;</li>
  <li>Repeat steps two to five to choose 3rd word.</li>
  </ol>
  <p>We can repeat the process for filling up the sentence until N words have been picked.</p>