Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- w1 = random.randint(0,s.length-3)
- output = s.text[w1] + ' ' + s.text[w1+1]
- prev_bigram = [s.text[w1], s.text[w1+1]]
- for num in range(k-2):
- if ' '.join(prev_bigram) in s.trigram_dict:
- next_word = random.choice(s.trigram_dict[' '.join(prev_bigram)])
- output = output + ' ' + next_word
- prev_bigram[0] = prev_bigram[1]
- prev_bigram[1] = next_word
- return output
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement