Skip to content

Instantly share code, notes, and snippets.

@amankharwal
Created January 19, 2021 12:15
Show Gist options
  • Save amankharwal/ab7f8dde12faab2aad669f5f52da0c85 to your computer and use it in GitHub Desktop.
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')
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