Advertisement
Guest User

Untitled

a guest
Mar 28th, 2017
60
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.42 KB | None | 0 0
  1. w1 = random.randint(0,s.length-3)
  2. output = s.text[w1] + ' ' + s.text[w1+1]
  3. prev_bigram = [s.text[w1], s.text[w1+1]]
  4. for num in range(k-2):
  5. if ' '.join(prev_bigram) in s.trigram_dict:
  6. next_word = random.choice(s.trigram_dict[' '.join(prev_bigram)])
  7. output = output + ' ' + next_word
  8. prev_bigram[0] = prev_bigram[1]
  9. prev_bigram[1] = next_word
  10. return output
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement