Skip to content

Instantly share code, notes, and snippets.

@amankharwal
Created January 19, 2021 12:13
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save amankharwal/e730954eec54ab8a9b4b4cd581b974c4 to your computer and use it in GitHub Desktop.
Save amankharwal/e730954eec54ab8a9b4b4cd581b974c4 to your computer and use it in GitHub Desktop.
import numpy as np
lexicon = {}
def update_lexicon(current : str, next_word : str) -> None:
# Add the input word to the lexicon if it in there yet.
if current not in lexicon:
lexicon.update({current: {next_word: 1} })
return
# Recieve te probabilties of the input word.
options = lexicon[current]
# Check if the output word is in the propability list.
if next_word not in options:
options.update({next_word : 1})
else:
options.update({next_word : options[next_word] + 1})
# Update the lexicon
lexicon[current] = options
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment