Skip to content

Instantly share code, notes, and snippets.

@amankharwal

amankharwal/next word.py Secret

Created Jan 19, 2021
Embed
What would you like to do?
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')
else:
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