Skip to content

Instantly share code, notes, and snippets.

Created January 19, 2021 12:15
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
Save amankharwal/ab7f8dde12faab2aad669f5f52da0c85 to your computer and use it in GitHub Desktop.
for word, transition in lexicon.items():
transition = dict((key, value / sum(transition.values())) for key, value in transition.items())
lexicon[word] = transition
line = input('> ')
word = line.strip().split(' ')[-1]
if word not in lexicon:
print('Word not found')
options = lexicon[word]
predicted = np.random.choice(list(options.keys()), p=list(options.values()))
print(line + ' ' + predicted)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment